سؤال

I ran ltrace on a Word processor and opened a sample file, but surprisingly got only two calls.

__libc_start_main(0x8048820, 1, 0xbfe08844, 0x8048850, 0x80488b0 <unfinished ...>
_ZN10AP_UnixApp4mainEPKciPPc(0x8048910, 1, 0xbfe08844, 0xb61feff4, 0x8048850) = 0
+++ exited (status 0) +++

Shouldn't ltrace print all library calls?

هل كانت مفيدة؟

المحلول

The problem is that ltrace only intercepts calls from the main executable (abiword here) to other shared libraries, but does not intercept calls from one shared library to another.

For abiword, the main function doesn't actually do much:

(gdb) disas main
Dump of assembler code for function main:
   0x0000000000400a70 <+0>: mov    %rsi,%rdx
   0x0000000000400a73 <+3>: mov    %edi,%esi
   0x0000000000400a75 <+5>: mov    $0x400b6c,%edi
   0x0000000000400a7a <+10>:    jmpq   0x400950 <_ZN10AP_UnixApp4mainEPKciPPc@plt>
End of assembler dump.

As you can see, it simply does a return AP_UnixApp::main(argc, "abiword", argv);, and all the real activity happens in the library that implements AP_UnixApp::main (in my case, in /usr/lib/libabiword-2.8.so).

On a Fedora system, you can try using frysk instead. In particular, this:

ftrace -sym '*' abiword

produces a (very long) trace, beginning with:

528.528 attached /usr/bin/abiword
528.528 call #libpthread.so.0#_init(0x1, 0x7fffa8ba5bd8, 0x7fffa8ba5be8, 0x7fffa8ba5be8, 0x1f25bc2, 0x7)
528.528  call #libpthread.so.0#__pthread_initialize_minimal(0x1, 0x7fffa8ba5bd8, 0x7fffa8ba5be8, 0x7fffa8ba5be8, 0x1f25bc2, 0x7)
528.528   call #libpthread.so.0#__libc_sigaction(0x20, 0x7fffa8ba5a70, 0x0, 0x0, 0x1f25bc2, 0x7)
528.528   call #libpthread.so.0#__libc_sigaction(0x21, 0x7fffa8ba5a70, 0x0, 0x7f32501f27b0, 0x0, 0x7)
528.528   call #libc.so.6#getrlimit(0x3, 0x7fffa8ba5b10, 0x3f, 0x40, 0x0, 0x7) = 0
528.528   call #libc.so.6#sysconf(0x1e, 0x7fffa8ba5b10, 0x3f, 0x30220e7b17, 0x0, 0x7)
528.528    call #libc.so.6#getpagesize(0x1e, 0x7fffa8ba5b10, 0xfffffffffff51435, 0x30220e7b17, 0x0, 0x7) = 4096
528.528   leave #libc.so.6#sysconf = 4096
528.528   call #libc.so.6#__libc_dl_error_tsd(0x1e, 0x7fffa8ba5b10, 0x800000, 0x2a40, 0x0, 0x7) = 139854069229848
...

Ftrace documentation here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top