[Lldb-commits] [lldb] [lldb-dap] Support inspecting memory (PR #104317)
Adrian Vogelsgesang via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 16 04:09:46 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)) {
----------------
vogelsgesang wrote:
> Gotcha, that is interesting. I guess they let you encode and decode a memoryReference how ever you want then right?
Correct. The memory reference is actually also displayed to the user, highlighted in red in the following screenshot.
![memref](https://github.com/user-attachments/assets/3a5697a3-b668-40ea-879f-b1a27080ddaf)
Also for single-address-space architectures, I could imagine that it would be useful to have memory references like `.rodata + 0x1234` based on the section names or `my_function + 0x1234` based on symbol names. Those memory references would convey more information to the user, and would also be stable across restarts where ASLR might shuffle the sections around. But that's an idea for another day / another commit
https://github.com/llvm/llvm-project/pull/104317
More information about the lldb-commits
mailing list