mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-08 10:18:13 +01:00
0f9a540c8c
Program test-coredump-unwind was modified to map backing files based on virtual addresses instead of segment numbers. The crasher.c is a program that essentially calls some functions and then writes to invalid address causing a crash. Before that, it detects which executables are mapped to which virtual addresses and writes this information to a file suitable for consumption by test-coredump-unwind. The mapping information is obtained form /proc/self/maps, so currently it only works on linux. The test itself is a shell script, which first runs the program and then runs test-coredump-unwind on the resulting core and address space map file to check whether the stack trace obtained from the dump roughly corresponds to what it should look like. Signed-off-by: Martin Milata <mmilata@redhat.com>
63 lines
1 KiB
C
63 lines
1 KiB
C
/* This program should crash and produce coredump */
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
void a(void) __attribute__((noinline));
|
|
void b(int x) __attribute__((noinline));
|
|
|
|
#ifdef __linux__
|
|
void write_maps(char *fname)
|
|
{
|
|
char buf[512], path[128];
|
|
char exec;
|
|
uintmax_t addr;
|
|
FILE *maps = fopen("/proc/self/maps", "r");
|
|
FILE *out = fopen(fname, "w");
|
|
|
|
if (!maps || !out)
|
|
exit(EXIT_FAILURE);
|
|
|
|
while (fgets(buf, sizeof(buf), maps))
|
|
{
|
|
if (sscanf(buf, "%jx-%*jx %*c%*c%c%*c %*x %*s %*d /%126[^\n]", &addr, &exec, path+1) != 3)
|
|
continue;
|
|
|
|
if (exec != 'x')
|
|
continue;
|
|
|
|
path[0] = '/';
|
|
fprintf(out, "0x%jx:%s ", addr, path);
|
|
}
|
|
fprintf(out, "\n");
|
|
|
|
fclose(out);
|
|
fclose(maps);
|
|
}
|
|
#else
|
|
#error Port me
|
|
#endif
|
|
|
|
void a(void)
|
|
{
|
|
*(int *)NULL = 42;
|
|
}
|
|
|
|
void b(int x)
|
|
{
|
|
if (x)
|
|
a();
|
|
else
|
|
b(1);
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
if (argc > 1)
|
|
write_maps(argv[1]);
|
|
b(0);
|
|
return 0;
|
|
}
|
|
|