From 6d352d08b36bfeb5ae8fa5440e48fff02d910906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 25 May 2005 13:58:32 +0000 Subject: [PATCH] Added an arch_get_caller() function that returns the caller of the calling function :-) Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12810 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/arch/debug.h | 26 +++++++++++++++++---- src/system/kernel/arch/x86/arch_debug.c | 31 +++++++++++++++++++++---- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/headers/private/kernel/arch/debug.h b/headers/private/kernel/arch/debug.h index 4ad968ce6d..06398d5092 100644 --- a/headers/private/kernel/arch/debug.h +++ b/headers/private/kernel/arch/debug.h @@ -1,11 +1,29 @@ /* -** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ #ifndef _KERNEL_ARCH_DEBUG_H #define _KERNEL_ARCH_DEBUG_H -int arch_dbg_init(kernel_args *ka); + +#include + +struct kernel_args; + + +#ifdef __cplusplus +extern "C" { +#endif + +status_t arch_dbg_init(kernel_args *args); +void *arch_get_caller(void); void arch_dbg_save_registers(int *); +#ifdef __cplusplus +} +#endif + #endif /* _KERNEL_ARCH_DEBUG_H */ diff --git a/src/system/kernel/arch/x86/arch_debug.c b/src/system/kernel/arch/x86/arch_debug.c index 46c7d08bee..3b73922349 100644 --- a/src/system/kernel/arch/x86/arch_debug.c +++ b/src/system/kernel/arch/x86/arch_debug.c @@ -16,7 +16,12 @@ #include -#define NUM_PREVIOUS_LOCATIONS 16 +struct stack_frame { + struct stack_frame *previous; + addr_t return_address; +}; + +#define NUM_PREVIOUS_LOCATIONS 32 extern struct iframe_stack gBootFrameStack; @@ -110,12 +115,12 @@ dbg_stack_trace(int argc, char **argv) dprintf(" vector: 0x%x, error code: 0x%x\n", frame->vector, frame->error_code); ebp = frame->ebp; } else { - uint32 eip = *((uint32 *)ebp + 1); + addr_t eip = ((struct stack_frame *)ebp)->return_address; const char *symbol, *image; - uint32 nextEbp = *(uint32 *)ebp; + addr_t nextEbp = (addr_t)((struct stack_frame *)ebp)->previous; addr_t baseAddress; bool exactMatch; - uint32 diff = nextEbp - ebp; + addr_t diff = nextEbp - ebp; if (eip == 0 || ebp == 0) break; @@ -147,7 +152,23 @@ dbg_stack_trace(int argc, char **argv) } -int +// #pragma mark - + + +void * +arch_get_caller(void) +{ + // It looks like you would get the wrong stack frame here, but + // since read_ebp() is an assembler inline macro, GCC seems to + // be smart enough to save its original value. + struct stack_frame *frame; + read_ebp(frame); + + return (void *)frame->return_address; +} + + +status_t arch_dbg_init(kernel_args *args) { // at this stage, the debugger command system is alive