extend rdi line info lookups with depth; fix bad panel deref in target view cmds

This commit is contained in:
Ryan Fleury
2024-06-10 12:34:22 -07:00
parent 5c8c1a89e3
commit c61f820aef
9 changed files with 75 additions and 18 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=add
:: --- Compile/Link Line Definitions ------------------------------------------ :: --- Compile/Link Line Definitions ------------------------------------------
set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7 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 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 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_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% set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 %clang_common% %auto_compile_flags%
+1 -1
View File
@@ -47,7 +47,7 @@ commands =
{ {
.rjf_f1 = .rjf_f1 =
{ {
.win = "build ryan_scratch no_meta && pushd build && ryan_scratch.exe && popd", .win = "build raddbg telemetry",
.linux = "", .linux = "",
.out = "*compilation*", .out = "*compilation*",
.footer_panel = true, .footer_panel = true,
+1 -1
View File
@@ -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_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0}; RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); 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) if(line_info_idx < unit_line_info.count)
{ {
RDI_Line *line = &unit_line_info.lines[line_info_idx]; RDI_Line *line = &unit_line_info.lines[line_info_idx];
+3 -3
View File
@@ -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_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0}; RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); 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) if(unit_line_info.voffs != 0)
{ {
Rng1U64 range = r1u64(base_voff, unit_line_info.voffs[line_info_idx+1]); 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_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0}; RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); 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) if(line_info_idx < unit_line_info.count)
{ {
RDI_Line *line = &unit_line_info.lines[line_info_idx]; 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_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0}; RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info); 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]); 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; S64 actual_line = (S64)unit_line_info.lines[line_info_idx].line_num;
DF_TextLineSrc2DasmInfoNode *src2dasm_n = push_array(scratch.arena, DF_TextLineSrc2DasmInfoNode, 1); DF_TextLineSrc2DasmInfoNode *src2dasm_n = push_array(scratch.arena, DF_TextLineSrc2DasmInfoNode, 1);
+3 -2
View File
@@ -3467,8 +3467,9 @@ DF_VIEW_CMD_FUNCTION_DEF(Target)
{ {
DF_Cmd *cmd = &n->cmd; DF_Cmd *cmd = &n->cmd;
// rjf: mismatched view => skip // rjf: mismatched window/panel => skip
if(df_panel_from_handle(cmd->params.panel) != panel) if(df_window_from_handle(cmd->params.window) != ws ||
df_panel_from_handle(cmd->params.panel) != panel)
{ {
continue; continue;
} }
+32 -6
View File
@@ -231,13 +231,13 @@ rdi_parsed_from_line_table(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_Parse
} }
RDI_PROC RDI_U64 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; RDI_U64 result = 0;
if(line_info->count > 0 && line_info->voffs[0] <= voff && voff < line_info->voffs[line_info->count - 1]) 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) // 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 first = 0;
RDI_U32 opl = line_info->count; RDI_U32 opl = line_info->count;
for(;;) for(;;)
@@ -262,6 +262,32 @@ rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff)
} }
} }
result = (RDI_U64)first; 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; return result;
} }
@@ -615,20 +641,20 @@ rdi_line_table_from_unit(RDI_Parsed *rdi, RDI_Unit *unit)
//- line info //- line info
RDI_PROC RDI_Line 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_Unit *unit = rdi_unit_from_voff(rdi, voff);
RDI_LineTable *line_table = rdi_line_table_from_unit(rdi, unit); 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; return line;
} }
RDI_PROC RDI_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_ParsedLineTable parsed = {0};
rdi_parsed_from_line_table(rdi, line_table, &parsed); 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}; RDI_Line result = {0};
if(line_info_idx < parsed.count) if(line_info_idx < parsed.count)
{ {
+3 -3
View File
@@ -159,7 +159,7 @@ RDI_PROC RDI_U32 *rdi_idx_run_from_first_count(RDI_Parsed *rdi, RDI_U32 raw_firs
//- line info //- line info
RDI_PROC void rdi_parsed_from_line_table(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_ParsedLineTable *out); 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 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); 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); RDI_PROC RDI_LineTable *rdi_line_table_from_unit(RDI_Parsed *rdi, RDI_Unit *unit);
//- line tables //- line tables
RDI_PROC RDI_Line rdi_line_from_voff(RDI_Parsed *rdi, 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_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); RDI_PROC RDI_SourceFile *rdi_source_file_from_line(RDI_Parsed *rdi, RDI_Line *line);
//- source files //- source files
+30
View File
@@ -1514,6 +1514,34 @@ extern "C"{
#include "mule_c.h" #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 //~ rjf: Fancy Visualization Eval Tests
@@ -2595,6 +2623,8 @@ mule_main(int argc, char** argv){
alloca_stepping_tests(); alloca_stepping_tests();
basic_inline_tests();
inline_stepping_tests(); inline_stepping_tests();
overloaded_line_stepping_tests(); overloaded_line_stepping_tests();
@@ -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; for(U64 voff = voff_range.min, last_voff = 0;
voff < voff_range.max && voff > last_voff;) 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) if(line_info_idx < line_info.count)
{ {
RDI_Line *line = &line_info.lines[line_info_idx]; RDI_Line *line = &line_info.lines[line_info_idx];