Linux 中的核心转储 [英] Core dump in Linux

查看:15
本文介绍了Linux 中的核心转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的进程崩溃时创建一个核心转储.目前我正在遵循这种方法:

I want to create a core dump whenever my process crashes. Currently I am following this approach:

  1. 使用 gcc/g++ 的-g"构建程序的特殊调试"版本.
  2. 执行ulimit -c unlimited"
  3. 现在我们在程序崩溃时获取核心转储.

但我想尽量减少步骤数,以便:

But I want to minimize the number of steps so that:

  • 应始终创建核心转储.即使它是发布"构建.不应要求用户手动执行命令ulimit -c unlimited".
  • 核心转储的回溯应该能够给出调用的文件、函数、行号.这是人类可读形式的堆栈跟踪.
  • 我不想使用-g"将程序构建为调试版本.或者至少它不应该包含生成人类可读堆栈跟踪不需要的任何其他调试信息.因为这将是程序的发布版本.

所以我有两个问题:

  1. 如何在程序的发布"版本中创建核心转储?
  2. 总是.无需手动执行ulimit -c unlimited"

推荐答案

通常的解决方案是使用 -g 构建并在发布文件之前剥离调试信息.寻找剥离"命令.您保留包含调试信息的文件,并使用它来调试您从客户那里获得的核心转储.

The usual solution is to build with -g and to strip off the debug information before releasing the file. Look for the 'strip' command. You keep the file with debug information and use it to debug core dumps you get from customers.

如果您想在用户机器上打印人类可读的回溯,您需要分发带有(一些)调试信息的二进制文件.在 glibc 中寻找 'backtrace()' 函数.

If you want to print the human readable backtrace on the users machine you'll need to distribute binaries with (some) debug information. Look for the 'backtrace()' function in glibc.

请注意,即使您的二进制文件不包含调试信息,也会创建核心转储(如果 ulimit 设置得当).

Note that core dumps will be created (if ulimit is set appropriately) even if your binary doesn't contain debug information.

确保创建核心转储的最佳方法可能是在运行二进制文件之前从设置 ulimit 的脚本执行二进制文件.

The best way to ensure the creation of a core dump is probably to execute your binary from a script which sets ulimit before running the binary.

这篇关于Linux 中的核心转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