Switch to edie() for errors

This commit is contained in:
Rodrigo Arias 2022-09-13 14:22:44 +02:00
parent 999862e530
commit f990cd668f
6 changed files with 70 additions and 65 deletions

View File

@ -81,9 +81,8 @@ context_switch(struct ovni_emu *emu)
chan_pop(chan, ST_KERNEL_CSOUT); chan_pop(chan, ST_KERNEL_CSOUT);
break; break;
default: default:
err("unexpected value '%c' (expecting 'O' or 'I')\n", edie(emu, "unexpected value '%c' (expecting 'O' or 'I')\n",
emu->cur_ev->header.value); emu->cur_ev->header.value);
abort();
} }
} }
@ -91,13 +90,16 @@ void
hook_pre_kernel(struct ovni_emu *emu) hook_pre_kernel(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.model != 'K') if(emu->cur_ev->header.model != 'K')
die("hook_pre_kernel: unexpected event with model %c\n", edie(emu, "hook_pre_kernel: unexpected event with model %c\n",
emu->cur_ev->header.model); emu->cur_ev->header.model);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {
case 'C': context_switch(emu); break; case 'C':
default: context_switch(emu);
break; break;
default:
edie(emu, "hook_pre_kernel: unexpected event with category %c\n",
emu->cur_ev->header.category);
} }
} }

View File

@ -104,13 +104,13 @@ chan_task_running(struct ovni_emu *emu, struct task *task, char tr)
proc = emu->cur_proc; proc = emu->cur_proc;
if(task->id == 0) if(task->id == 0)
die("task id cannot be 0\n"); edie(emu, "task id cannot be 0\n");
if(task->type->gid == 0) if(task->type->gid == 0)
die("task type gid cannot be 0\n"); edie(emu, "task type gid cannot be 0\n");
if(proc->appid <= 0) if(proc->appid <= 0)
die("app id must be positive\n"); edie(emu, "app id must be positive\n");
chan_set(&th->chan[CHAN_NANOS6_TASKID], task->id); chan_set(&th->chan[CHAN_NANOS6_TASKID], task->id);
chan_set(&th->chan[CHAN_NANOS6_TYPE], task->type->gid); chan_set(&th->chan[CHAN_NANOS6_TYPE], task->type->gid);
@ -130,19 +130,19 @@ chan_task_switch(struct ovni_emu *emu,
struct ovni_ethread *th = emu->cur_thread; struct ovni_ethread *th = emu->cur_thread;
if(!prev || !next) if(!prev || !next)
die("cannot switch to or from a NULL task\n"); edie(emu, "cannot switch to or from a NULL task\n");
if(prev == next) if(prev == next)
die("cannot switch to the same task\n"); edie(emu, "cannot switch to the same task\n");
if(next->id == 0) if(next->id == 0)
die("next task id cannot be 0\n"); edie(emu, "next task id cannot be 0\n");
if(next->type->gid == 0) if(next->type->gid == 0)
die("next task type id cannot be 0\n"); edie(emu, "next task type id cannot be 0\n");
if(prev->thread != next->thread) if(prev->thread != next->thread)
die("cannot switch to a task of another thread\n"); edie(emu, "cannot switch to a task of another thread\n");
/* No need to change the rank as we will switch to tasks from /* No need to change the rank as we will switch to tasks from
* same thread */ * same thread */
@ -193,7 +193,7 @@ expand_transition_value(struct ovni_emu *emu, int was_running, int runs_now)
/* Ensure we don't clobber the value */ /* Ensure we don't clobber the value */
if(tr == 'X' || tr == 'E') if(tr == 'X' || tr == 'E')
die("unexpected event value %c\n", tr); edie(emu, "unexpected event value %c\n", tr);
/* Modify the event value to detect nested transitions */ /* Modify the event value to detect nested transitions */
if(tr == 'x' && was_running) if(tr == 'x' && was_running)
@ -253,7 +253,7 @@ static void
create_task(struct ovni_emu *emu) create_task(struct ovni_emu *emu)
{ {
if(ovni_payload_size(emu->cur_ev) != 8) if(ovni_payload_size(emu->cur_ev) != 8)
die("cannot create task: unexpected payload size\n"); edie(emu, "cannot create task: unexpected payload size\n");
uint32_t task_id = emu->cur_ev->payload.u32[0]; uint32_t task_id = emu->cur_ev->payload.u32[0];
uint32_t type_id = emu->cur_ev->payload.u32[1]; uint32_t type_id = emu->cur_ev->payload.u32[1];
@ -285,9 +285,10 @@ pre_task(struct ovni_emu *emu)
static void static void
pre_type(struct ovni_emu *emu) pre_type(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.value != 'c') uint8_t value = emu->cur_ev->header.value;
edie(emu, "unexpected event value %c\n",
emu->cur_ev->header.value); if(value != 'c')
edie(emu, "unexpected event value %c\n", value);
if((emu->cur_ev->header.flags & OVNI_EV_JUMBO) == 0) if((emu->cur_ev->header.flags & OVNI_EV_JUMBO) == 0)
edie(emu, "expecting a jumbo event\n"); edie(emu, "expecting a jumbo event\n");
@ -478,6 +479,9 @@ check_affinity(struct ovni_emu *emu)
if(cpu->nrunning_threads > 1) if(cpu->nrunning_threads > 1)
{ {
eerr(emu, "cpu %s has more than one thread running\n", cpu->name); eerr(emu, "cpu %s has more than one thread running\n", cpu->name);
/* Only abort in linter mode so we can still see the
* trace to find out what was happening */
if(emu->enable_linter) if(emu->enable_linter)
abort(); abort();
} }
@ -487,13 +491,12 @@ void
hook_pre_nanos6(struct ovni_emu *emu) hook_pre_nanos6(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.model != '6') if(emu->cur_ev->header.model != '6')
die("hook_pre_nanos6: unexpected event with model %c\n", edie(emu, "hook_pre_nanos6: unexpected event with model %c\n",
emu->cur_ev->header.model); emu->cur_ev->header.model);
if(!emu->cur_thread->is_active) { if(!emu->cur_thread->is_active) {
eerr(emu, "hook_pre_nanos6: current thread %d not active\n", edie(emu, "hook_pre_nanos6: current thread %d not active\n",
emu->cur_thread->tid); emu->cur_thread->tid);
return;
} }
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)

View File

@ -80,8 +80,8 @@ pre_subsystem(struct ovni_emu *emu, int st)
chan_pop(chan, st); chan_pop(chan, st);
break; break;
default: default:
err("unexpected value '%c' (expecting '[' or ']')\n", emu->cur_ev->header.value); edie(emu, "unexpected value '%c' (expecting '[' or ']')\n",
abort(); emu->cur_ev->header.value);
} }
} }
@ -89,11 +89,11 @@ void
hook_pre_nodes(struct ovni_emu *emu) hook_pre_nodes(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.model != 'D') if(emu->cur_ev->header.model != 'D')
die("hook_pre_nodes: unexpected event with model %c\n", edie(emu, "hook_pre_nodes: unexpected event with model %c\n",
emu->cur_ev->header.model); emu->cur_ev->header.model);
if(!emu->cur_thread->is_running) if(!emu->cur_thread->is_running)
die("hook_pre_nodes: current thread %d not running\n", edie(emu, "hook_pre_nodes: current thread %d not running\n",
emu->cur_thread->tid); emu->cur_thread->tid);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)

