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