有这种方法可以在MS窗口上检索堆栈跟踪:http://msdn.microsoft.com/en-us/library/windows/desktop/bb204633%28v=vs.85%29.aspx
我尝试在我的应用程序中实现这一点(它不能仅在Windows上运行):
#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
然而,尽管如此,&#34;工作&#34;我只获得第三个库的符号名称,而不是我自己的应用程序中的函数,尽管我看到了它们的框架。它们有空符号和addr 0x0,参见示例输出:
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
这5个未知数是我的程序中的函数。为什么我不看他们?
答案 0 :(得分:0)
请注意,MS DbgHelp.dll可能的符号解析对gcc(MinGW)程序无效。 GCC工具附带了一个单独的工具“addr2line”,应该有所帮助。
到目前为止,Qt-DLL所得到的只是导出的符号。仅对于本机Windows-DLL,未显示的符号是可见的。 你的程序是否导出符号? (例如,exe通常不会导出符号。)您也可以尝试将代码移动到带有导出符号的DLL,至少可以看到这些 - 但是会被破坏。
还向我们展示输出中stack [i]的内容。