[Ltrace-devel] Getting prototypes from debug information

Dima Kogan lists at dima.secretsauce.net
Sat May 3 06:43:20 UTC 2014


Petr Machata <pmachata at redhat.com> writes:

> Dima Kogan <lists at dima.secretsauce.net> writes:
>
>> The command at this point is
>>
>>  ./ltrace -f [DK: forgot '-f' in the original email] -l 'libjpeg.so*' /usr/bin/geeqie /tmp/small.jpg
>>
>>  
>> Second, running this way reports libjpeg->libjpeg calls correctly, but
>> not geeqie->ltrace [PM: presumably libjpeg?] ones. So some libjpeg
>> functions still get the wrong prototypes. For instance I see this:
>>  geeqie->jpeg_read_header(0x7f23f62506c0, 1, 0, 1496 <unfinished ...>
>>
>> I looked into this a bit. import_DWARF_prototypes() was only called on
>> libjpeg.so.8. jpeg_read_header() was indeed parsed correctly, the parsed
>> data just wasn't used. Were we looking in the 'geeqie' plib instead of
>
> Hmm, that's strange, it seems to work for me in a simplified test case:
>
> -- hle1.c --
> int jedna (void);
> int dva (void);
> int main (int argc, char *argv[]) { jedna (); return dva (); }
>
> -- hle2.c --
> int dva (void) { return 2; }
> int jedna (void) { return dva (); }
>
> $ gcc hle1.c -g -L. -Wl,-rpath,. -lhle2
> $ gcc hle2.c -g -fpic -shared -o libhle2.so
> $ ~/tmp/ltrace/build/ltrace -llibhle* ./a.out -e''
> a.out->jedna( <unfinished ...>
> libhle2.so->dva()                                   = 2
> <... jedna resumed> )                               = 2
> a.out->dva()                                        = 2
> +++ exited (status 2) +++

I looked into this, and it's caused by the thread. If you modify your
main() in hle1.c to do pthread_create() and call jedna() from the
thread, then the in-second-thread jedna() call is shown with the default
prototype. This is with 'ltrace -f -l'. I have a little test library I
use to run these tests, and I'm attaching it so that you can see this in
action. Here's what happens:

 dima at shorty:~/projects/ltrace$ cd ltracetests/

 dima at shorty:~/projects/ltrace/ltracetests$ make
 <snip>

 dima at shorty:~/projects/ltrace/ltracetests$ ../ltrace -f -l tstlib.so ./tst

 [pid 23546] tst->linkedlisttest({ 5, nil })                            = <void>
 [pid 23546] tst->treetest({ 1, { 2, nil, nil }, { 3, nil, { 4, nil, nil } } } <unfinished ...>
 [pid 23546] tstlib.so->treetest({ 2, nil, nil })                       = nil
 [pid 23546] tstlib.so->treetest({ 3, nil, { 4, nil, nil } } <unfinished ...>
 [pid 23546] tstlib.so->treetest({ 4, nil, nil })                       = nil
 [pid 23546] <... treetest resumed> )                                   = { 5, nil, nil }
 [pid 23546] <... treetest resumed> )                                   = { 2, { 3, nil, nil }, { 4, nil, { 5, nil, nil } } }
 [pid 23546] tst->looptest({ { recurse^, 6 }, 5 })                      = <void>
 [pid 23546] tst->enumtest(A, B)                                        = 0
 [pid 23546] tst->arraytest({ [ 1.000000, 2.000000, 1.000000, 2.000000... ] }) = 1.000000
 [pid 23546] tst->enum_cxx_test( <unfinished ...>
 [pid 23546] tstlib.so->_Z3f127Colors2(GREEN2)                          = RED1
 [pid 23546] tstlib.so->_Z3f347Colors4(BLUE4)                           = RED3
 [pid 23546] tstlib.so->_Z3f557Colors5(RED5)                            = RED5
 [pid 23546] <... enum_cxx_test resumed> )                              = <void>
 [pid 23546] tst->stringtest("test")                                    = 4
 [pid 23546] tst->stringtest(nil)                                       = -1
 [pid 23546] tst->FILEtest(0x7f84e7bc42a0, 0x7f84e7bc4060)              = <void>
 [pid 23546] tst->voidfunc()                                            = <void>
 in thread
 [pid 23547] tst->looptest(0x7f84e7001f00, 10, 0x7f84e7bc5790, -1)      = 0x7f84e7001ef0
 [pid 23547] +++ exited (status 0) +++
 [pid 23546] +++ exited (status 0) +++

Note the looptest() call. The first one is in the main thread, and it's
reported correctly. The second is in a child thread, and it's
misreported.

dima
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ltracetests.tar.gz
Type: application/octet-stream
Size: 1955 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/ltrace-devel/attachments/20140502/7992ddf7/attachment.obj>


More information about the Ltrace-devel mailing list