2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # Runs Chrome / content_shell and attaches to the first renderer process in gdb.
8 RENDERER_PID_RE
='Renderer \(([0-9]+)\) paused waiting for debugger'
9 TARGET_FLAGS
="--no-sandbox --renderer-startup-dialog"
13 if [ -z "$TARGET" ]; then
14 echo "usage: $(basename $0) <path-to-content-shell> [more-args...]"
18 if [ -z "$DEBUGGER" ]; then
19 if which lldb
> /dev
/null
; then
22 elif which gdb
> /dev
/null
; then
24 CONTINUE
="signal SIGUSR1"
26 echo "no debugger found"
31 OUTPUT
=$
(mktemp
"${TMPDIR:-/tmp}"/"$(basename $0)".XXXXX
)
32 "$TARGET" $TARGET_FLAGS "$@" 2>&1 |
tee $OUTPUT &
37 browser_running ||
return
38 RENDERER_PID
=$
(renderer_pid
)
39 [ -n "$RENDERER_PID" ] && return
44 browser_running
() { ps
-p $BROWSER_PID > /dev
/null
; }
45 renderer_pid
() { [[ "$(cat $OUTPUT)" =~
$RENDERER_PID_RE ]] && echo ${BASH_REMATCH[1]}; }
48 if [ -n "$RENDERER_PID" ]; then
49 # print yellow message
50 echo -e "\n\033[1;33mDebugging renderer, use '$CONTINUE' to run.\033[0m\n"
51 $DEBUGGER -p $RENDERER_PID