From 2fc4a3472bf965f91a213a2339838a9af62809a9 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Tue, 24 Feb 2026 19:05:04 -0800 Subject: [PATCH] finalize DWARF line table conversion test --- src/radbin/radbin.c | 2 +- src/torture/torture.c | 30 ++++++++++++++++++++++++++++++ src/torture/torture.h | 1 + src/torture/torture_d2r.c | 34 +++++++++++++++++++++------------- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/radbin/radbin.c b/src/radbin/radbin.c index 2711b9ae..fd933399 100644 --- a/src/radbin/radbin.c +++ b/src/radbin/radbin.c @@ -536,7 +536,7 @@ rb_thread_entry_point(void *p) fprintf(stderr, "--breakpad Specifies that the utility should convert debug information\n"); fprintf(stderr, " data to the textual Breakpad format.\n\n"); - fprintf(stderr, "--VOff2Line Specifies that the utility should map virtual offset to source line.\n\n"); + fprintf(stderr, "--voff2line Specifies that the utility should map virtual offset to source line.\n\n"); fprintf(stderr, "--out: Specifies the path to which output data should be written. If\n"); fprintf(stderr, " not specified, the utility will choose a fallback. If dumping\n"); diff --git a/src/torture/torture.c b/src/torture/torture.c index 42832dd3..171ebd53 100644 --- a/src/torture/torture.c +++ b/src/torture/torture.c @@ -213,6 +213,36 @@ t_invoke(String8 exe_path, String8 cmdline, U64 timeout) return t_invoke_(exe_path, cmdline, timeout, 0, 0); } +internal B32 +t_match_line(String8 *output, String8 expected_line) +{ + U64 new_line_pos = str8_find_needle(*output, 0, str8_lit("\n"), 0); + String8 line = str8_prefix(*output, new_line_pos); + if (str8_ends_with(line, str8_lit("\r"), 0)) { + line = str8_chop(line, 1); + } + + B32 is_match = str8_match(line, expected_line, 0); + if (is_match) { + *output = str8_skip(*output, new_line_pos + 1); + } + + return is_match; +} + +internal B32 +t_match_linef(String8 *output, char *fmt, ...) +{ + Temp scratch = scratch_begin(0, 0); + va_list args; + va_start(args, fmt); + String8 expected_line = push_str8fv(scratch.arena, fmt, args); + B32 is_match = t_match_line(output, expected_line); + va_end(args); + scratch_end(scratch); + return is_match; +} + internal int t_test_is_before(void *raw_a, void *raw_b) { diff --git a/src/torture/torture.h b/src/torture/torture.h index 74f27eb4..647c3471 100644 --- a/src/torture/torture.h +++ b/src/torture/torture.h @@ -75,6 +75,7 @@ extern T_Test g_torture_tests[0xffffff]; } #define T_Ok(c) do { if (!(c)) { result.fail_file = __FILE__; result.fail_line = __LINE__; result.fail_cond = Stringify(c); goto exit__; } } while(0) +#define T_MatchLinef(out, ...) T_Ok(t_match_linef(out, __VA_ARGS__)) //////////////////////////////// diff --git a/src/torture/torture_d2r.c b/src/torture/torture_d2r.c index 7833c2f5..57239538 100644 --- a/src/torture/torture_d2r.c +++ b/src/torture/torture_d2r.c @@ -222,24 +222,26 @@ T_BeginTest(d2r_types) } T_EndTest; -#if 0 T_BeginTest(d2r_line_table) { DW_Writer *writer = dw_writer_begin(DW_Format_32Bit, DW_Version_5, DW_CompUnitKind_Compile, Arch_x64); - String8 comp_dir = str8_lit("c:/devel/"); + String8 comp_dir = str8_lit("c:/DEVEL/"); String8 comp_name = str8_lit("test.c"); - DW_WriterFile *file = dw_writer_new_file(writer, comp_name); - file->md5 = *(U128 *)&(U8[]){ 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }; + DW_WriterFile *foo_file = dw_writer_new_file(writer, str8_lit("/mnt/C/Devel/foo.c")); + DW_WriterFile *comp_file = dw_writer_new_file(writer, str8f(scratch.arena, "%S%S", comp_dir, comp_name)); struct { DW_WriterFile *file; U64 ln; U64 line_size; U64 voff; } test_table[] = { - { file, 6, 1 }, - { file, 4, 2 }, - { file, 2, 3 }, - { file, 1, 4 }, - { file, 8, 5 }, + { comp_file, 6, 1 }, + { comp_file, 4, 2 }, + { comp_file, 2, 3 }, + { comp_file, 1, 4 }, + { comp_file, 8, 5 }, + { foo_file, 1, 3 }, + { foo_file, 100, 1 }, + { comp_file, max_U32 - 0x100, 10 }, }; U64 exe_base = coff_default_exe_base_from_machine(COFF_MachineType_X64); @@ -250,6 +252,13 @@ T_BeginTest(d2r_line_table) voff += test_table[i].line_size; } + // emit one past last line + dw_writer_line_emit(writer, + test_table[ArrayCount(test_table) - 1].file, + test_table[ArrayCount(test_table) - 1].ln, + 0, + exe_base + voff); + dw_writer_tag_begin(writer, DW_TagKind_CompileUnit); dw_writer_push_attrib_string(writer, DW_AttribKind_Producer, str8_lit("RAD DWARF WRITER")); dw_writer_push_attrib_string(writer, DW_AttribKind_CompDir, comp_dir); @@ -263,18 +272,17 @@ T_BeginTest(d2r_line_table) for EachElement(i, test_table) { for EachIndex(k, test_table[i].line_size) { - String8 cmd_line = str8f(scratch.arena, "-voff2line -voff:%llx, a.rdi", test_table[i].voff + k); + String8 cmd_line = str8f(scratch.arena, "-voff2line -voff:0x%llx a.rdi", test_table[i].voff + k); String8 output = {0}; - t_invoke_(str8_lit("radbin.exe"), cmd_line, max_U64, scratch.arena, &output); + t_invoke_(t_radbin_path(), cmd_line, max_U64, scratch.arena, &output); T_Ok(g_last_exit_code == 0); - T_MatchLinef(&output, "%S:/%llu", test_table[i].file->path, test_table[i].ln); + T_MatchLinef(&output, "%S:%llu", test_table[i].file->path, test_table[i].ln); } } dw_writer_end(&writer); } T_EndTest; -#endif T_BeginTest(d2r_general) {