================
@@ -839,6 +839,43 @@ bool fromJSON(const llvm::json::Value &, 
DisassembleResponseBody &,
               llvm::json::Path);
 llvm::json::Value toJSON(const DisassembleResponseBody &);
 
+/// Arguments for `readMemory` request.
+struct ReadMemoryArguments {
+  /// Memory reference to the base location from which data should be read.
+  lldb::addr_t memoryReference;
+
+  /// Offset (in bytes) to be applied to the reference location before reading
+  /// data. Can be negative.
+  int64_t offset = 0;
+
+  /// Number of bytes to read at the specified location and offset.
+  uint64_t count;
+};
+bool fromJSON(const llvm::json::Value &, ReadMemoryArguments &,
+              llvm::json::Path);
+
+/// Response to `readMemory` request.
+struct ReadMemoryResponseBody {
+  /// The address of the first byte of data returned.
+  /// Treated as a hex value if prefixed with `0x`, or as a decimal value
+  /// otherwise.
+  std::string address;
+
+  /// The number of unreadable bytes encountered after the last successfully
+  /// read byte.
+  /// This can be used to determine the number of bytes that should be skipped
+  /// before a subsequent `readMemory` request succeeds.
+  uint64_t unreadableBytes = 0;
+
+  /// The bytes read from memory, encoded using base64. If the decoded length
+  /// of `data` is less than the requested `count` in the original `readMemory`
+  /// request, and `unreadableBytes` is zero or omitted, then the client should
+  /// assume it's reached the end of readable memory.
+  std::vector<std::byte> data;
----------------
ashgti wrote:

Sorry for making you go back and forth on this. Reading more of the helpers in 
llvm/ADT/StringExtras.h and the like, it looks like in llvm raw data bytes are 
are often either represented as `llvm::ArrayRef<uint8_t>` (for non-owning 
cases) or a `std::string` (for cases where you'd want to own the underlying 
data buffer).

I'm just used to swift where there is a separate `Data` type (from Foundation 
or `Array<Uint8>` used in the swift stdlib) for this and I was trying to figure 
out the c++ equivalent. It seems that `std::string` is the common way to handle 
this.

I guess we can go back to `std::string data;` here and then still convert the 
value to hex in from/toJSON or if you want to keep using the 
`std::vector<std::byte>` thats also fine.

In the SB API there is a `lldb::SBData` type for this use case and in 
lldb_private its built on top of `lldb_private::DataExtractor` but for the 
protocol representation, I am not sure either of those types make sense.

I'm open to suggestions for this, I just was worried about mishandling the data 
since it looked like a string.

https://github.com/llvm/llvm-project/pull/144552
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to