On Sat, Feb 5, 2022 at 1:45 AM stephen.t....@gmail.com <stephen.t.illingwo...@gmail.com> wrote: > > I'm trying to decode the DWARF data in an ELF binary and I'm not sure how to > handle functions. > > I'm using the elf/dwarf package in the Go standard library and successfully > using it to identify compile units and source files and also to find line > entries for an executed address. > > What I can't see is how to relate a dwarf.LineEntry to a function (or > SubProgram as it is called in DWARF terminology). > > If the SubProgram TAG has both Low PC and High PC attributes then I can see > how it can be done. Where it gets tricky is if a SubProgram has been inlined. > > What I don't fully understand is how InlinedSubPrograms relate to SubPrograms. > > I realise that this isn't really a Go question but I'm hoping someone has > used the Go standard library in this way and understands how to solve this > problem.
The DWARF line number information maps PC values to a file name and a line number. It sounds like you want to map a PC value to a function, and you want to consider inlining information. To do that use https://pkg.go.dev/debug/dwarf#Reader.SeekPC to get an Entry and look for the AttrName or AttrLinkageName attribute. Note that, as the documentation says, SeekPC is not efficient if you need to look up a bunch of PC values. For that you'll want to loop through the entries, call the Ranges method, and build a lookup table. Hope this helps. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXaPfiQh9AjSrheqo3s1xCWXgo21k19iBJw4hedDr28VQ%40mail.gmail.com.