调试
测试第一
在你经历痛苦的调试过程之前请使用 测试框架 来检查标准测试是否正常工作。如果它们未运行完成, 则可能是安装中断。
命令行
FreeCAD 的 "调试" 是由一些内部机制支持的。FreeCAD 的命令行版本提供了一些用于调试支持的选项。
以下是 FreeCAD 0.15 中能识别的选项:
一般性选项:
-v [ --version ] 打印版本字符串 -h [ --help ] 打印帮助信息 -c [ --console ] 以控制台模式启动 --response-file arg 也能使用 '@name' 指定
配置:
-l [ --write-log ] 输出 log 文件到: $HOME/.FreeCAD/FreeCAD.log --log-file arg 不像 --write-log,这个命令允许记录到任意文件 -u [ --user-cfg ] arg 用于加载/保存用户设置的用户配置文件 -s [ --system-cfg ] arg 用于加载/保存系统设置的用户配置文件 -t [ --run-test ] arg 测试等级 -M [ --module-path ] arg 额外的模块路径 -P [ --python-path ] arg 额外的python路径
生成回溯
如果你运行 FreeCAD 开发中的出血边缘(bleeding edge)版本, 则可能会发生 "崩溃 "。 您可以通过向开发人员提供 "回溯 " 来帮助解决此类问题。 为此, 您需要运行软件的 "调试版本 "。 "调试生成 " 是在编译时设置的参数, 因此您需要自己编译 FreeCAD, 或者获取编译 "调试 " 版本。
对于 Linux
Linux 调试 ---->
必要条件:
- 安装的 gdb 软件包
- FreeCAD 的调试版本 (此时仅可通过 从源代码构建)
- 导致崩溃的 FreeCAD 模式
步骤: 在终端窗口中输入以下内容:
$ cd 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
这将生成一个冗长的列表, 确切地列出程序在崩溃或冻结时正在执行的工作。将此内容包括在问题报告中。
对于 MacOSX
MacOSX 调试 ---->
必要条件:
- 安装好的软件包 lldb
- FreeCAD 的调试版本
- 一个导致崩溃的 FreeCAD 模式
步骤: 在终端窗口中输入以下内容:
$ cd FreeCAD/bin $ lldb FreeCADLLDB 将输出一些初始化信息。(lldb) 显示调试器正在终端中运行, 现在输入:
(lldb) run
FreeCAD 现在就要启动。执行导致 FreeCAD 崩溃或冻结的步骤, 然后在终端窗口中输入:
(lldb) bt
这将生成一个冗长的列表, 确切地列出程序在崩溃或冻结时正在执行的工作。将此内容包括在问题报告中。
Python 调试
这里是一个在 FreeCAD 中使用 winpdb 的例子:
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.
- 运行 winpdb 并且设置密码 (例如:测试)
- 使用以下内容创建一个 Python 文件
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)
- 开始 FreeCAD 并将上述文件加载到 FreeCAD
- 按 F6 执行
- 现在 FreeCAD 将变得没有响应, 因为 Python 调试器正在等待
- 切换到 Windpdb GUI, 然后单击 "附加 "。几秒钟后, 将出现一个项目 "<Input> ", 您必须双击
- 现在, 当前执行的脚本出现在 Winpdb 中。
- 在最后一行设置断点并按 F5
- 现在按 F7 键跟踪 Python 代码 Draft.makeWire
Visual Studio Code (VS Code)
VS Code Debugging ---->
Prerequisites:
- ptvsd package need to be installedpypi page
pip install 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…. 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.
- Getting started
- Installation: Download, Windows, Linux, Mac, Additional components, Docker, AppImage, Ubuntu Snap
- Basics: About FreeCAD, Interface, Mouse navigation, Selection methods, Object name, Preferences, Workbenches, Document structure, Properties, Help FreeCAD, Donate
- Help: Tutorials, Video tutorials
- Workbenches: Std Base, Arch, Assembly, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Start, Surface, TechDraw, Test Framework, Web
- Hubs: User hub, Power users hub, Developer hub