Mail Archives: djgpp/2003/11/28/12:29:55
"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 -