godotengine / godot-vscode-plugin

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

Attaching the Debugger to Running Godot 4.1 Mono Instance Does Not Work Using Latest #530

Open TheKizzyDev opened 8 months ago

TheKizzyDev commented 8 months ago

Godot version

v4.1.2.stable.mono.official [399c9dc39]

VS Code version

1.84.2

Godot Tools VS Code extension version

f65033c

System information

Windows 11

Issue description

I'd like to debug the currently selected scene in the Godot Editor from vscode. When I run it, and connect to to the debug server from vscode, it does not trigger any of the breakpoints. It seems to connect to the debug server without error though.

When I run the same scene by launching it from vscode, it works. There are disadvantages to this in that I can't configure the scene to show debug information e.g. show collisions, etc.

NOTE: I can't test whether this works in other versions of the tool since Godot 4 debugging is not supported there yet. I'm waiting on these changes to release #452

Steps to reproduce

  1. In the Godot Editor, verify the Editor Settings > Network > Debug settings are the following: Remote Host: 127.0.0.1 Remote Port: 6007
  2. Verify the Debug > Deploy with Remote Debug is enabled.
  3. Select a non-main scene with a script you want to debug, and run it using, "Run Current Scene (F6)".
  4. In vscode, create a launch.json with the following entry:
    {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "GDScript: Attach to Godot",
            "type": "godot",
            "request": "attach",
            "address": "127.0.0.1",
            "port": 6007
        }
    ]
    }
  5. Go to the script in vscode, and add breakpoints.
  6. Run the above "GDScript: Attach to Godot" configuration.
  7. Test the scene. None of the breakpoints should trigger.
DaelonSuzuka commented 8 months ago

Unfortunately, this is the expected behavior right now. I had to prioritize making launch sessions work consistently and reliably across Godot versions, and I haven't been able to get attach sessions working to that same standard.

389 contains a discussion of possible workarounds. Anything that uses "debugServer" should still work after #452, because that uses an entirely different protocol and completely bypasses the extension's debugger code. Sadly, that protocol only supports some of the debugger features, and I have not personally been able to get it to work reliably.

There are disadvantages to this in that I can't configure the scene to show debug information e.g. show collisions, etc.

Of course you can, just add "additional_options": "--debug-collisions" or similar to your debug configuration. The possible flags are available in the docs here: https://docs.godotengine.org/en/stable/tutorials/editor/command_line_tutorial.html

DaelonSuzuka commented 8 months ago

I just added most of the engine's debug CLI flags as explicit debug config parameters in #529. This should be merged to master soon(tm).

ex:


{
    "name": "Launch",
    "type": "godot",
    "request": "launch",
    // engine command line flags
    "profiling": false,
    "single_threaded_scene": false,
    "debug_collisions": false,
    "debug_paths": false,
    "debug_navigation": false,
    "debug_avoidance": false,
    "debug_stringnames": false,
    "frame_delay": 0,
    "time_scale": 1.0,
    "disable_vsync": false,
    "fixed_fps": 60,
    // anything else
    "additional_options": ""
}
TheKizzyDev commented 8 months ago

@DaelonSuzuka thanks for the quick reply, and great job so far! I missed the workaround in #389 , and I'll try what's there.

It's understandable that getting the launch feature to work first was priority. IMO, this fix is just a quality of life improvement to an already good tool.

UPDATE: The workaround works. Thank you!

DaelonSuzuka commented 4 months ago

Unfortunately, I still haven't gotten attach sessions to work. At this point I'm not certain it's possible.

The recommended way to use the debugger from VSCode is using a launch session without using the debugServer option. Using debugServer works kind of like an attach session, but none of this extension's custom debug features will work if you do that.

TheKizzyDev commented 4 months ago

@DaelonSuzuka thanks for the update!

Yeah, it's fine. Thank you for trying.

I've been working around the issue by just using the launch session rather than attach.

I do enjoy Godot's editor, but there are times when I want/miss/need features from another tool already provides like vscode that I can't reasonably expect Godot to implement.

Is there a feature proposal or something I can upvote to make the debugServer more extendable for external tools?

DaelonSuzuka commented 4 months ago

Is there a feature proposal or something I can upvote to make the debugServer more extendable for external tools?

No idea, but the term to search for is "Debug Adapter Protocol". The usual Godot debugger uses a custom protocol, which is a particular message/packet format sent over a TCP stream. DAP is a totally different protocol, which I haven't investigated beyond understanding that it's totally incompatible with the existing debug protocol.

(DAP docs: https://microsoft.github.io/debug-adapter-protocol)