Put "source" into DAP scope

Message ID 20240510184945.2943754-1-tromey@adacore.com
State New
Headers
Series Put "source" into DAP scope |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom Tromey May 10, 2024, 6:49 p.m. UTC
  I noticed a FIXME comment in the DAP code about adding a "source"
field to a scope.  This is easy to implement; I don't know why I
didn't do this originally.
---
 gdb/python/lib/gdb/dap/scopes.py     | 5 ++++-
 gdb/testsuite/gdb.dap/ada-scopes.exp | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
  

Comments

Tom Tromey June 4, 2024, 4:36 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> I noticed a FIXME comment in the DAP code about adding a "source"
Tom> field to a scope.  This is easy to implement; I don't know why I
Tom> didn't do this originally.

I'm checking this in.

Tom
  

Patch

diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py
index 8cd860141d6..09f440e087c 100644
--- a/gdb/python/lib/gdb/dap/scopes.py
+++ b/gdb/python/lib/gdb/dap/scopes.py
@@ -17,6 +17,7 @@  import gdb
 
 from .frames import frame_for_id
 from .server import request
+from .sources import make_source
 from .startup import in_gdb_thread
 from .varref import BaseReference
 
@@ -93,7 +94,9 @@  class _ScopeReference(BaseReference):
         result["namedVariables"] = self.child_count()
         if self.line is not None:
             result["line"] = self.line
-            # FIXME construct a Source object
+        filename = self.frame.filename()
+        if filename is not None:
+            result["source"] = make_source(filename)
         return result
 
     def has_children(self):
diff --git a/gdb/testsuite/gdb.dap/ada-scopes.exp b/gdb/testsuite/gdb.dap/ada-scopes.exp
index 12004f8fc32..4d895a5270d 100644
--- a/gdb/testsuite/gdb.dap/ada-scopes.exp
+++ b/gdb/testsuite/gdb.dap/ada-scopes.exp
@@ -59,6 +59,7 @@  set scopes [dict get [lindex $scopes 0] body scopes]
 # just in case something changes.
 lassign $scopes scope _ignore
 gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
+gdb_assert {[dict get $scope source name] == "prog.adb"} "scope has source"
 
 gdb_assert {[dict get $scope namedVariables] == 2} "two vars in scope"