Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-03

hot to handle SIGFPE, SIGSEGV using gdb as debugger

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Ishenin

Hello, FPC developers' list

I attached a simple program which handles division by zero (EDivByZero) exception and writes to the console when this happen. Run without debugger gives next output:
Exception is handled
1

When I run it with gdb I cannot continue usual execution after SIGFPE happen.

(gdb) run
Starting program:
C:\programming\mytest\debugger_exceptions/test_exception.exe [New thread 6100.0x13e4]

Program received signal SIGFPE, Arithmetic exception. 0x00401502 in EXCEPTION1 () at test_exception.lpr:15 15 a := a div (a - 1); // EDivByZero
(gdb) continue
Continuing.

Program received signal SIGFPE, Arithmetic exception. 0x00401502 in EXCEPTION1 () at test_exception.lpr:15 15 a := a div (a - 1); // EDivByZero
(gdb) continue
Continuing.

Program exited with code 030000000224.

Ok, tried "info signals" and found that gdb handles SIGFPE. I changed behavior:

(gdb) handle SIGFPE noprint
Signal Stop Print Pass to program Description SIGFPE No No Yes Arithmetic exception (gdb) handle SIGFPE nostop
Signal Stop Print Pass to program Description SIGFPE No No Yes Arithmetic exception (gdb) run
Starting program:
C:\programming\mytest\debugger_exceptions/test_exception.exe [New thread 5912.0xa3c]

Program exited with code 030000000224.

No luck :(

The same thing with SIGSEGV (look at Exception2 procedure).

Best regards,
Paul Ishenin.

Reply by email

Jonas Maebe
to Paul Ishenin
Paul Ishenin wrote 17 lines
Ok, tried "info signals" and found that gdb handles SIGFPE. I changed behavior: (gdb) handle SIGFPE noprint Signal Stop Print Pass to program Description SIGFPE No No Yes Arithmetic exception (gdb) handle SIGFPE nostop Signal Stop Print Pass to program Description SIGFPE No No Yes Arithmetic exception (gdb) run Starting program: C:\programming\mytest\debugger_exceptions/ test_exception.exe [New thread 5912.0xa3c] Program exited with code 030000000224. No luck :(

File a bug against gdb, it should work (it works under Mac OS X and Linux). The gdb bug repository is at http://sourceware.org/gdb/bugs/

Jonas

Reply by email

Paul Ishenin
to Jonas Maebe
Jonas Maebe wrote 23 lines
On 25 Mar 2009, at 14:01, Paul Ishenin wrote: > Ok, tried "info signals" and found that gdb handles SIGFPE. I changed > behavior: > > (gdb) handle SIGFPE noprint > Signal Stop Print Pass to program Description > SIGFPE No No Yes Arithmetic exception > (gdb) handle SIGFPE nostop > Signal Stop Print Pass to program Description > SIGFPE No No Yes Arithmetic exception > (gdb) run > Starting program: > C:\programming\mytest\debugger_exceptions/test_exception.exe > [New thread 5912.0xa3c] > > Program exited with code 030000000224. > > No luck :( File a bug against gdb, it should work (it works under Mac OS X and Linux). The gdb bug repository is at http://sourceware.org/gdb/bugs/

First I need to be sure that this is a gdb bug. Maybe fpc doing a bit different handling on osx and windows?

Jonas, can you write a small similar C++ test?

Best regards,
Paul Ishenin.

Reply by email

Jonas Maebe
to Paul Ishenin
Paul Ishenin wrote 7 lines
Jonas Maebe wrote: > > File a bug against gdb, it should work (it works under Mac OS X and > Linux). The gdb bug repository is at http://sourceware.org/gdb/bugs/ First I need to be sure that this is a gdb bug. Maybe fpc doing a bit different handling on osx and windows?

That is irrelevant:
a) it works without gdb
b) it doesn't work in gdb if you tell gdb to ignore all signal handlers

Just make sure you include a compiled program so that the gdb maintainers don't have to install FPC to test.

Jonas, can you write a small similar C++ test?

No, because
a) the C++ exception handling system does *not* automatically catch OS or hardware exceptions, it only catches exceptions raised by C++ code (so you need to write a hardware-exception-to-C++-exception conversion framework, similar to the code in our RTL for converting hardware/OS exceptions into Pascal exceptions)
b) I don't know how to catch signals under Windows (and am not interested at this time in learning low level Windows programming) c) my C++ knowledge/experience is extremely limited

A simple C program that triggers an FPU exception without installing any handlers, is of course easy (just make sure to compile it without optimizations, so the dead code is not removed):

int main()
{

   double a, b;
   a=1.0;
   b=0.0;
   a=a/b;
   return 0;
}

Jonas

Reply by email