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: Sat, 11 Nov 2000 19:51:36 +0000
> > From: Fernando Nasser <fnasser@cygnus.com>
> >
> > Someone said that heap corruption was harder to track than stack
> > corruption.
> >
> > I couldn't disagree more.  Many (most?) of the times the function tries
> > to return and gets a buggy return address and frame pointer.
> > It then crashes and you have no idea where it happened.

This is more in line with my personal experience.  Something gets
trashed in the heap and it is a fairly well defined mechanical process
to first script a reproducable sequence that triggers the event and
secondly script a debug sequence that watches for the corruption. 
Typically a few well placed watchpoints and a very long lunch (while it
runs :-) does the trick.

On the other hand applying such a technique to a stack corruption is far
more complicated.  The very nature of a stack is that it is constantly,
and _annonymously_ being reused.  Typically far more complex tracing
sequences are needed to capture the corruption in progress.

To look at it another way, all heap accesses are explict while the stack
may either be accessed explictly or implicitly through function
call/return.

	enjoy,
		Andrew

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