devoured elysium
devoured elysium

Reputation: 105177

Debugging recursive methods in Eclipse -- any clever way to avoid getting trapped into ever more nested calls?

A common problem I face when debugging recursive methods is that I can't avoid getting trapped into going deeper and deeper into the stack when I want to debug a given piece of code. The only way to avoid getting trapped is to manually disable the BP and then set up it again after the block of code I'm interested in has been passed.

enter image description here

In the above picture, I just want to do a little stroll over the loop's variables for each iteration, seeing if they're behaving as they should and if all's fine and dandy, but I'm currently only getting the first iteration of each call to combinations!

Any clever ideas to get around this?

Upvotes: 5

Views: 916

Answers (2)

Vallabh Patade
Vallabh Patade

Reputation: 5110

Try to use conditional breakpoint if you want to hit the breakpoint only for some condition or for ith recursion depth. If you want to unwind recursion, after some of your testing/validation, while debugging you can change the value of the base condition variable from eclipse debugger.

Upvotes: 2

peterk
peterk

Reputation: 5444

If you have the ability to modify the recursive method I often do this sort of thing.

int combinations(int, a1, int a2) {
    return(combinationsImpl(a1,a2,0));
}

int combinationsImpl(int, a1, int a2, int level) {
    if(done) {
        // on done 
        return(value);
    }
    // you can use level to do conditional break points, prints etc
    // you can save the value when it crashes or throws an exception etc
    // if you need to see variables in the stack log the level and the variables
    // to console or a file and then see on what level values become anomalous etc. 
    return(combinationsImpl(a1,a2,++level));
}

Upvotes: 0

Related Questions