[Lldb-commits] [lldb] [lldb-dap] Creating an API for sending custom dap events from lldb-dap. (PR #112384)

John Harrison via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 16 14:37:20 PDT 2024


https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/112384

>From af2e73635f85bd56b708e1240ad2c6837b7e449f Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Tue, 15 Oct 2024 09:13:49 -0700
Subject: [PATCH 1/6] [lldb-dap] Creating an API for sending custom dap events
 from lldb-dap.

Custom DAP events can be detected using https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent. This API allows an lldb python script to send custom events to the DAP client to allow extensions to handle these custom events.
---
 .../test/tools/lldb-dap/dap_server.py         |  2 +-
 .../API/tools/lldb-dap/custom-event/Makefile  |  3 ++
 .../custom-event/TestDAP_customEvent.py       | 46 +++++++++++++++++++
 .../API/tools/lldb-dap/custom-event/main.c    |  6 +++
 lldb/tools/lldb-dap/DAP.cpp                   | 38 +++++++++++++++
 lldb/tools/lldb-dap/DAP.h                     |  5 ++
 lldb/tools/lldb-dap/README.md                 | 24 ++++++++++
 lldb/tools/lldb-dap/lldb-dap.cpp              |  2 +
 8 files changed, 125 insertions(+), 1 deletion(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/custom-event/Makefile
 create mode 100644 lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py
 create mode 100644 lldb/test/API/tools/lldb-dap/custom-event/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 1d5e6e0d75c7cb..63748a71f1122d 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -1267,7 +1267,7 @@ def run_vscode(dbg, args, options):
 def main():
     parser = optparse.OptionParser(
         description=(
-            "A testing framework for the Visual Studio Code Debug " "Adaptor protocol"
+            "A testing framework for the Visual Studio Code Debug Adaptor protocol"
         )
     )
 
diff --git a/lldb/test/API/tools/lldb-dap/custom-event/Makefile b/lldb/test/API/tools/lldb-dap/custom-event/Makefile
new file mode 100644
index 00000000000000..10495940055b63
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/custom-event/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py b/lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py
new file mode 100644
index 00000000000000..2ae02b09c9f0fc
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py
@@ -0,0 +1,46 @@
+"""
+Test lldb-dap custom-event integration.
+"""
+
+import json
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbdap_testcase
+
+
+class TestDAP_customEvent(lldbdap_testcase.DAPTestCaseBase):
+    def test_custom_event(self):
+        """
+        Test sending a custom event.
+        """
+        program = self.getBuildArtifact("a.out")
+        source = "main.c"
+        custom_event_body = {
+            "key": 321,
+            "arr": [True],
+        }
+        self.build_and_launch(
+            program,
+            stopCommands=[
+                "lldb-dap custom-event my-custom-event-no-body",
+                "lldb-dap custom-event my-custom-event '{}'".format(
+                    json.dumps(custom_event_body)
+                ),
+            ],
+        )
+
+        breakpoint_line = line_number(source, "// breakpoint")
+
+        self.set_source_breakpoints(source, [breakpoint_line])
+        self.continue_to_next_stop()
+
+        custom_event = self.dap_server.wait_for_event(
+            filter=["my-custom-event-no-body"]
+        )
+        self.assertEquals(custom_event["event"], "my-custom-event-no-body")
+        self.assertIsNone(custom_event.get("body", None))
+
+        custom_event = self.dap_server.wait_for_event(filter=["my-custom-event"])
+        self.assertEquals(custom_event["event"], "my-custom-event")
+        self.assertEquals(custom_event["body"], custom_event_body)
diff --git a/lldb/test/API/tools/lldb-dap/custom-event/main.c b/lldb/test/API/tools/lldb-dap/custom-event/main.c
new file mode 100644
index 00000000000000..27bc22b94794b6
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/custom-event/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char const *argv[]) {
+  printf("example\n"); // breakpoint 1
+  return 0;
+}
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 119779d7bfecba..87f7eac2fb770b 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -962,6 +962,44 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
   return true;
 }
 
