Debugging/pl

Najpierw przetestuj
Zanim przejdziesz przez ból debugowania użyj środowiska pracy Test aby sprawdzić czy standardowe testy działają poprawnie. Jeśli testy nie są kompletne, prawdopodobnie instalacja jest uszkodzona.

Wiersz poleceń
Debugowanie w programie FreeCAD jest wspierane przez kilka wewnętrznych mechanizmów. Wersja programu FreeCAD z wierszem poleceń dostarcza kilka opcji do obsługi debugowania.

Są to obecnie rozpoznawane opcje w programie FreeCAD w wersji 0.19:

Opcje ogólne: -v [ --version ]    Drukuje ciąg znaków wersji. -h [ --help ]       Drukuje komunikat pomocy -c [ --console ]    Uruchamia się w trybie konsolowym --response-file arg Można też podać z '@name' --dump-config       Zrzuca konfigurację --get-config arg    Wypisuje wartość żądanego klucza konfiguracyjnego

Konfiguracja: -l [ --write-log ]       Zapisuje plik dziennika do: $HOME/.FreeCAD/FreeCAD.log (Linux) $HOME/Library/Preferencje/FreeCAD/FreeCAD.log (macOS) %APPDATA%FreeCAD/FreeCAD.log (Windows) --log-file arg           W przeciwieństwie do --write-log pozwala na logowanie do                            dowolnego pliku. -u [ --user-cfg ] arg    Plik konfiguracyjny użytkownika do ładowania / zapisywania ustawień użytkownika -s [ --system-cfg ] arg  Plik konfiguracyjny systemu do załadowania / zapisu ustawień systemowych -t [ --run-test ] arg    Przypadek testowy - lub 0 dla wszystkich -M [ --module-path ] arg Ścieżki do dodatkowych modułów -P [ --python-path ] arg Dodatkowe ścieżki dostępu do Pythona --single-instance        Pozwala na uruchomienie pojedynczej instancji aplikacji

Generowanie śladu wstecznego
Jeżeli używasz wersji FreeCAD z ostatniej fazy rozwoju, może ona ulec awarii. Możesz pomóc w rozwiązaniu takich problemów poprzez dostarczenie deweloperom śladów wstecz. Aby to zrobić, musisz mieć uruchomiony debug build oprogramowania. Debug build jest parametrem, który jest ustawiany w czasie kompilacji, więc albo będziesz musiał skompilować FreeCAD samodzielnie, albo zdobyć prekompilowaną wersję debug.

Dla systemu Linux
Debugowanie w systemie Linux →

Wymagania wstępne:


 * 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:

Find FreeCAD binary on your system:

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.

Dal systemu macOS
Debugowanie w systemie macOS →

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.

List Libraries Loaded by FreeCAD
(Applicable to Linux and macOS)

Sometimes it's helpful to understand what libraries FreeCAD is loading, specifically if there are multiple libraries being loaded of the same name but different versions (version collision). In order to see which libraries are loaded by FreeCAD when it crashes you should open a terminal and run it in the debugger. In a second terminal window, find out the process id of FreeCAD:

Use the returned id and pass it to :

This prints a long list of loaded resources. So for example, if trying to ascertain if more than one Coin3d library versions is loaded, scroll through the list or search directly for Coin in the output:

Python Debugging
For a more modern approach to debugging Python, see these posts:
 * Debugging macros with VS 2017
 * Python workbenches debugging
 * python3.dll, Qt5Windgets.dll, Qt5Gui.dll and Qt5Core.dll not found

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 using created configuration. You should see variables in debugger area.
 * When setting breakpoints, VS Code will complain about not finding the .py file opened in the VS Code editor.
 * Change "remoteRoot": "." to "remoteRoot": " "
 * For example, if the Python file resides in /home/FC_myscripts/myscript.py
 * Change to: "remoteRoot": "/home/FC_myscripts"
 * If your macro can't find ptvsd despite having installed it somewhere precede 'import ptvsd' with

where the path is to the directory where ptvsd got installed In the Mac package it is /Applications/FreeCAD.App/Contents/Resources/bin/python
 * On the left bottom edge of VSCode you can choose the Python executable - it's best to make this the version packaged with FreeCAD.

You can locate it on your system by typing

into FreeCAD's Python console.

Debugging OpenCasCade
For developers needing to dig deeper in to the OpenCasCade kernel, user @abdullah has created a thread orientation discussing how to do so.