Segment errors do not generate a core file problem and use the core file with gdb to locate the error code
Source: Internet
Author: User
Segment errors do not generate a core file problem and use the core file with gdb to locate the error code-Linux general technology-Linux programming and kernel information. The following is a detailed description. The problem that no 'core' file is created on a segmentation fault; Locate errors in the source with GDB and 'core' files
When a Linux program encounters a segment error (often caused by illegal memory access), it will generate a core file. If the program contains debugging information (the-g option is added during compilation ), then, you can use gdb to read the core file to quickly locate the source code with errors. During my internship at a software company (using RedHat Enterprise Linux), I thought this was very convenient for troubleshooting, but my own Debian GNU/Linux didn't generate this file by default.
After the check, the cause is that the maximum size of the core file (which can be viewed with ulimit-c) is 0. Set it to a non-0 value, for example:
Ulimit-c 2048 (set the maximum size of the core file to 2048 blocks, 1 block = 512 bytes, so the configuration here is actually 1 MIB)
Ulimit-c unlimited (unlimited core File Size)
Appendix: Use gdb to locate Errors Based on the core dump file.
Use this program for a test:
Int foo (int * p)
{
Return * p;
}
Main ()
{
Foo (0 );
}
Derek @ dli:/tmp $ gcc-g a. c
Derek @ dli:/tmp $./a. out
Segment error (core dumped)
Derek @ dli:/tmp $ gdb./a. out-c core
(About 10 other lines of information are omitted here)
Core was generated by './a. out '.
Program terminated with signal 11, Segmentation fault.
#0 0x0804834a in foo (p = 0x0) at a. c: 3
3 return * p;
If you enter another bt command, you can see clearly when the error was generated:
(Gdb) bt
#0 0x0804834a in foo (p = 0x0) at a. c: 3
#1 0x0804836b in main () at a. c: 8
There cannot be more clear error messages! In Windows, Trace and Step.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service