Skip to content

Commit

Permalink
dbgi: fix incorrect grab of raddbg header; raddbg_from_pdb: fix unsig…
Browse files Browse the repository at this point in the history
…ned interpretation of offsets in defrange symbols; fix incorrect byte position/size encoding ordering in some location info cases
  • Loading branch information
ryanfleury committed Jan 24, 2024
1 parent 3edc67e commit 69f7745
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/dbgi/dbgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ dbgi_parse_thread_entry_point(void *p)
file_base = os_file_map_view_open(file_map, OS_AccessFlag_Read, r1u64(0, file_props.size));
if(sizeof(RADDBG_Header) <= file_props.size)
{
RADDBG_Header *header = (RADDBG_Header*)&file_base;
RADDBG_Header *header = (RADDBG_Header*)file_base;
if(header->encoding_version != RADDBG_ENCODING_VERSION)
{
raddbg_file_is_up_to_date = 0;
Expand Down
14 changes: 13 additions & 1 deletion src/eval/eval_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,19 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8
case RADDBG_LocationKind_ValBytecodeStream:
{
U8 *bytecode_base = ctx->rdbg->location_data + block->location_data_off + sizeof(RADDBG_LocationKind);
loc_bytecode = str8_cstring((char *)bytecode_base);
U64 bytecode_size = 0;
for(U64 idx = 0; idx < ctx->rdbg->location_data_size; idx += 1)
{
U8 op = bytecode_base[idx];
if(op == 0)
{
break;
}
U8 ctrlbits = raddbg_eval_opcode_ctrlbits[op];
U32 p_size = RADDBG_DECODEN_FROM_CTRLBITS(ctrlbits);
bytecode_size += 1+p_size;
}
loc_bytecode = str8(bytecode_base, bytecode_size);
}break;
case RADDBG_LocationKind_AddrRegisterPlusU16:
case RADDBG_LocationKind_AddrAddrRegisterPlusU16:
Expand Down
10 changes: 9 additions & 1 deletion src/raddbg/raddbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
{
if(os_key_press(&events, os_handle_zero(), 0, OS_Key_Esc))
{
df_gfx_request_frame();
df_gfx_state->bind_change_active = 0;
}
if(os_key_press(&events, os_handle_zero(), 0, OS_Key_Delete))
{
df_gfx_request_frame();
df_unbind_spec(df_gfx_state->bind_change_cmd_spec, df_gfx_state->bind_change_binding);
df_gfx_state->bind_change_active = 0;
DF_CmdParams p = df_cmd_params_from_gfx();
Expand Down Expand Up @@ -117,6 +119,7 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
os_eat_event(&events, event);
DF_CmdParams p = df_cmd_params_from_gfx();
df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(df_g_cfg_src_write_cmd_kind_table[DF_CfgSrc_User]));
df_gfx_request_frame();
break;
}
}
Expand Down Expand Up @@ -151,8 +154,8 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
{
window->menu_bar_focus_press_started = 0;
}
df_gfx_request_frame();
}
df_gfx_request_frame();
}
else if(event->kind == OS_EventKind_Text)
{
Expand Down Expand Up @@ -180,28 +183,33 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
}
if(event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->is_repeat == 0)
{
df_gfx_request_frame();
ws->menu_bar_focused_on_press = ws->menu_bar_focused;
ws->menu_bar_key_held = 1;
ws->menu_bar_focus_press_started = 1;
}
if(event->kind == OS_EventKind_Release && event->key == OS_Key_Alt && event->is_repeat == 0)
{
df_gfx_request_frame();
ws->menu_bar_key_held = 0;
}
if(ws->menu_bar_focused && event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->is_repeat == 0)
{
os_eat_event(&events, event);
df_gfx_request_frame();
ws->menu_bar_focused = 0;
}
else if(ws->menu_bar_focus_press_started && !ws->menu_bar_focused && event->kind == OS_EventKind_Release && event->key == OS_Key_Alt && event->is_repeat == 0)
{
os_eat_event(&events, event);
df_gfx_request_frame();
ws->menu_bar_focused = !ws->menu_bar_focused_on_press;
ws->menu_bar_focus_press_started = 0;
}
else if(event->kind == OS_EventKind_Press && event->key == OS_Key_Esc && ws->menu_bar_focused && !ui_any_ctx_menu_is_open())
{
os_eat_event(&events, event);
df_gfx_request_frame();
ws->menu_bar_focused = 0;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/raddbg_convert/pdb/raddbg_codeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ typedef struct CV_SymDefrangeRegister{

// (SymKind: DEFRANGE_FRAMEPOINTER_REL)
typedef struct CV_SymDefrangeFramepointerRel{
U32 off;
S32 off;
CV_LvarAddrRange range;
// CV_LvarAddrGap[] gaps (rest of data)
} CV_SymDefrangeFramepointerRel;
Expand All @@ -1884,7 +1884,7 @@ typedef struct CV_SymDefrangeSubfieldRegister{

// (SymKind: DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE)
typedef struct CV_SymDefrangeFramepointerRelFullScope{
U32 off;
S32 off;
} CV_SymDefrangeFramepointerRelFullScope;

// (SymKind: DEFRANGE_REGISTER_REL)
Expand All @@ -1897,7 +1897,7 @@ enum{
typedef struct CV_SymDefrangeRegisterRel{
CV_Reg reg;
CV_DefrangeRegisterRelFlags flags;
U32 reg_off;
S32 reg_off;
CV_LvarAddrRange range;
// CV_LvarAddGap[] gaps (rest of data)
} CV_SymDefrangeRegisterRel;
Expand Down
21 changes: 10 additions & 11 deletions src/raddbg_convert/pdb/raddbg_from_pdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ pdbconv_symbol_cons(PDBCONV_Ctx *ctx, CV_SymParsed *sym, U32 sym_unique_id){
// set location case
CONS_Location *loc =
pdbconv_location_from_addr_reg_off(ctx, register_code, byte_size, byte_pos,
var_off, extra_indirection_to_value);
(S64)(S32)var_off, extra_indirection_to_value);

CONS_LocationSet *locset = cons_location_set_from_local(ctx->root, local_var);
cons_location_set_add_case(ctx->root, locset, 0, max_U64, loc);
Expand Down Expand Up @@ -2275,12 +2275,11 @@ pdbconv_symbol_cons(PDBCONV_Ctx *ctx, CV_SymParsed *sym, U32 sym_unique_id){
B32 extra_indirection = 0;
U32 byte_size = ctx->addr_size;
U32 byte_pos = 0;
U64 var_off = defrange_fprel->off;
S64 var_off = (S64)defrange_fprel->off;
CONS_Location *location =
pdbconv_location_from_addr_reg_off(ctx, fp_register_code, byte_size, byte_pos,
var_off, extra_indirection);


// extract range info
CV_LvarAddrRange *range = &defrange_fprel->range;
CV_LvarAddrGap *gaps = (CV_LvarAddrGap*)(defrange_fprel + 1);
Expand Down Expand Up @@ -2352,7 +2351,7 @@ pdbconv_symbol_cons(PDBCONV_Ctx *ctx, CV_SymParsed *sym, U32 sym_unique_id){
B32 extra_indirection = 0;
U32 byte_size = ctx->addr_size;
U32 byte_pos = 0;
U64 var_off = defrange_fprel_full_scope->off;
S64 var_off = (S64)defrange_fprel_full_scope->off;
CONS_Location *location =
pdbconv_location_from_addr_reg_off(ctx, fp_register_code, byte_size, byte_pos,
var_off, extra_indirection);
Expand Down Expand Up @@ -2385,7 +2384,7 @@ pdbconv_symbol_cons(PDBCONV_Ctx *ctx, CV_SymParsed *sym, U32 sym_unique_id){
U32 byte_pos = 0;

B32 extra_indirection_to_value = 0;
U64 var_off = defrange_register_rel->reg_off;
S64 var_off = defrange_register_rel->reg_off;

// setup location
CONS_Location *location =
Expand Down Expand Up @@ -2670,17 +2669,17 @@ pdbconv_known_global_insert(Arena *arena, PDBCONV_KnownGlobalSet *set, String8 n
static CONS_Location*
pdbconv_location_from_addr_reg_off(PDBCONV_Ctx *ctx,
RADDBG_RegisterCode reg_code,
U32 reg_byte_pos,
U32 reg_byte_size,
U64 offset,
U32 reg_byte_pos,
S64 offset,
B32 extra_indirection){
CONS_Location *result = 0;
if (offset <= max_U16){
if (0 <= offset && offset <= (S64)max_U16){
if (extra_indirection){
result = cons_location_addr_addr_reg_plus_u16(ctx->root, reg_code, offset);
result = cons_location_addr_addr_reg_plus_u16(ctx->root, reg_code, (U16)offset);
}
else{
result = cons_location_addr_reg_plus_u16(ctx->root, reg_code, offset);
result = cons_location_addr_reg_plus_u16(ctx->root, reg_code, (U16)offset);
}
}
else{
Expand All @@ -2689,7 +2688,7 @@ pdbconv_location_from_addr_reg_off(PDBCONV_Ctx *ctx,
CONS_EvalBytecode bytecode = {0};
U32 regread_param = RADDBG_EncodeRegReadParam(reg_code, reg_byte_size, reg_byte_pos);
cons_bytecode_push_op(arena, &bytecode, RADDBG_EvalOp_RegRead, regread_param);
cons_bytecode_push_uconst(arena, &bytecode, offset);
cons_bytecode_push_sconst(arena, &bytecode, offset);
cons_bytecode_push_op(arena, &bytecode, RADDBG_EvalOp_Add, 0);
if (extra_indirection){
cons_bytecode_push_op(arena, &bytecode, RADDBG_EvalOp_MemRead, ctx->addr_size);
Expand Down
4 changes: 2 additions & 2 deletions src/raddbg_convert/pdb/raddbg_from_pdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ static void pdbconv_known_global_insert(Arena *arena, PDBCONV_KnownGlobalSet *se
// location info helpers
static CONS_Location* pdbconv_location_from_addr_reg_off(PDBCONV_Ctx *ctx,
RADDBG_RegisterCode reg_code,
U32 reg_byte_pos,
U32 reg_byte_size,
U64 offset,
U32 reg_byte_pos,
S64 offset,
B32 extra_indirection);

static CV_EncodedFramePtrReg pdbconv_cv_encoded_fp_reg_from_proc(PDBCONV_Ctx *ctx,
Expand Down

0 comments on commit 69f7745

Please sign in to comment.