You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/start/qemu.md
+30-24Lines changed: 30 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -440,26 +440,6 @@ also running the embedded program.
440
440
441
441
In this section we'll use the `hello` example we already compiled.
442
442
443
-
Before getting started remotely debugging our app running in QEMU with GDB,
444
-
let's modify our app configuration `.cargo/config`, to enable the GNU ARM linker:
445
-
446
-
```toml
447
-
...
448
-
rustflags = [
449
-
# LLD (shipped with the Rust toolchain) is used as the default linker
450
-
#"-C", "link-arg=-Tlink.x", <--- Comment this line
451
-
452
-
# if you run into problems with LLD switch to the GNU linker by commenting out
453
-
# this line
454
-
"-C", "linker=arm-none-eabi-ld", #<--- Uncomment this line
455
-
```
456
-
We do that, as the default linker (LLD) doesn't always play nice with the GNU ARM GDB.
457
-
Rebuild the application.
458
-
459
-
```console
460
-
cargo build --example hello
461
-
```
462
-
463
443
The first debugging step is to launch QEMU in debugging mode:
464
444
465
445
```console
@@ -507,20 +487,45 @@ Reset () at $REGISTRY/cortex-m-rt-0.6.1/src/lib.rs:473
507
487
473 pub unsafe extern "C" fn Reset() -> ! {
508
488
```
509
489
490
+
510
491
You'll see that the process is halted and that the program counter is pointing
511
492
to a function named `Reset`. That is the reset handler: what Cortex-M cores
512
493
execute upon booting.
513
494
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
+
514
503
This reset handler will eventually call our main function. Let's skip all the
515
-
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.
516
505
517
506
```console
518
-
break hello::__cortex_m_rt_main
507
+
list main
519
508
```
509
+
This will show the source code, from the file examples/hello.rs.
520
510
521
511
```text
522
-
Breakpoint 1 at 0x410: file examples\hello.rs, line 13.
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
523
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
527
+
```
528
+
We can now instruct gdb to run up to our main function, with the `continue` command:
524
529
525
530
```console
526
531
continue
@@ -539,8 +544,9 @@ using the `next` command.
539
544
```console
540
545
next
541
546
```
547
+
542
548
```text
543
-
20 debug::exit(debug::EXIT_SUCCESS);
549
+
16 debug::exit(debug::EXIT_SUCCESS);
544
550
```
545
551
546
552
At this point you should see "Hello, world!" printed on the terminal that's
0 commit comments