+// Sends a custom DAP event with an optional body.
+//
+// See
+// https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent
+bool CustomDAPEventRequestHandler::DoExecute(
+    lldb::SBDebugger debugger, char **command,
+    lldb::SBCommandReturnObject &result) {
+  // Command format like: `custom-event <name> <body>?`
+  if (!command || !command[0] || llvm::StringRef(command[0]).empty()) {
+    result.SetError("Invalid use of custom-event, expected format "
+                    "`custom-event <name> <body>?`.");
+    return false;
+  }
+
+  llvm::StringRef name{command[0]};
+  llvm::json::Object event(CreateEventObject(name));
+
+  if (command[1] && !llvm::StringRef(command[1]).empty()) {
+    llvm::StringRef raw_body{command[1]};
+
+    llvm::Expected<llvm::json::Value> body = llvm::json::parse(raw_body);
+
+    if (!body) {
+      llvm::Error err = body.takeError();
+      std::string msg = "Failed to parse custom event body: " +
+                        llvm::toString(std::move(err));
+      result.SetError(msg.c_str());
+      return false;
+    }
+
+    event.try_emplace("body", std::move(*body));
+  }
+
+  g_dap.SendJSON(llvm::json::Value(std::move(event)));
+  result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
+  return true;
+}
+
 void DAP::SetFrameFormat(llvm::StringRef format) {
   if (format.empty())
     return;
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index ba6d3d80410e3d..966019fadcea34 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -144,6 +144,11 @@ struct ReplModeRequestHandler : public lldb::SBCommandPluginInterface {
                  lldb::SBCommandReturnObject &result) override;
 };
 
