Linux 核心转储文件格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6602176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Core-dump file format
提问by AvadhP
I have written a custom core-dump handling application for a project. I have changed '/proc/sys/kernel/core_pattern' to call my dump-handler and its invoked successfully.
我为一个项目编写了一个自定义的核心转储处理应用程序。我已更改“/proc/sys/kernel/core_pattern”以调用我的转储处理程序并成功调用它。
Now the issue is saving the core-dump into a file that can be recognized by gdb. Currently my dump-handler read the dump from STDIN and save it into a file 'core.dump'. When I try to load this core dump into gdb it gives me error:
现在的问题是将核心转储保存到 gdb 可以识别的文件中。目前,我的转储处理程序从 STDIN 读取转储并将其保存到文件“core.dump”中。当我尝试将此核心转储加载到 gdb 时,它给了我错误:
(gdb) ... is not a core dump: File format not recognized
(gdb) ... is not a core dump: File format not recognized
When I run 'file' command on a standard core dump it give me following:
当我在标准核心转储上运行“文件”命令时,它给了我以下信息:
core: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from './dump_gen'
core: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from './dump_gen'
And for custom generated dump, 'file' gives following:
对于自定义生成的转储,'file' 提供以下内容:
core.dump: data
core.dump: data
Please can anyone help me how to write core-dump correctly so it can be used in gdb.
请任何人都可以帮助我如何正确编写核心转储,以便它可以在 gdb 中使用。
PS: I don't want to use standard core dump file.
PS:我不想使用标准的核心转储文件。
采纳答案by Ulrich Dangel
I think you somehow don't write all the data to the core file.
我认为您以某种方式没有将所有数据写入核心文件。
Create a simple script, make it executable and set the core pattern to the script.
创建一个简单的脚本,使其可执行并将核心模式设置为脚本。
#!/bin/sh
cat > /tmp/core.$$
Now generate a core file (for example run sleep 1243
and press ctrl+\
) and it should work.
现在生成一个核心文件(例如运行sleep 1243
并按 ctrl+\
),它应该可以工作。
I just tested it myself on my system and it works without a problem.
我只是在我的系统上自己测试了它,它可以正常工作。
回答by dascandy
The first thing to check that comes to mind is the Elf header flag that indicates what kind of file it is. It has four values - shared object, unlinked object, executable and core dump. That's most likely what's causing gdb errors.
首先要检查的是 Elf 标头标志,它指示它是哪种文件。它有四个值——共享对象、未链接对象、可执行文件和核心转储。这很可能是导致 gdb 错误的原因。
Also, try examining it with objdump - it can pull apart the entire ELF file for analysis what part of it is apparently not good.
此外,尝试使用 objdump 检查它 - 它可以拆开整个 ELF 文件以分析它的哪一部分显然不好。
You can find the ELF spec at https://refspecs.linuxbase.org/elf/elf.pdf
您可以在https://refspecs.linuxbase.org/elf/elf.pdf 上找到 ELF 规范