Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using "request": "launch" item in launch.json for debugging does not send pathMappings #3568

Closed
karthiknadig opened this issue Dec 5, 2018 · 11 comments
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority

Comments

@karthiknadig
Copy link
Member

@gigi206 commented on Mon Oct 29 2018

Environment data

  • PTVSD version: 4.1.4
  • OS and version: Windows with msys2
  • Python version : 3.6.6

Issue

I use VSCode with extension ms-python.python-2018.9.1 and I use python under msys2 (cygwin like) :

$ python
Python 3.6.6 (default, Jun 28 2018, 10:27:26)
[GCC 7.3.0] on msys
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.platform
'msys'
>>>

When I try to debug a python file I have the following message :

pydev debugger: warning: trying to add breakpoint to file that does not exist: /:\Users\gigi\Desktop\python\gigix.py (will have no effect)

From pydevd_file_utils.py file, if I replace L231 by the following line, it works :

        real_path = subprocess.getoutput("cygpath -a '{}'".format(filename))

https://github.com/Microsoft/ptvsd/blob/66d75d8c87c848d0f7b60102ac6a2a134c34eae4/ptvsd/_vendored/pydevd/pydevd_file_utils.py#L231

I opened this issue (fabioz/PyDev.Debugger#125) but it seems that it should open here...

Is it possible to add a test to determine the path under cygwin / msys2 ?


@karthiknadig commented on Thu Nov 01 2018

Can you give the launch configuration you are using for this?


@gigi206 commented on Fri Nov 02 2018

I use the default configuration :

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost"
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "enter-your-module-name-here",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}

When I select Python: Current File (Integrated Terminal) and I start the debug, it works but I have the following message :

PS C:\Users\gigi\Desktop\python> cd 'c:\Users\gigi\Desktop\python'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'C:\Users\gigi\Desktop\VSCode-Anywhere\Third-Party\MSYS2\install\usr\bin\python.exe' 'c:\Users\gigi\Desktop\VSCode-Anywhere\VSCode\extensions\ms-python.python-2018.9.1\pythonFiles\experimental\ptvsd_launcher.py' '49689' 'c:\Users\gigi\Desktop\python\gigix.py'
pydev debugger: warning: trying to add breakpoint to file that does not exist: /:\Users\gigi\Desktop\python\gigix.py (will have no effect)

If I use the following Python code :

import ptvsd

ptvsd.enable_attach()
ptvsd.wait_for_attach()
...

I start my python program and my program pause and listen to port 5678 :

TCP    0.0.0.0:5678           0.0.0.0:0              LISTENING

When I click on Python: Attach, my program finish with the following message :

pydev debugger: warning: trying to add breakpoint to file that does not exist: /:/Users/gigi/Desktop/python/gigix.py (will have no effect)

If I replace the line 231 like explain above, it works.


@fabioz commented on Fri Nov 02 2018

@karthiknadig this is actually a feature request (support cygwin in the debugger) -- the first fix needed is dealing with cygpaths as @gigi206 pointed, but there may be more to it (as a note, when/if cygwin support is added, we should also make sure there's a worker to test it in the ci).


@karthiknadig commented on Fri Nov 02 2018

I see. It might be worth a shot to try 'Attach' with pathMappings.
@gigi206 Add the following to your launch configuration. You may have to tweak the paths for this to work:

        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "<set this value>"
                }
            ]
        },

@gigi206 commented on Fri Nov 02 2018

I have modified my launch.json file to :

"pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/c/Users/gigi/Desktop/python/"
                }
            ]

It seems to work with attach request type but pathMappings seems not be allowed with launch request type.

I have the message pydev debugger: warning: trying to add breakpoint to file that does not exist: /:\Users\gigi\Desktop\python\gigix.py (will have no effect) with launch request type but it works.


@karthiknadig commented on Fri Nov 02 2018

@DonJayamanne Does 'launch' support pathMappings? On the debugger side we handle pathMappings for both launch and attach.


@karthiknadig commented on Wed Dec 05 2018

Issue moved to Microsoft/vscode-python #3567 via ZenHub

@DonJayamanne
Copy link

