Debugging in FreeCAD: Difference between revisions
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
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. | 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. | ||
# Launch | # Launch FreeCAD | ||
# Normally, the python console is hidden. To show the console, go to Menu ''View''->''Panels''->''Python console''. | # Normally, the python console is hidden. To show the console, go to Menu ''View''->''Panels''->''Python console''. | ||
# Now ran these lines below | # Now ran these lines below | ||
Line 21: | Line 21: | ||
=Install and the debugger= | =Install and the debugger= | ||
We need a python debugger '' | We need a python debugger ''Winpdb''. If you did not installed before, install it with: | ||
sudo apt-get install winpdb | sudo apt-get install winpdb | ||
Now lets setup the debugger. | Now lets setup the debugger. | ||
# Start '' | # Start ''Winpdb''. | ||
# Set the debugger password to "test": Go to menu ''File''->''Password" and set the password. | # 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. | Now we will run a test python script in FreeCAD step by step. | ||
# | # Create a test script like from [https://www.freecadweb.org/wiki/index.php?title=Debugging]: | ||
<pre> | |||
import rpdb2 | |||
rpdb2.start_embedded_debugger("test") | |||
import FreeCAD | |||
import Part | |||
import Draft | |||
print "hello" | |||
print "hello" | |||
import Draft | |||
points=[FreeCAD.Vector(-3.0,-1.0,0.0),FreeCAD.Vector(-2.0,0.0,0.0)] | |||
Draft.makeWire(points,closed=False,face=False,support=None) | |||
</pre> | |||
# Open this script in FreeCAD and run it. FreeCAD will freeze, because the script line | |||
rpdb2.start_embedded_debugger("test") | |||
waits until you attach the debugger. | |||
# 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. | |||
# When you finish debugging, detach the debugger: Go to menu ''File''->''Detach''. | |||
= Comments = | |||
Thank you to user Kunda1 from [https://forum.freecadweb.org/viewtopic.php?f=8&t=32093 FreeCAD forum] for the instructions how to fix debugger. |
Latest revision as of 17:55, 10 November 2018
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.
- Launch FreeCAD
- Normally, the python console is hidden. To show the console, go to Menu View->Panels->Python console.
- Now ran these lines below
from xml.dom import minidom minidom.parseString("<test></test>")
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.
- Start Winpdb.
- 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.
- Create a test script like from [3]:
import rpdb2 rpdb2.start_embedded_debugger("test") import FreeCAD import Part import Draft print "hello" print "hello" import Draft points=[FreeCAD.Vector(-3.0,-1.0,0.0),FreeCAD.Vector(-2.0,0.0,0.0)] Draft.makeWire(points,closed=False,face=False,support=None)
- Open this script in FreeCAD and run it. FreeCAD will freeze, because the script line
rpdb2.start_embedded_debugger("test")
waits until you attach the debugger.
- 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.
- When you finish debugging, detach the debugger: Go to menu File->Detach.
Comments
Thank you to user Kunda1 from FreeCAD forum for the instructions how to fix debugger.