Add-G option at program compile time to support GDB debugging
Such as:
$ gcc-g Example.c-o example.x
After compiling the example.c with the above command, go to GDB debugging using the following command:
$ gdb example.x
In GDB debugging, the following commands are commonly used:
$ list Indent slightly l
List the program source code, each listing 10 lines, press Enter repeatedly run the previous command;
$ run shrinks slightly R
The program starts to run, after R can join the program startup parameters, the program runs to the breakpoint pause;
$ continue shrink slightly c
The program continues to run, pausing at the next breakpoint;
Single-Step debugging
$ step Indent slightly s
$ next shrinks slightly n
The program continues to run to the next breakpoint;
$ break shrinks slightly b
Set breakpoints at a certain point in the program;
$ info Break indent slightly i B
View breakpoint information;
Set/view Run parameters
$ set args---/show args
Load the running process for debugging (Attach to the running process to be debugged.) :
$ gdb attatch pid
Specifying source Directories
$ dir dirname ...
Output memory block data in hexadecimal
$ X/28HX---
Section error debugging, core file sample
Use the Ulimit command to see if the system is configured to support the functionality of dump core. With Ulimit-c or ulimit-a, you can see the configuration of the core file size, if 0, the system shuts down the dump core and can be opened by Ulimit-c Unlimited. If a segment error occurs, but there is no core dump, the system disables the creation of the core file.
$ GDB [exec file] [core file]
To view stack information:
$ bt
PS: For Python programs under Linux You can use the PDB to do debugging!
Published by Windows Livewriter.
GDB Common Debug Commands