Under the Linux platform, set the core dump file properties (location, size, file name, etc.)

Source: Internet
Author: User

Under the Linux platform, set the method for the core dump file generation:

1) Enter ULIMIT-C in the terminal if the result is 0, the system does not generate a core dump when the program crashes.

2) Use the Ulimit-c Unlimited command to turn on the core dump function without limiting the size of the generated core dump file. If you need a limit, add a numeric limit. Ulimit-c 1024

3) By default, core dump generates a file named core and is in the program's current directory. The new core will overwrite the existing core. By modifying the/proc/sys/kernel/core_uses_pid file, the PID of the process can be used as the extension, and the resulting core file format is core.xxx, where xxx is the PID

4) You can control the location and file format of the core file by modifying the/proc/sys/kernel/core_pattern. For example, to generate all the core files into the/corefile directory, the file name format is core-command name-pid-timestamp. echo "/corefile/core-%e-%p-%t" >/proc/sys/kernel/core_pattern

======================= Detailed explanation ==========================

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
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 modes have the same effect but do not take effect in some environments, 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

4. Debugging on the board using core files
-----------------------------
If the operating system of the board is also linux,core the Debug method still applies. If GDB is not supported on the board, you can copy the Development Board's environment (dependent libraries), executable files, and core files to the PC's Linux.
Debugging the core files generated on the board on the PC requires using the cross compiler's own gdb, and you need to specify Solib-absolute-prefix in GDB and Solib-search-path two variables to ensure GDB can find the dependent library path to the executable program. There is a way to create a configuration file that does not require each time you start gdb to configure the above variables, namely: Set up under the path of GDB to run. Gdbinit.
Configuration file Contents:
Set Solib-absolute-prefix Your_cross_compile_path
Set Solib-search-path Your_cross_compile_path
Set Solib-search-path Your_developer_tools_lib_path
Handle SIG32 nostop Noprint Pass

Under the Linux platform, set the core dump file properties (location, size, file name, etc.)

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.