Reputation: 14505
There is this way of retrieving a stack trace on MS windows: http://msdn.microsoft.com/en-us/library/windows/desktop/bb204633%28v=vs.85%29.aspx
I tried to implement this in my application (which doesn't run on Windows only) using this:
#elif defined HUGGLE_WIN
result = "";
unsigned int i;
void *stack[HUGGLE_STACK];
unsigned short frames;
SYMBOL_INFO *symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize( process, NULL, TRUE );
frames = CaptureStackBackTrace( 0, HUGGLE_STACK, stack, NULL );
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
for( i = 0; i < frames; i++ )
{
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
QString symbol_name = "unknown symbol";
if (!QString(symbol->Name).isEmpty())
symbol_name = QString(symbol->Name);
result += QString(QString::number(frames - i - 1) + QString(" ") + symbol_name + QString(" 0x") +
QString::number(symbol->Address, 16) + QString("\n"));
}
free( symbol );
#else
however, despite this "works" I get symbol names for 3rd libraries only, and not for my own functions that are in my application, despite I see frames for them. These have empty symbols and addr 0x0, see example output:
34 unknown symbol 0x0
33 unknown symbol 0x0
32 unknown symbol 0x0
31 unknown symbol 0x0
30 unknown symbol 0x0
29 ZN11QMetaObject8activateEP7QObjectiiPPv 0x6b954a50
28 ZN11QMetaObject8activateEP7QObjectPKS_iPPv 0x6b95495e
27 ZN6QTimer7timeoutENS_14QPrivateSignalE 0x6b9ad018
26 ZN6QTimer10timerEventEP11QTimerEvent 0x6b9588ea
25 ZN7QObject5eventEP6QEvent 0x6b94f3fc
24 ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent 0x2259ddfe
23 ZN12QApplication6notifyEP7QObjectP6QEvent 0x2259b4a4
22 ZN12QApplication6notifyEP7QObjectP6QEvent 0x2259b4a4
21 ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent 0x6b929e6c
20 ZN16QCoreApplication9sendEventEP7QObjectP6QEvent 0x6b9cf5ac
19 ZN28QEventDispatcherWin32Private14sendTimerEventEi 0x6b97904c
18 ZN28QEventDispatcherWin32Private21activateEventNotifierEP17QWinEventNotifier 0x6b978260
17 gapfnScSendMessage 0x76305fc8
16 GetThreadDesktop 0x76306c63
15 CharPrevW 0x7630768c
14 DispatchMessageW 0x7630787b
13 ZN21QEventDispatcherWin3213processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE 0x6b979682
12 ZN21QEventDispatcherWin3213processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE 0x6b979682
11 ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE 0x6b927f3c
10 ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE 0x6b9280ec
9 ZN16QCoreApplication4execEv 0x6b92a3dc
8 ZN15QGuiApplication4execEv 0x4606506
7 ZN12QApplication4execEv 0x2259b34a
6 ZN12QApplication4execEv 0x2259b34a
5 ZN12QApplication4execEv 0x2259b34a
4 ZN12QApplication4execEv 0x2259b34a
3 ZN12QApplication4execEv 0x2259b34a
2 BaseThreadInitThunk 0x76633378
1 RtlInitializeExceptionChain 0x778dbecf
0 RtlInitializeExceptionChain 0x778dbecf
these 5 unknowns are my function from my program. Why I don't see them?
Upvotes: 1
Views: 3934
Reputation: 971
Note that symbol resolution from MS DbgHelp.dll probable won't work for gcc (MinGW) programs. GCC tools come with a separate tool "addr2line" that should help here.
What you've got so far for the Qt-DLLs are the exported symbols only. Only for the native Windows-DLLs the unmangled symbols are visible. Does your program export symbols? (E.g. an exe usually doesn't export symbols.) You can also try to move your code to a DLL with exported symbols to at least see these - mangled though.
Also show us the content of stack[i] in the output.
Upvotes: 1