blob: 99dd3b96a1872e3b10e4317b5b446f6f1a509b33 [file] [log] [blame]
[email protected]588483dc2015-01-10 14:38:081#!/bin/bash
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.
5
6# Runs Chrome / content_shell and attaches to the first renderer process in gdb.
7
8RENDERER_PID_RE='Renderer \(([0-9]+)\) paused waiting for debugger'
9TARGET_FLAGS="--no-sandbox --renderer-startup-dialog"
[email protected]588483dc2015-01-10 14:38:0810TARGET=$1
11shift
12
13if [ -z "$TARGET" ]; then
14 echo "usage: $(basename $0) <path-to-content-shell> [more-args...]"
[email protected]0ca90e242015-08-13 06:35:5015 exit 1
[email protected]588483dc2015-01-10 14:38:0816fi
17
[email protected]0ca90e242015-08-13 06:35:5018if [ -z "$DEBUGGER" ]; then
19 if which lldb > /dev/null; then
20 DEBUGGER="lldb"
21 CONTINUE="continue"
22 elif which gdb > /dev/null; then
23 DEBUGGER="gdb -q"
24 CONTINUE="signal SIGUSR1"
25 else
26 echo "no debugger found"
27 exit 1
28 fi
29fi
30
31OUTPUT=$(mktemp "${TMPDIR:-/tmp}"/"$(basename $0)".XXXXX)
32"$TARGET" $TARGET_FLAGS "$@" 2>&1 | tee $OUTPUT &
[email protected]588483dc2015-01-10 14:38:0833BROWSER_PID=$!
34
35wait_renderer_pid() {
36 for i in {1..100}; do
37 browser_running || return
38 RENDERER_PID=$(renderer_pid)
39 [ -n "$RENDERER_PID" ] && return
40 sleep 0.2
41 done
42}
43
44browser_running() { ps -p $BROWSER_PID > /dev/null; }
45renderer_pid() { [[ "$(cat $OUTPUT)" =~ $RENDERER_PID_RE ]] && echo ${BASH_REMATCH[1]}; }
46
47wait_renderer_pid
48if [ -n "$RENDERER_PID" ]; then
49 # print yellow message
[email protected]0ca90e242015-08-13 06:35:5050 echo -e "\n\033[1;33mDebugging renderer, use '$CONTINUE' to run.\033[0m\n"
[email protected]588483dc2015-01-10 14:38:0851 $DEBUGGER -p $RENDERER_PID
52fi
53
54wait
55rm $OUTPUT