The chrome multi-process model poses a big challenge to debug.
If you set a breakpoint on the code, by default, VS will only track those breakpoints in the main process browser code. VS provides a "Attach to process" approach. For example, when the render process is started, you can use the menu "Debug" => "Attach to process" option, select the newly generated process, and then set breakpoints in the code where you need to track. However, this method can only be effective when the subprocess is started, and if we want to track the execution of some code when the child process starts, there is no way.
Second, for this chrome from the source code level provides support. There are two kinds of methods:
1. Use the startup option "--single-process" to start chrome in a single process. Found this method is not good to use has been
2. Use the startup option "--renderer-startup-dialog" and "--no-sandbox". Two options will let the child process eject a modal dialog after it starts. You can then continue to run the code after closing the dialog box. During this time, we can use the above "Attach to process" method to track the execution of child Process code.
The reason for adding "--no-sandbox" is that by default, the creation and startup of the Chrome subprocess is in Sanbox (which means that access to system resources is strictly limited) and the modal dialog UI cannot be displayed.
The main functions of the render process are as follows:
[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);
The Handlerendererrortestparameters function displays this modal dialog box.
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::d Ebug::waitfordebugger (true);
if (command_line. Hasswitch (Switches::krendererstartupdialog))
Childprocess::waitfordebugger ("Renderer");
This is parameter causes an assertion.
if (command_line. Hasswitch (switches::krendererasserttest)) {
Dcheck (false);
}
}