Finding variable value in Eclipse Debug Perspective - java

I am debugging a program, and once I step in an instruction, I get a list of variables in the Variables view, or if I hold the mouse on the variable, the its value is shown.
Now, I have an object that could possibly have many references to other objects, which, in turn, have their own attributes that contain other objects and so on. The search space could become very large. I would like to find where these values could be by searching the object attributes by value. Eclipse already searches these objects by attribute.
I tried EVars plugin, but it doesn't seem to be still compatible with Eclipse 4.4. Any other tools or recommendations on how to do it?
Thank you very much!

While debugging you can use the "Display" window where you can write pieces of code and "execute" them with inspect (highlight the code -> right click -> inspect).
In that window you have access to all variables of the breakpoint's context.
You could use some java 8 streams snippets to filter your objects.
https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdisplay%2Fref-display_view.htm
https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-evaluating_expressions.htm

Related

Accessing Netbeans Code Completion Variable List Programmatically

I have a working educational Java-palette Module for Netbeans that helps first-year students learn the basics of programming without needing to worry so much about syntax.
When a student drags an item from the palette, they get a popup that allows them to fill-in the details of the code to be dropped, such as variable names or values. I have ComboBoxes that list all the variables in the document. For the Java version of the palette, I simply used JavaParser to get a list of the variables, method names, classes, etc.
Now, I'm doing a version of this palette for C++ students. This time around, I'd rather not use JavaParser, javacc, ANTLR, etc as it seems like overkill. NetBeans already has the list I need when you hit Ctrl+space, but I can't find a way to access the list from a form. Geertjan has a great tutorial on using code completion in a JEditorPane
which addresses implementing your own code completion provider which brings me back to square one.
And this page suggests that NetBeans is simply grabbing a list of variables from the debugger stack. The debugger API doesn't suggest any straight forward methods for asking for a variable list that I could discern.
Any suggestion on using Netbeans APIs to grab a list of variables from a C++ source file, rather than resorting to a parser?

Eclipse - how to debug input parameter change

I have the following problem, we might even call it a classic one:
public void myMethod(Map<Object, Object> parameter){
someOtherObject.method(parameter);
.
.
.
someOtherThirdPartyObject.method(parameter);
}
And suddenly, in the end some method touched the input parameter Map, and I don't know where and how. Now, I know it would be desirable to make the parameter immutable, but it is not and that is the root of the problem. For instance, the methods inside myMethod are intended to perform some validations, but they do some more as well, which is wrong by design.
So, the question is how to create a breakpoint in this method where the execution pauses if an attribute of this parameter Map changes? It might be a good idea to put a conditional breakpoint after each method call, but if you have 20-odd methods, it's rather painful.
How can I debug when this input parameter is changing?
What you want appears to be called a "watchpoint". I actually didn't know this functionality existed and I used to work on the Eclipse Project!
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Ftasks%2Fcdt_t_add_watch.htm
It looks like you'll have to figure out what fields are being editted and then set a "Write" watchpoint using the help document above.
Additionally, Eclipse highlights variables which are modified, so if you step over your method calls one by one you will be able to see which one is modifying the value (and which field is being modified) because it will be highlighted (bright yellow, by default) in the "variables" tab in the "debug" perspective. Once you know which method if modifying the data you can run debug again, but this time debug the method that changes the value and just keep repeating until you find the problem.
This is a classic problem solving scenario where you start with a very large search space and systematically and methodologically narrow it down until the search space is small enough for you to locate the problem.
If you're trying to locate a spot where your map is being modified incorrectly, you might want to first start at the higher levels of the myMethod. Put breakpoints around the methods called inside the myMethod method. At each breakpoint, look at the contents of the Map. Eclipse has a variable watch panel where you can see the contents of every variable at a specific moment in time.
When you hit the breakpoint where you notice something is wrong. Stop. You now know to dig into someOtherObject.method(parameter); assuming the data was changed at it's breakpoint.
Now, someotherObject.method will likely have other methods inside it. Put your breakpoints inside this method around all of it's function calls and repeat the process. Continue repeating until there are no more methods left. Eventually, you will narrow down the problem and have the answer.
Unfortunately, there is no magic "fix my code" button for these types of problems. It just takes good, old fashioned Sherlock Holmes style investigative skills and reasoning to eliminate areas of the code that you know aren't the problem until you're left with a smaller section that allows you to get at the root cause.
If no code modification is allowed, you can
use the watchpoints method described by acattle to watch changes at this specific map instance or
have breakpoints in the Map methods modifying its state (if you want to do that for multiple instances). It does not matter that the Map code is binary only, you can still open it using Ctrl-Shift-T (Open Type), select the methods like put(...) or remove(...) in the outline view and add breakpoints using the context menu in the outline view.

