Embedded Rust Discovery book GDB problems

I'm on section 5.4 of the Embedded Rust Discovery book. I've gotten the code to compile and load into the discovery board. When I get to 'break main', gdb breaks at line 7, #[entry]', not line 9, like the example in the book.

Typing continue works, but again it breaks at line 7 not 9. But when I type 'next', GDB hangs.

If I hit control-c, I get the following:
(gdb) next
^C
Program received signal SIGINT, Interrupt.
0x080039ac in HardFault_ (ef=0x10001d88) at /Users/jprain/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.12/src/lib.rs:555
555 atomic::compiler_fence(Ordering::SeqCst);

I'm using a Mac running 10.15.6.

The code I'm trying to use is the same as the book, but it's here:

#![deny(unsafe_code)]
#![no_main]
#![no_std]

use aux5::{entry, prelude::*, Delay, Leds};
 
#[entry]
fn main() -> ! {
    let (mut delay, mut leds): (Delay, Leds) = aux5::init();

    let half_period = 500_u16;

    loop {
        leds[0].on();
        delay.delay_ms(half_period);

        leds[0].off();
        delay.delay_ms(half_period);
    }
}

Thanks!

So I've now set this up on both Ubuntu and MacOS and I'm getting the same problem on both.

I've found a work around though. Instead of typing 'break main' into gdb. I just type break and the line number. So in this case it would be 'break 9'. Then I can keep going with step and next the way the examples show.

I would still like to know why break main doesn't break on the main function the way it shows in the examples. Do I have something setup wrong? Has GDB changed and break main no longer works for embedded?

Glancing at the source, it looks like the #[entry] macro rewrites your main function into a modified version with a name like __cortex_m_rt_main, and then emits its own separate entry point function.

Really... That code is in the official rust docs.

https://docs.rust-embedded.org/discovery/05-led-roulette/the-led-and-delay-abstractions.html

Perhaps the behavior of the macro changed and the book hasn't been updated to reflect it, yet. It looks like the problem has been reported by other readers, too:

https://github.com/rust-embedded/discovery/issues/221

https://github.com/rust-embedded/discovery/issues/258

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.