Remote debugging

Sep 12, 2013 at 1:24 PM
Edited Sep 12, 2013 at 5:14 PM
We are having minor issues with remote debugging. We can set and break in the main file when debugging remotely. However we cannot do this in modules unless we use the 'break_into_debugger' method.

main.py <- can set breaks in VS
/ init.py
/ foo.py <- cannot set breaks in VS but programmatic break works

Ideally we'd like to be able to break into other modules (and relative files) without having to add break_into_debugger into each file.

Any suggestions?
Coordinator
Sep 12, 2013 at 7:30 PM
What OS does the debugging script run on?

Also, when you do break using break_into_debugger, does the call stack look correct (in particular, does it show the proper module name for the topmost frame)? It might also be worth checking the module paths in the Modules tool window (Debug -> Windows -> Modules) - this should list the full paths alongside Python module names; can you check to ensure that those paths look reasonable (i.e., at the minimum, include the proper file name in them)?
Sep 13, 2013 at 8:47 AM
Thank you for your reply.

We are using Ubuntu server 12.04.

The call stack looks fine, but in VS.NET, the module paths in the Modules tool window all point to the Linux paths, and the symbol status for each module is 'Symbols not loaded'.

So the question I think is how do we map the symbol paths from Linux to the local machine?

Thanks for your help.
Coordinator
Sep 13, 2013 at 4:54 PM
I wonder if one of our path checks in visualstudio_py_debugger.py is not correctly handling forward slash vs. backslash?

(Unrelated: we have far too many different functions for comparing paths in this file...)

I suspect filename_is_same at/near line 386:
def filename_is_same(win_path, local_path):
    import ntpath
    if ntpath.isabs(win_path) and path.isabs(local_path):
        return path.normcase(win_path) == path.normcase(local_path)
    return path.normcase(ntpath.basename(win_path)) == path.normcase(path.basename(local_path))
Using ntpath for the path on the debugger machine seems correct, but if both paths are absolute then we just do a direct comparison and don't account for the directory separator.

yazandiranieh - feel free to modify this file on your own machine ("Where is PTVS installed?") if you want, but pminaev is most familiar with this code, so he may have an easy fix for you.
Coordinator
Sep 14, 2013 at 12:10 AM
Actually, this looks wrong in a more general way - it's not that we don't account for directory separator, but it's that we're comparing two absolute paths for equality in the first place. In remote scenario (whether with msvsmon or our own transport), these will never match. We should probably always just do basename comparisons instead, like C++ and C# do.

yazandiranieh - try commenting out the if statement in the code that Zooba has referenced and see if that helps.
Sep 17, 2013 at 3:10 PM
Hi - we tried commenting out the if statement you referred to in visualstudio_py_debugger.py (on the machine where Python Tools are installed, i.e., ..\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_debugger.py), but that made no difference unfortunately.
Coordinator
Sep 17, 2013 at 3:24 PM
You need to edit this file on the machine that you're trying to debug (it's a part of the ptvsd package).
Sep 17, 2013 at 4:00 PM
Edited Sep 17, 2013 at 4:19 PM
IT WORKED! Awesome! Well done guys.

So this is what I did:
  • In ptvsd folder on the local machine (where Phython Tools are installed), I edited visualstudio_py_debugger.py as follows:
def filename_is_same(win_path, local_path):
    import ntpath
        
    #if ntpath.isabs(win_path) and path.isabs(local_path):
    #    return path.normcase(win_path) == path.normcase(local_path)
    return path.normcase(ntpath.basename(win_path)) == path.normcase(path.basename(local_path))
  • Uninstalled ptvsd package from the Linux machine using (sudo pip uninstall ptvsd)
  • Created a ptvsd directory in the Linux machine where my script is deployed, and copied over the contents of ptvsd folder in step 1 (i.e., Windows to Linux – I used MobaXterm)
  • Edited my main .py file to include
 import ptvsd
 ptvsd.enable_attach(secret=None)
  • Ran the application on the Linux machine.
  • Attached from VS.NET
Thanks again guys.
Yazan
Coordinator
Sep 17, 2013 at 4:07 PM
Thanks for confirming that this is indeed the problem! We'll see what we can do about a more generic solution (as with the change above, you might see some strangeness if you e.g. have two files with the same name in different packages).
Coordinator
Sep 17, 2013 at 4:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.