ShadowApex / godot-go

Go language bindings for the Godot Engine's GDNative API.
MIT License
363 stars 31 forks source link

Debugging #41

Open bryab opened 6 years ago

bryab commented 6 years ago

Hey, I was wondering if you all could provide a short guide on how to set this up for debugging. I am honestly new to Go and pretty new to Godot too.

Is it possible to debug this shared library while Godot is running?

ShadowApex commented 6 years ago

You can do some debugging with gdb with the following (Linux/Mac OSX):

  1. Compile Godot with debug symbols:

    git clone https://github.com/godotengine/godot.git
    git fetch && git checkout 3.0
    scons platform=<osx/x11> target=debug --jobs 4
  2. Then run Godot with GDB to catch any crashes or segfaults. You can install GDB with any Linux package manager or brew on OSX, then you can run the debug version of Godot with GDB:

    gdb godot
  3. Then set following forked processes and run Godot in GDB:

    (gdb) set follow-fork-mode child
    (gdb) run

Now if you experience a segfault, you can print a backtrace with bt:

#0  0x0000555557575e10 in Vector<SceneState::NodeData>::_get_size (this=0x148) at core/vector.h:61
#1  0x000055555757326c in Vector<SceneState::NodeData>::size (this=0x148) at core/vector.h:113
#2  0x0000555557565306 in SceneState::can_instance (this=0x0) at scene/resources/packed_scene.cpp:45
#3  0x0000555557571002 in PackedScene::can_instance (this=0x55555a0e4c70) at scene/resources/packed_scene.cpp:1670
#4  0x00005555562ec0e2 in MethodBind0RC<bool>::ptrcall (this=0x555559d88240, p_object=0x55555a0e4c70, p_args=0x55555a237380, r_ret=0xc420173a0c) at core/method_bind.gen.inc:565
#5  0x00005555564ba4ec in godot_method_bind_ptrcall (p_method_bind=0x555559d88240, p_instance=0x55555a0e4c70, p_args=0x55555a237380, p_ret=0xc420173a0c) at modules/gdnative/gdnative/gdnative.cpp:69
#6  0x00007fffd64093c8 in runtime.asmcgocall () at /usr/share/go-1.10/src/runtime/asm_amd64.s:688
#7  0x0000000000000810 in ?? ()
#8  0x0000000000000000 in ?? ()