问题
I need to get the information provided by addr2line (file and line from backtracing a function call) from within a C++ program. Is there a library call similar to addr2line?
edit: I am working in a Linux environment.
I know I can call addr2line directly and I know that I can use the source code of addr2line in my program (which is also GPL licensed). But I guess calling a library function, if it exists, is cleaner.
edit: I will use bfd of the binutils, just as addr2line does. What does bfd mean anyway?
回答1:
You can try the function dladdr()
. It uses the dynamic symbols of the program, not the debugging information (compile the program with gcc -rdynamic
).
Also, you can check the backtrace library, or the higher level stacktrace library.
Not exactly what you are asking, but they may prove useful.
回答2:
Check the source code of bsd implementation of addr2line, it has only about 400 lines code. Change the source to a library function should be very easy. http://sourceforge.net/apps/trac/elftoolchain/browser/trunk/addr2line/addr2line.c
来源:https://stackoverflow.com/questions/11556321/is-there-a-library-call-to-addr2line