Value tracking in Eclipse

Do Eclipse's Java tools have any equivalent (built-in or plugin) to the Value Tracking inspection in ReSharper? This would be similar to a Call Hierarchy, but tracks all previous value assignments and argument passes for a particular variable.
To clarify, I'm looking for a tool that uses static analysis to trace the origin of a value, within the IDE; this is not debugging at runtime.
Use the debugger mode in eclipse is very powerful. (Add watches!)
Highlight the variable and then press Control+Shift+G or Right Click->References->Workspace will get you all of the references of a particular variable, and you can see where it was assigned or passed as an argument that way. It will show up in a window on the bottom, and a double click will take you directly to the reference.

How to store debug variables in Eclipse?

I want to store debug variables while using a breakpoint and restore them regardless of the application. I probably need some plugin to let me serialize variables and restore them anytime.
To be more specific I want:
breakpoint
see variables, store them
let the flow go further
restore variables and view them in a convenient way (maybe in debug, but not while debugging) and compare variables with my application's view tier
ps. I was trying to find some plugin, but without results.
thanks
I completetly agree with stacker, to answer for your next question about expand all it's very hard to implement for eclipse guys - regarding to this
One risk is the difficulty of dealing
with self-referencing structures,
because application have to expand
them only one time. There may be
variable A which has a reference to B;
and there may be a variable B which
has a reference to A. This kind of
problems -seem- can easily solve by a
set, however this isn't the best
approach. Another risk may be the
quantity of the features I proposed. I
think it would be better to withdraw
some of these. I published them here,
because I couldn't determine which.
The only thing you can do (using the standard debugger) is, to copy the textual information from the variables view into the clipboard (Ctrl-C) and store (Ctrl-V) it in a texteditor for later reference. Please note that only expanded nodes, from the variables view, will be copied.

Changing object fields on the fly while debugging in Eclipse [duplicate]

Using Eclipse, when debugging is it possible to change the value of variables during runtime of a project for testing purposes.
For example, say I have a method that returns the number 5 but for testing purposes i want to output 10 instead. This isn't the problem I'm facing its a little more complex but its just to get my idea across.
You should be able to set a break-point, go into debug mode, open the variables views and here change the content of the variables.
You can access variables through the Variables view. There you can right click on any variable and select "Change value ...".
Resources :
standford.edu - eclipse guide
help.eclipse.org - change var value
... and you can do much, much more:-) Just to give you and idea.
You may change the code during debug which is hot swapped and is effectively changed (recompiled) in given debug session.
You may run given method run (e.g. after catching breakpoint) few times without rerunning debug -> use drop to frame feature on method stack.
After you have changed the code you have to save it (cntrl-S) to make it effective.
You will see your running application respond to the code-change after the cntrl-S
I hope this works for you. it took me some time to figure this out.
Run your application in debug mode then go to variables window. select the parameter then change values according to your requirements. then save (ctrl+s). and go ahead with your changes. Hope this will help.
If variables window is missing. then goto eclipse window->show views->variables

Categories