From 743b4d3a67c700028b08363c96fccdbfe720cfe9 Mon Sep 17 00:00:00 2001 From: Prateek Arora Date: Tue, 24 Feb 2026 19:46:26 -0800 Subject: [PATCH] WFI: Reacquire control of the core in the debugger after it executes a WFI instruction. A new gdb_stop_evt event was added, triggered when the debugger issues a stop request. --- src/iss/arch_if.h | 5 +++++ src/iss/debugger/cmdhandler.cpp | 6 ++++++ src/iss/debugger/cmdhandler.h | 1 + src/iss/debugger/gdb_session.cpp | 1 + src/iss/debugger/target_adapter_if.h | 3 +++ 5 files changed, 16 insertions(+) diff --git a/src/iss/arch_if.h b/src/iss/arch_if.h index a5dc719..66a330f 100644 --- a/src/iss/arch_if.h +++ b/src/iss/arch_if.h @@ -211,6 +211,11 @@ class arch_if { using unknown_instr_cb_t = std::tuple(arch_if* core, uint64_t addr, size_t len, uint8_t const*); + /** + * @brief trigger gdb stop event to resume fetch instruction thread + */ + virtual void cancel_wait() {} + protected: using rd_func_sig = iss::status(const addr_t&, unsigned, uint8_t*); util::delegate rd_func; diff --git a/src/iss/debugger/cmdhandler.cpp b/src/iss/debugger/cmdhandler.cpp index b1c4122..82da891 100644 --- a/src/iss/debugger/cmdhandler.cpp +++ b/src/iss/debugger/cmdhandler.cpp @@ -121,6 +121,12 @@ std::string cmd_handler::threads(std::string const& in_buf) { } } +int cmd_handler::send_stop_event(){ + CLOG(TRACE, connection) << "executing " << __FUNCTION__; + int ret = t->trigger_debugger_stop_event(); + return ret; +} + std::string cmd_handler::read_registers(std::string const& in_buf) { CLOG(TRACE, connection) << "executing " << __FUNCTION__; int ret; diff --git a/src/iss/debugger/cmdhandler.h b/src/iss/debugger/cmdhandler.h index a7f7b7e..d919c72 100644 --- a/src/iss/debugger/cmdhandler.h +++ b/src/iss/debugger/cmdhandler.h @@ -111,6 +111,7 @@ class cmd_handler { std::string detach(std::string const& in_buf); std::string query(std::string const& in_buf); std::string set(std::string const& in_buf); + int send_stop_event(); boost::optional handle_extended(std::string const& in_buf); std::string breakpoint(std::string const& in_buf); int rcmd(const char* const in_buf, out_func of, data_func df); diff --git a/src/iss/debugger/gdb_session.cpp b/src/iss/debugger/gdb_session.cpp index 375b2be..ce184b2 100644 --- a/src/iss/debugger/gdb_session.cpp +++ b/src/iss/debugger/gdb_session.cpp @@ -197,6 +197,7 @@ void gdb_session::receive_completed(const boost::system::error_code& e, std::str } else if(msg->at(0) == 3 || (msg->at(0) == -1 && msg->at(1) == -13)) { CLOG(TRACE, connection) << "Received BREAK, interrupting target"; handler.t->stop(); + handler.send_stop_event(); respond("+"); } else { CLOG(TRACE, connection) << "Received packet '" << *msg << "', processing it"; diff --git a/src/iss/debugger/target_adapter_if.h b/src/iss/debugger/target_adapter_if.h index e744abe..c77bc94 100644 --- a/src/iss/debugger/target_adapter_if.h +++ b/src/iss/debugger/target_adapter_if.h @@ -158,6 +158,9 @@ class target_adapter_if { avail buf is 1 */ virtual iss::status read_registers(std::vector& data_buf, std::vector& avail_buf) = 0; + /* Send gdb stop event to core*/ + virtual iss::status trigger_debugger_stop_event() = 0; + /* Write all registers. buf is 4-byte aligned and it is in target byte order */ virtual iss::status write_registers(const std::vector& buf) = 0;