[Issue 1001] print stack trace (in debug mode) when program die

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 4 16:38:12 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=1001



--- Comment #8 from Sean Kelly <sean at invisibleduck.org> 2010-02-04 16:38:11 PST ---
printstack doesn't exist on OSX, so it has to be faked there (which is pretty
easy to do).  The only trick is that the stack trace integration is line-based
using opApply, so on platforms where backtrace isn't available, the trace
should really be output to a buffer and then parsed for opApply output.  This
might not be possible with printstack though.  In any case, here's some code
I've used to mimic printstack on OSX.  The backtrace_symbols call is what I'd
use for opApply, since it's pretty much exactly what's needed.  If I remember
correctly, backtrace is just a wrapper for some of the stuff in <ucontext.h>.

#if defined(sun) || defined(__sun) || defined(_sun_) || defined(__solaris__)
#   include <ucontext.h>
#elif defined(__APPLE__)
#   include <execinfo.h>

    int printstack( int fd )
    {
        void* callstack[128];
        int   frames = backtrace( callstack, 128 );
        backtrace_symbols_fd( callstack, frames, fd );

        /*
        char** strs = backtrace_symbols( callstack, frames );
        for( i = 0; i < frames; ++i )
        {
            fprintf( fd, "%s\n", strs[i] );
        }
        free( strs );
        */
        return 0;
    }
#else
    int printstack( int fd )
    {
        return 0;
    }
#endif

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list