[Ltrace-devel] Getting prototypes from debug information

Petr Machata pmachata at redhat.com
Mon May 19 12:51:36 UTC 2014


Dima Kogan <lists at dima.secretsauce.net> writes:

> Petr Machata <pmachata at redhat.com> writes:
>
>> I understand what's happening.  In proc.c, you look at
>> proc->leader->dwfl, and use that if it's present.  If it's not, you
>> create a new one.  But then you only store it at lib->dwfl, never at
>> proc->leader->dwfl.  Only when -w is active is proc->leader->dwfl
>> actually initialized, in which case the duplication scenario does occur.
>
> Hmmm. I still don't see the duplication. Have you observed it?

Yeah.  Annotate like this:

diff --git a/dwarf_prototypes.c b/dwarf_prototypes.c
index 4860e4d..fc81abe 100644
--- a/dwarf_prototypes.c
+++ b/dwarf_prototypes.c
@@ -993,6 +993,7 @@ static void import(struct protolib *plib, struct library *lib, Dwfl *dwfl)
        Dwarf_Addr bias;
        Dwarf_Die *die = NULL;
        while ((die = dwfl_nextcu(dwfl, die, &bias)) != NULL) {
+               fprintf(stderr, "%#lx\n", dwarf_dieoffset(die));
                if (dwarf_tag(die) == DW_TAG_compile_unit)
                        process_die_compileunit(plib, lib,
                                                &type_dieoffset_hash, die);
@@ -1009,6 +1010,8 @@ bool import_DWARF_prototypes(struct library *lib)
        struct protolib *plib = lib->protolib;
        Dwfl *dwfl = lib->dwfl;
 
+       fprintf(stderr, "==================== %s ===================\n",
+               lib->soname);
        debug(DEBUG_FUNCTION, "Importing DWARF prototypes from '%s'",
              lib->soname);
        if (plib == NULL) {

And then have ltrace -x A+B, where A is from one library, and B from
another.  E.g. I have a test where foo is in main binary and bar in a
DSO, and see this:

$ ./ltrace -w2 -x foo+bar -L ../a.out 2>&1 | less
foo(==================== a.out ===================
0xb     [this actually comes from a.out]
0xb     [this comes from a c.so]
0xb     [this comes from libc.so.6]
0x270b
0x686a
0x6b21
[... more libc.so.6 CU's ...]
0xb     [this comes from ld-linux-x86-64.so.2]
0x52a4
0x952e
0xb33d
[... more ld-linux-x86-64.so.2 CU's ...]
1 <unfinished ...>
bar at c.so(==================== c.so ===================
0xb     [again a.out CU]
0xb     [again c.so CU]
0xb     [etc.]
0x270b
0x686a
0x6b21
[... etc. ...]
1)                                      = 1
 > a.out(foo+0x16) [400618]
        /home/petr/proj/ltrace/master/b.c:5
 > (null)((null)+0x0) [f0b2dc]
 > [...]

<... foo resumed> )                              = 1
 > a.out(main+0x1a) [400633]
        /home/petr/proj/ltrace/master/b.c:9
 > (null)((null)+0x0) [7fff43fc1657]
 > [...]

+++ exited (status 1) +++

You could perhaps more easily get the same effect by tracing main+puts
or something in your typical hello world binary.

Thanks,
PM



More information about the Ltrace-devel mailing list