Find segment errors using GDB and core
Use GDB and core to find a segment error when a program appears with a segment error, the following prompt appears to view the core file size limit change it to an unrestricted Run command example
1. When a program appears with a segment error, the following prompt appears:
Segmentation fault (core dumped)
Core refers to the memory distribution of process space when the program is running
Dumped says the kernel has thrown the core
In general, a core file should be automatically generated in the program run directory when a segment error occurs, but the core file cannot normally be generated because the Linux environment generally defaults to a core file limit of 0. 2. View the core file size limits:
Ulimit-c
3. Change it to unlimited:
Ulimit-c Unlimited
Once this is set, a core file is generated if a segment error occurs.
After compiling the program with the-G option, run the program to get the core file, and with GDB you can find the location of the segment error 4. Run command
GDB A.out Core
5. Sample
code:
The program ran a segment error:
do the following:
Following the steps shown above, it is easy to get a segment error on line 5th of the test.c file (under the test function, called by the main function)