On Tue, Apr 2, 2024 at 2:35 AM 'TheDiveO' via golang-nuts <golang-nuts@googlegroups.com> wrote: > > On Linux, given an arbitrary binary executable with symbol information in the > executable, how can I lookup an instruction pointer address to get the > corresponding symbol name? > > The binary (and its process) isn't a Go binary, but any arbitrary executable. > The stack unwinding has already been done, so I'm presented with a list of > instruction pointer addresses (return addresses) which I need to convert to > more useful symbol names. > > I've seen the stdlib's debug/elf package, but I lack the ELF knowledge to > press the elf package's knobs in the right order. Any examples of how to use > debug/elf, and is it even the right package to use in this case?
debug/elf is the package to use. You'll want to call the Symbols method and look through the Symbols for one whose Value is <= the PC you want while Value+Size is > the PC you want. If you are looking at runtime PC's from a stack trace, be aware that on most systems these days programs are position-independent, so there will be an offset between the addresses in the binary and the addresses from the stack trace. I don't know offhand of a standard way to figure out that offset. 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/CAOyqgcXQeaz_HuwDbrBdLmwOaL4XP2aig21118Woy8dDv_21mA%40mail.gmail.com.