Skip to main content

使用 XCode 进行调试

使用 XCode 进行调试

🌐 Debugging with XCode

生成用于调试源的 xcode 项目(无法从 xcode 构建代码)

🌐 Generate xcode project for debugging sources (cannot build code from xcode)

使用 --ide=xcode 参数运行 gn gen

🌐 Run gn gen with the --ide=xcode argument.

$ gn gen out/Testing --ide=xcode

这将生成 electron.ninja.xcworkspace。你需要打开此工作区以设置断点并进行检查。

🌐 This will generate the electron.ninja.xcworkspace. You will have to open this workspace to set breakpoints and inspect.

有关使用 GN 生成 IDE 项目的更多信息,请参见 gn help gen

🌐 See gn help gen for more information on generating IDE projects with GN.

调试和断点

🌐 Debugging and breakpoints

构建完成后启动 Electron 应用。 你现在可以打开上面创建的 Xcode 工作区,并通过“调试 > 附加到进程 > Electron”调试菜单附加到 Electron 进程。 【注意:如果你想调试渲染进程,你还需要附加到 Electron Helper。】

🌐 Launch Electron app after build. You can now open the xcode workspace created above and attach to the Electron process through the Debug > Attach To Process > Electron debug menu. [Note: If you want to debug the renderer process, you need to attach to the Electron Helper as well.]

现在,你可以在任何已索引的文件中设置断点。然而,你将无法直接在 Chromium 源代码中设置断点。 要在 Chromium 源代码中设置断点,你可以选择“调试 > 断点 > 创建符号断点”,并将任意函数名称设置为符号。这将为所有具有该名称的函数设置断点,如果有多个类,也会包含所有类。 你也可以在附加调试器之前执行设置断点的步骤,但符号断点函数的实际断点可能在调试器附加到应用之前不会显示。

🌐 You can now set breakpoints in any of the indexed files. However, you will not be able to set breakpoints directly in the Chromium source. To set break points in the Chromium source, you can choose Debug > Breakpoints > Create Symbolic Breakpoint and set any function name as the symbol. This will set the breakpoint for all functions with that name, from all the classes if there are more than one. You can also do this step of setting break points prior to attaching the debugger, however, actual breakpoints for symbolic breakpoint functions may not show up until the debugger is attached to the app.