editor_debugger_plugin.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*************************************************************************/
  2. /* editor_debugger_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "editor_debugger_plugin.h"
  31. #include "editor/debugger/script_editor_debugger.h"
  32. void EditorDebuggerPlugin::_breaked(bool p_really_did, bool p_can_debug, String p_message, bool p_has_stackdump) {
  33. if (p_really_did) {
  34. emit_signal(SNAME("breaked"), p_can_debug);
  35. } else {
  36. emit_signal(SNAME("continued"));
  37. }
  38. }
  39. void EditorDebuggerPlugin::_started() {
  40. emit_signal(SNAME("started"));
  41. }
  42. void EditorDebuggerPlugin::_stopped() {
  43. emit_signal(SNAME("stopped"));
  44. }
  45. void EditorDebuggerPlugin::_bind_methods() {
  46. ClassDB::bind_method(D_METHOD("send_message", "message", "data"), &EditorDebuggerPlugin::send_message);
  47. ClassDB::bind_method(D_METHOD("register_message_capture", "name", "callable"), &EditorDebuggerPlugin::register_message_capture);
  48. ClassDB::bind_method(D_METHOD("unregister_message_capture", "name"), &EditorDebuggerPlugin::unregister_message_capture);
  49. ClassDB::bind_method(D_METHOD("has_capture", "name"), &EditorDebuggerPlugin::has_capture);
  50. ClassDB::bind_method(D_METHOD("is_breaked"), &EditorDebuggerPlugin::is_breaked);
  51. ClassDB::bind_method(D_METHOD("is_debuggable"), &EditorDebuggerPlugin::is_debuggable);
  52. ClassDB::bind_method(D_METHOD("is_session_active"), &EditorDebuggerPlugin::is_session_active);
  53. ADD_SIGNAL(MethodInfo("started"));
  54. ADD_SIGNAL(MethodInfo("stopped"));
  55. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "can_debug")));
  56. ADD_SIGNAL(MethodInfo("continued"));
  57. }
  58. void EditorDebuggerPlugin::attach_debugger(ScriptEditorDebugger *p_debugger) {
  59. debugger = p_debugger;
  60. if (debugger) {
  61. debugger->connect("started", callable_mp(this, &EditorDebuggerPlugin::_started));
  62. debugger->connect("stopped", callable_mp(this, &EditorDebuggerPlugin::_stopped));
  63. debugger->connect("breaked", callable_mp(this, &EditorDebuggerPlugin::_breaked));
  64. }
  65. }
  66. void EditorDebuggerPlugin::detach_debugger(bool p_call_debugger) {
  67. if (debugger) {
  68. debugger->disconnect("started", callable_mp(this, &EditorDebuggerPlugin::_started));
  69. debugger->disconnect("stopped", callable_mp(this, &EditorDebuggerPlugin::_stopped));
  70. debugger->disconnect("breaked", callable_mp(this, &EditorDebuggerPlugin::_breaked));
  71. if (p_call_debugger && get_script_instance()) {
  72. debugger->remove_debugger_plugin(get_script_instance()->get_script());
  73. }
  74. debugger = nullptr;
  75. }
  76. }
  77. void EditorDebuggerPlugin::send_message(const String &p_message, const Array &p_args) {
  78. ERR_FAIL_COND_MSG(!debugger, "Plugin is not attached to debugger");
  79. debugger->send_message(p_message, p_args);
  80. }
  81. void EditorDebuggerPlugin::register_message_capture(const StringName &p_name, const Callable &p_callable) {
  82. ERR_FAIL_COND_MSG(!debugger, "Plugin is not attached to debugger");
  83. debugger->register_message_capture(p_name, p_callable);
  84. }
  85. void EditorDebuggerPlugin::unregister_message_capture(const StringName &p_name) {
  86. ERR_FAIL_COND_MSG(!debugger, "Plugin is not attached to debugger");
  87. debugger->unregister_message_capture(p_name);
  88. }
  89. bool EditorDebuggerPlugin::has_capture(const StringName &p_name) {
  90. ERR_FAIL_COND_V_MSG(!debugger, false, "Plugin is not attached to debugger");
  91. return debugger->has_capture(p_name);
  92. }
  93. bool EditorDebuggerPlugin::is_breaked() {
  94. ERR_FAIL_COND_V_MSG(!debugger, false, "Plugin is not attached to debugger");
  95. return debugger->is_breaked();
  96. }
  97. bool EditorDebuggerPlugin::is_debuggable() {
  98. ERR_FAIL_COND_V_MSG(!debugger, false, "Plugin is not attached to debugger");
  99. return debugger->is_debuggable();
  100. }
  101. bool EditorDebuggerPlugin::is_session_active() {
  102. ERR_FAIL_COND_V_MSG(!debugger, false, "Plugin is not attached to debugger");
  103. return debugger->is_session_active();
  104. }
  105. EditorDebuggerPlugin::~EditorDebuggerPlugin() {
  106. detach_debugger(true);
  107. }