Debugging/es: Difference between revisions
(Updating to match new version of source page) |
(Created page with "Configuración: -l [ --write-log ] Escribe un archivo de registro en: $HOME/.local/share/FreeCAD/FreeCAD.log (Linux) $HOME/Library/Application\ Support/FreeCAD/FreeCAD.log (macOS) %APPDATA%\FreeCAD\FreeCAD.log --log-file arg A diferencia de --write-log, esto permite iniciar sesión en un archivo arbitrario -u [ --user-cfg ] arg...") |
||
(43 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
<languages/> |
||
{{Docnav|Module Creation|Testing}} |
|||
{{Docnav |
|||
<div class="mw-translate-fuzzy"> |
|||
|[[Tracker|Tracker]] |
|||
|[[Testing|Testing]] |
|||
}} |
|||
{{TOCright}} |
|||
<span id="Test_First"></span> |
|||
== Prueba primero == |
== Prueba primero == |
||
Antes de |
Antes de pasar por la molestia de la depuración, utilice el [[Testing|Marco de pruebas]] para comprobar si las pruebas estándar funcionan correctamente. Si no se ejecutan por completo, es posible que haya una instalación defectuosa. |
||
</div> |
|||
<span id="Command_Line"></span> |
|||
<div class="mw-translate-fuzzy"> |
|||
== Línea de comandos == |
== Línea de comandos == |
||
La ''depuración'' de FreeCAD está respaldada por algunos mecanismos internos. La versión de línea de comandos de FreeCAD proporciona algunas opciones para soporte de depuración. |
|||
;-v: Con la opción "v" FreeCAD ofrece una salida más verbosa. |
|||
;-l: Con la opción "l" FreeCAD escribe información adicional a un archivo de registro. |
|||
</div> |
|||
Estas son las opciones reconocidas actualmente en FreeCAD 0.19: |
|||
Opciones genéricas: |
|||
Generic options: |
|||
-v [ --version ] |
-v [ --version ] Imprime la cadena de versión |
||
-h [ --help ] |
-h [ --help ] Imprime el mensaje de ayuda |
||
-c [ --console ] |
-c [ --console ] Comienza en modo consola |
||
--response-file arg |
--response-file arg También se puede especificar con '@nombre' |
||
--dump-config Configuración de volcados |
|||
--get-config arg Imprime el valor de la clave de configuración solicitada |
|||
Configuración: |
|||
Configuration: |
|||
-l [ --write-log ] |
-l [ --write-log ] Escribe un archivo de registro en: |
||
$HOME/.FreeCAD/FreeCAD.log |
$HOME/.local/share/FreeCAD/FreeCAD.log (Linux) |
||
$HOME/Library/Application\ Support/FreeCAD/FreeCAD.log (macOS) |
|||
--log-file arg Unlike to --write-log this allows to log to an |
|||
%APPDATA%\FreeCAD\FreeCAD.log |
|||
--log-file arg A diferencia de --write-log, esto permite iniciar sesión en un |
|||
-u [ --user-cfg ] arg User config file to load/save user settings |
|||
archivo arbitrario |
|||
-s [ --system-cfg ] arg System config file to load/save system settings |
|||
-u [ --user-cfg ] arg Archivo de configuración de usuario para cargar/guardar configuraciones de usuario |
|||
-t [ --run-test ] arg Test level |
|||
-s [ --system-cfg ] arg Archivo de configuración del sistema para cargar/guardar la configuración del sistema |
|||
-M [ --module-path ] arg Additional module paths |
|||
- |
-t [ --run-test ] arg Caso de prueba - o 0 para todos |
||
-M [ --module-path ] arg Rutas de módulos adicionales |
|||
-P [ --python-path ] arg Rutas adicionales de Python |
|||
--single-instance Permite ejecutar una única instancia de la aplicación |
|||
== Generating a Backtrace == |
== 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. |
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. |
||
<span id="For_Linux"></span> |
|||
=== For Linux === |
|||
=== Para Linux === |
|||
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
||
Linux Debugging ----> |
|||
Depuración de Linux → |
|||
<div class="mw-collapsible-content"> |
<div class="mw-collapsible-content"> |
||
Prerequisites: |
|||
Requisitos previos: |
|||
* software package gdb installed |
|||
* a debug build of FreeCAD (at this time only available by [[CompileOnUnix#For_a_Debug_build|building from source]]) |
|||
* paquete de software gdb instalado |
|||
* a FreeCAD model that causes a crash |
|||
* una versión de depuración de FreeCAD (en este momento solo está disponible mediante la [[Compile_on_Linux#For_a_Debug_build|compilación desde el código fuente]]) |
|||
* un modelo de FreeCAD que provoca un problema |
|||
Pasos: |
|||
Ingrese lo siguiente en la ventana de su terminal: |
|||
Encuentre el binario FreeCAD en su sistema: |
|||
Steps: |
|||
Enter the following in your terminal window: |
|||
{{Code|code= |
{{Code|code= |
||
$ whereis freecad |
|||
$ cd FreeCAD/bin |
|||
freecad: /usr/local/freecad <--- for example |
|||
$ cd /usr/local/freecad/bin |
|||
$ gdb FreeCAD |
$ gdb FreeCAD |
||
}} |
}} |
||
GNUdebugger will output some initializing information. The (gdb) shows GNUDebugger is running in the terminal, now input: |
|||
GNUdebugger generará información de inicialización. El (gdb) muestra que GNUDebugger se está ejecutando en la terminal, ahora ingrese: |
|||
{{Code|code= |
{{Code|code= |
||
(gdb) handle SIG33 noprint nostop |
(gdb) handle SIG33 noprint nostop |
||
(gdb) run |
(gdb) run |
||
}} |
}} |
||
FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window: |
|||
FreeCAD ahora se iniciará. Realice los pasos que hacen que FreeCAD se bloquee o se congele, luego ingrese en la ventana de terminal: |
|||
{{Code|code= |
{{Code|code= |
||
(gdb) bt |
(gdb) bt |
||
}} |
}} |
||
This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report. |
|||
Esto generará una lista larga de exactamente lo que estaba haciendo el programa cuando falló o se congeló. Incluya esto con su informe de problemas. |
|||
{{Code|code= |
{{Code|code= |
||
(gdb) bt full |
(gdb) bt full |
||
}} |
}} |
||
Print the values of the local variables also. This can be combined with a number to limit the number of frames shown. |
|||
Imprima también los valores de las variables locales. Esto se puede combinar con un número para limitar la cantidad de fotogramas mostrados. |
|||
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
||
<span id="For_macOS"></span> |
|||
=== For MacOSX === |
|||
=== Para macOS === |
|||
<!-- START OF COLLAPISBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
<!-- START OF COLLAPISBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
||
MacOSX Debugging ----> |
|||
Depuración de macOS → |
|||
<div class="mw-collapsible-content"> |
<div class="mw-collapsible-content"> |
||
Prerequisites: |
|||
Requisitos previos: |
|||
* software package lldb installed |
* software package lldb installed |
||
Line 88: | Line 119: | ||
$ lldb FreeCAD |
$ lldb FreeCAD |
||
}} |
}} |
||
LLDB will output some initializing information. The (lldb) shows the debugger is running in the terminal, now input: |
LLDB will output some initializing information. The (lldb) shows the debugger is running in the terminal, now input: |
||
{{Code|code= |
{{Code|code= |
||
(lldb) run |
(lldb) run |
||
Line 94: | Line 127: | ||
FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window: |
FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window: |
||
{{Code|code= |
{{Code|code= |
||
(lldb) bt |
(lldb) bt |
||
}} |
}} |
||
This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report. |
This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report. |
||
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
||
== 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: |
|||
{{incode|ps -A | grep FreeCAD}} |
|||
Use the returned id and pass it to {{incode|lsof}}: |
|||
{{incode| lsof -p process_id}} |
|||
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: |
|||
{{incode|lsof -p process_id | grep Coin}} |
|||
== Python Debugging == |
== Python Debugging == |
||
'''For a more modern approach to debugging Python, at least on Windows, see this [https://forum.freecadweb.org/viewtopic.php?f=22&t=28901&hilit=2017| post in the Forum].''' |
|||
For a more modern approach to debugging Python, see these posts: |
|||
* [https://forum.freecadweb.org/viewtopic.php?f=22&t=28901 Debugging macros with VS 2017] |
|||
* [https://forum.freecadweb.org/viewtopic.php?f=10&t=35383 Python workbenches debugging] |
|||
* [https://forum.freecadweb.org/viewtopic.php?f=4&t=40251 python3.dll, Qt5Windgets.dll, Qt5Gui.dll and Qt5Core.dll not found] |
|||
=== winpdb === |
=== winpdb === |
||
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
||
winpdb Debugging ----> |
|||
winpdb Debugging → |
|||
<div class="mw-collapsible-content"> |
<div class="mw-collapsible-content"> |
||
Here is an example of using ''Winpdb'' inside FreeCAD: |
Here is an example of using ''Winpdb'' inside FreeCAD: |
||
We need the |
We need the Python debugger: ''Winpdb''. If you do not have it installed, on Ubuntu/Debian install it with: |
||
{{Code|code= |
{{Code|code= |
||
Line 118: | Line 178: | ||
# Start ''Winpdb''. |
# Start ''Winpdb''. |
||
# Set the debugger password to "test": Go to menu ''File'' |
# Set the debugger password to "test": Go to menu ''File'' → ''Password" and set the password. |
||
Now we will run a test |
Now we will run a test Python script in FreeCAD step by step. |
||
# Run winpdb and set the password (e.g. test) |
# Run winpdb and set the password (e.g. test) |
||
# Create a Python file with this content |
# Create a Python file with this content |
||
{{Code|code= |
{{Code|code= |
||
import rpdb2 |
import rpdb2 |
||
Line 136: | Line 197: | ||
Draft.makeWire(points,closed=False,face=False,support=None) |
Draft.makeWire(points,closed=False,face=False,support=None) |
||
}} |
}} |
||
# Start FreeCAD and load the above file into FreeCAD |
# Start FreeCAD and load the above file into FreeCAD |
||
# Press F6 to execute it |
# Press F6 to execute it |
||
Line 143: | Line 205: | ||
# Set a break at the last line and press F5 |
# Set a break at the last line and press F5 |
||
# Now press F7 to step into the Python code of Draft.makeWire |
# Now press F7 to step into the Python code of Draft.makeWire |
||
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
||
=== Visual Studio Code (VS Code) === |
=== Visual Studio Code (VS Code) === |
||
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
||
VS Code Debugging ----> |
|||
VS Code Debugging → |
|||
<div class="mw-collapsible-content"> |
<div class="mw-collapsible-content"> |
||
Prerequisites: |
Prerequisites: |
||
* ptvsd package |
* The ptvsd package needs to be installed in a Python 3 outside of FreeCAD, then the module must be copied to FreeCAD's Python library folder. |
||
{{Code|code= |
|||
# In a cmd window that has a path to you local Python 3: |
|||
pip install ptvsd |
pip install ptvsd |
||
# Then if your Python is installed in C:\Users\<userid>\AppData\Local\Programs\Python\Python37 |
|||
}}[https://pypi.org/project/ptvsd/ pypi page] |
|||
# and your FreeCAD is installed in C:\freecad\bin |
|||
xcopy "C:\Users\<userid>\AppData\Local\Programs\Python\Python37\Lib\site-packages\ptvsd" "C:\freecad\bin\Lib\site-packages\ptvsd" |
|||
}} |
|||
[https://pypi.org/project/ptvsd/ pypi page] |
|||
[https://code.visualstudio.com/docs/python/debugging#_remote-debugging Visual Studio Code documentation for remote debugging] |
[https://code.visualstudio.com/docs/python/debugging#_remote-debugging Visual Studio Code documentation for remote debugging] |
||
Line 159: | Line 234: | ||
Steps: |
Steps: |
||
* Add following code at the beginning of your script |
* Add following code at the beginning of your script |
||
<pre> |
|||
{{Code|code= |
|||
import ptvsd |
import ptvsd |
||
print("Waiting for debugger attach") |
print("Waiting for debugger attach") |
||
Line 165: | Line 241: | ||
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True) |
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True) |
||
ptvsd.wait_for_attach() |
ptvsd.wait_for_attach() |
||
}} |
|||
</pre> |
|||
* Add a debug configuration in Visual Studio Code {{MenuCommand|Debug → Add Configurations…}}. It should looks like this : |
|||
* Add a debug configuration in Visual Studio Code {{MenuCommand|Debug → Add Configurations…}}. |
|||
* The config should look like this: |
|||
<!--NOT CHANGE THE <pre> </pre> BALISE CAUSE THE PIPE OR SPACE IN MACRO CODE CUT THE MACRO--> |
|||
<pre> |
<pre> |
||
"configurations": [ |
"configurations": [ |
||
Line 186: | Line 266: | ||
* In VS Code add a breakpoint anywhere you want. |
* In VS Code add a breakpoint anywhere you want. |
||
* Launch the script in FreeCAD. FreeCAD freeze waiting for attachment. |
* Launch the script in FreeCAD. FreeCAD freeze waiting for attachment. |
||
* In VS Code start debugging |
* 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": "<directory of file>" |
|||
*** For example, if the Python file resides in ''/home/FC_myscripts/myscript.py'' |
|||
*** Change to: "remoteRoot": "/home/FC_myscripts" |
|||
** If you're just debugging FreeCAD macros from the FreeCAD macro folder, and that folder is "C:/Users/<userid>/AppData/Roaming/FreeCAD/Macro", then use: |
|||
*** "localRoot": "C:/Users/<userid>/AppData/Roaming/FreeCAD/Macro", |
|||
*** "remoteRoot": "C:/Users/<userid>/AppData/Roaming/FreeCAD/Macro" |
|||
* If your macro can't find ptvsd despite having installed it somewhere precede 'import ptvsd' with |
|||
{{Code|code= |
|||
from sys import path |
|||
sys.path.append('/path/to/site-packages') |
|||
}} |
|||
Where the path is to the directory where ptvsd was installed. |
|||
* On the left bottom edge of VSCode you can choose the Python executable - it's best to make this the version packaged with FreeCAD. |
|||
In the Mac package it is /Applications/FreeCAD.App/Contents/Resources/bin/python. |
|||
You can locate it on your system by typing |
|||
{{Code|code= |
|||
import sys |
|||
print(sys.executable) |
|||
}} |
|||
into FreeCAD's Python console. |
|||
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
||
=== With LiClipse and AppImage === |
|||
{{Docnav/es|Module Creation/es|Testing/es}} |
|||
<!-- START OF COLLAPSIBLE DIV --><div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"> |
|||
{{Userdocnavi}} |
|||
LiClipse Debugging → |
|||
[[Category:Developer Documentation/es]] |
|||
<div class="mw-collapsible-content"> |
|||
* Extract AppImage. |
|||
{{Code|code= |
|||
> ./your location/FreeCAD_xxx.AppImage --appimage-extract |
|||
> cd squashfs-root/ |
|||
}} |
|||
* The sqashfs-root location is where the debugger later on is hooked up to. |
|||
* Make sure you can start a FreeCAD session from within the squashfs-root location. |
|||
{{Code|code= |
|||
squashfs-root> ./usr/bin/freecadcmd |
|||
}} |
|||
* Should start up a FreeCAD commandline session. |
|||
* Install [https://www.liclipse.com/ LiClipse]. |
|||
** Comes ready with pydev and has installers for all platforms. |
|||
** For linux it is just to extract (to any location) and run. |
|||
* Configure liclipse for debugging. |
|||
** Right-click pydev icon (upper right corner) and choose customize. |
|||
*** Activate "PyDev Debug" (through checkbox, or it might be needed to go to tab "Action Set Availability" and activate there first). |
|||
*** In the pydev menu you can now choose "start debug server". |
|||
** Use menu window/open perspective/other > debug. |
|||
*** Right-click debug icon (upper right corner) and choose customize. |
|||
*** Checking "Debug" brings the debugging navigation tools to the toolbar. |
|||
** Open preferences through menu window/preferences. |
|||
*** In PyDev/Interpreters add "new Interpreter by browsing". |
|||
*** The added interpreter should be: {{incode|your loc/squashfs-root/usr/bin/python}}. |
|||
*** If you are only using this for fc, you can add AddOn workbench folders as well, or do that in a pydev-project later on. |
|||
* Find path to {{incode|pydevd.py}} in your liclipse installation. |
|||
** Something along the lines of: {{incode|your location/liclipse/plugins/org.python.pydev.xx/pysrc}}. |
|||
* Create a regular pydev-project in liclipse. |
|||
** Import external sources, for example a macro that you want to debug, or an external workbench. |
|||
** In that macro (or workbench .py file) add the code lines: |
|||
: {{Code|code= |
|||
import sys; sys.path.append("path ending with /pysrc") |
|||
import pydevd; pydevd.settrace() |
|||
}} |
|||
:* This is where the execution will halt when the macro is run. |
|||
* Start the liclipse debug server (menu pydev). |
|||
* Start FreeCAD. |
|||
{{Code|code= |
|||
squashfs-root> ./usr/bin/freecad |
|||
}} |
|||
* Run the macro (or any other file with a {{incode|pydevd.settrace()}} trigger) from within freecad, as you would normally do. |
|||
* Happy debugging. |
|||
* The use of LiClipse for remote debugging, and the steps described here related to liclipse, should work on any platform. The parts related to AppImage is for linux only. |
|||
</div></div> <!-- END OF COLLAPSIBLE DIV --> |
|||
=== Pyzo === |
|||
See the [[Pyzo|main article about Pyzo]]. |
|||
== Debugging OpenCasCade == |
|||
For developers needing to dig deeper in to the OpenCasCade kernel, user @abdullah has created a [https://forum.freecadweb.org/viewtopic.php?f=10&t=47017 thread] orientation discussing how to do so. |
|||
{{Docnav |
|||
|[[Tracker|Tracker]] |
|||
|[[Testing|Testing]] |
|||
}} |
|||
{{Powerdocnavi{{#translation:}}}} |
|||
[[Category:Developer Documentation{{#translation:}}]] |
|||
[[Category:Python Code{{#translation:}}]] |
|||
{{clear}} |
{{clear}} |
Latest revision as of 18:47, 6 February 2024
Prueba primero
Antes de pasar por la molestia de la depuración, utilice el Marco de pruebas para comprobar si las pruebas estándar funcionan correctamente. Si no se ejecutan por completo, es posible que haya una instalación defectuosa.
Línea de comandos
La depuración de FreeCAD está respaldada por algunos mecanismos internos. La versión de línea de comandos de FreeCAD proporciona algunas opciones para soporte de depuración.
Estas son las opciones reconocidas actualmente en FreeCAD 0.19:
Opciones genéricas:
-v [ --version ] Imprime la cadena de versión -h [ --help ] Imprime el mensaje de ayuda -c [ --console ] Comienza en modo consola --response-file arg También se puede especificar con '@nombre' --dump-config Configuración de volcados --get-config arg Imprime el valor de la clave de configuración solicitada
Configuración:
-l [ --write-log ] Escribe un archivo de registro en: $HOME/.local/share/FreeCAD/FreeCAD.log (Linux) $HOME/Library/Application\ Support/FreeCAD/FreeCAD.log (macOS) %APPDATA%\FreeCAD\FreeCAD.log --log-file arg A diferencia de --write-log, esto permite iniciar sesión en un archivo arbitrario -u [ --user-cfg ] arg Archivo de configuración de usuario para cargar/guardar configuraciones de usuario -s [ --system-cfg ] arg Archivo de configuración del sistema para cargar/guardar la configuración del sistema -t [ --run-test ] arg Caso de prueba - o 0 para todos -M [ --module-path ] arg Rutas de módulos adicionales -P [ --python-path ] arg Rutas adicionales de Python --single-instance Permite ejecutar una única instancia de la aplicación
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.
Para Linux
Depuración de Linux →
Requisitos previos:
- paquete de software gdb instalado
- una versión de depuración de FreeCAD (en este momento solo está disponible mediante la compilación desde el código fuente)
- un modelo de FreeCAD que provoca un problema
Pasos: Ingrese lo siguiente en la ventana de su terminal:
Encuentre el binario FreeCAD en su sistema:
$ whereis freecad
freecad: /usr/local/freecad <--- for example
$ cd /usr/local/freecad/bin
$ gdb FreeCAD
GNUdebugger generará información de inicialización. El (gdb) muestra que GNUDebugger se está ejecutando en la terminal, ahora ingrese:
(gdb) handle SIG33 noprint nostop
(gdb) run
FreeCAD ahora se iniciará. Realice los pasos que hacen que FreeCAD se bloquee o se congele, luego ingrese en la ventana de terminal:
(gdb) bt
Esto generará una lista larga de exactamente lo que estaba haciendo el programa cuando falló o se congeló. Incluya esto con su informe de problemas.
(gdb) bt full
Imprima también los valores de las variables locales. Esto se puede combinar con un número para limitar la cantidad de fotogramas mostrados.
Para macOS
Depuración de macOS →
Requisitos previos:
- software package lldb installed
- a debug build of FreeCAD
- a FreeCAD model that causes a crash
Steps: Enter the following in your terminal window:
$ cd FreeCAD/bin
$ lldb FreeCAD
LLDB will output some initializing information. The (lldb) shows the debugger is running in the terminal, now input:
(lldb) run
FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window:
(lldb) bt
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:
ps -A | grep FreeCAD
Use the returned id and pass it to lsof
:
lsof -p process_id
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:
lsof -p process_id | grep Coin
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:
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.
- Run winpdb and set the password (e.g. test)
- Create a Python file with this content
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)
- Start FreeCAD and load the above file into FreeCAD
- Press F6 to execute it
- Now FreeCAD will become unresponsive because the Python debugger is waiting
- Switch to the Windpdb GUI and click on "Attach". After a few seconds an item "<Input>" appears where you have to double-click
- Now the currently executed script appears in Winpdb.
- Set a break at the last line and press F5
- Now press F7 to step into the Python code of Draft.makeWire
Visual Studio Code (VS Code)
VS Code Debugging →
Prerequisites:
- The ptvsd package needs to be installed in a Python 3 outside of FreeCAD, then the module must be copied to FreeCAD's Python library folder.
# In a cmd window that has a path to you local Python 3:
pip install ptvsd
# Then if your Python is installed in C:\Users\<userid>\AppData\Local\Programs\Python\Python37
# and your FreeCAD is installed in C:\freecad\bin
xcopy "C:\Users\<userid>\AppData\Local\Programs\Python\Python37\Lib\site-packages\ptvsd" "C:\freecad\bin\Lib\site-packages\ptvsd"
Visual Studio Code documentation for remote debugging
Steps:
- Add following code at the beginning of your script
import ptvsd
print("Waiting for debugger attach")
# 5678 is the default attach port in the VS Code debug configurations
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)
ptvsd.wait_for_attach()
- Add a debug configuration in Visual Studio Code Debug → Add Configurations….
- The config should look 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": "<directory of file>"
- For example, if the Python file resides in /home/FC_myscripts/myscript.py
- Change to: "remoteRoot": "/home/FC_myscripts"
- If you're just debugging FreeCAD macros from the FreeCAD macro folder, and that folder is "C:/Users/<userid>/AppData/Roaming/FreeCAD/Macro", then use:
- "localRoot": "C:/Users/<userid>/AppData/Roaming/FreeCAD/Macro",
- "remoteRoot": "C:/Users/<userid>/AppData/Roaming/FreeCAD/Macro"
- Change "remoteRoot": "." to "remoteRoot": "<directory of file>"
- If your macro can't find ptvsd despite having installed it somewhere precede 'import ptvsd' with
from sys import path
sys.path.append('/path/to/site-packages')
Where the path is to the directory where ptvsd was installed.
- On the left bottom edge of VSCode you can choose the Python executable - it's best to make this the version packaged with FreeCAD.
In the Mac package it is /Applications/FreeCAD.App/Contents/Resources/bin/python.
You can locate it on your system by typing
import sys
print(sys.executable)
into FreeCAD's Python console.
With LiClipse and AppImage
LiClipse Debugging →
- Extract AppImage.
> ./your location/FreeCAD_xxx.AppImage --appimage-extract
> cd squashfs-root/
- The sqashfs-root location is where the debugger later on is hooked up to.
- Make sure you can start a FreeCAD session from within the squashfs-root location.
squashfs-root> ./usr/bin/freecadcmd
- Should start up a FreeCAD commandline session.
- Install LiClipse.
- Comes ready with pydev and has installers for all platforms.
- For linux it is just to extract (to any location) and run.
- Configure liclipse for debugging.
- Right-click pydev icon (upper right corner) and choose customize.
- Activate "PyDev Debug" (through checkbox, or it might be needed to go to tab "Action Set Availability" and activate there first).
- In the pydev menu you can now choose "start debug server".
- Use menu window/open perspective/other > debug.
- Right-click debug icon (upper right corner) and choose customize.
- Checking "Debug" brings the debugging navigation tools to the toolbar.
- Open preferences through menu window/preferences.
- In PyDev/Interpreters add "new Interpreter by browsing".
- The added interpreter should be:
your loc/squashfs-root/usr/bin/python
. - If you are only using this for fc, you can add AddOn workbench folders as well, or do that in a pydev-project later on.
- Right-click pydev icon (upper right corner) and choose customize.
- Find path to
pydevd.py
in your liclipse installation.- Something along the lines of:
your location/liclipse/plugins/org.python.pydev.xx/pysrc
.
- Something along the lines of:
- Create a regular pydev-project in liclipse.
- Import external sources, for example a macro that you want to debug, or an external workbench.
- In that macro (or workbench .py file) add the code lines:
import sys; sys.path.append("path ending with /pysrc") import pydevd; pydevd.settrace()
- This is where the execution will halt when the macro is run.
- Start the liclipse debug server (menu pydev).
- Start FreeCAD.
squashfs-root> ./usr/bin/freecad
- Run the macro (or any other file with a
pydevd.settrace()
trigger) from within freecad, as you would normally do.
- Happy debugging.
- The use of LiClipse for remote debugging, and the steps described here related to liclipse, should work on any platform. The parts related to AppImage is for linux only.
Pyzo
See the main article about Pyzo.
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.
- FreeCAD scripting: Python, Introduction to Python, Python scripting tutorial, FreeCAD Scripting Basics
- Modules: Builtin modules, Units, Quantity
- Workbenches: Workbench creation, Gui Commands, Commands, Installing more workbenches
- Meshes and Parts: Mesh Scripting, Topological data scripting, Mesh to Part, PythonOCC
- Parametric objects: Scripted objects, Viewproviders (Custom icon in tree view)
- Scenegraph: Coin (Inventor) scenegraph, Pivy
- Graphical interface: Interface creation, Interface creation completely in Python (1, 2, 3, 4, 5), PySide, PySide examples beginner, intermediate, advanced
- Macros: Macros, How to install macros
- Embedding: Embedding FreeCAD, Embedding FreeCADGui
- Other: Expressions, Code snippets, Line drawing function, FreeCAD vector math library (deprecated)
- Hubs: User hub, Power users hub, Developer hub