// D import file generated from '../../../../gcc-4.6.1/libphobos/libdruntime/core/sys/windows/stacktrace.d'
module core.sys.windows.stacktrace;
version (Windows)
{
    import core.demangle;
    import core.runtime;
    import core.stdc.stdlib;
    import core.stdc.string;
    import core.sys.windows.dbghelp;
    import core.sys.windows.windows;
    debug (PRINTF)
{
    import core.stdc.stdio;
}
    extern (Windows) void RtlCaptureContext(CONTEXT* ContextRecord);

    private immutable __gshared bool initialized;


    class StackTrace : Throwable.TraceInfo
{
    public 
{
    this()
{
if (initialized)
m_trace = trace();
}
    const int opApply(scope int delegate(ref const(char[])) dg);
    const int opApply(scope int delegate(ref size_t, ref const(char[])) dg);
    override @safe const pure nothrow string toString();

    private 
{
    char[][] m_trace;
    static char[][] trace();

    static char[][] traceNoSync();

    static char[] formatStackFrame(void* pc)
{
import core.stdc.stdio : snprintf;
char[2 + 2 * size_t.sizeof + 1] buf = void;
immutable len = snprintf(buf.ptr,buf.length,"0x%p",pc);
len < buf.length || assert(0);
return buf[0..len].dup;
}

    static char[] formatStackFrame(void* pc, char* symName)
{
char[2048] demangleBuf = void;
auto res = formatStackFrame(pc);
res ~= " in ";
res ~= demangle(symName[0..strlen(symName)],demangleBuf);
return res;
}

    static char[] formatStackFrame(void* pc, char* symName, in char* fileName, uint lineNum)
{
import core.stdc.stdio : snprintf;
char[11] buf = void;
auto res = formatStackFrame(pc,symName);
res ~= " at ";
res ~= fileName[0..strlen(fileName)];
res ~= "(";
immutable len = snprintf(buf.ptr,buf.length,"%u",lineNum);
len < buf.length || assert(0);
res ~= buf[0..len];
res ~= ")";
return res;
}

}
}
}
    extern (Windows) BOOL FixupDebugHeader(HANDLE hProcess, ULONG ActionCode, ulong CallbackContext, ulong UserContext);

    shared static this();
}
