From: falcovorbis <fal...@us...> - 2024-10-08 10:27:40
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via d0f35280e58557ae330e5b00d013fb4cc77f1195 (commit) from 8eed75b86e84a8459075e658ba840d563a70a633 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d0f35280e58557ae330e5b00d013fb4cc77f1195 Author: Andy Barajas <and...@gm...> Date: Tue Oct 8 03:27:25 2024 -0700 Improve diagnose message (#614) * Handle invalid PC and PR addresses. Make sure addresses are in the text section of program * Make the logic more clear * Add options to demangle C++ symbols, show function names, print inlined function calls ----------------------------------------------------------------------- Summary of changes: kernel/arch/dreamcast/include/arch/arch.h | 14 ++++++++++ kernel/arch/dreamcast/kernel/irq.c | 44 ++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/kernel/arch/dreamcast/include/arch/arch.h b/kernel/arch/dreamcast/include/arch/arch.h index acb750d2..e944762b 100644 --- a/kernel/arch/dreamcast/include/arch/arch.h +++ b/kernel/arch/dreamcast/include/arch/arch.h @@ -40,6 +40,10 @@ extern uint32 _arch_mem_top; #define _arch_mem_top ((uint32) 0x8d000000) #endif +/** \brief Start and End address for .text portion of program. */ +extern char _executable_start; +extern char _etext; + #define PAGESIZE 4096 /**< \brief Page size (for MMU) */ #define PAGESIZE_BITS 12 /**< \brief Bits for page size */ #define PAGEMASK (PAGESIZE - 1) /**< \brief Mask for page offset */ @@ -415,6 +419,16 @@ const char *kos_get_authors(void); */ #define arch_valid_address(ptr) ((ptr_t)(ptr) >= 0x8c010000 && (ptr_t)(ptr) < _arch_mem_top) +/** \brief Returns true if the passed address is in the text section of your + program. + \ingroup arch + + \return Whether the address is valid or not for text + memory access. +*/ +#define arch_valid_text_address(ptr) \ + ((uintptr_t)(ptr) >= (uintptr_t)&_executable_start && (uintptr_t)(ptr) < (uintptr_t)&_etext) + __END_DECLS #endif /* __ARCH_ARCH_H */ diff --git a/kernel/arch/dreamcast/kernel/irq.c b/kernel/arch/dreamcast/kernel/irq.c index dbb75e01..b5ad0eec 100644 --- a/kernel/arch/dreamcast/kernel/irq.c +++ b/kernel/arch/dreamcast/kernel/irq.c @@ -124,6 +124,8 @@ extern irq_context_t *irq_srt_addr; static void irq_dump_regs(int code, int evt) { uint32_t fp; uint32_t *regs = irq_srt_addr->r; + bool valid_pc; + bool valid_pr; dbglog(DBG_DEAD, "Unhandled exception: PC %08lx, code %d, evt %04x\n", irq_srt_addr->pc, code, (uint16)evt); @@ -136,27 +138,39 @@ static void irq_dump_regs(int code, int evt) { arch_stk_trace_at(fp, 0); if(code == 1) { - dbglog(DBG_DEAD, "Encountered %s. Use this terminal command to help" - " diagnose:\n\n\t$KOS_ADDR2LINE -e your_program.elf %08lx %08lx", - irq_exception_string(evt), irq_srt_addr->pc, irq_srt_addr->pr); + dbglog(DBG_DEAD, "\nEncountered %s. ", irq_exception_string(evt)); + + valid_pc = arch_valid_text_address(irq_srt_addr->pc); + valid_pr = arch_valid_text_address(irq_srt_addr->pr); + /* Construct template message only if either PC/PR address is valid */ + if(valid_pc || valid_pr) { + dbglog(DBG_DEAD, "Use this template terminal command to help" + " diagnose:\n\n\t$KOS_ADDR2LINE -f -C -i -e prog.elf"); + + if(valid_pc) + dbglog(DBG_DEAD, " %08lx", irq_srt_addr->pc); + + if(valid_pr) + dbglog(DBG_DEAD, " %08lx", irq_srt_addr->pr); #ifdef FRAME_POINTERS - while(fp != 0xffffffff) { - /* Validate the function pointer (fp) */ - if((fp & 3) || (fp < 0x8c000000) || (fp > _arch_mem_top)) - break; + while(fp != 0xffffffff) { + /* Validate the function pointer (fp) */ + if((fp & 3) || (fp < 0x8c000000) || (fp > _arch_mem_top)) + break; - /* Get the return address from the function pointer */ - fp = arch_fptr_ret_addr(fp); + /* Get the return address from the function pointer */ + fp = arch_fptr_ret_addr(fp); - /* Validate the return address */ - if(!arch_valid_address(fp)) - break; + /* Validate the return address */ + if(!arch_valid_text_address(fp)) + break; - dbglog(DBG_DEAD, " %08lx", fp); - fp = arch_fptr_next(fp); - } + dbglog(DBG_DEAD, " %08lx", fp); + fp = arch_fptr_next(fp); + } #endif + } dbglog(DBG_DEAD, "\n"); } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |