getting the line of a function when walking the stack with libbfd

Vincent Torri vincent.torri@gmail.com
Mon Mar 19 18:03:00 GMT 2012


Hey

I'm writting a small tool that traces the stack, using libbfd. I've
found several programs [1] [2] [3] which are doing basically the same
thing :

1) initialize bfd, dbghelp and other stuff
2) call StackWalk()
3) for each frame, call bfd_find_nearest_line() to get the line, and
function and file names

But all of them do not find the correct line where the function is
called. It seems that the line is actually the one finishing the
function (that is a 'return' call or the closing curly bracket)

Is it normal (of course in bfd_find_nearest_line() name, there is
'nearest' ...) ?

Is there a solution to get the correct line where the function calls are done ?

thank you

Vincent Torri

[1] http://linuxgazette.net/151/misc/melinte/addr2line.c
[2] http://code.google.com/p/backtrace-mingw/source/browse/trunk/backtrace.c
[3] https://bitbucket.org/edd/stack_trace/src/0d266476cb67/src/stack.cpp



More information about the Binutils mailing list