Subject: Re: sanity checking arguments to library functions...
To: Brian C. Grayson <bgrayson@marvin.ece.utexas.edu>
From: Simon Burge <simonb@netbsd.org>
List: tech-userlevel
Date: 04/17/1999 21:17:39
"Brian C. Grayson" wrote:

> On Fri, Apr 16, 1999 at 10:53:29AM -0700, Ross Harvey wrote:
> > If the thing works by using gcc builtins like:
> > 
> >         __builtin_return_address(frameno)
> > 
> > Well...actually...that doesn't work on "any gcc/egcs-compiled program"
> > because the builtin isn't implemented on all architectures. (And, for  
> > those that it isn't implemented for, I don't think it errors out, so
> > you just get a run-time exception.)
> 
>   Do you know which NetBSD archs will choke?  It looks like it
> won't work on mips.

Seems ok on both Ultrix/MIPS and NetBSD/pmax.  This on NetBSD/pmax:

	mona:~ 56> cat > fofo.c
	main()
	{
		foo();
	}

	foo()
	{
		printf("__builtin_return_address(0): 0x%08x\n", __builtin_return_address(0));
		printf("__builtin_frame_address(0):  0x%08x\n", __builtin_frame_address(0));
		printf("__builtin_return_address(1): 0x%08x\n", __builtin_return_address(1)); /* line 10 */
		printf("__builtin_frame_address(1):  0x%08x\n", __builtin_frame_address(1));
	}
	mona:~ 57> cc -o fofo fofo.c
	fofo.c: In function `foo':
	fofo.c:10: warning: unsupported arg to `__builtin_return_address'
	mona:~ 58> ./fofo 
	__builtin_return_address(0): 0x00400ebc
	__builtin_frame_address(0):  0x7ffff620
	__builtin_return_address(1): 0x00000000
	__builtin_frame_address(1):  0x004010f0

Simon.