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>
This commit is contained in:
Tom Tromey
2024-07-05 10:31:27 -06:00
parent 8be33827cd
commit 0341f2767a
4 changed files with 20 additions and 9 deletions

View 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"]:

View File

@@ -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)

View File

@@ -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,

View 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)