blob: 3b5a834c41f0fce91c42e7498a688b6674606e7a [file] [log] [blame] [view]
Chong Gu4749ec12021-02-17 01:41:061# Debugging
2
David Dorwinfe186dd2022-05-20 18:35:133[TOC]
4
Fabrice de Gans5e00a85f2021-10-06 00:16:415It is possible to debug Fuchsia binaries using `zxdb`. For the sake of these
6examples, we will be using `base_unittests` as the test suite we wish to
7execute. These instructions assume that your Chromium build has the following gn
8arguments:
9
10```
11is_debug = true
12is_component_build = true
13target_os = "fuchsia"
14symbol_level = 2
15```
16
17## Manual debugging via the command line
Chong Gu4749ec12021-02-17 01:41:0618
191. (From Chromium) Install your package(s) and its symbols onto the device.
20
21 ```bash
Fabrice de Gans5e00a85f2021-10-06 00:16:4122 out/fuchsia/bin/install_base_unittests --fuchsia-out-dir=/path/to/fuchsia/out/directory
Chong Gu4749ec12021-02-17 01:41:0623 ```
24
252. (From Fuchsia source tree) Run the debugger.
26
Fabrice de Gans5e00a85f2021-10-06 00:16:4127 ```bash
28 fx debug -- --build-dir /path/to/chromium/src/out/directory
29 ```
Chong Gu4749ec12021-02-17 01:41:0630
313. Set up the debugger to attach to the process.
32
Fabrice de Gans5e00a85f2021-10-06 00:16:4133 ```
34 [zxdb] attach base_unittests.cmx
35 ```
Chong Gu4749ec12021-02-17 01:41:0636
374. Configure breakpoint(s).
38
Fabrice de Gans5e00a85f2021-10-06 00:16:4139 ```
40 [zxdb] break base::GetDefaultJob
41 ```
Chong Gu4749ec12021-02-17 01:41:0642
435. (In another terminal, from Fuchsia source tree) Run the test package.
44
Fabrice de Gans5e00a85f2021-10-06 00:16:4145 ```bash
46 fx shell run fuchsia-pkg://fuchsia.com/base_unittests#meta/base_unittests.cmx
47 ```
Chong Gu4749ec12021-02-17 01:41:0648
496. At this point, you should hit a breakpoint in `zxdb`.
50
Fabrice de Gans5e00a85f2021-10-06 00:16:4151 ```
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 Gu4749ec12021-02-17 01:41:0659
607. 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 Gans5e00a85f2021-10-06 00:16:4162 Run `help` inside ZXDB to see what debugger commands are available.
63
64## VS Code integration
65
661. Install the [zxdb](https://marketplace.visualstudio.com/items?itemName=fuchsia-authors.zxdb)
67 extension.
68
692. 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
753. 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
934. Start the debug configuration in VS Code. You should get a terminal with zxdb
94 running.
95
965. 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
1026. Breakpoints set in the IDE should work.