-
Notifications
You must be signed in to change notification settings - Fork 54
Python Debugger
The pdb plugin is used to debug python applications. It is possible to set breakpoints and run code step by step. The cursor follow the program flow and you can easily check variable values, execute statements etc.
This plugin provides a minimal but yet extremely useful strategy to debug python applications. You will need to know about python pdb commands for fully taking advantage of this plugin.
Check out:
https://docs.python.org/3/library/pdb.html
In order to use pdb plugin it is needed to create areavi instances and setting them as output targets for the debugger process. Consider the basic python application shown below.
Create the following dir:
mkdir mytest
cd mytest
Then put the two files below inside mytest folder:
# alpha.py
def func_alpha(n):
import beta
return beta.func_beta(n)
func_alpha(10)
# beta.py
def func_beta(m):
m = m + 1
return m
Open these two files in two tabs by pressing:
<Alt-comma>
in Global mode. Create a vertical/horizontal area for each one of the vy tabs that were created. For such, switch the focus to the tab that has alpha.py then press:
<Alt-less>
in GLOBAL mode, it will open a vertical areavi instance. Switch the focus to that areavi instance then make it an output target by pressing:
<Tab>
in NORMAL mode. Switch the focus to the tab that has beta.py opened then press:
<Alt-less>
to create a vertical area to set output target on by pressing:
<Tab>
as it was done with the tab having alpha.py.
Once the output targets were set on the areavi instances it is possible now to read the debug output on these areavi instances. Now it is possible to send debug commands to the process and watch the flow of the program.
Important: You don't need to follow the above steps you can merely check the debugger output by pressing:
<Alt-q>
In GLOBAL mode. It means that whenever you drop code to the debugger or press a keystroke then you can check the result by reading the contents from syslog window.
The syslog or cmd output window yields whatever was written to sys.stdout. The pdb process writes to sys.stdout whatever the process outputs thus you can read it through the syslog window.
The PYTHON mode is implemented in NORMAL mode. Once having set output targets for the debug process, it is time to set vy on PYTHON mode, for such, switch to PYTHON mode by pressing:
<Key-exclam>
In NORMAL mode then.
Once in PYTHON mode it is possible to start a python process through the debugger by pressing:
<Key-1>
in PYTHON mode.
It is important to notice that using this key command there is no way to pass command line arguments. Once the process was successful started then the debugger will output information about the program flow on the output targets that were set.
Note: In case you didn' set output targets then you can check whether the debugger started correctly by pressing:
<Alt-q>
In GLOBAL mode, it is regardless of the mode the AreaVi instance is set on.
It is possible to pass command line arguments to the python application by pressing:
<Key-2>
in PYTHON mode. The arguments are split using shlex module.
Just switch to PYTHON mode then press:
<Key-m>
It will pop an input widget, you type your PDB cmd then it is sent. You can set, remove breakpoints in this way as well.
The line over the cursor is set as a breakpoint if the keycommand:
<Key-b>
is issued in PYTHON mode. Check whether the breakpoint was set by:
<Alt-q>
Then use:
<Key-c>
That means 'continue' to get your program flow moving on. When it hits a breakpoint then the line gets shaded.
In order to set a temporary breakpoint, press:
<Key-B>
in PYTHON mode, the cursor line will be shaded and when the debugger hits that breakpoint the line will be unshaded.
In order to remove a breakpoint that was set it is enough to place the cursor over the line then press:
<Control-c>
in PYTHON mode.
In PYTHON mode it is enough to press:
<Control-C>
then it will clear all breakpoints.
In order to stop at the next breakpoint, press:
<Key-c>
in PYTHON mode. It sends a '(c)ontinue' to the debugger process.
Sometimes it is useful to evaluate some expressions that appear in the python program that is being debugged, such expressions will be evaluated in the current scope of the debugger process. Select the expression text then press:
<Key-p>
in PYTHON mode.
You can drop an expression to be evaluated in the current context by pressing
<Key-x>
PYTHON mode then entering the expression and hitting return.
When the debugging process has finished it is possible to terminate the process by pressing:
<Key-Q>
in PYTHON mode.