Re: "catch" not catching the correct exception

2018-07-26 Thread kinke via Digitalmars-d

On Thursday, 26 July 2018 at 07:38:08 UTC, Shachar Shemesh wrote:

Mecca doesn't call that. Should it? Can that be the problem?


Very likely so. It's (normally) used in core.thread.Thread's 
push/popContext() when switching into a fiber.


Re: "catch" not catching the correct exception

2018-07-26 Thread Shachar Shemesh via Digitalmars-d

On 26/07/18 10:31, Seb wrote:

On Thursday, 26 July 2018 at 05:52:51 UTC, Shachar Shemesh wrote:
At which point I'm stuck. I don't know how D's catch matching works, 
so I don't know where to continue looking.


https://github.com/dlang/druntime/blob/master/src/rt/dwarfeh.d

You still use druntime, right?


Yes.

/
 * Called when fibers switch contexts.
 * Params:
 *  newContext = stack to switch to
 * Returns:
 *  previous value of stack
 */
extern(C) void* _d_eh_swapContextDwarf(void* newContext) nothrow @nogc
{
auto old = ExceptionHeader.stack;
ExceptionHeader.stack = cast(ExceptionHeader*)newContext;
return old;
}

Mecca doesn't call that. Should it? Can that be the problem?

Shachar


Re: "catch" not catching the correct exception

2018-07-26 Thread Shachar Shemesh via Digitalmars-d

On 26/07/18 09:22, rikki cattermole wrote:
Hmm, sounds like the vtable and hence TypeInfo part of the reference is 
getting corrupted.


Have you checked that the type matches where you throw it?


Is that what "classinfo" returns? Because if so, it's printed by the 
logs I pasted in my question, and is correct (and, in any case, shows 
that Exception is the parent).


Shachar


Re: "catch" not catching the correct exception

2018-07-26 Thread Seb via Digitalmars-d

On Thursday, 26 July 2018 at 05:52:51 UTC, Shachar Shemesh wrote:
At which point I'm stuck. I don't know how D's catch matching 
works, so I don't know where to continue looking.


https://github.com/dlang/druntime/blob/master/src/rt/dwarfeh.d

You still use druntime, right?


Re: "catch" not catching the correct exception

2018-07-26 Thread rikki cattermole via Digitalmars-d
Hmm, sounds like the vtable and hence TypeInfo part of the reference is 
getting corrupted.


Have you checked that the type matches where you throw it?


"catch" not catching the correct exception

2018-07-25 Thread Shachar Shemesh via Digitalmars-d

Under mecca, we're using GC free exceptions.

I have code that uses mkEx 
(https://github.com/weka-io/mecca/blob/master/src/mecca/lib/exception.d#L307). 
Essentially, it constructs an exception in place inside a fiber-local 
buffer. The construction code seems correct, and the parent seems set 
correctly (Exception).


When thrown, however, a catch for Exception does not catch it. It is 
caught if we try to catch Throwable, and also if we try to catch 
FiberInterrupt (a class deriving directly from Throwable).


Thinking the buffer might have gotten corrupted by one of the scope 
exits, I've added the following code:


catch (Exception ex) {
// Code that should have run goes here
}
catch(Throwable ex) {
META!"XXX NONONONONO caught %s of type %s son of 
%s"(cast(void*)ex, ex.classinfo.name, ex.classinfo.base.name);

LOG_EXCEPTION(ex);
throw ex;
}

When run, I get the following log:
META XXX NONONONONO caught 0x7F1C616F39B0 of type 
weka.bucket.exceptions.NotBucketLeader son of object.Exception



It seems immediately obvious that the problem is not with using a static 
buffer for the exception (at least, it does not seem to be corrupted), 
but something else. Somehow, the catch matching does not work.


At which point I'm stuck. I don't know how D's catch matching works, so 
I don't know where to continue looking.


The problem does not happen consistently, but does happen frequently 
enough for me to be able to reproduce it when needed.


I need suggestions on how to debug this.

Thank you,
Shachar