Is there a library call to addr2line? [closed]

那年仲夏 提交于 2019-12-30 01:54:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!