GCC and GDB

Source: Internet
Author: User

1. GCC

Under Linux, GCC refers to the gcc C compiler. We illustrate several options for GCC from a program to an executable file:

If you write the code is HELLO.C, your program will go through the following steps to reach the hard disk or memory to become an executable file.

GCC-E main.c-o main. I//First step: hello.c (text) precompiled build hello.i (text)

Gcc-s main.i-o main. S//Second step: hello.i (Text) is generated by the compiler HELLO.S (assembly. Text

Gcc-c main. C-o main. O//Third step: Hello.s (Text) is generated by the assembler hello.o (binary).

GCC main. O-o main //Fourth step: hello.o (binary) The linker generates a hello executable file.

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/08/D6/wKiom1noBM2hp6S6AACH8TfOt6I961.png "title=" Gcc.png "alt=" Wkiom1nobm2hp6s6aach8tfot6i961.png "/>

In general, with GCC Main.c-o main can directly generate the executable file main.

2. GDB (some basic debug commands)

The program needs to be debugged at compile time to add the-G option, the program can be debugged

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/08/D7/wKiom1noBwiiWOxaAADzyX-Rm7k841.png "title=" Gdb.png "alt=" Wkiom1nobwiiwoxaaadzyx-rm7k841.png "/>

List Display source file:

List has no parameters, showing more than 10 rows after the current line or around

The list start,end displays the line of code from the line number start to end.

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/08/D7/wKiom1noCd7DSgt0AABTaqHGwAQ473.png "title=" List.png "alt=" Wkiom1nocd7dsgt0aabtaqhgwaq473.png "/>

Print to view data at run time

Print I displays the value of the current variable i

Print &i display the storage address of the variable i

print [email protected] Displays 5 values starting from array (array name)

Print array[2]@3 Displays the values of the 3 array elements starting with the second element of the array

Whatis I shows the data type of the variable i

Set Breakpoint break

Break LineNum set a breakpoint at the current file specified line LineNum

Break function sets a breakpoint at the entrance of the current file functions function

Show Breakpoint Info info breakpoints/break/watchpoints [num]

single-Step tracking Step [N] If a function call is encountered and the function compiles with debug information, it is executed inside the function.

Next [N] executes the entire function when the function call is encountered.

Continuous Execution continue starts at the current line, executes continuously to the next breakpoint, or reaches the end of the program. The command can give a number n, ignoring the subsequent N-1 breakpoint.

Runs the program run.

Clear (Clear all defined breakpoints), delete (delete all breakpoints, then give breakpoint number, multiple breakpoints separated by spaces)

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/19/3c2c56c4b7616619b505d3ebc7cc909c.png "title=" Gdb1.png "alt=" 3c2c56c4b7616619b505d3ebc7cc909c.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/19/6857b05b227a7a81f1350532880fa0e2.png "title=" 6.png " alt= "6857b05b227a7a81f1350532880fa0e2.png"/>

Finally, add one of the above functions can be abbreviated with the first letter

GCC and GDB

Related Article

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.