Stacktraces in static constructors

Benjamin Thaut via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 4 02:31:52 PDT 2016


On Wednesday, 4 May 2016 at 06:37:28 UTC, Nordlöw wrote:
> On Tuesday, 3 May 2016 at 12:31:10 UTC, Benjamin Thaut wrote:
>> I assume this is on windows? Yes its a known issue (I know
>
> No, the problem occurs on my Linux aswell.

 From core.runtime:

static this()
{
     // NOTE: Some module ctors will run before this handler is 
set, so it's
     //       still possible the app could exit without a stack 
trace.  If
     //       this becomes an issue, the handler could be set in C 
main
     //       before the module ctors are run.
     Runtime.traceHandler = &defaultTraceHandler;
}

So a possible workaround would be to either import core.runtime 
in each of your modules or manually run the line 
Runtime.traceHandler = &defaultTraceHandler.
Also I find it strange that the trace handler is initialized in a 
regular module constructor. In my eyes it should be a shared 
module ctor because the storage behind Runtime.traceHandler is 
__gshared anyway.

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d-learn mailing list