1

I am debugging my application in Eclipse. Finally I reached a breakpoint in a state which will trigger the bug in the next line of code.

Due to a breaking change in the class, the most likely solution would be to remove that line of code.

Of course I could do that now: remove the line, recompile and reproduce the sitatuation again. However, since it is hard to reproduce the bug, can I simply skip the execution of that line of code now? E.g. can I set the "instruction pointer" in Eclipse?

Things I did:

  • I don't want F6 (Step Over), since that will execute the line.
  • Also "Run to cursor" is not what I want, since that will also execute the problematic line.
  • Comment out the code according to How to modify Java code during debugging, but that re-executed the method, thus changing the state
  • I have tried to find an answer on this question, but I don't only want to run a single line of code but all the rest.
  • This question only has answers which run code in between.
  • The drop to frame feature is also not helpful.

The linked questions are from 2009 to 2013, so I hope to get new answers.

I'm using Eclipse 4.5.1 (Mars.1), latest official version at the time of asking.

Community
  • 1
  • 1
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

1 Answers1

2

If you want execute the line after the one you want to skip. When you reach the line before the line to be skipped, select the code and right click, choose Inspect from menu. This will execute the selected code and provide you the result in a popup.

If you know the lines that have to be skipped. you can put them in an if statement and change the value of the boolean in the variables view in eclipse. And then proceed to other lines. (using code from comments)

  if (skipped){
    //yourcode
    };

It is also possible to create expressions in eclipse.

One thing which I missed out was eclipse also supports hot code swap. You can comment out the line and save it. It will drop the debugger control back to the starting of the method. Hot deploy has supported the code changes in the method implementation only. If you add a new class or a new method, restart is still required. If you have the server in eclispe, here is how you can make that possible http://www.mkyong.com/eclipse/how-to-configure-hot-deploy-in-eclipse/

awsome
  • 2,143
  • 2
  • 23
  • 41
  • I am using that method and it is usefull. Just create if(skipped){//yourcode}; And open Expression, change skipped=true or skipped=false – hurricane Nov 03 '15 at 14:32
  • This is dangerous: if you do that during debugging, you may forget about the changes and accidentally commit them and it becomes part of the product. (Hopefully a unit test will catch it) – Thomas Weller Nov 03 '15 at 14:40