2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-24 19:04:02 +08:00
artiq/lit-test/libartiq_support/artiq_terminate.c

30 lines
888 B
C
Raw Normal View History

2015-07-27 10:46:43 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unwind.h>
#include <artiq_personality.h>
#define __USE_GNU
#include <dlfcn.h>
void __artiq_terminate(struct artiq_exception *exn,
struct artiq_backtrace_item *backtrace,
size_t backtrace_size) {
2015-07-27 10:46:43 +08:00
printf("Uncaught %s: %s (%"PRIi64", %"PRIi64", %"PRIi64")\n"
2015-07-27 14:10:20 +08:00
"at %s:%"PRIi32":%"PRIi32"\n",
2015-07-27 10:46:43 +08:00
exn->name, exn->message,
exn->param[0], exn->param[1], exn->param[1],
exn->file, exn->line, exn->column + 1);
for(size_t i = 0; i < backtrace_size; i++) {
Dl_info info;
if(dladdr((void*) backtrace[i].function, &info) && info.dli_sname) {
printf("at %s+%p\n", info.dli_sname, (void*)backtrace[i].offset);
} else {
printf("at %p+%p\n", (void*)backtrace[i].function, (void*)backtrace[i].offset);
}
}
2015-07-27 10:46:43 +08:00
exit(1);
}