Discussion:
[fpc-devel] hot to handle SIGFPE, SIGSEGV using gdb as debugger
Paul Ishenin
2009-03-25 13:01:31 UTC
Permalink
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.
Jonas Maebe
2009-03-25 13:08:44 UTC
Permalink
Post by Paul Ishenin
Ok, tried "info signals" and found that gdb handles SIGFPE. I
(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
Paul Ishenin
2009-03-25 13:14:44 UTC
Permalink
Post by Jonas Maebe
Post by Paul Ishenin
Ok, tried "info signals" and found that gdb handles SIGFPE. I changed
(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
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.
Jonas Maebe
2009-03-25 13:29:20 UTC
Permalink
Post by Paul Ishenin
Post by Jonas Maebe
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.
Post by Paul Ishenin
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
Paul Ishenin
2009-03-25 14:25:28 UTC
Permalink
Post by Jonas Maebe
Just make sure you include a compiled program so that the gdb
maintainers don't have to install FPC to test.
Sorry for annoyance. Please check whether I provide enough information
here: http://sourceware.org/bugzilla/show_bug.cgi?id=10004

Best regards,
Paul Ishenin.
Jonas Maebe
2009-03-25 14:44:27 UTC
Permalink
Post by Paul Ishenin
Post by Jonas Maebe
Just make sure you include a compiled program so that the gdb
maintainers don't have to install FPC to test.
Sorry for annoyance.
There was no annoyance from you, just from some things I have to do at
work currently.
Post by Paul Ishenin
Please check whether I provide enough information here: http://sourceware.org/bugzilla/show_bug.cgi?id=10004
Looks fine. I added myself in CC.


Jonas

Loading...