[Dlang-internal] Dlang structured exception handling on Windows

Petar Petar
Mon Mar 19 19:34:05 UTC 2018


On Monday, 19 March 2018 at 18:39:30 UTC, KytoDragon wrote:
> I currently have a problem i don't know how to fix:
>
> Programms compiled in D (either compiler) have the annoying 
> property that they absorb all windows seh-exceptions, print the 
> error code and terminate the process.
>
> For example, the following programm will print "Program exited 
> with code -1073741819" and exit:
>
> module test.Test;
>
> void main() {
>     *cast(int*)cast(void*)0 = 1;
> }
>
> But what I expected was the following:
>
> https://imgur.com/LH8gUtt (translated for your language)
>
> The problem with this is, that this "feature" somehow even 
> manages to catch windows fail-fast exceptions, which are 
> supossed to bypass all exception handling (and debuggers!) and 
> go directly to WER (Windows Error Reporting). This makes it 
> impossible to debug these types of exceptions, as D nearly 
> silently swallows them. My questions are now:
>
> What exactly causes this behaviour? (e.q. which part of 
> druntime/phobos/dmd/ldc2)
> Is there a way to disable that?
> Has anybody an other solution?

I'm not familiar with the neither the implementation details nor 
why it swallows all SEH exceptions, but anyway here's a few 
starting points:
* most (all?) of the exception handling support code is in the 
druntime 'src/rt/' folder - look for files starting with 'deh', 
e.g. 
https://github.com/dlang/druntime/blob/master/src/rt/deh_win32.d 
for dmd -m32 (Digital Mars C runtime) and 
https://github.com/dlang/druntime/blob/master/src/rt/deh_win64_posix.d  for the rest of the dmd platform support
* additionally, LDC has a modified or completely reworked version 
of this:
https://github.com/ldc-developers/druntime/tree/ldc/src/rt
   * for example, for 1.7 LDC release there was significant work 
in this area, which among other things added C++ exception 
handling support: 
https://github.com/ldc-developers/ldc/pull/2405/files
   * If you see differences between the DMD and LDC behavior, the 
quickest way to get an answer is to post in their forums: 
https://forum.dlang.org/group/ldc, or on their issue tracker: 
https://github.com/ldc-developers/ldc/issues


More information about the Dlang-internal mailing list