From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Eiler, James A." Newsgroups: gmane.os.tru64.managers Subject: SIGFPE and siginfo_t Date: Fri, 27 Jun 2003 23:51:26 -0400 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Trace: main.gmane.org 1056772360 14977 80.91.224.249 (28 Jun 2003 03:52:40 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 28 Jun 2003 03:52:40 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Sat Jun 28 05:52:37 2003 Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.22.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 19W6lQ-0003tA-00 for ; Sat, 28 Jun 2003 05:52:36 +0200 Original-Received: (qmail 6710 invoked by uid 5); 28 Jun 2003 03:52:40 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 6701 invoked by uid 49493); 28 Jun 2003 03:52:39 -0000 Original-Received: from James.Eiler@alcoa.com by sws1 by uid 49491 with qmail-scanner-1.14 (clamscan: 0.54. spamassassin: 2.50-cvs. Clear:SA:0(-1.7/5.0):. Processed in 4.102236 secs); 28 Jun 2003 03:52:39 -0000 Original-Received: from unknown (HELO emroute3.ornl.gov) (160.91.4.110) by 0 with SMTP; 28 Jun 2003 03:52:34 -0000 Original-Received: from emroute3.ornl.gov (localhost [127.0.0.1]) by emroute3.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HH6004SOARLGT@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 27 Jun 2003 23:52:33 -0400 (EDT) Original-Received: from NOAADC-MSW03.NOA.Alcoa.com (noaadc-msw03.noa.alcoa.com [147.154.9.220]) by emroute3.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HH600H9PAQRBK@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 27 Jun 2003 23:52:03 -0400 (EDT) Original-Received: from NOAADC-MXI02.NOA.Alcoa.com (unverified [147.154.9.24]) by NOAADC-MSW03.NOA.Alcoa.com (Content Technologies SMTPRS 4.3.6) with ESMTP id for ; Fri, 27 Jun 2003 23:51:31 -0400 Original-Received: by noaadc-mxi02.noa.alcoa.com with Internet Mail Service (5.5.2656.59) id ; Fri, 27 Jun 2003 23:51:31 -0400 Content-return: allowed Original-To: "tru64-unix-managers@ornl. gov \(E-mail\)" X-Mailer: Internet Mail Service (5.5.2656.59) Xref: main.gmane.org gmane.os.tru64.managers:4692 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:4692 Hi All, I apologize, but this is a bit long.... I'm running Tru64 UNIX, several versions (4.0G, 5.1A, 5.1B), various Patch Kits. I've got a C program that runs on all of these. This program is timer driven and reads analog input data and processes it. This program is fairly large and was written by numerous folks over a period of years. Occasionally, one or more of the analog input signals is zero. And when the program does a divide by zero, a SIGFPE is generated. We need this program to keep running, so I've put in a signal handler to process the SIGFPE signal. I know I'm doing a bad thing in the SIGFPE signal handler in that I'm doing an fprintf to stderr indicating that the program has done a divide by zero - but at least we know when the SIGFPE has been generated. But, we'd like to know which line of code is generating the error. If I took out the signal handler, I could very easily determine the exact line of code from the core file. But, like I said, we need to keep this program running.... I'm trying to use the siginfo_t structure that's described in Section 5.4, "Realtime Signal Handling", of the Guide to Realtime Programming. As I read it, when a SIGFPE is generated, siginfo_t should contain the address of the bad instruction in member si_addr. I've modified the example code from the section of the manual: > cat doit.c #include #include #include #include #include main() { pid_t pid; sigset_t newmask; int ii, jj; float fNum; struct sigaction action; void catchit(); sigemptyset(&newmask); sigaddset(&newmask, SIGFPE); action.sa_flags = SA_SIGINFO; action.sa_sigaction = catchit; if (sigaction(SIGFPE, &action, NULL) == -1) { perror("sigusr: sigaction"); _exit(1); } for( ii = 3; ii > -1; ii--) { fNum = 42.0 / (float) ii; } } void catchit(int signo, siginfo_t *info, void *extra) { int int_val = info->si_value.sival_int; printf("Signal %d, value %d received\n", signo, int_val); printf("si_addr = %d\n", info->si_addr ); fflush( stdout ); _exit(0); } I compile it, link it, and run it: > cc -g2 doit.c -lrt -o doit > ./doit Signal 8, value 0 received si_addr = 0 I would have thought si_addr should be something other than 0. If I step through the signal handler, I can see part of the address (see the ^^^^^ below): (ladebug) where >0 0x120001458 in catchit(signo=0x8, info=0x11fffbc98, extra=0x11fffbcf8) "doit .c":34 #1 0x3ff800d5af0 in __sigtramp(...) in /usr/shlib/libc.so #2 0x120001404 in main() "doit.c":29 ^^^^^^^^^^^ #3 0x1200012e8 in __start(...) in doit (ladebug) p *info struct siginfo { si_signo = 0x8; si_errno = 0x0; si_code = 0x3; _sifields = union { _sipad = [0] = 0x0,[1] = 0x0,[2] = 0x4,[3] = 0x0,[4] = 0x10,[5] = 0x0,[6] = 0x1,[7] = 0x0,[8] = 0xc0004900,[9] = 0x3ff,[10] = 0x0,[11] = 0x0,[12] = 0x2,[13] = 0x0,[14] = 0xe8ec3b2,[15] = 0x0,[16] = 0x1000,[17] = 0x0,[18] = 0x801fc548,[1 9] = 0x3ff,[20] = 0x0,[21] = 0x0,[22] = 0x0,[23] = 0x0,[24] = 0x20001404,[25] = ^^^^^^^^^^ 0x1,[26] = 0x8,[27] = 0x0; More (n if no)? Any help on this will be much appreciated! Thanks, Jim