Showing high and low PC of every program functions using DWARF library

353 views Asked by At

I am trying to make this code work : https://github.com/eliben/code-for-blog/blob/master/2011/dwarf_get_func_addr.c It is extracted from a tutorial made by Eli Bendersky on http://eli.thegreenplace.net/2011/02/07/how-debuggers-work-part-3-debugging-information Unfortunately, low pc and high pc return always the same address for almost every function:

DW_TAG_subprogram: 'aFunctionName'

low pc  : 0x00000001
high pc : 0x7f3a00000001

Whereas if objdump --dwarf=decodedline ./lulesh_normal >> dump_dwarf.txt gives me :

File name                            Line number    Starting address
lulesh.cc                                   1297            0x402e00

lulesh.cc                                   1297            0x402e11
lulesh.cc                                   1299            0x402ee4
lulesh.cc                                   1300            0x402ef0
lulesh.cc                                   1301            0x402ef6
lulesh.cc                                   1299            0x402f00
[...]

So it manages to link line and address but not to find the real address of the functions. Any idea why ?

Thank you for your help,

1

There are 1 answers

0
Employed Russian On BEST ANSWER

The code in dwarf_get_func_addr.c has at least one bug: it assumes that every function has DW_AT_low_pc and DW_AT_high_pc attributes, and will print uninitialized values if that is not the case.

You should initialize lowpc = highpc = -1; on line 42, so as not to print unintialized values.

Other than that, it's impossible to help you without access to your lulesh_normal binary.

You should do readelf -wi lulesh_normal, and then step through list_func_in_die in a debugger, and compare what the program is reading there with the output from readelf -- they should match one to one. If they don't, your version of libdwarf is possibly buggy.