最小核心转储(仅堆栈跟踪 + 当前帧) [英] Minimal core dump (stack trace + current frame only)

查看:16
本文介绍了最小核心转储(仅堆栈跟踪 + 当前帧)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 Linux 上配置进入核心转储的内容吗?我想获得类似 Windows mini-dumps 的东西(应用程序崩溃时有关堆栈帧的最少信息).我知道您可以使用 ulimit 为核心文件设置最大大小,但这不允许我控制核心内部的内容(即不能保证如果我将限制设置为 64kb例如,将转储堆栈的最后 16 页).

Can I configure what goes into a core dump on Linux? I want to obtain something like the Windows mini-dumps (minimal information about the stack frame when the app crashed). I know you can set a max size for the core files using ulimit, but this does not allow me to control what goes inside the core (i.e. there is no guarantee that if I set the limit to 64kb it will dump the last 16 pages of the stack, for example).

另外,如果可能的话,我想以编程方式(从代码)设置它.我查看了 man core 提到的 /proc/PID/coredump_filter 文件,但对于我的目的来说,它似乎过于粗略.

Also, I would like to set it in a programmatic way (from code), if possible. I have looked at the /proc/PID/coredump_filter file mentioned by man core, but it seems too coarse grained for my purposes.

提供一点背景信息:出于多种原因,我需要很小的核心文件:我需要通过网络为众多(数千)客户收集它们;此外,这些是带有少量 SD 卡的嵌入式设备,以及用于网络连接的 GPRS 调制解调器.所以任何超过 200k 的东西都是不可能的.

To provide a little context: I need tiny core files, for multiple reasons: I need to collect them over the network, for numerous (thousands) of clients; furthermore, these are embedded devices with little SD cards, and GPRS modems for the network connection. So anything above ~200k is out of question.

我正在开发一个运行 linux 2.6.24 的嵌入式设备.处理器是 PowerPC.不幸的是,powerpc-linux 目前在 breakpad 中支持,所以 google breakpad 不是一个选项

I am working on an embedded device which runs linux 2.6.24. The processor is PowerPC. Unfortunately, powerpc-linux is not supported in breakpad at the moment, so google breakpad is not an option

推荐答案

我通过两种方式解决"了这个问题:

I have "solved" this issue in two ways:

  1. 我为 SIGSEGV 安装了一个信号处理程序,并使用 backtrace/backtrace_symbols 打印出堆栈跟踪.我用 -rdynamic 编译了我的代码,所以即使在剥离调试信息之后,我仍然会得到一个带有有意义名称的回溯(同时保持可执行文件足够紧凑).
    我剥离了调试信息并将其放在一个单独的文件中,我将使用 strip 将其存储在安全的地方;从那里,我将使用 add22line 和从回溯(地址)中保存的信息来了解问题发生在哪里.这样我只需要存储几个字节.
  2. 另外,我发现我可以使用/proc/self/coredump_filter 不转储内存(将其内容设置为0"):只有线程和 proc 信息、寄存器、堆栈跟踪等保存在核心中.在这个答案
  3. 中查看更多信息
  1. I installed a signal handler for SIGSEGV, and used backtrace/backtrace_symbols to print out the stack trace. I compiled my code with -rdynamic, so even after stripping the debug info I still get a backtrace with meaningful names (while keeping the executable compact enough).
    I stripped the debug info and put it in a separate file, which I will store somewhere safe, using strip; from there, I will use add22line with the info saved from the backtrace (addresses) to understand where the problem happened. This way I have to store only a few bytes.
  2. Alternatively, I found I could use the /proc/self/coredump_filter to dump no memory (setting its content to "0"): only thread and proc info, registers, stacktrace etc. are saved in the core. See more in this answer

我仍然丢失了可能很宝贵的信息(全局和局部变量内容、参数..).我可以很容易地找出要转储的页面,但不幸的是,没有办法为正常的核心转储指定转储这些页面"(除非你愿意去修补 maydump() 内核中的函数).

I still lose information that could be precious (global and local variable(s) content, params..). I could easily figure out which page(s) to dump, but unfortunately there is no way to specify a "dump-these-pages" for normal core dumps (unless you are willing to go and patch the maydump() function in the kernel).

目前,我对有 2 个解决方案感到非常满意(总比没有好.)我的下一步行动是:

For now, I'm quite happy with there 2 solutions (it is better than nothing..) My next moves will be:

  • 看看将 Breakpad 移植到 powerpc-linux 有多么困难:已经有 powerpc-darwin 和 i386-linux 所以.. 有多难?:)
  • 尝试使用 google-coredumper 在当前的 ESP(应该给我本地和参数)和&some_global"周围(应该给我全局).
  • see how difficult would be to port Breakpad to powerpc-linux: there are already powerpc-darwin and i386-linux so.. how hard can it be? :)
  • try to use google-coredumper to dump only a few pages around the current ESP (that should give me locals and parameters) and around "&some_global" (that should give me globals).

这篇关于最小核心转储(仅堆栈跟踪 + 当前帧)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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