Add edie() and eerr() functions

These emit a detailed message of the state of the emulator on failure.
This commit is contained in:
Rodrigo Arias 2022-09-07 14:50:42 +02:00
parent 666075e8cd
commit 306a64999a
2 changed files with 42 additions and 0 deletions

39
emu.c
View File

@ -17,6 +17,7 @@
#define _POSIX_C_SOURCE 200112L
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@ -1178,6 +1179,44 @@ emu_destroy(struct ovni_emu *emu)
free(emu->global_thread);
}
void
edie(struct ovni_emu *emu, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "fatal: ");
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "fatal: while evaluating the event %c%c%c with clock=%ld in thread=%d\n",
emu->cur_ev->header.model,
emu->cur_ev->header.category,
emu->cur_ev->header.value,
emu->cur_ev->header.clock,
emu->cur_thread->tid);
abort();
}
void
eerr(struct ovni_emu *emu, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "fatal: ");
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "fatal: while evaluating the event %c%c%c with clock=%ld in thread=%d\n",
emu->cur_ev->header.model,
emu->cur_ev->header.category,
emu->cur_ev->header.value,
emu->cur_ev->header.clock,
emu->cur_thread->tid);
}
int
main(int argc, char *argv[])
{

3
emu.h
View File

@ -547,6 +547,9 @@ struct ovni_emu {
/* Emulator function declaration */
void edie(struct ovni_emu *emu, const char* fmt, ...);
void eerr(struct ovni_emu *emu, const char* fmt, ...);
void hook_init_ovni(struct ovni_emu *emu);
void hook_pre_ovni(struct ovni_emu *emu);