From 69f77456b8fceaac0b31937894886cd06acd1817 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Wed, 24 Jan 2024 11:57:17 -0800 Subject: [PATCH] dbgi: fix incorrect grab of raddbg header; raddbg_from_pdb: fix unsigned interpretation of offsets in defrange symbols; fix incorrect byte position/size encoding ordering in some location info cases --- src/dbgi/dbgi.c | 2 +- src/eval/eval_parser.c | 14 +++++++++++++- src/raddbg/raddbg.c | 10 +++++++++- src/raddbg_convert/pdb/raddbg_codeview.h | 6 +++--- src/raddbg_convert/pdb/raddbg_from_pdb.c | 21 ++++++++++----------- src/raddbg_convert/pdb/raddbg_from_pdb.h | 4 ++-- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/dbgi/dbgi.c b/src/dbgi/dbgi.c index 6183982e..976ed30c 100644 --- a/src/dbgi/dbgi.c +++ b/src/dbgi/dbgi.c @@ -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; diff --git a/src/eval/eval_parser.c b/src/eval/eval_parser.c index c999fd5f..e218d2c6 100644 --- a/src/eval/eval_parser.c +++ b/src/eval/eval_parser.c @@ -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: diff --git a/src/raddbg/raddbg.c b/src/raddbg/raddbg.c index 5030cd05..93279a53 100644 --- a/src/raddbg/raddbg.c +++ b/src/raddbg/raddbg.c @@ -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(); @@ -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; } } @@ -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) { @@ -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; } } diff --git a/src/raddbg_convert/pdb/raddbg_codeview.h b/src/raddbg_convert/pdb/raddbg_codeview.h index 70d60209..d8317878 100644 --- a/src/raddbg_convert/pdb/raddbg_codeview.h +++ b/src/raddbg_convert/pdb/raddbg_codeview.h @@ -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; @@ -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) @@ -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; diff --git a/src/raddbg_convert/pdb/raddbg_from_pdb.c b/src/raddbg_convert/pdb/raddbg_from_pdb.c index 9427fb44..e44d5f56 100644 --- a/src/raddbg_convert/pdb/raddbg_from_pdb.c +++ b/src/raddbg_convert/pdb/raddbg_from_pdb.c @@ -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); @@ -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); @@ -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); @@ -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 = @@ -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{ @@ -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); diff --git a/src/raddbg_convert/pdb/raddbg_from_pdb.h b/src/raddbg_convert/pdb/raddbg_from_pdb.h index fbd39381..c4e8e9e6 100644 --- a/src/raddbg_convert/pdb/raddbg_from_pdb.h +++ b/src/raddbg_convert/pdb/raddbg_from_pdb.h @@ -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,