【发布时间】:2015-11-21 00:39:29
【问题描述】:
试图创建一个没有所有内存数据转储的小型核心转储文件。 这个question 似乎有一个很好的解决方案。但是当我将掩码设置为0(排除所有内存数据)时,没有核心文件。如果我将掩码设置为 0x33,则生成核心文件。知道为什么吗?
#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
void baz() {
int *foo = (int*)-1; // make a bad pointer
printf("%d\n", *foo); // causes segfault
}
void bar() { baz(); }
void foo() { bar(); }
int main(int argc, char **argv) {
FILE *fp = fopen("/proc/self/coredump_filter", "wb");
if (!fp) {
printf("Failed to open /proc/self/coredump_filter\n"); exit(0);
}
int mask = 0;
fprintf(fp, "%08x\n", mask);
fclose(fp);
foo(); // this will call foo, bar, and baz. baz segfaults.
}
更新 1
为了澄清,我只需要核心有堆栈和符号,这样核心文件对我来说就足够小了。上面引用的问题建议使用 0 的掩码。
【问题讨论】: