Linux 使用 GDB 生成时如何限制核心转储文件的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7737465/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:38:29  来源:igfitidea点击:

How to limit the size of core dump file when generating it using GDB

linuxgdbarmembedded-linuxcoredump

提问by manav m-n

I am running an embedded application on ARM9 board, where total flash size is 180MB only. I am able to run gdb, but when I do

我在 ARM9 板上运行嵌入式应用程序,其中总闪存大小仅为 180MB。我能跑gdb,但是当我跑的时候

(gdb) generate-core-dump

(gdb) generate-core-dump

I get an error

我收到一个错误

warning: Memory read failed for corefile section, 1048576 bytes at 0x4156c000.
warning: Memory read failed for corefile section, 1048576 bytes at 0x50c00000.
Saved corefile core.5546
The program is running.  Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Tamper Detected
**********OUTSIDE ifelse 0*********
length validation is failed

I also set ulimit -c 50000but still the core dump exceeds this limit. When I do ls -lto check file size it is over 300 MB. In this case how should I limit the size of core dump?

我也设置了ulimit -c 50000但核心转储仍然超过了这个限制。当我ls -l检查文件大小时,它超过 300 MB。在这种情况下,我应该如何限制核心转储的大小?

采纳答案by Employed Russian

GDB does not respect 'ulimit -c', only the kernel does.

GDB 不尊重 'ulimit -c',只有内核尊重。

It's not clear whether you run GDB on target board, or on a development host (and using gdbserver on target). You probably should use the latter, which will allow you to collect full core dump.

不清楚您是在目标板上还是在开发主机上运行 GDB(并在目标上使用 gdbserver)。您可能应该使用后者,这将允许您收集完整的核心转储。

Truncated core dumps are a pain anyway, as often they will not contain exactly the info you need to debug the problem.

无论如何,截断的核心转储都很痛苦,因为它们通常不包含调试问题所需的准确信息。

回答by Thomas Petazzoni

When did you use ulimit -c ? It must be used before starting the program for which you're generating a core dump, and inside the same session.

你什么时候使用 ulimit -c ?它必须在启动要为其生成核心转储的程序之前以及在同一会话中使用。

回答by Tilo

in your shell rc-file:

在你的 shell rc 文件中:

limit coredumpsize 50000             # or whatever limit size you like

that should set the limit for everything, including GDB

这应该为一切设置限制,包括 GDB

Note:

笔记:

If you set it to 0 , you can make sure your home directory is not cluttered with core dump files.

如果将其设置为 0 ,则可以确保您的主目录不会被核心转储文件弄乱。