Skip to content

Commit fffb7f2

Browse files
authored
Rollup merge of rust-lang#101340 - andrewpollack:fuchsia-zxdb-docs, r=tmandry
Adding Fuchsia zxdb debugging walkthrough to docs Adding `zxdb` docs to walkthrough to show debugging steps
2 parents 95a992a + 2b8886f commit fffb7f2

File tree

1 file changed

+135
-2
lines changed

1 file changed

+135
-2
lines changed

src/doc/rustc/src/platform-support/fuchsia.md

+135-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ authoritative if this occurs. Instead of pinging individual members, use
4242
1. [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

142147
In 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

259264
Putting it all together:
@@ -639,6 +644,130 @@ available on the [Fuchsia devsite].
639644
Running the Rust test suite on Fuchsia is [not currently supported], but work is
640645
underway to enable it.
641646

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

0 commit comments

Comments
 (0)