Retrieving the function name from an address in .debug_info

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

Retrieving the function name from an address in .debug_info

Post by lpoulain »

All,

As many of you, I want to get a more meaningful stack trace when I experience a crash. So I embarked on understanding the DWARF format.

I was able to successfully decode the .debug_line section, so my stack traces now display the source code directory/filename/line number. Yay! (don't hesitate to ask me questions if you're stuck in that step)

For the next step I would like to display the function name as well. However, going through the .debug_info doesn't seem straightforward as each type of Debugging Information Entry (DIE) has a different size, and this size changes for each compilation unit. So yes, I can look at the .debug_abbrev section to find the schema for each DIE in each compilation unit, handle special cases for variable-length attributes, but this seems overly complicated when all I want is the address ranges each function covers.

Has anybody come up with a faster way?

Thanks
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

Re: Retrieving the function name from an address in .debug_i

Post by lpoulain »

Well, I bit the bullet and went the only way I know. At initialization time, go through the .debug_info section, go through each DIE, each attribute, compute how large they are based on the computing unit's schema. When a DIE is of type DW_TAG_subprogram, look for some of its attributes to build a table which contains the function names and address ranges.

When printing the stack trace, I just go through that table to find the function which is covering the desired range.

It was a major pain in the neck but it works! Phew!
Post Reply