I saw this somewhere, but I don't know where. It was basically something in Eclipse that was a feature when debugging that highlighted the code as it went through the code. I need this because I have decompiled a huge library, and I need to know how specific features are created.
Thanks,
Neil
F5 key : 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.
More details in this link
Related
it happens to me many times: I'm stepping with the debugger through my code, and ups! i made one step too far! Debugging, and made one step over too far
what now? restart the whole debugging session?
actually, there is a way to go ‘backwards’
The feature is called 'Drop to frame' right click on any line in stack, choose 'Drop to frame' and you go back to selected method beginning
https://help.eclipse.org/2021-03/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/views/debug/ref-droptoframe.htm
You can only jump to the start of the current function . Please keep that in mind.
What is the difference between step into and force step into in debugging?
From my own observation using the IntelliJ debugger over the years, if you try to step into a method call on a given line of code, the following will happen:
if the code being called be your own code, then the debugger will step into that method
if the code being called be some third party library, then the debugger will ignore your request, and instead step over that line
By telling IntelliJ to force step into a line, in the case of a third party method, it will then try to find source code for that method. If it can't find source code, then it might show you an auto generated stub based on the byte code/library. But, there may not be any code shown, or if there is, it would be IntelliJ's best guess based on byte code.
This question already has answers here:
How to modify Java code while running in debug mode?
(4 answers)
Closed 7 years ago.
I am debugging my application in Eclipse. Finally I reached a breakpoint in a state which will trigger the bug in the next line of code.
Due to a breaking change in the class, the most likely solution would be to remove that line of code.
Of course I could do that now: remove the line, recompile and reproduce the sitatuation again. However, since it is hard to reproduce the bug, can I simply skip the execution of that line of code now? E.g. can I set the "instruction pointer" in Eclipse?
Things I did:
I don't want F6 (Step Over), since that will execute the line.
Also "Run to cursor" is not what I want, since that will also execute the problematic line.
Comment out the code according to How to modify Java code during debugging, but that re-executed the method, thus changing the state
I have tried to find an answer on this question, but I don't only want to run a single line of code but all the rest.
This question only has answers which run code in between.
The drop to frame feature is also not helpful.
The linked questions are from 2009 to 2013, so I hope to get new answers.
I'm using Eclipse 4.5.1 (Mars.1), latest official version at the time of asking.
If you want execute the line after the one you want to skip. When you reach the line before the line to be skipped, select the code and right click, choose Inspect from menu. This will execute the selected code and provide you the result in a popup.
If you know the lines that have to be skipped. you can put them in an if statement and change the value of the boolean in the variables view in eclipse. And then proceed to other lines.
(using code from comments)
if (skipped){
//yourcode
};
It is also possible to create expressions in eclipse.
One thing which I missed out was eclipse also supports hot code swap. You can comment out the line and save it. It will drop the debugger control back to the starting of the method. Hot deploy has supported the code changes in the method implementation only. If you add a new class or a new method, restart is still required. If you have the server in eclispe, here is how you can make that possible http://www.mkyong.com/eclipse/how-to-configure-hot-deploy-in-eclipse/
Sorry for the strange name of my question. I don't know how to look for this because I don't know how these things are called.
There's a features in Visual Studio at least where you can click on the left of the code and set a starting point which is a big red dot. Then you run the program and you can trace the steps by pressing f8 or f5 (different f's really) and you see the variable values on each step etc. I find it extremely useful because I can see where an error occurs and how the program behaves.
I have no idea what this is called and I want to ask is there such a thing in NetBeans IDE 8.0.2 or jGrasp or any java compiler?
Sorry if anything sounds stupid, I'm kind of a newbie.
Thank you all
Most IDEs have debugging functionality built in.
In Netbeans, you can easily add/remove a break point by simply clicking the line number on right side of the source editor (you can also do via the editor popup menu)
You start the debugger through F5 (ShiftF5 for debug the current file) or via the debug icon on the toolbar
You can use F8 to step over the command/method call, F7 to step into a method. You can resume running the program using F5 while the debugger is running.
See Debugger and Profiler and Using the Visual Debugger in NetBeans IDE for more details
Finding how to do this in your IDE is pretty easy, see the other answers.
What is a bit more difficult is debugging an external (and/or) remote Java program in your IDE. Here it is how to do that with Eclipse: http://www.ibm.com/developerworks/library/os-eclipse-javadebug/. I guess other IDEs are similar. If you test via Maven/Surefire, you have a simple flag to do the same: http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html
From Javascript, I can simply write
debugger;
and when that line executes, it stops the code as if I had put a breakpoint there.
Is there an equivalent in Java? I need it to work in Eclipse specifically.
EDIT: can we take it as read that I am not an idiot and if placing a breakpoint with the IDE itself were an option, I would have already done so?
FURTHER EDIT: I had not thought it necessary to point out that since placing a breakpoint with IDE is not an option, any answer that revolves around placing a breakpoint with IDE is not likely to be helpful. In case everybody is dying of curiosity, the original code is not written in Java -- it's processed down to Java byte-code. As a result, Eclipse is confused enough it doesn't want to set breakpoints.
The JVM debugger, which Eclipse uses (mostly) under the covers, can set breakpoint at a line number in a method IF compiled with certain optional debugging info OR at method entry (always).
If your classes were compiled without debugging "lines" so the debugger can't set a line breakpoint, and you don't want to or can't recompile them, you can still set a method-entry breakpoint. In Package Explorer -- NOT an edit window for the source -- right-click the method name/signature and Toggle Method Breakpoint to on.
This can be combined with the comment by #ajp: add a method e.g. void [static] debugger(){} that doesn't do anything when you call it, but provides a convenient target where you can set a method breakpoint.
Warning: although it is possible to compile with partial debugging info, like debugging "vars" but not debugging "lines", generally people just use "debug on" or "debug off". If your classes are compiled without debugging "vars", the debugger will be much less useful.
I am probably going to get a few downvotes, but so be it...
If you open a source file in Eclipse and right-click on the left edge of the document view, you will get the popup menu illustrated in the image below.
As you can see, you have the option to toggle a breakpoint and also to turn off and on the line numbers. So, I am not sure what you mean by "My Eclipse is being operated in an environment where it cannot find line numbers to the source code". Unless you have some modified version of Eclipse that does not show this menu, I don't know what you mean by that. The option is there.
You wrote:
From Javascript, I can simply write
debugger;
and when that line executes, it stops the code as if I had put a breakpoint there.
And also:
can we take it as read that I am not an idiot and if placing a
breakpoint with the IDE itself were an option, I would have already
done so?
Option 1: The simple, "incorrect" answer is that there is no instruction in the Java language to make the program pause in a breakpoint nor there is an option like in languages like C++ to
make a debug build. So, your "ONLY" option is to execute a breakpoint from the IDE.
Option 2: The complicated, correct answer is that you can do what you want following these instructions: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html
In your case, I don't believe that you don't have the option to place a breakpoint with the IDE to debug your program; no matter how complex your program is. BUT, I am not here to debate that point. According to your post, you have to do option 2 laid out here.