[email protected] | 588483dc | 2015-01-10 14:38:08 | [diff] [blame] | 1 | #!/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 | |||||
8 | RENDERER_PID_RE='Renderer \(([0-9]+)\) paused waiting for debugger' | ||||
9 | TARGET_FLAGS="--no-sandbox --renderer-startup-dialog" | ||||
[email protected] | 588483dc | 2015-01-10 14:38:08 | [diff] [blame] | 10 | TARGET=$1 |
11 | shift | ||||
12 | |||||
13 | if [ -z "$TARGET" ]; then | ||||
14 | echo "usage: $(basename $0) <path-to-content-shell> [more-args...]" | ||||
[email protected] | 0ca90e24 | 2015-08-13 06:35:50 | [diff] [blame] | 15 | exit 1 |
[email protected] | 588483dc | 2015-01-10 14:38:08 | [diff] [blame] | 16 | fi |
17 | |||||
[email protected] | 0ca90e24 | 2015-08-13 06:35:50 | [diff] [blame] | 18 | if [ -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 | ||||
29 | fi | ||||
30 | |||||
31 | OUTPUT=$(mktemp "${TMPDIR:-/tmp}"/"$(basename $0)".XXXXX) | ||||
32 | "$TARGET" $TARGET_FLAGS "$@" 2>&1 | tee $OUTPUT & | ||||
[email protected] | 588483dc | 2015-01-10 14:38:08 | [diff] [blame] | 33 | BROWSER_PID=$! |
34 | |||||
35 | wait_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 | |||||
44 | browser_running() { ps -p $BROWSER_PID > /dev/null; } | ||||
45 | renderer_pid() { [[ "$(cat $OUTPUT)" =~ $RENDERER_PID_RE ]] && echo ${BASH_REMATCH[1]}; } | ||||
46 | |||||
47 | wait_renderer_pid | ||||
48 | if [ -n "$RENDERER_PID" ]; then | ||||
49 | # print yellow message | ||||
[email protected] | 0ca90e24 | 2015-08-13 06:35:50 | [diff] [blame] | 50 | echo -e "\n\033[1;33mDebugging renderer, use '$CONTINUE' to run.\033[0m\n" |
[email protected] | 588483dc | 2015-01-10 14:38:08 | [diff] [blame] | 51 | $DEBUGGER -p $RENDERER_PID |
52 | fi | ||||
53 | |||||
54 | wait | ||||
55 | rm $OUTPUT |