diff options
author | Tom Tromey <tromey@adacore.com> | 2024-07-05 10:31:27 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-08-14 10:08:58 -0600 |
commit | 0341f2767adab5281f040eadd276d711afec96f0 (patch) | |
tree | 9470bb63f16b24cc7d249945a211d9b1d2cb5b4a /gdb/python | |
parent | 8be33827cdc57fd7c31e84966f3c445b986be4ff (diff) | |
download | binutils-0341f2767adab5281f040eadd276d711afec96f0.zip binutils-0341f2767adab5281f040eadd276d711afec96f0.tar.gz binutils-0341f2767adab5281f040eadd276d711afec96f0.tar.bz2 |
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 <keiths@redhat.com>
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/dap/breakpoint.py | 11 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/locations.py | 5 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/sources.py | 6 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/startup.py | 7 |
4 files changed, 20 insertions, 9 deletions
diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index e60265b..0ffb507 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 92e68f5..967322f 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 ad0c913..a9f4ea6 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 3952447..a3f048b 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) |