Core Dump resolution (3)-configuration and debugging

Source: Internet
Author: User

Linux
Core Dump configuration and debugging
1. Core File generation switch and size limit
---------------------------------
1) Use ulimit
-C command to view the core file generation switch. If the result is 0, this function is disabled and core files are not generated.
2)
Use ulimit
-The cfilesize command can limit the size of the core file (The unit of filesize is Kbyte ). If ulimit
-Cunlimited indicates that the size of the core file is not limited. If the generated information exceeds this size, it will be cropped to generate an incomplete core file. Debug this
When the core file is used, GDB will prompt an error.
2. Name and path of the Core File
----------------------------
If the core file generated by the system does not contain any other extension names, it is all named core. The new core file will overwrite the original core file.
1)/proc/sys/kernel/core_uses_pid can control whether PID is added to the file name of the core file as an extension. If the file content is 1, the PID is added as the extension, and the generated core file format is core. xxxx. If it is 0, the generated core file is named core.
Run the following command to modify the file:
Echo
"1">
/Proc/sys/kernel/core_uses_pid
2) proc/sys/kernel/core_pattern can control the core file storage location and file name format.
Run the following command to modify the file:
Echo
"/Corefile/Core-% E-% P-% t">
Core_pattern, which can generate the core file to the/corefile directory, and the generated file name is core-command name-PID-timestamp.
The following is a list of parameters:

% P-insert PID into filename add PID

% U-insert current uid into filename add current uid

% G-insert current GID into filename add current GID

% S-insert signal that caused the coredump into the filename
Add the signal that causes the core to be generated

% T-insert UNIX time that the coredump occurred into filename
UNIX time when the core file is generated

% H-insert hostname where the coredump happened into filename
Add Host Name

% E-insert coredumping executable name into filename
Add command name
3. Use GDB to view the core file:
The following example shows how to create a core
Dump.
Core
After dump,
Use GDB to view the content of the core file,
To locate the file that causes the core
Dump row.
GDB [Exec
File] [core file]
For example:
GDB
./Test. Core
After entering GDB,
Run the BT command to view backtrace to check where the program is running,
To locate the core dump file-> row.
4. Use the core file for debugging ON THE DEVELOPMENT BOARD
-----------------------------
If the operating system of the Development Board is also Linux, the core debugging method is still applicable. If GDB is not supported on the Development Board, you can copy the Development Board environment (header files, libraries), executable files, and core files to Linux on the PC and run relevant commands.
Note: The executable file to be debugged must be added to-g during compilation so that the core file can display error information normally!
Notes:
In Linux, pay attention to the following issues to ensure coredump is generated when the program crashes:
1. Ensure that the directory where coredump is stored exists and the process
The directory has the write permission. The directory that stores coredump is the current directory of the process, which is generally the directory where the command was issued to start the process. However, if it is started through a script, the script may modify the current object
The current directory of the process is different from the directory where the script was originally executed. In this case, you can view the target of the "/proc/process pid>/CWD" symbolic link to determine the process.
The actual current directory address. You can also view the processes started by the system service in this way.
2. If the program calls seteuid ()/setegid () to change
By default, the system will not generate coredump for these processes. Many service programs call seteuid (), such as MySQL.
The user runs mysqld_safe to start mysql. The valid user of mysqld is always the msyql user. If you run a program with user
If the user of this program is B, these processes call seteuid. To allow these processes to generate Core
Dump,/proc/sys/fs
The content of the/suid_dumpable file is changed to 1 (usually 0 by default ).
3. This is generally known as setting a large enough core file size limit.
. The core file size generated when the program crashes is the memory size occupied by the program running. However, when a program crashes, the behavior cannot be estimated as usual. For example, errors such as buffer overflow may cause the stack to be
Damage, so the value of a variable is often changed to a mess, and then the program uses this size to apply for memory may cause the program to occupy more memory than usual. Therefore
Make sure that the size of the core file is set to unlimited.

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.