pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 1 | # Using breakpad with content shell |
| 2 | |
| 3 | When running layout tests, it is possible to use |
Euisang Lim | e2f2e78 | 2018-05-09 05:04:06 | [diff] [blame] | 4 | [breakpad](../../third_party/breakpad/) to capture stack traces on crashes while |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 5 | running without a debugger attached and with the sandbox enabled. |
| 6 | |
| 7 | ## Setup |
| 8 | |
| 9 | On all platforms, build the target `blink_tests`. |
| 10 | |
| 11 | *** note |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame^] | 12 | **Mac:** Add `enable_dsyms = 1` to your [gn build |
| 13 | arguments](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) before |
| 14 | building. This slows down linking several minutes, so don't just always set it |
| 15 | by default. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 16 | *** |
| 17 | |
| 18 | *** note |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame^] | 19 | **Linux:** Add `use_debug_fission = true` to your [gn build |
| 20 | arguments](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) before |
| 21 | building. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 22 | *** |
| 23 | |
| 24 | Then, create a directory where the crash dumps will be stored: |
| 25 | |
| 26 | * Linux/Mac: |
| 27 | ```bash |
| 28 | mkdir /tmp/crashes |
| 29 | ``` |
| 30 | * Android: |
| 31 | ```bash |
| 32 | adb shell mkdir /data/local/tmp/crashes |
| 33 | ``` |
| 34 | * Windows: |
| 35 | ```bash |
| 36 | mkdir %TEMP%\crashes |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 37 | ``` |
| 38 | |
| 39 | ## Running content shell with breakpad |
| 40 | |
| 41 | Breakpad can be enabled by passing `--enable-crash-reporter` and |
| 42 | `--crash-dumps-dir` to content shell: |
| 43 | |
| 44 | * Linux: |
| 45 | ```bash |
| 46 | out/Debug/content_shell --enable-crash-reporter \ |
| 47 | --crash-dumps-dir=/tmp/crashes chrome://crash |
| 48 | ``` |
| 49 | * Mac: |
| 50 | ```bash |
| 51 | out/Debug/Content\ Shell.app/Contents/MacOS/Content\ Shell \ |
| 52 | --enable-crash-reporter --crash-dumps-dir=/tmp/crashes chrome://crash |
| 53 | ``` |
| 54 | * Windows: |
| 55 | ```bash |
| 56 | out\Default\content_shell.exe --enable-crash-reporter ^ |
| 57 | --crash-dumps-dir=%TEMP%\crashes chrome://crash |
| 58 | ``` |
| 59 | * Android: |
| 60 | ```bash |
| 61 | build/android/adb_install_apk.py out/Default/apks/ContentShell.apk |
| 62 | build/android/adb_content_shell_command_line --enable-crash-reporter \ |
| 63 | --crash-dumps-dir=/data/local/tmp/crashes chrome://crash |
| 64 | build/android/adb_run_content_shell |
| 65 | ``` |
| 66 | |
| 67 | ## Retrieving the crash dump |
| 68 | |
| 69 | On Linux and Android, we first have to retrieve the crash dump. On Mac and |
| 70 | Windows, this step can be skipped. |
| 71 | |
| 72 | * Linux: |
| 73 | ```bash |
| 74 | components/crash/content/tools/dmp2minidump.py /tmp/crashes/*.dmp /tmp/minidump |
| 75 | ``` |
| 76 | * Android: |
| 77 | ```bash |
| 78 | adb pull $(adb shell ls /data/local/tmp/crashes/*) /tmp/chromium-renderer-minidump.dmp |
| 79 | components/breakpad/tools/dmp2minidump /tmp/chromium-renderer-minidump.dmp /tmp/minidump |
| 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 \ |
| 105 | --symbols-dir=out/Default/content_shell.breakpad.syms --clear |
| 106 | ``` |
| 107 | |
| 108 | Now we can generate a stack trace from the crash dump. Assuming the crash dump |
| 109 | is in minidump.dmp: |
| 110 | |
| 111 | * Linux/Android/Mac: |
| 112 | ```bash |
| 113 | out/Default/minidump_stackwalk minidump.dmp out/Debug/content_shell.breakpad.syms |
| 114 | ``` |
| 115 | * Windows: |
| 116 | ```bash |
| 117 | "c:\Program Files (x86)\Windows Kits\8.0\Debuggers\x64\cdb.exe" ^ |
| 118 | -y out\Default -c ".ecxr;k30;q" -z minidump.dmp |
| 119 | ``` |