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

dbghelp: Simplified module_find_by_addr().

parent e1064850
......@@ -962,7 +962,7 @@ static BOOL x86_64_fetch_minidump_module(struct dump_context* dc, unsigned index
ULONG size;
if (!(pcs = process_find_by_handle(dc->process->handle)) ||
!(module = module_find_by_addr(pcs, dc->modules[index].base, DMT_UNKNOWN)))
!(module = module_find_by_addr(pcs, dc->modules[index].base)))
return FALSE;
rtf = (const RUNTIME_FUNCTION*)pe_map_directory(module, IMAGE_DIRECTORY_ENTRY_EXCEPTION, &size);
if (rtf)
......
......@@ -398,7 +398,6 @@ struct symt_udt
enum module_type
{
DMT_UNKNOWN, /* for lookup, not actually used for a module */
DMT_ELF, /* a real ELF shared module */
DMT_PE, /* a native or builtin PE module */
DMT_MACHO, /* a real Mach-O shared module */
......@@ -732,8 +731,7 @@ extern const struct loader_ops empty_loader_ops DECLSPEC_HIDDEN;
extern BOOL module_init_pair(struct module_pair* pair, HANDLE hProcess,
DWORD64 addr) DECLSPEC_HIDDEN;
extern struct module*
module_find_by_addr(const struct process* pcs, DWORD64 addr,
enum module_type type) DECLSPEC_HIDDEN;
module_find_by_addr(const struct process* pcs, DWORD64 addr) DECLSPEC_HIDDEN;
extern struct module*
module_find_by_nameW(const struct process* pcs,
const WCHAR* name) DECLSPEC_HIDDEN;
......
......@@ -262,7 +262,7 @@ struct module* module_new(struct process* pcs, const WCHAR* name,
BOOL module_init_pair(struct module_pair* pair, HANDLE hProcess, DWORD64 addr)
{
if (!(pair->pcs = process_find_by_handle(hProcess))) return FALSE;
pair->requested = module_find_by_addr(pair->pcs, addr, DMT_UNKNOWN);
pair->requested = module_find_by_addr(pair->pcs, addr);
return module_get_debug(pair);
}
......@@ -416,27 +416,23 @@ BOOL module_get_debug(struct module_pair* pair)
* either the addr where module is loaded, or any address inside the
* module
*/
struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr,
enum module_type type)
struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr)
{
struct module* module;
if (type == DMT_UNKNOWN)
for (module = pcs->lmodules; module; module = module->next)
{
if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
(module = module_find_by_addr(pcs, addr, DMT_ELF)) ||
(module = module_find_by_addr(pcs, addr, DMT_MACHO)))
if (module->type == DMT_PE && addr >= module->module.BaseOfImage &&
addr < module->module.BaseOfImage + module->module.ImageSize)
return module;
}
else
{
for (module = pcs->lmodules; module; module = module->next)
{
if (type == module->type && addr >= module->module.BaseOfImage &&
if ((module->type == DMT_ELF || module->type == DMT_MACHO) &&
addr >= module->module.BaseOfImage &&
addr < module->module.BaseOfImage + module->module.ImageSize)
return module;
}
}
SetLastError(ERROR_MOD_NOT_FOUND);
return module;
}
......@@ -1094,7 +1090,7 @@ BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE;
module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
module = module_find_by_addr(pcs, BaseOfDll);
if (!module) return FALSE;
module_remove(pcs, module);
return TRUE;
......@@ -1498,7 +1494,7 @@ BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
if (!pcs) return FALSE;
if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
module = module_find_by_addr(pcs, dwAddr);
if (!module) return FALSE;
miw64 = module->module;
......@@ -1537,7 +1533,7 @@ DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
struct module* module;
if (!pcs) return 0;
module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
module = module_find_by_addr(pcs, dwAddr);
if (!module) return 0;
return module->module.BaseOfImage;
}
......@@ -1595,7 +1591,7 @@ PVOID WINAPI SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase)
struct module* module;
if (!pcs) return NULL;
module = module_find_by_addr(pcs, AddrBase, DMT_UNKNOWN);
module = module_find_by_addr(pcs, AddrBase);
if (!module || !module->cpu->find_runtime_function) return NULL;
return module->cpu->find_runtime_function(module, AddrBase);
......
......@@ -152,7 +152,7 @@ BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask,
if (ModBase)
{
pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
pair.requested = module_find_by_addr(pair.pcs, ModBase);
if (!module_get_debug(&pair)) return FALSE;
}
else
......
......@@ -1148,7 +1148,7 @@ static BOOL symt_enum_locals(struct process* pcs, const WCHAR* mask,
se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
pair.pcs = pcs;
pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc, DMT_UNKNOWN);
pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc);
if (!module_get_debug(&pair)) return FALSE;
if (symt_check_tag(pcs->localscope_symt, SymTagFunction) ||
......@@ -1318,7 +1318,7 @@ static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR Mask,
HeapFree(GetProcessHeap(), 0, mod);
return TRUE;
}
pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
pair.requested = module_find_by_addr(pair.pcs, BaseOfDll);
if (!module_get_debug(&pair))
return FALSE;
......@@ -1624,7 +1624,7 @@ BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
/* search first in local context */
pair.pcs = pcs;
pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc, DMT_UNKNOWN);
pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc);
if (module_get_debug(&pair) &&
(symt_check_tag(pcs->localscope_symt, SymTagFunction) ||
symt_check_tag(pcs->localscope_symt, SymTagInlineSite)))
......
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