+struct CustomDAPEventRequestHandler : public lldb::SBCommandPluginInterface {
+  bool DoExecute(lldb::SBDebugger debugger, char **command,
+                 lldb::SBCommandReturnObject &result) override;
+};
+
 struct DAP {
   std::string debug_adaptor_path;
   InputStream input;
diff --git a/lldb/tools/lldb-dap/README.md b/lldb/tools/lldb-dap/README.md
index 11086eb222d2eb..6d8f9ce4ee7565 100644
--- a/lldb/tools/lldb-dap/README.md
+++ b/lldb/tools/lldb-dap/README.md
@@ -290,6 +290,30 @@ The initial repl-mode can be configured with the cli flag `--repl-mode=<mode>`
 and may also be adjusted at runtime using the lldb command
 `lldb-dap repl-mode <mode>`.
 
+#### `lldb-dap custom-event`
+
+lldb-dap includes a custom command to trigger a Debug Adapter Protocol event 
+from a script. [See the specification](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Event) 
+for more details on Debug Adapter Protocol events.
+
+This command has the format:
+
+```
+lldb-dap custom-event <name> <body>?
+```
+
+For example you can use a launch configuration hook to run the command like:
+
+```json
+{
+  "program": "exe",
+  "stopCommands": [
+    "lldb-dap custom-event MyStopEvent",
+    "lldb-dap custom-event MyStopEvent '{\"key\":321}",
+  ]
+}
+```
+
 ## Contributing
 
 `lldb-dap` and `lldb` are developed under the umbrella of the [LLVM project](https://llvm.org/).
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 5e351ab11ab6ca..1cdb61b84e9542 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1896,6 +1896,8 @@ void request_initialize(const llvm::json::Object &request) {
   cmd.AddCommand(
       "repl-mode", new ReplModeRequestHandler(),
       "Get or set the repl behavior of lldb-dap evaluation requests.");
+  cmd.AddCommand("custom-event", new CustomDAPEventRequestHandler(),
+                 "Fires a custom lldb-dap event.");
 
   g_dap.progress_event_thread = std::thread(ProgressEventThreadFunction);
 

>From b7ead5aeb6948e81acdb08ccdab5a0da183c98c5 Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Tue, 15 Oct 2024 17:52:01 -0700
Subject: [PATCH 2/6] Adjusting the name from `lldb-dap custom-event` to
 `lldb-dap send-event` and implemented a check for stateful internal events.

---
 .../{custom-event => send-event}/Makefile     |  0
 .../TestDAP_sendEvent.py}                     | 28 +++++++++++---
 .../{custom-event => send-event}/main.c       |  0
 lldb/tools/lldb-dap/DAP.cpp                   | 37 +++++++++++++++----
 lldb/tools/lldb-dap/DAP.h                     |  2 +-
 lldb/tools/lldb-dap/lldb-dap.cpp              |  4 +-
 6 files changed, 56 insertions(+), 15 deletions(-)
 rename lldb/test/API/tools/lldb-dap/{custom-event => send-event}/Makefile (100%)
 rename lldb/test/API/tools/lldb-dap/{custom-event/TestDAP_customEvent.py => send-event/TestDAP_sendEvent.py} (55%)
 rename lldb/test/API/tools/lldb-dap/{custom-event => send-event}/main.c (100%)

diff --git a/lldb/test/API/tools/lldb-dap/custom-event/Makefile b/lldb/test/API/tools/lldb-dap/send-event/Makefile
similarity index 100%
rename from lldb/test/API/tools/lldb-dap/custom-event/Makefile
rename to lldb/test/API/tools/lldb-dap/send-event/Makefile
diff --git a/lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py b/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
similarity index 55%
rename from lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py
rename to lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
index 2ae02b09c9f0fc..f5cf884655e9dc 100644
--- a/lldb/test/API/tools/lldb-dap/custom-event/TestDAP_customEvent.py
+++ b/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
@@ -1,16 +1,18 @@
 """
-Test lldb-dap custom-event integration.
+Test lldb-dap send-event integration.
 """
 
 import json
+import time
+import threading
 
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 import lldbdap_testcase
 
 
-class TestDAP_customEvent(lldbdap_testcase.DAPTestCaseBase):
-    def test_custom_event(self):
+class TestDAP_sendEvent(lldbdap_testcase.DAPTestCaseBase):
+    def test_send_event(self):
         """
         Test sending a custom event.
         """
@@ -23,8 +25,8 @@ def test_custom_event(self):
         self.build_and_launch(
             program,
             stopCommands=[
-                "lldb-dap custom-event my-custom-event-no-body",
-                "lldb-dap custom-event my-custom-event '{}'".format(
+                "lldb-dap send-event my-custom-event-no-body",
+                "lldb-dap send-event my-custom-event '{}'".format(
                     json.dumps(custom_event_body)
                 ),
             ],
@@ -44,3 +46,19 @@ def test_custom_event(self):
         custom_event = self.dap_server.wait_for_event(filter=["my-custom-event"])
         self.assertEquals(custom_event["event"], "my-custom-event")
         self.assertEquals(custom_event["body"], custom_event_body)
+
+    def test_send_internal_event(self):
+        """
+        Test sending an internal event produces an error.
+        """
+        program = self.getBuildArtifact("a.out")
+        source = "main.c"
+        self.build_and_launch(program)
+
+        breakpoint_line = line_number(source, "// breakpoint")
+
+        self.set_source_breakpoints(source, [breakpoint_line])
+        self.continue_to_next_stop()
+
+        resp = self.dap_server.request_evaluate("`lldb-dap send-event stopped", context="repl")
+        self.assertRegex(resp['body']['result'], r"Invalid use of lldb-dap send-event, event \"stopped\" should be handled by lldb-dap internally.")
diff --git a/lldb/test/API/tools/lldb-dap/custom-event/main.c b/lldb/test/API/tools/lldb-dap/send-event/main.c
similarity index 100%
rename from lldb/test/API/tools/lldb-dap/custom-event/main.c
rename to lldb/test/API/tools/lldb-dap/send-event/main.c
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 87f7eac2fb770b..f54aec6a1d4cd2 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -962,24 +962,47 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
   return true;
 }
 
-// Sends a custom DAP event with an optional body.
+// Sends a DAP event with an optional body.
 //
 // See
 // https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent
-bool CustomDAPEventRequestHandler::DoExecute(
-    lldb::SBDebugger debugger, char **command,
-    lldb::SBCommandReturnObject &result) {
-  // Command format like: `custom-event <name> <body>?`
+bool SendEventRequestHandler::DoExecute(lldb::SBDebugger debugger,
+                                        char **command,
+                                        lldb::SBCommandReturnObject &result) {
+  // Command format like: `send-event <name> <body>?`
   if (!command || !command[0] || llvm::StringRef(command[0]).empty()) {
-    result.SetError("Invalid use of custom-event, expected format "
-                    "`custom-event <name> <body>?`.");
+    result.SetError("Not enough arguments found, expected format "
+                    "`lldb-dap send-event <name> <body>?`.");
     return false;
   }
 
   llvm::StringRef name{command[0]};
+  // Events that are stateful and should be handled by lldb-dap internally.
+  const std::array internal_events{"breakpoint", "capabilities", "continued",
+                                   "exited",     "initialize",   "loadedSource",
+                                   "module",     "process",      "stopped",
+                                   "terminated", "thread"};
+  if (std::find(internal_events.begin(), internal_events.end(), name) !=
+      std::end(internal_events)) {
+    std::string msg =
+        llvm::formatv("Invalid use of lldb-dap send-event, event \"{0}\" "
+                      "should be handled by lldb-dap internally.",
+                      name)
+            .str();
+    result.SetError(msg.c_str());
+    return false;
+  }
+
   llvm::json::Object event(CreateEventObject(name));
 
   if (command[1] && !llvm::StringRef(command[1]).empty()) {
+    // See if we have to unused arguments.
+    if (command[2] && !llvm::StringRef(command[1]).empty()) {
+      result.SetError("Additional arguments found, expected `lldb-dap send-event "
+                      "<name> <body>?`.");
+      return false;
+    }
+
     llvm::StringRef raw_body{command[1]};
 
     llvm::Expected<llvm::json::Value> body = llvm::json::parse(raw_body);
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 966019fadcea34..acc10ade75fd14 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -144,7 +144,7 @@ struct ReplModeRequestHandler : public lldb::SBCommandPluginInterface {
                  lldb::SBCommandReturnObject &result) override;
 };
 
-struct CustomDAPEventRequestHandler : public lldb::SBCommandPluginInterface {
+struct SendEventRequestHandler : public lldb::SBCommandPluginInterface {
   bool DoExecute(lldb::SBDebugger debugger, char **command,
                  lldb::SBCommandReturnObject &result) override;
 };
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 1cdb61b84e9542..f70b0d3d4cbee0 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1896,8 +1896,8 @@ void request_initialize(const llvm::json::Object &request) {
   cmd.AddCommand(
       "repl-mode", new ReplModeRequestHandler(),
       "Get or set the repl behavior of lldb-dap evaluation requests.");
-  cmd.AddCommand("custom-event", new CustomDAPEventRequestHandler(),
-                 "Fires a custom lldb-dap event.");
+  cmd.AddCommand("send-event", new SendEventRequestHandler(),
+                 "Sends an DAP event to the client.");
 
   g_dap.progress_event_thread = std::thread(ProgressEventThreadFunction);
 

>From 6af7bc69ad148a322b8c30b7639ace6252f30031 Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Tue, 15 Oct 2024 18:02:12 -0700
Subject: [PATCH 3/6] Updating the readme after renaming lldb-dap custom-event
 to lldb-dap send-event.

---
 lldb/tools/lldb-dap/README.md | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lldb/tools/lldb-dap/README.md b/lldb/tools/lldb-dap/README.md
index 6d8f9ce4ee7565..42b5f501e32c65 100644
--- a/lldb/tools/lldb-dap/README.md
+++ b/lldb/tools/lldb-dap/README.md
@@ -290,30 +290,37 @@ The initial repl-mode can be configured with the cli flag `--repl-mode=<mode>`
 and may also be adjusted at runtime using the lldb command
 `lldb-dap repl-mode <mode>`.
 
-#### `lldb-dap custom-event`
+#### `lldb-dap send-event`
 
-lldb-dap includes a custom command to trigger a Debug Adapter Protocol event 
-from a script. [See the specification](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Event) 
-for more details on Debug Adapter Protocol events.
+lldb-dap includes a command to trigger a Debug Adapter Protocol event
+from a script.
+
+The event maybe a custom DAP event or a standard event, if the event is not 
+handled internally by `lldb-dap`.
 
 This command has the format:
 
 ```
-lldb-dap custom-event <name> <body>?
+lldb-dap send-event <name> <body>?
 ```
 
-For example you can use a launch configuration hook to run the command like:
+For example you can use a launch configuration hook to trigger custom events like:
 
 ```json
 {
   "program": "exe",
   "stopCommands": [
-    "lldb-dap custom-event MyStopEvent",
-    "lldb-dap custom-event MyStopEvent '{\"key\":321}",
+    "lldb-dap send-event MyStopEvent",
+    "lldb-dap send-event MyStopEvent '{\"key\": 321}",
   ]
 }
 ```
 
+[See the specification](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Event) 
+for more details on Debug Adapter Protocol events and the VS Code 
+[debug.onDidReceiveDebugSessionCustomEvent](https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent) 
+API for handling a custom event from an extension.
+
 ## Contributing
 
 `lldb-dap` and `lldb` are developed under the umbrella of the [LLVM project](https://llvm.org/).

>From 5fd269ab1cff3a33df491513ec34ea7ab0841f74 Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Tue, 15 Oct 2024 18:03:50 -0700
Subject: [PATCH 4/6] Applying formatting.

---
 .../tools/lldb-dap/send-event/TestDAP_sendEvent.py    | 11 +++++++----
 lldb/tools/lldb-dap/DAP.cpp                           |  5 +++--
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py b/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
index f5cf884655e9dc..661a435fc03798 100644
--- a/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
+++ b/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
@@ -3,8 +3,6 @@
 """
 
 import json
-import time
-import threading
 
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
@@ -60,5 +58,10 @@ def test_send_internal_event(self):
         self.set_source_breakpoints(source, [breakpoint_line])
         self.continue_to_next_stop()
 
-        resp = self.dap_server.request_evaluate("`lldb-dap send-event stopped", context="repl")
-        self.assertRegex(resp['body']['result'], r"Invalid use of lldb-dap send-event, event \"stopped\" should be handled by lldb-dap internally.")
+        resp = self.dap_server.request_evaluate(
+            "`lldb-dap send-event stopped", context="repl"
+        )
+        self.assertRegex(
+            resp['body']['result'],
+            r"Invalid use of lldb-dap send-event, event \"stopped\" should be handled by lldb-dap internally."
+        )
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index f54aec6a1d4cd2..b24ad00f463f35 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -998,8 +998,9 @@ bool SendEventRequestHandler::DoExecute(lldb::SBDebugger debugger,
   if (command[1] && !llvm::StringRef(command[1]).empty()) {
     // See if we have to unused arguments.
     if (command[2] && !llvm::StringRef(command[1]).empty()) {
-      result.SetError("Additional arguments found, expected `lldb-dap send-event "
-                      "<name> <body>?`.");
+      result.SetError(
+          "Additional arguments found, expected `lldb-dap send-event "
+          "<name> <body>?`.");
       return false;
     }
 

>From 0266ba5655adc80fdbb007ef27180aaead02935a Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Tue, 15 Oct 2024 18:04:41 -0700
Subject: [PATCH 5/6] Fixing an invlaid offset when validating command
 arguments

---
 lldb/tools/lldb-dap/DAP.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index b24ad00f463f35..5ac75a6bb26118 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -997,7 +997,7 @@ bool SendEventRequestHandler::DoExecute(lldb::SBDebugger debugger,
 
   if (command[1] && !llvm::StringRef(command[1]).empty()) {
     // See if we have to unused arguments.
-    if (command[2] && !llvm::StringRef(command[1]).empty()) {
+    if (command[2] && !llvm::StringRef(command[2]).empty()) {
       result.SetError(
           "Additional arguments found, expected `lldb-dap send-event "
           "<name> <body>?`.");

>From fcd79e1dbaeb7ca53c51fe8bd9e56a87c897eb71 Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 16 Oct 2024 12:12:00 -0700
Subject: [PATCH 6/6] Fixing formatting and addressing how we check for extra
 arguments.

---
 lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py | 4 ++--
 lldb/tools/lldb-dap/DAP.cpp                                  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py b/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
index 661a435fc03798..de47651bb2fa1b 100644
--- a/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
+++ b/lldb/test/API/tools/lldb-dap/send-event/TestDAP_sendEvent.py
@@ -62,6 +62,6 @@ def test_send_internal_event(self):
             "`lldb-dap send-event stopped", context="repl"
         )
         self.assertRegex(
-            resp['body']['result'],
-            r"Invalid use of lldb-dap send-event, event \"stopped\" should be handled by lldb-dap internally."
+            resp["body"]["result"],
+            r"Invalid use of lldb-dap send-event, event \"stopped\" should be handled by lldb-dap internally.",
         )
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 5ac75a6bb26118..1c6801cfdc2b07 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -997,7 +997,7 @@ bool SendEventRequestHandler::DoExecute(lldb::SBDebugger debugger,
 
   if (command[1] && !llvm::StringRef(command[1]).empty()) {
     // See if we have to unused arguments.
-    if (command[2] && !llvm::StringRef(command[2]).empty()) {
+    if (command[2]) {
       result.SetError(
           "Additional arguments found, expected `lldb-dap send-event "
           "<name> <body>?`.");



More information about the lldb-commits mailing list