public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Remove some DAP helper functions
@ 2023-12-05 15:52 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-12-05 15:52 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dcdb91b3a663417ed4b51d9a145c76268541127b

commit dcdb91b3a663417ed4b51d9a145c76268541127b
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Nov 28 09:18:13 2023 -0700

    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.

Diff:
---
 gdb/python/lib/gdb/dap/disassemble.py | 32 +++++++++------------
 gdb/python/lib/gdb/dap/evaluate.py    | 53 ++++++++++++-----------------------
 gdb/python/lib/gdb/dap/launch.py      | 35 ++++++++++-------------
 gdb/python/lib/gdb/dap/locations.py   | 20 +++++--------
 gdb/python/lib/gdb/dap/modules.py     | 17 ++++-------
 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 069549eb7f8..493c8de7fe4 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 67e103e2ca7..d39e7879205 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 ee6ee05bac3..995641bd945 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 032174df9c8..30e9b6f5a76 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 87a4f6be669..6f1d17bf6f3 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 63cd3255b8a..111fb824c62 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]}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-05 15:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05 15:52 [binutils-gdb] Remove some DAP helper functions Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).