In my C program, I have an instruction pointer that points to some address in virtual memory, e.g., a function pointer. I would like to map this address to the corresponding source location (file path, line number) using the debug information in the executed binary at runtime. I know that GDB implements something like this, but am unsure how to approach this for my project.
I'm aware of addr2line and llvm-symbolizer, but both of those tools analyze addresses in ELF files, not binaries that are already loaded into virtual memory.
Similarly, this is not a duplicate of How do I access the addr2line
functionality within my C++ program?
Thanks to Yakov Galka's comment, I found a solution for what I want to do:
Then, I can call
addr2line
to determine the source location. In my case, everything is liked intoa.out
, so I can just callwhich then prints something like: