First, use GCC to compile the source file when you add the-G option to generate a debug file, for example, to debug a test.c file, enter the command $ gcc-g test.c-o test_gdb generate the Test_gdb file.
Then, run the command $ gdb test_gdb to enter debug mode.
In debug mode, (GDB) indicates that a command can be entered at this point, and the commonly used GDB debug commands are as follows:
GDB Common Commands |
Format |
Meaning |
Shorthand |
Break |
break [line number or function name] |
Set a breakpoint in the program |
B |
Cd |
CD Catalog |
Change the current working directory |
|
Continue |
Continue [Start, end] |
Continue execution from Breakpoint |
C |
Delete |
Delete Breakpoints Breakpoint Number |
Delete a breakpoint |
|
Display |
Display variable Name |
Display parameters |
|
File |
File File name |
Loading files |
|
Info |
Info variable Name |
List information for variables |
I |
Kill |
Kill |
Terminate program run |
|
List |
List [Start, end] |
Listing code listings for a file |
L |
Next |
Next |
Next line |
N |
Print |
Print variable Name |
Print variable Contents |
P |
Pwd |
Pwd |
Displays the current working directory |
|
Quit |
Quit |
Exit GDB |
Q |
Run |
Run args |
Run the program |
R |
Step |
Step |
Next step (can be performed inside the function) |
S |
Watch |
Watch variable name or expression |
Set a monitoring point for a variable or expression |
|
Use of GDB Debugging tools in GCC