<div>just to be clear, this is what i get:</div><div><br></div><div>0   test_stacktrace_sigint              0x0000000102e2f69f handleTermination + 35</div><div>1   libsystem_c.dylib                   0x00007fff919d794a _sigtramp + 26</div>
<div>2   ???                                 0x0000000000000005 0x0 + 5</div><div>3   test_stacktrace_sigint              0x0000000102e4c18d D2rt6dmain211_d_run_mainUiPPaPUAAaZiZi7runMainMFZv + 33</div><div><br></div><div>
iterm#2 is unreadable.</div><div><br></div><div><br></div><div class="gmail_quote">On Thu, Jun 6, 2013 at 2:50 PM, Timothee Cour <span dir="ltr"><<a href="mailto:thelastmammoth@gmail.com" target="_blank">thelastmammoth@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Great!<div>two issues (on OSX at least):</div><div><br></div><div>A)</div><div>it seems the top-most element of the call stack gets chopped off; eg in your code, the main_module.main symbol will not appear in the stack trace. </div>

<div>Any idea why or how to fix that? </div><div>Is that some inlining issue ? I tried with dmd -g, or -gs or -gc.</div><div>This can be annoying when the top-most function is a large function and it's not at all clear where the code stopped.</div>

<div><br></div><div>B)</div><div>there are no line numbers. I did a complex workaround by launching a process and calling atos to get those, but isn't there a better way?</div><div class="HOEnZb"><div class="h5"><div>
<br></div><div><br></div><div><br><div class="gmail_quote">
On Thu, Jun 6, 2013 at 8:44 AM, nazriel <span dir="ltr"><<a href="mailto:spam@dzfl.pl" target="_blank">spam@dzfl.pl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>On Wednesday, 5 June 2013 at 21:05:53 UTC, Timothee Cour wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
how do i get a stacktrace inside handleTermination?<br>
<br>
If not currently possible, could we have a compile flag that would enable<br>
this kind of feature? (making code slower would be OK, its an opt in<br>
feature)<br>
Ideally we'd also be able to walk up or down the stack trace (kind of what<br>
gdb would do, but I'd like to be able to do that without resorting to gdb,<br>
using a language/library solution)<br>
<br>
----<br>
<br>
import core.sys.posix.signal;<br>
import std.c.stdlib;<br>
import std.stdio;<br>
<br>
void main(string[] args)<br>
{<br>
        bsd_signal(SIGINT, &handleTermination);<br>
<br>
        while (true)<br>
        {<br>
<br>
        }<br>
}<br>
<br>
extern(C) void handleTermination(int signal)<br>
{<br>
        writefln("Caught signal: %s", signal);<br>
        exit(signal);<br>
}<br>
<br>
-----<br>
</blockquote>
<br></div></div>
You mean call stack?<br>
Maybe something like this:<br>
<a href="http://dpaste.dzfl.pl/99f217be" target="_blank">http://dpaste.dzfl.pl/99f217be</a><div><br>
<br>
---<br>
import core.sys.posix.signal;<br>
import std.c.stdlib;<br>
import std.stdio;<br></div>
import std.conv;<div><br>
<br>
void main(string[] args)<br>
{<br>
       bsd_signal(SIGINT, &handleTermination);<br>
<br>
       while (true)<br>
       {<br>
<br>
       }<br>
}<br>
<br>
extern(C) void handleTermination(int signal)<br>
{<br>
       writefln("Caught signal: %s", signal);<br></div>
       getTrace();<br>
       exit(signal);<br>
}<br>
<br>
extern (C) void* thread_stackBottom();<br>
extern (C) char** backtrace_symbols(void**, int size);<br>
<br>
void getTrace() {<br>
    void*[10] callstack;<br>
    void** stackTop;<br>
    void** stackBottom = cast(void**) thread_stackBottom();<br>
<br>
    asm {<br>
        mov [stackTop], RBP;<br>
    }<br>
<br>
    auto curr = stackTop;<br>
<br>
    size_t i;<br>
    for (i = 0; stackTop <= curr &&<br>
        curr < stackBottom && i < 10;)<br>
    {<br>
        callstack[i++] = *(curr+1);<br>
        curr = cast(void**) *curr;<br>
    }<br>
<br>
    auto ret = backtrace_symbols(callstack.<u></u>ptr, cast(int) i);<br>
    for (; i > 0; i--) {<br>
        writeln((*ret).to!string());<br>
        ret++;<br>
    }<br>
}<br>
---<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br>