简体   繁体   中英

How to set conditional breakpoint on return statement globally?

I have a code full of functions like:

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

On some step of execution some callee can return false , and false propagates through all the callers. It is hard to write error messages at the moment (code is rapidly changed). During debugging it is excessive to have error mesages before every return false; .

Is it possible to set conditional (condition: say, function return false ) breakpoint on return statment globally, using GDB ?

On some step of execution some callee can return false

As I understand, you want to find the first function which returned false inside f_i() . You can use reverse debugging for this. You can:

  1. finish current frame execution

    (gdb) fin

  2. step backwards, if return value is false

    (gdb) reverse-step

  3. if you need, you can continue to go backwards, deeper into false propagation calls

    (gdb) reverse-fin
    (gdb) reverse-step

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM