Linux Next segment Error core file

Source: Internet
Author: User
Tags gdb debugger

What is core dump?

Core means memory, dump means to throw out, heap out; When a program crashes, the process's stored image is copied in the core file of the current working directory of the process. The core file is simply a memory image (plus debugging information) that is used primarily for debugging.

Why is there no core file generation?

Sometimes the program is down, but the core file is not generated. The build of the core file is related to the environment settings of your current system, and you can set up a core file with the following statement.

InUnder Linux platform, setHow to generate the core dump file:
1. Enter in the terminalUlimit-c If the result is0, indicating that when the program crashes, the system does not generateCore dump.
2. Use ulimit-c unlimited command to turn on core dump function without restricting generation core dump file. If you need a limit, add a numeric limit. ulimit-c 1024x768
3. By default, core dump generates a file named core, And it's in the current directory of the program. The new core will overwrite the existing core. By modifying the /proc/sys/kernel/core_uses_pid file, the process's pid as an extension, the generated core file format is core.xxx, where xxx is pid
4. You can control core File save location and file format by modifying /proc/sys/kernel/core_pattern. For example: Generate all core files to /corefile directory, the format of the file name is core-command name -pid-timestamp echo "/corefile/core-%e-%p-%t" >/proc/sys/kernel/core_pattern

< Span lang= "en-US" > < Span lang= "en-US" >

< Span lang= "en-US" > < Span lang= "en-US" >

< Span lang= "en-US" > < Span lang= "en-US" >

< Span lang= "en-US" > < Span lang= "en-US" > 1. Accessing memory addresses that do not exist

2. access to system-protected memory addresses

3. Access to read-only memory addresses

4. Stack Overflow

......

View information about the occurrence of a segment error

1.dmesg

Debugging Methods for segment errors

1. Using printf to output information

Add output such as printf, near the program's important code , to track and print out where a segment error might appear in your code.

To facilitate this approach, you can use conditional compilation directives #ifdef Debug and #endif把printf functions to wrap up. This allows the debugging information to be viewed when the program is compiled with the-ddebug parameter, otherwise the debug information will not be displayed without the parameter.

2. Using GCC and GDB

To be able to use the GDB debugger, add the-g parameter to the compile phase

./GCC Helloworld.c-o-G HelloWorld

To debug a program using the GDB command

GdB./helloworld

After entering GDB, run the program:

Run

See from the output, receive SIGSEGV signal, trigger segment error, and prompt

When debugging is complete, enter the QUIT command to exit GDB

Quit

You can use the gdb tool to debug a segment error in a program by using debugging information from the core file that is generated when the program exits unexpectedly.

GdB./helloworld./core

See segment error message from output

When debugging is complete, enter the quit command to exit GDB:

Quit

Linux Next segment Error core file

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.