Преглед на файлове

Debugger: Correctly handle clients without supportsVariableType

Fixes: #25057
Ben McMorran преди 2 години
родител
ревизия
e02cf3f190
променени са 4 файла, в които са добавени 58 реда и са изтрити 23 реда
  1. 20 19
      Source/cmDebuggerVariables.cxx
  2. 8 4
      Tests/CMakeLib/testDebugger.h
  3. 29 0
      Tests/CMakeLib/testDebuggerVariables.cxx
  4. 1 0
      Tests/CMakeLib/testDebuggerVariablesHelper.cxx

+ 20 - 19
Source/cmDebuggerVariables.cxx

@@ -78,15 +78,16 @@ dap::array<dap::Variable> cmDebuggerVariables::HandleVariablesRequest()
           entry.Value.empty()) {
         continue;
       }
-      variables.push_back(dap::Variable{ {},
-                                         {},
-                                         {},
-                                         entry.Name,
-                                         {},
-                                         PrivateDataHint,
-                                         entry.Type,
-                                         entry.Value,
-                                         0 });
+      variables.push_back(dap::Variable{
+        {},
+        {},
+        {},
+        entry.Name,
+        {},
+        PrivateDataHint,
+        SupportsVariableType ? entry.Type : dap::optional<dap::string>(),
+        entry.Value,
+        0 });
     }
   }
 
@@ -106,16 +107,16 @@ void cmDebuggerVariables::EnumerateSubVariablesIfAny(
 {
   dap::array<dap::Variable> ret;
   for (auto const& variables : SubVariables) {
-    toBeReturned.emplace_back(
-      dap::Variable{ {},
-                     {},
-                     {},
-                     variables->GetName(),
-                     {},
-                     PrivatePropertyHint,
-                     SupportsVariableType ? "collection" : nullptr,
-                     variables->GetValue(),
-                     variables->GetId() });
+    toBeReturned.emplace_back(dap::Variable{
+      {},
+      {},
+      {},
+      variables->GetName(),
+      {},
+      PrivatePropertyHint,
+      SupportsVariableType ? "collection" : dap::optional<dap::string>(),
+      variables->GetValue(),
+      variables->GetId() });
   }
 }
 

+ 8 - 4
Tests/CMakeLib/testDebugger.h

@@ -19,11 +19,15 @@
   do {                                                                        \
     ASSERT_TRUE(x.name == expectedName);                                      \
     ASSERT_TRUE(x.value == expectedValue);                                    \
-    ASSERT_TRUE(x.type.value() == expectedType);                              \
-    ASSERT_TRUE(x.evaluateName.has_value() == false);                         \
-    if (std::string(expectedType) == "collection") {                          \
-      ASSERT_TRUE(x.variablesReference != 0);                                 \
+    if (expectedType == nullptr) {                                            \
+      ASSERT_TRUE(x.type == dap::optional<dap::string>());                    \
+    } else {                                                                  \
+      ASSERT_TRUE(x.type == dap::optional<dap::string>(expectedType));        \
+      if (std::string(expectedType) == "collection") {                        \
+        ASSERT_TRUE(x.variablesReference != 0);                               \
+      }                                                                       \
     }                                                                         \
+    ASSERT_TRUE(x.evaluateName.has_value() == false);                         \
   } while (false)
 
 #define ASSERT_VARIABLE_REFERENCE(x, expectedName, expectedValue,             \

+ 29 - 0
Tests/CMakeLib/testDebuggerVariables.cxx

@@ -8,6 +8,7 @@
 #include <unordered_set>
 #include <vector>
 
+#include <cm3p/cppdap/optional.h>
 #include <cm3p/cppdap/protocol.h>
 #include <cm3p/cppdap/types.h>
 
@@ -174,6 +175,33 @@ static bool testSortTheResult()
   return true;
 }
 
+static bool testNoSupportsVariableType()
+{
+  auto variablesManager =
+    std::make_shared<cmDebugger::cmDebuggerVariablesManager>();
+
+  auto vars = std::make_shared<cmDebugger::cmDebuggerVariables>(
+    variablesManager, "Variables", false, []() {
+      return std::vector<cmDebugger::cmDebuggerVariableEntry>{ { "test",
+                                                                 "value" } };
+    });
+
+  auto subvars = std::make_shared<cmDebugger::cmDebuggerVariables>(
+    variablesManager, "Children", false);
+
+  vars->AddSubVariables(subvars);
+
+  dap::array<dap::Variable> variables =
+    variablesManager->HandleVariablesRequest(
+      CreateVariablesRequest(vars->GetId()));
+
+  ASSERT_TRUE(variables.size() == 2);
+  ASSERT_VARIABLE(variables[0], "Children", "", nullptr);
+  ASSERT_VARIABLE(variables[1], "test", "value", nullptr);
+
+  return true;
+}
+
 int testDebuggerVariables(int, char*[])
 {
   return runTests(std::vector<std::function<bool()>>{
@@ -181,5 +209,6 @@ int testDebuggerVariables(int, char*[])
     testConstructors,
     testIgnoreEmptyStringEntries,
     testSortTheResult,
+    testNoSupportsVariableType,
   });
 }

+ 1 - 0
Tests/CMakeLib/testDebuggerVariablesHelper.cxx

@@ -8,6 +8,7 @@
 #include <utility>
 #include <vector>
 
+#include <cm3p/cppdap/optional.h>
 #include <cm3p/cppdap/protocol.h>
 #include <cm3p/cppdap/types.h>
 #include <stddef.h>