diff options
author | Gregory Anders <greg@gpanders.com> | 2023-09-01 16:02:20 -0500 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-09-20 10:59:47 -0600 |
commit | 0b7de6d3ee07653e97e65a2968742c93b7102f62 (patch) | |
tree | 4f90cf6e3dfa02f9bd013e86db73b02eb5a7c0df | |
parent | 61830fcb31d9b66c7af76eefc152b66a170fb49c (diff) | |
download | binutils-0b7de6d3ee07653e97e65a2968742c93b7102f62.zip binutils-0b7de6d3ee07653e97e65a2968742c93b7102f62.tar.gz binutils-0b7de6d3ee07653e97e65a2968742c93b7102f62.tar.bz2 |
gdb/dap: only include sourceReference if file path does not exist
According to the DAP specification if the "sourceReference" field is
included in a Source object, then the DAP client _must_ make a "source"
request to the debugger to retrieve file contents, even if the Source
object also includes path information.
If the Source's path field is a valid path that the DAP client is able
to read from the filesystem, having to make another request to the
debugger to get the file contents is wasteful and leads to incorrect
results (DAP clients will try to get the contents from the server and
display those contents as a file with the name in "source.path", but
this will conflict with the _acutal_ existing file at "source.path").
Instead, only set "sourceReference" if the source file path does not
exist.
Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r-- | gdb/python/lib/gdb/dap/sources.py | 16 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dap/sources.exp | 9 |
2 files changed, 16 insertions, 9 deletions
diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index 7fa1ae4..00a7070 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os + import gdb from .server import request, capability @@ -41,16 +43,20 @@ def make_source(fullname, filename): if fullname in _source_map: result = _source_map[fullname] else: - global _next_source result = { "name": filename, "path": fullname, - "sourceReference": _next_source, } + + if not os.path.exists(fullname): + global _next_source + result["sourceReference"] = _next_source + + global _id_map + _id_map[_next_source] = result + _next_source += 1 + _source_map[fullname] = result - global _id_map - _id_map[_next_source] = result - _next_source += 1 return result diff --git a/gdb/testsuite/gdb.dap/sources.exp b/gdb/testsuite/gdb.dap/sources.exp index a12c208..f1b19ac 100644 --- a/gdb/testsuite/gdb.dap/sources.exp +++ b/gdb/testsuite/gdb.dap/sources.exp @@ -30,20 +30,21 @@ if {[dap_launch $testfile stop_at_main 1] == ""} { } set obj [dap_check_request_and_response loadedSources loadedSources] -set ref 0 +set path "" foreach src [dict get [lindex $obj 0] body sources] { if {[file tail [dict get $src name]] == "sources.c"} { - set ref [dict get $src sourceReference] + set path [dict get $src path] } } -if {$ref == 0} { +if {$path == ""} { fail "sources.c in loadedSources" } else { pass "sources.c in loadedSources" set obj [dap_check_request_and_response "get source" source \ - [format {o sourceReference [i %d]} $ref]] + [format {o source [o path [s %s]] \ + sourceReference [i 0]} $path]] set text [dict get [lindex $obj 0] body content] gdb_assert {[string first "Distinguishing comment" $text] != -1} } |