@@ -42,6 +42,11 @@ authoritative if this occurs. Instead of pinging individual members, use
42421 . [ Testing] ( #testing )
4343 1 . [ Running unit tests] ( #running-unit-tests )
4444 1 . [ Running the compiler test suite] ( #running-the-compiler-test-suite )
45+ 1 . [ Debugging] ( #debugging )
46+ 1 . [ ` zxdb ` ] ( #zxdb )
47+ 1 . [ Attaching ` zxdb ` ] ( #attaching-zxdb )
48+ 1 . [ Using ` zxdb ` ] ( #using-zxdb )
49+ 1 . [ Displaying source code in ` zxdb ` ] ( #displaying-source-code-in-zxdb )
4550
4651## Requirements
4752
@@ -136,7 +141,7 @@ These options configure the following:
136141
137142* ` -Lnative=${SDK_PATH}/arch/${ARCH}/lib ` : Link against Fuchsia libraries from
138143 the SDK
139- * ` -Lnative=${SDK_PATH}/arch/${ARCH}/sysroot/lib ` : Link against Fuchsia kernel
144+ * ` -Lnative=${SDK_PATH}/arch/${ARCH}/sysroot/lib ` : Link against Fuchsia sysroot
140145 libraries from the SDK
141146
142147In total, our new project will look like:
@@ -253,7 +258,7 @@ the following options:
253258 platform of your choice
254259* ` -Lnative ${SDK_PATH}/arch/${ARCH}/lib ` : Link against Fuchsia libraries from
255260 the SDK
256- * ` -Lnative ${SDK_PATH}/arch/${ARCH}/sysroot/lib ` : Link against Fuchsia kernel
261+ * ` -Lnative ${SDK_PATH}/arch/${ARCH}/sysroot/lib ` : Link against Fuchsia sysroot
257262 libraries from the SDK
258263
259264Putting it all together:
@@ -638,6 +643,130 @@ available on the [Fuchsia devsite].
638643Running the Rust test suite on Fuchsia is [ not currently supported] , but work is
639644underway to enable it.
640645
646+ ## Debugging
647+
648+ ### ` zxdb `
649+
650+ Debugging components running on a Fuchsia emulator can be done using the
651+ console-mode debugger: [ zxdb] . We will demonstrate attaching necessary symbol
652+ paths to debug our ` hello-fuchsia ` component.
653+
654+ ### Attaching ` zxdb `
655+
656+ In a separate terminal, issue the following command from our ` hello_fuchsia `
657+ directory to launch ` zxdb ` :
658+
659+ ** In separate terminal**
660+ ``` sh
661+ ${SDK_PATH} /tools/${ARCH} /ffx debug connect -- \
662+ --symbol-path target/x86_64-fuchsia/debug
663+ ```
664+
665+ * ` --symbol-path ` gets required symbol paths, which are
666+ necessary for stepping through your program.
667+
668+ The "[ displaying source code in ` zxdb ` ] ( #displaying-source-code-in-zxdb ) " section describes how you can
669+ display Rust and/or Fuchsia source code in your debugging session.
670+
671+ ### Using ` zxdb `
672+
673+ Once launched, you will be presented with the window:
674+
675+ ``` sh
676+ Connecting (use " disconnect" to cancel)...
677+ Connected successfully.
678+ 👉 To get started, try " status" or " help" .
679+ [zxdb]
680+ ```
681+
682+ To attach to our program, we can run:
683+
684+ ``` sh
685+ [zxdb] attach hello_fuchsia
686+ ```
687+
688+ ** Expected output**
689+ ``` sh
690+ Waiting for process matching " hello_fuchsia" .
691+ Type " filter" to see the current filters.
692+ ```
693+
694+ Next, we can create a breakpoint at main using "b main":
695+
696+ ``` sh
697+ [zxdb] b main
698+ ```
699+
700+ ** Expected output**
701+ ``` sh
702+ Created Breakpoint 1 @ main
703+ ```
704+
705+ Finally, we can re-run the "hello_fuchsia" component from our original
706+ terminal:
707+
708+ ``` sh
709+ ${SDK_PATH} /tools/${ARCH} /ffx component run \
710+ --recreate \
711+ fuchsia-pkg://hello-fuchsia/hello_fuchsia_manifest#meta/hello_fuchsia.cm
712+ ```
713+
714+ Once our component is running, our ` zxdb ` window will stop execution
715+ in our main as desired:
716+
717+ ** Expected output**
718+ ``` txt
719+ Breakpoint 1 now matching 1 addrs for main
720+ 🛑 on bp 1 hello_fuchsia::main() • main.rs:2
721+ 1 fn main() {
722+ ▶ 2 println!("Hello Fuchsia!");
723+ 3 }
724+ 4
725+ [zxdb]
726+ ```
727+
728+ ` zxdb ` has similar commands to other debuggers like [ gdb] .
729+ To list the available commands, run "help" in the
730+ ` zxdb ` window or visit [ the zxdb documentation] .
731+
732+ ``` sh
733+ [zxdb] help
734+ ```
735+
736+ ** Expected output**
737+ ``` sh
738+ Help!
739+
740+ Type " help <command>" for command-specific help.
741+
742+ Other help topics (see " help <topic>" )
743+ ...
744+ ```
745+
746+ ### Displaying source code in ` zxdb `
747+
748+ By default, the debugger will not be able to display
749+ source code while debugging. For our user code, we displayed
750+ source code by pointing our debugger to our debug binary via
751+ the ` --symbol-path ` arg. To display library source code in
752+ the debugger, you must provide paths to the source using
753+ ` --build-dir ` . For example, to display the Rust and Fuchsia
754+ source code:
755+
756+ ``` sh
757+ ${SDK_PATH} /tools/${ARCH} /ffx debug connect -- \
758+ --symbol-path target/x86_64-fuchsia/debug \
759+ --build-dir ${RUST_SRC_PATH} /rust \
760+ --build-dir ${FUCHSIA_SRC_PATH} /fuchsia/out/default
761+ ```
762+
763+ * ` --build-dir ` links against source code paths, which
764+ are not strictly necessary for debugging, but is a nice-to-have
765+ for displaying source code in ` zxdb ` .
766+
767+ Linking to a Fuchsia checkout can help with debugging Fuchsia libraries,
768+ such as [ fdio] .
769+
641770[ Fuchsia team ] : https://team-api.infra.rust-lang.org/v1/teams/fuchsia.json
642771[ Fuchsia ] : https://fuchsia.dev/
643772[ source tree ] : https://fuchsia.dev/fuchsia-src/get-started/learn/build
@@ -648,3 +777,7 @@ underway to enable it.
648777[ reference for the file format ] : https://fuchsia.dev/reference/cml
649778[ Fuchsia devsite ] : https://fuchsia.dev/reference/cml
650779[ not currently supported ] : https://fxbug.dev/105393
780+ [ zxdb ] : https://fuchsia.dev/fuchsia-src/development/debugger
781+ [ gdb ] : https://www.sourceware.org/gdb/
782+ [ the zxdb documentation ] : https://fuchsia.dev/fuchsia-src/development/debugger
783+ [ fdio ] : https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/lib/fdio/
0 commit comments