[binutils-gdb] gdb/dap: fix decode_source

Tom Tromey tromey@sourceware.org
Mon May 12 17:49:45 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b33b677beadcb40369b1942169a3cdda636755c4

commit b33b677beadcb40369b1942169a3cdda636755c4
Author: oltolm <oleg.tolmatcev@gmail.com>
Date:   Sat May 10 10:56:12 2025 +0200

    gdb/dap: fix decode_source
    
    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>

Diff:
---
 gdb/python/lib/gdb/dap/sources.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py
index 625c01f5d12..efcd7995e4c 100644
--- a/gdb/python/lib/gdb/dap/sources.py
+++ b/gdb/python/lib/gdb/dap/sources.py
@@ -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:


More information about the Gdb-cvs mailing list