debug_adapter_parser.cpp 22 KB

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