Conditional breakpoints with GDB

Hello Rust Community,

long stroy short: I try to set a conditional breakpoint with a Result-variable, which doesn't seem to be working.

Some context: my goal is to automatically run integration tests on an embedded micro-controller (currently STM32 Nucleo-L476, so --target thumbv7m-none-eabi), but I don't think, that this is hugely important for the problem described below. The idea was to automatically run test-cases as binaries, that get loaded and run on the target hardware. By setting breakpoints on some key-functions, the tests are classified as passed/failed. And here lies the problem:


use cortex_m_semihosting::debug::{EXIT_FAILURE, EXIT_SUCCESS};

fn main() -> ! {
    // panic!("test-panic to see the GDB outcome");
    panic!("semi-hosting is not enabled");

fn test_failure(_: &core::panic::PanicInfo) -> ! {
    loop {}

The function to break on is cortex_m_semihosting::debug::exit(status). Depending on the value of status I want to:

  • quit 1 if status is EXIT_FAILURE (which has the value of Result::<(), ()>::Err(())).
  • else exit with 0, which is the default anyway, so no special quit 0 is required here.

Normally this should be easy enough with something like this as a GDB-script (this is the whole file openocd.gdb, but lines 9ff are relevant):

target extended-remote :3333

set print asm-demangle on
monitor arm semihosting enable

monitor reset init

# the next line is not working. This should break only if 
break cortex_m_semihosting::debug::exit if status.is_err()
commands 1
quit 1


With a running Openocd-target, this could be invoked with

$ arm-none-eabi-gdb -x openocd.gdb target/thumbv7m-none-eabi/debug/deps/TEST_NAME

Unfortunately this does not work: GDB answers with the following output:

Error in testing breakpoint condition:
Structure has no component named is_err.

It seems like the function resolution or calling it does not work. But I don't see the reason described in the GDB docs. Maybe it's related to the generic type Result<T, E>. Maybe I'm just blind :wink:

So, do you know the reason that this doesn't work? Or do you have an alternative suggestion?
Thanks in advance!