In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to debug BUG with IDEA". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to debug BUG with IDEA.
Conditional breakpoint
Scene: we are traversing a collection and expect the program to stop when certain preset conditions are met. For example, teacher Mu Fang calls the roll in class and needs to pause to confirm whether anyone is helping Xiaoming answer "yes".
Then teacher Mufang can do this:
Right-click the little red dot (breakpoint) next to the breakpoint, pop up the panel, and fill in the pause condition here in Condition, so that when debugging, when the program meets the conditions, it will stop steadily in the position of student= "Xiaoming".
Second, go back to the past.
Scene: people are not saints, who can make mistakes. In daily development, we all have disabled hands, such as debugging a business logic is more complex, there are multiple methods nested, accidentally shaking hands, breakpoints have passed, what should we do?
On this day, teacher Mu Fang called the roll before class as usual. when it came to Xiaoming, the disgraceful Xiaoming was secretly watching the girl he liked and didn't pay attention. When he reacted, he already missed the answer! Very remorseful (beauty disaster), at this time Xiao Ming can borrow Nobita's robot cat to travel through time:
Looking at the picture above, we can see that according to the order of roll call, it is now Xiao Hong's turn for teacher Mufang to call the roll. Xiao Ming has missed the answer. The robot cat can help Xiao Ming like this: click the Drop Frame icon in the red box above (if there are nested calls to multiple methods, you can click a few more times). In this way, Xiao Ming passed through and didn't miss the answer this time:
Tips: this button is called Drop Frame because the JVM stores the running state of the thread in terms of stack frames. Drop Frame literally translates to throw away the currently running stack frames and return to the position of the previous frame, thus realizing traversal.
Third, multi-thread debugging
Finally, the teacher called the roll and now we can have a normal class. When it comes to the questions asked by the students' favorite teacher, the students rush to answer.
As we know when we start multiple threads, which thread executes the program first depends entirely on the mood of CPU (like the existence of a father), which will cause a problem: it is impossible to debug in the execution order like a single thread. The phenomenon is that you only care about breaking points, and I lose if you don't jump randomly between threads. Examples of the program are as follows:
After the teacher asked the question, four students began to rush to answer:
With so many students rushing to answer, Mu Fang, who has been on the job for more than 30 years, thinks that the classroom may be a little chaotic if it goes on like this: but this does not bother Mu Fang, who has been in practice for more than 30 years. She right-clicks on the breakpoint and selects Thread to purposefully track a classmate's rush to answer (everything is under control).
IV. Remote debugging
As you can see here, Xiaoming has to introduce a skill of installing X: cloud debugging. That is, the local machine does not need to start the project, as long as the local source code matches the jar package running by the remote server, you can debug the code on the server directly on the local machine! The opening pose is as follows:
Allow remote debugging when a remote project is started
Most of them are SpringBoot projects now, so when we run a jar package on a remote server
Java-server-Xms512m-Xmx512m-Xdebug-Xnoagent-Djava.compiler=NONE-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8080-jar xiaoming.jar
The core command that works here is
-Xdebug-Xnoagent-Djava.compiler=NONE-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8080
Technically speaking, remote debugging is to establish scoket communication between the local machine and the remote service, so the local machine should be able to access the port of the remote service.
Set up remote debugging in idea
Then we can debug normally, the debugging mode is the same as the local running service debugging, do not believe you to initiate a request, and try a breakpoint in the corresponding logic code?
V. temporary execution of expressions
Another is when debugging, we can also temporarily execute some expressions, click the icon selected in the red box, and then enter the expression you want to execute, as follows:
You can see how fragile Xiaoming's mind is, because he is unable to face his actual age and is about to get his real age. He secretly subtracts 7 years, so his actual age will always be 18 (manually funny).
6. Modify the running value of the variable
Of course, if you want to modify the value of a variable dynamically when debugging, it is also easy to right-click on the variable and select Set Value, such as simply and rudely changing Xiao Ming's age to 18.
At this point, I believe you have a deeper understanding of "how to debug BUG with IDEA". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.