https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1fa4e5f29cdccc1a444f7…
commit 1fa4e5f29cdccc1a444f7118d42eb970d6165f6a
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sun Oct 21 14:46:44 2018 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Sun Oct 28 13:00:44 2018 +0100
[DRWTSN32] Improve stack dumping
---
base/applications/drwtsn32/stacktrace.cpp | 35 ++++++++++++++++++-------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/base/applications/drwtsn32/stacktrace.cpp
b/base/applications/drwtsn32/stacktrace.cpp
index 5c93f78834..0dbd5d06f4 100644
--- a/base/applications/drwtsn32/stacktrace.cpp
+++ b/base/applications/drwtsn32/stacktrace.cpp
@@ -2,12 +2,14 @@
* PROJECT: Dr. Watson crash reporter
* LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Print a stacktrace
- * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen(a)reactos.org)
+ * COPYRIGHT: Copyright 2017,2018 Mark Jansen (mark.jansen(a)reactos.org)
*/
#include "precomp.h"
#include <dbghelp.h>
+#define STACK_MAX_RECURSION_DEPTH 50
+
void BeginStackBacktrace(DumpData& data)
{
@@ -59,23 +61,28 @@ void PrintStackBacktrace(FILE* output, DumpData& data,
ThreadData& thread)
char buf[sizeof(SYMBOL_INFO) + STACKWALK_MAX_NAMELEN] = {0};
SYMBOL_INFO* sym = (SYMBOL_INFO *)buf;
IMAGEHLP_MODULE64 Module = { 0 };
+ LONG RecursionDepth = 0;
sym->SizeOfStruct = sizeof(sym);
- /* FIXME: Disasm function! */
+ /* FIXME: dump x bytes at EIP here + disasm it! */
xfprintf(output, NEWLINE "*----> Stack Back Trace <----*" NEWLINE
NEWLINE);
bool first = true;
- ULONG_PTR LastFrame = StackFrame.AddrFrame.Offset - 8;
- while(StackWalk64(MachineType, data.ProcessHandle, thread.Handle, &StackFrame,
&thread.Context,
- NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL))
+ while (StackWalk64(MachineType, data.ProcessHandle, thread.Handle, &StackFrame,
&thread.Context,
+ NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL))
{
- if (!StackFrame.AddrPC.Offset)
- break;
-
- if (LastFrame >= StackFrame.AddrFrame.Offset)
- break;
-
- LastFrame = StackFrame.AddrFrame.Offset;
+ if (StackFrame.AddrPC.Offset == StackFrame.AddrReturn.Offset)
+ {
+ if (RecursionDepth++ > STACK_MAX_RECURSION_DEPTH)
+ {
+ xfprintf(output, "- Aborting stackwalk -" NEWLINE);
+ break;
+ }
+ }
+ else
+ {
+ RecursionDepth = 0;
+ }
if (first)
{
@@ -85,7 +92,7 @@ void PrintStackBacktrace(FILE* output, DumpData& data,
ThreadData& thread)
Module.SizeOfStruct = sizeof(Module);
DWORD64 ModBase = SymGetModuleBase64(data.ProcessHandle,
StackFrame.AddrPC.Offset);
- if (!SymGetModuleInfo64(data.ProcessHandle, ModBase, &Module))
+ if (!ModBase || !SymGetModuleInfo64(data.ProcessHandle, ModBase, &Module))
strcpy(Module.ModuleName, "<nomod>");
memset(sym, '\0', sizeof(*sym) + STACKWALK_MAX_NAMELEN);
@@ -93,7 +100,7 @@ void PrintStackBacktrace(FILE* output, DumpData& data,
ThreadData& thread)
sym->MaxNameLen = STACKWALK_MAX_NAMELEN;
DWORD64 displacement;
- if (!SymFromAddr(data.ProcessHandle, StackFrame.AddrPC.Offset, &displacement,
sym))
+ if (!StackFrame.AddrPC.Offset || !SymFromAddr(data.ProcessHandle,
StackFrame.AddrPC.Offset, &displacement, sym))
strcpy(sym->Name, "<nosymbols>");
xfprintf(output, "%p %p %p %p %p %p %s!%s" NEWLINE,