Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 1 | # Debugging |
| 2 | |
David Dorwin | fe186dd | 2022-05-20 18:35:13 | [diff] [blame] | 3 | [TOC] |
| 4 | |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 5 | It is possible to debug Fuchsia binaries using `zxdb`. For the sake of these |
| 6 | examples, we will be using `base_unittests` as the test suite we wish to |
| 7 | execute. These instructions assume that your Chromium build has the following gn |
| 8 | arguments: |
| 9 | |
| 10 | ``` |
| 11 | is_debug = true |
| 12 | is_component_build = true |
| 13 | target_os = "fuchsia" |
| 14 | symbol_level = 2 |
| 15 | ``` |
| 16 | |
| 17 | ## Manual debugging via the command line |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 18 | |
| 19 | 1. (From Chromium) Install your package(s) and its symbols onto the device. |
| 20 | |
| 21 | ```bash |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 22 | out/fuchsia/bin/install_base_unittests --fuchsia-out-dir=/path/to/fuchsia/out/directory |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 23 | ``` |
| 24 | |
| 25 | 2. (From Fuchsia source tree) Run the debugger. |
| 26 | |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 27 | ```bash |
| 28 | fx debug -- --build-dir /path/to/chromium/src/out/directory |
| 29 | ``` |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 30 | |
| 31 | 3. Set up the debugger to attach to the process. |
| 32 | |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 33 | ``` |
| 34 | [zxdb] attach base_unittests.cmx |
| 35 | ``` |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 36 | |
| 37 | 4. Configure breakpoint(s). |
| 38 | |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 39 | ``` |
| 40 | [zxdb] break base::GetDefaultJob |
| 41 | ``` |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 42 | |
| 43 | 5. (In another terminal, from Fuchsia source tree) Run the test package. |
| 44 | |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 45 | ```bash |
| 46 | fx shell run fuchsia-pkg://fuchsia.com/base_unittests#meta/base_unittests.cmx |
| 47 | ``` |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 48 | |
| 49 | 6. At this point, you should hit a breakpoint in `zxdb`. |
| 50 | |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 51 | ``` |
| 52 | [zxdb] f |
| 53 | ▶ 0 base::GetDefaultJob() • default_job.cc:18 |
| 54 | 1 base::$anon::LaunchChildTestProcessWithOptions(…) • test_launcher.cc:335 |
| 55 | 2 base::$anon::DoLaunchChildTestProcess(…) • test_launcher.cc:528 |
| 56 | 3 base::TestLauncher::LaunchChildGTestProcess(…) • test_launcher.cc:877 |
| 57 | ... |
| 58 | ``` |
Chong Gu | 4749ec1 | 2021-02-17 01:41:06 | [diff] [blame] | 59 | |
| 60 | 7. Enjoy debugging! Steps 2 through 6 will also work for things like services |
| 61 | which aren't run directly from the command line, such as WebEngine. |
Fabrice de Gans | 5e00a85f | 2021-10-06 00:16:41 | [diff] [blame] | 62 | Run `help` inside ZXDB to see what debugger commands are available. |
| 63 | |
| 64 | ## VS Code integration |
| 65 | |
| 66 | 1. Install the [zxdb](https://marketplace.visualstudio.com/items?itemName=fuchsia-authors.zxdb) |
| 67 | extension. |
| 68 | |
| 69 | 2. Modify the `zxdb.command` setting in your Chromium workspace to this value: |
| 70 | |
| 71 | ```bash |
| 72 | (cd /path/to/fuchsia ; fx debug -- --enable-debug-adapter --build-dir /path/to/chromium/src/out/directory) |
| 73 | ``` |
| 74 | |
| 75 | 3. Edit your debug launch configurations in `.vscode/launch.json`: |
| 76 | |
| 77 | ```json |
| 78 | { |
| 79 | "version": "0.2.0", |
| 80 | "configurations": [ |
| 81 | { |
| 82 | "name": "Attach to base_unittests", |
| 83 | "type": "zxdb", |
| 84 | "request": "attach", |
| 85 | "process": "base_unittests.cmx" |
| 86 | } |
| 87 | ] |
| 88 | } |
| 89 | ``` |
| 90 | |
| 91 | You can add more configurations as needed. |
| 92 | |
| 93 | 4. Start the debug configuration in VS Code. You should get a terminal with zxdb |
| 94 | running. |
| 95 | |
| 96 | 5. Launch the test suite in a terminal. |
| 97 | |
| 98 | ```bash |
| 99 | out/fuchsia/bin/run_base_unittests -d --fuchsia-out-dir=/path/to/fuchsia/out/directory |
| 100 | ``` |
| 101 | |
| 102 | 6. Breakpoints set in the IDE should work. |