Debugging in FreeCAD

From Open Source Ecology
Jump to: navigation, search

How to setup a system to debug FreeCAD python scripts.

Check system stability

In some Linux systems the debugger will crash. The problem is caused by in expat library. This is happens for example on Ubuntu 18.04. To find out, if our system has this problem, run two python lines below. If Freecad crashes, we need to fix our system first.

  1. Launch FreeCAD
  2. Normally, the python console is hidden. To show the console, go to Menu View->Panels->Python console.
  3. Now ran these lines below
 from xml.dom import minidom

If FreeCAD crashes you need to fix it. We follow the instructions on [1]. They suggest to downgrade the libexpat file:

For Ubuntu download Ubuntu 16.04 versions of libexpat1_2.1.0 from [2]. These is usually libexpat1_2.1.0-7ubuntu0.16.04.3_amd64.deb (or libexpat1_2.1.0-7ubuntu0.16.04.3_i386.deb for 32 bit system)

Than go to your Download directory and install it with

sudo dpkg -i libexpat1_2.1.0-7ubuntu0.16.04.3_amd64.deb

Try again. If freecad does not crash, the debugger will probably work.

Install and the debugger

We need a python debugger Winpdb. If you did not installed before, install it with:

sudo apt-get install winpdb 

Now lets setup the debugger.

  1. Start Winpdb.
  2. Set the debugger password to "test": Go to menu File->Password" and set the password.

Now we will run a test python script in FreeCAD step by step.

  1. Create a test script like from [3]:
import rpdb2
import FreeCAD
import Part
import Draft
print "hello"
print "hello"
import Draft
  1. Open this script in FreeCAD and run it. FreeCAD will freeze, because the script line

waits until you attach the debugger.

  1. Attach the debugger. In Winpdb go to menu File->Attach. Winpdb will show you a window with your script or multiple script. Select your script and click OK.

Now you can execute the script line by line by clicking the "next"-Button from the Winpdb-Toolbar. Run all the lines. In the tab "Locals" you can see the values of the local variables.

  1. When you finish debugging, detach the debugger: Go to menu File->Detach.


Thank you to user Kunda1 from FreeCAD forum for the instructions how to fix debugger.