diff --git a/project.4coder b/project.4coder index f6eaee9e..b4cbff1c 100644 --- a/project.4coder +++ b/project.4coder @@ -48,7 +48,7 @@ commands = .rjf_f1 = { //.win = "build rdi_from_pdb rdi_dump && pushd build && rdi_from_pdb --pdb:mule_main.pdb --out:mule_main.rdi && rdi_dump mule_main.rdi > mule_main.dump && popd", - .win = "build raddbg telemetry", + .win = "build raddbg telemetry release", .linux = "", .out = "*compilation*", .footer_panel = true, diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 6189dac8..2f04dbb4 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -3368,7 +3368,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, DMN_EventNode *next_event_node = ctrl_state->first_dmn_event_node; // rjf: log event - if(next_event_node != 0) CTRL_CtrlThreadLogScope + if(next_event_node != 0) { DMN_Event *ev = &next_event_node->v; log_infof("--- event ---\n"); @@ -3532,9 +3532,9 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // rjf: run for new events ProfScope("run for new events") { - CTRL_CtrlThreadLogScope log_infof("{dmn_ctrl_run ..."); + log_infof("{dmn_ctrl_run ..."); DMN_EventList events = dmn_ctrl_run(scratch.arena, ctrl_ctx, run_ctrls); - CTRL_CtrlThreadLogScope log_infof("}\n"); + log_infof("}\n"); for(DMN_EventNode *src_n = events.first; src_n != 0; src_n = src_n->next) { DMN_EventNode *dst_n = ctrl_state->free_dmn_event_node; @@ -4184,7 +4184,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) B32 hard_stop = 0; CTRL_EventCause hard_stop_cause = ctrl_event_cause_from_dmn_event_kind(event->kind); B32 use_stepping_logic = 0; - CTRL_CtrlThreadLogScope switch(event->kind) + switch(event->kind) { default:{}break; case DMN_EventKind_Error: @@ -4501,120 +4501,123 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) B32 hit_trap_net_bp = 0; B32 hit_conditional_bp_but_filtered = 0; CTRL_TrapFlags hit_trap_flags = 0; - if(!hard_stop && use_stepping_logic) CTRL_CtrlThreadLogScope + if(!hard_stop && use_stepping_logic && event->kind == DMN_EventKind_Breakpoint) + ProfScope("for breakpoint events, gather bp info") { - if(event->kind == DMN_EventKind_Breakpoint) + Temp temp = temp_begin(scratch.arena); + String8List conditions = {0}; + + // rjf: entry breakpoints + for(DMN_TrapChunkNode *n = entry_traps.first; n != 0; n = n->next) { - Temp temp = temp_begin(scratch.arena); - String8List conditions = {0}; - - // rjf: entry breakpoints - for(DMN_TrapChunkNode *n = entry_traps.first; n != 0; n = n->next) + DMN_Trap *trap = n->v; + DMN_Trap *opl = n->v + n->count; + for(;trap < opl; trap += 1) { - DMN_Trap *trap = n->v; - DMN_Trap *opl = n->v + n->count; - for(;trap < opl; trap += 1) + if(dmn_handle_match(trap->process, event->process) && trap->vaddr == event->instruction_pointer) { - if(dmn_handle_match(trap->process, event->process) && trap->vaddr == event->instruction_pointer) + hit_entry = 1; + } + } + } + + // rjf: user breakpoints + for(DMN_TrapChunkNode *n = user_traps.first; n != 0; n = n->next) + { + DMN_Trap *trap = n->v; + DMN_Trap *opl = n->v + n->count; + for(;trap < opl; trap += 1) + { + if(dmn_handle_match(trap->process, event->process) && + trap->vaddr == event->instruction_pointer && + (!dmn_handle_match(event->thread, target_thread) || !target_thread_is_on_user_bp_and_trap_net_trap)) + { + CTRL_UserBreakpoint *user_bp = (CTRL_UserBreakpoint *)trap->id; + hit_user_bp = 1; + if(user_bp != 0 && user_bp->condition.size != 0) { - hit_entry = 1; + str8_list_push(temp.arena, &conditions, user_bp->condition); } } } - - // rjf: user breakpoints - for(DMN_TrapChunkNode *n = user_traps.first; n != 0; n = n->next) + } + + // rjf: evaluate hit stop conditions + if(conditions.node_count != 0) ProfScope("evaluate hit stop conditions") + { + DI_Key dbgi_key = {dbg_path->string, dbg_path->timestamp}; + RDI_Parsed *rdi = di_rdi_from_key(di_scope, &dbgi_key, max_U64); + for(String8Node *condition_n = conditions.first; condition_n != 0; condition_n = condition_n->next) { - DMN_Trap *trap = n->v; - DMN_Trap *opl = n->v + n->count; - for(;trap < opl; trap += 1) + ProfBegin("compile expression"); + String8 string = condition_n->string; + EVAL_ParseCtx parse_ctx = zero_struct; { - if(dmn_handle_match(trap->process, event->process) && - trap->vaddr == event->instruction_pointer && - (!dmn_handle_match(event->thread, target_thread) || !target_thread_is_on_user_bp_and_trap_net_trap)) - { - CTRL_UserBreakpoint *user_bp = (CTRL_UserBreakpoint *)trap->id; - hit_user_bp = 1; - if(user_bp != 0 && user_bp->condition.size != 0) - { - str8_list_push(temp.arena, &conditions, user_bp->condition); - } - } + parse_ctx.arch = arch; + parse_ctx.ip_voff = thread_rip_voff; + parse_ctx.rdi = rdi; + parse_ctx.type_graph = tg_graph_begin(bit_size_from_arch(arch)/8, 256); + parse_ctx.regs_map = ctrl_string2reg_from_arch(arch); + parse_ctx.reg_alias_map = ctrl_string2alias_from_arch(arch); + parse_ctx.locals_map = eval_push_locals_map_from_rdi_voff(temp.arena, rdi, thread_rip_voff); + parse_ctx.member_map = eval_push_member_map_from_rdi_voff(temp.arena, rdi, thread_rip_voff); + } + EVAL_TokenArray tokens = eval_token_array_from_text(temp.arena, string); + EVAL_ParseResult parse = eval_parse_expr_from_text_tokens(temp.arena, &parse_ctx, string, &tokens); + EVAL_ErrorList errors = parse.errors; + B32 parse_has_expr = (parse.expr != &eval_expr_nil); + B32 parse_is_type = (parse_has_expr && parse.expr->kind == EVAL_ExprKind_TypeIdent); + EVAL_IRTreeAndType ir_tree_and_type = {&eval_irtree_nil}; + if(parse_has_expr && errors.count == 0) + { + ir_tree_and_type = eval_irtree_and_type_from_expr(temp.arena, parse_ctx.type_graph, rdi, &eval_string2expr_map_nil, parse.expr, &errors); + } + EVAL_OpList op_list = {0}; + if(parse_has_expr && ir_tree_and_type.tree != &eval_irtree_nil) + { + eval_oplist_from_irtree(scratch.arena, ir_tree_and_type.tree, &op_list); + } + String8 bytecode = {0}; + if(parse_has_expr && parse_is_type == 0 && op_list.encoded_size != 0) + { + bytecode = eval_bytecode_from_oplist(scratch.arena, &op_list); + } + ProfEnd(); + EVAL_Result eval = {0}; + if(bytecode.size != 0) ProfScope("evaluate expression") + { + U64 module_base = module->vaddr_range.min; + U64 tls_base = dmn_tls_root_vaddr_from_thread(event->thread); + EVAL_Machine machine = {0}; + machine.u = &event->process; + machine.arch = arch; + machine.memory_read = ctrl_eval_memory_read; + machine.reg_size = regs_block_size_from_architecture(arch); + machine.reg_data = push_array(scratch.arena, U8, machine.reg_size); + machine.module_base = &module_base; + machine.tls_base = &tls_base; + dmn_thread_read_reg_block(event->thread, machine.reg_data); + eval = eval_interpret(&machine, bytecode); + } + if(eval.code == EVAL_ResultCode_Good && eval.value.u64 == 0) + { + hit_user_bp = 0; + hit_conditional_bp_but_filtered = 1; + log_infof(">>> stepping >>> conditional breakpoint hit, but condition eval'd to 0, and so filtered\n"); + } + else + { + hit_user_bp = 1; + hit_conditional_bp_but_filtered = 0; + log_infof(">>> stepping >>> conditional breakpoint hit\n"); + break; } } - - // rjf: evaluate hit stop conditions - if(conditions.node_count != 0) - { - DI_Key dbgi_key = {dbg_path->string, dbg_path->timestamp}; - RDI_Parsed *rdi = di_rdi_from_key(di_scope, &dbgi_key, max_U64); - for(String8Node *condition_n = conditions.first; condition_n != 0; condition_n = condition_n->next) - { - String8 string = condition_n->string; - EVAL_ParseCtx parse_ctx = zero_struct; - { - parse_ctx.arch = arch; - parse_ctx.ip_voff = thread_rip_voff; - parse_ctx.rdi = rdi; - parse_ctx.type_graph = tg_graph_begin(bit_size_from_arch(arch)/8, 256); - parse_ctx.regs_map = ctrl_string2reg_from_arch(arch); - parse_ctx.reg_alias_map = ctrl_string2alias_from_arch(arch); - parse_ctx.locals_map = eval_push_locals_map_from_rdi_voff(temp.arena, rdi, thread_rip_voff); - parse_ctx.member_map = eval_push_member_map_from_rdi_voff(temp.arena, rdi, thread_rip_voff); - } - EVAL_TokenArray tokens = eval_token_array_from_text(temp.arena, string); - EVAL_ParseResult parse = eval_parse_expr_from_text_tokens(temp.arena, &parse_ctx, string, &tokens); - EVAL_ErrorList errors = parse.errors; - B32 parse_has_expr = (parse.expr != &eval_expr_nil); - B32 parse_is_type = (parse_has_expr && parse.expr->kind == EVAL_ExprKind_TypeIdent); - EVAL_IRTreeAndType ir_tree_and_type = {&eval_irtree_nil}; - if(parse_has_expr && errors.count == 0) - { - ir_tree_and_type = eval_irtree_and_type_from_expr(temp.arena, parse_ctx.type_graph, rdi, &eval_string2expr_map_nil, parse.expr, &errors); - } - EVAL_OpList op_list = {0}; - if(parse_has_expr && ir_tree_and_type.tree != &eval_irtree_nil) - { - eval_oplist_from_irtree(scratch.arena, ir_tree_and_type.tree, &op_list); - } - String8 bytecode = {0}; - if(parse_has_expr && parse_is_type == 0 && op_list.encoded_size != 0) - { - bytecode = eval_bytecode_from_oplist(scratch.arena, &op_list); - } - EVAL_Result eval = {0}; - if(bytecode.size != 0) - { - U64 module_base = module->vaddr_range.min; - U64 tls_base = dmn_tls_root_vaddr_from_thread(event->thread); - EVAL_Machine machine = {0}; - machine.u = &event->process; - machine.arch = arch; - machine.memory_read = ctrl_eval_memory_read; - machine.reg_size = regs_block_size_from_architecture(arch); - machine.reg_data = push_array(scratch.arena, U8, machine.reg_size); - machine.module_base = &module_base; - machine.tls_base = &tls_base; - dmn_thread_read_reg_block(event->thread, machine.reg_data); - eval = eval_interpret(&machine, bytecode); - } - if(eval.code == EVAL_ResultCode_Good && eval.value.u64 == 0) - { - hit_user_bp = 0; - hit_conditional_bp_but_filtered = 1; - log_infof(">>> stepping >>> conditional breakpoint hit, but condition eval'd to 0, and so filtered\n"); - } - else - { - hit_user_bp = 1; - hit_conditional_bp_but_filtered = 0; - log_infof(">>> stepping >>> conditional breakpoint hit\n"); - break; - } - } - } - - // rjf: gather trap net hits + } + + // rjf: gather trap net hits + ProfScope("gather trap net hits") + { if(!hit_user_bp && dmn_handle_match(event->process, target_process)) { for(CTRL_TrapNode *node = msg->traps.first; @@ -4628,11 +4631,11 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) } } } - - log_infof(">>> stepping >>> stepping logic - BP event -> hit_user_bp: %i\n", hit_user_bp); - log_infof(">>> stepping >>> stepping logic - BP event -> hit_entry: %i\n", hit_entry); - temp_end(temp); } + + log_infof(">>> stepping >>> stepping logic - BP event -> hit_user_bp: %i\n", hit_user_bp); + log_infof(">>> stepping >>> stepping logic - BP event -> hit_entry: %i\n", hit_entry); + temp_end(temp); } //- rjf: hit conditional user bp but filtered -> single step diff --git a/src/demon/win32/demon_core_win32.c b/src/demon/win32/demon_core_win32.c index 9b66a259..a9179885 100644 --- a/src/demon/win32/demon_core_win32.c +++ b/src/demon/win32/demon_core_win32.c @@ -1342,7 +1342,9 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) B32 any_processes_live = dmn_w32_shared->new_process_pending; if(!any_processes_live) { - for(DMN_W32_Entity *process = dmn_w32_shared->entities_base->first; process != &dmn_w32_entity_nil; process = process->next) + for(DMN_W32_Entity *process = dmn_w32_shared->entities_base->first; + process != &dmn_w32_entity_nil; + process = process->next) { if(process->kind == DMN_W32_EntityKind_Process) { @@ -1382,7 +1384,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) ////////////////////////// //- rjf: set single step bit // - if(!dmn_handle_match(ctrls->single_step_thread, dmn_handle_zero())) + if(!dmn_handle_match(ctrls->single_step_thread, dmn_handle_zero())) ProfScope("set single step bit") { DMN_W32_Entity *thread = dmn_w32_entity_from_handle(ctrls->single_step_thread); Architecture arch = thread->arch; diff --git a/src/render/d3d11/render_d3d11.c b/src/render/d3d11/render_d3d11.c index 50288498..b417243d 100644 --- a/src/render/d3d11/render_d3d11.c +++ b/src/render/d3d11/render_d3d11.c @@ -168,6 +168,7 @@ r_init(CmdLine *cmdln) r_d3d11_state->device_rw_mutex = os_rw_mutex_alloc(); //- rjf: create base device + ProfBegin("create base device"); UINT creation_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; #if BUILD_DEBUG if(cmd_line_has_flag(cmdln, str8_lit("d3d11_debug"))) @@ -199,7 +200,6 @@ r_init(CmdLine *cmdln) D3D11_SDK_VERSION, &r_d3d11_state->base_device, 0, &r_d3d11_state->base_device_ctx); } - if(FAILED(error)) { char buffer[256] = {0}; @@ -207,10 +207,11 @@ r_init(CmdLine *cmdln) os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); os_exit_process(1); } + ProfEnd(); //- rjf: enable break-on-error #if BUILD_DEBUG - if(cmd_line_has_flag(cmdln, str8_lit("d3d11_debug"))) + if(cmd_line_has_flag(cmdln, str8_lit("d3d11_debug"))) ProfScope("enable break-on-error") { ID3D11InfoQueue *info = 0; error = r_d3d11_state->base_device->lpVtbl->QueryInterface(r_d3d11_state->base_device, &IID_ID3D11InfoQueue, (void **)(&info)); @@ -224,15 +225,20 @@ r_init(CmdLine *cmdln) #endif //- rjf: get main device + ProfBegin("get main device"); error = r_d3d11_state->base_device->lpVtbl->QueryInterface(r_d3d11_state->base_device, &IID_ID3D11Device1, (void **)(&r_d3d11_state->device)); error = r_d3d11_state->base_device_ctx->lpVtbl->QueryInterface(r_d3d11_state->base_device_ctx, &IID_ID3D11DeviceContext1, (void **)(&r_d3d11_state->device_ctx)); + ProfEnd(); //- rjf: get dxgi device/adapter/factory + ProfBegin("get dxgi device/adapter/factory"); error = r_d3d11_state->device->lpVtbl->QueryInterface(r_d3d11_state->device, &IID_IDXGIDevice1, (void **)(&r_d3d11_state->dxgi_device)); error = r_d3d11_state->dxgi_device->lpVtbl->GetAdapter(r_d3d11_state->dxgi_device, &r_d3d11_state->dxgi_adapter); error = r_d3d11_state->dxgi_adapter->lpVtbl->GetParent(r_d3d11_state->dxgi_adapter, &IID_IDXGIFactory2, (void **)(&r_d3d11_state->dxgi_factory)); + ProfEnd(); //- rjf: create main rasterizer + ProfScope("create main rasterizer") { D3D11_RASTERIZER_DESC1 desc = {D3D11_FILL_SOLID}; { @@ -244,6 +250,7 @@ r_init(CmdLine *cmdln) } //- rjf: create main blend state + ProfScope("create main blend state") { D3D11_BLEND_DESC desc = {0}; { @@ -259,6 +266,8 @@ r_init(CmdLine *cmdln) error = r_d3d11_state->device->lpVtbl->CreateBlendState(r_d3d11_state->device, &desc, &r_d3d11_state->main_blend_state); } + //- rjf: create empty blend state + ProfScope("create empty blend state") { D3D11_BLEND_DESC desc = {0}; { @@ -269,6 +278,7 @@ r_init(CmdLine *cmdln) } //- rjf: create nearest-neighbor sampler + ProfScope("create nearest-neighbor sampler") { D3D11_SAMPLER_DESC desc = zero_struct; { @@ -282,6 +292,7 @@ r_init(CmdLine *cmdln) } //- rjf: create bilinear sampler + ProfScope("create bilinear sampler") { D3D11_SAMPLER_DESC desc = zero_struct; { @@ -295,6 +306,7 @@ r_init(CmdLine *cmdln) } //- rjf: create noop depth/stencil state + ProfScope("create noop depth/stencil state") { D3D11_DEPTH_STENCIL_DESC desc = {0}; { @@ -306,6 +318,7 @@ r_init(CmdLine *cmdln) } //- rjf: create plain depth/stencil state + ProfScope("create plain depth/stencil state") { D3D11_DEPTH_STENCIL_DESC desc = {0}; { @@ -317,6 +330,7 @@ r_init(CmdLine *cmdln) } //- rjf: create buffers + ProfScope("create buffers") { D3D11_BUFFER_DESC desc = {0}; { @@ -329,9 +343,10 @@ r_init(CmdLine *cmdln) } //- rjf: build vertex shaders & input layouts - for(R_D3D11_VShadKind kind = (R_D3D11_VShadKind)0; - kind < R_D3D11_VShadKind_COUNT; - kind = (R_D3D11_VShadKind)(kind+1)) + ProfScope("build vertex shaders & input layouts") + for(R_D3D11_VShadKind kind = (R_D3D11_VShadKind)0; + kind < R_D3D11_VShadKind_COUNT; + kind = (R_D3D11_VShadKind)(kind+1)) { String8 source = *r_d3d11_g_vshad_kind_source_table[kind]; String8 source_name = r_d3d11_g_vshad_kind_source_name_table[kind]; @@ -342,6 +357,7 @@ r_init(CmdLine *cmdln) ID3DBlob *vshad_source_blob = 0; ID3DBlob *vshad_source_errors = 0; ID3D11VertexShader *vshad = 0; + ProfScope("compile vertex shader") { error = D3DCompile(source.str, source.size, @@ -396,6 +412,7 @@ r_init(CmdLine *cmdln) ID3DBlob *pshad_source_blob = 0; ID3DBlob *pshad_source_errors = 0; ID3D11PixelShader *pshad = 0; + ProfScope("compile pixel shader") { error = D3DCompile(source.str, source.size, @@ -428,9 +445,10 @@ r_init(CmdLine *cmdln) } //- rjf: build uniform type buffers - for(R_D3D11_UniformTypeKind kind = (R_D3D11_UniformTypeKind)0; - kind < R_D3D11_UniformTypeKind_COUNT; - kind = (R_D3D11_UniformTypeKind)(kind+1)) + ProfScope("build uniform type buffers") + for(R_D3D11_UniformTypeKind kind = (R_D3D11_UniformTypeKind)0; + kind < R_D3D11_UniformTypeKind_COUNT; + kind = (R_D3D11_UniformTypeKind)(kind+1)) { ID3D11Buffer *buffer = 0; { @@ -449,6 +467,7 @@ r_init(CmdLine *cmdln) } //- rjf: create backup texture + ProfScope("create backup texture") { U32 backup_texture_data[] = {