Tried to create a small core dump file without all the memory data dump. This question seems to have a good solution. But when I set the mask to be 0 (to exclude all the memory data), there is no core file. If I set the mask to be 0x33, then core file is produced. Any idea why?
#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.
}
UPDATE 1
To clarify, I need the core to have stack and symbols only so the core file will be small enough for me. The mask of 0 was suggested by the question quoted above.