Chrome多進程調試

來源:互聯網
上載者:User

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 plain copy print ? 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);  }}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.