使用 Xcode 调试¶
您可以使用 Xcode 构建和调试 WebKit。打开顶级目录中的 WebKit.xcworkspace
。
为了让 Xcode 使用通过上述 make
命令构建的文件,请转到 File > Workspace Settings... > Advanced... > Custom > Relative to Workspace 并调整 Products 和 Intermediates 的相对路径,使其指向 WebKitBuild
目录。
请注意,调试 WebCore 代码通常需要附加到相关的 WebContent 进程,而不是应用程序进程,应用程序进程主要运行 Source/WebKit/UIProcess 中的代码。根据您正在调试的内容,您需要附加和调试联合体中的不同进程。
您可能会发现使用 Tools/lldb/lldb_webkit.py
下的调试助手很有用。通过在 ~/.lldbinit
中添加行 command script import {Path to WebKit}/Tools/lldb/lldb_webkit.py
,可以将其添加到 ~/.lldbinit
以便在 LLDB 启动时自动加载。有关更多详细信息,请参阅 Wiki 文章 lldb 格式化程序。
在 LLDB 中调试调试版本时,还可以对对象调用一些函数,这些函数会转储调试信息。
- RenderObject
- showNodeTree()
- showLineTree()
- showRenderTree()
- Node
- showTree()
- showNodePath()
- showTreeForThis()
- showNodePathForThis()
调试布局测试¶
调试布局测试最简单的方法是使用 WebKitTestRunner 或 DumpRenderTree。在 Product > Scheme 中,选择“All Source”。
在 Product > Scheme > Edit Scheme 中,打开“Run”选项卡。在“Executable”中选择 WebKitTestRunner 或 DumpRenderTree,以所需为准。
转到 Arguments 并指定要调试的布局测试相对于构建目录的路径。例如,如果
WebKitBuild/Debug
是构建目录,则为 ../../LayoutTests/fast/dom/Element/element-traversal.html
。 您可能希望将 OS_ACTIVITY_MODE 环境变量设置为“disable”以抑制调试会话期间发生的所有系统日志。
如果您正在单步执行代码,您可能还需要指定 --no-timeout
选项,以防止 WebKitTestRunner 或 DumpRenderTree 在 30 秒后停止测试。
完成此操作后,您可以通过转到 Product > Perform Action > Run without Building 来运行 WebKitTestRunner 或 DumpRenderTree。
每次点击“Run”按钮可能会显著变慢,因为 Xcode 每次都会重新构建每个项目和框架。您可以通过转到“Build”选项卡并取消选中“Run”所涉及的所有框架的复选框来禁用此行为:
附加到 WebContent 进程¶
您可能会发现 Xcode 无法附加到 WebKitTestRunner 的 WebContent 或 Networking 进程。在这些情况下,在 UIProcess 代码中设置断点,例如在 TestController::runTest
中 TestInvocation::invoke
调用之前。一旦 UIProcess 中命中断点,通过 Debug > Attach to Process 在 Xcode 中手动附加到 WebContent.Development
或 Networking.Development
进程。