CEF笔记:render进程的调试
Chrome的多进程模型给DEBUG带来了很大的挑战。
一、如果你设置代码的断点,默认情况下,VS只会跟踪那些在主进程Browser代码中的那些断点。VS提供了"Attach To Process"的方法。比如当Render Process启动之后,可以用菜单"Debug"=>"Attach To Process"选项,选择那个新产生的进程,然后在你需要跟踪的代码处设置断点,就可以。但是这种方法,只能在子进程启动之后,才比较有效,如果我们想在子进程启动时,跟踪某些代码的执行,就没有办法了。
二、针对这个Chrome从源代码级别提供了支持。共有两种方法:
1. 用启动选项“--single-process“,以单进程的方法来启动Chrome。发现这个方法不好用了已经
2.用启动选项"--renderer-startup-dialog"和"--no-sandbox"。两个选项将会让子进程在启动之后,弹出一个模态对话框。之后在关闭这个对话框之后才可以继续运行代码。在这期间,我们可以用上述"Attach To Process"的方法来跟踪子进程代码的执行。
之所以要加上"--no-sandbox",是因为默认情况下Chrome的子进程的创建和启动是在sanbox中(也就说访问系统资源是严格限制的),无法显示模态对话框UI。
运行下面代码
int RendererMain(const MainFunctionParams& parameters) { const CommandLine& parsed_command_line = parameters.command_line_; base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; // This function allows pausing execution using the --renderer-startup-dialog // flag allowing us to attach a debugger. // Do not move this function down since that would mean we can't easily debug // whatever occurs before it. HandleRendererErrorTestParameters(parsed_command_line);
Render进程的主函数如下:
运行下面代码
// This function provides some ways to test crash and assertion handling // behavior of the renderer. static void HandleRendererErrorTestParameters(const CommandLine& command_line) { if (command_line.HasSwitch(switches::kWaitForDebugger)) base::debug::WaitForDebugger(60, true); if (command_line.HasSwitch(switches::kRendererStartupDialog)) ChildProcess::WaitForDebugger("Renderer"); // This parameter causes an assertion. if (command_line.HasSwitch(switches::kRendererAssertTest)) { DCHECK(false); } }
转载自:http://blog.csdn.net/leer168/article/details/8438149#
本文作者:方方和圆圆
本文链接:https://www.cnblogs.com/diligenceday/p/6058442.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步