From 6e9b2bd10727e318202f1ea6359456373de9ce99 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 10 Jun 2024 12:34:22 -0700 Subject: [PATCH] extend rdi line info lookups with depth; fix bad panel deref in target view cmds --- build.bat | 2 +- project.4coder | 2 +- src/dasm_cache/dasm_cache.c | 2 +- src/df/core/df_core.c | 6 +-- src/df/gfx/df_views.c | 5 ++- src/lib_rdi_format/rdi_format_parse.c | 38 ++++++++++++++++--- src/lib_rdi_format/rdi_format_parse.h | 6 +-- src/mule/mule_main.cpp | 30 +++++++++++++++ .../rdi_breakpad_from_pdb_main.c | 2 +- 9 files changed, 75 insertions(+), 18 deletions(-) diff --git a/build.bat b/build.bat index 9249f121..75d519e8 100644 --- a/build.bat +++ b/build.bat @@ -43,7 +43,7 @@ if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=add :: --- Compile/Link Line Definitions ------------------------------------------ set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7 set clang_common= -I..\src\ -I..\local\ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -set cl_debug= call cl /Od /DBUILD_DEBUG=1 %cl_common% %auto_compile_flags% +set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% %auto_compile_flags% set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common% %auto_compile_flags% set clang_debug= call clang -g -O0 -DBUILD_DEBUG=1 %clang_common% %auto_compile_flags% set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 %clang_common% %auto_compile_flags% diff --git a/project.4coder b/project.4coder index 7a6b0ae3..460ed992 100644 --- a/project.4coder +++ b/project.4coder @@ -47,7 +47,7 @@ commands = { .rjf_f1 = { - .win = "build ryan_scratch no_meta && pushd build && ryan_scratch.exe && popd", + .win = "build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, diff --git a/src/dasm_cache/dasm_cache.c b/src/dasm_cache/dasm_cache.c index 2b255e6a..e3ebddaa 100644 --- a/src/dasm_cache/dasm_cache.c +++ b/src/dasm_cache/dasm_cache.c @@ -460,7 +460,7 @@ dasm_parse_thread__entry_point(void *p) RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx); RDI_ParsedLineTable unit_line_info = {0}; rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); - U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff); + U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff, 0); if(line_info_idx < unit_line_info.count) { RDI_Line *line = &unit_line_info.lines[line_info_idx]; diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index cf59414c..a2221427 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -3278,7 +3278,7 @@ df_text_line_src2dasm_info_list_array_from_src_line_range(Arena *arena, DF_Entit RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx); RDI_ParsedLineTable unit_line_info = {0}; rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); - U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, base_voff); + U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, base_voff, 0); if(unit_line_info.voffs != 0) { Rng1U64 range = r1u64(base_voff, unit_line_info.voffs[line_info_idx+1]); @@ -3322,7 +3322,7 @@ df_text_line_dasm2src_info_from_dbgi_key_voff(DI_Key *dbgi_key, U64 voff) RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx); RDI_ParsedLineTable unit_line_info = {0}; rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); - U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff); + U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff, 0); if(line_info_idx < unit_line_info.count) { RDI_Line *line = &unit_line_info.lines[line_info_idx]; @@ -3957,7 +3957,7 @@ df_eval_parse_ctx_from_src_loc(DI_Scope *scope, DF_Entity *file, TxtPt pt) RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx); RDI_ParsedLineTable unit_line_info = {0}; rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); - U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, base_voff); + U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, base_voff, 0); Rng1U64 range = r1u64(base_voff, unit_line_info.voffs[line_info_idx+1]); S64 actual_line = (S64)unit_line_info.lines[line_info_idx].line_num; DF_TextLineSrc2DasmInfoNode *src2dasm_n = push_array(scratch.arena, DF_TextLineSrc2DasmInfoNode, 1); diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index c8870701..6a4c259d 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -3467,8 +3467,9 @@ DF_VIEW_CMD_FUNCTION_DEF(Target) { DF_Cmd *cmd = &n->cmd; - // rjf: mismatched view => skip - if(df_panel_from_handle(cmd->params.panel) != panel) + // rjf: mismatched window/panel => skip + if(df_window_from_handle(cmd->params.window) != ws || + df_panel_from_handle(cmd->params.panel) != panel) { continue; } diff --git a/src/lib_rdi_format/rdi_format_parse.c b/src/lib_rdi_format/rdi_format_parse.c index 87ccf1bc..85af6af7 100644 --- a/src/lib_rdi_format/rdi_format_parse.c +++ b/src/lib_rdi_format/rdi_format_parse.c @@ -231,13 +231,13 @@ rdi_parsed_from_line_table(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_Parse } RDI_PROC RDI_U64 -rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff) +rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff, RDI_U64 depth) { RDI_U64 result = 0; if(line_info->count > 0 && line_info->voffs[0] <= voff && voff < line_info->voffs[line_info->count - 1]) { + //- rjf: find i such that: (vmap[i].voff <= voff) && (voff < vmap[i + 1].voff) // assuming: (i < j) -> (vmap[i].voff < vmap[j].voff) - // find i such that: (vmap[i].voff <= voff) && (voff < vmap[i + 1].voff) RDI_U32 first = 0; RDI_U32 opl = line_info->count; for(;;) @@ -262,6 +262,32 @@ rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff) } } result = (RDI_U64)first; + + //- rjf: scan leftward, to find shallowest line info matching this voff + for(;result != 0;) + { + if(line_info->voffs[result-1] == voff) + { + result -= 1; + } + else + { + break; + } + } + + //- rjf: scan rightward, to match depth parameter + for(U64 idx = 0; idx < depth && result+1 < line_info->count; idx += 1) + { + if(line_info->voffs[result+1] == voff) + { + result += 1; + } + else + { + break; + } + } } return result; } @@ -615,20 +641,20 @@ rdi_line_table_from_unit(RDI_Parsed *rdi, RDI_Unit *unit) //- line info RDI_PROC RDI_Line -rdi_line_from_voff(RDI_Parsed *rdi, RDI_U64 voff) +rdi_line_from_voff(RDI_Parsed *rdi, RDI_U64 voff, RDI_U64 depth) { RDI_Unit *unit = rdi_unit_from_voff(rdi, voff); RDI_LineTable *line_table = rdi_line_table_from_unit(rdi, unit); - RDI_Line line = rdi_line_from_line_table_voff(rdi, line_table, voff); + RDI_Line line = rdi_line_from_line_table_voff(rdi, line_table, voff, depth); return line; } RDI_PROC RDI_Line -rdi_line_from_line_table_voff(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_U64 voff) +rdi_line_from_line_table_voff(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_U64 voff, RDI_U64 depth) { RDI_ParsedLineTable parsed = {0}; rdi_parsed_from_line_table(rdi, line_table, &parsed); - RDI_U64 line_info_idx = rdi_line_info_idx_from_voff(&parsed, voff); + RDI_U64 line_info_idx = rdi_line_info_idx_from_voff(&parsed, voff, depth); RDI_Line result = {0}; if(line_info_idx < parsed.count) { diff --git a/src/lib_rdi_format/rdi_format_parse.h b/src/lib_rdi_format/rdi_format_parse.h index 1e0c097a..82ccdbe7 100644 --- a/src/lib_rdi_format/rdi_format_parse.h +++ b/src/lib_rdi_format/rdi_format_parse.h @@ -159,7 +159,7 @@ RDI_PROC RDI_U32 *rdi_idx_run_from_first_count(RDI_Parsed *rdi, RDI_U32 raw_firs //- line info RDI_PROC void rdi_parsed_from_line_table(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_ParsedLineTable *out); -RDI_PROC RDI_U64 rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff); +RDI_PROC RDI_U64 rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff, RDI_U64 depth); RDI_PROC void rdi_parsed_from_source_line_map(RDI_Parsed *rdi, RDI_SourceLineMap *map, RDI_ParsedSourceLineMap *out); RDI_PROC RDI_U64 *rdi_line_voffs_from_num(RDI_ParsedSourceLineMap *map, RDI_U32 linenum, RDI_U32 *n_out); @@ -195,8 +195,8 @@ RDI_PROC RDI_Unit *rdi_unit_from_voff(RDI_Parsed *rdi, RDI_U64 voff); RDI_PROC RDI_LineTable *rdi_line_table_from_unit(RDI_Parsed *rdi, RDI_Unit *unit); //- line tables -RDI_PROC RDI_Line rdi_line_from_voff(RDI_Parsed *rdi, RDI_U64 voff); -RDI_PROC RDI_Line rdi_line_from_line_table_voff(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_U64 voff); +RDI_PROC RDI_Line rdi_line_from_voff(RDI_Parsed *rdi, RDI_U64 voff, RDI_U64 depth); +RDI_PROC RDI_Line rdi_line_from_line_table_voff(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_U64 voff, RDI_U64 depth); RDI_PROC RDI_SourceFile *rdi_source_file_from_line(RDI_Parsed *rdi, RDI_Line *line); //- source files diff --git a/src/mule/mule_main.cpp b/src/mule/mule_main.cpp index a9647a31..b1a93972 100644 --- a/src/mule/mule_main.cpp +++ b/src/mule/mule_main.cpp @@ -1514,6 +1514,34 @@ extern "C"{ #include "mule_c.h" } +//////////////////////////////// +//~ rjf: Basic Inline Line Info Tests + +#if defined(_MSC_VER) +# define FORCE_INLINE __forceinline +#elif defined(__clang__) +# define FORCE_INLINE __attribute__((always_inline)) +#else +# error need force inline for this compiler +#endif + +static FORCE_INLINE void +basic_inlinee(void) +{ + OutputDebugStringA("A\n"); + OutputDebugStringA("B\n"); + OutputDebugStringA("C\n"); + OutputDebugStringA("D\n"); +} + +static void +basic_inline_tests(void) +{ + OutputDebugStringA("{\n"); + basic_inlinee(); + OutputDebugStringA("}\n"); +} + //////////////////////////////// //~ rjf: Fancy Visualization Eval Tests @@ -2595,6 +2623,8 @@ mule_main(int argc, char** argv){ alloca_stepping_tests(); + basic_inline_tests(); + inline_stepping_tests(); overloaded_line_stepping_tests(); diff --git a/src/rdi_breakpad_from_pdb/rdi_breakpad_from_pdb_main.c b/src/rdi_breakpad_from_pdb/rdi_breakpad_from_pdb_main.c index 9a32b06e..b1cdede4 100644 --- a/src/rdi_breakpad_from_pdb/rdi_breakpad_from_pdb_main.c +++ b/src/rdi_breakpad_from_pdb/rdi_breakpad_from_pdb_main.c @@ -137,7 +137,7 @@ internal TS_TASK_FUNCTION_DEF(p2b_dump_proc_chunk_task__entry_point) for(U64 voff = voff_range.min, last_voff = 0; voff < voff_range.max && voff > last_voff;) { - RDI_U64 line_info_idx = rdi_line_info_idx_from_voff(&line_info, voff); + RDI_U64 line_info_idx = rdi_line_info_idx_from_voff(&line_info, voff, 0); if(line_info_idx < line_info.count) { RDI_Line *line = &line_info.lines[line_info_idx];