mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-14 16:12:24 -07:00
shift disassembly view to being usable as a view rule too; arbitrary disassembly view parameterization
This commit is contained in:
@@ -4969,6 +4969,7 @@ df_eval_viz_row_list_push_new(Arena *arena, DF_EvalView *eval_view, DF_EvalVizWi
|
||||
expr = df_expr_from_expr_cfg(arena, expr, cfg_table);
|
||||
}break;
|
||||
case DF_EvalVizBlockKind_Root:
|
||||
case DF_EvalVizBlockKind_Canvas:
|
||||
{
|
||||
cfg_table = block->cfg_table;
|
||||
}break;
|
||||
@@ -5322,6 +5323,19 @@ df_lang_kind_from_eval_params(E_Eval eval, MD_Node *params)
|
||||
return lang_kind;
|
||||
}
|
||||
|
||||
internal Architecture
|
||||
df_architecture_from_eval_params(E_Eval eval, MD_Node *params)
|
||||
{
|
||||
Architecture arch = Architecture_Null;
|
||||
MD_Node *arch_node = md_child_from_string(params, str8_lit("arch"), 0);
|
||||
String8 arch_kind_string = arch_node->first->string;
|
||||
if(str8_match(arch_kind_string, str8_lit("x64"), StringMatchFlag_CaseInsensitive))
|
||||
{
|
||||
arch = Architecture_x64;
|
||||
}
|
||||
return arch;
|
||||
}
|
||||
|
||||
internal Vec2S32
|
||||
df_dim2s32_from_eval_params(E_Eval eval, MD_Node *params)
|
||||
{
|
||||
|
||||
@@ -1634,6 +1634,7 @@ internal E_TypeKey df_type_key_from_params(MD_Node *params);
|
||||
internal E_Value df_value_from_params_key(MD_Node *params, String8 key);
|
||||
internal Rng1U64 df_range_from_eval_params(E_Eval eval, MD_Node *params);
|
||||
internal TXT_LangKind df_lang_kind_from_eval_params(E_Eval eval, MD_Node *params);
|
||||
internal Architecture df_architecture_from_eval_params(E_Eval eval, MD_Node *params);
|
||||
internal Vec2S32 df_dim2s32_from_eval_params(E_Eval eval, MD_Node *params);
|
||||
internal R_Tex2DFormat df_tex2dformat_from_eval_params(E_Eval eval, MD_Node *params);
|
||||
|
||||
|
||||
@@ -852,245 +852,6 @@ DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(bitmap)
|
||||
df_eval_viz_block_end(out, vb);
|
||||
}
|
||||
|
||||
#if 0
|
||||
internal Vec2F32
|
||||
df_bitmap_view_state__screen_from_canvas_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 cvs)
|
||||
{
|
||||
Vec2F32 scr =
|
||||
{
|
||||
(rect.x0+rect.x1)/2 + (cvs.x - bvs->view_center_pos.x) * bvs->zoom,
|
||||
(rect.y0+rect.y1)/2 + (cvs.y - bvs->view_center_pos.y) * bvs->zoom,
|
||||
};
|
||||
return scr;
|
||||
}
|
||||
|
||||
internal Rng2F32
|
||||
df_bitmap_view_state__screen_from_canvas_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 cvs)
|
||||
{
|
||||
Rng2F32 scr = r2f32(df_bitmap_view_state__screen_from_canvas_pos(bvs, rect, cvs.p0), df_bitmap_view_state__screen_from_canvas_pos(bvs, rect, cvs.p1));
|
||||
return scr;
|
||||
}
|
||||
|
||||
internal Vec2F32
|
||||
df_bitmap_view_state__canvas_from_screen_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 scr)
|
||||
{
|
||||
Vec2F32 cvs =
|
||||
{
|
||||
(scr.x - (rect.x0+rect.x1)/2) / bvs->zoom + bvs->view_center_pos.x,
|
||||
(scr.y - (rect.y0+rect.y1)/2) / bvs->zoom + bvs->view_center_pos.y,
|
||||
};
|
||||
return cvs;
|
||||
}
|
||||
|
||||
internal Rng2F32
|
||||
df_bitmap_view_state__canvas_from_screen_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 scr)
|
||||
{
|
||||
Rng2F32 cvs = r2f32(df_bitmap_view_state__canvas_from_screen_pos(bvs, rect, scr.p0), df_bitmap_view_state__canvas_from_screen_pos(bvs, rect, scr.p1));
|
||||
return cvs;
|
||||
}
|
||||
|
||||
internal DF_BitmapTopologyInfo
|
||||
df_vr_bitmap_topology_info_from_cfg(DF_CfgNode *cfg)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
DF_BitmapTopologyInfo info = {0};
|
||||
{
|
||||
info.fmt = R_Tex2DFormat_RGBA8;
|
||||
}
|
||||
{
|
||||
DF_CfgNode *width_cfg = df_cfg_node_child_from_string(cfg, str8_lit("w"), 0);
|
||||
DF_CfgNode *height_cfg = df_cfg_node_child_from_string(cfg, str8_lit("h"), 0);
|
||||
DF_CfgNode *fmt_cfg = df_cfg_node_child_from_string(cfg, str8_lit("fmt"), 0);
|
||||
String8List width_expr_strs = {0};
|
||||
String8List height_expr_strs = {0};
|
||||
for(DF_CfgNode *child = width_cfg->first; child != &df_g_nil_cfg_node; child = child->next)
|
||||
{
|
||||
str8_list_push(scratch.arena, &width_expr_strs, child->string);
|
||||
}
|
||||
for(DF_CfgNode *child = height_cfg->first; child != &df_g_nil_cfg_node; child = child->next)
|
||||
{
|
||||
str8_list_push(scratch.arena, &height_expr_strs, child->string);
|
||||
}
|
||||
String8 width_expr = str8_list_join(scratch.arena, &width_expr_strs, 0);
|
||||
String8 height_expr = str8_list_join(scratch.arena, &height_expr_strs, 0);
|
||||
String8 fmt_string = fmt_cfg->first->string;
|
||||
E_Eval width_eval = e_eval_from_string(scratch.arena, width_expr);
|
||||
E_Eval width_eval_value = e_value_eval_from_eval(width_eval);
|
||||
info.width = width_eval_value.value.u64;
|
||||
E_Eval height_eval = e_eval_from_string(scratch.arena, height_expr);
|
||||
E_Eval height_eval_value = e_value_eval_from_eval(height_eval);
|
||||
info.height = height_eval_value.value.u64;
|
||||
if(fmt_string.size != 0)
|
||||
{
|
||||
for(R_Tex2DFormat fmt = (R_Tex2DFormat)0; fmt < R_Tex2DFormat_COUNT; fmt = (R_Tex2DFormat)(fmt+1))
|
||||
{
|
||||
if(str8_match(r_tex2d_format_display_string_table[fmt], fmt_string, StringMatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.fmt = fmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
return info;
|
||||
}
|
||||
|
||||
internal UI_BOX_CUSTOM_DRAW(df_vr_bitmap_box_draw)
|
||||
{
|
||||
DF_VR_BitmapBoxDrawData *draw_data = (DF_VR_BitmapBoxDrawData *)user_data;
|
||||
Vec4F32 bg_color = box->palette->background;
|
||||
d_img(box->rect, draw_data->src, draw_data->texture, v4f32(1, 1, 1, 1), 0, 0, 0);
|
||||
if(draw_data->loaded_t < 0.98f)
|
||||
{
|
||||
Rng2F32 clip = box->rect;
|
||||
for(UI_Box *b = box->parent; !ui_box_is_nil(b); b = b->parent)
|
||||
{
|
||||
if(b->flags & UI_BoxFlag_Clip)
|
||||
{
|
||||
clip = intersect_2f32(b->rect, clip);
|
||||
}
|
||||
}
|
||||
d_blur(intersect_2f32(clip, box->rect), 10.f-9.f*draw_data->loaded_t, 0);
|
||||
}
|
||||
if(r_handle_match(draw_data->texture, r_handle_zero()))
|
||||
{
|
||||
d_rect(box->rect, v4f32(0, 0, 0, 1), 0, 0, 0);
|
||||
}
|
||||
d_rect(box->rect, v4f32(bg_color.x*bg_color.w, bg_color.y*bg_color.w, bg_color.z*bg_color.w, 1.f-draw_data->loaded_t), 0, 0, 0);
|
||||
if(draw_data->hovered)
|
||||
{
|
||||
Vec4F32 indicator_color = v4f32(1, 1, 1, 1);
|
||||
d_rect(pad_2f32(r2f32p(box->rect.x0 + draw_data->mouse_px.x*draw_data->ui_per_bmp_px,
|
||||
box->rect.y0 + draw_data->mouse_px.y*draw_data->ui_per_bmp_px,
|
||||
box->rect.x0 + draw_data->mouse_px.x*draw_data->ui_per_bmp_px + draw_data->ui_per_bmp_px,
|
||||
box->rect.y0 + draw_data->mouse_px.y*draw_data->ui_per_bmp_px + draw_data->ui_per_bmp_px),
|
||||
3.f),
|
||||
indicator_color, 3.f, 4.f, 1.f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(bitmap)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
HS_Scope *hs_scope = hs_scope_open();
|
||||
TEX_Scope *tex_scope = tex_scope_open();
|
||||
DF_VR_BitmapState *state = df_view_rule_block_user_state(key, DF_VR_BitmapState);
|
||||
if(state->last_open_frame_idx+1 < df_frame_index())
|
||||
{
|
||||
state->loaded_t = 0;
|
||||
}
|
||||
state->last_open_frame_idx = df_frame_index();
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: unpack context
|
||||
//
|
||||
DF_Entity *thread = df_entity_from_handle(df_interact_regs()->thread);
|
||||
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: evaluate expression
|
||||
//
|
||||
E_Eval value_eval = e_value_eval_from_eval(eval);
|
||||
U64 base_vaddr = value_eval.value.u64;
|
||||
DF_BitmapTopologyInfo topology_info = df_vr_bitmap_topology_info_from_cfg(cfg);
|
||||
U64 expected_size = topology_info.width*topology_info.height*r_tex2d_format_bytes_per_pixel_table[topology_info.fmt];
|
||||
Rng1U64 vaddr_range = r1u64(base_vaddr, base_vaddr+expected_size);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: map expression artifacts -> texture
|
||||
//
|
||||
U128 texture_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vaddr_range, 0);
|
||||
TEX_Topology topology = tex_topology_make(v2s32((S32)topology_info.width, (S32)topology_info.height), topology_info.fmt);
|
||||
R_Handle texture = tex_texture_from_key_topology(tex_scope, texture_key, topology, 0);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: animate
|
||||
//
|
||||
if(expected_size != 0)
|
||||
{
|
||||
if(r_handle_match(r_handle_zero(), texture))
|
||||
{
|
||||
df_gfx_request_frame();
|
||||
state->loaded_t = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
F32 rate = 1 - pow_f32(2, (-15.f * df_dt()));
|
||||
state->loaded_t += (1.f - state->loaded_t) * rate;
|
||||
if(state->loaded_t < 0.99f)
|
||||
{
|
||||
df_gfx_request_frame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: build preview
|
||||
//
|
||||
if(expected_size != 0)
|
||||
{
|
||||
F32 img_dim = dim.y - ui_top_font_size()*2.f;
|
||||
UI_Padding(ui_pct(1.f, 0.f))
|
||||
UI_PrefWidth(ui_px(img_dim*((F32)topology_info.width/(F32)topology_info.height), 1.f))
|
||||
UI_Column UI_Padding(ui_pct(1.f, 0.f))
|
||||
UI_PrefHeight(ui_px(img_dim, 1.f))
|
||||
{
|
||||
ui_image(texture, R_Tex2DSampleKind_Nearest, r2f32(v2f32(0, 0), v2f32((F32)topology_info.width, (F32)topology_info.height)), v4f32(1, 1, 1, state->loaded_t), 10.f*(1-state->loaded_t), str8_lit("image_box"));
|
||||
}
|
||||
}
|
||||
|
||||
tex_scope_close(tex_scope);
|
||||
hs_scope_close(hs_scope);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
DF_VIEW_SETUP_FUNCTION_DEF(bitmap)
|
||||
{
|
||||
DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState);
|
||||
DF_CfgNode *view_center_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("view_center"), StringMatchFlag_CaseInsensitive);
|
||||
DF_CfgNode *zoom_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("zoom"), StringMatchFlag_CaseInsensitive);
|
||||
DF_CfgNode *bitmap_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("bitmap"), StringMatchFlag_CaseInsensitive);
|
||||
DF_Entity *thread = df_entity_from_handle(df_interact_regs()->thread);
|
||||
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
|
||||
U64 thread_unwind_rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, df_interact_regs()->unwind_count);
|
||||
bvs->view_center_pos.x = (F32)f64_from_str8(bitmap_cfg->first->string);
|
||||
bvs->view_center_pos.y = (F32)f64_from_str8(bitmap_cfg->first->next->string);
|
||||
bvs->zoom = (F32)f64_from_str8(zoom_cfg->first->string);
|
||||
bvs->top = df_vr_bitmap_topology_info_from_cfg(bitmap_cfg);
|
||||
if(bvs->zoom == 0)
|
||||
{
|
||||
bvs->zoom = 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(bitmap)
|
||||
{
|
||||
DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState);
|
||||
String8 result = push_str8f(arena, "view_center:(%.2f %.2f) zoom:(%.2f) bitmap:(w:%I64u, h:%I64u, fmt:%S)",
|
||||
bvs->view_center_pos.x,
|
||||
bvs->view_center_pos.y,
|
||||
bvs->zoom,
|
||||
bvs->top.width,
|
||||
bvs->top.height,
|
||||
r_tex2d_format_display_string_table[bvs->top.fmt]);
|
||||
return result;
|
||||
}
|
||||
|
||||
DF_VIEW_CMD_FUNCTION_DEF(bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
DF_VIEW_UI_FUNCTION_DEF(bitmap)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: "geo"
|
||||
|
||||
|
||||
@@ -38,35 +38,6 @@ struct DF_VR_DisasmState
|
||||
F32 loaded_t;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: "bitmap"
|
||||
|
||||
typedef struct DF_BitmapTopologyInfo DF_BitmapTopologyInfo;
|
||||
struct DF_BitmapTopologyInfo
|
||||
{
|
||||
U64 width;
|
||||
U64 height;
|
||||
R_Tex2DFormat fmt;
|
||||
};
|
||||
|
||||
typedef struct DF_VR_BitmapState DF_VR_BitmapState;
|
||||
struct DF_VR_BitmapState
|
||||
{
|
||||
U64 last_open_frame_idx;
|
||||
F32 loaded_t;
|
||||
};
|
||||
|
||||
typedef struct DF_VR_BitmapBoxDrawData DF_VR_BitmapBoxDrawData;
|
||||
struct DF_VR_BitmapBoxDrawData
|
||||
{
|
||||
Rng2F32 src;
|
||||
R_Handle texture;
|
||||
F32 loaded_t;
|
||||
B32 hovered;
|
||||
Vec2S32 mouse_px;
|
||||
F32 ui_per_bmp_px;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: "geo"
|
||||
|
||||
|
||||
+112
-48
@@ -6862,6 +6862,8 @@ DF_VIEW_SETUP_FUNCTION_DEF(Disassembly)
|
||||
if(dv->initialized == 0)
|
||||
{
|
||||
dv->initialized = 1;
|
||||
dv->cursor = txt_pt(1, 1);
|
||||
dv->mark = txt_pt(1, 1);
|
||||
dv->style_flags = DASM_StyleFlag_Addresses|DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines|DASM_StyleFlag_SymbolNames;
|
||||
df_code_view_init(&dv->cv, view);
|
||||
}
|
||||
@@ -6875,23 +6877,54 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
|
||||
HS_Scope *hs_scope = hs_scope_open();
|
||||
TXT_Scope *txt_scope = txt_scope_open();
|
||||
|
||||
//- rjf: unpack disasm info
|
||||
DF_Entity *process = df_entity_from_handle(dv->process);
|
||||
Architecture arch = df_architecture_from_entity(process);
|
||||
U64 dasm_base_vaddr = AlignDownPow2(dv->base_vaddr, KB(16));
|
||||
DF_Entity *dasm_module = df_module_from_process_vaddr(process, dasm_base_vaddr);
|
||||
DI_Key dasm_dbgi_key = df_dbgi_key_from_module(dasm_module);
|
||||
Rng1U64 dasm_vaddr_range = r1u64(dasm_base_vaddr, dasm_base_vaddr+KB(16));
|
||||
U128 dasm_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, dasm_vaddr_range, 0);
|
||||
//////////////////////////////
|
||||
//- rjf: if disassembly views are not parameterized by anything, they
|
||||
// automatically snap to the selected thread's RIP, rounded down to the
|
||||
// nearest 16K boundary
|
||||
//
|
||||
B32 auto_selected_thread = 0;
|
||||
if(string.size == 0)
|
||||
{
|
||||
auto_selected_thread = 1;
|
||||
string = str8_lit("(rip.u64 & (~(0x4000 - 1))");
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: unpack parameterization info
|
||||
//
|
||||
E_Eval eval = e_eval_from_string(scratch.arena, string);
|
||||
E_Space space = eval.space;
|
||||
if(auto_selected_thread)
|
||||
{
|
||||
space = df_eval_space_from_entity(df_entity_from_handle(df_interact_regs()->process));
|
||||
}
|
||||
Rng1U64 range = df_range_from_eval_params(eval, params);
|
||||
Architecture arch = df_architecture_from_eval_params(eval, params);
|
||||
DF_Entity *space_entity = df_entity_from_eval_space(space);
|
||||
DF_Entity *dasm_module = &df_g_nil_entity;
|
||||
DI_Key dbgi_key = {0};
|
||||
U64 base_vaddr = 0;
|
||||
switch(space_entity->kind)
|
||||
{
|
||||
default:{}break;
|
||||
case DF_EntityKind_Process:
|
||||
{
|
||||
arch = df_architecture_from_entity(space_entity);
|
||||
dasm_module = df_module_from_process_vaddr(space_entity, range.min);
|
||||
dbgi_key = df_dbgi_key_from_module(dasm_module);
|
||||
base_vaddr = dasm_module->vaddr_rng.min;
|
||||
}break;
|
||||
}
|
||||
U128 dasm_key = df_key_from_eval_space_range(space, range, 0);
|
||||
U128 dasm_data_hash = {0};
|
||||
DASM_Params dasm_params = {0};
|
||||
{
|
||||
dasm_params.vaddr = dasm_vaddr_range.min;
|
||||
dasm_params.arch = arch;
|
||||
dasm_params.vaddr = range.min;
|
||||
dasm_params.arch = arch;
|
||||
dasm_params.style_flags = dv->style_flags;
|
||||
dasm_params.syntax = DASM_Syntax_Intel;
|
||||
dasm_params.base_vaddr = dasm_module->vaddr_rng.min;
|
||||
dasm_params.dbgi_key = dasm_dbgi_key;
|
||||
dasm_params.syntax = DASM_Syntax_Intel;
|
||||
dasm_params.base_vaddr = base_vaddr;
|
||||
dasm_params.dbgi_key = dbgi_key;
|
||||
}
|
||||
DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &dasm_data_hash);
|
||||
df_interact_regs()->text_key = dasm_info.text_key;
|
||||
@@ -6899,11 +6932,17 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
|
||||
U128 dasm_text_hash = {0};
|
||||
TXT_TextInfo dasm_text_info = txt_text_info_from_key_lang(txt_scope, df_interact_regs()->text_key, df_interact_regs()->lang_kind, &dasm_text_hash);
|
||||
String8 dasm_text_data = hs_data_from_hash(hs_scope, dasm_text_hash);
|
||||
B32 has_disasm = (dasm_info.lines.count != 0 && dasm_text_info.lines_count != 0);
|
||||
B32 is_loading = (!has_disasm && dim_1u64(range) != 0 && eval.msgs.max_kind == E_MsgKind_Null);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: process general code-view commands
|
||||
df_code_view_cmds(ws, panel, view, &dv->cv, cmds, dasm_text_data, &dasm_text_info, &dasm_info.lines, dasm_vaddr_range, dasm_dbgi_key);
|
||||
//
|
||||
df_code_view_cmds(ws, panel, view, &dv->cv, cmds, dasm_text_data, &dasm_text_info, &dasm_info.lines, range, dbgi_key);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: process disassembly-specific commands
|
||||
//
|
||||
for(DF_CmdNode *n = cmds->first; n != 0; n = n->next)
|
||||
{
|
||||
DF_Cmd *cmd = &n->cmd;
|
||||
@@ -6939,8 +6978,6 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
|
||||
}
|
||||
}
|
||||
}
|
||||
dv->process = df_handle_from_entity(process);
|
||||
dv->base_vaddr = params.vaddr;
|
||||
dv->goto_vaddr = params.vaddr;
|
||||
}break;
|
||||
case DF_CoreCmdKind_ToggleCodeBytesVisibility: {dv->style_flags ^= DASM_StyleFlag_CodeBytes;}break;
|
||||
@@ -6963,44 +7000,63 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
DASM_Scope *dasm_scope = dasm_scope_open();
|
||||
TXT_Scope *txt_scope = txt_scope_open();
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: if disassembly views are not parameterized by anything, they
|
||||
// automatically snap to the selected thread's RIP, rounded down to the
|
||||
// nearest 16K boundary
|
||||
//
|
||||
B32 auto_selected_thread = 0;
|
||||
if(string.size == 0)
|
||||
{
|
||||
auto_selected_thread = 1;
|
||||
string = str8_lit("(rip.u64 & (~(0x4000 - 1))");
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: set up invariants
|
||||
//
|
||||
F32 bottom_bar_height = ui_top_font_size()*2.f;
|
||||
Rng2F32 code_area_rect = r2f32p(rect.x0, rect.y0, rect.x1, rect.y1 - bottom_bar_height);
|
||||
Rng2F32 bottom_bar_rect = r2f32p(rect.x0, rect.y1 - bottom_bar_height, rect.x1, rect.y1);
|
||||
df_interact_regs()->cursor = dv->cursor;
|
||||
df_interact_regs()->mark = dv->mark;
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: no disasm process open? -> snap to selected thread
|
||||
//- rjf: unpack parameterization info
|
||||
//
|
||||
if(df_entity_is_nil(df_entity_from_handle(dv->process)))
|
||||
E_Eval eval = e_eval_from_string(scratch.arena, string);
|
||||
E_Space space = eval.space;
|
||||
if(auto_selected_thread)
|
||||
{
|
||||
DF_Entity *thread = df_entity_from_handle(df_interact_regs()->thread);
|
||||
U64 rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, df_interact_regs()->unwind_count);
|
||||
dv->process = df_handle_from_entity(df_entity_ancestor_from_kind(thread, DF_EntityKind_Process));
|
||||
dv->base_vaddr = rip_vaddr;
|
||||
dv->goto_vaddr = rip_vaddr;
|
||||
space = df_eval_space_from_entity(df_entity_from_handle(df_interact_regs()->process));
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: unpack disassembly info
|
||||
//
|
||||
DF_Entity *process = df_entity_from_handle(dv->process);
|
||||
Architecture arch = df_architecture_from_entity(process);
|
||||
U64 dasm_base_vaddr = AlignDownPow2(dv->base_vaddr, KB(16));
|
||||
DF_Entity *dasm_module = df_module_from_process_vaddr(process, dasm_base_vaddr);
|
||||
DI_Key dasm_dbgi_key = df_dbgi_key_from_module(dasm_module);
|
||||
Rng1U64 dasm_vaddr_range = r1u64(dasm_base_vaddr, dasm_base_vaddr+KB(16));
|
||||
U128 dasm_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, dasm_vaddr_range, 0);
|
||||
Rng1U64 range = df_range_from_eval_params(eval, params);
|
||||
Architecture arch = df_architecture_from_eval_params(eval, params);
|
||||
DF_Entity *space_entity = df_entity_from_eval_space(space);
|
||||
DF_Entity *dasm_module = &df_g_nil_entity;
|
||||
DI_Key dbgi_key = {0};
|
||||
U64 base_vaddr = 0;
|
||||
switch(space_entity->kind)
|
||||
{
|
||||
default:{}break;
|
||||
case DF_EntityKind_Process:
|
||||
{
|
||||
arch = df_architecture_from_entity(space_entity);
|
||||
dasm_module = df_module_from_process_vaddr(space_entity, range.min);
|
||||
dbgi_key = df_dbgi_key_from_module(dasm_module);
|
||||
base_vaddr = dasm_module->vaddr_rng.min;
|
||||
}break;
|
||||
}
|
||||
U128 dasm_key = df_key_from_eval_space_range(space, range, 0);
|
||||
U128 dasm_data_hash = {0};
|
||||
DASM_Params dasm_params = {0};
|
||||
{
|
||||
dasm_params.vaddr = dasm_vaddr_range.min;
|
||||
dasm_params.arch = arch;
|
||||
dasm_params.vaddr = range.min;
|
||||
dasm_params.arch = arch;
|
||||
dasm_params.style_flags = dv->style_flags;
|
||||
dasm_params.syntax = DASM_Syntax_Intel;
|
||||
dasm_params.base_vaddr = dasm_module->vaddr_rng.min;
|
||||
dasm_params.dbgi_key = dasm_dbgi_key;
|
||||
dasm_params.syntax = DASM_Syntax_Intel;
|
||||
dasm_params.base_vaddr = base_vaddr;
|
||||
dasm_params.dbgi_key = dbgi_key;
|
||||
}
|
||||
DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &dasm_data_hash);
|
||||
df_interact_regs()->text_key = dasm_info.text_key;
|
||||
@@ -7009,7 +7065,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
TXT_TextInfo dasm_text_info = txt_text_info_from_key_lang(txt_scope, df_interact_regs()->text_key, df_interact_regs()->lang_kind, &dasm_text_hash);
|
||||
String8 dasm_text_data = hs_data_from_hash(hs_scope, dasm_text_hash);
|
||||
B32 has_disasm = (dasm_info.lines.count != 0 && dasm_text_info.lines_count != 0);
|
||||
B32 is_loading = (!has_disasm && !df_entity_is_nil(process) && dim_1u64(dasm_vaddr_range) != 0);
|
||||
B32 is_loading = (!has_disasm && dim_1u64(range) != 0 && eval.msgs.max_kind == E_MsgKind_Null);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: is loading -> equip view with loading information
|
||||
@@ -7026,7 +7082,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
{
|
||||
U64 vaddr = dv->goto_vaddr;
|
||||
dv->goto_vaddr = 0;
|
||||
U64 line_idx = dasm_line_array_idx_from_code_off__linear_scan(&dasm_info.lines, vaddr-dasm_vaddr_range.min);
|
||||
U64 line_idx = dasm_line_array_idx_from_code_off__linear_scan(&dasm_info.lines, vaddr-range.min);
|
||||
S64 line_num = (S64)(line_idx+1);
|
||||
cv->goto_line_num = line_num;
|
||||
}
|
||||
@@ -7036,7 +7092,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
//
|
||||
if(!is_loading && has_disasm)
|
||||
{
|
||||
df_code_view_build(scratch.arena, ws, panel, view, cv, DF_CodeViewBuildFlag_All, code_area_rect, dasm_text_data, &dasm_text_info, &dasm_info.lines, dasm_vaddr_range, dasm_dbgi_key);
|
||||
df_code_view_build(scratch.arena, ws, panel, view, cv, DF_CodeViewBuildFlag_All, code_area_rect, dasm_text_data, &dasm_text_info, &dasm_info.lines, range, dbgi_key);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
@@ -7045,9 +7101,9 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
if(!is_loading && has_disasm)
|
||||
{
|
||||
U64 off = dasm_line_array_code_off_from_idx(&dasm_info.lines, df_interact_regs()->cursor.line-1);
|
||||
df_interact_regs()->vaddr_range = r1u64(dasm_base_vaddr+off, dasm_base_vaddr+off);
|
||||
df_interact_regs()->vaddr_range = r1u64(base_vaddr+off, base_vaddr+off);
|
||||
df_interact_regs()->voff_range = df_voff_range_from_vaddr_range(dasm_module, df_interact_regs()->vaddr_range);
|
||||
df_interact_regs()->lines = df_lines_from_dbgi_key_voff(df_frame_arena(), &dasm_dbgi_key, df_interact_regs()->voff_range.min);
|
||||
df_interact_regs()->lines = df_lines_from_dbgi_key_voff(df_frame_arena(), &dbgi_key, df_interact_regs()->voff_range.min);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
@@ -7063,10 +7119,12 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
UI_FlagsAdd(UI_BoxFlag_DrawTextWeak)
|
||||
DF_Font(ws, DF_FontSlot_Code)
|
||||
{
|
||||
DF_Entity *module = df_module_from_process_vaddr(process, dasm_vaddr_range.min);
|
||||
U64 cursor_vaddr = (1 <= df_interact_regs()->cursor.line && df_interact_regs()->cursor.line <= dasm_info.lines.count) ? (dasm_vaddr_range.min+dasm_info.lines.v[df_interact_regs()->cursor.line-1].code_off) : 0;
|
||||
ui_labelf("%S", path_normalized_from_string(scratch.arena, module->name));
|
||||
ui_spacer(ui_em(1.5f, 1));
|
||||
U64 cursor_vaddr = (1 <= df_interact_regs()->cursor.line && df_interact_regs()->cursor.line <= dasm_info.lines.count) ? (range.min+dasm_info.lines.v[df_interact_regs()->cursor.line-1].code_off) : 0;
|
||||
if(!df_entity_is_nil(dasm_module))
|
||||
{
|
||||
ui_labelf("%S", path_normalized_from_string(scratch.arena, dasm_module->name));
|
||||
ui_spacer(ui_em(1.5f, 1));
|
||||
}
|
||||
ui_labelf("Address: 0x%I64x, Line: %I64d, Column: %I64d", cursor_vaddr, df_interact_regs()->cursor.line, df_interact_regs()->cursor.column);
|
||||
ui_spacer(ui_pct(1, 0));
|
||||
ui_labelf("(read only)");
|
||||
@@ -7074,6 +7132,12 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: commit storage
|
||||
//
|
||||
dv->cursor = df_interact_regs()->cursor;
|
||||
dv->mark = df_interact_regs()->mark;
|
||||
|
||||
txt_scope_close(txt_scope);
|
||||
dasm_scope_close(dasm_scope);
|
||||
hs_scope_close(hs_scope);
|
||||
|
||||
@@ -419,8 +419,8 @@ typedef struct DF_DisasmViewState DF_DisasmViewState;
|
||||
struct DF_DisasmViewState
|
||||
{
|
||||
B32 initialized;
|
||||
DF_Handle process;
|
||||
U64 base_vaddr;
|
||||
TxtPt cursor;
|
||||
TxtPt mark;
|
||||
DASM_StyleFlags style_flags;
|
||||
U64 goto_vaddr;
|
||||
DF_CodeViewState cv;
|
||||
|
||||
@@ -432,7 +432,7 @@ fp_raster(Arena *arena, FP_Handle font_handle, F32 size, FP_RasterFlags flags, S
|
||||
F32 right_side_bearing = 0;
|
||||
if(font.face != 0)
|
||||
{
|
||||
atlas_dim.y = (S16)((96.f/72.f) * size * (font_metrics.ascent + font_metrics.descent) / design_units_per_em);
|
||||
atlas_dim.y = (S16)ceil_f32((96.f/72.f) * size * (font_metrics.ascent + font_metrics.descent) / design_units_per_em);
|
||||
for(U64 idx = 0; idx < glyphs_count; idx += 1)
|
||||
{
|
||||
DWRITE_GLYPH_METRICS *glyph_metrics = glyphs_metrics + idx;
|
||||
|
||||
Reference in New Issue
Block a user