Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 1 | # Using crashpad with content shell |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 2 | |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 3 | When running web tests, it is possible to use |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 4 | [crashpad](../third_party/crashpad/)/[breakpad](../../third_party/breakpad/) to |
| 5 | capture stack traces on crashes while running without a debugger attached and |
| 6 | with the sandbox enabled. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 7 | |
| 8 | ## Setup |
| 9 | |
| 10 | On all platforms, build the target `blink_tests`. |
| 11 | |
| 12 | *** note |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 13 | **Mac:** Add `enable_dsyms = 1` to your [gn build |
| 14 | arguments](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) before |
| 15 | building. This slows down linking several minutes, so don't just always set it |
| 16 | by default. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 17 | *** |
| 18 | |
| 19 | *** note |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 20 | **Linux:** Add `use_debug_fission = true` to your [gn build |
| 21 | arguments](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) before |
| 22 | building. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 23 | *** |
| 24 | |
| 25 | Then, create a directory where the crash dumps will be stored: |
| 26 | |
| 27 | * Linux/Mac: |
| 28 | ```bash |
| 29 | mkdir /tmp/crashes |
| 30 | ``` |
| 31 | * Android: |
| 32 | ```bash |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 33 | adb root |
| 34 | adb shell mkdir /data/data/org.chromium.content_shell_apk/cache |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 35 | ``` |
| 36 | * Windows: |
| 37 | ```bash |
| 38 | mkdir %TEMP%\crashes |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 39 | ``` |
| 40 | |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 41 | ## Running content shell with crashpad |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 42 | |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 43 | Crashpad can be enabled by passing `--enable-crash-reporter` and |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 44 | `--crash-dumps-dir` to content shell: |
| 45 | |
| 46 | * Linux: |
| 47 | ```bash |
| 48 | out/Debug/content_shell --enable-crash-reporter \ |
| 49 | --crash-dumps-dir=/tmp/crashes chrome://crash |
| 50 | ``` |
| 51 | * Mac: |
| 52 | ```bash |
| 53 | out/Debug/Content\ Shell.app/Contents/MacOS/Content\ Shell \ |
| 54 | --enable-crash-reporter --crash-dumps-dir=/tmp/crashes chrome://crash |
| 55 | ``` |
| 56 | * Windows: |
| 57 | ```bash |
| 58 | out\Default\content_shell.exe --enable-crash-reporter ^ |
| 59 | --crash-dumps-dir=%TEMP%\crashes chrome://crash |
| 60 | ``` |
| 61 | * Android: |
| 62 | ```bash |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 63 | out/Default/bin/content_shell_apk install |
| 64 | out/Default/bin/content_shell_apk launch chrome://crash |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 65 | --args="--enable-crash-reporter --crash-dumps-dir=/data/data/org.chromium.content_shell_apk/cache" |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 66 | ``` |
| 67 | |
| 68 | ## Retrieving the crash dump |
| 69 | |
| 70 | On Linux and Android, we first have to retrieve the crash dump. On Mac and |
| 71 | Windows, this step can be skipped. |
| 72 | |
| 73 | * Linux: |
| 74 | ```bash |
| 75 | components/crash/content/tools/dmp2minidump.py /tmp/crashes/*.dmp /tmp/minidump |
| 76 | ``` |
| 77 | * Android: |
| 78 | ```bash |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 79 | adb pull $(adb shell ls /data/data/org.chromium.content_shell_apk/cache/pending/*.dmp) /tmp/chromium-renderer-minidump.dmp |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 80 | ``` |
| 81 | |
| 82 | ## Symbolizing the crash dump |
| 83 | |
| 84 | On all platforms except for Windows, we need to convert the debug symbols to a |
| 85 | format that breakpad can understand. |
| 86 | |
| 87 | * Linux: |
| 88 | ```bash |
| 89 | components/crash/content/tools/generate_breakpad_symbols.py \ |
| 90 | --build-dir=out/Default --binary=out/Default/content_shell \ |
| 91 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear --jobs=16 |
| 92 | ``` |
| 93 | * Mac: |
| 94 | ```bash |
| 95 | components/crash/content/tools/generate_breakpad_symbols.py \ |
| 96 | --build-dir=out/Default \ |
| 97 | --binary=out/Default/Content\ Shell.app/Contents/MacOS/Content\ Shell \ |
| 98 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear --jobs=16 |
| 99 | ``` |
| 100 | * Android: |
| 101 | ```bash |
| 102 | components/crash/content/tools/generate_breakpad_symbols.py \ |
| 103 | --build-dir=out/Default \ |
| 104 | --binary=out/Default/lib/libcontent_shell_content_view.so \ |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 105 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear \ |
| 106 | --platform=android |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 107 | ``` |
| 108 | |
| 109 | Now we can generate a stack trace from the crash dump. Assuming the crash dump |
| 110 | is in minidump.dmp: |
| 111 | |
| 112 | * Linux/Android/Mac: |
| 113 | ```bash |
| 114 | out/Default/minidump_stackwalk minidump.dmp out/Debug/content_shell.breakpad.syms |
| 115 | ``` |
| 116 | * Windows: |
| 117 | ```bash |
| 118 | "c:\Program Files (x86)\Windows Kits\8.0\Debuggers\x64\cdb.exe" ^ |
| 119 | -y out\Default -c ".ecxr;k30;q" -z minidump.dmp |
| 120 | ``` |