debug_adapter_protocol.cpp 38 KB

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