NbPython debugger's primer

author : Jean-Yves Mengant

-- Parent project wiki:http://wiki.netbeans.org/Python



This primer is intended to provide a short introduction about how to use the nbpython debugger feature.

Sample prerequisite before using nbPython debugger.

Before starting using the debugger I will assume that you already have defined a nbPython Python or Jython project with some existing sources inside.

The screenshot below shows an acceptable context where MyFirst is a nbPython Python project and MyFirstJython a sample Jython project.

Since Debugging in Python offers the same features as debugging in Jython, I will only cover a Python debugging session in this primer. You may use exactly the same features for Jython


Step one : check debugger's options

Before starting using the debugger, let's have a look at the available configuration options :

To access debugger's options just go to Netbeans menu Tools / options / Python options / Debugger ; you'll then get the picture below


The default provided options should be acceptable assuming that the IP port number 29100 specified is not used by any other program on your machine. Options 'description :

Field Description
Debugger's listening starting port When debugging for better isolation the debugger is automatically started in a separate process and communicates with Netbeans IDEover an IP socket. This field specifies the port number where the debugger process is listening for incoming Netbeans Python debugging solicitations.
Debugging shell colors and fonts This group of button may be used to customized the debugging shell coloring
Stop at first line When checked the debugger will initially stop at the first line of the debugger's script. When unchecked the debugger will stop at the first found breakpoint in script.

Step two : setting breakpoints

The way to setup breakpoints in python are the same as in Java : just click on the left gutter of the line you want to be a breakpoint :


Step three : starting the debugger.

Same as for the breakpoints before, the nbPython python's debugger is built using the Netbeans debugger's framework standard and is sharing the same components as other Netbeans languages (buttons , shortcut , windows ...) . So the way to start the python debugger is quite the same as starting the Java debugger.

In order to start a python debugging session, you can either select a python project and from the menu select debug / project or select a python file within a Python project select the Python source file you want to debug and from the menu select debug / file.

NB : If a project contains more than one file the debug / project menu remains disabled until you define the 'main module' of the project in the Project / properties / run panel as shown in the screen below


As soon as the debugger has been started the python program will switch in debug mode and a debugging shell frame window will pop up as shown in following picture :


Step four : description of available debugger's features.

Navigation functions

The following navigations functions are available in python : step into , step over , continue , stop. The actions shortcuts and buttons are the same as for other languages and right clicking in Netbeans toolbar an select Debug will make the debug buttons available for step , continue or stop the debugger.

The debugger's shell window

The Python debugger's shell windows is started and activated when the debugger's starts and deactivated when the debugger's stops.

This windows has the same function as the PythonConsole and is fully aware of your current Python context stack. This implies that you can use it to dynamically test variables , functions or any acceptable Python expression when the debugger is stopped at a given breakpoint in your module. This shell is also used by the debugger to display the python stddout content. If you enter a wrong python expression in it you'll get an error stack frame back.

The picture below shows some dynamic usages of the shell in a debugging context


Other available python debugging windows

The following other standard Netbeans debugging windows are made available for Python's debugging and can be activated through the standard Window / Debugging menu.

The Local Variable Window view :


The Stack Window view :


The Thread Window view


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo