Use emacs to debug the C ++ program tutorial and emacs to debug
As the saying goes, Emacs is a god's editor, while Vim is the god of the editor. Master programmers use these two artifacts for development. I think the reason why Emacs is so powerful is that many operations that need to be clicked with the mouse in many other editors can be completed by using the keyboard under Emacs. This greatly saves you time searching for buttons on the monitor. Emacs runs more smoothly in Linux than in windows. When you use Emacs to edit a program, you do not have to leave the keyboard to complete all the work. Now let's take a look at how to use Emacs to debug C ++ programs.
1. Install Emacs and GCC
: Emacs: http://www.gnu.org/software/emacs/
GCC: http://gcc.gnu.org/
Ii. Configure emacs and GCC
We recommend that you open the display row number in Emacs. The specific operation is: Under C: \ Users \ maple \ AppData \ Roaming. open the emacs file, add (global-linum-mode t), and save the file. Note that brackets should also be written.
GCC adds the Path to the Path environment variable to ensure that the command g ++ can be correctly executed in cmd.
3. write and edit programs
Create a new file and use Emacs to open it. (The Emacs operation method has time to be introduced. You can follow the built-in tutorial ).
Save it first. Then use Emacs to call GCC by S-M-1
You can enter the shell command, which is the console command. We enter g ++ testdbg. cpp-g-o testdbg.exe
Compiled correctly. In this case, we open Tools-> GDB for debugging. We found that there are several more buttons in Emacs. For example:
Iv. debugging
1. Set breakpoints
Enter break 5 to set a breakpoint on the fifth line. We found a red dot on the left. That is the position of the breakpoint.
2. Run the program
Enter the run execution program. After the program is executed, it stops at the breakpoint.
3. One-step execution
The input step can be executed in one step. In GDB, press enter to repeat the previous step.
4. Print Variables
Use the print variable to print the value of the current variable.
V. Summary
Emacs can be used quickly to develop small modules. Emacs also provides the ability to view hexadecimal files, replacing winhex in linux, can be used to compare files. We will discuss these later. GDB is a powerful Debugger Attached to GCC, which is favored by many programmers. For details about GDB, refer to the manual.