在使用ARM GDB调试STM32的Rust固件时,回溯记录中充满重复条目 我在干什么

在使用ARM GDB调试STM32的Rust固件时,回溯记录中充满重复条目 我在干什么,rust,gdb,embedded,stm32,cortex-m3,Rust,Gdb,Embedded,Stm32,Cortex M3,我正在尝试使用Rust为STM32F103板制作固件,并使用GDB进行调试 我的项目或多或少遵循cargo板条箱的示例,包括cargo.toml。一个例外是我使用cortex-m-semihosting和panic-semihosting板条箱 编辑:src/main.rs: #![拒绝(不安全代码)] #![无标准] #![无主] 使用紧急停止作为uu; 使用cortex_m_rt::entry; 使用stm32f1x_hal::{ 序曲::*, 派克靴, }; 使用嵌入式硬件::数字::v2

我正在尝试使用Rust为STM32F103板制作固件,并使用GDB进行调试

我的项目或多或少遵循cargo板条箱的示例,包括cargo.toml。一个例外是我使用
cortex-m-semihosting
panic-semihosting
板条箱

编辑
src/main.rs

#![拒绝(不安全代码)]
#![无标准]
#![无主]
使用紧急停止作为uu;
使用cortex_m_rt::entry;
使用stm32f1x_hal::{
序曲::*,
派克靴,
};
使用嵌入式硬件::数字::v2::输出引脚;
#[条目]
fn main()->!{
让dp=pac::外围设备::take().unwrap();
让mut rcc=dp.rcc.constraint();
让mut gpioc=dp.gpioc.split(&mut rcc.apb2);
让mut led=gpioc.pc13.进入推拉输出(&mut gpioc.crh);
led。设置为低();
循环{}
}
我的
.cargo/config
如下所示:

[target.thumbv7m-none-eabi]
runner = 'arm-none-eabi-gdb'

rustflags = [
  "-C", "link-arg=-Tlink.x", # also tried old way with gcc linker, no difference
]

[build]
target = "thumbv7m-none-eabi"
Cargo.toml

[package]
name = "blue-pill-rust"
version = "0.1.0"
edition = "2018"

[[bin]]
name = "blue-pill-rust"
test = false
bench = false

[profile.release]
opt-level = "s"
debug = true

[dependencies.stm32f1xx-hal]
version = "0.5.3"
features = ["stm32f103", "rt", "medium"]

[dependencies.cortex-m]
version = "0.6.2"

[dependencies.cortex-m-rt]
version = "0.6.12"

[dependencies]
panic-halt = "0.2.0"
发生了什么 我直接使用GDB来闪存固件(BlackMagicProbe调试器的属性),但OpenOCD也出现了相同的结果:

$ arm-none-eabi-gdb
GNU gdb (GDB) 8.3.1
...

(gdb) target extended-remote /dev/ttyBmpGdb
Remote debugging using /dev/ttyBmpGdb
(gdb) attach 1
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0800448c in ?? ()
(gdb) file target/thumbv7m-none-eabi/release/blue-pill-rust
Reading symbols from target/thumbv7m-none-eabi/release/blue-pill-rust...
(gdb) load
...
(gdb) start
Temporary breakpoint 1 at 0x8000130: file src/main.rs, line 27.
Starting program: /media/data/projects/rust/blue-pill-rust/target/thumbv7m-none-eabi/release/blue-pill-rust
Note: automatically using hardware breakpoints for read-only addresses.

Temporary breakpoint 1, main () at src/main.rs:27
27      #[entry]
(gdb) step
blue_pill_rust::__cortex_m_rt_main () at src/main.rs:33
33          hprintln!("hello, world!").unwrap();
(gdb) next
hello, world!
warning: (Internal error: pc 0x80004d2 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x80004d2 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x80004d2 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x80004d2 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x80004d2 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x80004d2 in read in psymtab, but not in symtab.)

