This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


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

Re: alloca is bad?


Eli Zaretskii wrote:
> 
> > Date: Sun, 12 Nov 2000 08:06:27 +0000
> > From: Fernando Nasser <fnasser@cygnus.com>
> >
> > The problem is that with a corrupted SP and FP you have no idea of where
> > it happened.  Doesn't matter if the crash was immediately after the fact,
> > all evidence of when it happened is wiped away.
> 
> ??? The core file will usually tell you the function in which it
> crashed, and sometimes the one which called it (if you are lucky).
> GDB doesn't need the stack information to tell you what function
> crashed, the value of $pc should be enough.  At least usually.
> 
> Or am I missing something?
> 

Yes you are.  As Andrew explained in his message, if the stack is
corrupted the PC and FP can (and probably will) be clobbered with
the garbage when the function returns.

No backtrace, core dump or anything in this world will tell you where
you were when this happens as all information has been obliterated.

The GDB where command works by following the chain of stack frames
by using the saved values of frame pointers (or equivalent mechanisms)
to walk up the stack and give you that nice printout.  Without a point
to start, no chain can be recreated.


Bottom line: for most stack corruption problems, no "where" ("backtrace")


-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9

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