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;
+}
#ifndef __MEM_PORT_PROXY_HH__
#define __MEM_PORT_PROXY_HH__
+#include <limits>
+
#include "mem/port.hh"
#include "sim/byteswap.hh"
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);
+ }
};