Commit 6a859fb0 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: Move PE module loading to Unicode.

parent bcc19133
......@@ -477,11 +477,11 @@ extern BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup);
/* pe_module.c */
extern BOOL pe_load_nt_header(HANDLE hProc, DWORD base, IMAGE_NT_HEADERS* nth);
extern struct module*
pe_load_module(struct process* pcs, const char* name,
pe_load_module(struct process* pcs, const WCHAR* name,
HANDLE hFile, DWORD base, DWORD size);
extern struct module*
pe_load_module_from_pcs(struct process* pcs, const char* name,
const char* mod_name, DWORD base, DWORD size);
pe_load_module_from_pcs(struct process* pcs, const WCHAR* name,
const WCHAR* mod_name, DWORD base, DWORD size);
extern BOOL pe_load_debug_info(const struct process* pcs,
struct module* module);
/* source.c */
......
......@@ -517,21 +517,21 @@ DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageNam
if (module_is_elf_container_loaded(pcs, wImageName, wModuleName))
{
/* force the loading of DLL as builtin */
if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
if ((module = pe_load_module_from_pcs(pcs, wImageName, wModuleName,
BaseOfDll, SizeOfDll)))
goto done;
WARN("Couldn't locate %s\n", debugstr_w(wImageName));
return 0;
}
TRACE("Assuming %s as native DLL\n", debugstr_w(wImageName));
if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
if (!(module = pe_load_module(pcs, wImageName, hFile, BaseOfDll, SizeOfDll)))
{
if (module_get_type_by_name(ImageName) == DMT_ELF &&
(module = elf_load_module(pcs, ImageName, BaseOfDll)))
goto done;
FIXME("Should have successfully loaded debug information for image %s\n",
debugstr_w(wImageName));
if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
if ((module = pe_load_module_from_pcs(pcs, wImageName, wModuleName,
BaseOfDll, SizeOfDll)))
goto done;
WARN("Couldn't locate %s\n", debugstr_w(wImageName));
......
......@@ -2139,7 +2139,7 @@ static BOOL pdb_process_internal(const struct process* pcs,
/* Open and map() .PDB file */
if ((hFile = open_pdb_file(pcs, pdb_lookup)) == NULL ||
((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
((image = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) == NULL))
{
WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename);
......@@ -2269,7 +2269,7 @@ BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup)
if ((hFile = CreateFileA(pdb_lookup->filename, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE ||
((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
((image = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) == NULL))
{
WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename);
......
......@@ -103,7 +103,7 @@ static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
if (SymFindFileInPath(pcs->handle, NULL, dbg_name, NULL, 0, 0, 0, tmp, dbg_match, NULL) &&
(hFile = CreateFileA(tmp, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE &&
((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
((dbg_mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
{
hdr = (const IMAGE_SEPARATE_DEBUG_HEADER*)dbg_mapping;
......@@ -323,38 +323,32 @@ BOOL pe_load_debug_info(const struct process* pcs, struct module* module)
* pe_load_module
*
*/
struct module* pe_load_module(struct process* pcs, const char* name,
struct module* pe_load_module(struct process* pcs, const WCHAR* name,
HANDLE hFile, DWORD base, DWORD size)
{
struct module* module = NULL;
BOOL opened = FALSE;
HANDLE hMap;
void* mapping;
char loaded_name[MAX_PATH];
WCHAR loaded_name[MAX_PATH];
loaded_name[0] = '\0';
if (!hFile)
{
unsigned len = WideCharToMultiByte(CP_ACP,0, pcs->search_path, -1, NULL, 0, NULL, NULL);
char* sp;
if (!name)
{
/* FIXME SetLastError */
return NULL;
}
sp = HeapAlloc(GetProcessHeap(), 0, len);
if (!sp) return FALSE;
WideCharToMultiByte(CP_ACP,0, pcs->search_path, -1, sp, len, NULL, NULL);
if ((hFile = FindExecutableImage(name, sp, loaded_name)) == NULL)
if ((hFile = FindExecutableImageExW(name, pcs->search_path, loaded_name, NULL, NULL)) == NULL)
return NULL;
opened = TRUE;
}
else if (name) strcpy(loaded_name, name);
else if (name) strcpyW(loaded_name, name);
else if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
FIXME("Trouble ahead (no module name passed in deferred mode)\n");
if (!(module = module_find_by_nameA(pcs, loaded_name, DMT_PE)) &&
if (!(module = module_find_by_name(pcs, loaded_name, DMT_PE)) &&
(hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
{
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
......@@ -366,7 +360,7 @@ struct module* pe_load_module(struct process* pcs, const char* name,
if (!base) base = nth->OptionalHeader.ImageBase;
if (!size) size = nth->OptionalHeader.SizeOfImage;
module = module_newA(pcs, loaded_name, DMT_PE, FALSE, base, size,
module = module_new(pcs, loaded_name, DMT_PE, FALSE, base, size,
nth->FileHeader.TimeDateStamp,
nth->OptionalHeader.CheckSum);
if (module)
......@@ -405,17 +399,17 @@ BOOL pe_load_nt_header(HANDLE hProc, DWORD base, IMAGE_NT_HEADERS* nth)
* pe_load_module_from_pcs
*
*/
struct module* pe_load_module_from_pcs(struct process* pcs, const char* name,
const char* mod_name, DWORD base, DWORD size)
struct module* pe_load_module_from_pcs(struct process* pcs, const WCHAR* name,
const WCHAR* mod_name, DWORD base, DWORD size)
{
struct module* module;
const char* ptr;
const WCHAR* ptr;
if ((module = module_find_by_nameA(pcs, name, DMT_PE))) return module;
if ((module = module_find_by_name(pcs, name, DMT_PE))) return module;
if (mod_name) ptr = mod_name;
else
{
for (ptr = name + strlen(name) - 1; ptr >= name; ptr--)
for (ptr = name + strlenW(name) - 1; ptr >= name; ptr--)
{
if (*ptr == '/' || *ptr == '\\')
{
......@@ -424,7 +418,7 @@ struct module* pe_load_module_from_pcs(struct process* pcs, const char* name,
}
}
}
if (ptr && (module = module_find_by_nameA(pcs, ptr, DMT_PE))) return module;
if (ptr && (module = module_find_by_name(pcs, ptr, DMT_PE))) return module;
if (base)
{
if (pcs->dbg_hdr_addr)
......@@ -434,12 +428,12 @@ struct module* pe_load_module_from_pcs(struct process* pcs, const char* name,
if (pe_load_nt_header(pcs->handle, base, &nth))
{
if (!size) size = nth.OptionalHeader.SizeOfImage;
module = module_newA(pcs, name, DMT_PE, FALSE, base, size,
module = module_new(pcs, name, DMT_PE, FALSE, base, size,
nth.FileHeader.TimeDateStamp,
nth.OptionalHeader.CheckSum);
}
} else if (size)
module = module_newA(pcs, name, DMT_PE, FALSE, base, size,
module = module_new(pcs, name, DMT_PE, FALSE, base, size,
0 /* FIXME */, 0 /* FIXME */);
}
return module;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment