Debugging

i.debug.programpy.pngPython Tools includes integrated support for debugging multiple types of Python applications including attaching to Python processes, evaluating Python expressions in the watch and immediate windows, and inspecting local variables, step in, out, and over statements, set the next statement, and breaking on exceptions.

Right click on your project and choose Properties (Alt+Enter). From the Debug tab, you can choose one of four debuggers:

  • Standard VS Debugger for CPython
  • IronPython / .Net Debugger
  • Python MPI Debugger
  • Django Debugger

 

 

 

The Standard debugger basically works just like the VS debugger. The IronPython debugger uses the .Net debugger and allows you to debug into multi-lingual .Net projects in C#, VB, F#, ... The Python MPI Debugger supports debugging across remote processes on an HPC cluster (discussed elsewhere).

 

i.debug.choice.png


 

 

The Debug Interactive Window

Python Tools for Visual Studio includes an interactive window for debugging your code. You can launch the window from the Debug->Windows->Python Debug Interactive menu item. The debug interactive window can be summarized as a more powerful immediate window, letting you execute Python code against a debugged process.

The debug interactive window automatically connects to any process started in the debugger using the Standard Python launcher, or any process that is later attached using the Python Debugger.

When execution breaks into the debugger, the debug interactive window is now ready to start executing code. Note that executing code while the process is running is not allowed.

 

The debug interactive window supports several meta commands. All meta commands start with a $, and you can type $ or $help to get a list of the meta commands. Here are some of the most important commands.

Command Arguments Description
$procs   Lists the processes currently being debugged.
$proc process id Switches the current process to the specified process id.
$proc   Displays the current process id.
$mod module name Switches the current scope to the specified module name. This can also be done using the toolbar. The active module automatically changes back to <CurrentFrame> when execution breaks into the debugger.
$threads   Lists the threads currently being debugged.
$thread thread id Switches the current thread to the specified thread id.
$thread   Displays the current thread id.
$where,w,bt   Lists the frames for the current thread.
$frame frame id Switches the current frame to the specified frame id.
$frame   Displays the current frame id.
$up,u   Move the current frame one level up in the stack trace.
$down,d   Move the current frame one level down in the stack trace.
$continue,cont,c   Starts executing the program from the current statement.
$stepin,step,s   Steps into the next function call, if possible.
$stepout,return,r   Steps out of the current function.
$stepover,until,unt   Steps over the next function call.

Note that the standard debugger windows such as Processes, Threads and Call Stack are not synchronized with the debug interactive window. This means that changing the active process/thread/frame in the debug interactive window will not affect the other debugger windows, and similarly, changing the active process/thread/frame in the other debugger windows will not affect the debug interactive window.

The debug interactive window has its own set of options, which you can access using Tools->Options->Python Tools->Debug Interactive Window. Unlike the regular Python Interactive Window, which has one instance per Python interpreter installed, there is only one instance of the debug interactive window. It uses the Python interpreter for the process being debugged.

Debug Interactive Window Options

Last edited Oct 31, 2012 at 6:32 PM by huguesv, version 7

Comments

pminaev Thu at 5:56 PM 
Can you clarify what you mean by "Python debug EXE"? There really isn't any special executable in PTVS, but rather a startup script. You can find it at AppData\Local\Microsoft\VisualStudio\11.0\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_launcher.py (adjusting the version number as needed) - it's short, the arguments it takes are prominent in the code.

shaggygi97 Thu at 4:59 PM 
What is the path to the python debug exe and are there any arguments? We have a tool capable of calling the debugger for PyScript and PyDev for Eclipse and wanted to see if it was possible to call into debugger for PTVS.

Thanks