Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/18574
Change subject: mem: Add a readString method to the PortProxy which takes a
char *.
......................................................................
mem: Add a readString method to the PortProxy which takes a char *.
This version takes a char * instead of an std::string &, and a maximum
length to fill in like strncpy. This is intended to be a replacement
for the CopyStringOut function.
Change-Id: Ib661924a3fa7e05761d572ffecbe2c0cc8659d48
---
M src/mem/port_proxy.cc
M src/mem/port_proxy.hh
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/src/mem/port_proxy.cc b/src/mem/port_proxy.cc
index f56bfeb..60f79e3 100644
--- a/src/mem/port_proxy.cc
+++ b/src/mem/port_proxy.cc
@@ -110,3 +110,18 @@
str += c;
}
}
+
+bool
+PortProxy::tryReadString(char *str, Addr addr, size_t maxlen) const
+{
+ assert(maxlen);
+ while (maxlen--) {
+ if (!tryReadBlob(addr++, str, 1))
+ return false;
+ if (!*str++)
+ return true;
+ }
+ // We ran out of room, so back up and add a terminator.
+ *--str = '\0';
+ return true;
+}
diff --git a/src/mem/port_proxy.hh b/src/mem/port_proxy.hh
index 469273f..61a2071 100644
--- a/src/mem/port_proxy.hh
+++ b/src/mem/port_proxy.hh
@@ -59,6 +59,8 @@
#ifndef __MEM_PORT_PROXY_HH__
#define __MEM_PORT_PROXY_HH__
+#include <limits>
+
#include "mem/port.hh"
#include "sim/byteswap.hh"
@@ -242,6 +244,23 @@
if (!tryReadString(str, addr))
fatal("readString(%#x, ...) failed", addr);
}
+
+ /**
+ * Reads the string at guest address addr into the char * str, reading
up
+ * to maxlen characters. The last character read is always a nul
+ * terminator. Returns true on success and false on failure.
+ */
+ bool tryReadString(char *str, Addr addr, size_t maxlen) const;
+
+ /**
+ * Same as tryReadString, but insists on success.
+ */
+ void
+ readString(char *str, Addr addr, size_t maxlen) const
+ {
+ if (!tryReadString(str, addr, maxlen))
+ fatal("readString(%#x, ...) failed", addr);
+ }
};
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/18574
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ib661924a3fa7e05761d572ffecbe2c0cc8659d48
Gerrit-Change-Number: 18574
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev