godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.47k stars 148 forks source link

Support for debugging GDNative #675

Open SailorJoe6 opened 2 days ago

SailorJoe6 commented 2 days ago

Godot version

3.5

VS Code version

1.90.2 universal

Godot Tools VS Code extension version

2.0.0

System information

MacBook Pro M1 with Sonoma OS

Problem statement

I want to be able to step into my GDNative code while debugging. I used to be able to make this work on my Intel mac, but it was quite a hassle. Now that the this plugin exists, working with Godot is beautifully simple, except the plugin doesn't automatically allow you to step into my GDNative code. Now I have to find a wacky workaround, which is harder than ever with the universal build of Godot running on an Apple Silicon. I suppose I'll have to create a task that launches lldb-mi, finds the running process of godot and attaches to it for debugging into my GDNative code. This would be so much nicer if it was just a working feature of the plugin.

Proposed solution

Make sure to attach to any GDNative plugins that are running as part of the scene?

DaelonSuzuka commented 2 days ago

Yeah, that's probably not gonna happen. It took me more than six months to update the GDScript debugger for Godot 4, and "all" that's doing is translating messages from Godot's debug socket into a form that VSCode understands.

Add to that the fact that I don't really know anything about GDNative, I have no plans to use GDNative in my personal projects, and I expect very few people would ever use this feature... The return on investment just isn't there.

SailorJoe6 commented 1 day ago

Ok. Well, I guess that is what it is. For anyone who does use GDNative (or as it's called in Godot 4, GDPlugins) the problem wasn't too hard to solve. You need the CodeLLDB plugin installed to VSCode (which is recommended by Godot anyway) and if you're running on a recent mac, you need to follow the steps outlined in https://docs.godotengine.org/en/stable/contributing/development/debugging/macos_debug.html in order to attach to a running Godot instance. With that done, the following launch.json solves the issue:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "GDScript: Launch Project",
            "type": "godot",
            "request": "launch",
            "project": "${workspaceFolder}"
        },
        {
            "name": "godot-attach",
            "type": "lldb",
            "request": "attach",
            "program": "${config:godotTools.editorPath.godot3}" //adjust if you're using godot4
        }
    ],
    "compounds": [
        {
            "name": "godot-complete-launch",
            "configurations": [
                "GDScript: Launch Project",
                "godot-attach"
            ]
        }
    ]    
}

Set up "godot-complete-launch" as your default and then F5 will launch this plugin as usual, but also attach an LLDB session to it, so you can debug the C++ code in your plugin. Note: If you compile Godot from source, you can even debug Godot this way (not that you would want to do that).

DaelonSuzuka commented 1 day ago

Does this create two separate debug sessions or are they somehow merged together?