From ef9e2f627b00302ff17a9f1b26cf4d115fd38cb8 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 23 Sep 2023 00:57:03 -0400 Subject: [PATCH] kernel/arch: Make arch_debug_get_caller() a macro implemented by a builtin. Only the x86 and PPC implementations look like they would have worked, while the builtin is available and will work across all architectures. We already use it unconditionally in some parts of libroot. Change-Id: I2dffb3b2c7cdd605092382b9d649151adb921bb4 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6942 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- headers/private/kernel/arch/debug.h | 3 ++- src/system/kernel/arch/arm/arch_debug.cpp | 9 --------- src/system/kernel/arch/arm64/arch_debug.cpp | 7 ------- src/system/kernel/arch/m68k/arch_debug.cpp | 12 ------------ src/system/kernel/arch/ppc/arch_debug.cpp | 8 -------- src/system/kernel/arch/riscv64/arch_debug.cpp | 7 ------- src/system/kernel/arch/sparc/arch_debug.cpp | 7 ------- src/system/kernel/arch/x86/arch_debug.cpp | 8 -------- 8 files changed, 2 insertions(+), 59 deletions(-) diff --git a/headers/private/kernel/arch/debug.h b/headers/private/kernel/arch/debug.h index b2e1681302..381de33627 100644 --- a/headers/private/kernel/arch/debug.h +++ b/headers/private/kernel/arch/debug.h @@ -33,9 +33,10 @@ using BKernel::Thread; extern "C" { #endif +#define arch_debug_get_caller() __builtin_return_address(0) + status_t arch_debug_init(kernel_args *args); void arch_debug_stack_trace(void); -void *arch_debug_get_caller(void); int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, int32 skipIframes, int32 skipFrames, uint32 flags); void* arch_debug_get_interrupt_pc(bool* _isSyscall); diff --git a/src/system/kernel/arch/arm/arch_debug.cpp b/src/system/kernel/arch/arm/arch_debug.cpp index ae523f2b98..ce0a4a2bb1 100644 --- a/src/system/kernel/arch/arm/arch_debug.cpp +++ b/src/system/kernel/arch/arm/arch_debug.cpp @@ -467,15 +467,6 @@ arch_debug_stack_trace(void) } -void * -arch_debug_get_caller(void) -{ - /* Return the thread id as the kernel (for example the lock code) actually - gets a somewhat valid indication of the caller back. */ - return (void*) thread_get_current_thread_id(); -} - - int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, int32 skipIframes, int32 skipFrames, uint32 flags) diff --git a/src/system/kernel/arch/arm64/arch_debug.cpp b/src/system/kernel/arch/arm64/arch_debug.cpp index e7af9b7024..a61c58b0cd 100644 --- a/src/system/kernel/arch/arm64/arch_debug.cpp +++ b/src/system/kernel/arch/arm64/arch_debug.cpp @@ -449,13 +449,6 @@ arch_debug_stack_trace(void) } -void * -arch_debug_get_caller(void) -{ - return NULL; -} - - int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, int32 skipIframes, int32 skipFrames, uint32 flags) diff --git a/src/system/kernel/arch/m68k/arch_debug.cpp b/src/system/kernel/arch/m68k/arch_debug.cpp index eaa3819d41..9f52403d9d 100644 --- a/src/system/kernel/arch/m68k/arch_debug.cpp +++ b/src/system/kernel/arch/m68k/arch_debug.cpp @@ -269,18 +269,6 @@ arch_debug_contains_call(Thread *thread, const char *symbol, } -void * -arch_debug_get_caller(void) -{ - // TODO: implement me - //return __builtin_frame_address(1); - struct stack_frame *frame; - //frame = __builtin_frame_address(0); - frame = get_current_stack_frame(); - return (void *)frame->previous->return_address; -} - - int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, int32 skipIframes, int32 skipFrames, uint32 flags) diff --git a/src/system/kernel/arch/ppc/arch_debug.cpp b/src/system/kernel/arch/ppc/arch_debug.cpp index 597e37bcce..da09907213 100644 --- a/src/system/kernel/arch/ppc/arch_debug.cpp +++ b/src/system/kernel/arch/ppc/arch_debug.cpp @@ -280,14 +280,6 @@ arch_debug_contains_call(Thread *thread, const char *symbol, } -void * -arch_debug_get_caller(void) -{ - struct stack_frame *frame = get_current_stack_frame()->previous; - return (void *)frame->previous->return_address; -} - - int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, int32 skipIframes, int32 skipFrames, uint32 flags) diff --git a/src/system/kernel/arch/riscv64/arch_debug.cpp b/src/system/kernel/arch/riscv64/arch_debug.cpp index a2c159a230..aa9d36f946 100644 --- a/src/system/kernel/arch/riscv64/arch_debug.cpp +++ b/src/system/kernel/arch/riscv64/arch_debug.cpp @@ -358,13 +358,6 @@ arch_debug_contains_call(Thread *thread, const char *symbol, } -void * -arch_debug_get_caller(void) -{ - return NULL; -} - - void arch_debug_save_registers(struct arch_debug_registers* registers) { diff --git a/src/system/kernel/arch/sparc/arch_debug.cpp b/src/system/kernel/arch/sparc/arch_debug.cpp index 5b393406a8..90d4fcc5ea 100644 --- a/src/system/kernel/arch/sparc/arch_debug.cpp +++ b/src/system/kernel/arch/sparc/arch_debug.cpp @@ -24,13 +24,6 @@ arch_debug_contains_call(Thread *thread, const char *symbol, } -void * -arch_debug_get_caller(void) -{ - return NULL; -} - - void arch_debug_save_registers(struct arch_debug_registers* registers) { diff --git a/src/system/kernel/arch/x86/arch_debug.cpp b/src/system/kernel/arch/x86/arch_debug.cpp index bbdd62d62f..76dd6139a2 100644 --- a/src/system/kernel/arch/x86/arch_debug.cpp +++ b/src/system/kernel/arch/x86/arch_debug.cpp @@ -1117,14 +1117,6 @@ arch_debug_contains_call(Thread* thread, const char* symbol, addr_t start, } -void* -arch_debug_get_caller(void) -{ - stack_frame* frame = (stack_frame*)x86_get_stack_frame(); - return (void*)frame->previous->return_address; -} - - /*! Captures a stack trace (the return addresses) of the current thread. \param returnAddresses The array the return address shall be written to. \param maxCount The maximum number of return addresses to be captured.