[Lldb-commits] [lldb] Add lldb version into initialize response lldb-dap (PR #98703)

via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 12 17:36:32 PDT 2024


https://github.com/jeffreytan81 created https://github.com/llvm/llvm-project/pull/98703

Frequently, while troubleshooting user's debugging issues in VScode, we would like to know its version so that we can confirm if certain patch/feature is in or not.

This PR adds version string into `initialize` response so that telemetry can track it. 

>From 4c8619989ffd647fbbabeb124ef101bb9ec495be Mon Sep 17 00:00:00 2001
From: jeffreytan81 <jeffreytan at fb.com>
Date: Fri, 12 Jul 2024 17:34:31 -0700
Subject: [PATCH] Add lldb version into initialize response

---
 .../tools/lldb-dap/launch/TestDAP_launch.py   | 30 +++++++++++++++++++
 lldb/tools/lldb-dap/lldb-dap.cpp              |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
index b1b3d05ed4548..66d6d04cde882 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
@@ -475,3 +475,33 @@ def test_terminate_commands(self):
             pattern=terminateCommands[0],
         )
         self.verify_commands("terminateCommands", output, terminateCommands)
+
+    @skipIfWindows
+    def test_version(self):
+        """
+        Tests that "initialize" response contains the "version" string the same
+        as the one returned by "version" command.
+        """
+        program = self.getBuildArtifact("a.out")
+        self.build_and_launch(program)
+
+        source = "main.c"
+        breakpoint_line = line_number(source, "// breakpoint 1")
+        lines = [breakpoint_line]
+        # Set breakpoint in the thread function so we can step the threads
+        breakpoint_ids = self.set_source_breakpoints(source, lines)
+        self.continue_to_breakpoints(breakpoint_ids)
+
+        version_eval_response = self.dap_server.request_evaluate(
+            "`version", context="repl"
+        )
+        version_eval_output = version_eval_response["body"]["result"]
+
+        # The first line is the prompt line like "(lldb) version", so we skip it.
+        version_eval_output_without_prompt_line = version_eval_output.splitlines()[1:]
+        version_string = self.dap_server.get_initialize_value("version")
+        self.assertEqual(
+            version_eval_output_without_prompt_line,
+            version_string.splitlines(),
+            "version string does not match",
+        )
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index b74474b9d383c..020e08bfb75d0 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1710,6 +1710,8 @@ void request_initialize(const llvm::json::Object &request) {
   body.try_emplace("supportsLogPoints", true);
   // The debug adapter supports data watchpoints.
   body.try_emplace("supportsDataBreakpoints", true);
+  // Putting version string. Note: this is not part of DAP spec.
+  body.try_emplace("version", g_dap.debugger.GetVersionString());
 
   response.try_emplace("body", std::move(body));
   g_dap.SendJSON(llvm::json::Value(std::move(response)));



More information about the lldb-commits mailing list