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
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44607
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-04-12 05:05:26 -07:00
parent 86301ce456
commit b596aa86e2
2 changed files with 16 additions and 7 deletions

View File

@@ -466,7 +466,7 @@ BaseRemoteGDB::trap(int type)
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 @@ BaseRemoteGDB::trap(int type)
} catch (Unsupported &e) {
send("");
} catch (CmdError &e) {
send(e.error.c_str());
send(e.error);
} catch (...) {
panic("Unrecognzied GDB exception.");
}
@@ -837,7 +837,7 @@ BaseRemoteGDB::cmdUnsupported(GdbCommand::Context &ctx)
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 @@ std::map<std::string, BaseRemoteGDB::QuerySetCommand>
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 @@ BaseRemoteGDB::querySupported(QuerySetCommand::Context &ctx)
oss << "PacketSize=1024";
for (const auto& feature : availableFeatures())
oss << ';' << feature;
send(oss.str().c_str());
send(oss.str());
}
void
@@ -1040,13 +1040,13 @@ BaseRemoteGDB::queryXfer(QuerySetCommand::Context &ctx)
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

View File

@@ -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 @@ class BaseRemoteGDB
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.