Is it possible to change the response of a function in Eclipse during debugging?

Let's say I have the following code:

if(shouldDoSomething()) { // amazing code here } 

And let it also be said that shouldDoSomething() is a method for which I have no source code. Is there a way to force code in an if block, even if shouldDoSomething() returns false ? And vice versa?

I know that in C ++ in Visual Studio, I could just change the value in the EAX register and be in my path, but I did not know if there was anything like this for debugging in Eclipse when the code is written in this style

Refactoring code to capture the response in a variable is not an option.

+6
source share
1 answer

There may be an easier way to do this, but this should work:

1) Step B (F5) is the method for which you want to change the return value. This is normal if you do not have the source code for this method, and it is included in the class file.

2) Open the View window (Window> Show View> Show) and enter true in it

3) Highlight the true that you just typed, and right-click on it and select "Force Return" (or Alt + Shift + F)

4) Continue to execute your code. If you have an if statement configured as in your question, now it should go to the if block.

+4
source

Source: https://habr.com/ru/post/976842/


All Articles