Skip to content

Commit 1e6247e

Browse files
bors[bot]ubx-blem
andauthored
Merge #239
239: QEMU debugging updates r=adamgreig a=blelem Addressing a few issues: Fixes #237, Fixes #234, Fixes #217 The biggest issue this PR is addressing is correcting the "debugging QEMU with GDB" section that really didn't work with latest ARM toolchain (on my setup), because of two things: - gdb didn't map the rust libcore functions properly. For example, after connecting to a QEMU instance, it did not show the current PC to be on the Reset function, but some random method. - gdb didn't step over (`next`), after breaking at `main`. It just ran to the end of the program. The user is now instructed to disable the LDD and use the GNU ARM linker instead, which addresses the issues with the mapping. And instead of doing a simple, `break main` which did not allow the user to step over after hitting the breakpoint, the user is now guided to do a more complicated, `break hello::__cortex_m_rt_main`. After hitting that breakpoint, the `next` and `step` commands are working as one would expect. I am no expert in embedded rust, so the proposed solution may not be optimal, but I think they are better than the current instructions provided by the book which are not working at all on my setup. (Windows 10, with latest versions of QEMU, ARM toolchain, Rust) Co-authored-by: Berthier Lemieux <berthier.lemieux@u-blox.com>
2 parents 366c50a + 9f59ab8 commit 1e6247e

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

src/intro/install/verify.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ST-LINK header is circled in red.
1717
Now run the following command:
1818

1919
``` console
20-
$ openocd -f interface/stlink-v2-1.cfg -f target/stm32f3x.cfg
20+
$ openocd -f interface/stlink.cfg -f target/stm32f3x.cfg
2121
```
2222

2323
You should get the following output and the program should block the console:

src/intro/install/windows.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ GNU gdb (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 8.1.0.20180315-
1616

1717
## OpenOCD
1818

19-
There's no official binary release of OpenOCD for Windows but there are unofficial releases
20-
available [here][openocd]. Grab the 0.10.x zipfile and extract it somewhere on your drive (I
21-
recommend `C:\OpenOCD` but with the drive letter that makes sense to you) then update your `%PATH%`
22-
environment variable to include the following path: `C:\OpenOCD\bin` (or the path that you used
23-
before).
19+
There's no official binary release of OpenOCD for Windows but if you're not in the mood to compile
20+
it yourself, the xPack project provides a binary distribution, [here][openocd]. Follow the
21+
provided installation instructions. Then update your `%PATH%` environment variable to
22+
include the path where the binaries were installed. (`C:\Users\USERNAME\AppData\Roaming\xPacks\@xpack-dev-tools\openocd\0.10.0-13.1\.content\bin\`,
23+
if you've been using the easy install)
2424

25-
[openocd]: https://github.com/gnu-mcu-eclipse/openocd/releases
25+
[openocd]: https://xpack.github.io/openocd/
2626

2727
Verify that OpenOCD is in your `%PATH%` with:
2828

src/start/qemu.md

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ substitutions.
1616
## Creating a non standard Rust program
1717

1818
We'll use the [`cortex-m-quickstart`] project template to generate a new
19-
project from it.
19+
project from it. The created project will contain a barebone application: a good
20+
starting point for a new embedded rust application. In addition, the project will
21+
contain an `examples` directory, with several separate applications, highlighting
22+
some of the key embedded rust functionality.
2023

2124
[`cortex-m-quickstart`]: https://github.com/rust-embedded/cortex-m-quickstart
2225

@@ -151,8 +154,14 @@ target = "thumbv7m-none-eabi" # Cortex-M3
151154
```
152155

153156
To cross compile for the Cortex-M3 architecture we have to use
154-
`thumbv7m-none-eabi`. This compilation target has been set as the default so the
155-
two commands below do the same:
157+
`thumbv7m-none-eabi`. That target is not automatically installed when installing
158+
the Rust toolchain, it would now be a good time to add that target to the toolchain,
159+
if you haven't done it yet:
160+
``` console
161+
$ rustup target add thumbv7m-none-eabi
162+
```
163+
Since the `thumbv7m-none-eabi` compilation target has been set as the default in
164+
your `.cargo/config` file, the two commands below do the same:
156165

157166
```console
158167
cargo build --target thumbv7m-none-eabi
@@ -201,8 +210,6 @@ ELF Header:
201210

202211
`cargo-size` can print the size of the linker sections of the binary.
203212

204-
> **NOTE** this output assumes that rust-embedded/cortex-m-rt#111 has been
205-
> merged
206213

207214
```console
208215
cargo size --bin app --release -- -A
@@ -480,20 +487,45 @@ Reset () at $REGISTRY/cortex-m-rt-0.6.1/src/lib.rs:473
480487
473 pub unsafe extern "C" fn Reset() -> ! {
481488
```
482489

490+
483491
You'll see that the process is halted and that the program counter is pointing
484492
to a function named `Reset`. That is the reset handler: what Cortex-M cores
485493
execute upon booting.
486494

495+
> Note that on some setup, instead of displaying the line `Reset () at $REGISTRY/cortex-m-rt-0.6.1/src/lib.rs:473` as shown above, gdb may print some warnings like :
496+
>
497+
>`core::num::bignum::Big32x40::mul_small () at src/libcore/num/bignum.rs:254`
498+
> ` src/libcore/num/bignum.rs: No such file or directory.`
499+
>
500+
> That's a known glitch. You can safely ignore those warnings, you're most likely at Reset().
501+
502+
487503
This reset handler will eventually call our main function. Let's skip all the
488-
way there using a breakpoint and the `continue` command:
504+
way there using a breakpoint and the `continue` command. To set the breakpoint, let's first take a look where we would like to break in our code, with the `list` command.
489505

490506
```console
491-
break main
507+
list main
492508
```
509+
This will show the source code, from the file examples/hello.rs.
493510

494511
```text
495-
Breakpoint 1 at 0x400: file examples/panic.rs, line 29.
512+
6 extern crate panic_halt;
513+
7
514+
8 use cortex_m_rt::entry;
515+
9 use cortex_m_semihosting::{debug, hprintln};
516+
10
517+
11 #[entry]
518+
12 fn main() -> ! {
519+
13 hprintln!("Hello, world!").unwrap();
520+
14
521+
15 // exit QEMU
522+
```
523+
We would like to add a breakpoint just before the "Hello, world!", which is on line 13. We do that with the `break` command:
524+
525+
```console
526+
break 13
496527
```
528+
We can now instruct gdb to run up to our main function, with the `continue` command:
497529

498530
```console
499531
continue
@@ -502,8 +534,8 @@ continue
502534
```text
503535
Continuing.
504536
505-
Breakpoint 1, main () at examples/hello.rs:17
506-
17 let mut stdout = hio::hstdout().unwrap();
537+
Breakpoint 1, hello::__cortex_m_rt_main () at examples\hello.rs:13
538+
13 hprintln!("Hello, world!").unwrap();
507539
```
508540

509541
We are now close to the code that prints "Hello, world!". Let's move forward
@@ -514,15 +546,7 @@ next
514546
```
515547

516548
```text
517-
18 writeln!(stdout, "Hello, world!").unwrap();
518-
```
519-
520-
```console
521-
next
522-
```
523-
524-
```text
525-
20 debug::exit(debug::EXIT_SUCCESS);
549+
16 debug::exit(debug::EXIT_SUCCESS);
526550
```
527551

528552
At this point you should see "Hello, world!" printed on the terminal that's

0 commit comments

Comments
 (0)