diff options
author | Tom Tromey <tromey@adacore.com> | 2023-11-28 09:18:13 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-12-05 08:51:05 -0700 |
commit | dcdb91b3a663417ed4b51d9a145c76268541127b (patch) | |
tree | 85329b10b90a9bc80c98cf50ca6630dd1a6b38a2 /gdb | |
parent | e60675a228a8ecd2cfdc7e45cb315a1838b91f74 (diff) | |
download | binutils-dcdb91b3a663417ed4b51d9a145c76268541127b.zip binutils-dcdb91b3a663417ed4b51d9a145c76268541127b.tar.gz binutils-dcdb91b3a663417ed4b51d9a145c76268541127b.tar.bz2 |
Remove some DAP helper functions
Now that DAP requests are normally run on the gdb thread, some DAP
helper functions are no longer needed. Removing these simplifies the
code.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/python/lib/gdb/dap/disassemble.py | 32 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/evaluate.py | 53 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/launch.py | 35 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/locations.py | 20 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/modules.py | 17 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/scopes.py | 20 |
6 files changed, 66 insertions, 111 deletions
diff --git a/gdb/python/lib/gdb/dap/disassemble.py b/gdb/python/lib/gdb/dap/disassemble.py index 069549e..493c8de 100644 --- a/gdb/python/lib/gdb/dap/disassemble.py +++ b/gdb/python/lib/gdb/dap/disassemble.py @@ -16,11 +16,19 @@ import gdb from .server import request, capability -from .startup import in_gdb_thread -@in_gdb_thread -def _disassemble(pc, skip_insns, count): +@request("disassemble") +@capability("supportsDisassembleRequest") +def disassemble( + *, + memoryReference: str, + offset: int = 0, + instructionOffset: int = 0, + instructionCount: int, + **extra +): + pc = int(memoryReference, 0) + offset inf = gdb.selected_inferior() try: arch = gdb.selected_frame().architecture() @@ -28,8 +36,8 @@ def _disassemble(pc, skip_insns, count): # Maybe there was no frame. arch = inf.architecture() result = [] - total_count = skip_insns + count - for elt in arch.disassemble(pc, count=total_count)[skip_insns:]: + total_count = instructionOffset + instructionCount + for elt in arch.disassemble(pc, count=total_count)[instructionOffset:]: mem = inf.read_memory(elt["addr"], elt["length"]) result.append( { @@ -41,17 +49,3 @@ def _disassemble(pc, skip_insns, count): return { "instructions": result, } - - -@request("disassemble") -@capability("supportsDisassembleRequest") -def disassemble( - *, - memoryReference: str, - offset: int = 0, - instructionOffset: int = 0, - instructionCount: int, - **extra -): - pc = int(memoryReference, 0) + offset - return _disassemble(pc, instructionOffset, instructionCount) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 67e103e..d39e787 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -57,20 +57,6 @@ class _SetResult(VariableReference): super().__init__(None, value, "value") -# Helper function to perform an assignment. -@in_gdb_thread -def _set_expression(expression, value, frame_id, value_format): - with apply_format(value_format): - global_context = True - if frame_id is not None: - select_frame(frame_id) - global_context = False - lhs = gdb.parse_and_eval(expression, global_context=global_context) - rhs = gdb.parse_and_eval(value, global_context=global_context) - lhs.assign(rhs) - return _SetResult(lhs).to_object() - - # Helper function to evaluate a gdb command in a certain frame. @in_gdb_thread def _repl(command, frame_id): @@ -106,14 +92,6 @@ def eval_request( raise Exception('unknown evaluate context "' + context + '"') -@in_gdb_thread -def _variables(ref, start, count, value_format): - with apply_format(value_format): - var = find_variable(ref) - children = var.fetch_children(start, count) - return [x.to_object() for x in children] - - @request("variables") # Note that we ignore the 'filter' field. That seems to be # specific to javascript. @@ -125,7 +103,10 @@ def variables( if not client_bool_capability("supportsVariablePaging"): start = 0 count = 0 - return {"variables": _variables(variablesReference, start, count, format)} + with apply_format(format): + var = find_variable(variablesReference) + children = var.fetch_children(start, count) + return {"variables": [x.to_object() for x in children]} @capability("supportsSetExpression") @@ -133,18 +114,15 @@ def variables( def set_expression( *, expression: str, value: str, frameId: Optional[int] = None, format=None, **args ): - return _set_expression(expression, value, frameId, format) - - -# Helper function to perform an assignment. -@in_gdb_thread -def _set_variable(ref, name, value, value_format): - with apply_format(value_format): - var = find_variable(ref) - lhs = var.find_child_by_name(name) - rhs = gdb.parse_and_eval(value) + with apply_format(format): + global_context = True + if frameId is not None: + select_frame(frameId) + global_context = False + lhs = gdb.parse_and_eval(expression, global_context=global_context) + rhs = gdb.parse_and_eval(value, global_context=global_context) lhs.assign(rhs) - return lhs.to_object() + return _SetResult(lhs).to_object() @capability("supportsSetVariable") @@ -152,4 +130,9 @@ def _set_variable(ref, name, value, value_format): def set_variable( *, variablesReference: int, name: str, value: str, format=None, **args ): - return _set_variable(variablesReference, name, value, format) + with apply_format(format): + var = find_variable(variablesReference) + lhs = var.find_child_by_name(name) + rhs = gdb.parse_and_eval(value) + lhs.assign(rhs) + return lhs.to_object() diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index ee6ee05..995641b 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -20,7 +20,7 @@ from typing import Mapping, Optional, Sequence from .events import exec_and_expect_stop, expect_process from .server import request, capability -from .startup import in_gdb_thread, exec_and_log +from .startup import exec_and_log # The program being launched, or None. This should only be accessed @@ -28,24 +28,6 @@ from .startup import in_gdb_thread, exec_and_log _program = None -@in_gdb_thread -def _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram): - if cwd is not None: - exec_and_log("cd " + cwd) - if program is not None: - exec_and_log("file " + program) - inf = gdb.selected_inferior() - if stopAtBeginningOfMainSubprogram: - main = inf.main_name - if main is not None: - exec_and_log("tbreak " + main) - inf.arguments = args - if env is not None: - inf.clear_env() - for name, value in env.items(): - inf.set_env(name, value) - - # Any parameters here are necessarily extensions -- DAP requires this # from implementations. Any additions or changes here should be # documented in the gdb manual. @@ -61,7 +43,20 @@ def launch( ): global _program _program = program - _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram) + if cwd is not None: + exec_and_log("cd " + cwd) + if program is not None: + exec_and_log("file " + program) + inf = gdb.selected_inferior() + if stopAtBeginningOfMainSubprogram: + main = inf.main_name + if main is not None: + exec_and_log("tbreak " + main) + inf.arguments = args + if env is not None: + inf.clear_env() + for name, value in env.items(): + inf.set_env(name, value) @request("attach") diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py index 032174d..30e9b6f 100644 --- a/gdb/python/lib/gdb/dap/locations.py +++ b/gdb/python/lib/gdb/dap/locations.py @@ -20,18 +20,6 @@ from typing import Optional from .server import capability, request from .sources import decode_source -from .startup import in_gdb_thread - - -@in_gdb_thread -def _find_lines(source, start_line, end_line): - filename = decode_source(source) - lines = set() - for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]: - line = entry["line"] - if line >= start_line and line <= end_line: - lines.add(line) - return {"breakpoints": [{"line": x} for x in sorted(lines)]} # Note that the spec says that the arguments to this are optional. @@ -46,4 +34,10 @@ def _find_lines(source, start_line, end_line): def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra): if endLine is None: endLine = line - return _find_lines(source, line, endLine) + filename = decode_source(source) + lines = set() + for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]: + this_line = entry["line"] + if this_line >= line and this_line <= endLine: + lines.add(this_line) + return {"breakpoints": [{"line": x} for x in sorted(lines)]} diff --git a/gdb/python/lib/gdb/dap/modules.py b/gdb/python/lib/gdb/dap/modules.py index 87a4f6b..6f1d17b 100644 --- a/gdb/python/lib/gdb/dap/modules.py +++ b/gdb/python/lib/gdb/dap/modules.py @@ -45,22 +45,17 @@ def make_module(objf): return result -@in_gdb_thread -def _modules(start, count): +@capability("supportsModulesRequest") +@request("modules") +def modules(*, startModule: int = 0, moduleCount: int = 0, **args): # Don't count invalid objfiles or separate debug objfiles. objfiles = [x for x in gdb.objfiles() if is_module(x)] - if count == 0: + if moduleCount == 0: # Use all items. last = len(objfiles) else: - last = start + count + last = startModule + moduleCount return { - "modules": [make_module(x) for x in objfiles[start:last]], + "modules": [make_module(x) for x in objfiles[startModule:last]], "totalModules": len(objfiles), } - - -@capability("supportsModulesRequest") -@request("modules") -def modules(*, startModule: int = 0, moduleCount: int = 0, **args): - return _modules(startModule, moduleCount) diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py index 63cd325..111fb82 100644 --- a/gdb/python/lib/gdb/dap/scopes.py +++ b/gdb/python/lib/gdb/dap/scopes.py @@ -107,14 +107,13 @@ class _RegisterReference(_ScopeReference): ) -# Helper function to create a DAP scopes for a given frame ID. -@in_gdb_thread -def _get_scope(id): +@request("scopes") +def scopes(*, frameId: int, **extra): global frame_to_scope - if id in frame_to_scope: - scopes = frame_to_scope[id] + if frameId in frame_to_scope: + scopes = frame_to_scope[frameId] else: - frame = frame_for_id(id) + frame = frame_for_id(frameId) scopes = [] # Make sure to handle the None case as well as the empty # iterator case. @@ -127,10 +126,5 @@ def _get_scope(id): if locs: scopes.append(_ScopeReference("Locals", "locals", frame, locs)) scopes.append(_RegisterReference("Registers", frame)) - frame_to_scope[id] = scopes - return [x.to_object() for x in scopes] - - -@request("scopes") -def scopes(*, frameId: int, **extra): - return {"scopes": _get_scope(frameId)} + frame_to_scope[frameId] = scopes + return {"scopes": [x.to_object() for x in scopes]} |