36          let cp = cortex_m::Peripherals::take().unwrap();
(gdb)
每次我下一步执行
next
,其他代码行都会重复相同的问题,所以ARM半宿主(它打印“Hello,World!”)应该不会有问题

我尝试在Cargo.toml中禁用链接时间优化(
lto=false
)。这似乎解决了这个错误的问题,但问题的主要问题仍然存在

无论如何,如果我在
next
ing几次之后检查
backtrace
,我会得到以下图片:

(gdb) bt
...
#407 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#408 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#409 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#410 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#411 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#412 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#413 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
#414 0x08000152 in blue_pill_rust::__cortex_m_rt_main () at src/main.rs:31
...
这超过了1000个条目

我尝试在Cargo.toml中将0级优化替换为
“s”
(同时禁用lto)。这导致了类似的问题,但更详细一点:

...
#1576 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1577 0x080001e2 in cortex_m::interrupt::enable ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:49
#1578 cortex_m::interrupt::free (f=...)
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:75
#1579 cortex_m::peripheral::Peripherals::take ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/peripheral/mod.rs:152
#1580 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1581 0x080001e2 in cortex_m::interrupt::enable ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:49
#1582 cortex_m::interrupt::free (f=...)
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:75
#1583 cortex_m::peripheral::Peripherals::take ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/peripheral/mod.rs:152
#1584 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1585 0x080001e2 in cortex_m::interrupt::enable ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:49
#1586 cortex_m::interrupt::free (f=...)
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:75
#1587 cortex_m::peripheral::Peripherals::take ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/peripheral/mod.rs:152
#1588 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1589 0x080001e2 in cortex_m::interrupt::enable ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:49
#1590 cortex_m::interrupt::free (f=...)
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:75
#1591 cortex_m::peripheral::Peripherals::take ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/peripheral/mod.rs:152
#1592 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1593 0x080001e2 in cortex_m::interrupt::enable ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:49
#1594 cortex_m::interrupt::free (f=...)
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:75
#1595 cortex_m::peripheral::Peripherals::take ()
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/peripheral/mod.rs:152
#1596 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1597 0x080001e2 in cortex_m::interrupt::enable ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:49
#1598 cortex_m::interrupt::free (f=...)
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/interrupt.rs:75
#1599 cortex_m::peripheral::Peripherals::take ()
    at /home/superprower/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/peripheral/mod.rs:152
#1600 blue_pill_rust::__cortex_m_rt_main () at src/main.rs:34
#1601 0x080001e2 in cortex_m::interrupt::enable ()
...
并且是最新的


如果您能帮助您排除故障,我们将不胜感激。

为什么您认为它们是重复条目而不是实际的呼叫跟踪?请张贴来源。请发布一篇文章,以便其他人能够重现问题,请发布
src/main.rs:27
的来源。你的问题是什么?当“bug”发生时,您是否尝试单步通过调试器找到确切的指令?您是否尝试过单步执行代码?@KamilCuk:它们不是重复条目,您是正确的。然而,我认为一个程序在一个步骤中产生超过一千个元素的堆栈跟踪是不寻常的,尤其是包含该步骤中发生的函数的记录。例如,我根据链接和发布的示例,将代码简化为仅启用LED。
$ arm-none-eabi-gdb -v
GNU gdb (GDB) 8.3.1

$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/9.2.0/lto-wrapper
Target: arm-none-eabi
Configured with: /build/arm-none-eabi-gcc/src/gcc-9.2.0/configure --target=arm-none-eabi --prefix=/usr --with-sysroot=/usr/arm-none-eabi --with-native-system-header-dir=/include --libexecdir=/usr/lib --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-system-zlib --with-newlib --with-headers=/usr/arm-none-eabi/include --with-python-dir=share/gcc-arm-none-eabi --with-gmp --with-mpfr --with-mpc --with-isl --with-libelf --enable-gnu-indirect-function --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='Arch Repository' --with-bugurl=https://bugs.archlinux.org/ --with-multilib-list=rmprofile
Thread model: single
gcc version 9.2.0 (Arch Repository)