This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Catching stack overflow errors


Anthony Green <green@cygnus.com> writes:

> "Earl S. Harris, Jr." <esharris@mitre.org> writes:
> > I think this is important if the following conditions hold.
> > 
> > 1. A programmer wants to use non tail recursion in his/her C++ program.
> > 2. He/she doesn't want the program to crash inelegantly.
> 
> It is also important for other languages supported by GCC.  Java
> implementations are required to throw exceptions when a stack is blown
> but gcj currently ignores this.

There are some features in the development gcc that let you detect
stack overflows, if the usual OS signal-handling isn't robust enough
for you.  Look at the -fstack-limit-* options.  It has to be used in a
processor-specific way, but it does guarantee that you will get a
SIGTRAP _before_ the stack is expanded (rather than after all the
damage is done).  You can then catch the signal and deal with it by,
for instance, calling siglongjmp().
-- 
- Geoffrey Keating <geoffk@cygnus.com>

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