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