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

dbghelp: Base and symbols.

- report the correct image base for a symbol which is seen as being in a builtin PE module, whilst its debug information is gotten from an ELF module - module_get_debug now returns a pair of modules (the requested that has to be presented back to the client and the effective one, which contains the debug info) - reworked SymFromName in order to provide also the revelant module base address
parent bc31b388
...@@ -315,6 +315,12 @@ struct line_info ...@@ -315,6 +315,12 @@ struct line_info
} u; } u;
}; };
struct module_pair
{
struct module* requested; /* in: to module_get_debug() */
struct module* effective; /* out: module with debug info */
};
/* dbghelp.c */ /* dbghelp.c */
extern struct process* process_find_by_handle(HANDLE hProcess); extern struct process* process_find_by_handle(HANDLE hProcess);
extern HANDLE hMsvcrt; extern HANDLE hMsvcrt;
...@@ -342,8 +348,7 @@ extern struct module* ...@@ -342,8 +348,7 @@ extern struct module*
extern struct module* extern struct module*
module_find_by_name(const struct process* pcs, module_find_by_name(const struct process* pcs,
const char* name, enum module_type type); const char* name, enum module_type type);
extern struct module* extern BOOL module_get_debug(const struct process* pcs, struct module_pair*);
module_get_debug(const struct process* pcs, struct module*);
extern struct module* extern struct module*
module_new(struct process* pcs, const char* name, module_new(struct process* pcs, const char* name,
enum module_type type, BOOL virtual, enum module_type type, BOOL virtual,
......
...@@ -229,37 +229,36 @@ struct module* module_get_containee(const struct process* pcs, ...@@ -229,37 +229,36 @@ struct module* module_get_containee(const struct process* pcs,
* container (and also force the ELF container's debug info loading if deferred) * container (and also force the ELF container's debug info loading if deferred)
* - otherwise return the module itself if it has some debug info * - otherwise return the module itself if it has some debug info
*/ */
struct module* module_get_debug(const struct process* pcs, struct module* module) BOOL module_get_debug(const struct process* pcs, struct module_pair* pair)
{ {
struct module* parent;
IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64; IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64;
if (!module) return NULL; if (!pair->requested) return FALSE;
/* for a PE builtin, always get info from parent */ /* for a PE builtin, always get info from container */
if ((parent = module_get_container(pcs, module))) if (!(pair->effective = module_get_container(pcs, pair->requested)))
module = parent; pair->effective = pair->requested;
/* if deferred, force loading */ /* if deferred, force loading */
if (module->module.SymType == SymDeferred) if (pair->effective->module.SymType == SymDeferred)
{ {
BOOL ret; BOOL ret;
if (module->is_virtual) ret = FALSE; if (pair->effective->is_virtual) ret = FALSE;
else switch (module->type) else switch (pair->effective->type)
{ {
case DMT_ELF: case DMT_ELF:
ret = elf_load_debug_info(module, NULL); ret = elf_load_debug_info(pair->effective, NULL);
break; break;
case DMT_PE: case DMT_PE:
idsl64.SizeOfStruct = sizeof(idsl64); idsl64.SizeOfStruct = sizeof(idsl64);
idsl64.BaseOfImage = module->module.BaseOfImage; idsl64.BaseOfImage = pair->effective->module.BaseOfImage;
idsl64.CheckSum = module->module.CheckSum; idsl64.CheckSum = pair->effective->module.CheckSum;
idsl64.TimeDateStamp = module->module.TimeDateStamp; idsl64.TimeDateStamp = pair->effective->module.TimeDateStamp;
strcpy(idsl64.FileName, module->module.ImageName); strcpy(idsl64.FileName, pair->effective->module.ImageName);
idsl64.Reparse = FALSE; idsl64.Reparse = FALSE;
idsl64.hFile = INVALID_HANDLE_VALUE; idsl64.hFile = INVALID_HANDLE_VALUE;
pcs_callback(pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64); pcs_callback(pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
ret = pe_load_debug_info(pcs, module); ret = pe_load_debug_info(pcs, pair->effective);
pcs_callback(pcs, pcs_callback(pcs,
ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE, ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
&idsl64); &idsl64);
...@@ -268,11 +267,11 @@ struct module* module_get_debug(const struct process* pcs, struct module* module ...@@ -268,11 +267,11 @@ struct module* module_get_debug(const struct process* pcs, struct module* module
ret = FALSE; ret = FALSE;
break; break;
} }
if (!ret) module->module.SymType = SymNone; if (!ret) pair->effective->module.SymType = SymNone;
assert(module->module.SymType != SymDeferred); assert(pair->effective->module.SymType != SymDeferred);
module_compute_num_syms(module); module_compute_num_syms(pair->effective);
} }
return (module && module->module.SymType != SymNone) ? module : NULL; return pair->effective->module.SymType != SymNone;
} }
/*********************************************************************** /***********************************************************************
......
...@@ -102,7 +102,7 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask, ...@@ -102,7 +102,7 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask,
PVOID UserContext) PVOID UserContext)
{ {
struct process* pcs; struct process* pcs;
struct module* module; struct module_pair pair;
SOURCEFILE sf; SOURCEFILE sf;
char* ptr; char* ptr;
...@@ -112,15 +112,15 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask, ...@@ -112,15 +112,15 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask,
if (ModBase) if (ModBase)
{ {
module = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN); pair.requested = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE; if (!module_get_debug(pcs, &pair)) return FALSE;
} }
else else
{ {
if (Mask[0] == '!') if (Mask[0] == '!')
{ {
module = module_find_by_name(pcs, Mask + 1, DMT_UNKNOWN); pair.requested = module_find_by_name(pcs, Mask + 1, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE; if (!module_get_debug(pcs, &pair)) return FALSE;
} }
else else
{ {
...@@ -128,8 +128,8 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask, ...@@ -128,8 +128,8 @@ BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask,
return FALSE; return FALSE;
} }
} }
if (!module->sources) return FALSE; if (!pair.effective->sources) return FALSE;
for (ptr = module->sources; *ptr; ptr += strlen(ptr) + 1) for (ptr = pair.effective->sources; *ptr; ptr += strlen(ptr) + 1)
{ {
/* FIXME: not using Mask */ /* FIXME: not using Mask */
sf.ModBase = ModBase; sf.ModBase = ModBase;
...@@ -148,7 +148,7 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland, ...@@ -148,7 +148,7 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
PCSTR srcfile, PSYM_ENUMLINES_CALLBACK cb, PVOID user) PCSTR srcfile, PSYM_ENUMLINES_CALLBACK cb, PVOID user)
{ {
struct process* pcs; struct process* pcs;
struct module* module; struct module_pair pair;
struct hash_table_iter hti; struct hash_table_iter hti;
struct symt_ht* sym; struct symt_ht* sym;
regex_t re; regex_t re;
...@@ -168,13 +168,13 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland, ...@@ -168,13 +168,13 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
return FALSE; return FALSE;
} }
if (compiland) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland); if (compiland) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland);
module = module_find_by_addr(pcs, base, DMT_UNKNOWN); pair.requested = module_find_by_addr(pcs, base, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE; if (!module_get_debug(pcs, &pair)) return FALSE;
sci.SizeOfStruct = sizeof(sci); sci.SizeOfStruct = sizeof(sci);
sci.ModBase = base; sci.ModBase = base;
hash_table_iter_init(&module->ht_symbols, &hti, NULL); hash_table_iter_init(&pair.effective->ht_symbols, &hti, NULL);
while ((ptr = hash_table_iter_up(&hti))) while ((ptr = hash_table_iter_up(&hti)))
{ {
sym = GET_ENTRY(ptr, struct symt_ht, hash_elt); sym = GET_ENTRY(ptr, struct symt_ht, hash_elt);
...@@ -186,7 +186,7 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland, ...@@ -186,7 +186,7 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
{ {
if (dli->is_source_file) if (dli->is_source_file)
{ {
file = (char*)source_get(module, dli->u.source_file); file = (char*)source_get(pair.effective, dli->u.source_file);
if (regexec(&re, file, 0, NULL, 0) != 0) file = ""; if (regexec(&re, file, 0, NULL, 0) != 0) file = "";
strcpy(sci.FileName, file); strcpy(sci.FileName, file);
} }
......
...@@ -373,7 +373,7 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll, ...@@ -373,7 +373,7 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
PVOID UserContext) PVOID UserContext)
{ {
struct process* pcs; struct process* pcs;
struct module* module; struct module_pair pair;
char buffer[sizeof(SYMBOL_INFO) + 256]; char buffer[sizeof(SYMBOL_INFO) + 256];
SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer; SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
const char* tmp; const char* tmp;
...@@ -386,20 +386,20 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll, ...@@ -386,20 +386,20 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
UserContext); UserContext);
if (!(pcs = process_find_by_handle(hProcess))) return FALSE; if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN); pair.requested = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE; if (!module_get_debug(pcs, &pair)) return FALSE;
sym_info->SizeOfStruct = sizeof(SYMBOL_INFO); sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO); sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
while ((pos = vector_iter_up(&module->vtypes, pos))) while ((pos = vector_iter_up(&pair.effective->vtypes, pos)))
{ {
type = *(struct symt**)pos; type = *(struct symt**)pos;
sym_info->TypeIndex = (DWORD)type; sym_info->TypeIndex = (DWORD)type;
sym_info->info = 0; /* FIXME */ sym_info->info = 0; /* FIXME */
symt_get_info(type, TI_GET_LENGTH, &size); symt_get_info(type, TI_GET_LENGTH, &size);
sym_info->Size = size; sym_info->Size = size;
sym_info->ModBase = module->module.BaseOfImage; sym_info->ModBase = pair.requested->module.BaseOfImage;
sym_info->Flags = 0; /* FIXME */ sym_info->Flags = 0; /* FIXME */
sym_info->Value = 0; /* FIXME */ sym_info->Value = 0; /* FIXME */
sym_info->Address = 0; /* FIXME */ sym_info->Address = 0; /* FIXME */
...@@ -788,12 +788,12 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase, ...@@ -788,12 +788,12 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
PVOID pInfo) PVOID pInfo)
{ {
struct process* pcs = process_find_by_handle(hProcess); struct process* pcs = process_find_by_handle(hProcess);
struct module* module; struct module_pair pair;
if (!pcs) return FALSE; if (!pcs) return FALSE;
module = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN); pair.requested = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) if (!module_get_debug(pcs, &pair))
{ {
FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase)); FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
return FALSE; return FALSE;
......
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