This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
getting the line of a function when walking the stack with libbfd
- From: Vincent Torri <vincent dot torri at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 19 Mar 2012 19:03:04 +0100
- Subject: getting the line of a function when walking the stack with libbfd
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