@@ -962,6 +962,44 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
962962 return true ;
963963}
964964
965+ // Sends a custom DAP event with an optional body.
966+ //
967+ // See
968+ // https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent
969+ bool CustomDAPEventRequestHandler::DoExecute (
970+ lldb::SBDebugger debugger, char **command,
971+ lldb::SBCommandReturnObject &result) {
972+ // Command format like: `custom-event <name> <body>?`
973+ if (!command || !command[0 ] || llvm::StringRef (command[0 ]).empty ()) {
974+ result.SetError (" Invalid use of custom-event, expected format "
975+ " `custom-event <name> <body>?`." );
976+ return false ;
977+ }
978+
979+ llvm::StringRef name{command[0 ]};
980+ llvm::json::Object event (CreateEventObject (name));
981+
982+ if (command[1 ] && !llvm::StringRef (command[1 ]).empty ()) {
983+ llvm::StringRef raw_body{command[1 ]};
984+
985+ llvm::Expected<llvm::json::Value> body = llvm::json::parse (raw_body);
986+
987+ if (!body) {
988+ llvm::Error err = body.takeError ();
989+ std::string msg = " Failed to parse custom event body: " +
990+ llvm::toString (std::move (err));
991+ result.SetError (msg.c_str ());
992+ return false ;
993+ }
994+
995+ event.try_emplace (" body" , std::move (*body));
996+ }
997+
998+ g_dap.SendJSON (llvm::json::Value (std::move (event)));
999+ result.SetStatus (lldb::eReturnStatusSuccessFinishNoResult);
1000+ return true ;
1001+ }
1002+
9651003void DAP::SetFrameFormat (llvm::StringRef format) {
9661004 if (format.empty ())
9671005 return ;
0 commit comments