轉自: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進程的主函數如下:
- 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);
HandleRenderErrorTestParameters函數會顯示這個模態對話框。
- // 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);
- }
- }