Re: Detecting endless recursion?

Fergus Henderson <fjh@cs.mu.oz.au>
12 Jan 2004 13:36:15 -0500

          From comp.compilers

Related articles
Detecting endless recursion? witness@t-online.de (Uli Kusterer) (2004-01-12)
Re: Detecting endless recursion? jmcenerney@austin.rr.com (John McEnerney) (2004-01-12)
Re: Detecting endless recursion? fjh@cs.mu.oz.au (Fergus Henderson) (2004-01-12)
Re: Detecting endless recursion? nmm1@cus.cam.ac.uk (2004-01-16)
Re: Detecting endless recursion? jgd@cix.co.uk (2004-01-16)
Re: Detecting endless recursion? derkgwen@HotPOP.com (Derk Gwen) (2004-01-16)
Re: Detecting endless recursion? torbenm@diku.dk (2004-01-16)
Re: Detecting endless recursion? witness@t-online.de (Uli Kusterer) (2004-01-16)
Re: Detecting endless recursion? witness@t-online.de (Uli Kusterer) (2004-01-16)
[24 later articles]
| List of all articles for this month |
From: Fergus Henderson <fjh@cs.mu.oz.au>
Newsgroups: comp.compilers
Date: 12 Jan 2004 13:36:15 -0500
Organization: Compilers Central
References: 04-01-050
Keywords: debug, practice
Posted-Date: 12 Jan 2004 13:36:15 EST

Uli Kusterer <witness@t-online.de> writes:


> The best suggestion I've been able to get from some mailing lists was
>to just put a limit on the size of my pseudo-stack and when that is
>exceeded raise an error. This is very straightforward and would be
>easy to implement (and I feel stupid for not thinking of this), but I
>have no idea how to determine this limit.


If you want to base the limit on the amount of memory your system has,
the GNU libiberty library, which is included with GCC (amongst
others), defines functions physmem_total() and physmem_available(),
with platform-specific implementations for a variety of different
systems. See
<http://savannah.gnu.org/cgi-bin/viewcvs/gcc/gcc/libiberty/physmem.c>.
Note that if you're going to follow this approach, you should also
take into account the process resource limits; see the man pages or
the Posix specification for the getrlimit() function.


>[The limit you one is one deeper than the deepest program that's not stuck
>in a loop. My impression is that other than artifical examples like
>Ackerman's function, real code doesn't nest very deeply so an arbitrary
>limit like 100 deep shoulddo the trick. -John]


It depends a lot on your programming style. 100 nesting levels is too
small for some programs. If you do have a fixed limit, make sure that
it can be increased without recompiling the program (e.g. allow the
user to set the limit from an environment variable or command-line
option).
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.