Chrome多进程调试

来源:互联网 发布:淘宝店铺彻底释放 编辑:程序博客网 时间:2024/06/05 04:52

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。

Render进程的主函数如下:

[cpp] view plaincopy
  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 plaincopy在CODE上查看代码片派生到我的代码片
  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. }  


转自:http://blog.csdn.net/leer168/article/details/8438149

0 0
原创粉丝点击