GDB Debug and Pat on Linux (Dig a hole first)

Source: Internet
Author: User

should be for Noip to Noi-linux under the program, so forced to choose vim+gdb (mainly guide is too ugly).

Although the debugging function of the guide has dealt with most of the debugging, it is no harm to learn the use of gdb anyway.

1 generating Debug information

In order to debug a C + + program, first at compile time, we have to add debug information to the executable file. This can be done using the-g parameter of the compiler (cc/gcc/g++). Such as:

Gcc-g Hello.c-o Hello

g++-G Hello.cpp-o Hello

Without-G, you will not see the program's function name, variable name, instead of the memory address of the runtime. After you have added the debug information with-G and successfully compiled the target code, let's look at how to debug it with GDB.

2 start gdb the method

Enter GDB program

Program is your execution file, typically in the current directory.

3 GDB the basic commands

L or List:

View source, Ist can also be set to display the number of lines and specify the location

Such as:

(GDB) List

(GDB) List 10

(GDB) List 5,10

B or break: Set breakpoints

Such as:

(GDB) b func

(GDB) B *func

(GDB) b 10

Ps:func is the function name, * represents the previous entry, 10 is the line number

Dig a hole and fill it up later.

GDB Debug and Pat on Linux (Dig a hole first)

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.