This is the mail archive of the
mailing list for the binutils project.
Re: getting the line of a function when walking the stack with libbfd
On Tue, Mar 20, 2012 at 7:39 AM, Alan Modra <firstname.lastname@example.org> wrote:
> On Tue, Mar 20, 2012 at 05:39:08AM +0100, Vincent Torri wrote:
>> On Tue, Mar 20, 2012 at 5:33 AM, Alan Modra <email@example.com> wrote:
>> > On Mon, Mar 19, 2012 at 07:03:04PM +0100, Vincent Torri wrote:
>> >> 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)
>> > Does addr2line work?
>> I actually don't know how to use the addr2line program (I have to pass
>> an address and I don't know which value i have to use)
> Disassemble some of your binary with objdump to find call sites, plug
> in those addresses to addr2line. ?Experiment a little with other
> addresses near the calls.
ok, i'll try that. There's something I didn't mentioned (but you might
have guessed it) : the tool I'm writing is for Windows programs
compiled with MinGW. I already have something working with vc++.
Also, the code  and  are working like my tool (it's almost the
same code, anyway).
> There are many possibilites why your stack trace isn't giving you the
> lines you expect. ?eg.
> - You may not realise how stack traces work, ie. that they give
> ?return addresses, not call site addresses, or
that's quite possible :-) I've tried to write that tool by searching
examples on internet. But it's certainly possible to do what I want
as, for example, gdb is doing it (but is not using libbfd for stack
> - You may not have any line info in the binary, or
how can I check that ? Note that I compiled with -g, so I guess that I
have some debug info in my binary :)
> - The line info may be faulty, or
how can I check that ?
> - your binutils BFD may be buggy.
I've compiled the latest release of binutils and statically linked
libbfd to my tool.
Of course, I can provide the code (it's small, around 550 lines of
code), if you want to look at it :)