0

I have a code snippet similar to this :

int test( /* some arguments */)
{
    ret = func(/* some arguments */)
    if (ret < 0) 
    {
       /* do this */
    }

    /* do this */

    return ret;
}

the function func is returning -1 for some erroneous condition inside the function. This erroneous condition occurs once in 100 times the test function is called - so I put breakpoint in if (ret < 0) line. Now I want to debug what's going on inside the function func(). How do I do it when the breakpoint is hit in test function at the said line.

2
  • 1
    Can you move your breakpoint(s) to every error branch in func instead? Commented Dec 27, 2012 at 9:23
  • Another fine example why a function shall only have one exit point. Commented Dec 27, 2012 at 17:19

2 Answers 2

2

I would put a break point at

return -1;

within the function itself. In the way you are doing, the stack frame of the function would have been destroyed already. You COULD run the function again with the same arguements if you can move the code pointer, but if the function has side effects, it may not react the same way. I am not sure how to do it though, perhaps it needs the jump command.

Sign up to request clarification or add additional context in comments.

2 Comments

there are may such returns in the function func()
@shraddha as long as you can see the code of the function, and you are unable to rerun the function with the same arguements deterministically, I see no other option.
0

Is the behaviour deterministic? If so, breakpoint hit-counters are good for this. You can set a very large count breakpoint somewhere before the error is generated, break also on the error being returned, look at the counter, and then change the count to break at count-1. Then you can then debug the error as it occurs, and the breakpoint can be anywhere in the code, not just at the exact point or error.

Conditional breakpoints are underused...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.