diff options
author | Tom Tromey <tromey@adacore.com> | 2023-03-02 13:51:17 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-04-03 08:47:52 -0600 |
commit | d466f7492eccccb0f3c0936c12b5b140e139e353 (patch) | |
tree | 714cdf293c6cffff54ba065ce530cf349fb21045 /gdb/python | |
parent | 60a13bbcdfb0ce008a77563cea0c34c830d7b170 (diff) | |
download | gdb-d466f7492eccccb0f3c0936c12b5b140e139e353.zip gdb-d466f7492eccccb0f3c0936c12b5b140e139e353.tar.gz gdb-d466f7492eccccb0f3c0936c12b5b140e139e353.tar.bz2 |
Add readMemory and writeMemory requests to DAP
This adds the DAP readMemory and writeMemory requests. A small change
to the evaluation code is needed in order to test this -- this is one
of the few ways for a client to actually acquire a memory reference.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/dap/__init__.py | 1 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/memory.py | 51 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/varref.py | 5 |
3 files changed, 57 insertions, 0 deletions
diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index 9038e10..014fd08 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -25,6 +25,7 @@ from . import bt from . import disassemble from . import evaluate from . import launch +from . import memory from . import next from . import pause from . import scopes diff --git a/gdb/python/lib/gdb/dap/memory.py b/gdb/python/lib/gdb/dap/memory.py new file mode 100644 index 0000000..7eb8a27 --- /dev/null +++ b/gdb/python/lib/gdb/dap/memory.py @@ -0,0 +1,51 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import base64 +import gdb + +from .server import request, capability +from .startup import send_gdb_with_response, in_gdb_thread + + +@in_gdb_thread +def _read_memory(addr, count): + buf = gdb.selected_inferior().read_memory(addr, count) + return base64.b64encode(buf).decode("ASCII") + + +@request("readMemory") +@capability("supportsReadMemoryRequest") +def read_memory(*, memoryReference, offset=0, count, **extra): + addr = int(memoryReference, 0) + offset + buf = send_gdb_with_response(lambda: _read_memory(addr, count)) + return { + "address": hex(addr), + "data": buf, + } + + +@in_gdb_thread +def _write_memory(addr, contents): + buf = base64.b64decode(contents) + gdb.selected_inferior().write_memory(addr, buf) + + +@request("writeMemory") +@capability("supportsWriteMemoryRequest") +def write_memory(*, memoryReference, offset=0, data, **extra): + addr = int(memoryReference, 0) + offset + send_gdb_with_response(lambda: _write_memory(addr, data)) + return {} diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 888415a..88c34c2 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -116,6 +116,7 @@ class VariableReference(BaseReference): RESULT_NAME can be used to change how the simple string result is emitted in the result dictionary.""" super().__init__(name) + self.value = value self.printer = gdb.printing.make_visualizer(value) self.result_name = result_name # We cache all the children we create. @@ -160,6 +161,10 @@ class VariableReference(BaseReference): result["indexedVariables"] = num_children else: result["namedVariables"] = num_children + if self.value.type.code == gdb.TYPE_CODE_PTR: + result["memoryReference"] = hex(int(self.value)) + elif self.value.address is not None: + result["memoryReference"] = hex(int(self.value.address)) return result @in_gdb_thread |