Captain Bob's CI directive (2026-11-17) and the design he ruled point by point (docs/v4.0.0/plans/2026-11-17-emergency-diagnostic-build.md). - v4/system/dump.c, v4/include/v4/dump.h: what a node was doing when it stopped -- the fault's kind, address and count; P A B; the data stack, T first; the return stack, R first, each entry named by the word it falls in (the backtrace; ROM and below-every-word said so); the running line. Bounded dictionary walk; no C library. Ruled: every build, on a stop only (a handled fault keeps its line). - kernel/src/v4/sk_v4.c: the dump before each of the three halts (not started; POST's blocks not let go; a node stopped on a fault) -- Hera and any stopped node. kernel/Makefile links dump.o. - scripts/nightly.sh diagnose [<stage>]: after a failed stage, that configuration built again with EMERGENCY_CONSOLE_ENABLED=1 -- build only, nothing booted (ruled) -- its artifacts kept in logs/<TS>/diagnose/ only from a build that passed, with a README saying how to launch it with --log-level=debug. Always exits 0: evidence, never a result. The protocol runs it after a failed stage and still exits with that stage's code; acceptance.yml, nightly.yml and release.yml run it `if: failure()`, before the logs are kept. Any failed stage triggers it (ruled). - capsules/BLOCK_MAP.md: as the build writes it -- the v4:physics.4th row, missing since28ffed8f(ruled: commit the regenerated map). - Test first: test_dump.c failed with no dump.c (logs/20261117-dump), then 15 checks at both widths and under ASan+UBSan. The diagnose stage: a real EMERGENCY amd64 build; a failing build exits 0 and keeps no artifacts (a defect found and fixed this way); the protocol path keeps the stage's exit. - Also the write-up of the regression at046ce0be, for ruling. Not yet: acceptance on a clean tree (the next run); the kernel's stop wiring is compile-tested only -- no boot reaches a stop on purpose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
120 lines
4.1 KiB
C
120 lines
4.1 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/* dump.c -- what a node was doing when it stopped. See v4/dump.h. */
|
|
#include "v4/dump.h"
|
|
#include "v4/stack.h"
|
|
|
|
static void say(v4_dump_out out, void *self, const char *s)
|
|
{
|
|
unsigned n = 0;
|
|
while (s[n]) n++;
|
|
out(self, s, n);
|
|
}
|
|
|
|
static void say_num(v4_dump_out out, void *self, v4_cell v)
|
|
{
|
|
char buf[24];
|
|
unsigned i = sizeof buf;
|
|
v4_ucell u = v < 0 ? (v4_ucell)0 - (v4_ucell)v : (v4_ucell)v;
|
|
do { buf[--i] = (char)('0' + (int)(u % 10u)); u /= 10u; } while (u && i > 1);
|
|
if (v < 0) buf[--i] = '-';
|
|
out(self, buf + i, (unsigned)(sizeof buf - i));
|
|
}
|
|
|
|
static unsigned byte_at(const v4_node *n, v4_cell nfa, unsigned i)
|
|
{
|
|
v4_cell w = nfa + (v4_cell)(i / 4u);
|
|
if (w < 0 || w >= (v4_cell)V4_NODE_WORDS) return 0;
|
|
return (unsigned)(((v4_ucell)n->mem[w] >> (8u * (i % 4u))) & 0xFFu);
|
|
}
|
|
|
|
/* the newest word whose xt is at or below addr, or 0 */
|
|
static v4_cell word_of(const v4_node *n, const v4_image *im, v4_cell addr)
|
|
{
|
|
v4_cell xt;
|
|
unsigned k;
|
|
if (!im || im->latest <= 0 || im->latest >= (v4_cell)V4_NODE_WORDS) return 0;
|
|
for (xt = n->mem[im->latest], k = 0; xt > 4 && xt < (v4_cell)V4_NODE_WORDS && k < V4_NODE_WORDS;
|
|
xt = n->mem[xt - 1], k++)
|
|
if (xt <= addr) return xt;
|
|
return 0;
|
|
}
|
|
|
|
static void say_where(v4_dump_out out, void *self, const v4_node *n, const v4_image *im, v4_cell addr)
|
|
{
|
|
v4_cell xt, nfa;
|
|
unsigned len, i;
|
|
char c;
|
|
|
|
say_num(out, self, addr);
|
|
if (addr >= V4_ROM_BASE) { say(out, self, " in ROM"); return; }
|
|
xt = addr >= 0 && addr < (v4_cell)V4_NODE_WORDS ? word_of(n, im, addr) : 0;
|
|
if (xt == 0) { say(out, self, " below every word"); return; }
|
|
nfa = n->mem[xt - 2];
|
|
if (nfa < 0 || nfa >= xt) { say(out, self, " in a word with no name"); return; }
|
|
len = byte_at(n, nfa, 0);
|
|
if (len > 31u) len = 31u;
|
|
say(out, self, " in ");
|
|
for (i = 1; i <= len; i++) { c = (char)byte_at(n, nfa, i); out(self, &c, 1); }
|
|
}
|
|
|
|
static const char *kind_name(unsigned k)
|
|
{
|
|
switch (k) {
|
|
case V4_FAULT_ADDRESS: return "address fault";
|
|
case V4_FAULT_DATA_OVER: return "data overflow";
|
|
case V4_FAULT_DATA_UNDER: return "data underflow";
|
|
case V4_FAULT_RET_OVER: return "return overflow";
|
|
case V4_FAULT_RET_UNDER: return "return underflow";
|
|
case V4_FAULT_RAISED: return "error raised";
|
|
default: return "unknown fault";
|
|
}
|
|
}
|
|
|
|
void v4_dump_node(const v4_node *n, const v4_image *im, const char *line, unsigned len,
|
|
v4_dump_out out, void *self)
|
|
{
|
|
unsigned i, h;
|
|
|
|
say(out, self, "V4 DUMP: ");
|
|
if (n->faults == 0) say(out, self, "no fault");
|
|
else {
|
|
say(out, self, kind_name(n->fault_kind));
|
|
if (n->fault_kind == V4_FAULT_ADDRESS) { say(out, self, " at "); say_num(out, self, n->fault_addr); }
|
|
}
|
|
say(out, self, " faults="); say_num(out, self, (v4_cell)n->faults);
|
|
say(out, self, n->stopped ? " stopped\n" : " running\n");
|
|
|
|
say(out, self, "V4 DUMP: P="); say_num(out, self, n->p);
|
|
say(out, self, " A="); say_num(out, self, n->a);
|
|
say(out, self, " B="); say_num(out, self, n->b);
|
|
say(out, self, "\n");
|
|
|
|
say(out, self, "V4 DUMP: data stack depth="); say_num(out, self, (v4_cell)n->ds.depth); say(out, self, ":");
|
|
for (i = 0, h = n->ds.head; i < n->ds.depth; i++) {
|
|
v4_cell v;
|
|
if (i == 0) v = n->ds.t;
|
|
else if (i == 1) v = n->ds.s;
|
|
else { h = (h + V4_DATA_RING - 1u) % V4_DATA_RING; v = n->ds.ring[h]; }
|
|
say(out, self, " "); say_num(out, self, v);
|
|
}
|
|
say(out, self, "\n");
|
|
|
|
say(out, self, "V4 DUMP: return stack depth="); say_num(out, self, (v4_cell)n->rs.depth); say(out, self, ", R first:\n");
|
|
for (i = 0, h = n->rs.head; i < n->rs.depth; i++) {
|
|
v4_cell v;
|
|
if (i == 0) v = n->rs.r;
|
|
else { h = (h + V4_RET_RING - 1u) % V4_RET_RING; v = n->rs.ring[h]; }
|
|
say(out, self, "V4 DUMP: ");
|
|
say_where(out, self, n, im, v);
|
|
say(out, self, "\n");
|
|
}
|
|
|
|
if (line && len) {
|
|
say(out, self, "V4 DUMP: line: ");
|
|
out(self, line, len);
|
|
say(out, self, "\n");
|
|
}
|
|
}
|