Chrome多进程调试

13 篇文章 0 订阅

Chrome的多进程模型给DEBUG带来了很大的挑战。

一、如果你设置代码的断点,默认情况下,VS只会跟踪那些在主进程Browser代码中的那些断点。VS提供了"Attach To Process"的方法。比如当Render Process启动之后,可以用菜单"Debug"=>"Attach To Process"选项,选择那个新产生的进程,然后在你需要跟踪的代码处设置断点,就可以。但是这种方法,只能在子进程启动之后,才比较有效,如果我们想在子进程启动时,跟踪某些代码的执行,就没有办法了。

二、针对这个Chrome从源代码级别提供了支持。共有两种方法:

1. 用启动选项“--single-process“,以单进程的方法来启动Chrome。发现这个方法不好用了已经

2.用启动选项"--render-startup-dialog"和"--no-sandbox"。两个选项将会让子进程在启动之后,弹出一个模态对话框。之后在关闭这个对话框之后才可以继续运行代码。在这期间,我们可以用上述"Attach To Process"的方法来跟踪子进程代码的执行。

之所以要加上"--no-sandbox",是因为默认情况下Chrome的子进程的创建和启动是在sanbox中(也就说访问系统资源是严格限制的),无法显示模态对话框UI。

Render进程的主函数如下:

[cpp]  view plain copy
  1. int RendererMain(const MainFunctionParams& parameters) {  
  2.   const CommandLine& parsed_command_line = parameters.command_line_;  
  3.   base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;  
  4.   
  5.   // This function allows pausing execution using the --renderer-startup-dialog  
  6.   // flag allowing us to attach a debugger.  
  7.   // Do not move this function down since that would mean we can't easily debug  
  8.   // whatever occurs before it.  
  9.   HandleRendererErrorTestParameters(parsed_command_line);  

HandleRenderErrorTestParameters函数会显示这个模态对话框。

[cpp]  view plain copy
  1. // This function provides some ways to test crash and assertion handling  
  2. // behavior of the renderer.  
  3. static void HandleRendererErrorTestParameters(const CommandLine& command_line) {  
  4.   if (command_line.HasSwitch(switches::kWaitForDebugger))  
  5.     base::debug::WaitForDebugger(60, true);  
  6.   
  7.   
  8.   if (command_line.HasSwitch(switches::kRendererStartupDialog))  
  9.     ChildProcess::WaitForDebugger("Renderer");  
  10.   
  11.   
  12.   // This parameter causes an assertion.  
  13.   if (command_line.HasSwitch(switches::kRendererAssertTest)) {  
  14.     DCHECK(false);  
  15.   }  
  16. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值