[PATCH 02/22] [DbgHelp]: modules' pair
Eric Pouech
eric.pouech at wanadoo.fr
Fri Nov 24 15:17:10 CST 2006
- added a process field to the modules' pair structure
- this makes the code simpler to read, a bit more efficient,
and furthermore it'll be needed in future patches
A+
---
dlls/dbghelp/dbghelp_private.h | 3 +-
dlls/dbghelp/module.c | 10 +++---
dlls/dbghelp/source.c | 22 ++++++-------
dlls/dbghelp/symbol.c | 66 +++++++++++++++++++++-------------------
dlls/dbghelp/type.c | 15 ++++-----
5 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 3d9647c..ee1f711 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -333,6 +333,7 @@ struct line_info
struct module_pair
{
+ struct process* pcs;
struct module* requested; /* in: to module_get_debug() */
struct module* effective; /* out: module with debug info */
};
@@ -389,7 +390,7 @@ extern struct module*
extern struct module*
module_find_by_name(const struct process* pcs,
const char* name, enum module_type type);
-extern BOOL module_get_debug(const struct process* pcs, struct module_pair*);
+extern BOOL module_get_debug(struct module_pair*);
extern struct module*
module_new(struct process* pcs, const char* name,
enum module_type type, BOOL virtual,
diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index ec3c70c..eecf66b 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -244,13 +244,13 @@ struct module* module_get_containee(cons
* container (and also force the ELF container's debug info loading if deferred)
* - otherwise return the module itself if it has some debug info
*/
-BOOL module_get_debug(const struct process* pcs, struct module_pair* pair)
+BOOL module_get_debug(struct module_pair* pair)
{
IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64;
if (!pair->requested) return FALSE;
/* for a PE builtin, always get info from container */
- if (!(pair->effective = module_get_container(pcs, pair->requested)))
+ if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
pair->effective = pair->requested;
/* if deferred, force loading */
if (pair->effective->module.SymType == SymDeferred)
@@ -272,9 +272,9 @@ BOOL module_get_debug(const struct proce
idsl64.Reparse = FALSE;
idsl64.hFile = INVALID_HANDLE_VALUE;
- pcs_callback(pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
- ret = pe_load_debug_info(pcs, pair->effective);
- pcs_callback(pcs,
+ pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
+ ret = pe_load_debug_info(pair->pcs, pair->effective);
+ pcs_callback(pair->pcs,
ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
&idsl64);
break;
diff --git a/dlls/dbghelp/source.c b/dlls/dbghelp/source.c
index d9fb076..fd0a9a8 100644
--- a/dlls/dbghelp/source.c
+++ b/dlls/dbghelp/source.c
@@ -116,26 +116,25 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hP
PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles,
PVOID UserContext)
{
- struct process* pcs;
struct module_pair pair;
SOURCEFILE sf;
char* ptr;
if (!cbSrcFiles) return FALSE;
- pcs = process_find_by_handle(hProcess);
- if (!pcs) return FALSE;
+ pair.pcs = process_find_by_handle(hProcess);
+ if (!pair.pcs) return FALSE;
if (ModBase)
{
- pair.requested = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
}
else
{
if (Mask[0] == '!')
{
- pair.requested = module_find_by_name(pcs, Mask + 1, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.requested = module_find_by_name(pair.pcs, Mask + 1, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
}
else
{
@@ -162,7 +161,6 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hP
BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
PCSTR srcfile, PSYM_ENUMLINES_CALLBACK cb, PVOID user)
{
- struct process* pcs;
struct module_pair pair;
struct hash_table_iter hti;
struct symt_ht* sym;
@@ -173,8 +171,6 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess
const char* file;
if (!cb) return FALSE;
- pcs = process_find_by_handle(hProcess);
- if (!pcs) return FALSE;
if (!(dbghelp_options & SYMOPT_LOAD_LINES)) return TRUE;
if (regcomp(&re, srcfile, REG_NOSUB))
{
@@ -182,9 +178,11 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
+ pair.pcs = process_find_by_handle(hProcess);
+ if (!pair.pcs) return FALSE;
if (compiland) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland);
- pair.requested = module_find_by_addr(pcs, base, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.requested = module_find_by_addr(pair.pcs, base, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
sci.SizeOfStruct = sizeof(sci);
sci.ModBase = base;
diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c
index 1e66a32..0705ff6 100644
--- a/dlls/dbghelp/symbol.c
+++ b/dlls/dbghelp/symbol.c
@@ -695,13 +695,13 @@ int symt_find_nearest(struct module* mod
return low;
}
-static BOOL symt_enum_locals_helper(struct process* pcs, struct module_pair* pair,
+static BOOL symt_enum_locals_helper(struct module_pair* pair,
regex_t* preg, const struct sym_enum* se,
struct vector* v)
{
struct symt** plsym = NULL;
struct symt* lsym = NULL;
- DWORD pc = pcs->ctx_frame.InstructionOffset;
+ DWORD pc = pair->pcs->ctx_frame.InstructionOffset;
while ((plsym = vector_iter_up(v, plsym)))
{
@@ -713,7 +713,7 @@ static BOOL symt_enum_locals_helper(stru
struct symt_block* block = (struct symt_block*)lsym;
if (pc < block->address || block->address + block->size <= pc)
continue;
- if (!symt_enum_locals_helper(pcs, pair, preg, se, &block->vchildren))
+ if (!symt_enum_locals_helper(pair, preg, se, &block->vchildren))
return FALSE;
}
break;
@@ -746,8 +746,9 @@ static BOOL symt_enum_locals(struct proc
se->sym_info->SizeOfStruct = sizeof(*se->sym_info);
se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
- pair.requested = module_find_by_addr(pcs, pc, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.pcs = pcs;
+ pair.requested = module_find_by_addr(pair.pcs, pc, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
if ((idx = symt_find_nearest(pair.effective, pc)) == -1) return FALSE;
sym = pair.effective->addr_sorttab[idx];
@@ -758,7 +759,7 @@ static BOOL symt_enum_locals(struct proc
compile_regex(mask ? mask : "*", -1, &preg,
dbghelp_options & SYMOPT_CASE_INSENSITIVE);
- ret = symt_enum_locals_helper(pcs, &pair, &preg, se,
+ ret = symt_enum_locals_helper(&pair, &preg, se,
&((struct symt_function*)sym)->vchildren);
regfree(&preg);
return ret;
@@ -801,16 +802,16 @@ static void copy_symbolW(SYMBOL_INFOW* s
static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
const struct sym_enum* se)
{
- struct process* pcs = process_find_by_handle(hProcess);
struct module_pair pair;
const char* bang;
regex_t mod_regex, sym_regex;
+ pair.pcs = process_find_by_handle(hProcess);
if (BaseOfDll == 0)
{
/* do local variables ? */
if (!Mask || !(bang = strchr(Mask, '!')))
- return symt_enum_locals(pcs, Mask, se);
+ return symt_enum_locals(pair.pcs, Mask, se);
if (bang == Mask) return FALSE;
@@ -818,9 +819,9 @@ static BOOL sym_enum(HANDLE hProcess, UL
compile_regex(bang + 1, -1, &sym_regex,
dbghelp_options & SYMOPT_CASE_INSENSITIVE);
- for (pair.requested = pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
+ for (pair.requested = pair.pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
{
- if (pair.requested->type == DMT_PE && module_get_debug(pcs, &pair))
+ if (pair.requested->type == DMT_PE && module_get_debug(&pair))
{
if (regexec(&mod_regex, pair.requested->module.ModuleName, 0, NULL, 0) == 0 &&
symt_enum_module(&pair, &sym_regex, se))
@@ -831,11 +832,11 @@ static BOOL sym_enum(HANDLE hProcess, UL
*/
if (!pair.requested && (dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES))
{
- for (pair.requested = pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
+ for (pair.requested = pair.pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
{
if (pair.requested->type == DMT_ELF &&
- !module_get_containee(pcs, pair.requested) &&
- module_get_debug(pcs, &pair))
+ !module_get_containee(pair.pcs, pair.requested) &&
+ module_get_debug(&pair))
{
if (regexec(&mod_regex, pair.requested->module.ModuleName, 0, NULL, 0) == 0 &&
symt_enum_module(&pair, &sym_regex, se))
@@ -847,8 +848,8 @@ static BOOL sym_enum(HANDLE hProcess, UL
regfree(&sym_regex);
return TRUE;
}
- pair.requested = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair))
+ pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
+ if (!module_get_debug(&pair))
return FALSE;
/* we always ignore module name from Mask when BaseOfDll is defined */
@@ -978,14 +979,14 @@ BOOL WINAPI SymEnumerateSymbols(HANDLE h
BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address,
DWORD64* Displacement, PSYMBOL_INFO Symbol)
{
- struct process* pcs = process_find_by_handle(hProcess);
struct module_pair pair;
struct symt_ht* sym;
int idx;
- if (!pcs) return FALSE;
- pair.requested = module_find_by_addr(pcs, Address, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ 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 ((idx = symt_find_nearest(pair.effective, Address)) == -1) return FALSE;
sym = pair.effective->addr_sorttab[idx];
@@ -1084,8 +1085,9 @@ static BOOL find_name(struct process* pc
struct symt_ht* sym = NULL;
struct module_pair pair;
+ pair.pcs = pcs;
if (!(pair.requested = module)) return FALSE;
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ if (!module_get_debug(&pair)) return FALSE;
hash_table_iter_init(&pair.effective->ht_symbols, &hti, name);
while ((ptr = hash_table_iter_up(&hti)))
@@ -1232,7 +1234,6 @@ BOOL WINAPI SymGetSymPrev(HANDLE hProces
BOOL WINAPI SymGetLineFromAddr(HANDLE hProcess, DWORD dwAddr,
PDWORD pdwDisplacement, PIMAGEHLP_LINE Line)
{
- struct process* pcs = process_find_by_handle(hProcess);
struct module_pair pair;
int idx;
@@ -1240,9 +1241,10 @@ BOOL WINAPI SymGetLineFromAddr(HANDLE hP
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
- if (!pcs) return FALSE;
- pair.requested = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.pcs = process_find_by_handle(hProcess);
+ if (!pair.pcs) return FALSE;
+ pair.requested = module_find_by_addr(pair.pcs, dwAddr, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
if ((idx = symt_find_nearest(pair.effective, dwAddr)) == -1) return FALSE;
if (pair.effective->addr_sorttab[idx]->symt.tag != SymTagFunction) return FALSE;
@@ -1339,7 +1341,6 @@ BOOL WINAPI SymGetLineFromAddrW64(HANDLE
*/
BOOL WINAPI SymGetLinePrev(HANDLE hProcess, PIMAGEHLP_LINE Line)
{
- struct process* pcs = process_find_by_handle(hProcess);
struct module_pair pair;
struct line_info* li;
BOOL in_search = FALSE;
@@ -1348,9 +1349,10 @@ BOOL WINAPI SymGetLinePrev(HANDLE hProce
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
- if (!pcs) return FALSE;
- pair.requested = module_find_by_addr(pcs, Line->Address, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.pcs = process_find_by_handle(hProcess);
+ if (!pair.pcs) return FALSE;
+ pair.requested = module_find_by_addr(pair.pcs, Line->Address, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
if (Line->Key == 0) return FALSE;
li = (struct line_info*)Line->Key;
@@ -1425,15 +1427,15 @@ BOOL symt_get_func_line_next(struct modu
*/
BOOL WINAPI SymGetLineNext(HANDLE hProcess, PIMAGEHLP_LINE Line)
{
- struct process* pcs = process_find_by_handle(hProcess);
struct module_pair pair;
TRACE("(%p %p)\n", hProcess, Line);
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
- if (!pcs) return FALSE;
- pair.requested = module_find_by_addr(pcs, Line->Address, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ pair.pcs = process_find_by_handle(hProcess);
+ if (!pair.pcs) return FALSE;
+ pair.requested = module_find_by_addr(pair.pcs, Line->Address, DMT_UNKNOWN);
+ if (!module_get_debug(&pair)) return FALSE;
if (symt_get_func_line_next(pair.effective, Line)) return TRUE;
SetLastError(ERROR_NO_MORE_ITEMS); /* FIXME */
diff --git a/dlls/dbghelp/type.c b/dlls/dbghelp/type.c
index f967f9a..da8d679 100644
--- a/dlls/dbghelp/type.c
+++ b/dlls/dbghelp/type.c
@@ -372,7 +372,6 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess
PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
PVOID UserContext)
{
- struct process* pcs;
struct module_pair pair;
char buffer[sizeof(SYMBOL_INFO) + 256];
SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
@@ -385,9 +384,9 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess
hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
UserContext);
- if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
- pair.requested = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair)) return FALSE;
+ 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;
sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
@@ -787,13 +786,13 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProce
ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType,
PVOID pInfo)
{
- struct process* pcs = process_find_by_handle(hProcess);
struct module_pair pair;
- if (!pcs) return FALSE;
+ pair.pcs = process_find_by_handle(hProcess);
+ if (!pair.pcs) return FALSE;
- pair.requested = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN);
- if (!module_get_debug(pcs, &pair))
+ 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;
More information about the wine-patches
mailing list