About core Files
Linux programs may run into a crash during operation, at which point the core file can be recorded on the scene of the program, to facilitate the subsequent search for problems.
Preparatory work
- Enable Core file
By default, the core file is not enabled, that is, the program will not generate a crash core file, so you need to turn on this feature
- View Core file status
Ulimit-a
If the core file size behavior is 0, then the core files are not enabled and need to be executedUlimit-c 2048
To reset the upper limit of the core file size, you can customize the maximum file size value.
- Set the core file name and save address
sudo echo "./core.%p" >/proc/sys/kernel/core_pattern
The above command indicates that a crash file was generated in the current directory with the process ID of the file. There are other optional parameters:%p-insert pid into Filename%u-insert current uid to filename%g-insert current GID into filename%s-insert signal That caused, the coredump into the Filename%t-insert UNIX time, the coredump occurred into Filename%h-insert hostn Ame where the coredump happened into Filename%e-insert coredumping executable name into filename
Using the core file
Following the previous setup, when the program crashes, the core file is generated in the directory where the program is located. At this point, we can use GDB to open the core file
GDB Program Name core file
In general, the program navigates directly to the location where the program went wrong, and if not, you can use the where order to locate it.
It is important to note that the program compiles with the parameter option-G, which makes enough debugging information.
GDB Debug Core file