0

Is it possible to view the value of a variable from a higher stack level when hitting a breakpoint in eclipse? IE say we have the following functions -

void foo(){
  for(int i=0;i<100;i++){
    bar();
  }
}

void bar(){
  //breakpoint here
}

if I put a breakpoint in bar, can I see the value of i which should be 1 stack level above me without manually clicking on the stack level?

David says Reinstate Monica
  • 19,209
  • 22
  • 79
  • 122
  • pass `i` as parameter in method. – bNd Jan 12 '15 at 03:07
  • @bmthaker I could do that, but I really dont want to. It would be much simpler if I could just watch `i` it instead of changing my program every time I debug it. Also this is basically impossible if `bar` is called in a ton of other places – David says Reinstate Monica Jan 12 '15 at 03:08
  • You need to put breakpoint on for loop or create `i` as `public` variable instead of local variable. If public variable than you can see the `i` value from anywhere your code as it is local variable you can't. – bNd Jan 12 '15 at 03:10
  • @bmthaker I know there are plenty of ways I can modify my code to suit my needs. The point is, I want to do this **without** modifying my code. Modifying code just for debugging is generally a bad idea. – David says Reinstate Monica Jan 12 '15 at 03:12
  • No, I am not downvote this post. – bNd Jan 12 '15 at 05:59

1 Answers1

1

Generally you can watch any variable by right clicking on the variable and select "Watch" option. But this option will give "error during evaluation" when execution go out of scope in case of local variables. There are some workaround discussed in this post to generate rt.jar with debugging information enabled. I have not tried it personally but it may help you in this scenario. Good luck.

Community
  • 1
  • 1
kamoor
  • 2,909
  • 2
  • 19
  • 34