There are two ways to attach a debugger to example components:
From the command-line interface (CLI). This is currently the most well-supported way.
From VSCode. This works for attaching breakpoints and stepping through the code but more advanced commands may not work (see known issues).
The Fuchsia debugger is called zxdb. Once attached, you can follow this reference for common zxdb workflows.
Connect the debugger to your Fuchsia device, for example the emulator started before running an example.
$FUCHSIA_EMBEDDER_DIR/tools/ffx debug connect
When successful, this should start a [zxdb] prompt.
From the [zxdb] prompt, attach to embedder.cm and add a breakpoint to main:
[zxdb] attach embedder.cm [zxdb] break main
In a separate terminal, run an example component. The debugger should detect the running component, attach to it and break on the main function.
$FUCHSIA_EMBEDDER_DIR/scripts/build_and_run_example.sh hello_flutter
Install the Fuchsia VSCode extension.
Set the “Ffx Path” setting for this extension to the output from this command:
echo $FUCHSIA_EMBEDDER_DIR/tools/ffx
For example:
Make sure the target for the Fuchsia extension is set to fuchsia-emulator.
The examples can be run from VSCode's Run and Debug menu. Breakpoints that are added to the code should be triggered.
There are several options:
Example name: Which of the example components to run. Defaults to hello_flutter.
With Flutter Engine: Builds using a custom Flutter Engine (requires setup from making_engine_changes.md). Default is off.
With Fuchsia: Builds using a custom Fuchsia SDK and platform (requires setup from testing_fuchsia_sdk_changes.md). Default is off.