From 6a367f46894932bc4814fdf9c02ef04e441e2a5d Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Mon, 5 Aug 2024 11:34:29 +1000 Subject: [PATCH] libdebugger/target: Move global stepping variables in to the target data Updates #5098 --- cpukit/libdebugger/rtems-debugger-server.c | 9 ++-- cpukit/libdebugger/rtems-debugger-target.c | 51 ++++++++++++++-------- cpukit/libdebugger/rtems-debugger-target.h | 3 ++ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/cpukit/libdebugger/rtems-debugger-server.c b/cpukit/libdebugger/rtems-debugger-server.c index b7b9727d84..51d165c58f 100644 --- a/cpukit/libdebugger/rtems-debugger-server.c +++ b/cpukit/libdebugger/rtems-debugger-server.c @@ -1538,11 +1538,11 @@ remote_breakpoints(bool insert, uint8_t* buffer, int size) const char* comma2; comma2 = strchr(comma1 + 1, ','); if (comma2 != NULL) { - uint32_t capabilities; - uintptr_t addr; - DB_UINT kind; + uint32_t capabilities; + uintptr_t addr; + DB_UINT kind; addr = hex_decode_addr((const uint8_t*) comma1 + 1); - kind = hex_decode_uint((const uint8_t*)comma2 + 1); + kind = hex_decode_uint((const uint8_t*) comma2 + 1); capabilities = rtems_debugger_target_capabilities(); switch (buffer[1]) { case '0': @@ -1797,6 +1797,7 @@ rtems_debugger_session(void) if (rtems_debugger_server_flag(RTEMS_DEBUGGER_FLAG_RESET)) { rtems_debugger_printf("rtems-db: shutdown\n"); + sleep(2); rtems_fatal_error_occurred(1122); } diff --git a/cpukit/libdebugger/rtems-debugger-target.c b/cpukit/libdebugger/rtems-debugger-target.c index 2b55c93513..27a1ed5e62 100644 --- a/cpukit/libdebugger/rtems-debugger-target.c +++ b/cpukit/libdebugger/rtems-debugger-target.c @@ -349,11 +349,8 @@ rtems_debugger_target_swbreak_remove(void) return r; } -uintptr_t saved_break_address = 0; -rtems_id saved_tid = 0; - static rtems_debugger_target_exc_action -soft_step_and_continue(CPU_Exception_frame* frame) +rtems_debugger_soft_step_and_continue(CPU_Exception_frame* frame) { uintptr_t break_address; rtems_debugger_target *target = rtems_debugger->target; @@ -378,43 +375,57 @@ soft_step_and_continue(CPU_Exception_frame* frame) return rtems_debugger_target_exc_cascade; } - /* Remove the current breakpoint */ + /* + * Remove the current breakpoint + */ rtems_debugger_target_swbreak_control( false, break_address, target->breakpoint_size ); - /* Save off thread ID and break address for later usage */ - saved_tid = tid; - saved_break_address = break_address; + /* + * Save the thread ID and break address to recover after stepping + */ + target->step_tid = tid; + target->step_bp_address = break_address; - /* Populate the fake rtems_debugger_thread */ + /* + * Populate the fake rtems_debugger_thread + */ fake_debugger_thread.flags |= RTEMS_DEBUGGER_THREAD_FLAG_STEP; fake_debugger_thread.frame = frame; target_printk("rtems-db: stepping to the next instruction\n"); rtems_debugger_target_thread_stepping(&fake_debugger_thread); - /* rtems_debugger_unlock() not called until the step is resolved */ + /* + * rtems_debugger_unlock() not called until the step is resolved + */ return rtems_debugger_target_exc_step; } rtems_debugger_target_exc_action rtems_debugger_target_exception(CPU_Exception_frame* frame) { - Thread_Control* thread = _Thread_Get_executing(); - const rtems_id tid = thread->Object.id; + rtems_debugger_target *target = rtems_debugger->target; + Thread_Control* thread = _Thread_Get_executing(); + const rtems_id tid = thread->Object.id; - /* Resolve outstanding step+continue */ - if ( saved_break_address != 0 && tid == saved_tid ) { + /* + * Resolve outstanding step+continue + */ + if (target->step_bp_address != 0 && target->step_tid == tid) { rtems_debugger_target_swbreak_control( true, - saved_break_address, + target->step_bp_address, rtems_debugger->target->breakpoint_size ); - saved_break_address = saved_tid = 0; + target->step_bp_address = 0; + target->step_tid = 0; - /* Release the debugger lock now that the step+continue is complete */ + /* + * Release the debugger lock now that the step+continue is complete + */ target_printk("rtems-db: resuming after step\n"); rtems_debugger_unlock(); return rtems_debugger_target_exc_consumed; @@ -524,8 +535,10 @@ rtems_debugger_target_exception(CPU_Exception_frame* frame) target_printk("[} tid:%08" PRIx32 ": exception in interrupt context\n", tid); - /* soft_step_and_continue releases the debugger lock */ - return soft_step_and_continue( frame ); + /* + * Soft_step_and_continue releases the debugger lock + */ + return rtems_debugger_soft_step_and_continue(frame); } void diff --git a/cpukit/libdebugger/rtems-debugger-target.h b/cpukit/libdebugger/rtems-debugger-target.h index 3f6ceac80b..58a8f8ca97 100644 --- a/cpukit/libdebugger/rtems-debugger-target.h +++ b/cpukit/libdebugger/rtems-debugger-target.h @@ -107,6 +107,9 @@ typedef struct rtems_debugger_target { rtems_debugger_block swbreaks; /*<< The software breakpoint block. */ bool memory_access; /*<< Accessing target memory. */ jmp_buf access_return; /*<< Return from an access fault. */ + uintptr_t step_bp_address; /*<< Stepping break point address */ + rtems_id step_tid; /*<< Stepping task id */ + } rtems_debugger_target; /**