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

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

问题描述

我想要在我的进程崩溃时创建一个核心转储。目前我采用这种方法:


  1. 使用gcc / g ++的-g创建一个特殊的调试版本的程序。 / li>
  2. 执行ulimit -c unlimited

  3. 现在,只要程序崩溃,我们就得到核心转储。

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




  • 创建。即使它是释放构建。不应该要求用户手动执行命令 ulimit -c unlimited

  • 核心转储的backtrace应该能够给出文件,函数,调用的行号。这是以人类可读的形式的堆栈跟踪。

  • 我不想使用-g将程序构建为调试版。或者至少它不应该包含产生人类可读堆栈跟踪所不需要的任何其他调试信息。因为这是程序的发布版本。



所以我有两个问题:


  1. 如何在程序的发布版本中创建核心转储?

  2. 始终。无需手动执行 ulimit -c unlimited


解决方案

通常的解决方案是使用-g进行构建,并在释放文件之前去除调试信息。查找strip命令。
保存带有调试信息的文件,并使用它来调试从客户那里获得的核心转储。



如果要在用户上打印人类可读的backtrace机器,你需要用(一些)调试信息分发二进制文件。
查找glibc中的'backtrace()'函数。



注意,如果ulimit设置正确,不包含调试信息。



确保创建核心转储的最佳方法是从运行二进制文件之前设置ulimit的脚本执行二进制文件。 / p>

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

  1. Build a special "debug" version of the program using "-g" of gcc/g++.
  2. Execute "ulimit -c unlimited"
  3. Now we get the core dump whenever the program crashes.

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

  • Core dump should always get created. Even if it is "release" build. The user should not be asked to execute the command "ulimit -c unlimited" manually.
  • That core dump's backtrace should be able to give the file, function, line number of the calls. That is stack trace in a human readable form.
  • I don't want to build the program as a debug build with "-g". Or at least it shouldn't contain any other debugging information which is not required to produce the human readable stack trace. Because this would be a release build of the program.

So I have two questions:

  1. How to create a core dump in the "release" build of a program?
  2. Always. Without manually executing the "ulimit -c unlimited"

解决方案

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.

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.

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

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天全站免登陆