[Lldb-commits] [lldb] [lldb-dap] Creating an API for sending custom dap events from lldb-dap. (PR #112384)
Adrian Vogelsgesang via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 16 02:22:17 PDT 2024
================
@@ -962,6 +962,68 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
return true;
}
+// Sends a DAP event with an optional body.
+//
+// See
+// https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent
+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("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[2]).empty()) {
----------------
vogelsgesang wrote:
this would still allow things like `lldb-dap send-event foo bar "" "" baz`. I would have expected a condition similar to `command.size() >= 2`
https://github.com/llvm/llvm-project/pull/112384
More information about the lldb-commits
mailing list