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

via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 15 13:51:07 PDT 2024


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

>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 1/2] 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)));

>From 1ded00112144aaddd8f8de7d69f979e6771a7190 Mon Sep 17 00:00:00 2001
From: jeffreytan81 <jeffreytan at fb.com>
Date: Mon, 15 Jul 2024 16:50:51 -0400
Subject: [PATCH 2/2] Address review feedback

---
 lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py | 3 ++-
 lldb/tools/lldb-dap/lldb-dap.cpp                      | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

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 66d6d04cde882..dd47a2db8709b 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
@@ -499,7 +499,8 @@ def test_version(self):
 
         # 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")
+        lldb_json = self.dap_server.get_initialize_value("__lldb")
+        version_string = lldb_json["version"]
         self.assertEqual(
             version_eval_output_without_prompt_line,
             version_string.splitlines(),
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 020e08bfb75d0..9559248a0548c 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1710,8 +1710,11 @@ 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());
+
+  // Put in non-DAP specification lldb specific information.
+  llvm::json::Object lldb_json;
+  lldb_json.try_emplace("version", g_dap.debugger.GetVersionString());
+  body.try_emplace("__lldb", std::move(lldb_json));
 
   response.try_emplace("body", std::move(body));
   g_dap.SendJSON(llvm::json::Value(std::move(response)));



More information about the lldb-commits mailing list