Commit a2e65f13 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: Keep the file map around for every PE module, so that we can access…

dbghelp: Keep the file map around for every PE module, so that we can access image whenever we like to.
parent cbff4f06
...@@ -325,6 +325,7 @@ struct module ...@@ -325,6 +325,7 @@ struct module
/* specific information for debug types */ /* specific information for debug types */
struct elf_module_info* elf_info; struct elf_module_info* elf_info;
struct pe_module_info* pe_info;
struct dwarf2_module_info_s*dwarf2_info; struct dwarf2_module_info_s*dwarf2_info;
void (*module_remove)(struct process* pcs, struct module* module); void (*module_remove)(struct process* pcs, struct module* module);
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp); WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
struct pe_module_info
{
struct image_file_map fmap;
};
static void* pe_map_full(struct image_file_map* fmap, IMAGE_NT_HEADERS** nth) static void* pe_map_full(struct image_file_map* fmap, IMAGE_NT_HEADERS** nth)
{ {
if (!fmap->u.pe.full_map) if (!fmap->u.pe.full_map)
...@@ -236,9 +241,16 @@ static void pe_unmap_file(struct image_file_map* fmap) ...@@ -236,9 +241,16 @@ static void pe_unmap_file(struct image_file_map* fmap)
HeapFree(GetProcessHeap(), 0, fmap->u.pe.sect); HeapFree(GetProcessHeap(), 0, fmap->u.pe.sect);
HeapFree(GetProcessHeap(), 0, (void*)fmap->u.pe.strtable); /* FIXME ugly (see pe_map_file) */ HeapFree(GetProcessHeap(), 0, (void*)fmap->u.pe.strtable); /* FIXME ugly (see pe_map_file) */
CloseHandle(fmap->u.pe.hMap); CloseHandle(fmap->u.pe.hMap);
fmap->u.pe.hMap = NULL;
} }
} }
static void pe_module_remove(struct process* pcs, struct module* module)
{
pe_unmap_file(&module->pe_info->fmap);
HeapFree(GetProcessHeap(), 0, module->pe_info);
}
/****************************************************************** /******************************************************************
* pe_locate_with_coff_symbol_table * pe_locate_with_coff_symbol_table
* *
...@@ -247,8 +259,9 @@ static void pe_unmap_file(struct image_file_map* fmap) ...@@ -247,8 +259,9 @@ static void pe_unmap_file(struct image_file_map* fmap)
* Mingw32 requires this for stabs debug information as address for global variables isn't filled in * Mingw32 requires this for stabs debug information as address for global variables isn't filled in
* (this is similar to what is done in elf_module.c when using the .symtab ELF section) * (this is similar to what is done in elf_module.c when using the .symtab ELF section)
*/ */
static BOOL pe_locate_with_coff_symbol_table(struct module* module, struct image_file_map* fmap) static BOOL pe_locate_with_coff_symbol_table(struct module* module)
{ {
struct image_file_map* fmap = &module->pe_info->fmap;
const IMAGE_SYMBOL* isym; const IMAGE_SYMBOL* isym;
int i, numsym, naux; int i, numsym, naux;
char tmp[9]; char tmp[9];
...@@ -306,8 +319,9 @@ static BOOL pe_locate_with_coff_symbol_table(struct module* module, struct image ...@@ -306,8 +319,9 @@ static BOOL pe_locate_with_coff_symbol_table(struct module* module, struct image
* *
* Load public symbols out of the COFF symbol table (if any). * Load public symbols out of the COFF symbol table (if any).
*/ */
static BOOL pe_load_coff_symbol_table(struct module* module, struct image_file_map* fmap) static BOOL pe_load_coff_symbol_table(struct module* module)
{ {
struct image_file_map* fmap = &module->pe_info->fmap;
const IMAGE_SYMBOL* isym; const IMAGE_SYMBOL* isym;
int i, numsym, naux; int i, numsym, naux;
const char* strtable; const char* strtable;
...@@ -382,8 +396,9 @@ static inline DWORD pe_get_sect_size(IMAGE_SECTION_HEADER* sect) ...@@ -382,8 +396,9 @@ static inline DWORD pe_get_sect_size(IMAGE_SECTION_HEADER* sect)
* look for stabs information in PE header (it's how the mingw compiler provides * look for stabs information in PE header (it's how the mingw compiler provides
* its debugging information) * its debugging information)
*/ */
static BOOL pe_load_stabs(const struct process* pcs, struct module* module, struct image_file_map* fmap) static BOOL pe_load_stabs(const struct process* pcs, struct module* module)
{ {
struct image_file_map* fmap = &module->pe_info->fmap;
struct image_section_map sect_stabs, sect_stabstr; struct image_section_map sect_stabs, sect_stabstr;
BOOL ret = FALSE; BOOL ret = FALSE;
...@@ -404,7 +419,7 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module, stru ...@@ -404,7 +419,7 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module, stru
} }
image_unmap_section(&sect_stabs); image_unmap_section(&sect_stabs);
image_unmap_section(&sect_stabstr); image_unmap_section(&sect_stabstr);
if (ret) pe_locate_with_coff_symbol_table(module, fmap); if (ret) pe_locate_with_coff_symbol_table(module);
} }
TRACE("%s the STABS debug info\n", ret ? "successfully loaded" : "failed to load"); TRACE("%s the STABS debug info\n", ret ? "successfully loaded" : "failed to load");
...@@ -417,9 +432,9 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module, stru ...@@ -417,9 +432,9 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module, stru
* look for dwarf information in PE header (it's also a way for the mingw compiler * look for dwarf information in PE header (it's also a way for the mingw compiler
* to provide its debugging information) * to provide its debugging information)
*/ */
static BOOL pe_load_dwarf(const struct process* pcs, struct module* module, static BOOL pe_load_dwarf(const struct process* pcs, struct module* module)
struct image_file_map* fmap)
{ {
struct image_file_map* fmap = &module->pe_info->fmap;
struct image_section_map sect_debuginfo, sect_debugstr, sect_debugabbrev, sect_debugline, sect_debugloc; struct image_section_map sect_debuginfo, sect_debugstr, sect_debugabbrev, sect_debugline, sect_debugloc;
BOOL ret = FALSE; BOOL ret = FALSE;
...@@ -516,8 +531,9 @@ static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module, ...@@ -516,8 +531,9 @@ static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
* *
* Process MSC debug information in PE file. * Process MSC debug information in PE file.
*/ */
static BOOL pe_load_msc_debug_info(const struct process* pcs, struct module* module, struct image_file_map* fmap) static BOOL pe_load_msc_debug_info(const struct process* pcs, struct module* module)
{ {
struct image_file_map* fmap = &module->pe_info->fmap;
BOOL ret = FALSE; BOOL ret = FALSE;
const IMAGE_DATA_DIRECTORY* dir; const IMAGE_DATA_DIRECTORY* dir;
const IMAGE_DEBUG_DIRECTORY*dbg = NULL; const IMAGE_DEBUG_DIRECTORY*dbg = NULL;
...@@ -566,8 +582,9 @@ done: ...@@ -566,8 +582,9 @@ done:
/*********************************************************************** /***********************************************************************
* pe_load_export_debug_info * pe_load_export_debug_info
*/ */
static BOOL pe_load_export_debug_info(const struct process* pcs, struct module* module, struct image_file_map* fmap) static BOOL pe_load_export_debug_info(const struct process* pcs, struct module* module)
{ {
struct image_file_map* fmap = &module->pe_info->fmap;
unsigned int i; unsigned int i;
const IMAGE_EXPORT_DIRECTORY* exports; const IMAGE_EXPORT_DIRECTORY* exports;
DWORD base = module->module.BaseOfImage; DWORD base = module->module.BaseOfImage;
...@@ -649,48 +666,28 @@ static BOOL pe_load_export_debug_info(const struct process* pcs, struct module* ...@@ -649,48 +666,28 @@ static BOOL pe_load_export_debug_info(const struct process* pcs, struct module*
* pe_load_debug_info * pe_load_debug_info
* *
*/ */
BOOL pe_load_debug_info_internal(const struct process* pcs, struct module* module, BOOL pe_load_debug_info(const struct process* pcs, struct module* module)
struct image_file_map* fmap)
{ {
BOOL ret = FALSE; BOOL ret = FALSE;
if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY)) if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY))
{ {
ret = pe_load_stabs(pcs, module, fmap) || ret = pe_load_stabs(pcs, module) ||
pe_load_dwarf(pcs, module, fmap) || pe_load_dwarf(pcs, module) ||
pe_load_msc_debug_info(pcs, module, fmap) || pe_load_msc_debug_info(pcs, module) ||
pe_load_coff_symbol_table(module, fmap); pe_load_coff_symbol_table(module);
/* if we still have no debug info (we could only get SymExport at this /* if we still have no debug info (we could only get SymExport at this
* point), then do the SymExport except if we have an ELF container, * point), then do the SymExport except if we have an ELF container,
* in which case we'll rely on the export's on the ELF side * in which case we'll rely on the export's on the ELF side
*/ */
} }
/* FIXME shouldn't we check that? if (!module_get_debug(pcs, module))l */ /* FIXME shouldn't we check that? if (!module_get_debug(pcs, module)) */
if (pe_load_export_debug_info(pcs, module, fmap) && !ret) if (pe_load_export_debug_info(pcs, module) && !ret)
ret = TRUE; ret = TRUE;
return ret; return ret;
} }
BOOL pe_load_debug_info(const struct process* pcs, struct module* module)
{
BOOL ret = FALSE;
HANDLE hFile;
struct image_file_map fmap;
hFile = CreateFileW(module->module.LoadedImageName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return FALSE;
if (pe_map_file(hFile, &fmap, DMT_PE))
{
ret = pe_load_debug_info_internal(pcs, module, &fmap);
pe_unmap_file(&fmap);
}
CloseHandle(hFile);
return ret;
}
/****************************************************************** /******************************************************************
* pe_load_native_module * pe_load_native_module
* *
...@@ -700,7 +697,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name, ...@@ -700,7 +697,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
{ {
struct module* module = NULL; struct module* module = NULL;
BOOL opened = FALSE; BOOL opened = FALSE;
struct image_file_map fmap; struct pe_module_info* module_info;
WCHAR loaded_name[MAX_PATH]; WCHAR loaded_name[MAX_PATH];
loaded_name[0] = '\0'; loaded_name[0] = '\0';
...@@ -715,25 +712,33 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name, ...@@ -715,25 +712,33 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
else if (name) strcpyW(loaded_name, name); else if (name) strcpyW(loaded_name, name);
else if (dbghelp_options & SYMOPT_DEFERRED_LOADS) else if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
FIXME("Trouble ahead (no module name passed in deferred mode)\n"); FIXME("Trouble ahead (no module name passed in deferred mode)\n");
if (!(module_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*module_info))))
if (pe_map_file(hFile, &fmap, DMT_PE)) return NULL;
if (pe_map_file(hFile, &module_info->fmap, DMT_PE))
{ {
if (!base) base = fmap.u.pe.ntheader.OptionalHeader.ImageBase; if (!base) base = module_info->fmap.u.pe.ntheader.OptionalHeader.ImageBase;
if (!size) size = fmap.u.pe.ntheader.OptionalHeader.SizeOfImage; if (!size) size = module_info->fmap.u.pe.ntheader.OptionalHeader.SizeOfImage;
module = module_new(pcs, loaded_name, DMT_PE, FALSE, base, size, module = module_new(pcs, loaded_name, DMT_PE, FALSE, base, size,
fmap.u.pe.ntheader.FileHeader.TimeDateStamp, module_info->fmap.u.pe.ntheader.FileHeader.TimeDateStamp,
fmap.u.pe.ntheader.OptionalHeader.CheckSum); module_info->fmap.u.pe.ntheader.OptionalHeader.CheckSum);
if (module) if (module)
{ {
module->pe_info = module_info;
module->module_remove = pe_module_remove;
if (dbghelp_options & SYMOPT_DEFERRED_LOADS) if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
module->module.SymType = SymDeferred; module->module.SymType = SymDeferred;
else else
pe_load_debug_info_internal(pcs, module, &fmap); pe_load_debug_info(pcs, module);
}
else
{
ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
pe_unmap_file(&module_info->fmap);
} }
else ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
pe_unmap_file(&fmap);
} }
if (!module) HeapFree(GetProcessHeap(), 0, module_info);
if (opened) CloseHandle(hFile); if (opened) CloseHandle(hFile);
return module; 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