From: Tom Tromey Date: Fri, 5 Jul 2024 16:31:27 +0000 (-0600) Subject: Introduce exec_mi_and_log for DAP X-Git-Tag: gdb-16-branchpoint~1139 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0341f2767adab5281f040eadd276d711afec96f0;p=thirdparty%2Fbinutils-gdb.git Introduce exec_mi_and_log for DAP 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 --- diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index e60265b2f69..0ffb5074670 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -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"]: diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py index 92e68f5e235..967322fbeaf 100644 --- a/gdb/python/lib/gdb/dap/locations.py +++ b/gdb/python/lib/gdb/dap/locations.py @@ -16,10 +16,9 @@ # 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) diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index ad0c913c8c1..a9f4ea62f69 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -15,10 +15,8 @@ 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, diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index 3952447e4d7..a3f048bd396 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -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)