[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: problem with backtrace() after system update



On Wed, Jan 13, 2010 at 01:01:27PM +0100, Bartek 'BaSz' Szurgot wrote:
> Aurelien Jarno wrote:
> >Bartek 'BaSz' Szurgot a écrit :
> >>hi,
> >
> >Hi,
> >
> >>some time ago i wrote C++ code to save backtrace in a vector of
> >>strings. it worked fine until one of system updates (~month
> >>ago), when it suddenly started to show too short listening(s).
> >>i've tried example from manual (man backtrace) to verify this,
> >>and it does not work properly too. example output is:
> >>
> >>$ gcc -Wall -g3 -rdynamic main.c && ./a.out 10
> >>backtrace() returned 4 addresses
> >>./a.out(_Z7myfunc3v+0x1c) [0x400b28]
> >>./a.out [0x400ba9]
> >>./a.out(_Z6myfunci+0x23) [0x400bce]
> >>./a.out(_Z6myfunci+0x1c) [0x400bc7]
> >>
> >>where there should be >10 calls on stack. raising number given
> >>as an argument does not change output.
> >
> >What are the missing entries you expect?
> 
> in the man's example function myFunc() is recurrent. here it should be
> call 10 times. this is its body taken from man:
> void myfunc(int ncalls)
> {
>   if (ncalls > 1)
>     myfunc(ncalls - 1);
>   else
>     myfunc2();
> }
> 
> example output provided in man does show more calls to myFunc() (i.e. 3):
> 
> $ cc -rdynamic prog.c -o prog
> $ ./prog 3
> backtrace() returned 8 addresses
> ./prog(myfunc3+0x5c) [0x80487f0]
> ./prog [0x8048871]
> ./prog(myfunc+0x21) [0x8048894]
> ./prog(myfunc+0x1a) [0x804888d]
> ./prog(myfunc+0x1a) [0x804888d]
> ./prog(main+0x65) [0x80488fb]
> /lib/libc.so.6(__libc_start_main+0xdc) [0xb7e38f9c]
> ./prog [0x8048711]

gcc does tail-recursion optimization, hence in the previous code it's
normal to have a short backtrace.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org


Reply to: