Eric Pouech : dbghelp: Move debug info loading out of image backends into SymLoadModuleEx().

Alexandre Julliard julliard at winehq.org
Tue Nov 16 16:32:28 CST 2021


Module: wine
Branch: master
Commit: ced12a1a3aca214c64887e1dc65df67015015394
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ced12a1a3aca214c64887e1dc65df67015015394

Author: Eric Pouech <eric.pouech at gmail.com>
Date:   Tue Nov 16 17:47:30 2021 +0100

dbghelp: Move debug info loading out of image backends into SymLoadModuleEx().

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dbghelp/elf_module.c   |  7 +----
 dlls/dbghelp/macho_module.c |  4 ---
 dlls/dbghelp/module.c       | 74 ++++++++++++++++++++++++---------------------
 dlls/dbghelp/pe_module.c    |  9 +-----
 4 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index dbae4db40d2..def8b444e4e 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -1261,15 +1261,10 @@ static BOOL elf_load_file_from_fmap(struct process* pcs, const WCHAR* filename,
 
         elf_module_info->file_map = *fmap;
         elf_reset_file_map(fmap);
-        if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
-        {
-            elf_info->module->module.SymType = SymDeferred;
-            ret = TRUE;
-        }
-        else ret = elf_load_debug_info(pcs, elf_info->module);
 
         elf_module_info->elf_mark = 1;
         elf_module_info->elf_loader = 0;
+        ret = TRUE;
     } else ret = TRUE;
 
     if (elf_info->flags & ELF_INFO_NAME)
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c
index c4a19b63de0..7d0d45b3a5a 100644
--- a/dlls/dbghelp/macho_module.c
+++ b/dlls/dbghelp/macho_module.c
@@ -1495,10 +1495,6 @@ static BOOL macho_load_file(struct process* pcs, const WCHAR* filename,
 
         macho_module_info->file_map = fmap;
         reset_file_map(&fmap);
-        if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
-            macho_info->module->module.SymType = SymDeferred;
-        else if (!macho_load_debug_info(pcs, macho_info->module))
-            ret = FALSE;
 
         macho_info->module->format_info[DFI_MACHO]->u.macho_info->in_use = 1;
         macho_info->module->format_info[DFI_MACHO]->u.macho_info->is_loader = 0;
diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index 8f8820f90a9..5c439dd1d3c 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -200,7 +200,7 @@ struct module* module_new(struct process* pcs, const WCHAR* name,
     module_set_module(module, name);
     module->module.ImageName[0] = '\0';
     lstrcpynW(module->module.LoadedImageName, name, ARRAY_SIZE(module->module.LoadedImageName));
-    module->module.SymType = SymNone;
+    module->module.SymType = SymDeferred;
     module->module.NumSyms = 0;
     module->module.TimeDateStamp = stamp;
     module->module.CheckSum = checksum;
@@ -350,54 +350,59 @@ struct module* module_get_containee(const struct process* pcs, const struct modu
     return NULL;
 }
 
-/******************************************************************
- *		module_get_debug
- *
- * get the debug information from a module:
- * - if the module's type is deferred, then force loading of debug info (and return
- *   the module itself)
- * - if the module has no debug info and has an ELF container, then return the ELF
- *   container (and also force the ELF container's debug info loading if deferred)
- * - otherwise return the module itself if it has some debug info
- */
-BOOL module_get_debug(struct module_pair* pair)
+BOOL module_load_debug(struct module* module)
 {
     IMAGEHLP_DEFERRED_SYMBOL_LOADW64    idslW64;
 
-    if (!pair->requested) return FALSE;
-    /* for a PE builtin, always get info from container */
-    if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
-        pair->effective = pair->requested;
     /* if deferred, force loading */
-    if (pair->effective->module.SymType == SymDeferred)
+    if (module->module.SymType == SymDeferred)
     {
         BOOL ret;
         
-        if (pair->effective->is_virtual) ret = FALSE;
-        else if (pair->effective->type == DMT_PE)
+        if (module->is_virtual) ret = FALSE;
+        else if (module->type == DMT_PE)
         {
             idslW64.SizeOfStruct = sizeof(idslW64);
-            idslW64.BaseOfImage = pair->effective->module.BaseOfImage;
-            idslW64.CheckSum = pair->effective->module.CheckSum;
-            idslW64.TimeDateStamp = pair->effective->module.TimeDateStamp;
-            memcpy(idslW64.FileName, pair->effective->module.ImageName,
-                   sizeof(pair->effective->module.ImageName));
+            idslW64.BaseOfImage = module->module.BaseOfImage;
+            idslW64.CheckSum = module->module.CheckSum;
+            idslW64.TimeDateStamp = module->module.TimeDateStamp;
+            memcpy(idslW64.FileName, module->module.ImageName,
+                   sizeof(module->module.ImageName));
             idslW64.Reparse = FALSE;
             idslW64.hFile = INVALID_HANDLE_VALUE;
 
-            pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idslW64);
-            ret = pe_load_debug_info(pair->pcs, pair->effective);
-            pcs_callback(pair->pcs,
+            pcs_callback(module->process, CBA_DEFERRED_SYMBOL_LOAD_START, &idslW64);
+            ret = pe_load_debug_info(module->process, module);
+            pcs_callback(module->process,
                          ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
                          &idslW64);
         }
-        else ret = pair->pcs->loader->load_debug_info(pair->pcs, pair->effective);
+        else ret = module->process->loader->load_debug_info(module->process, module);
 
-        if (!ret) pair->effective->module.SymType = SymNone;
-        assert(pair->effective->module.SymType != SymDeferred);
-        pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
+        if (!ret) module->module.SymType = SymNone;
+        assert(module->module.SymType != SymDeferred);
+        module->module.NumSyms = module->ht_symbols.num_elts;
     }
-    return pair->effective->module.SymType != SymNone;
+    return module->module.SymType != SymNone;
+}
+
+/******************************************************************
+ *		module_get_debug
+ *
+ * get the debug information from a module:
+ * - if the module's type is deferred, then force loading of debug info (and return
+ *   the module itself)
+ * - if the module has no debug info and has an ELF container, then return the ELF
+ *   container (and also force the ELF container's debug info loading if deferred)
+ * - otherwise return the module itself if it has some debug info
+ */
+BOOL module_get_debug(struct module_pair* pair)
+{
+    if (!pair->requested) return FALSE;
+    /* for a PE builtin, always get info from container */
+    if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
+        pair->effective = pair->requested;
+    return module_load_debug(pair->effective);
 }
 
 /***********************************************************************
@@ -966,7 +971,6 @@ DWORD64 WINAPI  SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageNam
         WARN("Couldn't locate %s\n", debugstr_w(wImageName));
         return 0;
     }
-    module->module.NumSyms = module->ht_symbols.num_elts;
     /* by default module_new fills module.ModuleName from a derivation
      * of LoadedImageName. Overwrite it, if we have better information
      */
@@ -974,7 +978,8 @@ DWORD64 WINAPI  SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageNam
         module_set_module(module, wModuleName);
     if (wImageName)
         lstrcpynW(module->module.ImageName, wImageName, ARRAY_SIZE(module->module.ImageName));
-
+    if ((dbghelp_options & SYMOPT_DEFERRED_LOADS) == 0)
+        module_load_debug(module);
     return module->module.BaseOfImage;
 }
 
@@ -1494,6 +1499,7 @@ static struct module* native_load_module(struct process* pcs, const WCHAR* name,
 
 static BOOL native_load_debug_info(struct process* process, struct module* module)
 {
+    module->module.SymType = SymNone;
     return FALSE;
 }
 
diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c
index 77ae122901a..e0266db0387 100644
--- a/dlls/dbghelp/pe_module.c
+++ b/dlls/dbghelp/pe_module.c
@@ -751,7 +751,7 @@ BOOL pe_load_debug_info(const struct process* pcs, struct module* module)
     /* FIXME shouldn't we check that? if (!module_get_debug(pcs, module)) */
     if (pe_load_export_debug_info(pcs, module) && !ret)
         ret = TRUE;
-
+    if (!ret) module->module.SymType = SymNone;
     return ret;
 }
 
@@ -797,8 +797,6 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
         opened = TRUE;
     }
     else if (name) lstrcpyW(loaded_name, name);
-    else if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
-        FIXME("Trouble ahead (no module name passed in deferred mode)\n");
     if (!(modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info))))
         return NULL;
     modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1);
@@ -824,12 +822,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
             modfmt->module = module;
             modfmt->remove = pe_module_remove;
             modfmt->loc_compute = NULL;
-
             module->format_info[DFI_PE] = modfmt;
-            if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
-                module->module.SymType = SymDeferred;
-            else
-                pe_load_debug_info(pcs, module);
             module->reloc_delta = base - PE_FROM_OPTHDR(&modfmt->u.pe_info->fmap, ImageBase);
         }
         else




More information about the wine-cvs mailing list