[Lldb-commits] [lldb] [lldb-dap] Support inspecting memory (PR #104317)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 15 18:36:54 PDT 2024
================
@@ -4028,6 +4049,154 @@ void request_disassemble(const llvm::json::Object &request) {
response.try_emplace("body", std::move(body));
g_dap.SendJSON(llvm::json::Value(std::move(response)));
}
+
+// "ReadMemoryRequest": {
+// "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Reads bytes from memory at the provided location. Clients
+// should only call this request if the corresponding
+// capability `supportsReadMemoryRequest` is true.",
+// "properties": {
+// "command": {
+// "type": "string",
+// "enum": [ "readMemory" ]
+// },
+// "arguments": {
+// "$ref": "#/definitions/ReadMemoryArguments"
+// }
+// },
+// "required": [ "command", "arguments" ]
+// }]
+// },
+// "ReadMemoryArguments": {
+// "type": "object",
+// "description": "Arguments for `readMemory` request.",
+// "properties": {
+// "memoryReference": {
+// "type": "string",
+// "description": "Memory reference to the base location from which data
+// should be read."
+// },
+// "offset": {
+// "type": "integer",
+// "description": "Offset (in bytes) to be applied to the reference
+// location before reading data. Can be negative."
+// },
+// "count": {
+// "type": "integer",
+// "description": "Number of bytes to read at the specified location and
+// offset."
+// }
+// },
+// "required": [ "memoryReference", "count" ]
+// },
+// "ReadMemoryResponse": {
+// "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `readMemory` request.",
+// "properties": {
+// "body": {
+// "type": "object",
+// "properties": {
+// "address": {
+// "type": "string",
+// "description": "The address of the first byte of data returned.
+// Treated as a hex value if prefixed with `0x`, or
+// as a decimal value otherwise."
+// },
+// "unreadableBytes": {
+// "type": "integer",
+// "description": "The number of unreadable bytes encountered after
+// the last successfully read byte.\nThis can be
+// used to determine the number of bytes that should
+// be skipped before a subsequent
+// `readMemory` request succeeds."
+// },
+// "data": {
+// "type": "string",
+// "description": "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."
+// }
+// },
+// "required": [ "address" ]
+// }
+// }
+// }]
+// },
+void request_readMemory(const llvm::json::Object &request) {
+ llvm::json::Object response;
+ FillResponse(request, response);
+ auto arguments = request.getObject("arguments");
+
+ lldb::SBProcess process = g_dap.target.GetProcess();
+ if (!process.IsValid()) {
+ response["success"] = false;
+ response["message"] = "No process running";
+ g_dap.SendJSON(llvm::json::Value(std::move(response)));
+ return;
+ }
+
+ auto memoryReference = GetString(arguments, "memoryReference");
+ lldb::addr_t addr;
+ if (memoryReference.consumeInteger(0, addr)) {
----------------
clayborg wrote:
Gotcha, that is interesting. I guess they let you encode and decode a `memoryReference` how ever you want then right? I mean, you could return "hello" for a memory reference and they will hand that back to you so you can decode it how you want later? It does make sense and some DSPs have multiple address spaces so they might want to specify the address space like `"[0]0x1000"` or `"[1]0x1000"` as the first can mean `instruction address space at address 0x1000` and the second can mean `data address space at address 0x1000`.
If this is the case, then we probably want two functions to encode and decode `memoryReferences` to/fromt strings in JSONUtils:
```
std::string EncodeMemoryReference(lldb::addr_t addr);
lldb::addr_t DecodeMemoryReference(std::string memoryReference);
```
And then use that function here to decode the memory reference.
https://github.com/llvm/llvm-project/pull/104317
More information about the lldb-commits
mailing list