Skip to content

Commit e06c016

Browse files
committed
wip
1 parent 34bd24c commit e06c016

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

host/src/windows/dbghelp.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,19 @@ unsafe fn init(cleanup: bool) -> Dbghelp {
231231
}
232232

233233
pub fn add_module(path: &str) {
234-
// let mut instance = lock_instance();
235-
// let instance = instance
236-
// .as_mut()
237-
// .expect("add_module must be called after init");
238-
239-
// if let Some(module_dirname) = module_path_str_to_dirname(path) {
240-
// let dirname = module_dirname.dirname();
241-
// if !instance.search_path_entries.iter().any(|el| el == dirname) {
242-
// instance.search_path_entries.push(dirname.to_owned());
243-
// }
244-
// }
234+
let mut instance = lock_instance();
235+
let instance = instance
236+
.as_mut()
237+
.expect("add_module must be called after init");
245238

246-
// refresh_modules_and_search_path(instance);
239+
if let Some(module_dirname) = module_path_str_to_dirname(path) {
240+
let dirname = module_dirname.dirname();
241+
if !instance.search_path_entries.iter().any(|el| el == dirname) {
242+
instance.search_path_entries.push(dirname.to_owned());
243+
}
244+
}
245+
246+
refresh_modules_and_search_path(instance);
247247
}
248248

249249
#[cfg(feature = "unloading")]
@@ -333,5 +333,21 @@ pub unsafe fn super_special_reinit_of_dbghelp() {
333333
return;
334334
}
335335

336+
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(module: isize) -> BOOL);
337+
338+
let lib = libloading::Library::new("dbghelp.dll").unwrap_or_else(|e| {
339+
panic!("Failed to load dbghelp.dll which is needed for backtraces to work correctly: {e}");
340+
});
341+
let lib = libloading::os::windows::Library::from(lib);
342+
let handle = lib.into_raw();
343+
344+
dbg!();
345+
while is_library_loaded("dbghelp.dll") {
346+
dbg!();
347+
let result = FreeLibrary(handle);
348+
handle_error(result, "FreeLibrary");
349+
}
350+
dbg!();
351+
336352
*instance = Some(unsafe { init(true) });
337353
}

0 commit comments

Comments
 (0)