Is there a way to see the line/method that's currently executing in the NetBeans debugger, without doing step-by-step execution?
I know I could set breakpoints, but I'm curious if there's a way to do it without breakpoints.
VisualVM, which comes bundled with java JDK, can show you live trackable method executions.
From the right border of the code editor, you should see a lot of colored short lines (which indicate warnings, errors, searches etc), among them there is an line with an small green box in the middle of the line, click it and you will locate the program counter.
The line is small so not easy to click.
In most IDEs, there is a tool bar button and menu to locate current executing line.
#Leon is showing how to locate the current position of the caret, which does not necessarily coincide with the program counter.
In the right border of the code editor, there are, indeed, small colored lines (which indicate lines where there are warnings, errors, breakpoints, etc.), among which is one line with a small box in its middle. But it shows the line where the caret happens to be located.
This is not necessarily the location of the program counter because the caret position may have changed since reaching the last breakpoint or other line of code.
The program counter being represented by a (too-small) green block arrow in the left margin of the code editor, where a breakpoint symbol and others can further obfuscate it, no amount of enlarging the editor window contents will make it significantly easier to find the program counter.
Of course, the program counter will change to where it will be visible by stepping out of, into, or over whatever's at the current program counter line. This isn't ideal. And there's a better way.
Alt+Shift+9 will open the Debugging window (below), which will show a number that represents the line number of the program counter.
Moreover, an expanded + dropdown indicator will show a line containing the same pertinent info, but double-clicking this line will open the window containing the program counter and clearly enough show it.
At least that's my experience so far.
Related
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.
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
I'm making java app. which runs on the console. I'm currently implementing a command similar to clear in Linux.
I found a way to clear the console through this question
I'm using this answer
The problem, however, is that the current line does not move up to become the top line. What happens is that every line above the current line gets cleared but the current remains where it is.
How do I move the current line to become the first line --- be on the top?
System.out.print("\f");
Prints a formfeed, which clears the screen and moves the cursor to the top.
So what I am trying to do it so simulate clearing screen of Eclipse terminal.
I know there isn't a real solution for clearing the screen so I know I must use tons of empty lines to clear the screen.
The problem is that when I do tons of new line characters the pointer would be at the bottom of the terminal.
How would I do this so I would end up with pointer at the top of terminal and entire view would appear clear of any text?
So it would look like Aircrack-ng like interface. The screen keep changing but only by scrolling down and updating the content, etc.
What you want basically is to emulate the clrtobot curses function. Which:
erase from the cursor to the end of screen. That is, they erase all lines below the cursor in the window. Also, the current line to the right of the cursor, inclusive, is erased.
In window$, there's the "cls" function, so you must use something like
Runtime.getRuntime().exec("cls");
In most *nix there's the "clear" function. But please don't rely too much on this solution, because this varies, but you can use something like:
Runtime.getRuntime().exec("clear");
I'm yet to see a solution non OS dependent.
I hope it helped. Cheers