[DRWTSN32] Implement arm context reading

CORE-17605 CORE-17604
This commit is contained in:
Mark Jansen 2021-06-05 22:13:22 +02:00
parent f028ca5b08
commit 1f44552d36
4 changed files with 51 additions and 19 deletions

View file

@ -2,7 +2,7 @@
* PROJECT: Dr. Watson crash reporter * PROJECT: Dr. Watson crash reporter
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Debug loop * PURPOSE: Debug loop
* COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org) * COPYRIGHT: Copyright 2017 Mark Jansen <mark.jansen@reactos.org>
*/ */
#include "precomp.h" #include "precomp.h"

View file

@ -2,7 +2,7 @@
* PROJECT: Dr. Watson crash reporter * PROJECT: Dr. Watson crash reporter
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Entrypoint / main print function * PURPOSE: Entrypoint / main print function
* COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org) * COPYRIGHT: Copyright 2017 Mark Jansen <mark.jansen@reactos.org>
*/ */
#include "precomp.h" #include "precomp.h"
@ -62,10 +62,15 @@ static void PrintThread(FILE* output, DumpData& data, DWORD tid, ThreadData& thr
xfprintf(output, "eax:%p ebx:%p ecx:%p edx:%p esi:%p edi:%p" NEWLINE, xfprintf(output, "eax:%p ebx:%p ecx:%p edx:%p esi:%p edi:%p" NEWLINE,
ctx.Eax, ctx.Ebx, ctx.Ecx, ctx.Edx, ctx.Esi, ctx.Edi); ctx.Eax, ctx.Ebx, ctx.Ecx, ctx.Edx, ctx.Esi, ctx.Edi);
#elif defined(_M_AMD64) #elif defined(_M_AMD64)
xfprintf(output, "rax:%p rbx:%p rcx:%p rdx:%p rsi:%p rdi:%p" NEWLINE, xfprintf(output, "rax:%p rbx:%p rcx:%p rdx:%p rsi:%p rdi:%p rbp:%p rsp:%p" NEWLINE,
ctx.Rax, ctx.Rbx, ctx.Rcx, ctx.Rdx, ctx.Rsi, ctx.Rdi); ctx.Rax, ctx.Rbx, ctx.Rcx, ctx.Rdx, ctx.Rsi, ctx.Rdi, ctx.Rbp, ctx.Rsp);
xfprintf(output, "r8:%p r9:%p r10:%p r11:%p r12:%p r13:%p r14:%p r15:%p" NEWLINE, xfprintf(output, "r8:%p r9:%p r10:%p r11:%p r12:%p r13:%p r14:%p r15:%p" NEWLINE,
ctx.R8, ctx.R9, ctx.R10, ctx.R11, ctx.R12, ctx.R13, ctx.R14, ctx.R15); ctx.R8, ctx.R9, ctx.R10, ctx.R11, ctx.R12, ctx.R13, ctx.R14, ctx.R15);
#elif defined(_M_ARM)
xfprintf(output, "r0:%p r1:%p r2:%p r3:%p r4:%p r5:%p r6:%p" NEWLINE,
ctx.R0, ctx.R1, ctx.R2, ctx.R3, ctx.R4, ctx.R5, ctx.R6);
xfprintf(output, "r7:%p r8:%p r9:%p r10:%p r11:%p r12:%p" NEWLINE,
ctx.R7, ctx.R8, ctx.R9, ctx.R10, ctx.R11, ctx.R12);
#else #else
#error Unknown architecture #error Unknown architecture
#endif #endif
@ -79,6 +84,9 @@ static void PrintThread(FILE* output, DumpData& data, DWORD tid, ThreadData& thr
#elif defined(_M_AMD64) #elif defined(_M_AMD64)
xfprintf(output, "rip:%p rsp:%p rbp:%p" NEWLINE, xfprintf(output, "rip:%p rsp:%p rbp:%p" NEWLINE,
ctx.Rip, ctx.Rsp, ctx.Rbp); ctx.Rip, ctx.Rsp, ctx.Rbp);
#elif defined(_M_ARM)
xfprintf(output, "sp:%p lr:%p pc:%p cpsr:%p" NEWLINE,
ctx.Sp, ctx.Lr, ctx.Pc, ctx.Cpsr);
#else #else
#error Unknown architecture #error Unknown architecture
#endif #endif
@ -89,6 +97,16 @@ static void PrintThread(FILE* output, DumpData& data, DWORD tid, ThreadData& thr
#if defined(_M_IX86) || defined(_M_AMD64) #if defined(_M_IX86) || defined(_M_AMD64)
xfprintf(output, "dr0:%p dr1:%p dr2:%p dr3:%p dr6:%p dr7:%p" NEWLINE, xfprintf(output, "dr0:%p dr1:%p dr2:%p dr3:%p dr6:%p dr7:%p" NEWLINE,
ctx.Dr0, ctx.Dr1, ctx.Dr2, ctx.Dr3, ctx.Dr6, ctx.Dr7); ctx.Dr0, ctx.Dr1, ctx.Dr2, ctx.Dr3, ctx.Dr6, ctx.Dr7);
#elif defined(_M_ARM)
for (int n = 0; n < ARM_MAX_BREAKPOINTS; ++n)
xfprintf(output, "Bvr%d:%p%s", n, ctx.Bvr[n], ((n + 1) == ARM_MAX_BREAKPOINTS) ? NEWLINE : " ");
for (int n = 0; n < ARM_MAX_BREAKPOINTS; ++n)
xfprintf(output, "Bcr%d:%p%s", n, ctx.Bcr[n], ((n + 1) == ARM_MAX_BREAKPOINTS) ? NEWLINE : " ");
for (int n = 0; n < ARM_MAX_WATCHPOINTS; ++n)
xfprintf(output, "Wvr%d:%p%s", n, ctx.Wvr[n], ((n + 1) == ARM_MAX_WATCHPOINTS) ? NEWLINE : " ");
for (int n = 0; n < ARM_MAX_WATCHPOINTS; ++n)
xfprintf(output, "Wcr%d:%p%s", n, ctx.Wcr[n], ((n + 1) == ARM_MAX_WATCHPOINTS) ? NEWLINE : " ");
#else #else
#error Unknown architecture #error Unknown architecture
#endif #endif

View file

@ -2,7 +2,7 @@
* PROJECT: Dr. Watson crash reporter * PROJECT: Dr. Watson crash reporter
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Print a stacktrace * PURPOSE: Print a stacktrace
* COPYRIGHT: Copyright 2017,2018 Mark Jansen (mark.jansen@reactos.org) * COPYRIGHT: Copyright 2017,2018 Mark Jansen <mark.jansen@reactos.org>
*/ */
#include "precomp.h" #include "precomp.h"
@ -38,25 +38,37 @@ void PrintStackBacktrace(FILE* output, DumpData& data, ThreadData& thread)
DWORD MachineType; DWORD MachineType;
STACKFRAME64 StackFrame = { { 0 } }; STACKFRAME64 StackFrame = { { 0 } };
#ifdef _M_X64 StackFrame.AddrPC.Mode = AddrModeFlat;
StackFrame.AddrReturn.Mode = AddrModeFlat;
StackFrame.AddrFrame.Mode = AddrModeFlat;
StackFrame.AddrStack.Mode = AddrModeFlat;
StackFrame.AddrBStore.Mode = AddrModeFlat;
#if defined(_M_IX86)
MachineType = IMAGE_FILE_MACHINE_I386;
StackFrame.AddrPC.Offset = thread.Context.Eip;
StackFrame.AddrStack.Offset = thread.Context.Esp;
StackFrame.AddrFrame.Offset = thread.Context.Ebp;
#elif defined(_M_AMD64)
MachineType = IMAGE_FILE_MACHINE_AMD64; MachineType = IMAGE_FILE_MACHINE_AMD64;
StackFrame.AddrPC.Offset = thread.Context.Rip; StackFrame.AddrPC.Offset = thread.Context.Rip;
StackFrame.AddrPC.Mode = AddrModeFlat;
StackFrame.AddrStack.Offset = thread.Context.Rsp; StackFrame.AddrStack.Offset = thread.Context.Rsp;
StackFrame.AddrStack.Mode = AddrModeFlat;
StackFrame.AddrFrame.Offset = thread.Context.Rbp; StackFrame.AddrFrame.Offset = thread.Context.Rbp;
StackFrame.AddrFrame.Mode = AddrModeFlat; #elif defined(_M_ARM)
MachineType = IMAGE_FILE_MACHINE_ARMNT;
StackFrame.AddrPC.Offset = thread.Context.Pc;
StackFrame.AddrStack.Offset = thread.Context.Sp;
StackFrame.AddrFrame.Offset = thread.Context.R11;
#elif defined(_M_ARM64)
MachineType = IMAGE_FILE_MACHINE_ARM64;
StackFrame.AddrPC.Offset = thread.Context.Pc;
StackFrame.AddrStack.Offset = thread.Context.Sp;
StackFrame.AddrFrame.Offset = thread.Context.u.s.Fp;
#else #else
MachineType = IMAGE_FILE_MACHINE_I386; #error "Unknown architecture"
StackFrame.AddrPC.Offset = thread.Context.Eip;
StackFrame.AddrPC.Mode = AddrModeFlat;
StackFrame.AddrStack.Offset = thread.Context.Esp;
StackFrame.AddrStack.Mode = AddrModeFlat;
StackFrame.AddrFrame.Offset = thread.Context.Ebp;
StackFrame.AddrFrame.Mode = AddrModeFlat;
#endif #endif
#define STACKWALK_MAX_NAMELEN 512 #define STACKWALK_MAX_NAMELEN 512
char buf[sizeof(SYMBOL_INFO) + STACKWALK_MAX_NAMELEN] = {0}; char buf[sizeof(SYMBOL_INFO) + STACKWALK_MAX_NAMELEN] = {0};
SYMBOL_INFO* sym = (SYMBOL_INFO *)buf; SYMBOL_INFO* sym = (SYMBOL_INFO *)buf;
@ -64,7 +76,7 @@ void PrintStackBacktrace(FILE* output, DumpData& data, ThreadData& thread)
LONG RecursionDepth = 0; LONG RecursionDepth = 0;
sym->SizeOfStruct = sizeof(sym); sym->SizeOfStruct = sizeof(sym);
/* FIXME: dump x bytes at EIP here + disasm it! */ /* FIXME: dump x bytes at PC here + disasm it! */
xfprintf(output, NEWLINE "*----> Stack Back Trace <----*" NEWLINE NEWLINE); xfprintf(output, NEWLINE "*----> Stack Back Trace <----*" NEWLINE NEWLINE);
bool first = true; bool first = true;
@ -116,6 +128,8 @@ void PrintStackBacktrace(FILE* output, DumpData& data, ThreadData& thread)
ULONG_PTR stackPointer = thread.Context.Esp; ULONG_PTR stackPointer = thread.Context.Esp;
#elif defined(_M_AMD64) #elif defined(_M_AMD64)
ULONG_PTR stackPointer = thread.Context.Rsp; ULONG_PTR stackPointer = thread.Context.Rsp;
#elif defined(_M_ARM) || defined(_M_ARM64)
ULONG_PTR stackPointer = thread.Context.Sp;
#else #else
#error Unknown architecture #error Unknown architecture
#endif #endif

View file

@ -2,7 +2,7 @@
* PROJECT: Dr. Watson crash reporter * PROJECT: Dr. Watson crash reporter
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Output system info * PURPOSE: Output system info
* COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org) * COPYRIGHT: Copyright 2017 Mark Jansen <mark.jansen@reactos.org>
*/ */
#include "precomp.h" #include "precomp.h"