3. Coredump Fault Analysis
First, the definition: Core dump is also called the kernel dump. When an exception occurs while the program is running, the Linux system can store the contents of the memory in a core file when the program goes wrong, called core Dump.
Second, Segment fault: This is the main solution of core dump error. Linux applications often encounter errors such as Segment fault (segment error) while they are running. The causes of such errors are usually:
- Array access is out of bounds.
- Accesses a null pointer.
- Stack overflow.
- Modifies read-only memory.
Third, Core dump enable
???? On Linux systems, the core dump function is turned off by default, but the core dump function can be turned on/off via the Ulimit command:
???? Open: Ulimit–c Unlimited
???? Close: Ulimit–c 0
???? Iv. Core file analysis.
???? After core dump occurs, you can use GDB to view the contents of the core file to locate where the program went wrong.
???? Usage: GDB Program name core file name
???? Example: GDB./test Core.core
???? Use Gdb+core file to find errors in the program.
Then there are two instances:
- To access a null pointer:
#include <stdio.h>
#include <stdlib.h>
?
void Main ()
{
int *ptr = NULL;
?
*ptr = 0;
}
But at this point we can not find the wrong information with GDB, this is because we just did not add-G at compile time, generate debugging information. Next, add debugging information. The following debugs see that he directly locates the wrong place:
?
2. Access to read-only memory.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
?
void Main ()
{
???? Char ptr[] = "123456";
Ptr[0] = ' 7 ';
}
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
3. Coredump Fault Analysis