nx_probe_dwhdr.nx source
↩ module page · 48 lines · 1625 B
1// nx_probe_dwhdr.nx -- KAT: does our DWARF v5 header emitter produce the EXTERNALLY VALIDATED bytes?
2//
3// The reference is NOT our own decoder. It is 119 bytes that GNU readelf 2.42 parsed correctly,
4// including per-row file attribution (runtime/alpha.nx line 5 @0x00, runtime/beta.nx line 9 @0x14).
5// Fixture + field decode: knowledge/dwarf_debugline_fixture_2026_08_07.md
6// Comparing against our own reader would only prove two organs by one author agree (debt 1786111455).
7//
8// Prints the emitted bytes as hex on stdout for byte-for-byte diff against the fixture.
9// expect_exit: 0
10import "nx_dwarf_line.nx"
11
12func dwh_hex(v: i64) -> i64 {
13 let t: *u8 = sys_mmap(8)
14 var hi: i64 = (v >> 4) & 0xF
15 var lo: i64 = v & 0xF
16 if hi < 10 { t[0] = (48 + hi) as u8 } else { t[0] = (87 + hi) as u8 }
17 if lo < 10 { t[1] = (48 + lo) as u8 } else { t[1] = (87 + lo) as u8 }
18 t[2] = 32 as u8
19 sys_write(1, t, 3)
20 return 0
21}
22
23func main() -> i64 {
24 let src: *u8 = "runtime/alpha.nxruntime/beta.nx" as *u8
25 let foff: *i64 = sys_mmap(64) as *i64
26 let flen: *i64 = sys_mmap(64) as *i64
27 foff[0] = 0
28 flen[0] = 16
29 foff[1] = 16
30 flen[1] = 15
31
32 let d: *NxDwLine = nx_dwline_new(4096)
33 nx_dwline_header(d, src, foff, flen, 2)
34 nx_dwline_set_address(d, 0)
35 nx_dwline_record(d, 0, 1, 5)
36 nx_dwline_record(d, 20, 2, 9)
37 nx_dwline_end_sequence(d)
38 nx_dwline_finish(d)
39
40 let n: i64 = nx_dwline_size(d)
41 let b: *u8 = nx_dwline_bytes(d)
42 var i: i64 = 0
43 while i < n {
44 dwh_hex(b[i] as i64)
45 i = i + 1
46 }
47 sys_write(1, "\n" as *u8, 1)
48 return 0
49}