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 <bbruce@ucdavis.edu>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 7aafa3d..e02ada0 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -575,6 +575,16 @@
     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 671ee51..280f12c 100644
--- a/src/base/remote_gdb.hh
+++ b/src/base/remote_gdb.hh
@@ -172,6 +172,7 @@
     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 3fd4f81..b46c32f 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 @@
 
     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 1f6e072..ca51bbd 100644
--- a/src/sim/workload.cc
+++ b/src/sim/workload.cc
@@ -80,6 +80,14 @@
     }
     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 9b3ef04..f9bb8db 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -92,6 +92,7 @@
     // 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);