microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.81k stars 131 forks source link

Hitting a breakpoint in symlinked file opens a new instance of the file #1495

Open dasz-odoo opened 8 months ago

dasz-odoo commented 8 months ago

Type: Bug

Behaviour

Expected vs. Actual

I develop addons for an open source project, in order to have all standard files + my customised addons files I open the project repository and have a symlink to my custom addons directory. Using breakpoints in those files always open a new tab. When I open the file for working, the path is /dev/my_custom_addon/.../file.py which is a symlink to my_home/work/dev/... which is also the path that my debugger opens when hitting the breakpoint i.e. not the short symlink path but the absolute path

Steps to reproduce:

  1. put a breakpoint in a symlinked file
  2. run your program and hit that breakpoint
  3. vscode will open the same file but from the absolute path, not the symlinked path

Expected Behavior:

Do not open the same file from the symlinked path. Stop the debugger in the same file where I put my breakpoint.

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` XXX ```

User Settings

``` languageServer: "Pylance" ```

VS Code version: Code 1.85.1 (0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2, 2023-12-13T09:47:11.635Z) OS version: Linux x64 5.15.0-91-generic snap Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz (8 x 2390)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
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
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|2, 2, 2| |Memory (System)|15.43GB (6.64GB free)| |Process Argv|--no-sandbox --force-user-env --unity-launch --crash-reporter-id 7eaf83cf-f98c-4cc8-8689-c053473e589c| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|cinnamon| |XDG_CURRENT_DESKTOP|X-Cinnamon| |XDG_SESSION_DESKTOP|cinnamon| |XDG_SESSION_TYPE|x11|
Extensions (32) Extension|Author (truncated)|Version ---|---|--- comment-tagged-templates|bie|0.3.2 es7-react-js-snippets|dsz|4.4.3 gitlens|eam|14.6.1 restore-terminals|Eth|1.1.8 auto-rename-tag|for|0.1.10 copilot|Git|1.147.0 copilot-chat|Git|0.11.1 better-cpp-syntax|jef|1.17.2 OdooSnippets|jig|1.5.0 vscode-redux-devtools|jin|1.0.2 cmake-language-support-vscode|jos|0.0.9 rainbow-csv|mec|3.11.0 vscode-scss|mrm|0.10.0 language-gettext|mro|0.2.2 vscode-docker|ms-|1.28.0 csharp|ms-|2.14.8 vscode-dotnet-runtime|ms-|2.0.0 flake8|ms-|2023.10.0 isort|ms-|2023.10.1 python|ms-|2023.22.1 vscode-pylance|ms-|2023.12.1 cmake-tools|ms-|1.16.32 cpptools|ms-|1.18.5 cpptools-extension-pack|ms-|1.3.0 hexeditor|ms-|1.9.12 jinja-snippets|nox|1.0.0 vscode-xml|red|0.26.1 LiveServer|rit|5.7.9 jinjahtml|sam|0.20.0 cmake|twx|0.0.17 gitblame|wad|10.6.0 jinja|who|0.0.8 (1 theme extensions excluded)
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vshan820:30294714 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 py29gd2263:30899288 vsclangdc:30486549 c4g48928:30535728 azure-dev_surveyone:30548225 a9j8j154:30646983 0bi6i642:30933247 pythongtdpath:30769146 i26e3531:30792625 welcomedialogc:30910334 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30928863 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 accentitlementsc:30887149 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 aa_t_chat:30882232 cp7184t3:30927821 ```
dasz-odoo commented 8 months ago

this is the same as https://github.com/microsoft/ptvsd/issues/2094 which also links 3 other issues of the same nature

gigberg commented 6 months ago

as this thread mentioned Symbolic links to folders can lead to the same file opened in two tabs #100533, you could add pathMapping option in you debugpy launch.json.

for me example: true path /usr/local/yourname symlinked path /home/yourname

i add pathMapping option in my launch.json, and when remote on port 5678, vscode can be:

        {
            "name": "Python: Remote Attach",
            // python -m debugpy --listen 5678 --wait-for-client train.py --arg1 ARG1
            // then run the code whih this launch.json
            "type": "debugpy",
            // attach
            "request": "attach",
            "justMyCode": false,
        "connect": {
            "host": "localhost",
            "port": 5678
        },
            "pathMappings": [
                {
                    "localRoot": "/home/yourname", // your project prefered path, usually symlinked path
                    "remoteRoot": "/usr/local/yourname" //  another path
                }
            ]
          },

however, i have only test when remote debug client and server is on the same machine. and this only work in debugpy situation, not for search return two results, or run bash command: code xxxfile open two tab.

A guess, everytime debugpy request for symlinked file (this always happen), then it change to request for true file according to the pathMapping. As a consequence, vscode get file open request against true file( the key is that the request path should be as same as the project path in vscode).