Handle DAP supportsVariableType capability
authorTom Tromey <tromey@adacore.com>
Tue, 16 May 2023 13:36:08 +0000 (07:36 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 12 Jun 2023 18:09:46 +0000 (12:09 -0600)
A DAP client can report the supportsVariableType capability in the
initialize request.  In this case, gdb can include the type of a
variable or expression in various results.

gdb/python/lib/gdb/dap/evaluate.py
gdb/python/lib/gdb/dap/server.py
gdb/python/lib/gdb/dap/varref.py
gdb/testsuite/gdb.dap/basic-dap.exp
gdb/testsuite/lib/dap-support.exp

index 1db6962f8e09d01c78c28e652146ae0e185abcf1..2b400651b67ec463e98ddf62f203f45149b44b75 100644 (file)
@@ -70,7 +70,6 @@ def _repl(command, frame_id):
     }
 
 
-# FIXME supportsVariableType handling
 @request("evaluate")
 def eval_request(
     *,
index be66676f73019b7e7f5dd7f6d502473208bc30d4..b1c75ab967f4366f4e5a54ff50d80a83a35fe8cf 100644 (file)
@@ -186,6 +186,17 @@ def capability(name, value=True):
     return wrap
 
 
+def client_bool_capability(name):
+    """Return the value of a boolean client capability.
+
+    If the capability was not specified, or did not have boolean type,
+    False is returned."""
+    global _server
+    if name in _server.config and isinstance(_server.config[name], bool):
+        return _server.config[name]
+    return False
+
+
 @request("initialize")
 def initialize(**args):
     global _server, _capabilities
index 88c34c204684e7c1e7851d867e002302b232e164..23f18d647c3d901f43ebe687dfe122fa8f31dd43 100644 (file)
@@ -15,6 +15,7 @@
 
 import gdb
 from .startup import in_gdb_thread
+from .server import client_bool_capability
 from abc import abstractmethod
 
 
@@ -165,6 +166,8 @@ class VariableReference(BaseReference):
             result["memoryReference"] = hex(int(self.value))
         elif self.value.address is not None:
             result["memoryReference"] = hex(int(self.value.address))
+        if client_bool_capability("supportsVariableType"):
+            result["type"] = str(self.value.type)
         return result
 
     @in_gdb_thread
index 9aaa94051e66efb02bf75fab5ecbf871b8d12e83..ca0d1be9f1249a1b0a1c1489f8b7cc1d4035fa64 100644 (file)
@@ -162,7 +162,8 @@ dap_match_values "global value in main" [lindex $obj 0] \
 set obj [dap_check_request_and_response "set global in main" \
             setExpression {o expression [s global_variable] value [s 23]}]
 dap_match_values "global value in main after set" [lindex $obj 0] \
-    "body result" 23
+    "body result" 23 \
+    "body type" int
 
 set obj [dap_request_and_response \
             evaluate {o expression [s nosuchvariable]}]
index 8667164fa11ac85718bb04c01bbd27cebd3b045f..5c547480d09ad85d4c8878b46aa54e8119487d4b 100644 (file)
@@ -230,7 +230,9 @@ proc _dap_initialize {name} {
     if {[dap_gdb_start]} {
        return ""
     }
-    return [dap_check_request_and_response $name initialize]
+    return [dap_check_request_and_response $name initialize \
+               {o clientID [s "gdb testsuite"] \
+                    supportsVariableType [l true]}]
 }
 
 # Start gdb, send a DAP initialize request, and then a launch request