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.
Related
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?
As the title says: is it possible to set a breakpoint in classes with no source available? Does any debugger support this? Bonus points for being able to view the stack and local variables.
edit: Sorry for being unclear from start, but I'm not interested in method breakpoints. I want to set a breakpoint inside the method.
If you are using eclipse, you can set breakpoints on the methods in the class using the outline view.
You can set a method breakpoint using the outline view of the class in question. Then the debugger breaks at the first line of the method.(taken from How to put breakpoint in class without having it's source?)
Right click on the method in eclipse outline view and select Toggle Method Breakpoint
P.S. I have tried this and it works for me.
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.
so as the title states, can i change things while debug mode is running an application in Eclipse? You know like colors or stuff like that, I've seen Notch (Creator of Minecraft) do this thing when he was making "Escape" in 48 hours. I think that if I can do that then is more easy for me to change things like, moving buttons in the main menu, changing backgrounds or at least text colors.
PS: I'm using Slick2D
Thanks and have a nice day.
If I understand your question correctly, you can do the following:
Window->Open perspective->Debug
Add a breakpoint somewhere in your code where applicable
Window->Show view->Variables
Run->Debug
When the debugging pauses because of your breakpoint, go to the variables panel and change whatever value has been assigned so far (in the "Values" column).
Run->Resume (or Step Over, or Step Into) to continue debugging
The program will resume with your new value assigned to the variable
Is there any way to set breakpoints on all methods of a given class?
I have a huge (2300 lines) legacy class and I need to set breakpoints on all method calls to understand how this mess works.
You can follow the steps below:
Run -> View breakpoints -> Add -> Java Method Breakpoints
Class pattern -> full reference of your class (e.g., mypackage.MyClass)
Method Name -> * (i.e., asterisk wild card)
I have discovered workaround :
1. I have set "Toggle Brakepoint" hotkey to Alt+Numpad 0.
2. After that you can click on first method
3. Use "Toggle Brakepoint"
4. Alt+Down - goto Next Method. ( Alt+Up - goto Previous Method. )
5. Repeat 3 step.
This is similar to Sergey Senkov's answer, but without hotkeys.
In the structure view, click on the first method. Repeat the following for each method:
Context Menu Key
M to toggle the method breakpoint.
Down
There is a plugin for idea:
Simple Toggle All Method Breakpoint.
It allows you to breakpoint all methods / clear all method's breakpoints in one click from context menu on class in Project view.
As Andrey Lavrukhin suggested, there is Simple Toggle All Method Breakpoint, install it through Settings -> Plugins. Works perfectly.
The only way you'll be able to do what you want is to set method breakpoints on each and every method with the class in question. You need to click on the left hand gutter next to the method - a little red circle with 4 dots will appear and you may get a warning saying method level breakpoints can impact performance. You can then further configure the breakpoint (by rightclicking on it, or select shift+F8) and set it so that it breaks on entry, exit or both
I'm afraid theres no way to do this in a single step/setting.