[PATCH] dbghelp: search for debugfiles in modulepath too.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] dbghelp: search for debugfiles in modulepath too.

Andreas Maier
Debug symbols (like PDB, ...) could not be found if the direcory of
the module and application differs. Applying this patch they will
be found.
Dbghelp searches the module path too. (See MS docs).

Signed-off-by: Andreas Maier <[hidden email]>
---
 dlls/dbghelp/dbghelp_private.h |  6 +++---
 dlls/dbghelp/msc.c             |  4 ++--
 dlls/dbghelp/path.c            | 34 +++++++++++++++++++++++++++++++---
 dlls/dbghelp/pe_module.c       |  2 +-
 4 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 76f5d00830..98f418df79 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -649,9 +649,9 @@ extern BOOL         pdb_virtual_unwind(struct cpu_stack_walk* csw, DWORD_PTR ip,
                                        CONTEXT* context, struct pdb_cmd_pair* cpair) DECLSPEC_HIDDEN;
 
 /* path.c */
-extern BOOL         path_find_symbol_file(const struct process* pcs, PCSTR full_path,
-                                          const GUID* guid, DWORD dw1, DWORD dw2, PSTR buffer,
-                                          BOOL* is_unmatched) DECLSPEC_HIDDEN;
+extern BOOL         path_find_symbol_file(const struct process* pcs, const struct module* module,
+                                          PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2,
+                                          PSTR buffer, BOOL* is_unmatched) DECLSPEC_HIDDEN;
 
 /* pe_module.c */
 extern BOOL         pe_load_nt_header(HANDLE hProc, DWORD64 base, IMAGE_NT_HEADERS* nth) DECLSPEC_HIDDEN;
diff --git a/dlls/dbghelp/msc.c b/dlls/dbghelp/msc.c
index cc1259df18..0e4e00f334 100644
--- a/dlls/dbghelp/msc.c
+++ b/dlls/dbghelp/msc.c
@@ -2450,11 +2450,11 @@ static HANDLE map_pdb_file(const struct process* pcs,
     switch (lookup->kind)
     {
     case PDB_JG:
-        ret = path_find_symbol_file(pcs, lookup->filename, NULL, lookup->timestamp,
+        ret = path_find_symbol_file(pcs, module, lookup->filename, NULL, lookup->timestamp,
                                     lookup->age, dbg_file_path, &module->module.PdbUnmatched);
         break;
     case PDB_DS:
-        ret = path_find_symbol_file(pcs, lookup->filename, &lookup->guid, 0,
+        ret = path_find_symbol_file(pcs, module, lookup->filename, &lookup->guid, 0,
                                     lookup->age, dbg_file_path, &module->module.PdbUnmatched);
         break;
     }
diff --git a/dlls/dbghelp/path.c b/dlls/dbghelp/path.c
index 8c74426eec..2e4d98233f 100644
--- a/dlls/dbghelp/path.c
+++ b/dlls/dbghelp/path.c
@@ -49,6 +49,17 @@ static inline const WCHAR* file_nameW(const WCHAR* str)
     return p + 1;
 }
 
+static inline void file_pathW(const WCHAR* srcFileNameW,
+    WCHAR* dstFilePathW)
+{
+    int len;
+
+    for (len = strlenW(srcFileNameW) - 1; (len > 0) && (!is_sepW(srcFileNameW[len])); len--);
+
+    lstrcpynW(dstFilePathW, srcFileNameW, len);
+    dstFilePathW[len] = L'\0';
+}
+
 /******************************************************************
  * FindDebugInfoFile (DBGHELP.@)
  *
@@ -612,9 +623,9 @@ static BOOL CALLBACK module_find_cb(PCWSTR buffer, PVOID user)
     return mf->matched == 2;
 }
 
-BOOL path_find_symbol_file(const struct process* pcs, PCSTR full_path,
-                           const GUID* guid, DWORD dw1, DWORD dw2, PSTR buffer,
-                           BOOL* is_unmatched)
+BOOL path_find_symbol_file(const struct process* pcs, const struct module* module,
+                           PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2,
+                           PSTR buffer, BOOL* is_unmatched)
 {
     struct module_find  mf;
     WCHAR               full_pathW[MAX_PATH];
@@ -643,6 +654,23 @@ BOOL path_find_symbol_file(const struct process* pcs, PCSTR full_path,
         return TRUE;
     }
 
+    /* FIXME: Use Environment-Variables (see MS docs)
+                 _NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH
+       FIXME: Implement "Standard Path Elements" (Path) ... (see MS docs)
+              do a search for (every?) path-element like this ...
+              <path>
+              <path>\dll
+              <path>\symbols\dll
+              (dll may be exe, or sys depending on the file extension)   */
+
+    /* 2. check module-path */
+    file_pathW(module->module.LoadedImageName, tmp);
+    if (do_searchW(filename, tmp, FALSE, module_find_cb, &mf))
+    {
+        WideCharToMultiByte(CP_ACP, 0, tmp, -1, buffer, MAX_PATH, NULL, NULL);
+        return TRUE;
+    }
+
     while (searchPath)
     {
         ptr = strchrW(searchPath, ';');
diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c
index e7255f89ba..ea2a8262d2 100644
--- a/dlls/dbghelp/pe_module.c
+++ b/dlls/dbghelp/pe_module.c
@@ -531,7 +531,7 @@ static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
 
     TRACE("Processing DBG file %s\n", debugstr_a(dbg_name));
 
-    if (path_find_symbol_file(pcs, dbg_name, NULL, timestamp, 0, tmp, &module->module.DbgUnmatched) &&
+    if (path_find_symbol_file(pcs, module, dbg_name, NULL, timestamp, 0, tmp, &module->module.DbgUnmatched) &&
         (hFile = CreateFileA(tmp, GENERIC_READ, FILE_SHARE_READ, NULL,
                              OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE &&
         ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
--
2.11.0