Debugging/sv

Testa först
Innan du går igenom avbuggningssmärtan, använd testramverket för att kontrollera om standardtesterna fungerar korrekt. Om inte så kanske det kan bero på en trasig installation.

kommandorad
Avbuggningen av FreeCAD stöds av en del interna mekanismer. Kommandoradsversionen av FreeCAD erbjuder alternativ för avbuggningsstöd:


 * -v: Med "v" alternativet så ger FreeCAD en mer pratig utmatning.
 * -l: Med "l" alternativet så skriver FreeCAD extra information till en loggfil.

These are the currently recognized options in FreeCAD 0.15:

Generic options: -v [ --version ]     Prints version string -h [ --help ]        Prints help message -c [ --console ]     Starts in console mode --response-file arg  Can be specified with '@name', too

Configuration: -l [ --write-log ]      Writes a log file to: $HOME/.FreeCAD/FreeCAD.log --log-file arg          Unlike to --write-log this allows to log to an                            arbitrary file -u [ --user-cfg ] arg   User config file to load/save user settings -s [ --system-cfg ] arg System config file to load/save system settings -t [ --run-test ] arg   Test level -M [ --module-path ] arg Additional module paths -P [ --python-path ] arg Additional python paths

Generating a Backtrace
If you are running a version of FreeCAD from the bleeding edge of the development curve, it may "crash". You can help solve such problems by providing the developers with a "backtrace". To do this, you need to be running a "debug build" of the software. "Debug build" is a parameter that is set at compile time, so you'll either need to compile FreeCAD yourself, or obtain a pre-compiled "debug" version.

For Linux
Linux Debugging → Prerequisites:


 * software package gdb installed
 * a debug build of FreeCAD (at this time only available by building from source)
 * a FreeCAD model that causes a crash

Steps: Enter the following in your terminal window:

GNUdebugger will output some initializing information. The (gdb) shows GNUDebugger is running in the terminal, now input:

FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window:

This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report.

Print the values of the local variables also. This can be combined with a number to limit the number of frames shown.

For MacOSX
MacOSX Debugging →

Prerequisites:


 * software package lldb installed
 * a debug build of FreeCAD
 * a FreeCAD model that causes a crash

Steps: Enter the following in your terminal window:

LLDB will output some initializing information. The (lldb) shows the debugger is running in the terminal, now input:

FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window:

This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report.

Python Debugging
For a more modern approach to debugging Python, see these posts:
 * Debugging macros with VS 2017
 * Python workbenches debugging

winpdb
winpdb Debugging →

Here is an example of using Winpdb inside FreeCAD:

We need the python debugger: Winpdb. If you do not have it installed, on Ubuntu/Debian install it with:

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) Run winpdb and set the password (e.g. test)
 * 2) Create a Python file with this content


 * 1) Start FreeCAD and load the above file into FreeCAD
 * 2) Press F6 to execute it
 * 3) Now FreeCAD will become unresponsive because the Python debugger is waiting
 * 4) Switch to the Windpdb GUI and click on "Attach". After a few seconds an item "" appears where you have to double-click
 * 5) Now the currently executed script appears in Winpdb.
 * 6) Set a break at the last line and press F5
 * 7) Now press F7 to step into the Python code of Draft.makeWire

Visual Studio Code (VS Code)
VS Code Debugging →

Prerequisites:


 * ptvsd package need to be installed

pypi page

Visual Studio Code documentation for remote debugging

Steps:
 * Add following code at the beginning of your script


 * Add a debug configuration in Visual Studio Code . It should looks like this :

"configurations": [ {           "name": "Python: Attacher", "type": "python", "request": "attach", "port": 5678, "host": "localhost", "pathMappings": [ {                   "localRoot": "${workspaceFolder}", "remoteRoot": "." }           ]        },


 * In VS Code add a breakpoint anywhere you want.
 * Launch the script in FreeCAD. FreeCAD freeze waiting for attachment.
 * In VS Code start debugging used created configuration. You should see variables in debugger area.