*BSD News Article 87175


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!lucy.swin.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.mel.connect.com.au!news.syd.connect.com.au!phaedrus.kralizec.net.au!news.mel.aone.net.au!grumpy.fl.net.au!news.webspan.net!newsfeeds.sol.net!hammer.uoregon.edu!arclight.uoregon.edu!news.bbnplanet.com!su-news-hub1.bbnplanet.com!newsxfer3.itd.umich.edu!howland.erols.net!blackbush.xlink.net!news-kar1.dfn.de!news-stu1.dfn.de!news-mue1.dfn.de!news-nue1.dfn.de!news
-lei1.dfn.de!news-ber1.dfn.de!news-ham1.dfn.de!news-han1.dfn.de!news-koe1.dfn.de!main.Germany.EU.net!Dortmund.Germany.EU.net!interface-business.de!usenet
From: j@ida.interface-business.de (J Wunsch)
Newsgroups: comp.unix.bsd.netbsd.misc
Subject: Re: faulting address in signal handler
Date: 20 Jan 1997 16:54:22 GMT
Organization: interface business GmbH, Dresden
Lines: 61
Message-ID: <5c07vu$63c@innocence.interface-business.de>
References: <5bqspu$dnn@gummo.bbb.sub.org>
Reply-To: joerg_wunsch@interface-business.de (Joerg Wunsch)
NNTP-Posting-Host: ida.interface-business.de
X-Newsreader: knews 0.9.6
X-Phone: +49-351-31809-14
X-Fax: +49-351-3361187
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.netbsd.misc:5215

bertram@gummo.bbb.sub.org (Bertram Barth) wrote:

> I'm trying to compile yooda-1.2 (OODBMS) for NetBSD-1.2/i386.
> Within an signal-handler for SIGSEGV and SIGBUS I need to find
> the faulting address but I can't find it.
> 
> How can I access the faulting address within this signal-handler?

This is fairly system-dependant.  If your kernel pushes that
information on the signal stack, you could fetch it there.

The following crock seems to work on my FreeBSD system.  YMMV.  Note
that it contains several DONTs: it makes an assumption about the
parameters on the signal stack which doesn't need to be valid (hidden
in the obscure cast to struct sigframe *), and it performs stdio
actions inside the signal handler.

j@ida 790% cat foo.c
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <machine/frame.h>

void
sighandler(int signo)
{
	struct sigframe *sfp = (struct sigframe *)&signo;

	printf("Trap type %d at address %p, EIP %p\n", sfp->sf_code,
		sfp->sf_addr, sfp->sf_sc.sc_eip);
	exit(0);
}

int
main(void)
{
	char *p = (char *)0xdeadc0de;

	signal(SIGSEGV, sighandler);
	*p = 3;
	return 0;
}
j@ida 791% gcc -g foo.c
j@ida 792% gdb -q a.out
(gdb) run
Starting program: /var/tmp/a.out 

Program received signal SIGSEGV, Segmentation fault.
0x1674 in main () at foo.c:22
22		*p = 3;
(gdb) cont
Continuing.
Trap type 12 at address 0xdeadc0de, EIP 0x1674

Program exited normally.
(gdb) quit

-- 
J"org Wunsch					       Unix support engineer
joerg_wunsch@interface-business.de       http://www.interface-business.de/~j