在你经历痛苦的调试过程之前请使用 测试框架 来检查标准测试是否正常工作。如果它们未完全运行, 则可能这是不完整的安装。
FreeCAD 的 "调试" 是由一些内部机制支持的。FreeCAD 的命令行版本提供了一些用于支持调试的选项。
以下是 FreeCAD 0.19 中能识别的选项:
一般性选项:
-v [ --version ] 打印版本字符串 -h [ --help ] 打印帮助信息 -c [ --console ] 以控制台模式启动 --response-file arg 也能使用 '@name' 指定 --dump-config 转储配置 -get-config arg 根据关键字打印特定的配置
配置:
-l [ --write-log ] 输出 log 文件到: $HOME/.FreeCAD/FreeCAD.log(Linux) $HOME/Library/Preferences/FreeCAD/FreeCAD.log (macOS) %APPDATA%\FreeCAD\FreeCAD.log (Windows)
--log-file arg 不像 --write-log,这个命令允许记录log到任意文件 -u [ --user-cfg ] arg 用于加载/保存用户设置的用户配置文件 -s [ --system-cfg ] arg 用于加载/保存系统设置的用户配置文件 -t [ --run-test ] arg 测试用例 -M [ --module-path ] arg 额外的模块路径 -P [ --python-path ] arg 额外的python脚本路径 --single-instance 允许以单例模式运行
如果你运行 FreeCAD 开发中的出血边缘(bleeding edge)版本, 则可能会发生 "崩溃 "。 您可以通过向开发人员提供 "回溯 " 来帮助解决此类问题。 为此, 您需要运行软件的 "调试版本 "。 "调试生成 " 是在编译时设置的参数, 因此您需要自己编译 FreeCAD, 或者获取预编译的"调试 " 版本。
Linux Debugging →
Prerequisites:
步骤: 在终端窗口中输入以下内容:
Find FreeCAD binary on your system:
$ whereis freecad
freecad: /usr/local/freecad <--- for example
$ cd /usr/local/freecad/bin
$ gdb FreeCAD
GNUdebugger will output some initializing information. The (gdb) shows GNUDebugger is running in the terminal, now input:
(gdb) handle SIG33 noprint nostop
(gdb) run
FreeCAD 现在就要启动。执行导致 FreeCAD 崩溃或冻结的步骤, 然后在终端窗口中输入:
(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.
(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.
MacOSX 调试 ---->
必要条件:
macOS Debugging →
Prerequisites:
步骤: 在终端窗口中输入以下内容:
$ 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 现在就要启动。执行导致 FreeCAD 崩溃或冻结的步骤, 然后在终端窗口中输入:
(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.
(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
这里是一个在 FreeCAD 中使用 winpdb 的例子:
For a more modern approach to debugging Python, see these posts:
winpdb 调试 →
这里是一个在FreeCAD内使用“Winpdb”的例子
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.
Now we will run a test Python script in FreeCAD step by step.
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)
VS Code Debugging →
Prerequisites:
# 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:
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()
"configurations": [ { "name": "Python: Attacher", "type": "python", "request": "attach", "port": 5678, "host": "localhost", "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "." } ] },
from sys import path
sys.path.append('/path/to/site-packages')
Where the path is to the directory where ptvsd was installed.
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.
LiClipse Debugging →
> ./your location/FreeCAD_xxx.AppImage --appimage-extract
> cd squashfs-root/
squashfs-root> ./usr/bin/freecadcmd
your loc/squashfs-root/usr/bin/python
.pydevd.py
in your liclipse installation.
your location/liclipse/plugins/org.python.pydev.xx/pysrc
.import sys; sys.path.append("path ending with /pysrc")
import pydevd; pydevd.settrace()
squashfs-root> ./usr/bin/freecad
pydevd.settrace()
trigger) from within freecad, as you would normally do.See the main article about Pyzo.
For developers needing to dig deeper in to the OpenCasCade kernel, user @abdullah has created a thread orientation discussing how to do so.