Search code examples
functiondebuggingtestingreturngdb

How to use GDB to check where a function calls return?


I have a function called test_linked_list() that tests a data structure using a series of if statements. If a test fails it calls return 0.

// ie.
test_linked_list() {
    if(!insert_end(l,10)) 
        return 0;
    // ... more tests
}

I want to know which test fails. Instead of setting breakpoints manually in gdb and using next to see which return 0 is called, is there another way? For example, a GDB script?


Solution

  • is there another way?

    One simple way to use the UNIX convention of return 0 on success, and return 1, return 2, etc. for different failures.

    Note that compilers ~always use a single return for each function; there aren't "which return" -- they are all the same once the function is compiled.