Use emacs to debug the C ++ program tutorial and emacs to debug

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.