http://blog.csdn.net/mr_chenping/article/details/13767609
When an unusual program exits, the kernel generates a core file (a memory image, plus debugging information) in the current working directory. Using GDB to view the core file, you can indicate the number of files and rows in the code that caused the program to fail.
1.core file generation switch and size limit
---------------------------------
1) Use the ULIMIT-C command to view the build switch for the core file. If the result is 0, this feature is turned off and the core file is not generated.
2) using the ulimit-c filesize command, you can limit the size of the core file (FileSize is KByte). If Ulimit-c Unlimited, the core file size is not restricted. If the generated information exceeds this size, it will be cropped, resulting in an incomplete core file. GDB will prompt for errors while debugging this core file.
The name and build path of the 2.core file
----------------------------
Core file generation Path:
Enter the executable file under the same path to run the command.
If the system-generated core file does not have any other extension names, it is all named Core. The new core file generation will overwrite the original core file.
1)/proc/sys/kernel/core_uses_pid can control whether a PID is added as an extension in the file name of the core file. The file content is 1, which means adding a PID as the extension, the resulting core file format is core.xxxx, and 0 means that the resulting core file is named Core.
You can modify this file by using the following command:
echo "1" >/proc/sys/kernel/core_uses_pid
2) Proc/sys/kernel/core_pattern can control the core file save location and file name format.
You can modify this file by using the following command:
echo "/corefile/core-%e-%p-%t" > Core_pattern, the core file can be generated uniformly into the/corefile directory, resulting in a file named core-command name-pid-timestamp
echo "Core-%e-%p-%t" > Core_pattern so that the core file is generated in the directory where the executable file resides
The following is a list of parameters:
%p-insert pid into filename add PID
%u-insert current UID to filename to add the present UID
%g-insert current GID into filename to add an existing GID
%s-insert signal that caused the coredump into the filename adds a signal that causes the core to be generated
%t-insert Unix time, the coredump occurred into filename when you add a core file when you build Unix
%h-insert hostname where the coredump happened into filename adds host name
%e-insert coredumping executable name into filename add command name
Viewing of 3.core files
-----------------
The core file needs to be viewed using GDB.
GdB./a.out
Core-file core.xxxx
Use the BT command to see where the program went wrong.
The following two command methods also have the same effect, but in some circumstances do not take effect, so it is recommended to use the above command.
1) gdb-core=core.xxxx
File./a.out
Bt
2) Gdb-c core.xxxx
File./a.out
Bt
Note: The executable file to be debugged, at compile time need to add-g,core file to display error message normally! Sometimes the core information is large, beyond the space limits of the Development Board, the resulting core information is incomplete and unusable, can be mounted to the PC way to circumvent this.
write a simple procedure to see the core The file will not be generated.
$ more FOO.C
#include <stdio.h>
static void sub (void);
int main (void)
{
Sub ();
return 0;
}
static void sub (void)
{
int *p = NULL;
/* Derefernce A null pointer, expect core dump. */
printf ("%d", *p);
}
$ gcc-wall-g FOO.C
$./a.out
Segmentation fault
$ ls-l core.*
-RW-------1 uniware uniware 53248 June 17:10 core.9128
Pay attention to the above output information, more than one (core dumped). It does produce a core file, and 9128 is the PID of the process. We use GDB to look at this core.
$ gdb--core=core.9128
GNU gdb Asianux (6.0POST-0.20040223.17.1AX)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU general public License, and you are
Welcome to change it and/or distribute copies of it under certain.
Type "Show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "Show warranty" for details.
This GDB is configured as "I386-asianux-linux-gnu".
Core is generated by './a.out '.
Program terminated with signal one, segmentation fault.
#0 0x08048373 in?? ()
(GDB) bt
#0 0x08048373 in?? ()
#1 0xbfffd8f8 in?? ()
#2 0x0804839e in?? ()
#3 0xb74cc6b3 in?? ()
#4 0x00000000 in?? ()
At this time with BT can not see BackTrace, that is, call stack, originally GDB does not know where the symbolic information. Let's tell it:
(gdb) file./a.out
Reading symbols from./a.out...done.
Using host libthread_db Library "/lib/tls/libthread_db.so.1".
(GDB) bt
#0 0x08048373 in Sub () at Foo.c:17
#1 0x08048359 in Main () at Foo.c:8
At this time the backtrace came out.
(GDB) L
8 Sub ();
9 return 0;
10}
11
A static void sub (void)
13 {
int *p = NULL;
15
/* Derefernce A null pointer, expect core dump. */
printf ("%d", *p);
(GDB)
Linux Core Files