Start the Fuchsia debugger (zxdb
) and debug the sample component, which is now updated to crash when it runs.
The tasks include:
Do the following:
Start the Fuchsia debugger:
tools/ffx debug connect
This command automatically connects the debugger to the default target device, which is the emulator instance.
When connected to the device, this command starts the zxdb
terminal, for example:
$ tools/ffx debug connect Connecting (use "disconnect" to cancel)... Connected successfully. 👉 To get started, try "status" or "help". [zxdb]
In the zxdb
terminal, attach the debugger to the hello_world.cm
component:
This command prints output similar to the following:
[zxdb] attach hello_world.cm Waiting for process matching "hello_world.cm". Type "filter" to see the current filters.
In the zxdb
terminal, set a breakpoint at the main()
method:
This command prints output similar to the following:
[zxdb] break main Created Breakpoint 1 @ main Pending: No current matches for location. It will be matched against new processes and shared libraries.
In a different terminal, run the sample component:
Note: In this new terminal, make sure that you change to the same work directory (for instance, cd $HOME/fuchsia-getting-started
).
tools/bazel run //src/hello_world:pkg.component
In the zxdb
terminal, the sample component is paused at the breakpoint:
Attached Process 1 state=Running koid=17658651 name=hello_world.cm Downloading symbols... Breakpoint 1 now matching 1 addrs for main Could not load symbols for "<vDSO>" because there was no mapping for build ID "1dbd2861a642d61b". Symbol downloading complete. 0 succeeded, 1 failed. 🛑 on bp 1, 2 main() • hello_world.cc:8 6 7 int main() { ▶ 8 std::cout << "Hello again, World!\n"; 9 abort(); 10 return 0; [zxdb]
Note: You can re-build and re-run your component as many times as you want, but do not need to restart the debugger or run attach
again. The debugger will preserve your breakpoints and continue watching for future processes called hello_world.cm
.
In the new terminal, monitor device logs for the hello_world
component:
tools/ffx log --filter hello_world
This comment prints output similar to the following:
$ tools/ffx log --filter hello_world ... [215.904][pkg-resolver][pkg-resolver][I] resolved fuchsia-pkg://bazel.pkg.component.runnable/hello_world as fuchsia-pkg://bazel.pkg.component.runnable/hello_world to 4c1ba90570cc92a62fab8e718a2fad4599583c5b49a684b97469452c9c9387a8 with TUF [215.952][pkg-resolver][pkg-resolver][I] resolved fuchsia-pkg://bazel.pkg.component.runnable/hello_world as fuchsia-pkg://bazel.pkg.component.runnable/hello_world to 4c1ba90570cc92a62fab8e718a2fad4599583c5b49a684b97469452c9c9387a8 with TUF
Notice the Hello again, World!
line is not printed yet.
In the zxdb
terminal, use next
to step through the code:
In the zxdb
terminal, the code get executed line by line, for example:
... 🛑 on bp 1 main() • hello_world.cc:8 6 7 int main() { ▶ 8 std::cout << "Hello again, World!\n"; 9 abort(); 10 return 0; [zxdb] {{ '<strong>'}}next{{ '</strong>'}} 🛑 main() • hello_world.cc:9 7 int main() { 8 std::cout << "Hello again, World!\n"; ▶ 9 abort(); 10 return 0; 11 }
In the device logs terminal, verify that the Hello again, World!
line is now printed:
[ffx-laboratory:hello_world.cm][I] Hello again, World!
To exit the zxdb
terminal, type exit
or press Ctrl-D
.
This causes the component to finish the execution of the rest of the code.
Note: For more information on usages and best practices on zxdb
, see the zxdb user guide.