View File

@ -111,13 +111,13 @@ chan_task_running(struct ovni_emu *emu, struct task *task)
proc = emu->cur_proc; proc = emu->cur_proc;
if(task->id == 0) if(task->id == 0)
die("task id cannot be 0\n"); edie(emu, "task id cannot be 0\n");
if(task->type->gid == 0) if(task->type->gid == 0)
die("task type gid cannot be 0\n"); edie(emu, "task type gid cannot be 0\n");
if(proc->appid <= 0) if(proc->appid <= 0)
die("app id must be positive\n"); edie(emu, "app id must be positive\n");
chan_set(&th->chan[CHAN_NOSV_TASKID], task->id); chan_set(&th->chan[CHAN_NOSV_TASKID], task->id);
chan_set(&th->chan[CHAN_NOSV_TYPE], task->type->gid); chan_set(&th->chan[CHAN_NOSV_TYPE], task->type->gid);
@ -136,19 +136,19 @@ chan_task_switch(struct ovni_emu *emu,
struct ovni_ethread *th = emu->cur_thread; struct ovni_ethread *th = emu->cur_thread;
if(!prev || !next) if(!prev || !next)
die("cannot switch to or from a NULL task\n"); edie(emu, "cannot switch to or from a NULL task\n");
if(prev == next) if(prev == next)
die("cannot switch to the same task\n"); edie(emu, "cannot switch to the same task\n");
if(next->id == 0) if(next->id == 0)
die("next task id cannot be 0\n"); edie(emu, "next task id cannot be 0\n");
if(next->type->gid == 0) if(next->type->gid == 0)
die("next task type id cannot be 0\n"); edie(emu, "next task type id cannot be 0\n");
if(prev->thread != next->thread) if(prev->thread != next->thread)
die("cannot switch to a task of another thread\n"); edie(emu, "cannot switch to a task of another thread\n");
/* No need to change the rank or app ID, as we can only switch /* No need to change the rank or app ID, as we can only switch
* to tasks of the same thread */ * to tasks of the same thread */
@ -166,7 +166,7 @@ static void
update_task_state(struct ovni_emu *emu) update_task_state(struct ovni_emu *emu)
{ {
if(ovni_payload_size(emu->cur_ev) < 4) if(ovni_payload_size(emu->cur_ev) < 4)
die("missing task id in payload\n"); edie(emu, "missing task id in payload\n");
uint32_t task_id = emu->cur_ev->payload.u32[0]; uint32_t task_id = emu->cur_ev->payload.u32[0];
@ -179,7 +179,7 @@ update_task_state(struct ovni_emu *emu)
struct task *task = task_find(info->tasks, task_id); struct task *task = task_find(info->tasks, task_id);
if(task == NULL) if(task == NULL)
die("cannot find task with id %u\n", task_id); edie(emu, "cannot find task with id %u\n", task_id);
switch(emu->cur_ev->header.value) switch(emu->cur_ev->header.value)
{ {
@ -188,7 +188,7 @@ update_task_state(struct ovni_emu *emu)
case 'p': task_pause(stack, task); break; case 'p': task_pause(stack, task); break;
case 'r': task_resume(stack, task); break; case 'r': task_resume(stack, task); break;
default: default:
die("unexpected Nanos6 task event value %c\n", edie(emu, "unexpected Nanos6 task event value %c\n",
emu->cur_ev->header.value); emu->cur_ev->header.value);
} }
} }
@ -200,7 +200,7 @@ expand_transition_value(struct ovni_emu *emu, int was_running, int runs_now)
/* Ensure we don't clobber the value */ /* Ensure we don't clobber the value */
if(tr == 'X' || tr == 'E') if(tr == 'X' || tr == 'E')
die("unexpected event value %c\n", tr); edie(emu, "unexpected event value %c\n", tr);
/* Modify the event value to detect nested transitions */ /* Modify the event value to detect nested transitions */
if(tr == 'x' && was_running) if(tr == 'x' && was_running)
@ -225,7 +225,7 @@ update_task_channels(struct ovni_emu *emu,
case 'X': chan_task_switch(emu, prev, next); break; case 'X': chan_task_switch(emu, prev, next); break;
case 'E': chan_task_switch(emu, prev, next); break; case 'E': chan_task_switch(emu, prev, next); break;
default: default:
die("unexpected transition value %c\n", tr); edie(emu, "unexpected transition value %c\n", tr);
} }
} }
@ -254,7 +254,7 @@ static void
create_task(struct ovni_emu *emu) create_task(struct ovni_emu *emu)
{ {
if(ovni_payload_size(emu->cur_ev) != 8) if(ovni_payload_size(emu->cur_ev) != 8)
die("cannot create task: unexpected payload size\n"); edie(emu, "cannot create task: unexpected payload size\n");
uint32_t task_id = emu->cur_ev->payload.u32[0]; uint32_t task_id = emu->cur_ev->payload.u32[0];
uint32_t type_id = emu->cur_ev->payload.u32[1]; uint32_t type_id = emu->cur_ev->payload.u32[1];
@ -279,7 +279,7 @@ pre_task(struct ovni_emu *emu)
update_task(emu); update_task(emu);
break; break;
default: default:
die("unexpected event value %c\n", edie(emu, "unexpected task event value %c\n",
emu->cur_ev->header.value); emu->cur_ev->header.value);
} }
} }
@ -288,11 +288,11 @@ static void
pre_type(struct ovni_emu *emu) pre_type(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.value != 'c') if(emu->cur_ev->header.value != 'c')
die("unexpected event value %c\n", edie(emu, "unexpected event value %c\n",
emu->cur_ev->header.value); emu->cur_ev->header.value);
if((emu->cur_ev->header.flags & OVNI_EV_JUMBO) == 0) if((emu->cur_ev->header.flags & OVNI_EV_JUMBO) == 0)
die("expecting a jumbo event\n"); edie(emu, "expecting a jumbo event\n");
uint8_t *data = &emu->cur_ev->payload.jumbo.data[0]; uint8_t *data = &emu->cur_ev->payload.jumbo.data[0];
uint32_t typeid = *(uint32_t *) data; uint32_t typeid = *(uint32_t *) data;
@ -447,9 +447,8 @@ check_affinity(struct ovni_emu *emu)
if(cpu->nrunning_threads > 1) if(cpu->nrunning_threads > 1)
{ {
err("cpu %s has more than one thread running\n", edie(emu, "cpu %s has more than one thread running\n",
cpu->name); cpu->name);
abort();
} }
} }
@ -457,11 +456,11 @@ void
hook_pre_nosv(struct ovni_emu *emu) hook_pre_nosv(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.model != 'V') if(emu->cur_ev->header.model != 'V')
die("hook_pre_nosv: unexpected event with model %c\n", edie(emu, "hook_pre_nosv: unexpected event with model %c\n",
emu->cur_ev->header.model); emu->cur_ev->header.model);
if(!emu->cur_thread->is_active) if(!emu->cur_thread->is_active)
die("hook_pre_nosv: current thread %d not active\n", edie(emu, "hook_pre_nosv: current thread %d not active\n",
emu->cur_thread->tid); emu->cur_thread->tid);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)

