Using gdb to skip irrelevant failure while debugging at remote-site

Many a times in big team projects, you have many errors(say X) in code which don't happen to be your current focus(say A).
Normally, developers add there code in various option exactly for this purpose to suppress irrelevant but failing code(X) to isolate these errors during debugging.
But many a time it happens that failing-code is not under any option or you can not use that option (due to any reason).

And the situation worsens further when you are debugging a issue via remote-session (which are usually very slow). And it would take lot of time for you to edit the faulty-code and upload the executable at customer end again for debugging.

In such scenarios, you can use following trick using gdb to isolate & suppress errors

Lets say you have following code

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>


int main()
{
    int i = 0;
    //....
    //....
    //....
    {    // line 12
        i = 9 ;
        assert(i>9);     // code which has irrelevant error for now.
    }
    //....     // line 16
    //....
    //....
    //....
    //....

    for(i = 0 ; i=10;i++){
        printf("%d",i);     // code with error you are concerned about
    }
}


And you need to supress error due to code on line 12 to 15.

Here are the steps :
1. Start the gdb for debugging session
     gdb finderror               // for our example
2. Set breakpoint on code, you wish to suppress.
     b main.c:12                 // this sets the breakpoint, say 1
3. Add "jump" action on break-point
     command 1                // this "command" allows you to automate set of actions everytime breakpoint 1 is hit
     > jump 16                   // first action defined is to jump to line 16, without executing code between line 12 to 15
     > print "skipping error-code"   // second action to inform you that you have skipped the error-code
     > end                          // end the list of action to perform for break-point 1


By adopting above method, you can skip time-consuming process of editing code to suppress irrelevant errors and uploading the build again for remote-debugging.
Please feel free to ask any question related to this in comment section, and I would get back to you as soon as possible.

comments powered by Disqus