wickedchicken
wickedchicken

Reputation: 4773

map memory addresses to line numbers using DWARF information

I have an application that traces program execution through memory. I tried to use readelf --debug-dump=decodedline to get memory address / line # information, but the memory addresses I see don't match up often with the ones given by that dump. I wrote something to match up each address with the "most recent" one appearing in the DWARF data -- this seemed to clean some things up but I'm not sure if that's the "official" way to interpret this data.

Can someone explain the exact process to map a program address to line number using DWARF?

Upvotes: 5

Views: 2815

Answers (2)

J C Gonzalez
J C Gonzalez

Reputation: 911

Indeed, as mentioned by Phil Miller's answer, addr2line is your friend. I have a gist where I show how I get the line number in the (C++) application source code from an address obtained from a backtrace.

Following this process will not show you the process you mention, but can give you an idea of how the code gets mapped into the object code (in an executable or a library/archive). Hope it helps.

Upvotes: 1

Phil Miller
Phil Miller

Reputation: 38158

Have a look at the program addr2line. It can probably give you some guidance on how to do this, if not solving your problem entirely (e.g. by shelling out to it, or linking its functionality in).

Upvotes: 4

Related Questions