Chrome多進程調試

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

launch_win.cc中的launchProcess創建進程的地方。


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進程的主函數如下:

  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函數會顯示這個模態對話框。

  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. }  
發佈了103 篇原創文章 · 獲贊 19 · 訪問量 81萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章