From 68fc8b0eba299c3a7fa3833ace2c94933a26749e Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 29 Jan 2024 18:53:11 +0100 Subject: [PATCH] Encode ovnievents output for HTML --- doc/user/emulation/events.md | 6 +-- src/emu/ovnievents.c | 75 +++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/doc/user/emulation/events.md b/doc/user/emulation/events.md index e1ee7ae..0a95bdd 100644 --- a/doc/user/emulation/events.md +++ b/doc/user/emulation/events.md @@ -8,7 +8,7 @@ Built on Jan 29 2024. List of events for the model *nanos6* with identifier **`6`** at version `1.0.0`:
6Yc+(u32 typeid, str label)
-
creates task type %{typeid} with label "%{label}"
+
creates task type %{typeid} with label "%{label}"
6Tc(u32 taskid, u32 typeid)
creates task %{taskid} with type %{typeid}
6Tx(u32 taskid)
@@ -400,7 +400,7 @@ List of events for the model *ovni* with identifier **`O`** at version `1.0.0`:
OAr(i32 cpu, i32 tid)
changes the affinity of thread %{tid} to CPU %{cpu}
OAs(i32 cpu)
-
switches it's own affinity to the CPU %{cpu}
+
switches it's own affinity to the CPU %{cpu}
OB.
emits a burst event to measure latency
OHC(i32 cpu, u64 tag)
@@ -498,7 +498,7 @@ List of events for the model *nosv* with identifier **`V`** at version `1.0.0`:
VTr(u32 taskid)
resumes the task %{taskid}
VYc+(u32 typeid, str label)
-
creates task type %{typeid} with label "%{label}"
+
creates task type %{typeid} with label "%{label}"
VSr
receives a task from another thread
VSs
diff --git a/src/emu/ovnievents.c b/src/emu/ovnievents.c index 3e1f14f..64ea902 100644 --- a/src/emu/ovnievents.c +++ b/src/emu/ovnievents.c @@ -16,19 +16,66 @@ #include "stream.h" #include "trace.h" -static void +static int +html_encode(char *dst, int ndst, const char *src) +{ + int j = 0; + int nsrc = strlen(src); + + for (int i = 0; i < nsrc; i++) { + /* Simple check */ + if (j + 10 >= ndst) { + err("not enough room"); + return -1; + } + + int c = src[i]; + switch (c) { + case '&': strcpy(&dst[j], "&"); j += 5; break; + case '"': strcpy(&dst[j], """); j += 6; break; + case '\'': strcpy(&dst[j], "'"); j += 6; break; + case '<': strcpy(&dst[j], "<"); j += 4; break; + case '>': strcpy(&dst[j], ">"); j += 4; break; + default: dst[j++] = c; break; + } + } + + dst[j] = '\0'; + + return 0; +} + +static int print_event(struct model_spec *spec, long i) { struct ev_decl *evdecl = &spec->evlist[i]; struct ev_spec *evspec = &spec->evspec->alloc[i]; - const char *name = evspec->mcv; + char name[16]; + if (html_encode(name, 16, evspec->mcv) != 0) { + err("html_encode failed for %s", evspec->mcv); + return -1; + } - printf("
%s
\n", name, name, evdecl->signature); - printf("
%s
\n", evdecl->description); + char signature[1024]; + if (html_encode(signature, 1024, evdecl->signature) != 0) { + err("html_encode failed for %s", evdecl->signature); + return -1; + } + + char desc[1024]; + if (html_encode(desc, 1024, evdecl->description) != 0) { + err("html_encode failed for %s", evdecl->description); + return -1; + } + + printf("
%s
\n", name, name, signature); + printf("
%s
\n", desc); + + return 0; } -static void +static int print_model(struct model_spec *spec) { printf("\n"); @@ -38,9 +85,16 @@ print_model(struct model_spec *spec) spec->name, spec->model, spec->version); printf("
\n"); - for (long j = 0; j < spec->evspec->nevents; j++) - print_event(spec, j); + for (long j = 0; j < spec->evspec->nevents; j++) { + if (print_event(spec, j) != 0) { + err("cannot print event %d", j); + return -1; + } + } + printf("
\n"); + + return 0; } int @@ -54,7 +108,7 @@ main(void) /* Register all the models */ if (models_register(&model) != 0) { err("failed to register models"); - return -1; + return 1; } printf("# Emulator events\n"); @@ -66,7 +120,10 @@ main(void) if (!model.registered[i]) continue; - print_model(model.spec[i]); + if (print_model(model.spec[i]) != 0) { + err("cannot print model %c events", i); + return 1; + } } return 0;