Search code examples
debugginggdbstm32f4openocd

GDB and OpenOCD: output all executed functions


Currently, I debugging STM32F4 MCU (Nucleo board) and now my task is to know all functions that have been called one way or another during execution flow. Of course with OpenOCD and GDB I can already see backtrace when the target is paused but actually, it cannot reflects full history of firmware' running. Also, there are some hardware ISRs that I think doesn't have "parents" in terms of C call stack.

Simplified example. Suppose we have a source like this:

#include "math.h"

ISR tick_10ms() {
    asm("nope");
}

void foo(double x) {
    double y = sin(x);
}

int bar(int a, int b, int c) {
    foo((double)(a-b+c));
    return 0;
}

void main() {
    foo(3.14);
    int z = bar(1, 2, 3);

    while (1) {}
}

and when we program MCU with it I want to see something like (in real-time or on halt – doesn't matter):

main()
  foo(3.14)
    sin(3.14)
  bar(1, 2, 3)
    foo(2.0)
      sin(2.0)
tick_10ms()
tick_10ms()
tick_10ms()
...

So is it possible in any way (or at least similar)?


Solution

  • Try starting your program "under" gdb.

    Then say something like:

    rbreak .
    commands
    frame
    cont
    end
    

    This should put a breakpoint to all functions (see rbreak on how to selectively put a breakpoint on function in certain modules), and run frame+continue on each hit.