Reopening, as this relates to remote debugging.
Was too hasty in closing, apologies @d3r3kk

@DonJayamanne DonJayamanne reopened this Dec 6, 2018
@d3r3kk d3r3kk changed the title pydev debugger: warning: trying to add breakpoint to file that does not exist Using "request": "launch" item in launch.json for debugging does not send pathMappings Jan 15, 2019
@d3r3kk
Copy link

d3r3kk commented Jan 15, 2019

After some very helpful descriptions from @karthiknadig I was able to understand what the issue is here. We send the following for "request": "attach" debug configurations, but not for "request": "launch" configurations:

"pathMappings": [
    {
        "localRoot": "<local>",
        "remoteRoot": "<remote>"
    }
]

This is a bit counter-intuitive perhaps that we would need to send these mappings, but this is a scenario that does indeed call for it.

Probably all that is needed is to add the same logic from AttachConfigurationResolver::provideAttachDefaults to LaunchConfigurationResolver::provideLaunchDefaults, near the end of the method replace:

        this.sendTelemetry('launch', debugConfiguration);

with:

        if (!debugConfiguration.pathMappings) {
            debugConfiguration.pathMappings = [];
        }
        // This is for backwards compatibility.
        if (debugConfiguration.localRoot && debugConfiguration.remoteRoot) {
            debugConfiguration.pathMappings!.push({
                localRoot: debugConfiguration.localRoot,
                remoteRoot: debugConfiguration.remoteRoot
            });
        }
        this.sendTelemetry('launch', debugConfiguration);

(or some better-shared manner of doing so between launch.ts and attach.ts...)

@d3r3kk d3r3kk added bug Issue identified by VS Code Team member as probable bug needs PR area-debugging and removed triage labels Jan 15, 2019
@qubitron qubitron added the important Issue identified as high-priority label Mar 20, 2019
@DonJayamanne DonJayamanne removed their assignment Apr 4, 2019
@DonJayamanne DonJayamanne added this to the 2019 - April Sprint 9 milestone Apr 24, 2019
@ghost ghost removed the needs PR label May 28, 2019
@DonJayamanne DonJayamanne reopened this May 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 15, 2019
@luabud luabud reopened this Jul 30, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jul 30, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jul 30, 2019
@karrtikr karrtikr added needs proposal Need to make some design decisions needs PR and removed needs PR labels Jul 31, 2019
@DonJayamanne
Copy link

@karthiknadig Please could you advice what needs to be passed to PTVSD to get this issue resolved.
The previous solution (PR #5852) was reverted as it broke the debugger

@DonJayamanne
Copy link

DonJayamanne commented Aug 1, 2019

Prescribed Solution

  • Launch should not prevent users form manually adding pathMappings. Path mappings should not be set by default for launch, but it should not be disallowed. currently users see squiggles when they put pathMappings in a lunch request.

  • In multiprocess launch scenario:

    • The launch request does not require pathMappings. But if users provide it that we should use that one.
    • While attaching to the child-process the pathMappings must be included in the attach request, if one was not provided with the parent's launch request. The generated path mapping should have current working directory for localRoot and . for remoteRoot.
"pathMappings":[
    {
        "localRoot": "<current-working-directory>", // full path to current working directory
        "remoteRoot": "."
    }
]

@DonJayamanne DonJayamanne removed the needs proposal Need to make some design decisions label Aug 13, 2019
@ericsnowcurrently
Copy link
Member

To verify:

  • use a custom "cwd" in a launch config (make it a sub-directory of the workspace root)
  • use a custom "pathMappings" in a launch config (make the localRoot a sub-directory of the workspace root)

For each of the above, verify that multi-proc debugging works.

@ericsnowcurrently
Copy link
Member

@DonJayamanne, you suggested that #5852 had been reverted, but I don't see that anywhere.

@karrtikr karrtikr removed their assignment Aug 26, 2019
@ericsnowcurrently
Copy link
Member

merged: #7024

@kimadeline
Copy link

✅ Validated

@ghost ghost removed the needs PR label Aug 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority
Projects
None yet
Development

No branches or pull requests

9 participants