GDB is a set of character-interface assemblies that you can use to debug C and C + + programs on Linux, which provides the following features:
1 set a breakpoint in the program when the program runs to a breakpoint pause
2 Display the value of a variable, you can print or monitor a variable, display the value of a variable
3 Single Step execution
4 Modifying the value of a variable at run time
5 Trace Path
6 Thread Switching
Wait a minute
Below is an example of the following procedure
When we are going to use GDB to debug the program, we need to add-g when compiling with GCC, as follows:
GDB is able to debug the program is also in the compilation of the-G option, when this option is set, GCC will plug in the program information, as GDB debugging the foreshadowing
, and GDB can then use these mats and information to interact with the program.
There are two ways to enter GDB, one is to enter GDB directly on the command line, and then use the file command in GDB to load the program you want to debug:
The other is to use it directly on the command line: GDB program name
Both of these methods are to load a program that has been paved and will be debugged in GDB.
After GDB is carried out and the program is loaded, we can perform a series of debugging operations:
1 set input parameters with "set args parameter value 1 parameter value 2 ..."
2 Use "List start line number" to print content
The list can also select intervals to print the code:
3. Set breakpoints with "B position"
4. Run the program with the "Run parameter"
5. Display variable name to show the variable
6. Use "C" to continue running the program
7. Use the SET command to change the value of a variable
8 Use the Q command to exit GDB
9 Use the P command to print the value of a variable
10 Set Conditional breakpoints
11 Deleting breakpoints with Delete
12 Using info break to display breakpoint information
13. Use BT to display the function call path
14 use Whatis or PType to show the type of the variable
GDB debugging of "Go" Linux programming