What is core under linux

藏色散人
Release: 2023-03-23 10:00:50
Original
2770 people have browsed it

Under Linux, core is a memory image with debugging information added. When a program exits or terminates abnormally under Linux, we will use the core file for analysis, which contains the memory and registers when the program is running. , stack pointer and other information, the format is ELF, it can be understood that the current status of the program work is dumped into a file.

What is core under linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What is core under linux?

Detailed explanation of how to use core files under Linux

Sometimes the program will exit abnormally without any logs. At this time, you can use the code file for analysis, which will record the program operation. Memory, registers, stack pointers and other information

Core file:

Usually when a program exits or terminates abnormally under Linux, we will use the core file for analysis, which contains the program runtime The memory, registers, stack pointer and other information are in the format of ELF. It can be understood that the current status of the program is dumped into a file. By analyzing this file with tools, we can locate the corresponding stack call and other information when the program exits abnormally or terminates. Provide help solving problems.

Use core file debugging

Generation method

View the status of the current core file

$ ulimit -a
...
-c: core file size (blocks)   0 # 关闭状态
...
Copy after login

Open The generation switch

ulimit -c unlimited
ulimit -a
...
-c: core file size (blocks)   unlimited
...
Copy after login

limits the size of the core file. The unit is blocks. Generally, 1 block=512 bytes. If the setting is too small, the file may not be generated.

$ ulimit -c 1024
$ ulimit -a
...
-c: core file size (blocks)   1024
...
Copy after login

Turn off the generation switch

ulimit -c 0
ulimit -a
...
-c: core file size (blocks)   0
...
Copy after login

The above operation on the core file only takes effect currently. If it needs to take effect permanently, the corresponding operation must be written to /etc/profile

Generation path

The core file is generated in the working directory of the program by default. The generation path can be set. You need to ensure that there is enough space and write permission for the corresponding directory.

echo /MyCoreDumpDir/core.%e.%p > /proc/sys/kernel/core_pattern
Copy after login

The parameter list used in naming

%p - insert pid into filename # 添加 pid 
%u - insert current uid into filename # 添加当前 uid 
%g - insert current gid into filename # 添加当前 gid 
%s - insert signal that caused the coredump into the filename # 添加导致产生 core 的信号 
%t - insert UNIX time that the coredump occurred into filename # 添加 core 文件生成时的 unix 时间 
%h - insert hostname where the coredump happened into filename # 添加主机名 
%e - insert coredumping executable name into filename # 添加命令名
Copy after login

/proc/sys/kernel/core_uses_pid If the value of this file is 1, then whenever %p is configured, the final generated core file will add pid

Debugging method

You can use gdb to debug the core file. You need to bring the -g option when compiling.

$ gdb a.out
...
(gdb) core-file core
...
(gdb) bt 
...
Copy after login

If you need to debug the core file generated by the embedded device on the PC, you need to select the corresponding option. The platform's gdb tool, and set the location of the symbol file after entering gdb

$ xxx-xxx-gdb a.out
...
(gdb) solib-search-path xxx.so:xxx.so
...
(gdb) core-file core
...
(gdb) bt
...
Copy after login

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is core under linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template