如何轻松打包分析核心转储所需的库(即 packcore)
HPUX 上可用的 GDB 版本有一个名为“packcore”的命令,该命令创建一个包含核心转储、可执行文件和所有库的 tarball。当尝试在不同的机器上调试核心转储时,我发现这非常有用。
在 Linux 机器上的 GDB 标准版本中是否有类似的命令?
我正在寻找一个简单的命令,当生产机器上出现问题时,不一定是开发人员的人也可以运行该命令。
The version of GDB that is available on HPUX has a command called "packcore", which creates a tarball containing the core dump, the executable and all libraries. I've found this extremely useful when trying to debug core dumps on a different machine.
Is there a similar command in the standard version of GDB that I might find on a Linux machine?
I'm looking for an easy command that someone that isn't necessarily a developer can run when things go bad on a production machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
核心文件包含生成它的命令。理想情况下,这将包括相应可执行文件的完整路径。例如:
在 ELF 二进制文件上运行 ldd 将显示它所依赖的库:
所以现在我知道了分析核心转储所需的可执行文件和库。
这里棘手的部分是从核心文件中提取可执行路径。似乎没有一个好的工具可以直接阅读此内容。数据以 prpsinfo 结构编码(来自
/usr/include/sys/procfs.h
),您可以使用readelf
: 找到数据的位置大小。 ..因此,理论上可以编写一个代码片段来从该结构中提取命令行,并以一种使整个过程更容易自动化的方式打印出来。当然,您可以只解析
file
的输出:这就是所有部分。这是将所有内容放在一起的起点:
对于我的示例,如果我将此脚本命名为
packcore
并通过sleep
命令在核心文件上运行它,我会得到以下结果:就目前而言,这个脚本非常脆弱;我仅根据此示例输出对 ldd 的输出做出了很多假设。
The core file includes the command from which it was generated. Ideally this will include the full path to the appropriate executable. For example:
Running
ldd
on an ELF binary will show what libraries it depends on:So now I know the executable and the libraries needed to analyze the core dump.
The tricky part here is extracting the executable path from the core file. There doesn't appear to be a good tool for reading this directly. The data is encoded in a prpsinfo structure (from
/usr/include/sys/procfs.h
), and you can find the location size of the data usingreadelf
:...so one could in theory write a code snippet to extract the command line from this structure and print it out in a way that would make this whole process easier to automate. You could, of course, just parse the output of
file
:So that's all the parts. Here's a starting point for putting it all together:
For my example, if I name this script
packcore
and run it on the core file from thesleep
command, I get this:As it stands this script is pretty fragile; I've made lots of assumptions about the output from
ldd
based on only this sample output.下面是执行必要步骤的脚本(仅在 RHEL5 上测试,但也可能在其他地方工作):
Here's a script that does the necessary steps (tested only on RHEL5, but might work elsewhere too):
我为此编写了 shell 脚本。它使用了上面答案中的想法,并添加了一些使用信息和附加命令。将来我可能会添加命令,以便使用 gdb 在 docker 容器中快速调试。
I've written shell script for this. It uses ideas from the answers above and adds some usage information and additional commands. In future I'll possibly add command for quick debugging in docker container with gdb.