debug_adapter_protocol.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. /**************************************************************************/
  2. /* debug_adapter_protocol.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_protocol.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/debugger/debugger_marshalls.h"
  33. #include "core/io/json.h"
  34. #include "core/io/marshalls.h"
  35. #include "editor/debugger/script_editor_debugger.h"
  36. #include "editor/editor_log.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/run/editor_run_bar.h"
  39. #include "editor/settings/editor_settings.h"
  40. DebugAdapterProtocol *DebugAdapterProtocol::singleton = nullptr;
  41. Error DAPeer::handle_data() {
  42. int read = 0;
  43. // Read headers
  44. if (!has_header) {
  45. if (!connection->get_available_bytes()) {
  46. return OK;
  47. }
  48. while (true) {
  49. if (req_pos >= DAP_MAX_BUFFER_SIZE) {
  50. req_pos = 0;
  51. ERR_FAIL_V_MSG(ERR_OUT_OF_MEMORY, "Response header too big");
  52. }
  53. Error err = connection->get_partial_data(&req_buf[req_pos], 1, read);
  54. if (err != OK) {
  55. return FAILED;
  56. } else if (read != 1) { // Busy, wait until next poll
  57. return ERR_BUSY;
  58. }
  59. char *r = (char *)req_buf;
  60. int l = req_pos;
  61. // End of headers
  62. if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') {
  63. r[l - 3] = '\0'; // Null terminate to read string
  64. String header = String::utf8(r);
  65. content_length = header.substr(16).to_int();
  66. has_header = true;
  67. req_pos = 0;
  68. break;
  69. }
  70. req_pos++;
  71. }
  72. }
  73. if (has_header) {
  74. while (req_pos < content_length) {
  75. if (content_length >= DAP_MAX_BUFFER_SIZE) {
  76. req_pos = 0;
  77. has_header = false;
  78. ERR_FAIL_COND_V_MSG(req_pos >= DAP_MAX_BUFFER_SIZE, ERR_OUT_OF_MEMORY, "Response content too big");
  79. }
  80. Error err = connection->get_partial_data(&req_buf[req_pos], content_length - req_pos, read);
  81. if (err != OK) {
  82. return FAILED;
  83. } else if (read < content_length - req_pos) {
  84. return ERR_BUSY;
  85. }
  86. req_pos += read;
  87. }
  88. // Parse data
  89. String msg = String::utf8((const char *)req_buf, req_pos);
  90. // Apply a timestamp if it there's none yet
  91. if (!timestamp) {
  92. timestamp = OS::get_singleton()->get_ticks_msec();
  93. }
  94. // Response
  95. if (DebugAdapterProtocol::get_singleton()->process_message(msg)) {
  96. // Reset to read again
  97. req_pos = 0;
  98. has_header = false;
  99. timestamp = 0;
  100. }
  101. }
  102. return OK;
  103. }
  104. Error DAPeer::send_data() {
  105. while (res_queue.size()) {
  106. Dictionary data = res_queue.front()->get();
  107. if (!data.has("seq")) {
  108. data["seq"] = ++seq;
  109. }
  110. const Vector<uint8_t> &formatted_data = format_output(data);
  111. int data_sent = 0;
  112. while (data_sent < formatted_data.size()) {
  113. int curr_sent = 0;
  114. Error err = connection->put_partial_data(formatted_data.ptr() + data_sent, formatted_data.size() - data_sent, curr_sent);
  115. if (err != OK) {
  116. return err;
  117. }
  118. data_sent += curr_sent;
  119. }
  120. res_queue.pop_front();
  121. }
  122. return OK;
  123. }
  124. Vector<uint8_t> DAPeer::format_output(const Dictionary &p_params) const {
  125. const Vector<uint8_t> &content = Variant(p_params).to_json_string().to_utf8_buffer();
  126. Vector<uint8_t> response = vformat("Content-Length: %d\r\n\r\n", content.size()).to_utf8_buffer();
  127. response.append_array(content);
  128. return response;
  129. }
  130. Error DebugAdapterProtocol::on_client_connected() {
  131. ERR_FAIL_COND_V_MSG(clients.size() >= DAP_MAX_CLIENTS, FAILED, "Max client limits reached");
  132. Ref<StreamPeerTCP> tcp_peer = server->take_connection();
  133. tcp_peer->set_no_delay(true);
  134. Ref<DAPeer> peer = memnew(DAPeer);
  135. peer->connection = tcp_peer;
  136. clients.push_back(peer);
  137. EditorDebuggerNode::get_singleton()->get_default_debugger()->set_move_to_foreground(false);
  138. EditorNode::get_log()->add_message("[DAP] Connection Taken", EditorLog::MSG_TYPE_EDITOR);
  139. return OK;
  140. }
  141. void DebugAdapterProtocol::on_client_disconnected(const Ref<DAPeer> &p_peer) {
  142. clients.erase(p_peer);
  143. if (!clients.size()) {
  144. reset_ids();
  145. EditorDebuggerNode::get_singleton()->get_default_debugger()->set_move_to_foreground(true);
  146. }
  147. EditorNode::get_log()->add_message("[DAP] Disconnected", EditorLog::MSG_TYPE_EDITOR);
  148. }
  149. void DebugAdapterProtocol::reset_current_info() {
  150. _current_request = "";
  151. _current_peer.unref();
  152. }
  153. void DebugAdapterProtocol::reset_ids() {
  154. breakpoint_id = 0;
  155. breakpoint_list.clear();
  156. breakpoint_source_list.clear();
  157. reset_stack_info();
  158. }
  159. void DebugAdapterProtocol::reset_stack_info() {
  160. stackframe_id = 0;
  161. variable_id = 1;
  162. stackframe_list.clear();
  163. scope_list.clear();
  164. variable_list.clear();
  165. object_list.clear();
  166. object_pending_set.clear();
  167. }
  168. int DebugAdapterProtocol::parse_variant(const Variant &p_var) {
  169. switch (p_var.get_type()) {
  170. case Variant::VECTOR2:
  171. case Variant::VECTOR2I: {
  172. int id = variable_id++;
  173. Vector2 vec = p_var;
  174. const String type_scalar = Variant::get_type_name(p_var.get_type() == Variant::VECTOR2 ? Variant::FLOAT : Variant::INT);
  175. DAP::Variable x, y;
  176. x.name = "x";
  177. y.name = "y";
  178. x.type = type_scalar;
  179. y.type = type_scalar;
  180. x.value = rtos(vec.x);
  181. y.value = rtos(vec.y);
  182. Array arr = { x.to_json(), y.to_json() };
  183. variable_list.insert(id, arr);
  184. return id;
  185. }
  186. case Variant::RECT2:
  187. case Variant::RECT2I: {
  188. int id = variable_id++;
  189. Rect2 rect = p_var;
  190. const String type_scalar = Variant::get_type_name(p_var.get_type() == Variant::RECT2 ? Variant::FLOAT : Variant::INT);
  191. DAP::Variable x, y, w, h;
  192. x.name = "x";
  193. y.name = "y";
  194. w.name = "w";
  195. h.name = "h";
  196. x.type = type_scalar;
  197. y.type = type_scalar;
  198. w.type = type_scalar;
  199. h.type = type_scalar;
  200. x.value = rtos(rect.position.x);
  201. y.value = rtos(rect.position.y);
  202. w.value = rtos(rect.size.x);
  203. h.value = rtos(rect.size.y);
  204. Array arr = { x.to_json(), y.to_json(), w.to_json(), h.to_json() };
  205. variable_list.insert(id, arr);
  206. return id;
  207. }
  208. case Variant::VECTOR3:
  209. case Variant::VECTOR3I: {
  210. int id = variable_id++;
  211. Vector3 vec = p_var;
  212. const String type_scalar = Variant::get_type_name(p_var.get_type() == Variant::VECTOR3 ? Variant::FLOAT : Variant::INT);
  213. DAP::Variable x, y, z;
  214. x.name = "x";
  215. y.name = "y";
  216. z.name = "z";
  217. x.type = type_scalar;
  218. y.type = type_scalar;
  219. z.type = type_scalar;
  220. x.value = rtos(vec.x);
  221. y.value = rtos(vec.y);
  222. z.value = rtos(vec.z);
  223. Array arr = { x.to_json(), y.to_json(), z.to_json() };
  224. variable_list.insert(id, arr);
  225. return id;
  226. }
  227. case Variant::TRANSFORM2D: {
  228. int id = variable_id++;
  229. Transform2D transform = p_var;
  230. const String type_vec2 = Variant::get_type_name(Variant::VECTOR2);
  231. DAP::Variable x, y, origin;
  232. x.name = "x";
  233. y.name = "y";
  234. origin.name = "origin";
  235. x.type = type_vec2;
  236. y.type = type_vec2;
  237. origin.type = type_vec2;
  238. x.value = String(transform.columns[0]);
  239. y.value = String(transform.columns[1]);
  240. origin.value = String(transform.columns[2]);
  241. x.variablesReference = parse_variant(transform.columns[0]);
  242. y.variablesReference = parse_variant(transform.columns[1]);
  243. origin.variablesReference = parse_variant(transform.columns[2]);
  244. Array arr = { x.to_json(), y.to_json(), origin.to_json() };
  245. variable_list.insert(id, arr);
  246. return id;
  247. }
  248. case Variant::PLANE: {
  249. int id = variable_id++;
  250. Plane plane = p_var;
  251. DAP::Variable d, normal;
  252. d.name = "d";
  253. normal.name = "normal";
  254. d.type = Variant::get_type_name(Variant::FLOAT);
  255. normal.type = Variant::get_type_name(Variant::VECTOR3);
  256. d.value = rtos(plane.d);
  257. normal.value = String(plane.normal);
  258. normal.variablesReference = parse_variant(plane.normal);
  259. Array arr = { d.to_json(), normal.to_json() };
  260. variable_list.insert(id, arr);
  261. return id;
  262. }
  263. case Variant::QUATERNION: {
  264. int id = variable_id++;
  265. Quaternion quat = p_var;
  266. const String type_float = Variant::get_type_name(Variant::FLOAT);
  267. DAP::Variable x, y, z, w;
  268. x.name = "x";
  269. y.name = "y";
  270. z.name = "z";
  271. w.name = "w";
  272. x.type = type_float;
  273. y.type = type_float;
  274. z.type = type_float;
  275. w.type = type_float;
  276. x.value = rtos(quat.x);
  277. y.value = rtos(quat.y);
  278. z.value = rtos(quat.z);
  279. w.value = rtos(quat.w);
  280. Array arr = { x.to_json(), y.to_json(), z.to_json(), w.to_json() };
  281. variable_list.insert(id, arr);
  282. return id;
  283. }
  284. case Variant::AABB: {
  285. int id = variable_id++;
  286. AABB aabb = p_var;
  287. const String type_vec3 = Variant::get_type_name(Variant::VECTOR3);
  288. DAP::Variable position, size;
  289. position.name = "position";
  290. size.name = "size";
  291. position.type = type_vec3;
  292. size.type = type_vec3;
  293. position.value = String(aabb.position);
  294. size.value = String(aabb.size);
  295. position.variablesReference = parse_variant(aabb.position);
  296. size.variablesReference = parse_variant(aabb.size);
  297. Array arr = { position.to_json(), size.to_json() };
  298. variable_list.insert(id, arr);
  299. return id;
  300. }
  301. case Variant::BASIS: {
  302. int id = variable_id++;
  303. Basis basis = p_var;
  304. const String type_vec3 = Variant::get_type_name(Variant::VECTOR3);
  305. DAP::Variable x, y, z;
  306. x.name = "x";
  307. y.name = "y";
  308. z.name = "z";
  309. x.type = type_vec3;
  310. y.type = type_vec3;
  311. z.type = type_vec3;
  312. x.value = String(basis.rows[0]);
  313. y.value = String(basis.rows[1]);
  314. z.value = String(basis.rows[2]);
  315. x.variablesReference = parse_variant(basis.rows[0]);
  316. y.variablesReference = parse_variant(basis.rows[1]);
  317. z.variablesReference = parse_variant(basis.rows[2]);
  318. Array arr = { x.to_json(), y.to_json(), z.to_json() };
  319. variable_list.insert(id, arr);
  320. return id;
  321. }
  322. case Variant::TRANSFORM3D: {
  323. int id = variable_id++;
  324. Transform3D transform = p_var;
  325. DAP::Variable basis, origin;
  326. basis.name = "basis";
  327. origin.name = "origin";
  328. basis.type = Variant::get_type_name(Variant::BASIS);
  329. origin.type = Variant::get_type_name(Variant::VECTOR3);
  330. basis.value = String(transform.basis);
  331. origin.value = String(transform.origin);
  332. basis.variablesReference = parse_variant(transform.basis);
  333. origin.variablesReference = parse_variant(transform.origin);
  334. Array arr = { basis.to_json(), origin.to_json() };
  335. variable_list.insert(id, arr);
  336. return id;
  337. }
  338. case Variant::COLOR: {
  339. int id = variable_id++;
  340. Color color = p_var;
  341. const String type_float = Variant::get_type_name(Variant::FLOAT);
  342. DAP::Variable r, g, b, a;
  343. r.name = "r";
  344. g.name = "g";
  345. b.name = "b";
  346. a.name = "a";
  347. r.type = type_float;
  348. g.type = type_float;
  349. b.type = type_float;
  350. a.type = type_float;
  351. r.value = rtos(color.r);
  352. g.value = rtos(color.g);
  353. b.value = rtos(color.b);
  354. a.value = rtos(color.a);
  355. Array arr = { r.to_json(), g.to_json(), b.to_json(), a.to_json() };
  356. variable_list.insert(id, arr);
  357. return id;
  358. }
  359. case Variant::ARRAY: {
  360. int id = variable_id++;
  361. Array array = p_var;
  362. DAP::Variable size;
  363. size.name = "size";
  364. size.type = Variant::get_type_name(Variant::INT);
  365. size.value = itos(array.size());
  366. Array arr = { size.to_json() };
  367. for (int i = 0; i < array.size(); i++) {
  368. DAP::Variable var;
  369. var.name = itos(i);
  370. var.type = Variant::get_type_name(array[i].get_type());
  371. var.value = array[i];
  372. var.variablesReference = parse_variant(array[i]);
  373. arr.push_back(var.to_json());
  374. }
  375. variable_list.insert(id, arr);
  376. return id;
  377. }
  378. case Variant::DICTIONARY: {
  379. int id = variable_id++;
  380. Dictionary dictionary = p_var;
  381. Array arr;
  382. for (const KeyValue<Variant, Variant> &kv : dictionary) {
  383. DAP::Variable var;
  384. var.name = kv.key;
  385. Variant value = kv.value;
  386. var.type = Variant::get_type_name(value.get_type());
  387. var.value = value;
  388. var.variablesReference = parse_variant(value);
  389. arr.push_back(var.to_json());
  390. }
  391. variable_list.insert(id, arr);
  392. return id;
  393. }
  394. case Variant::PACKED_BYTE_ARRAY: {
  395. int id = variable_id++;
  396. PackedByteArray array = p_var;
  397. DAP::Variable size;
  398. size.name = "size";
  399. size.type = Variant::get_type_name(Variant::INT);
  400. size.value = itos(array.size());
  401. Array arr = { size.to_json() };
  402. for (int i = 0; i < array.size(); i++) {
  403. DAP::Variable var;
  404. var.name = itos(i);
  405. var.type = "byte";
  406. var.value = itos(array[i]);
  407. arr.push_back(var.to_json());
  408. }
  409. variable_list.insert(id, arr);
  410. return id;
  411. }
  412. case Variant::PACKED_INT32_ARRAY: {
  413. int id = variable_id++;
  414. PackedInt32Array array = p_var;
  415. DAP::Variable size;
  416. size.name = "size";
  417. size.type = Variant::get_type_name(Variant::INT);
  418. size.value = itos(array.size());
  419. Array arr = { size.to_json() };
  420. for (int i = 0; i < array.size(); i++) {
  421. DAP::Variable var;
  422. var.name = itos(i);
  423. var.type = "int";
  424. var.value = itos(array[i]);
  425. arr.push_back(var.to_json());
  426. }
  427. variable_list.insert(id, arr);
  428. return id;
  429. }
  430. case Variant::PACKED_INT64_ARRAY: {
  431. int id = variable_id++;
  432. PackedInt64Array array = p_var;
  433. DAP::Variable size;
  434. size.name = "size";
  435. size.type = Variant::get_type_name(Variant::INT);
  436. size.value = itos(array.size());
  437. Array arr = { size.to_json() };
  438. for (int i = 0; i < array.size(); i++) {
  439. DAP::Variable var;
  440. var.name = itos(i);
  441. var.type = "long";
  442. var.value = itos(array[i]);
  443. arr.push_back(var.to_json());
  444. }
  445. variable_list.insert(id, arr);
  446. return id;
  447. }
  448. case Variant::PACKED_FLOAT32_ARRAY: {
  449. int id = variable_id++;
  450. PackedFloat32Array array = p_var;
  451. DAP::Variable size;
  452. size.name = "size";
  453. size.type = Variant::get_type_name(Variant::INT);
  454. size.value = itos(array.size());
  455. Array arr = { size.to_json() };
  456. for (int i = 0; i < array.size(); i++) {
  457. DAP::Variable var;
  458. var.name = itos(i);
  459. var.type = "float";
  460. var.value = rtos(array[i]);
  461. arr.push_back(var.to_json());
  462. }
  463. variable_list.insert(id, arr);
  464. return id;
  465. }
  466. case Variant::PACKED_FLOAT64_ARRAY: {
  467. int id = variable_id++;
  468. PackedFloat64Array array = p_var;
  469. DAP::Variable size;
  470. size.name = "size";
  471. size.type = Variant::get_type_name(Variant::INT);
  472. size.value = itos(array.size());
  473. Array arr = { size.to_json() };
  474. for (int i = 0; i < array.size(); i++) {
  475. DAP::Variable var;
  476. var.name = itos(i);
  477. var.type = "double";
  478. var.value = rtos(array[i]);
  479. arr.push_back(var.to_json());
  480. }
  481. variable_list.insert(id, arr);
  482. return id;
  483. }
  484. case Variant::PACKED_STRING_ARRAY: {
  485. int id = variable_id++;
  486. PackedStringArray array = p_var;
  487. DAP::Variable size;
  488. size.name = "size";
  489. size.type = Variant::get_type_name(Variant::INT);
  490. size.value = itos(array.size());
  491. Array arr = { size.to_json() };
  492. for (int i = 0; i < array.size(); i++) {
  493. DAP::Variable var;
  494. var.name = itos(i);
  495. var.type = Variant::get_type_name(Variant::STRING);
  496. var.value = array[i];
  497. arr.push_back(var.to_json());
  498. }
  499. variable_list.insert(id, arr);
  500. return id;
  501. }
  502. case Variant::PACKED_VECTOR2_ARRAY: {
  503. int id = variable_id++;
  504. PackedVector2Array array = p_var;
  505. DAP::Variable size;
  506. size.name = "size";
  507. size.type = Variant::get_type_name(Variant::INT);
  508. size.value = itos(array.size());
  509. Array arr = { size.to_json() };
  510. for (int i = 0; i < array.size(); i++) {
  511. DAP::Variable var;
  512. var.name = itos(i);
  513. var.type = Variant::get_type_name(Variant::VECTOR2);
  514. var.value = String(array[i]);
  515. var.variablesReference = parse_variant(array[i]);
  516. arr.push_back(var.to_json());
  517. }
  518. variable_list.insert(id, arr);
  519. return id;
  520. }
  521. case Variant::PACKED_VECTOR3_ARRAY: {
  522. int id = variable_id++;
  523. PackedVector3Array array = p_var;
  524. DAP::Variable size;
  525. size.name = "size";
  526. size.type = Variant::get_type_name(Variant::INT);
  527. size.value = itos(array.size());
  528. Array arr = { size.to_json() };
  529. for (int i = 0; i < array.size(); i++) {
  530. DAP::Variable var;
  531. var.name = itos(i);
  532. var.type = Variant::get_type_name(Variant::VECTOR3);
  533. var.value = String(array[i]);
  534. var.variablesReference = parse_variant(array[i]);
  535. arr.push_back(var.to_json());
  536. }
  537. variable_list.insert(id, arr);
  538. return id;
  539. }
  540. case Variant::PACKED_COLOR_ARRAY: {
  541. int id = variable_id++;
  542. PackedColorArray array = p_var;
  543. DAP::Variable size;
  544. size.name = "size";
  545. size.type = Variant::get_type_name(Variant::INT);
  546. size.value = itos(array.size());
  547. Array arr = { size.to_json() };
  548. for (int i = 0; i < array.size(); i++) {
  549. DAP::Variable var;
  550. var.name = itos(i);
  551. var.type = Variant::get_type_name(Variant::COLOR);
  552. var.value = String(array[i]);
  553. var.variablesReference = parse_variant(array[i]);
  554. arr.push_back(var.to_json());
  555. }
  556. variable_list.insert(id, arr);
  557. return id;
  558. }
  559. case Variant::PACKED_VECTOR4_ARRAY: {
  560. int id = variable_id++;
  561. PackedVector4Array array = p_var;
  562. DAP::Variable size;
  563. size.name = "size";
  564. size.type = Variant::get_type_name(Variant::INT);
  565. size.value = itos(array.size());
  566. Array arr;
  567. arr.push_back(size.to_json());
  568. for (int i = 0; i < array.size(); i++) {
  569. DAP::Variable var;
  570. var.name = itos(i);
  571. var.type = Variant::get_type_name(Variant::VECTOR4);
  572. var.value = String(array[i]);
  573. var.variablesReference = parse_variant(array[i]);
  574. arr.push_back(var.to_json());
  575. }
  576. variable_list.insert(id, arr);
  577. return id;
  578. }
  579. case Variant::OBJECT: {
  580. // Objects have to be requested from the debuggee. This has do be done
  581. // in a lazy way, as retrieving object properties takes time.
  582. EncodedObjectAsID *encoded_obj = Object::cast_to<EncodedObjectAsID>(p_var);
  583. // Object may be null; in that case, return early.
  584. if (!encoded_obj) {
  585. return 0;
  586. }
  587. // Object may have been already requested.
  588. ObjectID object_id = encoded_obj->get_object_id();
  589. if (object_list.has(object_id)) {
  590. return object_list[object_id];
  591. }
  592. // Queue requesting the object.
  593. int id = variable_id++;
  594. object_list.insert(object_id, id);
  595. return id;
  596. }
  597. default:
  598. // Simple atomic stuff, or too complex to be manipulated
  599. return 0;
  600. }
  601. }
  602. void DebugAdapterProtocol::parse_object(SceneDebuggerObject &p_obj) {
  603. // If the object is not on the pending list, we weren't expecting it. Ignore it.
  604. ObjectID object_id = p_obj.id;
  605. if (!object_pending_set.erase(object_id)) {
  606. return;
  607. }
  608. // Populate DAP::Variable's with the object's properties. These properties will be divided by categories.
  609. Array properties;
  610. Array script_members;
  611. Array script_constants;
  612. Array script_node;
  613. DAP::Variable node_type;
  614. Array node_properties;
  615. for (SceneDebuggerObject::SceneDebuggerProperty &property : p_obj.properties) {
  616. PropertyInfo &info = property.first;
  617. // Script members ("Members/" prefix)
  618. if (info.name.begins_with("Members/")) {
  619. info.name = info.name.trim_prefix("Members/");
  620. script_members.push_back(parse_object_variable(property));
  621. }
  622. // Script constants ("Constants/" prefix)
  623. else if (info.name.begins_with("Constants/")) {
  624. info.name = info.name.trim_prefix("Constants/");
  625. script_constants.push_back(parse_object_variable(property));
  626. }
  627. // Script node ("Node/" prefix)
  628. else if (info.name.begins_with("Node/")) {
  629. info.name = info.name.trim_prefix("Node/");
  630. script_node.push_back(parse_object_variable(property));
  631. }
  632. // Regular categories (with type Variant::NIL)
  633. else if (info.type == Variant::NIL) {
  634. if (!node_properties.is_empty()) {
  635. node_type.value = itos(node_properties.size());
  636. variable_list.insert(node_type.variablesReference, node_properties.duplicate());
  637. properties.push_back(node_type.to_json());
  638. }
  639. node_type.name = info.name;
  640. node_type.type = "Category";
  641. node_type.variablesReference = variable_id++;
  642. node_properties.clear();
  643. }
  644. // Regular properties.
  645. else {
  646. node_properties.push_back(parse_object_variable(property));
  647. }
  648. }
  649. // Add the last category.
  650. if (!node_properties.is_empty()) {
  651. node_type.value = itos(node_properties.size());
  652. variable_list.insert(node_type.variablesReference, node_properties.duplicate());
  653. properties.push_back(node_type.to_json());
  654. }
  655. // Add the script categories, in reverse order to be at the front of the array:
  656. // ( [members; constants; node; category1; category2; ...] )
  657. if (!script_node.is_empty()) {
  658. DAP::Variable node;
  659. node.name = "Node";
  660. node.type = "Category";
  661. node.value = itos(script_node.size());
  662. node.variablesReference = variable_id++;
  663. variable_list.insert(node.variablesReference, script_node);
  664. properties.push_front(node.to_json());
  665. }
  666. if (!script_constants.is_empty()) {
  667. DAP::Variable constants;
  668. constants.name = "Constants";
  669. constants.type = "Category";
  670. constants.value = itos(script_constants.size());
  671. constants.variablesReference = variable_id++;
  672. variable_list.insert(constants.variablesReference, script_constants);
  673. properties.push_front(constants.to_json());
  674. }
  675. if (!script_members.is_empty()) {
  676. DAP::Variable members;
  677. members.name = "Members";
  678. members.type = "Category";
  679. members.value = itos(script_members.size());
  680. members.variablesReference = variable_id++;
  681. variable_list.insert(members.variablesReference, script_members);
  682. properties.push_front(members.to_json());
  683. }
  684. ERR_FAIL_COND(!object_list.has(object_id));
  685. variable_list.insert(object_list[object_id], properties);
  686. }
  687. void DebugAdapterProtocol::parse_evaluation(DebuggerMarshalls::ScriptStackVariable &p_var) {
  688. // If the eval is not on the pending list, we weren't expecting it. Ignore it.
  689. String eval = p_var.name;
  690. if (!eval_pending_list.erase(eval)) {
  691. return;
  692. }
  693. DAP::Variable variable;
  694. variable.name = p_var.name;
  695. variable.value = p_var.value;
  696. variable.type = Variant::get_type_name(p_var.value.get_type());
  697. variable.variablesReference = parse_variant(p_var.value);
  698. eval_list.insert(variable.name, variable);
  699. }
  700. const Variant DebugAdapterProtocol::parse_object_variable(const SceneDebuggerObject::SceneDebuggerProperty &p_property) {
  701. const PropertyInfo &info = p_property.first;
  702. const Variant &value = p_property.second;
  703. DAP::Variable var;
  704. var.name = info.name;
  705. var.type = Variant::get_type_name(info.type);
  706. var.value = value;
  707. var.variablesReference = parse_variant(value);
  708. return var.to_json();
  709. }
  710. ObjectID DebugAdapterProtocol::search_object_id(DAPVarID p_var_id) {
  711. for (const KeyValue<ObjectID, DAPVarID> &E : object_list) {
  712. if (E.value == p_var_id) {
  713. return E.key;
  714. }
  715. }
  716. return ObjectID();
  717. }
  718. bool DebugAdapterProtocol::request_remote_object(const ObjectID &p_object_id) {
  719. // If the object is already on the pending list, we don't need to request it again.
  720. if (object_pending_set.has(p_object_id)) {
  721. return false;
  722. }
  723. TypedArray<uint64_t> arr;
  724. arr.append(p_object_id);
  725. EditorDebuggerNode::get_singleton()->get_default_debugger()->request_remote_objects(arr);
  726. object_pending_set.insert(p_object_id);
  727. return true;
  728. }
  729. bool DebugAdapterProtocol::request_remote_evaluate(const String &p_eval, int p_stack_frame) {
  730. // If the eval is already on the pending list, we don't need to request it again
  731. if (eval_pending_list.has(p_eval)) {
  732. return false;
  733. }
  734. EditorDebuggerNode::get_singleton()->get_default_debugger()->request_remote_evaluate(p_eval, p_stack_frame);
  735. eval_pending_list.insert(p_eval);
  736. return true;
  737. }
  738. const DAP::Source &DebugAdapterProtocol::fetch_source(const String &p_path) {
  739. const String &global_path = ProjectSettings::get_singleton()->globalize_path(p_path);
  740. HashMap<String, DAP::Source>::Iterator E = breakpoint_source_list.find(global_path);
  741. if (E != breakpoint_source_list.end()) {
  742. return E->value;
  743. }
  744. DAP::Source &added_source = breakpoint_source_list.insert(global_path, DAP::Source())->value;
  745. added_source.name = global_path.get_file();
  746. added_source.path = global_path;
  747. added_source.compute_checksums();
  748. return added_source;
  749. }
  750. void DebugAdapterProtocol::update_source(const String &p_path) {
  751. const String &global_path = ProjectSettings::get_singleton()->globalize_path(p_path);
  752. HashMap<String, DAP::Source>::Iterator E = breakpoint_source_list.find(global_path);
  753. if (E != breakpoint_source_list.end()) {
  754. E->value.compute_checksums();
  755. }
  756. }
  757. bool DebugAdapterProtocol::process_message(const String &p_text) {
  758. JSON json;
  759. ERR_FAIL_COND_V_MSG(json.parse(p_text) != OK, true, "Malformed message!");
  760. Dictionary params = json.get_data();
  761. bool completed = true;
  762. if (OS::get_singleton()->get_ticks_msec() - _current_peer->timestamp > _request_timeout) {
  763. Dictionary response = parser->prepare_error_response(params, DAP::ErrorType::TIMEOUT);
  764. _current_peer->res_queue.push_front(response);
  765. return true;
  766. }
  767. // Append "req_" to any command received; prevents name clash with existing functions, and possibly exploiting
  768. String command = "req_" + (String)params["command"];
  769. if (parser->has_method(command)) {
  770. _current_request = params["command"];
  771. Array args = { params };
  772. Dictionary response = parser->callv(command, args);
  773. if (!response.is_empty()) {
  774. _current_peer->res_queue.push_front(response);
  775. } else {
  776. // Launch request needs to be deferred until we receive a configurationDone request.
  777. if (command != "req_launch") {
  778. completed = false;
  779. }
  780. }
  781. }
  782. reset_current_info();
  783. return completed;
  784. }
  785. void DebugAdapterProtocol::notify_initialized() {
  786. Dictionary event = parser->ev_initialized();
  787. _current_peer->res_queue.push_back(event);
  788. }
  789. void DebugAdapterProtocol::notify_process() {
  790. String launch_mode = _current_peer->attached ? "attach" : "launch";
  791. Dictionary event = parser->ev_process(launch_mode);
  792. for (const Ref<DAPeer> &peer : clients) {
  793. peer->res_queue.push_back(event);
  794. }
  795. }
  796. void DebugAdapterProtocol::notify_terminated() {
  797. Dictionary event = parser->ev_terminated();
  798. for (const Ref<DAPeer> &peer : clients) {
  799. if ((_current_request == "launch" || _current_request == "restart") && _current_peer == peer) {
  800. continue;
  801. }
  802. peer->res_queue.push_back(event);
  803. }
  804. }
  805. void DebugAdapterProtocol::notify_exited(const int &p_exitcode) {
  806. Dictionary event = parser->ev_exited(p_exitcode);
  807. for (const Ref<DAPeer> &peer : clients) {
  808. if ((_current_request == "launch" || _current_request == "restart") && _current_peer == peer) {
  809. continue;
  810. }
  811. peer->res_queue.push_back(event);
  812. }
  813. }
  814. void DebugAdapterProtocol::notify_stopped_paused() {
  815. Dictionary event = parser->ev_stopped_paused();
  816. for (const Ref<DAPeer> &peer : clients) {
  817. peer->res_queue.push_back(event);
  818. }
  819. }
  820. void DebugAdapterProtocol::notify_stopped_exception(const String &p_error) {
  821. Dictionary event = parser->ev_stopped_exception(p_error);
  822. for (const Ref<DAPeer> &peer : clients) {
  823. peer->res_queue.push_back(event);
  824. }
  825. }
  826. void DebugAdapterProtocol::notify_stopped_breakpoint(const int &p_id) {
  827. Dictionary event = parser->ev_stopped_breakpoint(p_id);
  828. for (const Ref<DAPeer> &peer : clients) {
  829. peer->res_queue.push_back(event);
  830. }
  831. }
  832. void DebugAdapterProtocol::notify_stopped_step() {
  833. Dictionary event = parser->ev_stopped_step();
  834. for (const Ref<DAPeer> &peer : clients) {
  835. peer->res_queue.push_back(event);
  836. }
  837. }
  838. void DebugAdapterProtocol::notify_continued() {
  839. Dictionary event = parser->ev_continued();
  840. for (const Ref<DAPeer> &peer : clients) {
  841. if (_current_request == "continue" && peer == _current_peer) {
  842. continue;
  843. }
  844. peer->res_queue.push_back(event);
  845. }
  846. reset_stack_info();
  847. }
  848. void DebugAdapterProtocol::notify_output(const String &p_message, RemoteDebugger::MessageType p_type) {
  849. Dictionary event = parser->ev_output(p_message, p_type);
  850. for (const Ref<DAPeer> &peer : clients) {
  851. peer->res_queue.push_back(event);
  852. }
  853. }
  854. void DebugAdapterProtocol::notify_custom_data(const String &p_msg, const Array &p_data) {
  855. Dictionary event = parser->ev_custom_data(p_msg, p_data);
  856. for (const Ref<DAPeer> &peer : clients) {
  857. if (peer->supportsCustomData) {
  858. peer->res_queue.push_back(event);
  859. }
  860. }
  861. }
  862. void DebugAdapterProtocol::notify_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) {
  863. Dictionary event = parser->ev_breakpoint(p_breakpoint, p_enabled);
  864. for (const Ref<DAPeer> &peer : clients) {
  865. if (_current_request == "setBreakpoints" && peer == _current_peer) {
  866. continue;
  867. }
  868. peer->res_queue.push_back(event);
  869. }
  870. }
  871. Array DebugAdapterProtocol::update_breakpoints(const String &p_path, const Array &p_lines) {
  872. Array updated_breakpoints;
  873. // Add breakpoints
  874. for (int i = 0; i < p_lines.size(); i++) {
  875. DAP::Breakpoint breakpoint(fetch_source(p_path));
  876. breakpoint.line = p_lines[i];
  877. // Avoid duplicated entries.
  878. List<DAP::Breakpoint>::Element *E = breakpoint_list.find(breakpoint);
  879. if (E) {
  880. updated_breakpoints.push_back(E->get().to_json());
  881. continue;
  882. }
  883. EditorDebuggerNode::get_singleton()->get_default_debugger()->_set_breakpoint(p_path, p_lines[i], true);
  884. // Breakpoints are inserted at the end of the breakpoint list.
  885. List<DAP::Breakpoint>::Element *added_breakpoint = breakpoint_list.back();
  886. ERR_FAIL_NULL_V(added_breakpoint, Array());
  887. ERR_FAIL_COND_V(!(added_breakpoint->get() == breakpoint), Array());
  888. updated_breakpoints.push_back(added_breakpoint->get().to_json());
  889. }
  890. // Remove breakpoints
  891. // Must be deferred because we are iterating the breakpoint list.
  892. Vector<int> to_remove;
  893. for (const DAP::Breakpoint &b : breakpoint_list) {
  894. if (b.source->path == p_path && !p_lines.has(b.line)) {
  895. to_remove.push_back(b.line);
  896. }
  897. }
  898. // Safe to remove queued data now.
  899. for (const int &line : to_remove) {
  900. EditorDebuggerNode::get_singleton()->get_default_debugger()->_set_breakpoint(p_path, line, false);
  901. }
  902. return updated_breakpoints;
  903. }
  904. void DebugAdapterProtocol::on_debug_paused() {
  905. if (EditorRunBar::get_singleton()->get_pause_button()->is_pressed()) {
  906. notify_stopped_paused();
  907. } else {
  908. notify_continued();
  909. }
  910. }
  911. void DebugAdapterProtocol::on_debug_stopped() {
  912. notify_exited();
  913. notify_terminated();
  914. reset_ids();
  915. }
  916. void DebugAdapterProtocol::on_debug_output(const String &p_message, int p_type) {
  917. notify_output(p_message, RemoteDebugger::MessageType(p_type));
  918. }
  919. void DebugAdapterProtocol::on_debug_breaked(const bool &p_reallydid, const bool &p_can_debug, const String &p_reason, const bool &p_has_stackdump) {
  920. if (!p_reallydid) {
  921. notify_continued();
  922. return;
  923. }
  924. if (p_reason == "Breakpoint") {
  925. if (_stepping) {
  926. notify_stopped_step();
  927. _stepping = false;
  928. } else {
  929. _processing_breakpoint = true; // Wait for stack_dump to find where the breakpoint happened
  930. }
  931. } else {
  932. notify_stopped_exception(p_reason);
  933. }
  934. _processing_stackdump = p_has_stackdump;
  935. }
  936. void DebugAdapterProtocol::on_debug_breakpoint_toggled(const String &p_path, const int &p_line, const bool &p_enabled) {
  937. DAP::Breakpoint breakpoint(fetch_source(p_path));
  938. breakpoint.verified = true;
  939. breakpoint.line = p_line;
  940. if (p_enabled) {
  941. // Add the breakpoint
  942. breakpoint.id = breakpoint_id++;
  943. breakpoint_list.push_back(breakpoint);
  944. } else {
  945. // Remove the breakpoint
  946. List<DAP::Breakpoint>::Element *E = breakpoint_list.find(breakpoint);
  947. if (E) {
  948. breakpoint.id = E->get().id;
  949. breakpoint_list.erase(E);
  950. }
  951. }
  952. notify_breakpoint(breakpoint, p_enabled);
  953. }
  954. void DebugAdapterProtocol::on_debug_stack_dump(const Array &p_stack_dump) {
  955. if (_processing_breakpoint && !p_stack_dump.is_empty()) {
  956. // Find existing breakpoint
  957. Dictionary d = p_stack_dump[0];
  958. DAP::Breakpoint breakpoint(fetch_source(d["file"]));
  959. breakpoint.line = d["line"];
  960. List<DAP::Breakpoint>::Element *E = breakpoint_list.find(breakpoint);
  961. if (E) {
  962. notify_stopped_breakpoint(E->get().id);
  963. }
  964. _processing_breakpoint = false;
  965. }
  966. stackframe_id = 0;
  967. stackframe_list.clear();
  968. scope_list.clear();
  969. // Fill in stacktrace information
  970. for (int i = 0; i < p_stack_dump.size(); i++) {
  971. Dictionary stack_info = p_stack_dump[i];
  972. DAP::StackFrame stackframe(fetch_source(stack_info["file"]));
  973. stackframe.id = stackframe_id++;
  974. stackframe.name = stack_info["function"];
  975. stackframe.line = stack_info["line"];
  976. stackframe.column = 0;
  977. // Information for "Locals", "Members" and "Globals" variables respectively
  978. Vector<int> scope_ids;
  979. for (int j = 0; j < 3; j++) {
  980. scope_ids.push_back(variable_id++);
  981. }
  982. stackframe_list.push_back(stackframe);
  983. scope_list.insert(stackframe.id, scope_ids);
  984. }
  985. _current_frame = 0;
  986. _processing_stackdump = false;
  987. }
  988. void DebugAdapterProtocol::on_debug_stack_frame_vars(const int &p_size) {
  989. _remaining_vars = p_size;
  990. ERR_FAIL_COND(!scope_list.has(_current_frame));
  991. Vector<int> scope_ids = scope_list.find(_current_frame)->value;
  992. for (const int &var_id : scope_ids) {
  993. if (variable_list.has(var_id)) {
  994. variable_list.find(var_id)->value.clear();
  995. } else {
  996. variable_list.insert(var_id, Array());
  997. }
  998. }
  999. }
  1000. void DebugAdapterProtocol::on_debug_stack_frame_var(const Array &p_data) {
  1001. DebuggerMarshalls::ScriptStackVariable stack_var;
  1002. stack_var.deserialize(p_data);
  1003. ERR_FAIL_COND(!scope_list.has(_current_frame));
  1004. Vector<int> scope_ids = scope_list.find(_current_frame)->value;
  1005. ERR_FAIL_COND(scope_ids.size() != 3);
  1006. ERR_FAIL_INDEX(stack_var.type, 4);
  1007. int var_id = scope_ids.get(stack_var.type);
  1008. DAP::Variable variable;
  1009. variable.name = stack_var.name;
  1010. variable.value = stack_var.value;
  1011. variable.type = Variant::get_type_name(stack_var.value.get_type());
  1012. variable.variablesReference = parse_variant(stack_var.value);
  1013. variable_list.find(var_id)->value.push_back(variable.to_json());
  1014. _remaining_vars--;
  1015. }
  1016. void DebugAdapterProtocol::on_debug_data(const String &p_msg, const Array &p_data) {
  1017. // Ignore data that is already handled by DAP
  1018. if (p_msg == "debug_enter" || p_msg == "debug_exit" || p_msg == "stack_dump" || p_msg == "stack_frame_vars" || p_msg == "stack_frame_var" || p_msg == "output" || p_msg == "request_quit") {
  1019. return;
  1020. }
  1021. if (p_msg == "scene:inspect_objects") {
  1022. if (!p_data.is_empty()) {
  1023. // An object was requested from the debuggee; parse it.
  1024. SceneDebuggerObject remote_obj;
  1025. remote_obj.deserialize(p_data[0]);
  1026. parse_object(remote_obj);
  1027. }
  1028. } else if (p_msg == "evaluation_return") {
  1029. // An evaluation was requested from the debuggee; parse it.
  1030. DebuggerMarshalls::ScriptStackVariable remote_evaluation;
  1031. remote_evaluation.deserialize(p_data);
  1032. parse_evaluation(remote_evaluation);
  1033. }
  1034. notify_custom_data(p_msg, p_data);
  1035. }
  1036. void DebugAdapterProtocol::poll() {
  1037. if (server->is_connection_available()) {
  1038. on_client_connected();
  1039. }
  1040. List<Ref<DAPeer>> to_delete;
  1041. for (const Ref<DAPeer> &peer : clients) {
  1042. peer->connection->poll();
  1043. StreamPeerTCP::Status status = peer->connection->get_status();
  1044. if (status == StreamPeerTCP::STATUS_NONE || status == StreamPeerTCP::STATUS_ERROR) {
  1045. to_delete.push_back(peer);
  1046. } else {
  1047. _current_peer = peer;
  1048. Error err = peer->handle_data();
  1049. if (err != OK && err != ERR_BUSY) {
  1050. to_delete.push_back(peer);
  1051. }
  1052. err = peer->send_data();
  1053. if (err != OK && err != ERR_BUSY) {
  1054. to_delete.push_back(peer);
  1055. }
  1056. }
  1057. }
  1058. for (const Ref<DAPeer> &peer : to_delete) {
  1059. on_client_disconnected(peer);
  1060. }
  1061. to_delete.clear();
  1062. }
  1063. Error DebugAdapterProtocol::start(int p_port, const IPAddress &p_bind_ip) {
  1064. _request_timeout = (uint64_t)_EDITOR_GET("network/debug_adapter/request_timeout");
  1065. _sync_breakpoints = (bool)_EDITOR_GET("network/debug_adapter/sync_breakpoints");
  1066. _initialized = true;
  1067. return server->listen(p_port, p_bind_ip);
  1068. }
  1069. void DebugAdapterProtocol::stop() {
  1070. for (const Ref<DAPeer> &peer : clients) {
  1071. peer->connection->disconnect_from_host();
  1072. }
  1073. clients.clear();
  1074. server->stop();
  1075. _initialized = false;
  1076. }
  1077. DebugAdapterProtocol::DebugAdapterProtocol() {
  1078. server.instantiate();
  1079. singleton = this;
  1080. parser = memnew(DebugAdapterParser);
  1081. reset_ids();
  1082. EditorRunBar::get_singleton()->get_pause_button()->connect(SceneStringName(pressed), callable_mp(this, &DebugAdapterProtocol::on_debug_paused));
  1083. EditorDebuggerNode *debugger_node = EditorDebuggerNode::get_singleton();
  1084. debugger_node->connect("breakpoint_toggled", callable_mp(this, &DebugAdapterProtocol::on_debug_breakpoint_toggled));
  1085. debugger_node->get_default_debugger()->connect("stopped", callable_mp(this, &DebugAdapterProtocol::on_debug_stopped));
  1086. debugger_node->get_default_debugger()->connect(SceneStringName(output), callable_mp(this, &DebugAdapterProtocol::on_debug_output));
  1087. debugger_node->get_default_debugger()->connect("breaked", callable_mp(this, &DebugAdapterProtocol::on_debug_breaked));
  1088. debugger_node->get_default_debugger()->connect("stack_dump", callable_mp(this, &DebugAdapterProtocol::on_debug_stack_dump));
  1089. debugger_node->get_default_debugger()->connect("stack_frame_vars", callable_mp(this, &DebugAdapterProtocol::on_debug_stack_frame_vars));
  1090. debugger_node->get_default_debugger()->connect("stack_frame_var", callable_mp(this, &DebugAdapterProtocol::on_debug_stack_frame_var));
  1091. debugger_node->get_default_debugger()->connect("debug_data", callable_mp(this, &DebugAdapterProtocol::on_debug_data));
  1092. }
  1093. DebugAdapterProtocol::~DebugAdapterProtocol() {
  1094. memdelete(parser);
  1095. }