How can I get a backtrace on segfault?
Steven Schveighoffer
schveiguy at yahoo.com
Wed Sep 14 05:15:45 PDT 2011
On Wed, 14 Sep 2011 05:55:48 -0400, Alex Rønne Petersen
<xtzgzorex at gmail.com> wrote:
> On 14-09-2011 11:47, Jonathan M Davis wrote:
>> On Wednesday, September 14, 2011 10:38:38 Tobias Pankrath wrote:
>>>> What OS are you on? On 32-bit Linux, it should just work. On 64-bit
>>>
>>> Linux,
>>>
>>>> there's a bug which makes it so that you don't get one. If you're on
>>>> Windows (which I'm guessing that you're not since you're talking about
>>>> segfaults rather than access violations), then I believe that it
>>>> should
>>>> just work, but there might be something that you have to do to get it
>>>
>>> to
>>>
>>>> work (I don't use Windows much, so I'm not sure).
>>>>
>>>> - Jonathan M Davis
>>>
>>> 64 bit linux :-(. Thank you for your fast response.
>>
>> Actually. wait. I wasn't thinking right. You never get a backtrace from
>> a
>> segfault. There _is_ a bug on 64-bit Linux which makes it so that
>> backtraces
>> don't work, but you don't get a stacktrace from a segfault regardless.
>> The way
>> to handle that is to get a core dump and use gdb on it. However,
>> unfortunately, 64-bit programs generated by dmd don't seem to be work
>> with gdb
>> (though 32-bit programs will). It's a result of the fact that 64-bit
>> support
>> for dmd is pretty new. Still, they're annoying bugs.
>>
>> In any case, the best way to handle your problem would probably be to
>> compile
>> your program as 32-bit, run it with core dumps enabled, and use gdb on
>> it.
>> That should show you where the problem is unless the segfault is 64-bit
>> specific for some reason.
>>
>> - Jonathan M Davis
>
> As an aside, I still think DMD needs an option to insert null checks
> everywhere, at least for debugging...
That would not fix this problem (stack overflow).
I hazard to guess that stack overflow likely would not produce a helpful
stack trace either, but maybe I'm wrong.
In any case, have you tried this? Works on unixen only.
import core.stdc.signal;
extern(C) void handleSegv(int) { assert(0); }
void main()
{
signal(SIGSEGV, &handleSegv);
...
}
Not sure if it prints a stack trace on a stack overflow, however.
-Steve
More information about the Digitalmars-d-learn
mailing list