forked from Imagelibrary/binutils-gdb
Nearly every DAP request implementation forwards its work to the gdb
thread, using send_gdb_with_response. This patch refactors the
'request' decorator to make this automatic, and to provide some
parameters so that the unusual requests can express their needs as
well.
In a few spots this simplifies the code by removing an unnecessary
helper function. This could be done in more places as well if we
wanted.
The main motivation for this patch is that I thought it would be
helpful for cancellation. I am still working on that, but meanwhile
the parameterization of 'request' makes it easy to handle the
'notStopped' response as well.
Reviewed-by: Kévin Le Gouguec <legouguec@adacore.com>
(cherry picked from commit c98921b258)
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
# 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
|
|
|
|
|
|
@request("readMemory")
|
|
@capability("supportsReadMemoryRequest")
|
|
def read_memory(*, memoryReference: str, offset: int = 0, count: int, **extra):
|
|
addr = int(memoryReference, 0) + offset
|
|
buf = gdb.selected_inferior().read_memory(addr, count)
|
|
return {
|
|
"address": hex(addr),
|
|
"data": base64.b64encode(buf).decode("ASCII"),
|
|
}
|
|
|
|
|
|
@request("writeMemory")
|
|
@capability("supportsWriteMemoryRequest")
|
|
def write_memory(*, memoryReference: str, offset: int = 0, data: str, **extra):
|
|
addr = int(memoryReference, 0) + offset
|
|
buf = base64.b64decode(data)
|
|
gdb.selected_inferior().write_memory(addr, buf)
|