microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
192 stars 6 forks source link

Attach debugger not consistently working #1076

Open Js-Wizard opened 3 weeks ago

Js-Wizard commented 3 weeks ago

Type: Bug

Open Unity project. Activate debug mode. Open script in VS code. Run attach debugger command, selecting Unity editor instance. Debugger attaches as expected. Then, detach debugger. Deactivate and then reactivate debug mode in Unity. Try to attach debugger again and it fails, not expected. Starts working again if VS code is closed and then opened again by double-clicking a script in Unity.

Extension version: 1.0.1 VS Code version: Code 1.88.1 (e170252f762678dec6ca2cc69aba1570769a5d39, 2024-04-10T17:41:02.734Z) OS version: Windows_NT x64 10.0.22621 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 x 1498)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|11.77GB (1.63GB free)| |Process Argv|C:\\Users\\brent\\UnityProjects\\wgl test -g C:\\Users\\brent\\UnityProjects\\wgl test\\Assets\\HelloWorld.cs:1:0 --crash-reporter-id 4d00c348-05c3-4fcc-8fad-e0310cdba0de| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscoreces:30445986 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyonecf:30548226 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 ccp2r3:30993541 dsvsc020:30976470 pythonait:31006305 gee8j676:31009558 chatpanelt:31018789 dsvsc021:30996838 g316j359:31013175 pythoncenvpt:31022790 ```
jbevain commented 3 weeks ago

Hi @Js-Wizard,

Thanks for reaching out.

Could you modify your launch.json to include some logging:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Unity",
            "type": "vstuc",
            "request": "attach",
            "logFile": "${workspaceRoot}/debug.log"
        }
    ]
}

And check for any exception in there whenever attaching doesn't work? Thank you!

Js-Wizard commented 3 weeks ago

Log: debug.log

Unity Editor version: 2022.3.25f1

When reproducing the bug this time, I was unable to reproduce it until I closed and reopened the Unity project.

github-actions[bot] commented 3 weeks ago

@jbevain, the 'needs-more-info' label has been removed upon receiving further response from the original bug filer.

jbevain commented 3 weeks ago

@Js-Wizard, thanks! This one exception we have a fix for that will be release soon, it can be happening when it's not successfully connecting.

It's not giving us the root of the issue though. From your description, the first debugging works, then the second one doesn't. That log is for the second session. It's possible that something is happening in the first session that is setting the debugger in a weird state. Is there anything interesting the in the log for the first session? Thanks!

Js-Wizard commented 3 weeks ago

@jbevain Here is the log from the successful attempt: debug.log

The log covers attaching and then manually detaching. The last couple lines are from detaching.

jbevain commented 3 weeks ago

Hi @Js-Wizard,

Thanks for providing those logs. Unfortunately, there's nothing obvious in there that would point at an issue. Obviously, this is not something that we can reproduce, so I'm wondering if it may be specific to either your environment or your project.

Thanks!

Js-Wizard commented 3 weeks ago

@jbevain

Unity editor version: reproduced with 2022.3.25f1 and 2021.3.20f1 "Visual Studio Editor" Unity package version: 2.0.22 "Visual Studio Code Editor" Unity package version: 1.2.5 "C# Dev Kit" VS Code extension version: 1.4.29 "Unity" VS Code extension version: 1.0.1

The bug reproduces in a fresh new project on both Unity editor versions.

Additional information: It appears that the bug only occurs when VS Code is opened via the opening of a script from the Unity editor asset browser. If VS Code is opened independently instead, and the same Unity project folder is opened, the bug does not occur.

jbevain commented 2 weeks ago

OK I can finally repro, investigating, thanks for the guidance so far.

jbevain commented 2 weeks ago

At this point we believe the issue is partly in Unity. We're collaborating with them on trying to find a solution.

@Js-Wizard I'm curious about the workflow though, why do you need to disable and re-enable debug mode in Unity?

Js-Wizard commented 2 weeks ago

@jbevain The mode toggles between debug mode and release mode. Debug mode allows C# debugging, while release mode has better C# performance, more accurately representing the performance of the build. Both debugging and performance optimization can be required throughout development, so sometimes I need to switch the mode several times in one session, especially if there are bugs in a new optimization.