]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dap: fix decode_source
authoroltolm <oleg.tolmatcev@gmail.com>
Sat, 10 May 2025 08:56:12 +0000 (10:56 +0200)
committerTom Tromey <tromey@adacore.com>
Mon, 12 May 2025 17:47:31 +0000 (11:47 -0600)
The documentation for the Source interface says

   * The path of the source to be shown in the UI.
   * It is only used to locate and load the content of the source if no
   * `sourceReference` is specified (or its value is 0).

but the code used `path` first. I fixed it to use `sourceReference` first.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/lib/gdb/dap/sources.py

index 625c01f5d12d6ad5e3e86b440a610fdafbede36c..efcd7995e4c4240d990634d813b6c3bcac916711 100644 (file)
@@ -64,9 +64,9 @@ 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:
+    if "sourceReference" not in source or source["sourceReference"] <= 0:
+        if "path" in source:
+            return source["path"]
         raise DAPException("either 'path' or 'sourceReference' must appear in Source")
     ref = source["sourceReference"]
     if ref not in _id_map: