digitalmars.D.learn - setAssertHandler (druntime) segfaults
- Lutger (19/19) Jul 24 2009 There is a function setAssertHandler in druntime, but when I try to use ...
- Jarrett Billingsley (9/28) Jul 24 2009 t
- Lutger (11/46) Jul 24 2009 Ok I tried. Funny thing, with -g enabled it doesn't segfault anymore.
- Jarrett Billingsley (7/52) Jul 24 2009 n
- Lutger (1/1) Jul 24 2009 http://d.puremagic.com/issues/show_bug.cgi?id=3208
There is a function setAssertHandler in druntime, but when I try to use it it segfaults. I'm not sure how it should be used, this is a complete example of what I try to do: import std.stdio; import core.exception; void handleAssertion(string file, size_t line, string msg = null) { writefln("assert in %s at line %s", file, line); }; static this() { setAssertHandler( &handleAssertion ); } unittest { assert(false); } void main() {} output: assert in test at line 16 Segmentation fault This is with dmd 2.031 on linux. Is this a bug, am I doing something wrong?
Jul 24 2009
On Fri, Jul 24, 2009 at 4:37 PM, Lutger<lutger.blijdestijn gmail.com> wrote= :There is a function setAssertHandler in druntime, but when I try to use i=tit segfaults. I'm not sure how it should be used, this is a complete exam=pleof what I try to do: import std.stdio; import core.exception; void handleAssertion(string file, size_t line, string msg =3D null) { =A0 =A0writefln("assert in %s at line %s", file, line); }; static this() { =A0 =A0setAssertHandler( &handleAssertion =A0); } unittest { assert(false); } void main() {} output: assert in test at line 16 Segmentation fault This is with dmd 2.031 on linux. Is this a bug, am I doing something wron=g? Hm, it might - and I'm just taking a wild guess here - be that std.stdio hasn't yet been initialized when you do the writefln in your assertion handler. But you really should try using a debugger to get a stacktrace.
Jul 24 2009
Jarrett Billingsley wrote:On Fri, Jul 24, 2009 at 4:37 PM, Lutger<lutger.blijdestijn gmail.com> wrote:Ok I tried. Funny thing, with -g enabled it doesn't segfault anymore. Without -g, the trace is not intelligible to me. Segfault also occurs when commenting out writefln. This is useless I assume but anyway, this is what gdb gives me: Backtrace stopped: previous frame inner to this frame (corrupt stack?)There is a function setAssertHandler in druntime, but when I try to use it it segfaults. I'm not sure how it should be used, this is a complete example of what I try to do: import std.stdio; import core.exception; void handleAssertion(string file, size_t line, string msg = null) { writefln("assert in %s at line %s", file, line); }; static this() { setAssertHandler( &handleAssertion ); } unittest { assert(false); } void main() {} output: assert in test at line 16 Segmentation fault This is with dmd 2.031 on linux. Is this a bug, am I doing something wrong?Hm, it might - and I'm just taking a wild guess here - be that std.stdio hasn't yet been initialized when you do the writefln in your assertion handler. But you really should try using a debugger to get a stacktrace.
Jul 24 2009
On Fri, Jul 24, 2009 at 5:46 PM, Lutger<lutger.blijdestijn gmail.com> wrote= :Jarrett Billingsley wrote:nOn Fri, Jul 24, 2009 at 4:37 PM, Lutger<lutger.blijdestijn gmail.com> wrote:Ok I tried. Funny thing, with -g enabled it doesn't segfault anymore. Without -g, the trace is not intelligible to me. Segfault also occurs whe=There is a function setAssertHandler in druntime, but when I try to use it it segfaults. I'm not sure how it should be used, this is a complete example of what I try to do: import std.stdio; import core.exception; void handleAssertion(string file, size_t line, string msg =3D null) { writefln("assert in %s at line %s", file, line); }; static this() { setAssertHandler( &handleAssertion =A0); } unittest { assert(false); } void main() {} output: assert in test at line 16 Segmentation fault This is with dmd 2.031 on linux. Is this a bug, am I doing something wrong?Hm, it might - and I'm just taking a wild guess here - be that std.stdio hasn't yet been initialized when you do the writefln in your assertion handler. =A0But you really should try using a debugger to get a stacktrace.commenting out writefln. This is useless I assume but anyway, this is what gdb gives me: Backtrace stopped: previous frame inner to this frame (corrupt stack?)I'm.. utterly at a loss. It seems that exiting the assertion handler by doing anything other than throwing an exception causes the segfault. And like you said, -g makes the problem disappear. I have no idea what's going on.
Jul 24 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3208
Jul 24 2009