Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Related question:

http://programmers.stackexchange.com/questions/225243/is-printing-to-console-stdout-a-good-debugging-strategy

We have something like this

private int myFunction(int i)

{
    //line a
    someCode(); 
    //line b
    someMoreCode();
    //line c
    return v; 
}

private void myMain()
{
    for (int i = 0; i<10; i++)
    {

     myfunction(i); 
    }
}

Now something's going wrong in myFunction, let's say for when i = 6.

The way I see it, I have two options:

  • I can add a breakpoint at line a, run the debugger and step return till i=6, and look at the values at each line.
  • I can go in a put console/stdout statements at lines a, b, c, and get a complete listing/trace of how the variable that I'm interested in are changing.

The problem with this second solution, is that I'm then constantly pasting/typing in console statements and then going through an removing them.

What would be a lot easier, is being able to click in breakpoints, and then telling it, which variables I'm interested in, and have the debugger print out those variables, as well as the line number to a log.

Is this possible?

share|improve this question

1 Answer 1

You can add code to a breakpoint to decide when it becomes active.

Right click on the breakpoint and select Breakpoint Properties, select the Conditional check box and you will be able to type code - something like:

return i == 6;

to stop when i is 6.

More details in Java Debugging with Eclipse

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.