How to use Emacs to debug a C + + program _c language

Source: Internet
Author: User

Emacs, as the saying goes, is God's editor, and Vim is the editor's God. Master programmers are using these two artifacts to develop. I think that Emacs is great because many of the other editors have to use the mouse to select a lot of steps, which can be done through the keyboard under Emacs. Greatly saves you the time to find the button on the monitor. Emacs runs on Linux more smoothly than Windows, and when you edit a program with Emacs, you can do all of your work without leaving the keyboard. So let's take a look at how Emacs can be used to debug C + + programs today.

First, install Emacs and GCC

Download Address: emacs:http://www.gnu.org/software/emacs/

gcc:http://gcc.gnu.org/

Ii. configuring Emacs and GCC

Emacs advises you to open the display line number. The specific action is: Under C:\Users\maple\AppData\Roaming there is an. emacs file, open it, add (Global-linum-mode t) and save, note that the parentheses are also written.

GCC adds a path to the PATH environment variable to ensure that the g++ command is executed correctly under CMD.

Third, write the program, edit

We'll create a new file and then open it with Emacs (Emacs has time to do this, and you can follow the tutorials that come with it).

Let's save it first. Then use Emacs to invoke GCC, press s-m-1

Appears to let you enter the shell command, which is the console command. We enter g++ testdbg.cpp-g-o testdbg.exe

Compile correctly. When we opened tools->gdb for debugging, we found that Emacs had a few more buttons. The following figure:

Four, debugging

1. Set breakpoints

Enter break 5 to set a breakpoint on line fifth and we find a little red dot on the left. That's where the breakpoint is.

2. Run the program

Enter the run execution program and stop at the breakpoint when the program is executed.

3, one step implementation

Input step can be single-step, in gdb, directly press ENTER to repeat the last step of the action.

4. Print variable

With the print variable, you can print out the value of the current variable.

V. Summary

Using Emacs to get rid of the constraints of various Ides, the rapid development of small modules, Emacs with the ability to view hexadecimal files, on Linux, instead of Winhex work, can be compared to the file, these will be time to talk about. GDB is a powerful debugger attached to GCC, which is popular with programmers, and the information about GDB can be found in 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.