Start the Fuchsia debugger (zxdb) in VS Code and step through the sample driver’s code.
The tasks include:
qemu_edu driver.In VS Code, do the following:
Click the TERMINAL tab on the VS Code panel.
In the terminal, view the list of the running driver hosts:
tools/ffx driver list-hosts
This command prints output similar to the following:
$ tools/ffx driver list-hosts Driver Host: 5507 fuchsia-boot:///#meta/bus-pci.cm fuchsia-boot:///#meta/display.cm fuchsia-boot:///#meta/goldfish-display.cm fuchsia-boot:///#meta/goldfish.cm fuchsia-boot:///#meta/goldfish_control.cm fuchsia-boot:///#meta/goldfish_sensor.cm fuchsia-boot:///#meta/goldfish_sync.cm fuchsia-boot:///#meta/hid.cm fuchsia-boot:///#meta/platform-bus-x86.cm fuchsia-boot:///#meta/platform-bus.cm unbound ... Driver Host: 25673 fuchsia-pkg://fuchsia.com/virtual_audio#meta/virtual_audio_driver.cm unbound Driver Host: {{ '<strong>' }}85211{{ '</strong>' }} fuchsia-pkg://bazel.pkg.component.runnable/qemu_edu#meta/qemu_edu.cm
Make a note of the process ID (PID) of the qemu_edu driver host (85211 in the example above).
Click the Run and Debug icon on the left side of VS Code.
{: .screenshot width=“350”}
Click the Show all automatic debug configurations link.
This opens the Command Palette and displays a list of launch configurations:
{: .screenshot width=“500”}
In the Command Palette, click Add Config (fuchsia-drivers)....
Click zxdb.
This opens the .vscode/launch.json file.
Update this launch.json file to the following configuration:
"configurations": [ { "name": "{{ '<strong>' }}Fuchsia drivers{{ '</strong>' }}", "type": "zxdb", "request": "launch", "launchCommand": "{{ '<strong>' }}tools/bazel run //src/qemu_edu/tools:pkg.eductl_tool -- fact 12{{ '</strong>' }}", "process": "{{ '<var>' }}PID{{ '</var>' }}" } ]
Replace PID with the PID of your qemu_edu driver host from step 2, for example:
"process": "{{ '<strong>' }}85211{{ '</strong>' }}"
This configures the debugger to attach to the driver host using the PID and run eductl_tool.
To save the file, press CTRL+S (or Command+S on macOS).
Click the Explorer icon on the left side of VS Code.
{: .screenshot width=“50”}
Open the src/qemu_edu/drivers/edu_device.cc file.
To set a breakpoint at the QemuEduDevice::HandleIrq() method, click the space to the left of the line number.
{: .screenshot}
When a breakpoint is set, a red dot appears.
Click the Run and Debug icon on the left side of VS Code.
At the top of the Run and Debug panel, select the Fuchsia drivers option in the dropdown menu.
At the top of the Run and Debug panel, click the Play icon to launch the debugger.
{: .screenshot width=“350”}
This builds and runs eductl_tools, which causes the debugger to pause at the line where the breakpoint is set in the src/qemu_edu/drivers/edu_device.cc file.
Click the DEBUG CONSOLE tab on the VS Code panel.
{: .screenshot}
This shows the console output of the Fuchsia debugger (zxdb).
Click the TERMINAL tab on the VS Code panel.
The panel shows that the eductl_tool command is idling after printing output similar to the following:
$ tools/bazel run //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 ... INFO: Build completed successfully, 1 total action Running workflow: pkg.eductl_tool_base Running task: pkg.debug_symbols_base (step 1/2) Running task: pkg.eductl_tool.run_base (step 2/2) added repository bazel.pkg.eductl.tool.runnable
In the debug toolbar at the top of VS Code, click the Step Over icon.
{: .screenshot width=“250”}
Continue to click the Step Over icon to step through the HandleIrq() function until the line 126 is reached.
When the HandleIrq() function is finished, it replies with the result of the factorial.
In the TERMINAL panel, verify that the eductl_tool command has exited after printing the result of the factorial:
$ tools/bazel run //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 ... INFO: Build completed successfully, 1 total action Running workflow: pkg.eductl_tool_base Running task: pkg.debug_symbols_base (step 1/2) Running task: pkg.eductl_tool.run_base (step 2/2) added repository bazel.pkg.eductl.tool.runnable {{ '<strong>' }}Factorial(12) = 479001600{{ '</strong>' }} $
To exit the debugger, click the Stop icon in the debug toolbar.
{: .screenshot width=“250”}