]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce exec_mi_and_log for DAP
authorTom Tromey <tromey@adacore.com>
Fri, 5 Jul 2024 16:31:27 +0000 (10:31 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 14 Aug 2024 16:08:58 +0000 (10:08 -0600)
This adds a new exec_mi_and_log function that wraps gdb.execute_mi and
logs the command.  This can be handy when debugging DAP.

Reviewed-by: Keith Seitz <keiths@redhat.com>
gdb/python/lib/gdb/dap/breakpoint.py
gdb/python/lib/gdb/dap/locations.py
gdb/python/lib/gdb/dap/sources.py
gdb/python/lib/gdb/dap/startup.py

index e60265b2f69d83c8e4a9d33f2286a947d2d77884..0ffb5074670615dd021dc54e614c53dea4d06ee6 100644 (file)
@@ -23,7 +23,14 @@ import gdb
 
 from .server import capability, request, send_event
 from .sources import make_source
-from .startup import DAPException, LogLevel, in_gdb_thread, log_stack, parse_and_eval
+from .startup import (
+    DAPException,
+    LogLevel,
+    exec_mi_and_log,
+    in_gdb_thread,
+    log_stack,
+    parse_and_eval,
+)
 from .typecheck import type_check
 
 # True when suppressing new breakpoint events.
@@ -368,7 +375,7 @@ def _catch_exception(filterId, **args):
         cmd = "-catch-" + filterId
     else:
         raise DAPException("Invalid exception filterID: " + str(filterId))
-    result = gdb.execute_mi(cmd)
+    result = exec_mi_and_log(cmd)
     # A little lame that there's no more direct way.
     for bp in gdb.breakpoints():
         if bp.number == result["bkptno"]:
index 92e68f5e23593e7f12e6c8667d5f94e21aadcb67..967322fbeafaa6d63bdc197aa3d78f45cf6dff80 100644 (file)
 # This is deprecated in 3.9, but required in older versions.
 from typing import Optional
 
-import gdb
-
 from .server import capability, request
 from .sources import decode_source
+from .startup import exec_mi_and_log
 
 
 # Note that the spec says that the arguments to this are optional.
@@ -36,7 +35,7 @@ def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **
         endLine = line
     filename = decode_source(source)
     lines = set()
-    for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]:
+    for entry in exec_mi_and_log("-symbol-list-lines", filename)["lines"]:
         this_line = entry["line"]
         if this_line >= line and this_line <= endLine:
             lines.add(this_line)
index ad0c913c8c1fd3ebb731f5c239dec01c6d6f1c72..a9f4ea62f69909a1718d6fb2f720ce71dda4d5b2 100644 (file)
 
 import os
 
-import gdb
-
 from .server import capability, request
-from .startup import DAPException, in_gdb_thread
+from .startup import DAPException, exec_mi_and_log, in_gdb_thread
 
 # The next available source reference ID.  Must be greater than 0.
 _next_source = 1
@@ -83,7 +81,7 @@ def decode_source(source):
 @capability("supportsLoadedSourcesRequest")
 def loaded_sources(**extra):
     result = []
-    for elt in gdb.execute_mi("-file-list-exec-source-files")["files"]:
+    for elt in exec_mi_and_log("-file-list-exec-source-files")["files"]:
         result.append(make_source(elt["fullname"], elt["file"]))
     return {
         "sources": result,
index 3952447e4d7732d4788f5d3a82d78adb46bdd310..a3f048bd396be4f1b9d0dbf53e89c4cacfbd0c4e 100644 (file)
@@ -217,3 +217,10 @@ def exec_and_log(cmd, propagate_exception=False):
             raise DAPException(str(e)) from e
         else:
             log_stack()
+
+
+@in_gdb_thread
+def exec_mi_and_log(*args):
+    """Wrap gdb.execute_mi, logging the command."""
+    log("+++ " + str(args))
+    return gdb.execute_mi(*args)