This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Tue, Mar 20, 2012 at 7:39 AM, Alan Modra <amodra@gmail.com> 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 <amodra@gmail.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.

I played a bit with objdump -S and addr2line seems to work.

My program:

[code]

#include <sw.h>

void fct(Sw *sw)
{
  sw_frames_get(sw, NULL, NULL);
}

int main()
{
  Sw *sw;

  sw = sw_init(NULL);     /* This is line 13 */
  fct(sw);
  /* fct2(sw); */

  sw_shutdown(sw);

  return 0;
}
[/code]

objdump -S sw;exe gives:

[code]
  Sw *sw;

  sw = sw_init(NULL);
  4016c1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  4016c8:	e8 2b 00 00 00       	call   4016f8 <_sw_init>
  4016cd:	89 44 24 1c          	mov    %eax,0x1c(%esp)
[/code]

and "addr2line 4016c1" returns line 13, which is the line where
sw_init() is called

Vincent Torri


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]