Is there a library call to addr2line?

steffen picture steffen · Jul 19, 2012 · Viewed 9.1k times · Source

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?

Answer

user416983 picture user416983 · Feb 28, 2013

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/p/elftoolchain/code/HEAD/tree/trunk/addr2line/addr2line.c