diff --git a/src/dbgi/dbgi.c b/src/dbgi/dbgi.c index d1161c62..2228734c 100644 --- a/src/dbgi/dbgi.c +++ b/src/dbgi/dbgi.c @@ -1511,11 +1511,11 @@ di_match_store_alloc(void) store->match_name_slots = push_array(arena, DI_MatchNameSlot, store->match_name_slots_count); store->u2m_ring_cv = os_condition_variable_alloc(); store->u2m_ring_mutex = os_mutex_alloc(); - store->u2m_ring_size = KB(64); + store->u2m_ring_size = KB(2); store->u2m_ring_base = push_array_no_zero(arena, U8, store->u2m_ring_size); store->m2u_ring_cv = os_condition_variable_alloc(); store->m2u_ring_mutex = os_mutex_alloc(); - store->m2u_ring_size = KB(64); + store->m2u_ring_size = KB(2); store->m2u_ring_base = push_array_no_zero(arena, U8, store->m2u_ring_size); return store; } @@ -1547,22 +1547,27 @@ di_match_store_begin(DI_MatchStore *store, DI_KeyArray keys) for(DI_MatchNameNode *node = store->last_lru_match_name, *prev = 0; node != 0; node = prev) { prev = node->prev; - if(node->last_gen_touched+1 != store->gen) + if(node->last_gen_touched+64 < store->gen) { U64 slot_idx = node->hash%store->match_name_slots_count; DI_MatchNameSlot *slot = &store->match_name_slots[slot_idx]; DLLRemove_NP(store->first_lru_match_name, store->last_lru_match_name, node, lru_next, lru_prev); DLLRemove(slot->first, slot->last, node); SLLStackPush(store->first_free_match_name, node); + store->active_match_name_nodes_count -= 1; + } + else + { + break; } } } } -internal B32 -di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) +internal RDI_SectionKind +di_match_store_section_kind_from_name(DI_MatchStore *store, String8 name, U64 endt_us) { - B32 result = 0; + RDI_SectionKind result = 0; { // rjf: unpack name U64 hash = di_hash_from_string(name, 0); @@ -1597,6 +1602,7 @@ di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) DLLPushBack(slot->first, slot->last, node); node->first_gen_touched = store->gen; DLLInsert_NP(store->first_lru_match_name, store->last_lru_match_name, (DI_MatchNameNode *)0, node, lru_next, lru_prev); + store->active_match_name_nodes_count += 1; } // rjf: touch node for this gen @@ -1617,6 +1623,8 @@ di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) { store->u2m_ring_write_pos += ring_write_struct(store->u2m_ring_base, store->u2m_ring_size, store->u2m_ring_write_pos, &name.size); store->u2m_ring_write_pos += ring_write(store->u2m_ring_base, store->u2m_ring_size, store->u2m_ring_write_pos, name.str, name.size); + store->u2m_ring_write_pos += 7; + store->u2m_ring_write_pos -= store->u2m_ring_write_pos%8; sent = 1; break; } @@ -1637,7 +1645,7 @@ di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) // rjf: if this node's state is stale, consume results from match work & store them if(node->req_params_hash != node->cmp_params_hash) { - for(B32 done = 0; !done && os_now_microseconds() < endt_us;) + for(B32 done = 0; !done;) { Temp scratch = scratch_begin(0, 0); @@ -1655,6 +1663,8 @@ di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) store->m2u_ring_read_pos += ring_read_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_read_pos, &result_name.size); result_name.str = push_array(scratch.arena, U8, result_name.size); store->m2u_ring_read_pos += ring_read(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_read_pos, result_name.str, result_name.size); + store->m2u_ring_read_pos += 7; + store->m2u_ring_read_pos -= store->m2u_ring_read_pos%8; store->m2u_ring_read_pos += ring_read_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_read_pos, &result_params_hash); store->m2u_ring_read_pos += ring_read_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_read_pos, &result_dbgi_idx); store->m2u_ring_read_pos += ring_read_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_read_pos, &result_section_kind); @@ -1678,13 +1688,19 @@ di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) if(n->hash == result_hash && str8_match(result_name, n->name, 0)) { n->cmp_params_hash = result_params_hash; - n->has_matches = (result_idx != 0); + n->section_kind = result_section_kind; break; } } // rjf: we're done if we got the hash we were looking for - if(result_hash == hash) + if(result_hash == hash && result_params_hash == store->params_hash) + { + done = 1; + } + + // rjf: we're done if we're out of time + if(os_now_microseconds() >= endt_us) { done = 1; } @@ -1694,7 +1710,7 @@ di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us) } // rjf: return node present info - result = node->has_matches; + result = node->section_kind; } return result; } @@ -1714,11 +1730,85 @@ ASYNC_WORK_DEF(di_match_work) store->u2m_ring_read_pos += ring_read_struct(store->u2m_ring_base, store->u2m_ring_size, store->u2m_ring_read_pos, &name.size); name.str = push_array(scratch.arena, U8, name.size); store->u2m_ring_read_pos += ring_read(store->u2m_ring_base, store->u2m_ring_size, store->u2m_ring_read_pos, name.str, name.size); + store->u2m_ring_read_pos += 7; + store->u2m_ring_read_pos -= store->u2m_ring_read_pos%8; break; } os_condition_variable_wait(store->u2m_ring_cv, store->u2m_ring_mutex, max_U64); } os_condition_variable_broadcast(store->u2m_ring_cv); + + //- rjf: read parameters + U64 params_hash = 0; + DI_KeyArray params_keys = {0}; + OS_MutexScopeR(store->params_rw_mutex) + { + params_keys = di_key_array_copy(scratch.arena, &store->params_keys); + params_hash = store->params_hash; + } + + //- rjf: do match + RDI_NameMapKind name_map_kinds[] = + { + RDI_NameMapKind_GlobalVariables, + RDI_NameMapKind_ThreadVariables, + RDI_NameMapKind_Procedures, + RDI_NameMapKind_Types, + }; + RDI_SectionKind name_map_section_kinds[] = + { + RDI_SectionKind_GlobalVariables, + RDI_SectionKind_ThreadVariables, + RDI_SectionKind_Procedures, + RDI_SectionKind_TypeNodes, + }; + for EachIndex(dbgi_idx, params_keys.count) + { + DI_Scope *di_scope = di_scope_open(); + DI_Key key = params_keys.v[dbgi_idx]; + RDI_Parsed *rdi = di_rdi_from_key(di_scope, &key, max_U64); + for EachElement(name_map_kind_idx, name_map_kinds) + { + RDI_NameMap *name_map = rdi_element_from_name_idx(rdi, NameMaps, name_map_kinds[name_map_kind_idx]); + RDI_ParsedNameMap parsed_name_map = {0}; + rdi_parsed_from_name_map(rdi, name_map, &parsed_name_map); + RDI_NameMapNode *node = rdi_name_map_lookup(rdi, &parsed_name_map, name.str, name.size); + U32 num = 0; + U32 *run = rdi_matches_from_map_node(rdi, node, &num); + for(U32 run_idx = 0; run_idx < num; run_idx += 1) + { + OS_MutexScope(store->m2u_ring_mutex) for(;;) + { + U64 unconsumed_size = store->m2u_ring_write_pos - store->m2u_ring_read_pos; + U64 available_size = store->m2u_ring_size - unconsumed_size; + U64 needed_size = 0; + needed_size += sizeof(U64); + needed_size += name.size; + needed_size += 7; + needed_size -= needed_size%8; + needed_size += sizeof(U64); + needed_size += sizeof(U64); + needed_size += sizeof(RDI_SectionKind); + needed_size += sizeof(U32); + if(available_size >= needed_size) + { + store->m2u_ring_write_pos += ring_write_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_write_pos, &name.size); + store->m2u_ring_write_pos += ring_write(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_write_pos, name.str, name.size); + store->m2u_ring_write_pos += 7; + store->m2u_ring_write_pos -= store->m2u_ring_write_pos%8; + store->m2u_ring_write_pos += ring_write_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_write_pos, ¶ms_hash); + store->m2u_ring_write_pos += ring_write_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_write_pos, &dbgi_idx); + store->m2u_ring_write_pos += ring_write_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_write_pos, &name_map_section_kinds[name_map_kind_idx]); + store->m2u_ring_write_pos += ring_write_struct(store->m2u_ring_base, store->m2u_ring_size, store->m2u_ring_write_pos, &run[run_idx]); + break; + } + os_condition_variable_wait(store->m2u_ring_cv, store->m2u_ring_mutex, max_U64); + } + os_condition_variable_broadcast(store->m2u_ring_cv); + } + } + di_scope_close(di_scope); + } } scratch_end(scratch); return 0; diff --git a/src/dbgi/dbgi.h b/src/dbgi/dbgi.h index 8ab168ad..7a050585 100644 --- a/src/dbgi/dbgi.h +++ b/src/dbgi/dbgi.h @@ -279,7 +279,7 @@ struct DI_MatchNameNode U64 cmp_params_hash; String8 name; U64 hash; - B32 has_matches; + RDI_SectionKind section_kind; // DI_Match *first_match; // DI_Match *last_match; }; @@ -311,6 +311,7 @@ struct DI_MatchStore DI_Match *first_free_match; DI_MatchNameNode *first_lru_match_name; DI_MatchNameNode *last_lru_match_name; + U64 active_match_name_nodes_count; // rjf: user -> match work ring buffer OS_Handle u2m_ring_cv; @@ -463,7 +464,7 @@ internal void di_search_thread__entry_point(void *p); internal DI_MatchStore *di_match_store_alloc(void); internal void di_match_store_begin(DI_MatchStore *store, DI_KeyArray keys); -internal B32 di_match_store_name_has_matches(DI_MatchStore *store, String8 name, U64 endt_us); +internal RDI_SectionKind di_match_store_section_kind_from_name(DI_MatchStore *store, String8 name, U64 endt_us); ASYNC_WORK_DEF(di_match_work); #endif // DBGI_H diff --git a/src/file_stream/file_stream.c b/src/file_stream/file_stream.c index e30cc17a..6225b7c5 100644 --- a/src/file_stream/file_stream.c +++ b/src/file_stream/file_stream.c @@ -53,12 +53,6 @@ fs_init(void) fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size); fs_shared->u2s_ring_cv = os_condition_variable_alloc(); fs_shared->u2s_ring_mutex = os_mutex_alloc(); - fs_shared->streamer_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4); - fs_shared->streamers = push_array(arena, OS_Handle, 1); - for(U64 idx = 0; idx < fs_shared->streamer_count; idx += 1) - { - // fs_shared->streamers[idx] = os_thread_launch(fs_streamer_thread__entry_point, (void *)idx, 0); - } fs_shared->detector_thread = os_thread_launch(fs_detector_thread__entry_point, 0, 0); } diff --git a/src/file_stream/file_stream.h b/src/file_stream/file_stream.h index e948c5a1..54098da0 100644 --- a/src/file_stream/file_stream.h +++ b/src/file_stream/file_stream.h @@ -76,10 +76,6 @@ struct FS_Shared OS_Handle u2s_ring_cv; OS_Handle u2s_ring_mutex; - // rjf: streamer threads - U64 streamer_count; - OS_Handle *streamers; - // rjf: change detector threads OS_Handle detector_thread; }; diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index cb76b6e4..0791c5d6 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -3985,6 +3985,11 @@ rd_window_frame(RD_Window *ws) ui_divider(ui_em(1.f, 1.f)); + //- rjf: draw match store stats + ui_labelf("name match nodes: %I64u", rd_state->match_store->active_match_name_nodes_count); + + ui_divider(ui_em(1.f, 1.f)); + //- rjf: draw registers ui_labelf("hover_reg_slot: %i", rd_state->hover_regs_slot); struct @@ -4072,6 +4077,7 @@ rd_window_frame(RD_Window *ws) ui_divider(ui_em(1.f, 1.f)); //- rjf: draw entity tree +#if 0 RD_EntityRec rec = {0}; S32 indent = 0; UI_PrefWidth(ui_text_dim(10, 1)) ui_labelf("Entity Tree:"); @@ -4096,6 +4102,7 @@ rd_window_frame(RD_Window *ws) indent += rec.push_count; indent -= rec.pop_count; } +#endif } } @@ -10375,6 +10382,28 @@ rd_theme_color_from_txt_token_kind_lookup_string(TXT_TokenKind kind, String8 str } } + // rjf: try to map using asynchronous matching system + if(!mapped && kind == TXT_TokenKind_Identifier) + { + RDI_SectionKind section_kind = di_match_store_section_kind_from_name(rd_state->match_store, string, 0); + mapped = 1; + switch(section_kind) + { + default:{mapped = 0;}break; + case RDI_SectionKind_Procedures: + case RDI_SectionKind_GlobalVariables: + case RDI_SectionKind_ThreadVariables: + { + color = RD_ThemeColor_CodeSymbol; + }break; + case RDI_SectionKind_TypeNodes: + { + color = RD_ThemeColor_CodeType; + }break; + } + } + +#if 0 // rjf: try to map as symbol if(!mapped && kind == TXT_TokenKind_Identifier) { @@ -10396,6 +10425,7 @@ rd_theme_color_from_txt_token_kind_lookup_string(TXT_TokenKind kind, String8 str color = RD_ThemeColor_CodeType; } } +#endif } return color; } @@ -11485,6 +11515,7 @@ rd_init(CmdLine *cmdln) } rd_state->num_frames_requested = 2; rd_state->seconds_until_autosave = 0.5f; + rd_state->match_store = di_match_store_alloc(); for(U64 idx = 0; idx < ArrayCount(rd_state->cmds_arenas); idx += 1) { rd_state->cmds_arenas[idx] = arena_alloc(); @@ -16678,6 +16709,15 @@ rd_frame(void) scratch_end(scratch); } + ////////////////////////////// + //- rjf: set name matching parameters; begin matching + // + { + DI_KeyList keys_list = d_push_active_dbgi_key_list(scratch.arena); + DI_KeyArray keys = di_key_array_from_list(scratch.arena, &keys_list); + di_match_store_begin(rd_state->match_store, keys); + } + ////////////////////////////// //- rjf: update/render all windows // diff --git a/src/raddbg/raddbg_core.h b/src/raddbg/raddbg_core.h index deb20e44..17700eb4 100644 --- a/src/raddbg/raddbg_core.h +++ b/src/raddbg/raddbg_core.h @@ -821,7 +821,10 @@ struct RD_State // rjf: frame parameters F32 frame_dt; - DI_Scope *frame_di_scope; + DI_Scope *frame_di_scope; + + // rjf: dbgi match store + DI_MatchStore *match_store; // rjf: ambiguous path table U64 ambiguous_path_slots_count;