Running a script in debugging mode

Print Previous page Top page Next page

To execute a script in debug mode , select it from the list and click the button of running in a debugging mode debug .

As a result, the IDLE program (integrated development environment) will be started in the mode of script file editing.

dialog_debug

 

To run the script for execution, press F5 or select the Run/Run Module menu item.

To execute the script step by step:

- launch a Shell (menu Run/Python Shell);

- enable the Debugger option in the Debug shell menu.

 

A debug control window will appear, in which you need to enable the Source option. To view the values of local variables, you need to enable the option - Locals, global - Globals.

 

dialog_debug2

 

Commands (buttons) are available for debugging:

- Go - continue without stepping to the breakpoint.

- Step - execute the current line and go to the next one

- Over - if the current line contains a function call, press this button to enter this function

- Out - execute and exit the function

- Quit - finish execution.

 

A breakpoint can be specified by calling the pop-up menu by right-clicking on the desired line.

 

dialog_debug3

 

After setting a breakpoint, the line will be highlighted in yellow. To run to a breakpoint, you need to press Go.

 

To ensure the autonomous execution of the script in debug mode, a copy of the script is automatically formed with the name debug_script_name.py next to the original script.

The copy of the script includes 2 blocks. One is written at the beginning of the script, the other at the end. The blocks have approximately the following content:

 

#debug.begin1

import sys

sys.path.append('C:/Users/Public/Documents/Panorama/py_mapapi14')

import mapsyst

debug_syspath = 'C:/Program Files/Panorama/Panorama14/'

mapsyst.setuppanlib(debug_syspath)

import mapdebug

debug_docname = 'C:/111/test3d/debug_moveobjects.mpt'

debug_hmap, debug_hobj = mapdebug.open(debug_syspath, debug_docname)

if debug_hmap == 0:

   sys.exit()

#debug.end1

#debug.begin2

MoveObjects(debug_hmap, debug_hobj)

mapdebug.close(debug_hmap, debug_hobj)

#debug.end2

 

If during the debugging process the source code of the script was edited, then you can delete the inserted blocks and rename the script.

The first block provides customization of access to the prototypes of MAPAPI functions and structures, GIS libraries, data contents and objects selected on maps that were at the time of the forming a copy of the script.

The second block provides a call of the specified function, the transfer of input parameters and the closing of data at the end of its execution.

If you need to debug in another environment, then after calling the debugger and creating a copy of the script, you can close the IDLE program and debug a copy of the script in another program.

If during the script execution an editing of a map is carried out and a map has SITX format, then when starting the script in a debugger the access on editing will be closed. The SITX format provides editing access to the first program that opened it. Therefore, it is necessary either to sort the map with a change of format to the SIT or, after forming a copy of the script, close the debugger, close the GIS and run the debug program from the Explorer.