Debugging custom module

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By qofa

How can I debug my module when running the godot editor?

When I print to stdout or stderr from within the module, nothing appears in the editor. The debugger in the editor does not debug module code.

Running the editor from the command line or running it in gdb doesnt produce any output either…

Try starting the editor from a terminal/command prompt and look at the output there instead.

Calinou | 2020-09-20 23:04

I have done that. The output is not there either.

qofa | 2020-09-21 00:08

:bust_in_silhouette: Reply From: Zylann

To debug a module you must get familiar with C++ debugging. Running a compiled executable straight away will get you very poor information. Also, the debugger inside Godot has nothing to do with C++, it is meant for GDScript.

print_line("Hello"); or printf("Hello\n"); is the simplest way to “debug” but you need to have a system console available when the editor opens. Like Calinou suggested, try opening the editor from the command line. To do this you must go to your project directory, write the path to the Godot executable and add the -e argument to start your project in editor mode.
See Command line tutorial — Godot Engine (stable) documentation in English

However this workflow won’t catch deeper C++ errors, and won’t give you interactive callstacks when something wrong happens. You should use a debugger to be able to catch them, step through the code, put breakpoints, look at variable values etc.
You can use GDB from command line, however if you use an IDE like VSCode, Visual Studio or QtCreator, there should be an interface letting you debug the editor by default.
Of course, to debug the editor you must also build it using target=debug in your SCons options.
See Configuring an IDE — Godot Engine (stable) documentation in English