debug_adapter_parser.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /**************************************************************************/
  2. /* debug_adapter_parser.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "debug_adapter_parser.h"
  31. #include "core/variant/variant.h"
  32. #include "editor/debugger/debug_adapter/debug_adapter_types.h"
  33. #include "editor/debugger/editor_debugger_node.h"
  34. #include "editor/debugger/script_editor_debugger.h"
  35. #include "editor/export/editor_export_platform.h"
  36. #include "editor/gui/editor_run_bar.h"
  37. #include "editor/plugins/script_editor_plugin.h"
  38. void DebugAdapterParser::_bind_methods() {
  39. // Requests
  40. ClassDB::bind_method(D_METHOD("req_initialize", "params"), &DebugAdapterParser::req_initialize);
  41. ClassDB::bind_method(D_METHOD("req_disconnect", "params"), &DebugAdapterParser::req_disconnect);
  42. ClassDB::bind_method(D_METHOD("req_launch", "params"), &DebugAdapterParser::req_launch);
  43. ClassDB::bind_method(D_METHOD("req_attach", "params"), &DebugAdapterParser::req_attach);
  44. ClassDB::bind_method(D_METHOD("req_restart", "params"), &DebugAdapterParser::req_restart);
  45. ClassDB::bind_method(D_METHOD("req_terminate", "params"), &DebugAdapterParser::req_terminate);
  46. ClassDB::bind_method(D_METHOD("req_configurationDone", "params"), &DebugAdapterParser::req_configurationDone);
  47. ClassDB::bind_method(D_METHOD("req_pause", "params"), &DebugAdapterParser::req_pause);
  48. ClassDB::bind_method(D_METHOD("req_continue", "params"), &DebugAdapterParser::req_continue);
  49. ClassDB::bind_method(D_METHOD("req_threads", "params"), &DebugAdapterParser::req_threads);
  50. ClassDB::bind_method(D_METHOD("req_stackTrace", "params"), &DebugAdapterParser::req_stackTrace);
  51. ClassDB::bind_method(D_METHOD("req_setBreakpoints", "params"), &DebugAdapterParser::req_setBreakpoints);
  52. ClassDB::bind_method(D_METHOD("req_breakpointLocations", "params"), &DebugAdapterParser::req_breakpointLocations);
  53. ClassDB::bind_method(D_METHOD("req_scopes", "params"), &DebugAdapterParser::req_scopes);
  54. ClassDB::bind_method(D_METHOD("req_variables", "params"), &DebugAdapterParser::req_variables);
  55. ClassDB::bind_method(D_METHOD("req_next", "params"), &DebugAdapterParser::req_next);
  56. ClassDB::bind_method(D_METHOD("req_stepIn", "params"), &DebugAdapterParser::req_stepIn);
  57. ClassDB::bind_method(D_METHOD("req_evaluate", "params"), &DebugAdapterParser::req_evaluate);
  58. ClassDB::bind_method(D_METHOD("req_godot/put_msg", "params"), &DebugAdapterParser::req_godot_put_msg);
  59. }
  60. Dictionary DebugAdapterParser::prepare_base_event() const {
  61. Dictionary event;
  62. event["type"] = "event";
  63. return event;
  64. }
  65. Dictionary DebugAdapterParser::prepare_success_response(const Dictionary &p_params) const {
  66. Dictionary response;
  67. response["type"] = "response";
  68. response["request_seq"] = p_params["seq"];
  69. response["command"] = p_params["command"];
  70. response["success"] = true;
  71. return response;
  72. }
  73. Dictionary DebugAdapterParser::prepare_error_response(const Dictionary &p_params, DAP::ErrorType err_type, const Dictionary &variables) const {
  74. Dictionary response, body;
  75. response["type"] = "response";
  76. response["request_seq"] = p_params["seq"];
  77. response["command"] = p_params["command"];
  78. response["success"] = false;
  79. response["body"] = body;
  80. DAP::Message message;
  81. String error, error_desc;
  82. switch (err_type) {
  83. case DAP::ErrorType::WRONG_PATH:
  84. error = "wrong_path";
  85. error_desc = "The editor and client are working on different paths; the client is on \"{clientPath}\", but the editor is on \"{editorPath}\"";
  86. break;
  87. case DAP::ErrorType::NOT_RUNNING:
  88. error = "not_running";
  89. error_desc = "Can't attach to a running session since there isn't one.";
  90. break;
  91. case DAP::ErrorType::TIMEOUT:
  92. error = "timeout";
  93. error_desc = "Timeout reached while processing a request.";
  94. break;
  95. case DAP::ErrorType::UNKNOWN_PLATFORM:
  96. error = "unknown_platform";
  97. error_desc = "The specified platform is unknown.";
  98. break;
  99. case DAP::ErrorType::MISSING_DEVICE:
  100. error = "missing_device";
  101. error_desc = "There's no connected device with specified id.";
  102. break;
  103. case DAP::ErrorType::UNKNOWN:
  104. default:
  105. error = "unknown";
  106. error_desc = "An unknown error has occurred when processing the request.";
  107. break;
  108. }
  109. message.id = err_type;
  110. message.format = error_desc;
  111. message.variables = variables;
  112. response["message"] = error;
  113. body["error"] = message.to_json();
  114. return response;
  115. }
  116. Dictionary DebugAdapterParser::req_initialize(const Dictionary &p_params) const {
  117. Dictionary response = prepare_success_response(p_params);
  118. Dictionary args = p_params["arguments"];
  119. Ref<DAPeer> peer = DebugAdapterProtocol::get_singleton()->get_current_peer();
  120. peer->linesStartAt1 = args.get("linesStartAt1", false);
  121. peer->columnsStartAt1 = args.get("columnsStartAt1", false);
  122. peer->supportsVariableType = args.get("supportsVariableType", false);
  123. peer->supportsInvalidatedEvent = args.get("supportsInvalidatedEvent", false);
  124. DAP::Capabilities caps;
  125. response["body"] = caps.to_json();
  126. DebugAdapterProtocol::get_singleton()->notify_initialized();
  127. if (DebugAdapterProtocol::get_singleton()->_sync_breakpoints) {
  128. // Send all current breakpoints
  129. List<String> breakpoints;
  130. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  131. for (List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  132. String breakpoint = E->get();
  133. String path = breakpoint.left(breakpoint.find(":", 6)); // Skip initial part of path, aka "res://"
  134. int line = breakpoint.substr(path.size()).to_int();
  135. DebugAdapterProtocol::get_singleton()->on_debug_breakpoint_toggled(path, line, true);
  136. }
  137. } else {
  138. // Remove all current breakpoints
  139. EditorDebuggerNode::get_singleton()->get_default_debugger()->_clear_breakpoints();
  140. }
  141. return response;
  142. }
  143. Dictionary DebugAdapterParser::req_disconnect(const Dictionary &p_params) const {
  144. if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->attached) {
  145. EditorRunBar::get_singleton()->stop_playing();
  146. }
  147. return prepare_success_response(p_params);
  148. }
  149. Dictionary DebugAdapterParser::req_launch(const Dictionary &p_params) const {
  150. Dictionary args = p_params["arguments"];
  151. if (args.has("project") && !is_valid_path(args["project"])) {
  152. Dictionary variables;
  153. variables["clientPath"] = args["project"];
  154. variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
  155. return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
  156. }
  157. if (args.has("godot/custom_data")) {
  158. DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsCustomData = args["godot/custom_data"];
  159. }
  160. DebugAdapterProtocol::get_singleton()->get_current_peer()->pending_launch = p_params;
  161. return Dictionary();
  162. }
  163. Dictionary DebugAdapterParser::_launch_process(const Dictionary &p_params) const {
  164. Dictionary args = p_params["arguments"];
  165. ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
  166. if ((bool)args["noDebug"] != dbg->is_skip_breakpoints()) {
  167. dbg->debug_skip_breakpoints();
  168. }
  169. String platform_string = args.get("platform", "host");
  170. if (platform_string == "host") {
  171. EditorRunBar::get_singleton()->play_main_scene();
  172. } else {
  173. int device = args.get("device", -1);
  174. int idx = -1;
  175. if (platform_string == "android") {
  176. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  177. if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Android") {
  178. idx = i;
  179. break;
  180. }
  181. }
  182. } else if (platform_string == "web") {
  183. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  184. if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Web") {
  185. idx = i;
  186. break;
  187. }
  188. }
  189. }
  190. if (idx == -1) {
  191. return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM);
  192. }
  193. EditorRunBar *run_bar = EditorRunBar::get_singleton();
  194. Error err = platform_string == "android" ? run_bar->start_native_device(device * 10000 + idx) : run_bar->start_native_device(idx);
  195. if (err) {
  196. if (err == ERR_INVALID_PARAMETER && platform_string == "android") {
  197. return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE);
  198. } else {
  199. return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
  200. }
  201. }
  202. }
  203. DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = false;
  204. DebugAdapterProtocol::get_singleton()->notify_process();
  205. return prepare_success_response(p_params);
  206. }
  207. Dictionary DebugAdapterParser::req_attach(const Dictionary &p_params) const {
  208. ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
  209. if (!dbg->is_session_active()) {
  210. return prepare_error_response(p_params, DAP::ErrorType::NOT_RUNNING);
  211. }
  212. DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = true;
  213. DebugAdapterProtocol::get_singleton()->notify_process();
  214. return prepare_success_response(p_params);
  215. }
  216. Dictionary DebugAdapterParser::req_restart(const Dictionary &p_params) const {
  217. // Extract embedded "arguments" so it can be given to req_launch/req_attach
  218. Dictionary params = p_params, args;
  219. args = params["arguments"];
  220. args = args["arguments"];
  221. params["arguments"] = args;
  222. Dictionary response = DebugAdapterProtocol::get_singleton()->get_current_peer()->attached ? req_attach(params) : _launch_process(params);
  223. if (!response["success"]) {
  224. response["command"] = p_params["command"];
  225. return response;
  226. }
  227. return prepare_success_response(p_params);
  228. }
  229. Dictionary DebugAdapterParser::req_terminate(const Dictionary &p_params) const {
  230. EditorRunBar::get_singleton()->stop_playing();
  231. return prepare_success_response(p_params);
  232. }
  233. Dictionary DebugAdapterParser::req_configurationDone(const Dictionary &p_params) const {
  234. Ref<DAPeer> peer = DebugAdapterProtocol::get_singleton()->get_current_peer();
  235. if (!peer->pending_launch.is_empty()) {
  236. peer->res_queue.push_back(_launch_process(peer->pending_launch));
  237. peer->pending_launch.clear();
  238. }
  239. return prepare_success_response(p_params);
  240. }
  241. Dictionary DebugAdapterParser::req_pause(const Dictionary &p_params) const {
  242. EditorRunBar::get_singleton()->get_pause_button()->set_pressed(true);
  243. EditorDebuggerNode::get_singleton()->_paused();
  244. DebugAdapterProtocol::get_singleton()->notify_stopped_paused();
  245. return prepare_success_response(p_params);
  246. }
  247. Dictionary DebugAdapterParser::req_continue(const Dictionary &p_params) const {
  248. EditorRunBar::get_singleton()->get_pause_button()->set_pressed(false);
  249. EditorDebuggerNode::get_singleton()->_paused();
  250. DebugAdapterProtocol::get_singleton()->notify_continued();
  251. return prepare_success_response(p_params);
  252. }
  253. Dictionary DebugAdapterParser::req_threads(const Dictionary &p_params) const {
  254. Dictionary response = prepare_success_response(p_params), body;
  255. response["body"] = body;
  256. Array arr;
  257. DAP::Thread thread;
  258. thread.id = 1; // Hardcoded because Godot only supports debugging one thread at the moment
  259. thread.name = "Main";
  260. arr.push_back(thread.to_json());
  261. body["threads"] = arr;
  262. return response;
  263. }
  264. Dictionary DebugAdapterParser::req_stackTrace(const Dictionary &p_params) const {
  265. if (DebugAdapterProtocol::get_singleton()->_processing_stackdump) {
  266. return Dictionary();
  267. }
  268. Dictionary response = prepare_success_response(p_params), body;
  269. response["body"] = body;
  270. bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
  271. bool columns_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->columnsStartAt1;
  272. Array arr;
  273. DebugAdapterProtocol *dap = DebugAdapterProtocol::get_singleton();
  274. for (const KeyValue<DAP::StackFrame, List<int>> &E : dap->stackframe_list) {
  275. DAP::StackFrame sf = E.key;
  276. if (!lines_at_one) {
  277. sf.line--;
  278. }
  279. if (!columns_at_one) {
  280. sf.column--;
  281. }
  282. arr.push_back(sf.to_json());
  283. }
  284. body["stackFrames"] = arr;
  285. return response;
  286. }
  287. Dictionary DebugAdapterParser::req_setBreakpoints(const Dictionary &p_params) const {
  288. Dictionary response = prepare_success_response(p_params), body;
  289. response["body"] = body;
  290. Dictionary args = p_params["arguments"];
  291. DAP::Source source;
  292. source.from_json(args["source"]);
  293. bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
  294. if (!is_valid_path(source.path)) {
  295. Dictionary variables;
  296. variables["clientPath"] = source.path;
  297. variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
  298. return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
  299. }
  300. // If path contains \, it's a Windows path, so we need to convert it to /, and make the drive letter uppercase
  301. if (source.path.contains("\\")) {
  302. source.path = source.path.replace("\\", "/");
  303. source.path = source.path.substr(0, 1).to_upper() + source.path.substr(1);
  304. }
  305. Array breakpoints = args["breakpoints"], lines;
  306. for (int i = 0; i < breakpoints.size(); i++) {
  307. DAP::SourceBreakpoint breakpoint;
  308. breakpoint.from_json(breakpoints[i]);
  309. lines.push_back(breakpoint.line + !lines_at_one);
  310. }
  311. Array updated_breakpoints = DebugAdapterProtocol::get_singleton()->update_breakpoints(source.path, lines);
  312. body["breakpoints"] = updated_breakpoints;
  313. return response;
  314. }
  315. Dictionary DebugAdapterParser::req_breakpointLocations(const Dictionary &p_params) const {
  316. Dictionary response = prepare_success_response(p_params), body;
  317. response["body"] = body;
  318. Dictionary args = p_params["arguments"];
  319. Array locations;
  320. DAP::BreakpointLocation location;
  321. location.line = args["line"];
  322. if (args.has("endLine")) {
  323. location.endLine = args["endLine"];
  324. }
  325. locations.push_back(location.to_json());
  326. body["breakpoints"] = locations;
  327. return response;
  328. }
  329. Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const {
  330. Dictionary response = prepare_success_response(p_params), body;
  331. response["body"] = body;
  332. Dictionary args = p_params["arguments"];
  333. int frame_id = args["frameId"];
  334. Array scope_list;
  335. DAP::StackFrame frame;
  336. frame.id = frame_id;
  337. HashMap<DAP::StackFrame, List<int>, DAP::StackFrame>::Iterator E = DebugAdapterProtocol::get_singleton()->stackframe_list.find(frame);
  338. if (E) {
  339. ERR_FAIL_COND_V(E->value.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
  340. List<int>::ConstIterator itr = E->value.begin();
  341. for (int i = 0; i < 3; ++itr, ++i) {
  342. DAP::Scope scope;
  343. scope.variablesReference = *itr;
  344. switch (i) {
  345. case 0:
  346. scope.name = "Locals";
  347. scope.presentationHint = "locals";
  348. break;
  349. case 1:
  350. scope.name = "Members";
  351. scope.presentationHint = "members";
  352. break;
  353. case 2:
  354. scope.name = "Globals";
  355. scope.presentationHint = "globals";
  356. }
  357. scope_list.push_back(scope.to_json());
  358. }
  359. }
  360. EditorDebuggerNode::get_singleton()->get_default_debugger()->request_stack_dump(frame_id);
  361. DebugAdapterProtocol::get_singleton()->_current_frame = frame_id;
  362. body["scopes"] = scope_list;
  363. return response;
  364. }
  365. Dictionary DebugAdapterParser::req_variables(const Dictionary &p_params) const {
  366. // If _remaining_vars > 0, the debuggee is still sending a stack dump to the editor.
  367. if (DebugAdapterProtocol::get_singleton()->_remaining_vars > 0) {
  368. return Dictionary();
  369. }
  370. Dictionary args = p_params["arguments"];
  371. int variable_id = args["variablesReference"];
  372. if (HashMap<int, Array>::Iterator E = DebugAdapterProtocol::get_singleton()->variable_list.find(variable_id); E) {
  373. Dictionary response = prepare_success_response(p_params);
  374. Dictionary body;
  375. response["body"] = body;
  376. if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsVariableType) {
  377. for (int i = 0; i < E->value.size(); i++) {
  378. Dictionary variable = E->value[i];
  379. variable.erase("type");
  380. }
  381. }
  382. body["variables"] = E ? E->value : Array();
  383. return response;
  384. } else {
  385. // If the requested variable is an object, it needs to be requested from the debuggee.
  386. ObjectID object_id = DebugAdapterProtocol::get_singleton()->search_object_id(variable_id);
  387. if (object_id.is_null()) {
  388. return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
  389. }
  390. DebugAdapterProtocol::get_singleton()->request_remote_object(object_id);
  391. }
  392. return Dictionary();
  393. }
  394. Dictionary DebugAdapterParser::req_next(const Dictionary &p_params) const {
  395. EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_next();
  396. DebugAdapterProtocol::get_singleton()->_stepping = true;
  397. return prepare_success_response(p_params);
  398. }
  399. Dictionary DebugAdapterParser::req_stepIn(const Dictionary &p_params) const {
  400. EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_step();
  401. DebugAdapterProtocol::get_singleton()->_stepping = true;
  402. return prepare_success_response(p_params);
  403. }
  404. Dictionary DebugAdapterParser::req_evaluate(const Dictionary &p_params) const {
  405. Dictionary args = p_params["arguments"];
  406. String expression = args["expression"];
  407. int frame_id = args.has("frameId") ? static_cast<int>(args["frameId"]) : DebugAdapterProtocol::get_singleton()->_current_frame;
  408. if (HashMap<String, DAP::Variable>::Iterator E = DebugAdapterProtocol::get_singleton()->eval_list.find(expression); E) {
  409. Dictionary response = prepare_success_response(p_params);
  410. Dictionary body;
  411. response["body"] = body;
  412. DAP::Variable var = E->value;
  413. body["result"] = var.value;
  414. body["variablesReference"] = var.variablesReference;
  415. // Since an evaluation can alter the state of the debuggee, they are volatile, and should only be used once
  416. DebugAdapterProtocol::get_singleton()->eval_list.erase(E->key);
  417. return response;
  418. } else {
  419. DebugAdapterProtocol::get_singleton()->request_remote_evaluate(expression, frame_id);
  420. }
  421. return Dictionary();
  422. }
  423. Dictionary DebugAdapterParser::req_godot_put_msg(const Dictionary &p_params) const {
  424. Dictionary args = p_params["arguments"];
  425. String msg = args["message"];
  426. Array data = args["data"];
  427. EditorDebuggerNode::get_singleton()->get_default_debugger()->_put_msg(msg, data);
  428. return prepare_success_response(p_params);
  429. }
  430. Dictionary DebugAdapterParser::ev_initialized() const {
  431. Dictionary event = prepare_base_event();
  432. event["event"] = "initialized";
  433. return event;
  434. }
  435. Dictionary DebugAdapterParser::ev_process(const String &p_command) const {
  436. Dictionary event = prepare_base_event(), body;
  437. event["event"] = "process";
  438. event["body"] = body;
  439. body["name"] = OS::get_singleton()->get_executable_path();
  440. body["startMethod"] = p_command;
  441. return event;
  442. }
  443. Dictionary DebugAdapterParser::ev_terminated() const {
  444. Dictionary event = prepare_base_event();
  445. event["event"] = "terminated";
  446. return event;
  447. }
  448. Dictionary DebugAdapterParser::ev_exited(const int &p_exitcode) const {
  449. Dictionary event = prepare_base_event(), body;
  450. event["event"] = "exited";
  451. event["body"] = body;
  452. body["exitCode"] = p_exitcode;
  453. return event;
  454. }
  455. Dictionary DebugAdapterParser::ev_stopped() const {
  456. Dictionary event = prepare_base_event(), body;
  457. event["event"] = "stopped";
  458. event["body"] = body;
  459. body["threadId"] = 1;
  460. return event;
  461. }
  462. Dictionary DebugAdapterParser::ev_stopped_paused() const {
  463. Dictionary event = ev_stopped();
  464. Dictionary body = event["body"];
  465. body["reason"] = "paused";
  466. body["description"] = "Paused";
  467. return event;
  468. }
  469. Dictionary DebugAdapterParser::ev_stopped_exception(const String &p_error) const {
  470. Dictionary event = ev_stopped();
  471. Dictionary body = event["body"];
  472. body["reason"] = "exception";
  473. body["description"] = "Exception";
  474. body["text"] = p_error;
  475. return event;
  476. }
  477. Dictionary DebugAdapterParser::ev_stopped_breakpoint(const int &p_id) const {
  478. Dictionary event = ev_stopped();
  479. Dictionary body = event["body"];
  480. body["reason"] = "breakpoint";
  481. body["description"] = "Breakpoint";
  482. Array breakpoints;
  483. breakpoints.push_back(p_id);
  484. body["hitBreakpointIds"] = breakpoints;
  485. return event;
  486. }
  487. Dictionary DebugAdapterParser::ev_stopped_step() const {
  488. Dictionary event = ev_stopped();
  489. Dictionary body = event["body"];
  490. body["reason"] = "step";
  491. body["description"] = "Breakpoint";
  492. return event;
  493. }
  494. Dictionary DebugAdapterParser::ev_continued() const {
  495. Dictionary event = prepare_base_event(), body;
  496. event["event"] = "continued";
  497. event["body"] = body;
  498. body["threadId"] = 1;
  499. return event;
  500. }
  501. Dictionary DebugAdapterParser::ev_output(const String &p_message, RemoteDebugger::MessageType p_type) const {
  502. Dictionary event = prepare_base_event(), body;
  503. event["event"] = "output";
  504. event["body"] = body;
  505. body["category"] = (p_type == RemoteDebugger::MessageType::MESSAGE_TYPE_ERROR) ? "stderr" : "stdout";
  506. body["output"] = p_message + "\r\n";
  507. return event;
  508. }
  509. Dictionary DebugAdapterParser::ev_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) const {
  510. Dictionary event = prepare_base_event(), body;
  511. event["event"] = "breakpoint";
  512. event["body"] = body;
  513. body["reason"] = p_enabled ? "new" : "removed";
  514. body["breakpoint"] = p_breakpoint.to_json();
  515. return event;
  516. }
  517. Dictionary DebugAdapterParser::ev_custom_data(const String &p_msg, const Array &p_data) const {
  518. Dictionary event = prepare_base_event(), body;
  519. event["event"] = "godot/custom_data";
  520. event["body"] = body;
  521. body["message"] = p_msg;
  522. body["data"] = p_data;
  523. return event;
  524. }