diff options
author | Tom Tromey <tromey@adacore.com> | 2023-07-27 14:21:13 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-08-01 13:12:24 -0600 |
commit | 4b6521cf69f45050f857edeb592bc46ea198041d (patch) | |
tree | fc8da2310d85a8243c69cadbee9d3d6dff121d0d | |
parent | c64cba1b56ea7dd7b0b2107fd22ef989dfb5921e (diff) | |
download | gdb-4b6521cf69f45050f857edeb592bc46ea198041d.zip gdb-4b6521cf69f45050f857edeb592bc46ea198041d.tar.gz gdb-4b6521cf69f45050f857edeb592bc46ea198041d.tar.bz2 |
Handle Source in DAP breakpointLocations
This changes the DAP breakpointLocations request to accept a Source
and to decode it properly.
-rw-r--r-- | gdb/python/lib/gdb/dap/locations.py | 12 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/sources.py | 16 |
2 files changed, 20 insertions, 8 deletions
diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py index 594f1ba..a299e8d 100644 --- a/gdb/python/lib/gdb/dap/locations.py +++ b/gdb/python/lib/gdb/dap/locations.py @@ -19,11 +19,13 @@ import gdb from typing import Optional from .server import capability, request +from .sources import decode_source from .startup import in_gdb_thread, send_gdb_with_response @in_gdb_thread -def _find_lines(filename, start_line, end_line): +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"] @@ -44,10 +46,4 @@ def _find_lines(filename, start_line, end_line): def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra): if endLine is None: endLine = line - if "path" in source: - filename = source["path"] - elif "name" in source: - filename = source["name"] - else: - raise Exception("") - return send_gdb_with_response(lambda: _find_lines(filename, line, endLine)) + return send_gdb_with_response(lambda: _find_lines(source, line, endLine)) diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index 50b5909..8063528 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -55,6 +55,22 @@ def make_source(fullname, filename): @in_gdb_thread +def decode_source(source): + """Decode a Source object. + + Finds and returns the filename of a given Source object.""" + if "path" in source: + return source["path"] + if "sourceReference" not in source: + raise Exception("either 'path' or 'sourceReference' must appear in Source") + ref = source["sourceReference"] + global _id_map + if ref not in _id_map: + raise Exception("no sourceReference " + str(ref)) + return _id_map[ref]["path"] + + +@in_gdb_thread def _sources(): result = [] for elt in gdb.execute_mi("-file-list-exec-source-files")["files"]: |