delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/11/28/12:29:55

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Message-ID: <0c4c01c3b5d5$22af6f50$0600000a@broadpark.no>
From: "Gisle Vanem" <giva AT bgnett DOT no>
To: <djgpp AT delorie DOT com>
References: <20031128114118 DOT 28353 DOT 00001166 AT mb-m11 DOT aol DOT com>
Subject: Re: general protection fault
Date: Fri, 28 Nov 2003 18:29:10 +0100
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Reply-To: djgpp AT delorie DOT com

"Sterten" <sterten AT aol DOT com> said:

> when I get a GPF with my compiled program (which happens quite often) ,
> then the whole screen is written full of GPF- information.
> 
> So everything, which was written before to the screen is overwritten.
> But I need these printouts for debugging.
> I doesn't help, when I redirect the output to a file, since DJGPP
> won't close the file, when the GPF occurs, so the file will be empty.
> 
> what can I do ?

Several things. The easiest is to redirect traceback to stderr:
  redir -e trace.fil buggy-prog 
or 
  buggy-prog >&> trace.fil
if you use 4DOS.

Don't mistake redir for Windows' redir (in \windows\system32).

Or you can write a handler for SIGSEGV/SIGILL/SIGFPE and
handle those errors more gracefully (close your files etc).
Something like:

void sigcatch (int sig)
{
  static int been_here = 0;
  static jmp_buf exc_buf;
  if (been_here)
  {
    signal (sig, SIG_DFL);
    __djgpp_exception_state_ptr = &exc_buf;
  }
  else   /* save context in case of reentry */
  {
    memcpy (&exc_buf, __djgpp_exception_state_ptr, sizeof(exc_buf));
    been_here = 1;
    /* do your critical stuff here. But as little as possible */
  }
  raise (SIGABRT);  /* this gives a nice traceback */
}

main ()
....
signal (SIGSEGV, sigcatch);
signal (SIGILL, sigcatch);
signal (SIGFPE, sigcatch);

The memcpy() is just a trick to get a traceback of the original
fault.

--gv

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019