From aa6633ca2157b686d5398e8a09f538c15089fd36 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 17 Nov 2022 10:35:52 +0100 Subject: [PATCH] Utils: improve assert stack printing on windows Ignore the two top level frames since those only contain the assert infrastructure and indent the stack to make it better distinguishible from the actual asserts. Change-Id: I7aaa4996de5f96404bd3766310a3ae07616fb705 Reviewed-by: Christian Stenger --- src/libs/utils/qtcassert.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/utils/qtcassert.cpp b/src/libs/utils/qtcassert.cpp index 65e39891f61..d8f07b736bd 100644 --- a/src/libs/utils/qtcassert.cpp +++ b/src/libs/utils/qtcassert.cpp @@ -64,7 +64,8 @@ void dumpBacktrace(int maxdepth) frame.AddrStack.Offset = ctx.Sp; frame.AddrFrame.Offset = ctx.Fp; #endif - int depth = 0; + // ignore the first two frames those contain only writeAssertLocation and dumpBacktrace + int depth = -3; static bool symbolsInitialized = false; if (!symbolsInitialized) { @@ -82,6 +83,8 @@ void dumpBacktrace(int maxdepth) &SymFunctionTableAccess64, &SymGetModuleBase64, NULL)) { + if (++depth < 0) + continue; char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); @@ -95,7 +98,7 @@ void dumpBacktrace(int maxdepth) IMAGEHLP_LINE64 lineInfo; SymSetOptions(SYMOPT_LOAD_LINES); - QString out = QString("%1: 0x%2 at %3") + QString out = QString(" %1: 0x%2 at %3") .arg(depth) .arg(QString::number(pSymbol->Address, 16)) .arg(QString::fromLatin1(&pSymbol->Name[0], pSymbol->NameLen)); @@ -105,7 +108,7 @@ void dumpBacktrace(int maxdepth) QString::number(lineInfo.LineNumber))); } qDebug().noquote() << out; - if (++depth == maxdepth) + if (depth == maxdepth) break; } mutex.unlock();