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 |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 14 | arguments](https://gn.googlesource.com/gn/+/main/docs/quick_start.md) before |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 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 | |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 19 | Then, create a directory where the crash dumps will be stored: |
| 20 | |
| 21 | * Linux/Mac: |
| 22 | ```bash |
| 23 | mkdir /tmp/crashes |
| 24 | ``` |
| 25 | * Android: |
| 26 | ```bash |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 27 | adb root |
| 28 | adb shell mkdir /data/data/org.chromium.content_shell_apk/cache |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 29 | ``` |
| 30 | * Windows: |
| 31 | ```bash |
| 32 | mkdir %TEMP%\crashes |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 33 | ``` |
| 34 | |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 35 | ## Running content shell with crashpad |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 36 | |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 37 | Crashpad can be enabled by passing `--enable-crash-reporter` and |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 38 | `--crash-dumps-dir` to content shell: |
| 39 | |
| 40 | * Linux: |
| 41 | ```bash |
| 42 | out/Debug/content_shell --enable-crash-reporter \ |
| 43 | --crash-dumps-dir=/tmp/crashes chrome://crash |
| 44 | ``` |
| 45 | * Mac: |
| 46 | ```bash |
| 47 | out/Debug/Content\ Shell.app/Contents/MacOS/Content\ Shell \ |
| 48 | --enable-crash-reporter --crash-dumps-dir=/tmp/crashes chrome://crash |
| 49 | ``` |
| 50 | * Windows: |
| 51 | ```bash |
| 52 | out\Default\content_shell.exe --enable-crash-reporter ^ |
| 53 | --crash-dumps-dir=%TEMP%\crashes chrome://crash |
| 54 | ``` |
| 55 | * Android: |
| 56 | ```bash |
Joshua Peraza | 6f96b9d | 2019-02-12 16:55:14 | [diff] [blame] | 57 | out/Default/bin/content_shell_apk install |
| 58 | out/Default/bin/content_shell_apk launch chrome://crash |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 59 | --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] | 60 | ``` |
| 61 | |
| 62 | ## Retrieving the crash dump |
| 63 | |
Joshua Peraza | 00e6c56 | 2020-01-09 18:19:37 | [diff] [blame] | 64 | On Android, we first have to retrieve the crash dump. On other platforms, this |
| 65 | step can be skipped. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 66 | |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 67 | * Android: |
| 68 | ```bash |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 69 | 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] | 70 | ``` |
| 71 | |
| 72 | ## Symbolizing the crash dump |
| 73 | |
| 74 | On all platforms except for Windows, we need to convert the debug symbols to a |
| 75 | format that breakpad can understand. |
| 76 | |
| 77 | * Linux: |
| 78 | ```bash |
| 79 | components/crash/content/tools/generate_breakpad_symbols.py \ |
| 80 | --build-dir=out/Default --binary=out/Default/content_shell \ |
| 81 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear --jobs=16 |
| 82 | ``` |
| 83 | * Mac: |
| 84 | ```bash |
| 85 | components/crash/content/tools/generate_breakpad_symbols.py \ |
| 86 | --build-dir=out/Default \ |
| 87 | --binary=out/Default/Content\ Shell.app/Contents/MacOS/Content\ Shell \ |
| 88 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear --jobs=16 |
| 89 | ``` |
| 90 | * Android: |
| 91 | ```bash |
| 92 | components/crash/content/tools/generate_breakpad_symbols.py \ |
| 93 | --build-dir=out/Default \ |
| 94 | --binary=out/Default/lib/libcontent_shell_content_view.so \ |
Jochen Eisinger | b003ef45 | 2019-05-07 06:10:03 | [diff] [blame] | 95 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear \ |
| 96 | --platform=android |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 97 | ``` |
| 98 | |
| 99 | Now we can generate a stack trace from the crash dump. Assuming the crash dump |
| 100 | is in minidump.dmp: |
| 101 | |
| 102 | * Linux/Android/Mac: |
| 103 | ```bash |
| 104 | out/Default/minidump_stackwalk minidump.dmp out/Debug/content_shell.breakpad.syms |
| 105 | ``` |
| 106 | * Windows: |
| 107 | ```bash |
| 108 | "c:\Program Files (x86)\Windows Kits\8.0\Debuggers\x64\cdb.exe" ^ |
| 109 | -y out\Default -c ".ecxr;k30;q" -z minidump.dmp |
| 110 | ``` |