[fpc-devel] debugging exception handling in windows

Seth Grover sethdgrover at gmail.com
Mon Mar 22 15:32:41 CET 2010


I'm doing some win32 development (::shudder:: ;-)) and am trying to
take a closer look at the way fatal exceptions (floating point
exceptions, access violations, etc.) are handled as I try to figure
out a way around the limitations described in mantis issue #12974.
I've got fpc compiled and installed with debugging information and am
successfully able to step through the RTL code in GDB.

I've got a very simple main program: I'm not even to the point where
I'm experimenting with .dll's yet. All the main program does is cause
a FPE inside a try/except block. When I run the program, I'm able to
see, of course, that the exception is caught/handled in my except

However, when I get GDB involved, things get strange. I would like to
debug into syswin32_i386_exception_handler step through it. Here's
what happened in GDB:

$ gdb ./project1.exe
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) break fpc_raiseexception
Breakpoint 1 at 0x4081b5: file
C:/cygwin/home/nitrodev/fpc-2.4.0/rtl/inc/except.inc, line 195.
Breakpoint 2 at 0x40d9e6: file system.pp, line 694.
(gdb) r
Starting program: c:\tmp/./project1.exe
Loaded symbols for C:\WINNT\system32\KERNEL32.DLL
Loaded symbols for C:\WINNT\system32\OLEAUT32.DLL
Loaded symbols for C:\WINNT\system32\OLE32.DLL
Loaded symbols for C:\WINNT\system32\rpcrt4.dll
Loaded symbols for C:\WINNT\system32\ADVAPI32.DLL
Loaded symbols for C:\WINNT\system32\GDI32.DLL
Loaded symbols for C:\WINNT\system32\USER32.DLL

Program received signal SIGFPE, Arithmetic exception.
0x00401526 in main () at project1.lpr:14
14          d := 5.0 / d;
(gdb) c

Program received signal SIGFPE, Arithmetic exception.
0x00401526 in main () at project1.lpr:14
14          d := 5.0 / d;
(gdb) c

Program exited with code 0200.

So, I'm able to set the breakpoint at SYSWIN32_I386_EXCEPTION_HANDLER.
However, when the program runs, for some reason GDB seems to see the
SIGFPE exception twice (?), and then the program never stops inside
SYSWIN32_I386_EXCEPTION_HANDLER for me to step through it.

Can somebody with more experience debugging under windows tell me
what's going on? What's with GDB seeing the same exception twice? Why
won't it stop inside syswin32_i386_exception_handler? I assume
something Windows is doing to catch the exception and pass it on to
the program is at odds with the way GDB tries to report it, but I
don't know enough about exception handling in Windows yet to try to
guess what it would be and what I can do about it, if anything.

Any thoughts?



This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.

Seth Grover

More information about the fpc-devel mailing list