dbghelp: Add helper to initialize a module_pair.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Eric Pouech 2021-10-13 15:17:33 +02:00 committed by Alexandre Julliard
parent eded75f8d2
commit 099a8bbfd3
6 changed files with 20 additions and 49 deletions

View File

@ -629,6 +629,8 @@ extern const WCHAR S_WineLoaderW[] DECLSPEC_HIDDEN;
extern const WCHAR S_SlashW[] DECLSPEC_HIDDEN;
extern const struct loader_ops no_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;

View File

@ -3652,10 +3652,7 @@ BOOL dwarf2_virtual_unwind(struct cpu_stack_walk *csw, ULONG_PTR ip,
struct module_pair pair;
struct frame_info info;
if (!(pair.pcs = process_find_by_handle(csw->hProcess)) ||
!(pair.requested = module_find_by_addr(pair.pcs, ip, DMT_UNKNOWN)) ||
!module_get_debug(&pair))
return FALSE;
if (!module_init_pair(&pair, csw->hProcess, ip)) return FALSE;
if (!dwarf2_fetch_frame_info(pair.effective, csw->cpu, ip, &info)) return FALSE;
/* if at very beginning of function, return and use default unwinder */

View File

@ -262,6 +262,13 @@ struct module* module_new(struct process* pcs, const WCHAR* name,
return module;
}
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);
return module_get_debug(pair);
}
/***********************************************************************
* module_find_by_nameW
*

View File

@ -3199,10 +3199,7 @@ BOOL pdb_virtual_unwind(struct cpu_stack_walk *csw, DWORD_PTR ip,
char* strbase;
BOOL ret = TRUE;
if (!(pair.pcs = process_find_by_handle(csw->hProcess)) ||
!(pair.requested = module_find_by_addr(pair.pcs, ip, DMT_UNKNOWN)) ||
!module_get_debug(&pair))
return FALSE;
if (!module_init_pair(&pair, csw->hProcess, ip)) return FALSE;
if (!pair.effective->format_info[DFI_PDB]) return FALSE;
pdb_info = pair.effective->format_info[DFI_PDB]->u.pdb_info;
TRACE("searching %lx => %lx\n", ip, ip - (DWORD_PTR)pair.effective->module.BaseOfImage);

View File

@ -1363,10 +1363,7 @@ BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address,
struct module_pair pair;
struct symt_ht* sym;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, Address, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, Address)) return FALSE;
if ((sym = symt_find_nearest(pair.effective, Address)) == NULL) return FALSE;
symt_fill_sym_info(&pair, NULL, &sym->symt, Symbol);
@ -1717,10 +1714,7 @@ static BOOL get_line_from_addr(HANDLE hProcess, DWORD64 addr,
struct symt_ht* symt;
struct symt_function* func;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, addr, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
if ((symt = symt_find_nearest(pair.effective, addr)) == NULL) return FALSE;
if (symt->symt.tag != SymTagFunction) return FALSE;
@ -1862,10 +1856,7 @@ static BOOL symt_get_func_line_prev(HANDLE hProcess, struct internal_line_t* int
struct line_info* li;
struct line_info* srcli;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, addr, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
if (key == NULL) return FALSE;
@ -1944,10 +1935,7 @@ static BOOL symt_get_func_line_next(HANDLE hProcess, struct internal_line_t* int
struct line_info* srcli;
if (key == NULL) return FALSE;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, addr, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
/* search current source file */
for (srcli = key; !srcli->is_source_file; srcli--);
@ -2344,10 +2332,7 @@ BOOL WINAPI SymAddSymbol(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR name,
TRACE("(%p %s %s %u)\n", hProcess, wine_dbgstr_a(name), wine_dbgstr_longlong(addr), size);
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, BaseOfDll)) return FALSE;
return symt_new_custom(pair.effective, name, addr, size) != NULL;
}
@ -2400,11 +2385,8 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
if (!cb) return FALSE;
if (!(dbghelp_options & SYMOPT_LOAD_LINES)) return TRUE;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
if (!module_init_pair(&pair, hProcess, base)) return FALSE;
if (compiland) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland);
pair.requested = module_find_by_addr(pair.pcs, base, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!(srcmask = file_regex(srcfile))) return FALSE;
sci.SizeOfStruct = sizeof(sci);

View File

@ -483,9 +483,7 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
UserContext);
if (!(pair.pcs = process_find_by_handle(hProcess))) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, BaseOfDll)) return FALSE;
sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
@ -1007,16 +1005,7 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
{
struct module_pair pair;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
if (!module_get_debug(&pair))
{
FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
return FALSE;
}
if (!module_init_pair(&pair, hProcess, ModBase)) return FALSE;
return symt_get_info(pair.effective, symt_index2ptr(pair.effective, TypeId), GetType, pInfo);
}
@ -1031,10 +1020,7 @@ BOOL WINAPI SymGetTypeFromName(HANDLE hProcess, ULONG64 BaseOfDll,
struct symt* type;
DWORD64 size;
pair.pcs = process_find_by_handle(hProcess);
if (!pair.pcs) return FALSE;
pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
if (!module_get_debug(&pair)) return FALSE;
if (!module_init_pair(&pair, hProcess, BaseOfDll)) return FALSE;
type = symt_find_type_by_name(pair.effective, SymTagNull, Name);
if (!type) return FALSE;
Symbol->Index = Symbol->TypeIndex = symt_ptr2index(pair.effective, type);