custom module loads -> support manually specifying pdb path

This commit is contained in:
Ryan Fleury
2026-07-23 20:28:52 -07:00
parent b0841ff2da
commit 78d12eb914
3 changed files with 62 additions and 49 deletions
+43 -41
View File
@@ -20,45 +20,45 @@
//~ Usage Macros //~ Usage Macros
#if !defined(RADDBG_MARKUP_STUBS) #if !defined(RADDBG_MARKUP_STUBS)
# define raddbg_is_attached(...) raddbg_is_attached__impl() # define raddbg_is_attached(...) raddbg_is_attached__impl()
# define raddbg_thread_id(...) raddbg_thread_id__impl() # define raddbg_thread_id(...) raddbg_thread_id__impl()
# define raddbg_thread_name(...) raddbg_thread_name__impl(raddbg_thread_id(), __VA_ARGS__) # define raddbg_thread_name(...) raddbg_thread_name__impl(raddbg_thread_id(), __VA_ARGS__)
# define raddbg_thread_id_name(id, ...) raddbg_thread_name__impl((id), __VA_ARGS__) # define raddbg_thread_id_name(id, ...) raddbg_thread_name__impl((id), __VA_ARGS__)
# define raddbg_thread_color_u32(u32) raddbg_thread_color__impl(raddbg_thread_id(), (u32)) # define raddbg_thread_color_u32(u32) raddbg_thread_color__impl(raddbg_thread_id(), (u32))
# define raddbg_thread_color_rgba(r, g, b, a) raddbg_thread_color__impl(raddbg_thread_id(), ((unsigned int)((r)*255) << 24) | ((unsigned int)((g)*255) << 16) | ((unsigned int)((b)*255) << 8) | ((unsigned int)(a)*255)) # define raddbg_thread_color_rgba(r, g, b, a) raddbg_thread_color__impl(raddbg_thread_id(), ((unsigned int)((r)*255) << 24) | ((unsigned int)((g)*255) << 16) | ((unsigned int)((b)*255) << 8) | ((unsigned int)(a)*255))
# define raddbg_thread_id_color_u32(id, u32) raddbg_thread_color__impl((id), (u32)) # define raddbg_thread_id_color_u32(id, u32) raddbg_thread_color__impl((id), (u32))
# define raddbg_thread_id_color_rgba(id, r, g, b, a) raddbg_thread_color__impl((id), ((unsigned int)((r)*255) << 24) | ((unsigned int)((g)*255) << 16) | ((unsigned int)((b)*255) << 8) | ((unsigned int)(a)*255)) # define raddbg_thread_id_color_rgba(id, r, g, b, a) raddbg_thread_color__impl((id), ((unsigned int)((r)*255) << 24) | ((unsigned int)((g)*255) << 16) | ((unsigned int)((b)*255) << 8) | ((unsigned int)(a)*255))
# define raddbg_break(...) raddbg_break__impl() # define raddbg_break(...) raddbg_break__impl()
# define raddbg_break_if(expr, ...) ((expr) ? raddbg_break__impl() : (void)0) # define raddbg_break_if(expr, ...) ((expr) ? raddbg_break__impl() : (void)0)
# define raddbg_watch(fmt, ...) raddbg_watch__impl((fmt), __VA_ARGS__) # define raddbg_watch(fmt, ...) raddbg_watch__impl((fmt), __VA_ARGS__)
# define raddbg_pin(expr, ...) /* NOTE(rjf): inspected by debugger ui - does not change program execution */ # define raddbg_pin(expr, ...) /* NOTE(rjf): inspected by debugger ui - does not change program execution */
# define raddbg_log(...) raddbg_log__impl(__VA_ARGS__) # define raddbg_log(...) raddbg_log__impl(__VA_ARGS__)
# define raddbg_entry_point(...) raddbg_exe_data char raddbg_gen_data_id()[] = ("entry_point: \"" #__VA_ARGS__ "\"") # define raddbg_entry_point(...) raddbg_exe_data char raddbg_gen_data_id()[] = ("entry_point: \"" #__VA_ARGS__ "\"")
# define raddbg_type_view(type, ...) raddbg_exe_data char raddbg_gen_data_id()[] = ("type_view: {type: ```" #type "```, expr: ```" #__VA_ARGS__ "```}") # define raddbg_type_view(type, ...) raddbg_exe_data char raddbg_gen_data_id()[] = ("type_view: {type: ```" #type "```, expr: ```" #__VA_ARGS__ "```}")
# define raddbg_add_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (1), (size), (r), (w), (x)) # define raddbg_add_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (1), (size), (r), (w), (x))
# define raddbg_remove_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (0), (size), (r), (w), (x)) # define raddbg_remove_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (0), (size), (r), (w), (x))
# define raddbg_annotate_vaddr_range(ptr, size, ...) raddbg_annotate_vaddr_range__impl((ptr), (size), __VA_ARGS__) # define raddbg_annotate_vaddr_range(ptr, size, ...) raddbg_annotate_vaddr_range__impl((ptr), (size), __VA_ARGS__)
# define raddbg_load_module(ptr, size, name) raddbg_load_module__impl((ptr), (size), (name)) # define raddbg_load_module(ptr, size, name, dbg_path) raddbg_load_module__impl((ptr), (size), (name), (dbg_path))
#else #else
# define raddbg_is_attached(...) (0) # define raddbg_is_attached(...) (0)
# define raddbg_thread_id(...) ((void)0) # define raddbg_thread_id(...) ((void)0)
# define raddbg_thread_name(fmt, ...) ((void)0) # define raddbg_thread_name(fmt, ...) ((void)0)
# define raddbg_thread_id_name(id, fmt, ...) ((void)0) # define raddbg_thread_id_name(id, fmt, ...) ((void)0)
# define raddbg_thread_color_u32(u32) ((void)0) # define raddbg_thread_color_u32(u32) ((void)0)
# define raddbg_thread_color_rgba(r, g, b, a) ((void)0) # define raddbg_thread_color_rgba(r, g, b, a) ((void)0)
# define raddbg_thread_id_color_u32(id, u32) ((void)0) # define raddbg_thread_id_color_u32(id, u32) ((void)0)
# define raddbg_thread_id_color_rgba(id, r, g, b, a) ((void)0) # define raddbg_thread_id_color_rgba(id, r, g, b, a) ((void)0)
# define raddbg_break(...) ((void)0) # define raddbg_break(...) ((void)0)
# define raddbg_break_if(expr, ...) ((void)expr) # define raddbg_break_if(expr, ...) ((void)expr)
# define raddbg_watch(fmt, ...) ((void)0) # define raddbg_watch(fmt, ...) ((void)0)
# define raddbg_pin(expr, ...) # define raddbg_pin(expr, ...)
# define raddbg_log(fmt, ...) ((void)0) # define raddbg_log(fmt, ...) ((void)0)
# define raddbg_entry_point(...) struct raddbg_gen_data_id(){int __unused__;} # define raddbg_entry_point(...) struct raddbg_gen_data_id(){int __unused__;}
# define raddbg_type_view(type, ...) struct raddbg_gen_data_id(){int __unused__;} # define raddbg_type_view(type, ...) struct raddbg_gen_data_id(){int __unused__;}
# define raddbg_add_breakpoint(ptr, size, r, w, x) ((void)0) # define raddbg_add_breakpoint(ptr, size, r, w, x) ((void)0)
# define raddbg_remove_breakpoint(ptr, size, r, w, x) ((void)0) # define raddbg_remove_breakpoint(ptr, size, r, w, x) ((void)0)
# define raddbg_annotate_vaddr_range(ptr, size, ...) ((void)0) # define raddbg_annotate_vaddr_range(ptr, size, ...) ((void)0)
# define raddbg_load_module(ptr, size, name) ((void)0) # define raddbg_load_module(ptr, size, name, dbg_path) ((void)0)
#endif #endif
//////////////////////////////// ////////////////////////////////
@@ -469,7 +469,7 @@ raddbg_annotate_vaddr_range__impl(void *ptr, unsigned __int64 size, char *fmt, .
} }
void void
raddbg_load_module__impl(void *ptr, unsigned __int64 size, char *name) raddbg_load_module__impl(void *ptr, unsigned __int64 size, char *name, char *dbg_path)
{ {
if(raddbg_is_attached()) if(raddbg_is_attached())
{ {
@@ -480,12 +480,14 @@ raddbg_load_module__impl(void *ptr, unsigned __int64 size, char *name)
unsigned __int64 vaddr; unsigned __int64 vaddr;
unsigned __int64 size; unsigned __int64 size;
unsigned __int64 name_vaddr; unsigned __int64 name_vaddr;
unsigned __int64 dbg_path_vaddr;
}; };
#pragma pack(pop) #pragma pack(pop)
RADDBG_LoadModuleInfo info; RADDBG_LoadModuleInfo info;
info.vaddr = (unsigned __int64)ptr; info.vaddr = (unsigned __int64)ptr;
info.size = size; info.size = size;
info.name_vaddr= (unsigned __int64)name; info.name_vaddr = (unsigned __int64)name;
info.dbg_path_vaddr = (unsigned __int64)dbg_path;
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 6320 6322) #pragma warning(disable: 6320 6322)
__try __try
+18 -7
View File
@@ -497,7 +497,7 @@ w32_dmn_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address)
//- rjf: modules //- rjf: modules
internal DMN_ModuleInfo * internal DMN_ModuleInfo *
w32_dmn_module_info_from_process_module(Arena *arena, HANDLE process, HANDLE module, U64 base_vaddr, U64 module_name_vaddr, B32 module_name_is_unicode, B32 is_main_module) w32_dmn_module_info_from_process_module(Arena *arena, HANDLE process, HANDLE module, U64 base_vaddr, U64 module_name_vaddr, B32 module_name_is_unicode, B32 is_main_module, U64 dbg_path_vaddr)
{ {
DMN_ModuleInfo *info = push_array(arena, DMN_ModuleInfo, 1); DMN_ModuleInfo *info = push_array(arena, DMN_ModuleInfo, 1);
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -791,6 +791,16 @@ w32_dmn_module_info_from_process_module(Arena *arena, HANDLE process, HANDLE mod
} }
} }
//- rjf: nonzero debug path address -> try to read new path from it
if(dbg_path_vaddr != 0)
{
String8 debug_path_override_maybe = w32_dmn_str8_cstring_from_process_vaddr(arena, process, dbg_path_vaddr);
if(debug_path_override_maybe.size != 0)
{
debug_info_path = debug_path_override_maybe;
}
}
//- rjf: fill info //- rjf: fill info
info->arch = arch; info->arch = arch;
info->vsize = image_vsize; info->vsize = image_vsize;
@@ -2087,7 +2097,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls)
B32 module_name_is_unicode = (evt.u.CreateProcessInfo.fUnicode != 0); B32 module_name_is_unicode = (evt.u.CreateProcessInfo.fUnicode != 0);
// rjf: parse module info // rjf: parse module info
DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process_handle, module_handle, module_base, module_name_vaddr, module_name_is_unicode, 1); DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process_handle, module_handle, module_base, module_name_vaddr, module_name_is_unicode, 1, 0);
// rjf: create process/module entities (module is implied for processes - not reported directly via module events) // rjf: create process/module entities (module is implied for processes - not reported directly via module events)
W32_DMN_Entity *process = w32_dmn_entity_alloc(w32_dmn_shared->entities_base, W32_DMN_EntityKind_Process, evt.dwProcessId); W32_DMN_Entity *process = w32_dmn_entity_alloc(w32_dmn_shared->entities_base, W32_DMN_EntityKind_Process, evt.dwProcessId);
@@ -2324,7 +2334,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls)
HANDLE module_handle = evt.u.LoadDll.hFile; HANDLE module_handle = evt.u.LoadDll.hFile;
U64 module_name_vaddr = (U64)evt.u.LoadDll.lpImageName; U64 module_name_vaddr = (U64)evt.u.LoadDll.lpImageName;
B32 module_name_is_unicode = (evt.u.LoadDll.fUnicode != 0); B32 module_name_is_unicode = (evt.u.LoadDll.fUnicode != 0);
DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process->handle, module_handle, module_base, module_name_vaddr, module_name_is_unicode, 0); DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process->handle, module_handle, module_base, module_name_vaddr, module_name_is_unicode, 0, 0);
// rjf: create module entity // rjf: create module entity
W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, module_base); W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, module_base);
@@ -2777,13 +2787,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls)
case W32_DMN_EXCEPTION_RADDBG_LOAD_MODULE: case W32_DMN_EXCEPTION_RADDBG_LOAD_MODULE:
{ {
// rjf: unpack parameters // rjf: unpack parameters
U64 vaddr = exception->ExceptionInformation[0]; U64 vaddr = exception->ExceptionInformation[0];
U64 size = exception->ExceptionInformation[1]; U64 size = exception->ExceptionInformation[1];
U64 name_vaddr = exception->ExceptionInformation[2]; U64 name_vaddr = exception->ExceptionInformation[2];
U64 dbg_path_vaddr = exception->ExceptionInformation[3];
// rjf: parse module info // rjf: parse module info
W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId);
DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process->handle, 0, vaddr, name_vaddr, 0, 0); DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process->handle, 0, vaddr, name_vaddr, 0, 0, dbg_path_vaddr);
// rjf: create module entity // rjf: create module entity
W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, vaddr); W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, vaddr);
+1 -1
View File
@@ -346,7 +346,7 @@ internal String16 w32_dmn_read_memory_str16(Arena *arena, HANDLE process_handle,
#define w32_dmn_process_write_struct(process, vaddr, ptr) w32_dmn_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) #define w32_dmn_process_write_struct(process, vaddr, ptr) w32_dmn_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr)
//- rjf: modules //- rjf: modules
internal DMN_ModuleInfo *w32_dmn_module_info_from_process_module(Arena *arena, HANDLE process, HANDLE module, U64 base_vaddr, U64 module_name_vaddr, B32 module_name_is_unicode, B32 is_main_module); internal DMN_ModuleInfo *w32_dmn_module_info_from_process_module(Arena *arena, HANDLE process, HANDLE module, U64 base_vaddr, U64 module_name_vaddr, B32 module_name_is_unicode, B32 is_main_module, U64 dbg_path_vaddr);
//- rjf: threads //- rjf: threads
internal B32 w32_dmn_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block); internal B32 w32_dmn_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block);