How do I set a conditional breakpoint on a return statement globally?

I have code full of features like:

bool f_i() 
    if (!f_0()) {
        return false;
    if (!f_1()) {
        return false;
    // ...
    if (!f_n()) {
        return false;
    return true;
// etc...


At some stage of execution, some call can return false

, but false

propagates through all callers. It is difficult to write error messages at the moment (code changes quickly). During debugging, it is redundant to have error messages in front of each one return false;


Is it possible to set a conditional (condition: say a return function false

) breakpoint on a return

statment globally using GDB



source to share

1 answer

At some stage of execution, some command may return false

As I understand it, you want to find the first function that returned false

inside f_i()

. You can use reverse debugging for this . You can:

  • end execution of the current frame

    (gdb) fin

  • step back if return value false

    (gdb) reverse step

  • if you need to, you can keep going backwards, deeper into the false

    challenges of the spread

    (gdb) reverse-fin
    (gdb) reverse step



All Articles