debug_adapter_parser.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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/editor_node.h"
  34. #include "editor/editor_run_native.h"
  35. #include "editor/export/editor_export_platform.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::prepare_success_response);
  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(":", 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. EditorNode::get_singleton()->run_stop();
  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. ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
  160. if ((bool)args["noDebug"] != dbg->is_skip_breakpoints()) {
  161. dbg->debug_skip_breakpoints();
  162. }
  163. String platform_string = args.get("platform", "host");
  164. if (platform_string == "host") {
  165. EditorNode::get_singleton()->run_play();
  166. } else {
  167. int device = args.get("device", -1);
  168. int idx = -1;
  169. if (platform_string == "android") {
  170. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  171. if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Android") {
  172. idx = i;
  173. break;
  174. }
  175. }
  176. } else if (platform_string == "web") {
  177. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  178. if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Web") {
  179. idx = i;
  180. break;
  181. }
  182. }
  183. }
  184. if (idx == -1) {
  185. return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM);
  186. }
  187. EditorNode *editor = EditorNode::get_singleton();
  188. Error err = platform_string == "android" ? editor->run_play_native(device * 10000 + idx) : editor->run_play_native(idx);
  189. if (err) {
  190. if (err == ERR_INVALID_PARAMETER && platform_string == "android") {
  191. return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE);
  192. } else {
  193. return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
  194. }
  195. }
  196. }
  197. DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = false;
  198. DebugAdapterProtocol::get_singleton()->notify_process();
  199. return prepare_success_response(p_params);
  200. }
  201. Dictionary DebugAdapterParser::req_attach(const Dictionary &p_params) const {
  202. ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
  203. if (!dbg->is_session_active()) {
  204. return prepare_error_response(p_params, DAP::ErrorType::NOT_RUNNING);
  205. }
  206. DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = true;
  207. DebugAdapterProtocol::get_singleton()->notify_process();
  208. return prepare_success_response(p_params);
  209. }
  210. Dictionary DebugAdapterParser::req_restart(const Dictionary &p_params) const {
  211. // Extract embedded "arguments" so it can be given to req_launch/req_attach
  212. Dictionary params = p_params, args;
  213. args = params["arguments"];
  214. args = args["arguments"];
  215. params["arguments"] = args;
  216. Dictionary response = DebugAdapterProtocol::get_singleton()->get_current_peer()->attached ? req_attach(params) : req_launch(params);
  217. if (!response["success"]) {
  218. response["command"] = p_params["command"];
  219. return response;
  220. }
  221. return prepare_success_response(p_params);
  222. }
  223. Dictionary DebugAdapterParser::req_terminate(const Dictionary &p_params) const {
  224. EditorNode::get_singleton()->run_stop();
  225. return prepare_success_response(p_params);
  226. }
  227. Dictionary DebugAdapterParser::req_pause(const Dictionary &p_params) const {
  228. EditorNode::get_singleton()->get_pause_button()->set_pressed(true);
  229. EditorDebuggerNode::get_singleton()->_paused();
  230. DebugAdapterProtocol::get_singleton()->notify_stopped_paused();
  231. return prepare_success_response(p_params);
  232. }
  233. Dictionary DebugAdapterParser::req_continue(const Dictionary &p_params) const {
  234. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  235. EditorDebuggerNode::get_singleton()->_paused();
  236. DebugAdapterProtocol::get_singleton()->notify_continued();
  237. return prepare_success_response(p_params);
  238. }
  239. Dictionary DebugAdapterParser::req_threads(const Dictionary &p_params) const {
  240. Dictionary response = prepare_success_response(p_params), body;
  241. response["body"] = body;
  242. Array arr;
  243. DAP::Thread thread;
  244. thread.id = 1; // Hardcoded because Godot only supports debugging one thread at the moment
  245. thread.name = "Main";
  246. arr.push_back(thread.to_json());
  247. body["threads"] = arr;
  248. return response;
  249. }
  250. Dictionary DebugAdapterParser::req_stackTrace(const Dictionary &p_params) const {
  251. if (DebugAdapterProtocol::get_singleton()->_processing_stackdump) {
  252. return Dictionary();
  253. }
  254. Dictionary response = prepare_success_response(p_params), body;
  255. response["body"] = body;
  256. bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
  257. bool columns_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->columnsStartAt1;
  258. Array arr;
  259. DebugAdapterProtocol *dap = DebugAdapterProtocol::get_singleton();
  260. for (const KeyValue<DAP::StackFrame, List<int>> &E : dap->stackframe_list) {
  261. DAP::StackFrame sf = E.key;
  262. if (!lines_at_one) {
  263. sf.line--;
  264. }
  265. if (!columns_at_one) {
  266. sf.column--;
  267. }
  268. arr.push_back(sf.to_json());
  269. }
  270. body["stackFrames"] = arr;
  271. return response;
  272. }
  273. Dictionary DebugAdapterParser::req_setBreakpoints(const Dictionary &p_params) const {
  274. Dictionary response = prepare_success_response(p_params), body;
  275. response["body"] = body;
  276. Dictionary args = p_params["arguments"];
  277. DAP::Source source;
  278. source.from_json(args["source"]);
  279. bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
  280. if (!is_valid_path(source.path)) {
  281. Dictionary variables;
  282. variables["clientPath"] = source.path;
  283. variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
  284. return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
  285. }
  286. Array breakpoints = args["breakpoints"], lines;
  287. for (int i = 0; i < breakpoints.size(); i++) {
  288. DAP::SourceBreakpoint breakpoint;
  289. breakpoint.from_json(breakpoints[i]);
  290. lines.push_back(breakpoint.line + !lines_at_one);
  291. }
  292. Array updated_breakpoints = DebugAdapterProtocol::get_singleton()->update_breakpoints(source.path, lines);
  293. body["breakpoints"] = updated_breakpoints;
  294. return response;
  295. }
  296. Dictionary DebugAdapterParser::req_breakpointLocations(const Dictionary &p_params) const {
  297. Dictionary response = prepare_success_response(p_params), body;
  298. response["body"] = body;
  299. Dictionary args = p_params["arguments"];
  300. Array locations;
  301. DAP::BreakpointLocation location;
  302. location.line = args["line"];
  303. if (args.has("endLine")) {
  304. location.endLine = args["endLine"];
  305. }
  306. locations.push_back(location.to_json());
  307. body["breakpoints"] = locations;
  308. return response;
  309. }
  310. Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const {
  311. Dictionary response = prepare_success_response(p_params), body;
  312. response["body"] = body;
  313. Dictionary args = p_params["arguments"];
  314. int frame_id = args["frameId"];
  315. Array scope_list;
  316. DAP::StackFrame frame;
  317. frame.id = frame_id;
  318. HashMap<DAP::StackFrame, List<int>, DAP::StackFrame>::Iterator E = DebugAdapterProtocol::get_singleton()->stackframe_list.find(frame);
  319. if (E) {
  320. ERR_FAIL_COND_V(E->value.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
  321. for (int i = 0; i < 3; i++) {
  322. DAP::Scope scope;
  323. scope.variablesReference = E->value[i];
  324. switch (i) {
  325. case 0:
  326. scope.name = "Locals";
  327. scope.presentationHint = "locals";
  328. break;
  329. case 1:
  330. scope.name = "Members";
  331. scope.presentationHint = "members";
  332. break;
  333. case 2:
  334. scope.name = "Globals";
  335. scope.presentationHint = "globals";
  336. }
  337. scope_list.push_back(scope.to_json());
  338. }
  339. }
  340. EditorDebuggerNode::get_singleton()->get_default_debugger()->request_stack_dump(frame_id);
  341. DebugAdapterProtocol::get_singleton()->_current_frame = frame_id;
  342. body["scopes"] = scope_list;
  343. return response;
  344. }
  345. Dictionary DebugAdapterParser::req_variables(const Dictionary &p_params) const {
  346. // If _remaining_vars > 0, the debuggee is still sending a stack dump to the editor.
  347. if (DebugAdapterProtocol::get_singleton()->_remaining_vars > 0) {
  348. return Dictionary();
  349. }
  350. Dictionary response = prepare_success_response(p_params), body;
  351. response["body"] = body;
  352. Dictionary args = p_params["arguments"];
  353. int variable_id = args["variablesReference"];
  354. HashMap<int, Array>::Iterator E = DebugAdapterProtocol::get_singleton()->variable_list.find(variable_id);
  355. if (E) {
  356. if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsVariableType) {
  357. for (int i = 0; i < E->value.size(); i++) {
  358. Dictionary variable = E->value[i];
  359. variable.erase("type");
  360. }
  361. }
  362. body["variables"] = E ? E->value : Array();
  363. return response;
  364. } else {
  365. return Dictionary();
  366. }
  367. }
  368. Dictionary DebugAdapterParser::req_next(const Dictionary &p_params) const {
  369. EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_next();
  370. DebugAdapterProtocol::get_singleton()->_stepping = true;
  371. return prepare_success_response(p_params);
  372. }
  373. Dictionary DebugAdapterParser::req_stepIn(const Dictionary &p_params) const {
  374. EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_step();
  375. DebugAdapterProtocol::get_singleton()->_stepping = true;
  376. return prepare_success_response(p_params);
  377. }
  378. Dictionary DebugAdapterParser::req_evaluate(const Dictionary &p_params) const {
  379. Dictionary response = prepare_success_response(p_params), body;
  380. response["body"] = body;
  381. Dictionary args = p_params["arguments"];
  382. String value = EditorDebuggerNode::get_singleton()->get_var_value(args["expression"]);
  383. body["result"] = value;
  384. return response;
  385. }
  386. Dictionary DebugAdapterParser::req_godot_put_msg(const Dictionary &p_params) const {
  387. Dictionary args = p_params["arguments"];
  388. String msg = args["message"];
  389. Array data = args["data"];
  390. EditorDebuggerNode::get_singleton()->get_default_debugger()->_put_msg(msg, data);
  391. return prepare_success_response(p_params);
  392. }
  393. Dictionary DebugAdapterParser::ev_initialized() const {
  394. Dictionary event = prepare_base_event();
  395. event["event"] = "initialized";
  396. return event;
  397. }
  398. Dictionary DebugAdapterParser::ev_process(const String &p_command) const {
  399. Dictionary event = prepare_base_event(), body;
  400. event["event"] = "process";
  401. event["body"] = body;
  402. body["name"] = OS::get_singleton()->get_executable_path();
  403. body["startMethod"] = p_command;
  404. return event;
  405. }
  406. Dictionary DebugAdapterParser::ev_terminated() const {
  407. Dictionary event = prepare_base_event();
  408. event["event"] = "terminated";
  409. return event;
  410. }
  411. Dictionary DebugAdapterParser::ev_exited(const int &p_exitcode) const {
  412. Dictionary event = prepare_base_event(), body;
  413. event["event"] = "exited";
  414. event["body"] = body;
  415. body["exitCode"] = p_exitcode;
  416. return event;
  417. }
  418. Dictionary DebugAdapterParser::ev_stopped() const {
  419. Dictionary event = prepare_base_event(), body;
  420. event["event"] = "stopped";
  421. event["body"] = body;
  422. body["threadId"] = 1;
  423. return event;
  424. }
  425. Dictionary DebugAdapterParser::ev_stopped_paused() const {
  426. Dictionary event = ev_stopped();
  427. Dictionary body = event["body"];
  428. body["reason"] = "paused";
  429. body["description"] = "Paused";
  430. return event;
  431. }
  432. Dictionary DebugAdapterParser::ev_stopped_exception(const String &p_error) const {
  433. Dictionary event = ev_stopped();
  434. Dictionary body = event["body"];
  435. body["reason"] = "exception";
  436. body["description"] = "Exception";
  437. body["text"] = p_error;
  438. return event;
  439. }
  440. Dictionary DebugAdapterParser::ev_stopped_breakpoint(const int &p_id) const {
  441. Dictionary event = ev_stopped();
  442. Dictionary body = event["body"];
  443. body["reason"] = "breakpoint";
  444. body["description"] = "Breakpoint";
  445. Array breakpoints;
  446. breakpoints.push_back(p_id);
  447. body["hitBreakpointIds"] = breakpoints;
  448. return event;
  449. }
  450. Dictionary DebugAdapterParser::ev_stopped_step() const {
  451. Dictionary event = ev_stopped();
  452. Dictionary body = event["body"];
  453. body["reason"] = "step";
  454. body["description"] = "Breakpoint";
  455. return event;
  456. }
  457. Dictionary DebugAdapterParser::ev_continued() const {
  458. Dictionary event = prepare_base_event(), body;
  459. event["event"] = "continued";
  460. event["body"] = body;
  461. body["threadId"] = 1;
  462. return event;
  463. }
  464. Dictionary DebugAdapterParser::ev_output(const String &p_message) const {
  465. Dictionary event = prepare_base_event(), body;
  466. event["event"] = "output";
  467. event["body"] = body;
  468. body["category"] = "stdout";
  469. body["output"] = p_message + "\r\n";
  470. return event;
  471. }
  472. Dictionary DebugAdapterParser::ev_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) const {
  473. Dictionary event = prepare_base_event(), body;
  474. event["event"] = "breakpoint";
  475. event["body"] = body;
  476. body["reason"] = p_enabled ? "new" : "removed";
  477. body["breakpoint"] = p_breakpoint.to_json();
  478. return event;
  479. }
  480. Dictionary DebugAdapterParser::ev_custom_data(const String &p_msg, const Array &p_data) const {
  481. Dictionary event = prepare_base_event(), body;
  482. event["event"] = "godot/custom_data";
  483. event["body"] = body;
  484. body["message"] = p_msg;
  485. body["data"] = p_data;
  486. return event;
  487. }