I am not sure if it is recent issue or it was from the "beginning". Is it normal behavior that we can't see the value of variable in debug mode when we tick on it? (It says ctr+shift+I to watch).
You can also use ctrl + shift + D to display the selected content.
Whatever you are trying to get the contents debug should reach that code.
No, this isn't normal behaviour in Eclipse. As soon as a thread hits a breakpoint and enables the debugging perspective, you should be able to inspect your variables either by hovering, Ctrl+Shift+I or with "Inspect" in your context menu.
In what state is Eclipse when you are trying to watch the variable?
Related
I'm using VSCode for Java development, and at some point in time, the debugging variables do not show the toString() results by default. I have to click on the eyeball icon that has "Click to expand" tooltip. In the example below, the Boolean before and after expanding. Stepping through the code cases the view to reset to non-expanded. How do I get the value to show by default?
You can enable this setting debug.autoExpandLazyVariables
I am pretty new at developing larger software and I am using Eclipse as IDE.
When my program is running, I want to have certain informations about the status in different classes (like values of certain objects). Up until now I was just printing it all out on the console with System.out.println(object.value);.
After a while the console became confusing with all the different values printed higgledy-piggledy. Now I am searching for a plugin or something, with which I can do something like
StatusMonitor monitorSize = new StatusMonitor();
StatusMonitor monitorHeight = new StatusMonitor();
monitorSize.print(object.size);
monitorHeight.print(object.height);
And then Eclipse has two different terminals/windows where the specific variables are printed.
Is there a possibility to achieve that?
YOU SHOULD DEBUG IT. FOR THIS ADD BREAKPOINTS IN THE CODE(To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively you can double-click on this position.) WHERE YOU WANT TO CHECK THE VALUES OF VARIABLES. WHEN YOU HAVE PUT THE BREAKPOINTS IN YOUR CODE THEN RIGHT CLICK ON THE CLASS WITH MAIN METHOD THEN SELECT --> DEBUG AS--> JAVA APPLICATION. THEN A DIALOG BOX WLL OPEN CLICK YES ON IT AND NOW YOUR CODE WILL BE OPEN IN DEBUG MODE. ON THE TOP PANEL .There will be options such as STEP INTO ETC. ALSO THERE WILL ARE FEW SHORTCUTS:
F5-->Executes the currently selected line and goes to the next line in your program. If the selected line is a method call the debugger steps into the associated code.
F6-->F6 steps over the call, i.e. it executes a method without stepping into it in the debugger.
F7-->F7 steps out to the caller of the currently executed method. This finishes the execution of the current method and returns to the caller of this method.
F8-->F8 tells the Eclipse debugger to resume the execution of the program code until is reaches the next breakpoint or watchpoint.
In my java eclipse debugger the variables field is always empty and the step over and step into icons are disabled help me with this issues
I did try all the options from google like adding checking variables attributes in preferences menu but am still unable to find a solution help me friends
This is a issue that is faced sometimes, somethings you might try out are:-
-> Close variable window and open again
-> Reset the perspective and see if variables now show up.
-> Close the variables tab and then reset the perspective, this should reopen the working variables tab.
-> If none of them still works , you can right click on the variable and select inspect, then it should come up in a popup window
Incase you do not know how to show vairables view, Window --> Show View --> Variables
Reference
In order to see the value of variables, you have to set a breakpoint.
See the documentation here: EclipseDebugging
If you already set it, try resetting the perspective
Suppose I was making a game and within the render method which cycles hundreds of times per second I have two lines of code e.g.
Sprite sprite = new Sprite (...);
screen.renderSprite(...);
Which creates an object and renders it onto the screen so it shows. But suppose it didn't show; it would be natural to assume that if there is no error then it just wasn't called.
So in Eclipse how I can check if these two lines of code have been called in line x? If you tell me to use breakpoints tell me step by step because I feel that would only obfuscate the render method. (?) I want to check if the object has been created and utilized.
If you need more information don't hesitate to ask.
11. Sprite sprite = new Sprite (...);
12. screen.renderSprite(...);
Right click on line 12 (in my example but will be different in your code.)
Click on Toggle breakpoint
Click Run > Debug As an then either selct Java Application or an existing launch configuration
Once the code starts and enters screen.renderSprite, the program will halt and you'll be able to check it.
First of all you will have to identify some lines in your code at which you know that your sprite wasn't rendered (maybe a state flag?).
From that you have two options:
If you maintain the source code of method #renderSprite(...) you should consider using a logger (like apache logging which should be already included as a plugin of your Eclipse IDE). Thus your application wouldn't obfuscate your rendering processes.
The other option would be debugging: Set up a breakpoint (double-click left of said lines) and run your application in debug mode. You can also set conditions for the breakpoint to stop only in certain cases. Therefor you'll have to right-click a breakpoint and choose "Breakpoint Properties..." and check the "conditional"-box. In the textfield below you can define your condition in Java (you'll have access to all variables just like in your Editor). For more information see the debug help page of Eclipse or Lars Vogel's tutorial on debugging. By debugging your rendering would be paused, but it should be easier for you to find the concrete source of your problem.
A line with a breakpoint set, whose bytecode has been executed, will have a little checkmark on the breakpoint image.
How can I watch the contents of several variables (for example, TreeSet's) simultaneously? I can watch contents of one TreeSet, clicking on it in "Variables" window, but I have no idea how to do that for several variables.
You can use Expressions windows: while debugging, menu window -> Show View -> Expressions, then it has place to type variables of which you need to see contents
You can add a watchpoint for each variable you're interested in.
A watchpoint is a special breakpoint that stops the execution of an application whenever the value of a given expression changes, without specifying where it might occur. Unlike breakpoints (which are line-specific), watchpoints are associated with files. They take effect whenever a specified condition is true, regardless of when or where it occurred. You can set a watchpoint on a global variable by highlighting the variable in the editor, or by selecting it in the Outline view.
You can do so by these ways.
Add watchpoint and while debugging you can see variable in debugger window perspective under variable tab.
OR
Add System.out.println("variable = " + variable); and see in console.
And how about selecting the text you want to watch, and then using the shortcut "Ctrl + shift + I"