As the saying goes, Emacs is the editor of God, and Vim is the god of editors. Expert programmers use these two magical tools for development. I think that the reason why Emacs is powerful is that many operations that require you to click many steps with the mouse under other editors can be completed through the keyboard under Emacs. This greatly saves you time finding buttons on your monitor. Emacs runs on Linux and feels smoother than Windows. When editing programs with Emacs, you can do all the work without leaving the keyboard. So today let's see how to use Emacs to debug C++ programs.
1. Install Emacs and GCC
Download address: Emacs:/software/emacs/
GCC:/
2. Configure emacs and GCC
Emacs recommends that you turn on the display line number. The specific operation is: under C:\Users\maple\AppData\Roaming, there is a .emacs file, open it, add (global-linum-mode t) and save, and note that the brackets should be written together.
GCC adds a path to the Path environment variable to ensure that the g++ command can be executed correctly under cmd.
3. Write the program and edit it
We create a new file and open it with Emacs (I will introduce the operation method of Emacs if you have time. You can follow the tutorials included).
Let's save it first. Then use Emacs to call GCC and press S-M-1
The shell command appears, and this is the console command. We enter g++ -g -o
Compiled correctly. At this time, we opened Tools->GDB for debugging, and we found that Emacs has several more buttons. As shown in the figure below:
4. Debugging
1. Set breakpoint
Enter break 5 to indicate that the breakpoint is set in the fifth line. We found that there is a small red dot on the left. That is the breakpoint position.
2. Run the program
Enter run to execute the program, and the program will stop at the breakpoint after executing.
3. Step-by-step execution
Enter step to perform in a single step. In GDB, press Enter directly to repeat the previous step.
4. Print variables
Using the print variable, you can print out the value of the current variable.
5. Summary
Using Emacs, we have got rid of the constraints of various IDEs and can develop small modules very quickly. Emacs also has the function of viewing hex files. On Linux, it replaces winhex's work and can compare files. I will talk about these later if you have time. GDB is a powerful debugger attached to GCC and is loved by programmers. You can check the manual for information about GDB.