View File

@ -312,7 +312,7 @@ pre_thread_execute(struct ovni_emu *emu, struct ovni_ethread *th)
/* The thread cannot be already running */ /* The thread cannot be already running */
if(th->state == TH_ST_RUNNING) if(th->state == TH_ST_RUNNING)
die("pre_thread_execute: thread %d already running\n", edie(emu, "pre_thread_execute: thread %d already running\n",
th->tid); th->tid);
cpuid = emu->cur_ev->payload.i32[0]; cpuid = emu->cur_ev->payload.i32[0];
@ -456,11 +456,11 @@ pre_affinity_set(struct ovni_emu *emu)
cpuid = emu->cur_ev->payload.i32[0]; cpuid = emu->cur_ev->payload.i32[0];
if(th->cpu == NULL) if(th->cpu == NULL)
die("pre_affinity_set: thread %d doesn't have a CPU\n", edie(emu, "pre_affinity_set: thread %d doesn't have a CPU\n",
th->tid); th->tid);
if(!th->is_active) if(!th->is_active)
die("pre_affinity_set: thread %d is not active\n", edie(emu, "pre_affinity_set: thread %d is not active\n",
th->tid); th->tid);
/* Migrate current cpu to the one at cpuid */ /* Migrate current cpu to the one at cpuid */
@ -521,16 +521,16 @@ pre_affinity_remote(struct ovni_emu *emu)
/* The remote_th cannot be in states dead or unknown */ /* The remote_th cannot be in states dead or unknown */
if(remote_th->state == TH_ST_DEAD) if(remote_th->state == TH_ST_DEAD)
die("pre_affinity_remote: remote thread %d in state DEAD\n", edie(emu, "pre_affinity_remote: remote thread %d in state DEAD\n",
remote_th->tid); remote_th->tid);
if(remote_th->state == TH_ST_UNKNOWN) if(remote_th->state == TH_ST_UNKNOWN)
die("pre_affinity_remote: remote thread %d in state UNKNOWN\n", edie(emu, "pre_affinity_remote: remote thread %d in state UNKNOWN\n",
remote_th->tid); remote_th->tid);
/* It must have an assigned CPU */ /* It must have an assigned CPU */
if(remote_th->cpu == NULL) if(remote_th->cpu == NULL)
die("pre_affinity_remote: remote thread %d has no CPU\n", edie(emu, "pre_affinity_remote: remote thread %d has no CPU\n",
remote_th->tid); remote_th->tid);
/* Migrate current cpu to the one at cpuid */ /* Migrate current cpu to the one at cpuid */

View File

@ -78,7 +78,8 @@ pre_tampi_mode(struct ovni_emu *emu, int state)
chan_pop(&th->chan[CHAN_TAMPI_MODE], state); chan_pop(&th->chan[CHAN_TAMPI_MODE], state);
break; break;
default: default:
abort(); edie(emu, "unexpected event value %c for tampi mode\n",
emu->cur_ev->header.value);
} }
} }
@ -86,7 +87,7 @@ void
hook_pre_tampi(struct ovni_emu *emu) hook_pre_tampi(struct ovni_emu *emu)
{ {
if(emu->cur_ev->header.model != 'T') if(emu->cur_ev->header.model != 'T')
die("hook_pre_tampi: unexpected event with model %c\n", edie(emu, "hook_pre_tampi: unexpected event with model %c\n",
emu->cur_ev->header.model); emu->cur_ev->header.model);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)