diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 846e1720..ffa258d2 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -5403,15 +5403,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) //- rjf: unpack process/module info CTRL_Entity *process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->process)); - CTRL_Entity *module = &ctrl_entity_nil; - for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next) - { - if(child->kind == CTRL_EntityKind_Module) - { - module = child; - break; - } - } + CTRL_Entity *module = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Module); U64 module_base_vaddr = module->vaddr_range.min; CTRL_Entity *dbg_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); DI_Key dbgi_key = {dbg_path->string, dbg_path->timestamp}; @@ -5448,6 +5440,41 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) } } + //- rjf: add traps for module-baked entry points, if specified + if(!entries_found) + { + String8 raddbg_data = ctrl_raddbg_data_from_module(scratch.arena, module->handle); + U8 split_char = 0; + String8List raddbg_data_text_parts = str8_split(scratch.arena, raddbg_data, &split_char, 1, 0); + for(String8Node *text_n = raddbg_data_text_parts.first; text_n != 0; text_n = text_n->next) + { + String8 text = text_n->string; + MD_Node *root = md_tree_from_string(scratch.arena, text); + if(str8_match(root->first->string, str8_lit("entry_point"), 0)) + { + String8 name = root->first->first->string; + U32 procedure_id = 0; + { + RDI_NameMapNode *node = rdi_name_map_lookup(rdi, &map, name.str, name.size); + U32 id_count = 0; + U32 *ids = rdi_matches_from_map_node(rdi, node, &id_count); + if(id_count > 0) + { + procedure_id = ids[0]; + } + } + RDI_Procedure *procedure = rdi_element_from_name_idx(rdi, Procedures, procedure_id); + U64 voff = rdi_first_voff_from_procedure(rdi, procedure); + if(voff != 0) + { + entries_found = 1; + DMN_Trap trap = {process->handle.dmn_handle, module_base_vaddr + voff}; + dmn_trap_chunk_list_push(scratch.arena, &entry_traps, 256, &trap); + } + } + } + } + //- rjf: add traps for PID-correllated entry points if(!entries_found) { diff --git a/src/eval/eval_core.h b/src/eval/eval_core.h index 1a5792b9..e887e1c2 100644 --- a/src/eval/eval_core.h +++ b/src/eval/eval_core.h @@ -523,11 +523,11 @@ struct E_LookupRuleMap U64 slots_count; }; -typedef struct E_LookupRuleTagPair E_LookupRuleTagPair; -struct E_LookupRuleTagPair +typedef struct E_LookupRuleExprPair E_LookupRuleExprPair; +struct E_LookupRuleExprPair { E_LookupRule *rule; - E_Expr *tag; + E_Expr *expr; }; //////////////////////////////// diff --git a/src/eval/eval_ir.c b/src/eval/eval_ir.c index 70937c02..ccb15550 100644 --- a/src/eval/eval_ir.c +++ b/src/eval/eval_ir.c @@ -1818,11 +1818,11 @@ E_IRGEN_FUNCTION_DEF(default) E_Expr *lhs = expr->first; E_Expr *rhs = lhs->next; E_IRTreeAndType lhs_irtree = e_irtree_and_type_from_expr(scratch.arena, lhs); - E_LookupRule *lookup_rule = &e_lookup_rule__default; - ProfScope("lookup via rule '%.*s'", str8_varg(lookup_rule->name)) + E_LookupRuleExprPair lhs_lookup_rule = e_lookup_rule_expr_pair_from_expr_irtree(lhs, &lhs_irtree); + ProfScope("lookup via rule '%.*s'", str8_varg(lhs_lookup_rule.rule->name)) { - E_LookupInfo lookup_info = lookup_rule->info(arena, &lhs_irtree, &e_expr_nil, str8_zero()); - E_LookupAccess lookup_access = lookup_rule->access(arena, expr->kind, lhs, rhs, &e_expr_nil, lookup_info.user_data); + E_LookupInfo lookup_info = lhs_lookup_rule.rule->info(arena, &lhs_irtree, lhs_lookup_rule.expr, str8_zero()); + E_LookupAccess lookup_access = lhs_lookup_rule.rule->access(arena, expr->kind, lhs, rhs, lhs_lookup_rule.expr, lookup_info.user_data); result = lookup_access.irtree_and_type; } scratch_end(scratch); @@ -3339,11 +3339,31 @@ e_expr_irext_cast(Arena *arena, E_Expr *rhs, E_IRTreeAndType *rhs_irtree, E_Type //////////////////////////////// //~ rjf: Expression & IR-Tree => Rules +internal E_LookupRuleExprPair +e_lookup_rule_expr_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree) +{ + E_LookupRuleExprPair result = {&e_lookup_rule__default, &e_expr_nil}; + + // rjf: first, try set name -> rule mapping + if(result.rule == &e_lookup_rule__default && e_type_kind_from_key(irtree->type_key) == E_TypeKind_Set) + { + E_Type *type = e_type_from_key__cached(irtree->type_key); + String8 name = type->name; + E_LookupRule *candidate = e_lookup_rule_from_string(name); + if(candidate != &e_lookup_rule__nil) + { + result.rule = candidate; + } + } + + return result; +} + #if 0 // TODO(rjf): @eval -internal E_LookupRuleTagPair +internal E_LookupRuleExprPair e_lookup_rule_tag_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree) { - E_LookupRuleTagPair result = {&e_lookup_rule__default, &e_expr_nil}; + E_LookupRuleExprPair result = {&e_lookup_rule__default, &e_expr_nil}; { // rjf: first try explicitly-stored tags B32 default_is_forced = 0; diff --git a/src/eval/eval_ir.h b/src/eval/eval_ir.h index 18be9eee..105765a9 100644 --- a/src/eval/eval_ir.h +++ b/src/eval/eval_ir.h @@ -288,8 +288,10 @@ internal E_Expr *e_expr_irext_cast(Arena *arena, E_Expr *rhs, E_IRTreeAndType *r //////////////////////////////// //~ rjf: Expression & IR-Tree => Rules +internal E_LookupRuleExprPair e_lookup_rule_expr_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree); + #if 0 // TODO(rjf): @eval -internal E_LookupRuleTagPair e_lookup_rule_tag_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree); +internal E_LookupRuleExprPair e_lookup_rule_tag_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree); #endif #endif // EVAL_IR_H diff --git a/src/eval_visualization/eval_visualization_core.c b/src/eval_visualization/eval_visualization_core.c index a292c43f..9332bf9c 100644 --- a/src/eval_visualization/eval_visualization_core.c +++ b/src/eval_visualization/eval_visualization_core.c @@ -608,9 +608,10 @@ ev_block_tree_from_exprs(Arena *arena, EV_View *view, String8 filter, E_ExprChai } // rjf: get expr's lookup rule - // TODO(rjf): @eval E_LookupRuleTagPair lookup_rule_and_tag = &e_lookup_rule_tag_pair_from_expr_irtree(t->expr, &expr_irtree); - E_LookupRule *lookup_rule = &e_lookup_rule__default; - E_Expr *lookup_rule_tag = &e_expr_nil; + // TODO(rjf): @eval E_LookupRuleExprPair lookup_rule_and_tag = &e_lookup_rule_tag_pair_from_expr_irtree(t->expr, &expr_irtree); + E_LookupRuleExprPair lookup_rule_and_tag = e_lookup_rule_expr_pair_from_expr_irtree(t->expr, &expr_irtree); + E_LookupRule *lookup_rule = lookup_rule_and_tag.rule; + E_Expr *lookup_rule_tag = lookup_rule_and_tag.expr; // rjf: get top-level lookup/expansion info E_LookupInfo lookup_info = lookup_rule->info(arena, &expr_irtree, lookup_rule_tag, filter); diff --git a/src/lib_raddbg_markup/raddbg_markup.h b/src/lib_raddbg_markup/raddbg_markup.h index 84bddf4e..a141fa53 100644 --- a/src/lib_raddbg_markup/raddbg_markup.h +++ b/src/lib_raddbg_markup/raddbg_markup.h @@ -25,7 +25,8 @@ # define raddbg_watch(fmt, ...) ((void)0) # define raddbg_pin(expr, ...) # define raddbg_log(fmt, ...) ((void)0) -# define raddbg_auto_view_rule(type, ...) struct raddbg_glue(raddbg_auto_view_rule_stub__, __COUNTER__){int __unused__} +# define raddbg_entry_point(...) struct raddbg_gen_data_id(){int __unused__} +# define raddbg_auto_view_rule(type, ...) struct raddbg_gen_data_id(){int __unused__} #else # define raddbg_is_attached(...) raddbg_is_attached__impl() # define raddbg_thread_name(fmt, ...) raddbg_thread_name__impl((fmt), __VA_ARGS__) @@ -36,7 +37,8 @@ # define raddbg_watch(fmt, ...) raddbg_watch__impl((fmt), __VA_ARGS__) # define raddbg_pin(expr, ...) /* NOTE(rjf): inspected by debugger ui - does not change program execution */ # define raddbg_log(fmt, ...) raddbg_log__impl((fmt), __VA_ARGS__) -# define raddbg_auto_view_rule(type, ...) raddbg_exe_data static char raddbg_glue(raddbg_auto_view_rule_data__, __COUNTER__)[] = ("auto_view_rule: {type: \"" #type "\", view_rule: \"" #__VA_ARGS__ "\"}") +# define raddbg_entry_point(...) raddbg_exe_data static char raddbg_gen_data_id()[] = ("entry_point: " #__VA_ARGS__) +# define raddbg_auto_view_rule(type, ...) raddbg_exe_data static char raddbg_gen_data_id()()[] = ("auto_view_rule: {type: \"" #type "\", view_rule: \"" #__VA_ARGS__ "\"}") #endif //////////////////////////////// @@ -44,6 +46,7 @@ #define raddbg_glue_(a, b) a##b #define raddbg_glue(a, b) raddbg_glue_(a, b) +#define raddbg_gen_data_id() raddbg_glue(raddbg_data__, __COUNTER__) //////////////////////////////// //~ Win32 Implementations diff --git a/src/mule/mule_main.cpp b/src/mule/mule_main.cpp index 3962a8db..f1799a40 100644 --- a/src/mule/mule_main.cpp +++ b/src/mule/mule_main.cpp @@ -2685,6 +2685,8 @@ dynamic_step_test(void){ //////////////////////////////// +raddbg_entry_point(mule_main); + int mule_main(int argc, char** argv) { diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 5704bb8f..155e490a 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -10053,7 +10053,7 @@ rd_window_frame(void) // rjf: hot effect extension if(box->flags & UI_BoxFlag_DrawHotEffects) { - B32 is_hot = ui_key_match(box->key, ui_hot_key()); + B32 is_hot = !ui_key_match(box->key, ui_key_zero()) && ui_key_match(box->key, ui_hot_key()); Vec4F32 hover_color = ui_color_from_tags_key_name(box->tags_key, str8_lit("hover")); // rjf: brighten @@ -10264,7 +10264,7 @@ rd_window_frame(void) if(b->flags & UI_BoxFlag_DrawHotEffects) { Vec4F32 color = ui_color_from_tags_key_name(box->tags_key, str8_lit("hover")); - if(!ui_key_match(b->key, ui_hot_key())) + if(ui_key_match(b->key, ui_key_zero()) || !ui_key_match(b->key, ui_hot_key())) { color.w *= b->hot_t; } diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index 7f7971a5..6c271264 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -78,6 +78,9 @@ // code. This is used by the debugger UI, but does not show up anywhere // other than the source code, so it can either be used as a macro (which // expands to nothing), or in comments too. +// - `raddbg_entry_point(name)`, e.g. `raddbg_entry_point(entry_point)`: +// declares the entry point for an executable, which the debugger will use +// when stepping into a program, rather than the defaults (e.g. `main`). // - `raddbg_auto_view_rule(, )`, e.g. // `raddbg_auto_view_rule(DynamicArray, slice)`: declares an // auto-view-rule from source code, rather than from debugger