First, conditional breakpoints
This technique is often used in loops, such as traversing 1 large lists to stop a breakpoint at a specific value.
Reference, in the location of the breakpoint, right-click on the small red dot next to the breakpoint, will come out an interface, condition here to fill in the breakpoint conditions can be, so when debugging, will automatically stop in the i=10 position
Second, back to the "previous step"
This technique is most suitable for the special complex method set method of the scene, not easy to run up, accidentally hand shake, breakpoint passed, want to look back to see just the variable value, if not know the skill, can only run again.
Refer to the Method1 method call Method2, the position of the current breakpoint j=100, click the red arrow position after the drop frame icon, time across the
Back to the beginning of the METHOD1 call, the variable I became 99, no problem, old iron, is not very 6:)
Note: Curiosity is the ladder of human progress, if you want to know why this function is called drop frame, rather than like back to Previous, you can go through the JVM book, the JVM inside the stack frame as a unit to save the running state of the thread, drop frame to throw away the current running stack frame , so that the position of the current "pointer" is naturally to the position of the previous frame.
Three, multi-threaded debugging
Multi-threaded running at the same time, who first executed, who after the execution, completely look at the CPU mood, can not control successively, the operation may be no problem, but debugging is more troublesome, the most obvious is the breakpoint jumping, a moment to stop the thread, a moment to stop in another thread, such as:
If you want the next breakpoint position to be the 2nd verse, you may be disappointed:
If you want to let the thread debug, you want to be willing to come, let it stop at which thread to stop on which thread, you can in the Figure 3 breakpoints on the red dot right-click,
That is: Suspend hangs on a per-thread basis, not all. Set these 3 breakpoints so you can try again.
Note In the Red box position, when the breakpoint stops, the drop-down box can see each thread (note: It's a good habit to give a thread an easy-to-recognize name!) ), we can select the thread "Bird in the Sky"
The breakpoint was stopped in the 2nd verse.
Four, remote debugging
This is also a weapon to install B, the machine does not have to start the project, as long as there is source code, you can directly remotely debug the server code on the local machine, open posture as follows:
4.1 When the project starts, allow remote debugging first
Java-server-xms512m-xmx512m-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,server=y,suspend= N,address=9081-djava.ext.dirs=. ${main_class}
The thing that works is
-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9081
Note: Remote debugging from the technical, is in the local and remote establish scoket communication, so the port does not conflict, and this confidential allow access to the remote port, the other parameter, put in front of-jar or ${main_class}
Setting up remote debugging in 4.2 idea
And then you can debug it.
The premise is that the machine has the source code of the project, where needed to make a breakpoint, and then access a remote URL to try, the breakpoint will stop.
V. Temporarily execute an expression/modify the running value of a variable
When debugging, you can temporarily execute some expressions, refer to: Click on any of the two icons can be
After clicking on the + sign, you can enter an expression in the new input box, such as I+5
Then enter and you'll see the results right away.
Of course, if you want to dynamically modify the value of a variable when debugging, it is also easy to right-click on the variable and select Set value, and the rest of the world knows.
The use of the above debugging skills, quite a lot of people to get the code to feel more, I wish you a happy weekend!
You may not know the idea advanced debugging tips