From 337c4ccf011eef6b9a5924142457d1c34a75e5f3 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Thu, 23 Apr 2015 22:54:45 +0200 Subject: [PATCH] kernel debugger: Use memcpy for stack trace on kernel stack. If it was already determined that the memory is within the kernel stack, a simple memcpy is enough. This allows capturing kernel stack traces in situations where a fault handler cannot be installed (i.e. where one is already installed). --- src/system/kernel/arch/x86/arch_debug.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_debug.cpp b/src/system/kernel/arch/x86/arch_debug.cpp index 654dac2d0f..c15750db9d 100644 --- a/src/system/kernel/arch/x86/arch_debug.cpp +++ b/src/system/kernel/arch/x86/arch_debug.cpp @@ -63,11 +63,14 @@ already_visited(addr_t* visited, int32* _last, int32* _num, addr_t bp) /*! Safe to be called only from outside the debugger. */ static status_t -get_next_frame_no_debugger(addr_t bp, addr_t* _next, addr_t* _ip) +get_next_frame_no_debugger(addr_t bp, addr_t* _next, addr_t* _ip, + bool onKernelStack) { // TODO: Do this more efficiently in assembly. stack_frame frame; - if (user_memcpy(&frame, (void*)bp, sizeof(frame)) != B_OK) + if (onKernelStack) + memcpy(&frame, (void*)bp, sizeof(frame)); + else if (user_memcpy(&frame, (void*)bp, sizeof(frame)) != B_OK) return B_BAD_ADDRESS; *_ip = frame.return_address; @@ -1089,7 +1092,7 @@ arch_debug_contains_call(Thread* thread, const char* symbol, addr_t start, } else { addr_t ip, nextBp; - if (get_next_frame_no_debugger(bp, &nextBp, &ip) != B_OK + if (get_next_frame_no_debugger(bp, &nextBp, &ip, true) != B_OK || ip == 0 || bp == 0) break; @@ -1159,8 +1162,10 @@ arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, skipFrames = 0; } } else { - if (get_next_frame_no_debugger(bp, &nextBp, &ip) != B_OK) + if (get_next_frame_no_debugger(bp, &nextBp, &ip, + onKernelStack) != B_OK) { break; + } } if (skipFrames <= 0