如何在gdb中调试Chrome子进程崩溃(Aw-Snap页面)并获取栈追踪?
Let me walk you through how to fix this issue—Chrome’s multi-process architecture is the main culprit here, and we need to adjust both GDB settings and Chrome’s launch flags to capture those renderer crashes properly.
Why Your Current Setup Isn’t Working
Chrome spins up separate processes for tabs (renderers), GPU, plugins, etc. By default, GDB detaches from child processes after a fork(), which is why you lose track when the browser starts up. Setting detach-on-fork off breaks Chrome’s process management because it expects child processes to detach cleanly, hence the failed launch.
Solution 1: Tune GDB to Track Child Processes (With Sandbox Disabled)
This method keeps GDB attached to all child processes and switches focus to them when they crash:
- Launch GDB with your Chrome binary (adjust the path if needed):
gdb /usr/bin/google-chrome - Inside GDB, set these critical debugging options:
# Don't detach from child processes after fork set detach-on-fork off # Switch GDB's focus to the child process when fork happens set follow-fork-mode child # Notify when new threads/processes are created set print thread-events on - Start Chrome with sandbox disabled (sandbox blocks debugger access to child processes):
When a tab crashes (shows "Aw, Snap!"), GDB will halt at the crash point. Runrun --no-sandboxbt fullto get a complete stack trace.
Solution 2: Attach GDB Directly to Renderer Processes
If you only care about renderer crashes, this approach makes Chrome launch each renderer inside GDB automatically:
Run Chrome with this command (again, disable sandbox for debugging):
google-chrome --renderer-cmd-prefix="gdb -ex 'handle SIGSEGV stop print pass' -ex 'run' -ex 'bt full' -ex 'quit' --args" --no-sandbox
Every time a renderer process crashes, GDB will print the full stack trace to your terminal before exiting.
Key Notes
- Always use
--no-sandboxfor debugging: Chrome’s sandbox prevents debuggers from accessing child processes, so this flag is non-negotiable for capturing crashes. - Install debug symbols: If your stack traces only show memory addresses instead of function names, install Chrome’s debug symbols package (e.g.,
google-chrome-dbgon Debian/Ubuntu). - Disable GPU if needed: Add
--disable-gputo rule out GPU process interference if crashes are inconsistent.
内容的提问来源于stack exchange,提问作者kenorb

