From 2ae9692dfe9324f2d616900f0514fe43a3a667af Mon Sep 17 00:00:00 2001 From: Quentin Forcioli Date: Fri, 12 Aug 2022 15:44:54 +0200 Subject: [PATCH] base, sim: Adding support for message to GDB from python Adding a small python function that allows to display messages directly in GDB from the python interpreter. This function is inside the Workload SimObject (The stub is not a SimObject). ex: system.workload.sendToGdb("message to display") Change-Id: I46ddae079b10d298743e023f95bf15608f50e358 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63531 Reviewed-by: Bobby Bruce Maintainer: Bobby Bruce Tested-by: kokoro --- src/base/remote_gdb.cc | 10 ++++++++++ src/base/remote_gdb.hh | 1 + src/sim/Workload.py | 10 +++++++++- src/sim/workload.cc | 8 ++++++++ src/sim/workload.hh | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc index 7aafa3d3db..e02ada025a 100644 --- a/src/base/remote_gdb.cc +++ b/src/base/remote_gdb.cc @@ -575,6 +575,16 @@ BaseRemoteGDB::trap(ContextID id, int signum,const std::string& stopReason) processCommands(signum); } +bool +BaseRemoteGDB::sendMessage(std::string message) +{ + if (!attached) + return false; + DPRINTF(GDBMisc, "passing message %s\n", message); + sendOPacket(message); + return true; +} + void BaseRemoteGDB::incomingConnection(int revent) { diff --git a/src/base/remote_gdb.hh b/src/base/remote_gdb.hh index 671ee51542..280f12c55f 100644 --- a/src/base/remote_gdb.hh +++ b/src/base/remote_gdb.hh @@ -172,6 +172,7 @@ class BaseRemoteGDB bool selectThreadContext(ContextID id); void trap(ContextID id, int signum,const std::string& stopReason=""); + bool sendMessage(std::string message); /** @} */ // end of api_remote_gdb diff --git a/src/sim/Workload.py b/src/sim/Workload.py index 3fd4f81cc9..b46c32fb48 100644 --- a/src/sim/Workload.py +++ b/src/sim/Workload.py @@ -24,7 +24,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from m5.params import * -from m5.SimObject import SimObject +from m5.SimObject import SimObject, cxxMethod from m5.objects.SimpleMemory import * @@ -37,6 +37,14 @@ class Workload(SimObject): wait_for_remote_gdb = Param.Bool(False, "Wait for a remote GDB connection") + @cxxMethod + def sendToGdb(self, message): + """send a message to the GDB client + Args: + message (str): message to send + """ + pass + class StubWorkload(Workload): type = "StubWorkload" diff --git a/src/sim/workload.cc b/src/sim/workload.cc index 1f6e0721d8..ca51bbdb73 100644 --- a/src/sim/workload.cc +++ b/src/sim/workload.cc @@ -80,6 +80,14 @@ Workload::trapToGdb(int signal, ContextID ctx_id) } return false; }; +bool +Workload::sendToGdb(std::string msg){ + if (gdb) + return gdb->sendMessage(msg); + else + return false; + } + void Workload::startup() diff --git a/src/sim/workload.hh b/src/sim/workload.hh index 9b3ef04fb7..f9bb8dba3c 100644 --- a/src/sim/workload.hh +++ b/src/sim/workload.hh @@ -92,6 +92,7 @@ class Workload : public SimObject // Once trapping into GDB is no longer a special case routed through the // system object, this helper can be removed. bool trapToGdb(int signal, ContextID ctx_id); + bool sendToGdb(std::string msg); virtual void registerThreadContext(ThreadContext *tc); virtual void replaceThreadContext(ThreadContext *tc);