eliminate unnecessary info in debug engine entity abstraction / demon events; adjust symbol server / debug info loading such that the debug info loader is the one who decides to kick off downloads based on presence in cache path; use cache path as key, unpack info for download requests

This commit is contained in:
Ryan Fleury
2026-06-08 21:06:44 -07:00
parent b22f9f2d8b
commit 132751777f
19 changed files with 199 additions and 318 deletions
+1 -15
View File
@@ -102,17 +102,6 @@ struct D_BreakpointList
U64 count;
};
////////////////////////////////
//~ Dynamic Linker Types
typedef U32 D_TlsModel;
enum
{
D_TlsModel_Null,
D_TlsModel_WinodwsNt,
D_TlsModel_Gnu
};
////////////////////////////////
//~ rjf: Entity Types
@@ -136,11 +125,8 @@ struct D_Entity
U64 timestamp;
D_BreakpointFlags bp_flags;
String8 string;
D_TlsModel tls_model;
U64 tls_index;
U64 tls_offset;
U64 tls_root_vaddr;
OperatingSystem target_os;
OperatingSystem os;
D_MsgID src_msg_id;
};
+9 -34
View File
@@ -42,20 +42,6 @@ d_exception_kind_from_dmn(DMN_ExceptionKind kind)
return result;
}
internal D_TlsModel
d_tls_model_from_dmn(DMN_TlsModel type)
{
D_TlsModel result = D_TlsModel_Null;
switch(type)
{
default:{}break;
case DMN_TlsModel_Null: {result = D_TlsModel_Null;}break;
case DMN_TlsModel_WinodwsNt: {result = D_TlsModel_WinodwsNt;}break;
case DMN_TlsModel_Gnu: {result = D_TlsModel_Gnu;}break;
}
return result;
}
internal String8
d_string_from_event_kind(D_EventKind kind)
{
@@ -645,8 +631,7 @@ d_serialized_string_from_event(Arena *arena, D_Event *event, U64 max)
str8_serial_push_struct(scratch.arena, &srl, &event->exception_code);
str8_serial_push_struct(scratch.arena, &srl, &event->rgba);
str8_serial_push_struct(scratch.arena, &srl, &event->bp_flags);
str8_serial_push_struct(scratch.arena, &srl, &event->target_os);
str8_serial_push_struct(scratch.arena, &srl, &event->tls_model);
str8_serial_push_struct(scratch.arena, &srl, &event->os);
str8_serial_push_struct(scratch.arena, &srl, &event->tls_index);
str8_serial_push_struct(scratch.arena, &srl, &event->tls_offset);
String8 string = event->string;
@@ -682,8 +667,7 @@ d_event_from_serialized_string(Arena *arena, String8 string)
read_off += str8_deserial_read_struct(string, read_off, &event.exception_code);
read_off += str8_deserial_read_struct(string, read_off, &event.rgba);
read_off += str8_deserial_read_struct(string, read_off, &event.bp_flags);
read_off += str8_deserial_read_struct(string, read_off, &event.target_os);
read_off += str8_deserial_read_struct(string, read_off, &event.tls_model);
read_off += str8_deserial_read_struct(string, read_off, &event.os);
read_off += str8_deserial_read_struct(string, read_off, &event.tls_index);
read_off += str8_deserial_read_struct(string, read_off, &event.tls_offset);
read_off += str8_deserial_read_struct(string, read_off, &event.string.size);
@@ -1300,8 +1284,7 @@ d_entity_store_apply_events(D_EntityCtxRWStore *store, D_EventList *list)
if(machine != &d_entity_nil)
{
D_Entity *process = d_entity_alloc(store, machine, D_EntityKind_Process, event->arch, event->entity, (U64)event->entity_id);
process->tls_model = event->tls_model;
process->target_os = event->target_os;
process->os = event->os;
process->src_msg_id = event->msg_id;
d_entity_equip_string(store, process, event->string);
}
@@ -1437,8 +1420,6 @@ d_entity_store_apply_events(D_EntityCtxRWStore *store, D_EventList *list)
d_entity_equip_string(store, module, event->string);
module->timestamp = event->timestamp;
module->vaddr_range = event->vaddr_rng;
module->tls_index = event->tls_index;
module->tls_offset = event->tls_offset;
D_Entity *first_module = d_entity_child_from_kind(process, D_EntityKind_Module);
if(first_module == module && process->string.size == 0)
{
@@ -1565,7 +1546,7 @@ d_thread_read_reg_block(D_Handle handle, void *reg_block)
if(thread_ctx != 0)
{
Arch arch = thread->arch;
OperatingSystem os = process->target_os;
OperatingSystem os = process->os;
result = arch_os_write_reg_block_from_thread_ctx(arch, os, reg_block, thread_ctx);
}
}
@@ -2683,14 +2664,12 @@ d_ctrl_thread__module_open(D_Handle process, D_Handle module, U64 base_vaddr, DM
}
//////////////////////////////
//- rjf: no found debug info path -> try to fall back on symbol server
//- rjf: no found debug info path -> try to fall back on symbol server cache path
//
#if 0
if(initial_debug_info_path.size == 0)
{
initial_debug_info_path = smsv_local_path_from_key(arena, str8_skip_last_slash(module_info->debug_info_path), module_info->debug_info_guid, module_info->debug_info_age);
}
#endif
//////////////////////////////
//- rjf: write 1 at attachment marker, to signify attachment
@@ -3154,8 +3133,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->process);
out_evt->arch = event->arch;
out_evt->entity_id = event->code;
out_evt->tls_model = d_tls_model_from_dmn(event->tls_model);
out_evt->target_os = OperatingSystem_CURRENT; // TODO: operating system of the remote target machine
out_evt->os = OperatingSystem_CURRENT; // TODO: operating system of the remote target machine
d_ctrl_state->process_counter += 1;
}break;
case DMN_EventKind_CreateThread:
@@ -3985,7 +3963,7 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
evt->msg_id = msg->msg_id;
evt->entity = process;
evt->arch = process_arch;
evt->target_os = process_os;
evt->os = process_os;
evt->string = path;
}
@@ -6064,11 +6042,8 @@ d_call_stack_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U6
dst_e->stack_base = src_e->stack_base;
dst_e->timestamp = src_e->timestamp;
dst_e->bp_flags = src_e->bp_flags;
dst_e->string = push_str8_copy(scratch.arena, src_e->string);
dst_e->tls_index = src_e->tls_index;
dst_e->tls_offset = src_e->tls_offset;
dst_e->target_os = src_e->target_os;
dst_e->tls_model = src_e->tls_model;
dst_e->string = str8_copy(scratch.arena, src_e->string);
dst_e->os = src_e->os;
}
if(dst_parent == &d_entity_nil)
{
-1
View File
@@ -404,7 +404,6 @@ read_only global D_ModuleInfo d_module_info_nil = {0};
internal U64 d_hash_from_handle(D_Handle handle);
internal D_EventCause d_event_cause_from_dmn_event_kind(DMN_EventKind event_kind);
internal D_ExceptionKind d_exception_kind_from_dmn(DMN_ExceptionKind kind);
internal D_TlsModel d_tls_model_from_dmn(DMN_TlsModel type);
internal String8 d_string_from_event_kind(D_EventKind kind);
internal String8 d_string_from_msg_kind(D_MsgKind kind);
internal D_EntityKind d_entity_kind_from_string(String8 string);
-125
View File
@@ -1326,80 +1326,6 @@ d_lines_from_file_path_line_num(Arena *arena, String8 file_path, S64 line_num, U
return list;
}
////////////////////////////////
//~ rjf: Process/Thread/Module Info Lookups
internal U64
d_tls_base_vaddr_from_process_root_rip(D_Entity *process, U64 root_vaddr, U64 rip_vaddr)
{
ProfBeginFunction();
U64 base_vaddr = 0;
if(!d_ctrl_targets_running())
{
Temp scratch = scratch_begin(0, 0);
//- rjf: unpack module info
D_Entity *module = d_module_from_process_vaddr(process, rip_vaddr);
U64 addr_size = byte_size_from_arch(process->arch);
switch(process->tls_model)
{
case D_TlsModel_Null: {}break;
case D_TlsModel_WinodwsNt:
{
// read thread local base pointer out of TEB
U64 thread_local_base = root_vaddr;
U64 tls_addr_array = 0;
D_ProcessMemorySlice tls_addr_array_slice = d_process_memory_slice_from_vaddr_range(scratch.arena, process->handle, r1u64(thread_local_base, thread_local_base + addr_size), 0, 0);
String8 tls_array_vaddr_data = tls_addr_array_slice.data;
if(tls_array_vaddr_data.size == addr_size)
{
U64 tls_array_vaddr = 0;
MemoryCopyStr8(&tls_array_vaddr, tls_array_vaddr_data);
// read thread local storage pointer (array of TLS pointers, one per module)
U64 tls_ptr_vaddr = tls_array_vaddr + module->tls_index * addr_size;
D_ProcessMemorySlice result_slice = d_process_memory_slice_from_vaddr_range(scratch.arena, process->handle, r1u64(tls_ptr_vaddr, tls_ptr_vaddr + addr_size), 0, 0);
String8 result_data = result_slice.data;
if(result_data.size == addr_size)
{
MemoryCopyStr8(&base_vaddr, result_data);
}
}
}break;
case D_TlsModel_Gnu:
{
if(module->tls_index > 0) // zero is reserved for the generation counter
{
// read dynamic thread vector pointer (one per dynamic module)
U64 dtv_base = root_vaddr;
U64 dtv_size = addr_size * 2; // union dtv { size_t counter; struct dtv_pointer { void *val, *to_free; }; };
U64 dtv_pointer_vaddr = dtv_base + module->tls_index * dtv_size;
D_ProcessMemorySlice dtv_pointer_slice = d_process_memory_slice_from_vaddr_range(scratch.arena, process->handle, r1u64(dtv_pointer_vaddr, dtv_pointer_vaddr + dtv_size), 0, 0);
String8 dtv_pointer_data = dtv_pointer_slice.data;
if(dtv_pointer_data.size == dtv_size)
{
U64 dtv_pointer = 0;
MemoryCopyStr8(&dtv_pointer, dtv_pointer_data);
// verify that TLS block was allocated
U64 tls_dtv_unallocated = addr_size == 4 ? max_U32 : max_U64;
if(dtv_pointer != tls_dtv_unallocated)
{
base_vaddr = dtv_pointer + module->tls_offset; // add tls_offset because DT_NEEDED modules share TLS block with the main exe
}
}
}
}break;
default: {InvalidPath;}break;
}
scratch_end(scratch);
}
ProfEnd();
return base_vaddr;
}
////////////////////////////////
//~ rjf: Target Controls
@@ -1509,57 +1435,6 @@ d_query_cached_cfa_from_thread_unwind(D_Entity *thread, U64 unwind_count)
return cfa;
}
internal U64
d_query_cached_tls_base_vaddr_from_process_root_rip(D_Entity *process, U64 root_vaddr, U64 rip_vaddr)
{
U64 result = 0;
for(U64 cache_idx = 0; cache_idx < ArrayCount(d_user_state->tls_base_caches); cache_idx += 1)
{
D_RunTLSBaseCache *cache = &d_user_state->tls_base_caches[(d_user_state->tls_base_cache_gen+cache_idx)%ArrayCount(d_user_state->tls_base_caches)];
if(cache_idx == 0 && cache->slots_count == 0)
{
cache->slots_count = 256;
cache->slots = push_array(cache->arena, D_RunTLSBaseCacheSlot, cache->slots_count);
}
else if(cache->slots_count == 0)
{
break;
}
D_Handle handle = process->handle;
U64 hash = d_hash_from_seed_string(d_hash_from_string(str8_struct(&handle)), str8_struct(&rip_vaddr));
U64 slot_idx = hash%cache->slots_count;
D_RunTLSBaseCacheSlot *slot = &cache->slots[slot_idx];
D_RunTLSBaseCacheNode *node = 0;
for(D_RunTLSBaseCacheNode *n = slot->first; n != 0; n = n->hash_next)
{
if(d_handle_match(n->process, handle) && n->root_vaddr == root_vaddr && n->rip_vaddr == rip_vaddr)
{
node = n;
break;
}
}
if(node == 0)
{
U64 tls_base_vaddr = d_tls_base_vaddr_from_process_root_rip(process, root_vaddr, rip_vaddr);
if(tls_base_vaddr != 0)
{
node = push_array(cache->arena, D_RunTLSBaseCacheNode, 1);
SLLQueuePush_N(slot->first, slot->last, node, hash_next);
node->process = handle;
node->root_vaddr = root_vaddr;
node->rip_vaddr = rip_vaddr;
node->tls_base_vaddr = tls_base_vaddr;
}
}
if(node != 0 && node->tls_base_vaddr != 0)
{
result = node->tls_base_vaddr;
break;
}
}
return result;
}
internal E_String2NumMap *
d_query_cached_locals_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff)
{
+1 -8
View File
@@ -313,8 +313,7 @@ struct D_Event
U32 rgba;
D_BreakpointFlags bp_flags;
String8 string;
OperatingSystem target_os;
D_TlsModel tls_model;
OperatingSystem os;
};
typedef struct D_EventNode D_EventNode;
@@ -443,11 +442,6 @@ internal D_LineListArray d_lines_array_from_file_path_line_range(Arena *arena, S
internal D_LineList d_lines_from_dbgi_key_file_path_line_num(Arena *arena, DI_Key dbgi_key, String8 file_path, S64 line_num, U64 max_voffs_per_line);
internal D_LineList d_lines_from_file_path_line_num(Arena *arena, String8 file_path, S64 line_num, U64 max_voffs_per_line);
////////////////////////////////
//~ rjf: Process/Thread/Module Info Lookups
internal U64 d_tls_base_vaddr_from_process_root_rip(D_Entity *process, U64 root_vaddr, U64 rip_vaddr);
////////////////////////////////
//~ rjf: Target Controls
@@ -473,7 +467,6 @@ internal DI_KeyList d_push_active_dbgi_key_list(Arena *arena);
internal U64 d_query_cached_rip_from_thread(D_Entity *thread);
internal U64 d_query_cached_rip_from_thread_unwind(D_Entity *thread, U64 unwind_count);
internal U64 d_query_cached_cfa_from_thread_unwind(D_Entity *thread, U64 unwind_count);
internal U64 d_query_cached_tls_base_vaddr_from_process_root_rip(D_Entity *process, U64 root_vaddr, U64 rip_vaddr);
internal E_String2NumMap *d_query_cached_locals_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff);
internal E_String2NumMap *d_query_cached_member_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff);