checkpoint on minidump support

This commit is contained in:
Ryan Fleury committed 2026-08-26 17:24:43 -07:00
1 parent 64daed7030
commit 8a7be007c1
8 files changed
+530 -350

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ D_CmdTable: // | | |
{Attach 1 1 "query:unattached_processes" PID 0 0 0 0 0 1 1 Null "attach" "Attach" "Attaches to a process that is already running on the local machine." "" "" }
//- rjf: crash dump opening
{OpenCrashDump 0 0 `folder:\\"$input\\"` FilePath 0 0 0 0 0 1 1 FileOutline "open_crash_dump" "Open Crash Dump" "Opens a crash dump file and recreates debuggee state at the time of the crash." "" "" }
{OpenCrashDump 1 1 `folder:\\"$input\\"` FilePath 0 0 0 0 0 1 1 FileOutline "open_crash_dump" "Open Crash Dump" "Opens a crash dump file and recreates debuggee state at the time of the crash." "" "" }
}
@enum D_CmdKind:
+434 -283
View File
@@ -1751,6 +1751,75 @@ d_cached_sp_from_thread(D_Handle handle)
////////////////////////////////
//~ rjf: Module Image Info Functions
//- rjf: module info stores / evictions
internal void
d_module_info_store(D_Handle module, Arena **stored_arena, D_ModuleInfo *info)
{
D_ModuleInfoCache *cache = &d_ctrl_state->module_info_cache;
U64 hash = d_hash_from_handle(module);
U64 slot_idx = hash%cache->slots_count;
D_ModuleInfoCacheSlot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
MutexScopeW(stripe->rw_mutex)
{
D_ModuleInfoCacheNode *node = 0;
for EachNode(n, D_ModuleInfoCacheNode, slot->first)
{
if(d_handle_match(n->module, module))
{
node = n;
break;
}
}
if(!node)
{
node = push_array(*stored_arena, D_ModuleInfoCacheNode, 1);
DLLPushBack(slot->first, slot->last, node);
node->module = module;
node->arena = *stored_arena;
node->v = *info;
}
}
*stored_arena = 0;
}
internal void
d_module_info_evict(D_Handle module)
{
D_ModuleInfoCache *cache = &d_ctrl_state->module_info_cache;
U64 hash = d_hash_from_handle(module);
U64 slot_idx = hash%cache->slots_count;
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
D_ModuleInfoCacheSlot *slot = &cache->slots[slot_idx];
MutexScopeW(stripe->rw_mutex) for(;;)
{
D_ModuleInfoCacheNode *node = 0;
for(D_ModuleInfoCacheNode *n = slot->first; n != 0; n = n->next)
{
if(d_handle_match(n->module, module))
{
node = n;
break;
}
}
if(node && access_pt_is_expired(&node->access_pt, .time = 0, .update_idxs = 0))
{
DLLRemove(slot->first, slot->last, node);
arena_release(node->arena);
break;
}
if(node)
{
cond_var_wait_rw_w(stripe->cv, stripe->rw_mutex, max_U64);
}
else
{
break;
}
}
}
//- rjf: cache lookups
internal D_ModuleInfo *
@@ -1785,6 +1854,15 @@ d_entry_point_voff_from_module(D_Handle module_handle)
return result;
}
internal U64
d_raddbg_attached_marker_voff_from_module(D_Handle module_handle)
{
Access *access = access_open();
U64 result = d_info_from_module(access, module_handle)->raddbg_attached_marker_voff;
access_close(access);
return result;
}
internal String8
d_initial_debug_info_path_from_module(Arena *arena, D_Handle module_handle)
{
@@ -2650,238 +2728,79 @@ d_ctrl_thread__append_program_defined_bp_traps(Arena *arena, D_Entity *bp, DMN_T
dmn_trap_chunk_list_push(arena, traps_out, 256, &trap);
}
//- rjf: module lifetime open/close work
internal void
d_ctrl_thread__module_open(D_Handle process, D_Handle module, U64 base_vaddr, DMN_ModuleInfo *module_info)
{
Temp scratch = scratch_begin(0,0);
//////////////////////////////
//- rjf: allocate / set up basic per-module info
//
Arena *arena = arena_alloc();
String8 raddbg_data = d_data_from_process_vaddr_range(arena, process, shift_1u64(module_info->raddbg_info_voff_range, base_vaddr), 0);
//////////////////////////////
//- rjf: prepare unwind info
//
UWND_Unwinder unwinder = UWND_Unwinder_Null;
void *unwind_info_opaque = 0;
{
//- rjf: PE/x64 unwinder
if(dim_1u64(module_info->pe_intel_pdatas_vaddr_range) != 0)
{
unwinder = UWND_Unwinder_PEx64;
PE_X64_UWND_ModuleUnwindInfo *unwind_info = push_array(arena, PE_X64_UWND_ModuleUnwindInfo, 1);
{
U64 pdatas_count = dim_1u64(module_info->pe_intel_pdatas_vaddr_range) / sizeof(PE_IntelPdata);
String8 pdatas_data = d_data_from_process_vaddr_range(arena, process, module_info->pe_intel_pdatas_vaddr_range, 0);
pdatas_count = Min(pdatas_count, pdatas_data.size / sizeof(PE_IntelPdata));
PE_IntelPdata *pdatas = (PE_IntelPdata *)pdatas_data.str;
unwind_info->pdatas = pdatas;
unwind_info->pdatas_count = pdatas_count;
}
unwind_info_opaque = unwind_info;
}
//- rjf: .eh_frame unwinder
else if(dim_1u64(module_info->eh_frame_header_vaddr_range) != 0)
{
unwinder = UWND_Unwinder_EHFrame;
EH_UWND_ModuleUnwindInfo *unwind_info = push_array(arena, EH_UWND_ModuleUnwindInfo, 1);
{
String8 eh_frame_hdr_data = d_data_from_process_vaddr_range(arena, process, module_info->eh_frame_header_vaddr_range, 0);
unwind_info->ptr_ctx.pc_vaddr = module_info->eh_frame_header_vaddr_range.min;
unwind_info->ptr_ctx.data_vaddr = module_info->eh_frame_header_vaddr_range.min;
unwind_info->header = eh_parse_frame_hdr(eh_frame_hdr_data, byte_size_from_arch(module_info->arch), &unwind_info->ptr_ctx);
}
unwind_info_opaque = unwind_info;
}
}
//////////////////////////////
//- rjf: compute local symbol server cache path for this debug info
//
String8 local_symbol_server_cache_path = smsv_local_path_from_key(scratch.arena, str8_skip_last_slash(module_info->debug_info_path), module_info->debug_info_guid, module_info->debug_info_age);
//////////////////////////////
//- rjf: pick default initial debug info path
//
String8 initial_debug_info_path = {0};
{
String8List candidates = {0};
// rjf: push module-embedded debug info paths, try both relative-to-exe & absolute
if(module_info->debug_info_path.size != 0)
{
PathStyle path_style = path_style_from_str8(module_info->debug_info_path);
if(path_style == PathStyle_Relative)
{
String8 module_image_folder = str8_chop_last_slash(module_info->module_path);
str8_list_pushf(scratch.arena, &candidates, "%S/%S", module_image_folder, module_info->debug_info_path);
}
str8_list_push(scratch.arena, &candidates, module_info->debug_info_path);
}
// rjf: push heuristic-based debug info paths
{
String8 exe_path = module_info->module_path;
String8 exe_path_no_ext = str8_chop_last_dot(exe_path);
str8_list_pushf(scratch.arena, &candidates, "%S.pdb", exe_path_no_ext);
str8_list_pushf(scratch.arena, &candidates, "%S.pdb", exe_path);
str8_list_pushf(scratch.arena, &candidates, "%S.rdi", exe_path_no_ext);
str8_list_pushf(scratch.arena, &candidates, "%S.rdi", exe_path);
}
// rjf: push local symbol server cache's path
if(local_symbol_server_cache_path.size != 0)
{
str8_list_push(scratch.arena, &candidates, local_symbol_server_cache_path);
}
// rjf: pick first candidate that works
for EachNode(n, String8Node, candidates.first)
{
String8 candidate_path = n->string;
FileProperties props = properties_from_file_path(candidate_path);
if(props.modified != 0 && props.size != 0)
{
initial_debug_info_path = str8_copy(arena, path_normalized_from_string(scratch.arena, candidate_path));
break;
}
}
}
//////////////////////////////
//- rjf: no found debug info path -> try to fall back on symbol server cache path.
//
// if it exists, we can just use it. if it doesn't, then we only want to pick it *if*
// automatic downloads are enabled.
//
if(initial_debug_info_path.size == 0 && d_ctrl_state->auto_download_debug_info && local_symbol_server_cache_path.size != 0)
{
initial_debug_info_path = str8_copy(arena, local_symbol_server_cache_path);
}
//////////////////////////////
//- rjf: write 1 at attachment marker, to signify attachment
//
if(module_info->raddbg_is_attached_marker_voff != 0)
{
U8 new_value = 1;
d_process_write_struct(process, base_vaddr + module_info->raddbg_is_attached_marker_voff, &new_value);
}
//////////////////////////////
//- rjf: fill info
//
D_ModuleInfo info = {0};
{
info.entry_point_voff = module_info->entry_point_voff;
info.unwinder = unwinder;
info.unwind_info = unwind_info_opaque;
info.local_debug_info_path = initial_debug_info_path;
info.dbg_name = str8_copy(arena, str8_skip_last_slash(module_info->debug_info_path));
info.dbg_guid = module_info->debug_info_guid;
info.dbg_age = module_info->debug_info_age;
info.raddbg_attached_marker_voff = module_info->raddbg_is_attached_marker_voff;
info.raddbg_data = raddbg_data;
}
//////////////////////////////
//- rjf: insert info into cache
//
{
D_ModuleInfoCache *cache = &d_ctrl_state->module_info_cache;
U64 hash = d_hash_from_handle(module);
U64 slot_idx = hash%cache->slots_count;
D_ModuleInfoCacheSlot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
MutexScopeW(stripe->rw_mutex)
{
D_ModuleInfoCacheNode *node = 0;
for EachNode(n, D_ModuleInfoCacheNode, slot->first)
{
if(d_handle_match(n->module, module))
{
node = n;
break;
}
}
if(!node)
{
node = push_array(arena, D_ModuleInfoCacheNode, 1);
DLLPushBack(slot->first, slot->last, node);
node->module = module;
node->arena = arena;
node->v = info;
}
}
}
scratch_end(scratch);
}
internal void
d_ctrl_thread__module_close(D_Handle process, D_Handle module, U64 base_vaddr)
{
DMN_Handle process_dmn = d_dmn_from_handle(process);
//////////////////////////////
//- rjf: evict module info from cache
//
U64 raddbg_attached_marker_voff = 0;
{
D_ModuleInfoCache *cache = &d_ctrl_state->module_info_cache;
U64 hash = d_hash_from_handle(module);
U64 slot_idx = hash%cache->slots_count;
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
D_ModuleInfoCacheSlot *slot = &cache->slots[slot_idx];
MutexScopeW(stripe->rw_mutex) for(;;)
{
D_ModuleInfoCacheNode *node = 0;
for(D_ModuleInfoCacheNode *n = slot->first; n != 0; n = n->next)
{
if(d_handle_match(n->module, module))
{
node = n;
break;
}
}
if(node && access_pt_is_expired(&node->access_pt, .time = 0, .update_idxs = 0))
{
raddbg_attached_marker_voff = node->v.raddbg_attached_marker_voff;
DLLRemove(slot->first, slot->last, node);
arena_release(node->arena);
break;
}
if(node)
{
cond_var_wait_rw_w(stripe->cv, stripe->rw_mutex, max_U64);
}
else
{
break;
}
}
}
//////////////////////////////
//- rjf: write 0 at attachment marker, to signify detachment
//
if(raddbg_attached_marker_voff != 0)
{
U8 new_value = 0;
d_process_write_struct(process, base_vaddr + raddbg_attached_marker_voff, &new_value);
}
}
//- rjf: dump process closing work
internal void
d_ctrl_thread__close_dump_process(D_MsgID msg_id, D_Handle process)
{
// rjf: unpack dump cache
D_DumpCache *cache = &d_ctrl_state->dump_cache;
U64 hash = d_hash_from_handle(process);
U64 slot_idx = hash%cache->slots_count;
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
// rjf: remove node from cache
D_DumpNode *node = 0;
{
RWMutexScope(stripe->rw_mutex, 1)
{
for(D_DumpNode *n = cache->slots[slot_idx].first; n != 0; n = n->next)
{
if(d_handle_match(n->process, process))
{
node = n;
break;
}
}
if(node != 0)
{
DLLRemove(cache->slots[slot_idx].first, cache->slots[slot_idx].last, node);
}
}
}
// rjf: evict module infos
for EachIndex(idx, node->modules_count)
{
d_module_info_evict(node->modules[idx].module_handle);
}
// rjf: close debug infos
for EachIndex(idx, node->modules_count)
{
D_Entity *module_ent = d_entity_from_handle(node->modules[idx].module_handle);
DI_Key dbgi_key = d_dbgi_key_from_module(module_ent);
di_close(dbgi_key, 0);
}
// rjf: send events for modules being unloaded
for EachIndex(idx, node->modules_count)
{
Temp scratch = scratch_begin(0, 0);
D_EventList evts = {0};
D_Event *evt = d_event_list_push(scratch.arena, &evts);
evt->kind = D_EventKind_EndModule;
evt->msg_id = msg_id;
evt->entity = node->modules[idx].module_handle;
evt->string = node->modules[idx].path;
d_c2u_push_events(&evts);
scratch_end(scratch);
}
// rjf: send events for threads being ended
for EachIndex(idx, node->threads_count)
{
Temp scratch = scratch_begin(0, 0);
D_EventList evts = {0};
D_Event *evt = d_event_list_push(scratch.arena, &evts);
evt->kind = D_EventKind_EndThread;
evt->msg_id = msg_id;
evt->entity = node->threads[idx].thread_handle;
evt->entity_id = node->threads[idx].id;
d_c2u_push_events(&evts);
scratch_end(scratch);
}
// rjf: send debug event for process closing
{
Temp scratch = scratch_begin(0, 0);
@@ -2899,52 +2818,26 @@ d_ctrl_thread__close_dump_process(D_MsgID msg_id, D_Handle process)
ins_atomic_u64_inc_eval(&d_ctrl_state->reg_gen);
ins_atomic_u64_inc_eval(&d_ctrl_state->run_gen);
// rjf: eliminate dump node from cache
// rjf: release node contents
if(node != 0)
{
D_DumpCache *cache = &d_ctrl_state->dump_cache;
U64 hash = d_hash_from_handle(process);
U64 slot_idx = hash%cache->slots_count;
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
// rjf: remove node
D_DumpNode *node = 0;
RWMutexScope(stripe->rw_mutex, 1)
for EachIndex(idx, node->modules_count)
{
for(D_DumpNode *n = cache->slots[slot_idx].first; n != 0; n = n->next)
{
if(d_handle_match(n->process, process))
{
node = n;
break;
}
}
if(node != 0)
{
DLLRemove(cache->slots[slot_idx].first, cache->slots[slot_idx].last, node);
}
}
// rjf: release node contents
if(node != 0)
{
for EachIndex(idx, node->modules_count)
{
file_map_view_close(node->modules[idx].map, node->modules[idx].base, r1u64(0, node->modules[idx].props.size));
file_map_close(node->modules[idx].map);
file_close(node->modules[idx].file);
}
file_map_view_close(node->map, node->base, r1u64(0, node->props.size));
file_map_close(node->map);
file_close(node->file);
arena_release(node->arena);
}
// rjf: attach node to free list
if(node != 0) RWMutexScope(stripe->rw_mutex, 1)
{
node->next = (D_DumpNode *)stripe->free;
stripe->free = node;
file_map_view_close(node->modules[idx].map, node->modules[idx].base, r1u64(0, node->modules[idx].props.size));
file_map_close(node->modules[idx].map);
file_close(node->modules[idx].file);
}
file_map_view_close(node->map, node->base, r1u64(0, node->props.size));
file_map_close(node->map);
file_close(node->file);
arena_release(node->arena);
}
// rjf: attach node to free list
if(node != 0) RWMutexScope(stripe->rw_mutex, 1)
{
node->next = (D_DumpNode *)stripe->free;
stripe->free = node;
}
}
@@ -3208,8 +3101,11 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
ProfScope("push ctrl events associated with this demon event") switch(event->kind)
{
default:{}break;
//- rjf: process creation
case DMN_EventKind_CreateProcess:
{
// rjf: process ID -> message ID
D_MsgID msg_id = 0;
for(D_Entity *entry = d_ctrl_state->ctrl_thread_entity_store->ctx.root->first;
entry != &d_entity_nil;
@@ -3222,6 +3118,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
break;
}
}
// rjf: push
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
out_evt->kind = D_EventKind_NewProc;
out_evt->msg_id = msg_id;
@@ -3231,6 +3129,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->os = OperatingSystem_CURRENT; // TODO: operating system of the remote target machine
d_ctrl_state->process_counter += 1;
}break;
//- rjf: create thread
case DMN_EventKind_CreateThread:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3245,14 +3145,144 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->rip_vaddr = event->instruction_pointer;
out_evt->string = event->string;
}break;
//- rjf: load module
case DMN_EventKind_LoadModule:
{
Temp scratch2 = scratch_begin(&scratch.arena, 1);
//- rjf: unpack module
D_Handle process_handle = d_handle_from_dmn(D_MachineID_Local, event->process);
D_Handle module_handle = d_handle_from_dmn(D_MachineID_Local, event->module);
D_Event *out_evt1 = d_event_list_push(scratch.arena, &evts);
String8 module_path = path_normalized_from_string(scratch.arena, event->string);
String8 module_path = path_normalized_from_string(scratch2.arena, event->string);
U64 exe_timestamp = properties_from_file_path(module_path).modified;
d_ctrl_thread__module_open(process_handle, module_handle, event->address, event->module_info);
DMN_ModuleInfo *module_info = event->module_info;
U64 base_vaddr = event->address;
//- rjf: allocate / set up basic per-module info
Arena *arena = arena_alloc();
String8 raddbg_data = d_data_from_process_vaddr_range(arena, process_handle, shift_1u64(module_info->raddbg_info_voff_range, base_vaddr), 0);
//- rjf: prepare unwind info
UWND_Unwinder unwinder = UWND_Unwinder_Null;
void *unwind_info_opaque = 0;
{
//- rjf: PE/x64 unwinder
if(dim_1u64(module_info->pe_intel_pdatas_vaddr_range) != 0)
{
unwinder = UWND_Unwinder_PEx64;
PE_X64_UWND_ModuleUnwindInfo *unwind_info = push_array(arena, PE_X64_UWND_ModuleUnwindInfo, 1);
{
U64 pdatas_count = dim_1u64(module_info->pe_intel_pdatas_vaddr_range) / sizeof(PE_IntelPdata);
String8 pdatas_data = d_data_from_process_vaddr_range(arena, process_handle, module_info->pe_intel_pdatas_vaddr_range, 0);
pdatas_count = Min(pdatas_count, pdatas_data.size / sizeof(PE_IntelPdata));
PE_IntelPdata *pdatas = (PE_IntelPdata *)pdatas_data.str;
unwind_info->pdatas = pdatas;
unwind_info->pdatas_count = pdatas_count;
}
unwind_info_opaque = unwind_info;
}
//- rjf: .eh_frame unwinder
else if(dim_1u64(module_info->eh_frame_header_vaddr_range) != 0)
{
unwinder = UWND_Unwinder_EHFrame;
EH_UWND_ModuleUnwindInfo *unwind_info = push_array(arena, EH_UWND_ModuleUnwindInfo, 1);
{
String8 eh_frame_hdr_data = d_data_from_process_vaddr_range(arena, process_handle, module_info->eh_frame_header_vaddr_range, 0);
unwind_info->ptr_ctx.pc_vaddr = module_info->eh_frame_header_vaddr_range.min;
unwind_info->ptr_ctx.data_vaddr = module_info->eh_frame_header_vaddr_range.min;
unwind_info->header = eh_parse_frame_hdr(eh_frame_hdr_data, byte_size_from_arch(module_info->arch), &unwind_info->ptr_ctx);
}
unwind_info_opaque = unwind_info;
}
}
//- rjf: compute local symbol server cache path for this debug info
String8 local_symbol_server_cache_path = smsv_local_path_from_key(scratch2.arena, str8_skip_last_slash(module_info->debug_info_path), module_info->debug_info_guid, module_info->debug_info_age);
//- rjf: pick default initial debug info path
String8 initial_debug_info_path = {0};
{
String8List candidates = {0};
// rjf: push module-embedded debug info paths, try both relative-to-exe & absolute
if(module_info->debug_info_path.size != 0)
{
PathStyle path_style = path_style_from_str8(module_info->debug_info_path);
if(path_style == PathStyle_Relative)
{
String8 module_image_folder = str8_chop_last_slash(module_info->module_path);
str8_list_pushf(scratch2.arena, &candidates, "%S/%S", module_image_folder, module_info->debug_info_path);
}
str8_list_push(scratch2.arena, &candidates, module_info->debug_info_path);
}
// rjf: push heuristic-based debug info paths
{
String8 exe_path = module_info->module_path;
String8 exe_path_no_ext = str8_chop_last_dot(exe_path);
str8_list_pushf(scratch2.arena, &candidates, "%S.pdb", exe_path_no_ext);
str8_list_pushf(scratch2.arena, &candidates, "%S.pdb", exe_path);
str8_list_pushf(scratch2.arena, &candidates, "%S.rdi", exe_path_no_ext);
str8_list_pushf(scratch2.arena, &candidates, "%S.rdi", exe_path);
}
// rjf: push local symbol server cache's path
if(local_symbol_server_cache_path.size != 0)
{
str8_list_push(scratch2.arena, &candidates, local_symbol_server_cache_path);
}
// rjf: pick first candidate that works
for EachNode(n, String8Node, candidates.first)
{
String8 candidate_path = n->string;
FileProperties props = properties_from_file_path(candidate_path);
if(props.modified != 0 && props.size != 0)
{
initial_debug_info_path = str8_copy(arena, path_normalized_from_string(scratch2.arena, candidate_path));
break;
}
}
}
//- rjf: no found debug info path -> try to fall back on symbol server cache path.
//
// if it exists, we can just use it. if it doesn't, then we only want to pick it *if*
// automatic downloads are enabled.
//
if(initial_debug_info_path.size == 0 && d_ctrl_state->auto_download_debug_info && local_symbol_server_cache_path.size != 0)
{
initial_debug_info_path = str8_copy(arena, local_symbol_server_cache_path);
}
//- rjf: write 1 at attachment marker, to signify attachment
if(module_info->raddbg_is_attached_marker_voff != 0)
{
U8 new_value = 1;
d_process_write_struct(process_handle, base_vaddr + module_info->raddbg_is_attached_marker_voff, &new_value);
}
//- rjf: fill info
D_ModuleInfo info = {0};
{
info.entry_point_voff = module_info->entry_point_voff;
info.unwinder = unwinder;
info.unwind_info = unwind_info_opaque;
info.local_debug_info_path = initial_debug_info_path;
info.dbg_name = str8_copy(arena, str8_skip_last_slash(module_info->debug_info_path));
info.dbg_guid = module_info->debug_info_guid;
info.dbg_age = module_info->debug_info_age;
info.raddbg_attached_marker_voff = module_info->raddbg_is_attached_marker_voff;
info.raddbg_data = raddbg_data;
}
//- rjf: insert info into cache
d_module_info_store(module_handle, &arena, &info);
//- rjf: push module load
D_Event *out_evt1 = d_event_list_push(scratch.arena, &evts);
out_evt1->kind = D_EventKind_NewModule;
out_evt1->msg_id = msg->msg_id;
out_evt1->entity = module_handle;
@@ -3265,8 +3295,9 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt1->string = module_path;
out_evt1->tls_index = event->module_info->tls_index;
out_evt1->tls_offset = event->module_info->tls_offset;
//- rjf: push initial debug info path set
D_Event *out_evt2 = d_event_list_push(scratch.arena, &evts);
String8 initial_debug_info_path = d_initial_debug_info_path_from_module(scratch.arena, module_handle);
U64 debug_info_timestamp = properties_from_file_path(initial_debug_info_path).modified;
out_evt2->kind = D_EventKind_ModuleDebugInfoPathChange;
out_evt2->msg_id = msg->msg_id;
@@ -3274,9 +3305,14 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt2->parent = process_handle;
out_evt2->timestamp = debug_info_timestamp;
out_evt2->string = initial_debug_info_path;
// rjf: open debug info
DI_Key initial_dbgi_key = di_key_from_path_timestamp(initial_debug_info_path, debug_info_timestamp);
di_open(initial_dbgi_key);
scratch_end(scratch2);
}break;
//- rjf: exit process
case DMN_EventKind_ExitProcess:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3286,6 +3322,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->u64_code = event->code;
d_ctrl_state->process_counter -= 1;
}break;
//- rjf: exit thread
case DMN_EventKind_ExitThread:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3294,22 +3332,42 @@ 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->thread);
out_evt->entity_id = event->code;
}break;
//- rjf: unload module
case DMN_EventKind_UnloadModule:
ProfScope("unload module %.*s", str8_varg(event->string))
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
//- rjf: unpack module
D_Handle module_handle = d_handle_from_dmn(D_MachineID_Local, event->module);
D_Entity *module_ent = d_entity_from_handle(module_handle);
D_Entity *process_ent = d_process_from_entity(module_ent);
String8 module_path = event->string;
d_ctrl_thread__module_close(process_ent->handle, module_handle, module_ent->vaddr_range.min);
U64 base_vaddr = module_ent->vaddr_range.min;
U64 raddbg_attached_marker_voff = d_raddbg_attached_marker_voff_from_module(module_handle);
//- rjf: evict module info from cache
d_module_info_evict(module_handle);
//- rjf: write 0 at attachment marker, to signify detachment
if(raddbg_attached_marker_voff != 0)
{
U8 new_value = 0;
d_process_write_struct(process_ent->handle, base_vaddr + raddbg_attached_marker_voff, &new_value);
}
//- rjf: push event
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
out_evt->kind = D_EventKind_EndModule;
out_evt->msg_id = msg->msg_id;
out_evt->entity = module_handle;
out_evt->string = module_path;
//- rjf: close debug info
DI_Key dbgi_key = d_dbgi_key_from_module(module_ent);
di_close(dbgi_key, 0);
}break;
//- rjf: debug string
case DMN_EventKind_DebugString:
{
U64 num_strings = (event->string.size + d_ctrl_state->c2u_ring_max_string_size-1) / d_ctrl_state->c2u_ring_max_string_size;
@@ -3323,6 +3381,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->string = str8_substr(event->string, r1u64(string_idx*d_ctrl_state->c2u_ring_max_string_size, (string_idx+1)*d_ctrl_state->c2u_ring_max_string_size));
}
}break;
//- rjf: thread names
case DMN_EventKind_SetThreadName:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3333,6 +3393,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->string = event->string;
out_evt->entity_id = event->code;
}break;
//- rjf: thread color
case DMN_EventKind_SetThreadColor:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3343,6 +3405,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->entity_id = event->code;
out_evt->rgba = event->user_data;
}break;
//- rjf: vaddr range notes
case DMN_EventKind_SetVAddrRangeNote:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3352,6 +3416,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->vaddr_rng = r1u64(event->address, event->address + event->size);
out_evt->string = event->string;
}break;
//- rjf: programmatic breakpoint sets
case DMN_EventKind_SetBreakpoint:
{
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
@@ -3361,6 +3427,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->vaddr_rng = r1u64(event->address, event->address+event->size);
out_evt->bp_flags = d_breakpoint_flags_from_dmn_trap_flags(event->flags);
}break;
//- rjf: programmatic breakpoint unsets
case DMN_EventKind_UnsetBreakpoint:
{
// TODO(rjf): this needs to be reflected in the resolved trap list too!!!!!!!!
@@ -3858,7 +3926,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
{
Temp scratch = scratch_begin(0, 0);
//////////////////////////////
//- rjf: unpack path
//
String8 path = msg->path;
File file = file_open(AccessFlag_Read, path);
FileProperties props = properties_from_file(file);
@@ -3866,7 +3936,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
void *base = file_map_view_open(map, AccessFlag_Read, r1u64(0, props.size));
String8 data = str8(base, base ? props.size : 0);
//////////////////////////////
//- rjf: try to parse file data as a dump file, extract abstracted (over format) dump info
//
B32 stored = 0;
D_EventList evts = {0};
Arena *arena = 0;
@@ -3880,7 +3952,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
Arch process_arch = Arch_Null;
OperatingSystem process_os = OperatingSystem_Null;
{
////////////////////////////
//- rjf: try minidump parse -> construct events for entity creation
//
{
MDMP_Header header = {0};
str8_deserial_read_struct(data, 0, &header);
@@ -3954,7 +4028,6 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
}break;
case MDMP_StreamKind_Memory64List:
{
U64 memories64_count = 0;
U64 off = dir->location.foff;
off += str8_deserial_read_struct(data, off, &memories64_count);
off += str8_deserial_read_struct(data, off, &memories64_base_foff);
@@ -3992,10 +4065,21 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
case MDMP_Arch_x64:{process_arch = Arch_x64;}break;
}
// rjf: system info -> os
if(system_info != 0) switch(system_info->platform_id)
{
default:{}break;
case MDMP_PlatformID_Win32s:
case MDMP_PlatformID_Win32Windows:
case MDMP_PlatformID_Win32NT:
{
process_os = OperatingSystem_Windows;
}break;
}
// rjf: create process handle
d_ctrl_state->ctrl_thread_dump_handle_id_gen += 1;
process = d_dump_handle_make(D_MachineID_Local, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
process_os = OperatingSystem_Windows; // NOTE(rjf): minidumps are always windows
// rjf: gather threads
dump_threads_count = threads_count;
@@ -4035,6 +4119,7 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
FileProperties module_props = properties_from_file(module_file);
FileMap module_map = file_map_open(AccessFlag_Read, module_file);
void *module_base = file_map_view_open(module_map, AccessFlag_Read, r1u64(0, module_props.size));
String8 module_data = str8(module_base, module_props.size);
// rjf: store
d_ctrl_state->ctrl_thread_dump_handle_id_gen += 1;
@@ -4050,7 +4135,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
}
}
//////////////////////////////
//- rjf: record process creation
//
{
D_Event *evt = d_event_list_push(scratch.arena, &evts);
evt->kind = D_EventKind_NewProc;
@@ -4061,7 +4148,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
evt->string = path;
}
//////////////////////////////
//- rjf: store the dump parse artifacts in the dump cache, otherwise release
//
if(stored)
{
U64 hash = d_hash_from_handle(process);
@@ -4105,7 +4194,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
file_close(file);
}
//////////////////////////////
//- rjf: record thread creation
//
for EachIndex(idx, dump_threads_count)
{
D_Handle thread_handle = dump_threads[idx].thread_handle;
@@ -4120,24 +4211,84 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
// TODO(rjf): evt->tls_root = ; (use thread->thread_context)
}
//////////////////////////////
//- rjf: record module loading
//
for EachIndex(idx, dump_modules_count)
{
// rjf: open module
//- rjf: open module
D_Handle module_handle = dump_modules[idx].module_handle;
Rng1U64 vaddr_range = dump_modules[idx].vaddr_range;
#if 0
// TODO(rjf): I don't think we can use this demon module info path here
//- TODO(rjf): I don't think we can use this demon module info path here
DMN_ModuleInfo module_info = {0};
d_ctrl_thread__module_open(process, module_handle, vaddr_range.min, dump_modules[idx].path, r1u64(0, 0), 0);
#endif
// rjf: open debug info
//- rjf: analyze module file, produce module info
Arena *module_info_arena = arena_alloc();
D_ModuleInfo module_info = {0};
{
String8 module_data = str8((U8 *)dump_modules[idx].base, dump_modules[idx].props.size);
//- rjf: PEs
PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, module_data);
if(pe.arch != Arch_Null)
{
//- rjf: fill basics
module_info.entry_point_voff = pe.entry_point;
//- rjf: fill unwinder info
switch(pe.arch)
{
default:{}break;
case Arch_x64:
if(PE_DataDirectoryIndex_EXCEPTIONS < pe.data_dir_count)
{
Rng1U64 pdatas_foff_range = pe.data_dir_franges[PE_DataDirectoryIndex_EXCEPTIONS];
U64 pdatas_count_supposedly = dim_1u64(pdatas_foff_range) / sizeof(PE_IntelPdata);
U64 pdatas_count_possible = pdatas_foff_range.min < module_data.size ? (module_data.size - pdatas_foff_range.min) / sizeof(PE_IntelPdata) : 0;
U64 pdatas_count = Min(pdatas_count_possible, pdatas_count_supposedly);
PE_X64_UWND_ModuleUnwindInfo *module_unwind_info = push_array(module_info_arena, PE_X64_UWND_ModuleUnwindInfo, 1);
module_unwind_info->pdatas_count = pdatas_count;
module_unwind_info->pdatas = (PE_IntelPdata *)(module_data.str + pdatas_foff_range.min);
module_info.unwinder = UWND_Unwinder_PEx64;
module_info.unwind_info = module_unwind_info;
}break;
}
//- rjf: fill debug path info
{
String8 raw_debug_dir = str8_substr(module_data, pe.data_dir_franges[PE_DataDirectoryIndex_DEBUG]);
PE_DebugInfoList debug_dir = pe_debug_info_list_from_raw_debug_dir(scratch.arena, module_data, raw_debug_dir);
for(PE_DebugInfoNode *n = debug_dir.first; n != 0; n = n->next)
{
if(n->v.path.size != 0)
{
module_info.local_debug_info_path = str8_copy(module_info_arena, n->v.path);
module_info.dbg_name = str8_skip_last_slash(module_info.local_debug_info_path);
module_info.dbg_guid = n->v.guid;
module_info.dbg_age = n->v.age;
break;
}
}
}
//- TODO(rjf): still missing: raddbg data (rare but in theory possible)
}
}
//- rjf: store module info
d_module_info_store(module_handle, &module_info_arena, &module_info);
//- rjf: open debug info
String8 initial_debug_info_path = d_initial_debug_info_path_from_module(scratch.arena, module_handle);
U64 debug_info_timestamp = properties_from_file_path(initial_debug_info_path).modified;
DI_Key initial_dbgi_key = di_key_from_path_timestamp(initial_debug_info_path, debug_info_timestamp);
di_open(initial_dbgi_key);
// rjf: push module load event
//- rjf: push module load event
{
D_Event *evt = d_event_list_push(scratch.arena, &evts);
evt->kind = D_EventKind_NewModule;
@@ -4151,7 +4302,7 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
// TODO(rjf): evt->tls_root = ; (use thread->thread_context)
}
// rjf: push debug info initial path set event
//- rjf: push debug info initial path set event
{
D_Event *evt = d_event_list_push(scratch.arena, &evts);
evt->kind = D_EventKind_ModuleDebugInfoPathChange;
+5 -4
View File
@@ -549,9 +549,14 @@ internal U64 d_cached_sp_from_thread(D_Handle handle);
////////////////////////////////
//~ rjf: Module Image Info Functions
//- rjf: module info stores / evictions
internal void d_module_info_store(D_Handle module, Arena **stored_arena, D_ModuleInfo *info);
internal void d_module_info_evict(D_Handle module);
//- rjf: cache lookups
internal D_ModuleInfo *d_info_from_module(Access *access, D_Handle module);
internal U64 d_entry_point_voff_from_module(D_Handle module_handle);
internal U64 d_raddbg_attached_marker_voff_from_module(D_Handle module_handle);
internal String8 d_initial_debug_info_path_from_module(Arena *arena, D_Handle module_handle);
////////////////////////////////
@@ -600,10 +605,6 @@ internal void d_ctrl_thread__append_resolved_module_user_bp_traps(Arena *arena,
internal void d_ctrl_thread__append_resolved_process_user_bp_traps(Arena *arena, D_EvalScope *eval_scope, D_Handle process, D_BreakpointList *user_bps, DMN_TrapChunkList *traps_out);
internal void d_ctrl_thread__append_program_defined_bp_traps(Arena *arena, D_Entity *bp, DMN_TrapChunkList *traps_out);
//- rjf: module lifetime open/close work
internal void d_ctrl_thread__module_open(D_Handle process, D_Handle module, U64 base_vaddr, DMN_ModuleInfo *module_info);
internal void d_ctrl_thread__module_close(D_Handle process, D_Handle module, U64 base_vaddr);
//- rjf: dump process closing work
internal void d_ctrl_thread__close_dump_process(D_MsgID msg_id, D_Handle process);
+10 -10
View File
@@ -5969,7 +5969,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
U32 load_config_size = 0;
if (sizeof(load_config_size) <= load_config_data.size) {
MemoryCopyStruct(&load_config_size, load_config_data.str); // TODO: load config
PE_DataDirectory *load_config_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_LOAD_CONFIG);
PE_DataDirectory *load_config_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_LOAD_CONFIG);
load_config_dir->virt_off = lnk_voff_from_symbol(image_section_table, load_config_symbol);
load_config_dir->virt_size = load_config_size;
} else {
@@ -5985,7 +5985,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
String8 raw_pdata = str8_substr(image_data, rng_1u64(pdata_sect->foff, pdata_sect->foff + pdata_sect->vsize));
pe_pdata_sort(config->machine, raw_pdata);
PE_DataDirectory *pdata_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_EXCEPTIONS);
PE_DataDirectory *pdata_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_EXCEPTIONS);
pdata_dir->virt_off = lnk_get_first_section_contrib_voff(image_section_table, pdata_sect);
pdata_dir->virt_size = lnk_get_section_contrib_size(pdata_sect);
}
@@ -5995,7 +5995,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
{
LNK_Section *edata_sect = lnk_image_section_table_search(config, sectab, str8_lit(".edata"), PE_EDATA_SECTION_FLAGS);
if (edata_sect) {
PE_DataDirectory *export_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_EXPORT);
PE_DataDirectory *export_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_EXPORT);
LNK_SectionContrib *edata_first_contrib = lnk_get_first_section_contrib(edata_sect);
LNK_SectionContrib *edata_last_contrib = lnk_get_last_section_contrib(edata_sect);
export_dir->virt_off = lnk_get_first_section_contrib_voff(image_section_table, edata_sect);
@@ -6007,7 +6007,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
{
LNK_Section *reloc_sect = lnk_image_section_table_search(config, sectab, str8_lit(".reloc"), PE_RELOC_SECTION_FLAGS);
if (reloc_sect) {
PE_DataDirectory *reloc_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_BASE_RELOC);
PE_DataDirectory *reloc_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_BASE_RELOC);
reloc_dir->virt_off = lnk_get_first_section_contrib_voff(image_section_table, reloc_sect);
reloc_dir->virt_size = lnk_get_section_contrib_size(reloc_sect);
}
@@ -6021,7 +6021,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
if (idata_sect && null_import_desc && null_thunk_data) {
COFF_ParsedSymbol null_import_desc_parsed = lnk_parsed_from_symbol(null_import_desc);
LNK_SectionContrib *idata_first_contrib = lnk_get_first_section_contrib(idata_sect);
PE_DataDirectory *import_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_IMPORT);
PE_DataDirectory *import_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_IMPORT);
import_dir->virt_off = image_section_table[idata_first_contrib->u.sect_idx + 1]->voff + idata_first_contrib->u.off;
import_dir->virt_size = null_import_desc_parsed.value - idata_first_contrib->u.off + sizeof(PE_ImportEntry);
@@ -6029,7 +6029,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
U64 null_thunk_data_voff = image_section_table[null_thunk_data_parsed.section_number]->voff + null_thunk_data_parsed.value;
U64 first_import_foff = image_section_table[idata_first_contrib->u.sect_idx+1]->foff + idata_first_contrib->u.off;
PE_ImportEntry *first_import = str8_deserial_get_raw_ptr(image_data, first_import_foff, sizeof(*first_import));
PE_DataDirectory *import_addr_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_IMPORT_ADDR);
PE_DataDirectory *import_addr_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_IMPORT_ADDR);
import_addr_dir->virt_off = first_import->import_addr_table_voff;
import_addr_dir->virt_size = null_thunk_data_voff - first_import->import_addr_table_voff /* null */ + coff_word_size_from_machine(config->machine);
}
@@ -6043,7 +6043,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
if (didat_sect && null_import_desc && last_null_thunk) {
COFF_ParsedSymbol null_import_desc_parsed = lnk_parsed_from_symbol(null_import_desc);
LNK_SectionContrib *didat_first_contrib = lnk_get_first_section_contrib(didat_sect);
PE_DataDirectory *import_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_DELAY_IMPORT);
PE_DataDirectory *import_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_DELAY_IMPORT);
import_dir->virt_off = lnk_get_first_section_contrib_voff(image_section_table, didat_sect);
import_dir->virt_size = lnk_get_section_contrib_size(didat_sect);
}
@@ -6077,7 +6077,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
}
// patch directory
PE_DataDirectory *tls_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_TLS);
PE_DataDirectory *tls_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_TLS);
tls_dir->virt_off = lnk_voff_from_symbol(image_section_table, tls_used_symbol);
tls_dir->virt_size = is_tls_header64 ? sizeof(PE_TLSHeader64) : sizeof(PE_TLSHeader32);
@@ -6090,7 +6090,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
LNK_Section *debug_dir_sect = lnk_image_section_table_search(config, sectab, str8_lit(".RAD_LINK_PE_DEBUG_DIR"), PE_RDATA_SECTION_FLAGS);
if (debug_dir_sect) {
// patch directory
PE_DataDirectory *debug_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_DEBUG);
PE_DataDirectory *debug_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_DEBUG);
debug_dir->virt_off = lnk_get_first_section_contrib_voff(image_section_table, debug_dir_sect);
debug_dir->virt_size = lnk_get_section_contrib_size(debug_dir_sect);
@@ -6116,7 +6116,7 @@ lnk_build_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_SymbolT
{
LNK_Section *rsrc_sect = lnk_image_section_table_search(config, sectab, str8_lit(".rsrc"), PE_RSRC_SECTION_FLAGS);
if (rsrc_sect) {
PE_DataDirectory *rsrc_dir = pe_data_directory_from_idx(image_data, pe, PE_DataDirectoryIndex_RESOURCES);
PE_DataDirectory *rsrc_dir = pe_data_directory_from_idx(image_data, &pe, PE_DataDirectoryIndex_RESOURCES);
rsrc_dir->virt_off = lnk_get_first_section_contrib_voff(image_section_table, rsrc_sect);
rsrc_dir->virt_size = lnk_get_section_contrib_size(rsrc_sect);
}
+20 -1
View File
@@ -210,6 +210,25 @@ typedef enum MDMP_ArchEnum
}
MDMP_ArchEnum;
typedef U32 MDMP_PlatformID;
typedef enum MDMP_PlatformIDEnum
{
MDMP_PlatformID_Win32s = 0x0, // Windows 3.1
MDMP_PlatformID_Win32Windows = 0x1, // Windows 95, 98, Me
MDMP_PlatformID_Win32NT = 0x2, // Windows NT, 2000, XP, & later
//- rjf: extensions
MDMP_PlatformID_Unix = 0x8000,
MDMP_PlatformID_MacOSX = 0x8101,
MDMP_PlatformID_IOS = 0x8102,
MDMP_PlatformID_Linux = 0x8201,
MDMP_PlatformID_Solaris = 0x8202,
MDMP_PlatformID_Android = 0x8203,
MDMP_PlatformID_PS3 = 0x8204,
MDMP_PlatformID_NaCl = 0x8205,
MDMP_PlatformID_Fuchsia = 0x8206,
}
MDMP_PlatformIDEnum;
typedef struct MDMP_SystemInfo MDMP_SystemInfo;
struct MDMP_SystemInfo
{
@@ -221,7 +240,7 @@ struct MDMP_SystemInfo
U32 major_version;
U32 minor_version;
U32 build_number;
U32 platform_id;
MDMP_PlatformID platform_id;
U32 csd_version_rva;
U16 suite_mask;
U16 padding;
+9 -4
View File
@@ -361,7 +361,7 @@ pe_string_from_file_characteristics(Arena *arena, PE_ImageFileCharacteristics fi
#define X(ID, VAL, DISPLAY_STRING) case (1 << VAL): str8_list_push(scratch.arena, &result, str8_lit(DISPLAY_STRING)); break;
PE_ImageFileCharacteristic_XList
#undef X
default: str8_list_pushf(scratch.arena, &result, "%llu", i);
default: str8_list_pushf(scratch.arena, &result, "%llu", i);
}
}
String8 string = str8_list_join(arena, &result, &(StringJoin){.sep=str8_lit(", ")});
@@ -649,11 +649,12 @@ pe_bin_info_from_data(Arena *arena, String8 data)
}
internal PE_DataDirectory *
pe_data_directory_from_idx(String8 file_data, PE_BinInfo pe, PE_DataDirectoryIndex dir_idx)
pe_data_directory_from_idx(String8 file_data, PE_BinInfo *pe, PE_DataDirectoryIndex dir_idx)
{
PE_DataDirectory *result = 0;
if (dir_idx < pe.data_dir_count) {
result = str8_deserial_get_raw_ptr(file_data, pe.data_dir_range.min + sizeof(*result)*dir_idx, sizeof(*result));
if(dir_idx < pe->data_dir_count)
{
result = str8_deserial_get_raw_ptr(file_data, pe->data_dir_range.min + sizeof(*result)*dir_idx, sizeof(*result));
}
return result;
}
@@ -688,6 +689,7 @@ pe_debug_info_list_from_raw_debug_dir(Arena *arena, String8 raw_image, String8 r
str8_deserial_read_cstr(raw_image, entry->foff+sizeof(cv), &path);
n->v.cv_pdb20_header = cv;
n->v.path = path;
n->v.age = cv.age;
}
}break;
case PE_CODEVIEW_PDB70_MAGIC:
@@ -700,6 +702,8 @@ pe_debug_info_list_from_raw_debug_dir(Arena *arena, String8 raw_image, String8 r
str8_deserial_read_cstr(raw_image, entry->foff+sizeof(cv), &path);
n->v.cv_pdb70_header = cv;
n->v.path = path;
n->v.guid = cv.guid;
n->v.age = cv.age;
}
}break;
case PE_CODEVIEW_RDI_MAGIC:
@@ -712,6 +716,7 @@ pe_debug_info_list_from_raw_debug_dir(Arena *arena, String8 raw_image, String8 r
str8_deserial_read_cstr(raw_image, entry->foff+sizeof(cv), &path);
n->v.cv_rdi_header = cv;
n->v.path = path;
n->v.guid = cv.guid;
}
}break;
default:{}break;
+50 -46
View File
@@ -54,22 +54,22 @@ enum
};
#define PE_ImageFileCharacteristic_XList \
X(RELOCS_STRIPPED , 0 , "Relocations Stripped" ) \
X(EXECUTABLE_IMAGE , 1 , "Executable" ) \
X(LINE_NUMS_STRIPPED , 2 , "Line Numbers Stripped" ) \
X(LOCAL_SYMS_STRIPPED , 3 , "Local Symbols Stripped" ) \
X(AGGRESSIVE_WS_TRIM , 4 , "Aggressive Working Set Trim") \
X(LARGE_ADDRESS_AWARE , 5 , "Large Address Aware" ) \
X(RESERVED , 6 , "Reserved" ) \
X(BYTES_REVERSED_LO , 7 , "Bytes Reversed Low" ) \
X(32BIT_MACHINE , 8 , "32-Bit Machine" ) \
X(DEBUG_STRIPPED , 9 , "Debug Information Stripped" ) \
X(REMOVABLE_RUN_FROM_SWAP, 10, "Removable: Run from Swap" ) \
X(NET_RUN_FROM_SWAP , 11, "Network: Run from Swap" ) \
X(SYSTEM , 12, "System File" ) \
X(DLL , 13, "DLL" ) \
X(UP_SYSTEM_ONLY , 14, "Uniprocessor System Only" ) \
X(BYTES_REVERSED_HI , 15, "Bytes Reversed High" )
X(RELOCS_STRIPPED , 0 , "Relocations Stripped" ) \
X(EXECUTABLE_IMAGE , 1 , "Executable" ) \
X(LINE_NUMS_STRIPPED , 2 , "Line Numbers Stripped" ) \
X(LOCAL_SYMS_STRIPPED , 3 , "Local Symbols Stripped" ) \
X(AGGRESSIVE_WS_TRIM , 4 , "Aggressive Working Set Trim") \
X(LARGE_ADDRESS_AWARE , 5 , "Large Address Aware" ) \
X(RESERVED , 6 , "Reserved" ) \
X(BYTES_REVERSED_LO , 7 , "Bytes Reversed Low" ) \
X(32BIT_MACHINE , 8 , "32-Bit Machine" ) \
X(DEBUG_STRIPPED , 9 , "Debug Information Stripped" ) \
X(REMOVABLE_RUN_FROM_SWAP, 10, "Removable: Run from Swap" ) \
X(NET_RUN_FROM_SWAP , 11, "Network: Run from Swap" ) \
X(SYSTEM , 12, "System File" ) \
X(DLL , 13, "DLL" ) \
X(UP_SYSTEM_ONLY , 14, "Uniprocessor System Only" ) \
X(BYTES_REVERSED_HI , 15, "Bytes Reversed High" )
typedef U16 PE_ImageFileCharacteristics;
enum
@@ -1006,28 +1006,29 @@ struct PE_HandlerScope
typedef struct PE_BinInfo PE_BinInfo;
struct PE_BinInfo
{
Arch arch;
U64 image_base;
U64 entry_point;
B32 is_pe32;
PE_WindowsSubsystem subsystem;
U32 *check_sum;
U64 virt_section_align;
U64 file_section_align;
U64 section_count;
U64 symbol_count;
U64 optional_header_off;
Rng1U64 section_table_range;
Rng1U64 symbol_table_range;
Rng1U64 string_table_range;
Rng1U64 data_dir_range;
Rng1U64 *data_dir_franges;
Rng1U64 *data_dir_vranges;
U32 data_dir_count;
PE_TLSHeader64 tls_header;
Arch arch;
U64 image_base;
U64 entry_point;
B32 is_pe32;
PE_WindowsSubsystem subsystem;
U32 *check_sum;
U64 virt_section_align;
U64 file_section_align;
U64 section_count;
U64 symbol_count;
U64 optional_header_off;
Rng1U64 section_table_range;
Rng1U64 symbol_table_range;
Rng1U64 string_table_range;
Rng1U64 data_dir_range;
Rng1U64 *data_dir_franges;
Rng1U64 *data_dir_vranges;
U32 data_dir_count;
PE_TLSHeader64 tls_header;
};
typedef struct PE_DebugInfo
typedef struct PE_DebugInfo PE_DebugInfo;
struct PE_DebugInfo
{
PE_DebugDirectory header;
U32 cv_magic;
@@ -1035,21 +1036,24 @@ typedef struct PE_DebugInfo
PE_CvHeaderPDB70 cv_pdb70_header;
PE_CvHeaderRDI cv_rdi_header;
String8 path;
}
PE_DebugInfo;
Guid guid;
U32 age;
};
typedef struct PE_DebugInfoNode
typedef struct PE_DebugInfoNode PE_DebugInfoNode;
struct PE_DebugInfoNode
{
struct PE_DebugInfoNode *next;
PE_DebugInfo v;
} PE_DebugInfoNode;
PE_DebugInfoNode *next;
PE_DebugInfo v;
};
typedef struct PE_DebugInfoList
typedef struct PE_DebugInfoList PE_DebugInfoList;
struct PE_DebugInfoList
{
PE_DebugInfoNode *first;
PE_DebugInfoNode *last;
U64 count;
} PE_DebugInfoList;
U64 count;
};
////////////////////////////////
//~ rjf: Basic Enum Functions
@@ -1076,7 +1080,7 @@ internal String8 pe_string_from_dll_characteristics(Arena *arena, PE_DllCharacte
internal B32 pe_check_magic(String8 data);
internal PE_BinInfo pe_bin_info_from_data(Arena *arena, String8 data);
internal PE_DataDirectory * pe_data_directory_from_idx(String8 file_data, PE_BinInfo pe, PE_DataDirectoryIndex dir_idx);
internal PE_DataDirectory * pe_data_directory_from_idx(String8 file_data, PE_BinInfo *pe, PE_DataDirectoryIndex dir_idx);
internal PE_DebugInfoList pe_parse_debug_directory(Arena *arena, String8 raw_image, String8 raw_debug_dir);
internal PE_DebugInfoList pe_debug_info_list_from_raw_debug_dir(Arena *arena, String8 raw_image, String8 raw_debug_dir);
internal PE_ParsedStaticImportTable pe_static_imports_from_data(Arena *arena, B32 is_pe32, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 dir_file_range);
+1 -1
View File
@@ -637,7 +637,7 @@ RD_CmdKindInfo rd_cmd_kind_info_table[257] =
{ str8_lit_comp("set_entity_name"), str8_lit_comp("Sets the passed entity's name."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp("")}},
{ str8_lit_comp("download_module_debug_info"), str8_lit_comp("Tries to download a module's debug info from symbol server(s)."), str8_lit_comp(""), str8_lit_comp("{module_commands}"), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_CtrlEntity, str8_lit_comp("query:modules")}},
{ str8_lit_comp("attach"), str8_lit_comp("Attaches to a process that is already running on the local machine."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_PID, str8_lit_comp("query:unattached_processes")}},
{ str8_lit_comp("open_crash_dump"), str8_lit_comp("Opens a crash dump file and recreates debuggee state at the time of the crash."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_FilePath, str8_lit_comp("folder:\"$input\"")}},
{ str8_lit_comp("open_crash_dump"), str8_lit_comp("Opens a crash dump file and recreates debuggee state at the time of the crash."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_FilePath, str8_lit_comp("folder:\"$input\"")}},
{ str8_lit_comp("exit"), str8_lit_comp("Exits the debugger."), str8_lit_comp("quit,close,abort"), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp("")}},
{ str8_lit_comp("open_palette"), str8_lit_comp("Opens the palette."), str8_lit_comp("help,cmd,lister"), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp("")}},
{ str8_lit_comp("run_command"), str8_lit_comp("Runs a command from the command palette."), str8_lit_comp("help,cmd"), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_CmdName, str8_lit_comp("query:commands")}},