Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to modify the response of a function in Eclipse while debugging?

Let's say I have the following code:

if(shouldDoSomething()) {

    // amazing code here
}

And let's also say shouldDoSomething() is a method I don't have source code for. Is there any way I can force the code into the if block even if shouldDoSomething() returns false? And vice versa?

I know in C++ in Visual Studio I could just change the value in the EAX register and be on my way, but I didn't know if there was something similar for debugging in Eclipse when code is written in this style?

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

like image 265
Matt Felzani Avatar asked Oct 16 '14 18:10

Matt Felzani


1 Answers

Perhaps there is a neater way of doing this, but this should work :

1) Step Into (F5) the method you want to change the return value for. It is fine if you do not have the source code for this method and it steps into a class file.

2) Open the Display View (Window>Show View>Display) and type true into it

3) Highlight the true you just typed and right click on it and choose Force Return (or Alt+Shift+F)

4) Continue stepping through your code. If you had your if statement set up as in your question it should now step into the if statement block.

like image 191
SamYonnou Avatar answered Nov 04 '22 07:11

SamYonnou