Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/44607 )

Change subject: base: Streamline the "send" method of the BaseRemoteGDB class.
......................................................................

base: Streamline the "send" method of the BaseRemoteGDB class.

The existing send method takes a const char *, but frequently the class
wants to use it to send a std::string, also frequently after generating
that string with csprintf. Rather than force each call sight to add a
.c_str() and call csprintf, this change adds helpers which will accept a
std::string and call c_str for you, or accept a format const char * and
arguments and call csprintf for you (and then call .c_str() on the
result).

Change-Id: Ifcef5e09f6469322c6040374209972528c80fb25
---
M src/base/remote_gdb.cc
M src/base/remote_gdb.hh
2 files changed, 16 insertions(+), 7 deletions(-)



diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 3fc5240..16373e6 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -466,7 +466,7 @@
         active = true;
     } else {
         // Tell remote host that an exception has occurred.
-        send(csprintf("S%02x", type).c_str());
+        send("S%02x", type);
     }

     // Stick frame regs into our reg cache.
@@ -506,7 +506,7 @@
         } catch (Unsupported &e) {
             send("");
         } catch (CmdError &e) {
-            send(e.error.c_str());
+            send(e.error);
         } catch (...) {
             panic("Unrecognzied GDB exception.");
         }
@@ -837,7 +837,7 @@
 bool
 BaseRemoteGDB::cmdSignal(GdbCommand::Context &ctx)
 {
-    send(csprintf("S%02x", ctx.type).c_str());
+    send("S%02x", ctx.type);
     return true;
 }

@@ -986,7 +986,7 @@
 void
 BaseRemoteGDB::queryC(QuerySetCommand::Context &ctx)
 {
-    send(csprintf("QC%x", encodeThreadId(tc->contextId())).c_str());
+    send("QC%x", encodeThreadId(tc->contextId()));
 }

 void
@@ -999,7 +999,7 @@
     oss << "PacketSize=1024";
     for (const auto& feature : availableFeatures())
         oss << ';' << feature;
-    send(oss.str().c_str());
+    send(oss.str());
 }

 void
@@ -1040,13 +1040,13 @@

     std::string encoded;
     encodeXferResponse(content, encoded, offset, length);
-    send(encoded.c_str());
+    send(encoded);
 }

 void
 BaseRemoteGDB::queryFThreadInfo(QuerySetCommand::Context &ctx)
 {
-    send(csprintf("m%x", encodeThreadId(tc->contextId())).c_str());
+    send("m%x", encodeThreadId(tc->contextId()));
 }

 void
diff --git a/src/base/remote_gdb.hh b/src/base/remote_gdb.hh
index 0d67b09..cfd6b3d 100644
--- a/src/base/remote_gdb.hh
+++ b/src/base/remote_gdb.hh
@@ -51,6 +51,7 @@
 #include <vector>

 #include "arch/types.hh"
+#include "base/cprintf.hh"
 #include "base/pollevent.hh"
 #include "base/socket.hh"
 #include "base/types.hh"
@@ -203,6 +204,14 @@

     void recv(std::vector<char> &bp);
     void send(const char *data);
+    void send(const std::string &data) { send(data.c_str()); }
+
+    template <typename ...Args>
+    void
+    send(const char *format, const Args &...args)
+    {
+        send(csprintf(format, args...));
+    }

     /*
      * Simulator side debugger state.

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44607
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ifcef5e09f6469322c6040374209972528c80fb25
Gerrit-Change-Number: 44607
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to