@@ -231,19 +231,19 @@ unsafe fn init(cleanup: bool) -> Dbghelp {
231
231
}
232
232
233
233
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" ) ;
245
238
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) ;
247
247
}
248
248
249
249
#[ cfg( feature = "unloading" ) ]
@@ -333,5 +333,21 @@ pub unsafe fn super_special_reinit_of_dbghelp() {
333
333
return ;
334
334
}
335
335
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
+
336
352
* instance = Some ( unsafe { init ( true ) } ) ;
337
353
}
0 commit comments