In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
What are the characteristics of the GUD debugger in Emacs debugging? many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
The following is a brief exploration of the features of Emacs's debugging tool GUD.
If you are a C or C++ developer, you have probably already used GDB (GNU Debugger), which is undoubtedly one of the most powerful and unrivalled debuggers today. Its only disadvantage is that it is based on the command line, and although it still provides many powerful features, it sometimes has some limitations. This is why smart people began to pursue Integrated Development Environment, a graphical GUI integrated development environment that integrates editors and debuggers. There are still some developers who firmly believe that using the mouse will reduce productivity, and clicking with the mouse on GUI is the temptation of the devil.
Because Emacs is one of the coolest text editors today, I'll show you how to write code, compile code, and debug code without touching the mouse or leaving Emacs.
GUD (LCTT) is a pattern mode under Emacs for running GDB in Emacs, given that its acronym is better known. It provides GDB with all the features of Emacs so that users can debug the code without leaving the editor.
Preparation for using GUD
If you are using a Linux machine, it is likely that you have already installed GDB and gcc. The next step is to make sure that Emacs is installed. I will assume that the reader is familiar with GDB and has at least done some basic debugging with it. If you haven't been exposed to GDB, you can make a quick start. These materials are available everywhere on the Internet.
For those new to Emacs, I will introduce you to some basic terms. Throughout the article, you will see keyboard shortcuts such as Cmurc Mmerx. Here C represents the Ctrl key and M represents the Alt key. Cmurc represents that the Ctrl key and the c key are pressed at the same time. If you see Cmurc c, it means pressing the Ctrl key and the c key at the same time, and then pressing the c key immediately after the release. In Emacs, the main area for editing text is called the main buffer main buffer, while the area below the Emacs window for entering commands is called the mini-buffer mini buffer.
Start Emacs and press Cmurx Cmurf to create a new file. Emacs will prompt you for a file name, and here let's name the file buggyFactorial.cpp. Once the file is opened, enter the following code:
# include#include int factorial (int num) {int product = 1; while (num--) {product * = num;} return product;} int main () {int result = factorial (5); assert (result = = 120);}
Use the Cmurx Cmurs shortcut key to save the file. The file has been saved, and it's time to compile. Press Mmurx, type compile at the pop-up prompt prompt and click enter. Then at the prompt, replace the content with Gateway +-g buggyFactorial.cpp and click enter again.
Figure 1: compile commands in the Emacs mini-buffer
This opens another buffer in Emacs, showing the status of the compilation. If there are no errors in your code input, you will expect the buffer shown in figure 2.
Figure 2: compilation status
To hide the compiled buffer, first make sure your cursor is in the compiled buffer (you can move the cursor from one buffer to another using the Cmurx o shortcut key instead of using the mouse), and then press Cmurx 0. The next step is to run the code and see if it works well. Press Mmuri! Shortcut key and type. / a.out at the prompt in the mini-buffer.
Figure 3: output of the code in the mini buffer
You can see that the assertion failure is displayed in the mini buffer. It is obvious that there is an error in the code because the factorial of 5 is 120. So let's start debugging now.
Use GUD mode code
Now that our code has been compiled, it's time to see what went wrong. Press the Mmurx shortcut key and enter gdb at the prompt. At the next prompt, type gdb-i=mi a.out. If all goes well, GDB will launch in the Emacs buffer and you will see the window shown in figure 4.
Figure 4: GDB buffer in Emacs
At the gdb prompt, type break main to set the breakpoint and r to run the program. The program starts running and stops at the main () function.
Once GDB reaches the breakpoint set at main, a new buffer pops up showing the code you are debugging. Note that the red dot on the left is where you set the breakpoint, and there will be a small flag indicating which line the current code is running to. Currently, the flag is at the breakpoint (figure 5).
Figure 5: GDB and code are displayed in two separate windows
To debug the factorial function, we need to step through it. To do this, you can use the GDB command step at the GBD prompt, or use the Emacs shortcut Cmurc Cmurs. There are other shortcuts, but I prefer the GDB command. So I'll use them later in this article.
When stepping, let's pay attention to the factorial values in the local variables. Refer to fig. 6 to set the display of local variable values in the Emacs frame.
Figure 6: displaying local variables using independent frames in Emacs
Step through the GDB prompt and observe the change in the value of the local variable. In the first iteration of the loop, we found a problem. The result of multiplication here should be 5 instead of 4.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.