From: Eric Pouech <epouech@codeweavers.com> Signed-off-by: Eric Pouech <epouech@codeweavers.com> --- dlls/dbghelp/dbghelp_private.h | 3 +- dlls/dbghelp/elf_module.c | 2 +- dlls/dbghelp/macho_module.c | 2 +- dlls/dbghelp/symbol.c | 75 ++++++++++++++++++---------------- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 39a12af130f..20892db8cda 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -913,8 +913,7 @@ extern int __cdecl symt_cmp_addr(const void* p1, const void* p2); extern void copy_symbolW(SYMBOL_INFOW* siw, const SYMBOL_INFO* si); extern void symbol_setname(SYMBOL_INFO* si, const char* name); extern BOOL symt_match_stringAW(const char *string, const WCHAR *re, BOOL _case); -extern struct symt_ht* - symt_find_nearest(struct module* module, DWORD_PTR addr); +extern symref_t symt_find_nearest(struct module* module, DWORD_PTR addr); extern struct symt_ht* symt_find_symbol_at(struct module* module, DWORD_PTR addr); extern struct symt_module* diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index af6fb916290..81f933c76ef 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -946,7 +946,7 @@ static int elf_new_wine_thunks(struct module* module, const struct hash_table* h ULONG64 ref_addr; struct location loc; - symt = symt_find_nearest(module, addr); + symt = (struct symt_ht*)SYMT_SYMREF_TO_PTR(symt_find_nearest(module, addr)); if (symt && !symt_get_address(&symt->symt, &ref_addr)) ref_addr = addr; if (!symt || addr != ref_addr) diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c index 9b24fd48ae0..a8358510caf 100644 --- a/dlls/dbghelp/macho_module.c +++ b/dlls/dbghelp/macho_module.c @@ -1151,7 +1151,7 @@ static void macho_finish_stabs(struct module* module, struct hash_table* ht_symt if (ste->used) continue; - sym = symt_find_nearest(module, ste->addr); + sym = (struct symt_ht*)SYMT_SYMREF_TO_PTR(symt_find_nearest(module, ste->addr)); if (sym) symt_get_address(&sym->symt, &addr); if (sym && ste->addr == addr) diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c index a21fc73ce8a..d6b7dba4426 100644 --- a/dlls/dbghelp/symbol.c +++ b/dlls/dbghelp/symbol.c @@ -264,7 +264,7 @@ struct symt_public* symt_new_public(struct module* module, TRACE_(dbghelp_symt)("Adding public symbol %s:%s @%Ix\n", debugstr_w(module->modulename), debugstr_a(name), address); if ((dbghelp_options & SYMOPT_AUTO_PUBLICS) && - symt_find_nearest(module, address) != NULL) + symt_find_nearest(module, address)) return NULL; if ((sym = pool_alloc(&module->pool, sizeof(*sym)))) { @@ -871,7 +871,7 @@ static BOOL symt_fill_sym_info(struct module_pair* pair, return TRUE; } -static BOOL symt_fill_sym_info_from_symref(struct module_pair* pair, symref_t symref, SYMBOL_INFO* sym_info) +static BOOL symt_fill_sym_info_from_symref(struct module_pair* pair, const struct symt_function* func, symref_t symref, SYMBOL_INFO* sym_info) { DWORD tag; DWORD64 size; @@ -882,7 +882,7 @@ static BOOL symt_fill_sym_info_from_symref(struct module_pair* pair, symref_t sy sym_info->Tag = tag; if (symt_is_symref_ptr(symref)) - return symt_fill_sym_info(pair, NULL, SYMT_SYMREF_TO_PTR(symref), sym_info); + return symt_fill_sym_info(pair, func, SYMT_SYMREF_TO_PTR(symref), sym_info); /* FIXME this isn't optimal; perhaps implement SymGetInfoTypeEx to support multiple * queries at once! @@ -946,9 +946,9 @@ struct sym_enum }; static BOOL send_symbol(const struct sym_enum* se, struct module_pair* pair, - const struct symt_function* func, const struct symt* sym) + const struct symt_function* func, symref_t symref) { - if (!symt_fill_sym_info(pair, func, sym, se->sym_info)) return FALSE; + if (!symt_fill_sym_info_from_symref(pair, func, symref, se->sym_info)) return FALSE; if (se->index && se->sym_info->Index != se->index) return FALSE; if (se->tag && se->sym_info->Tag != se->tag) return FALSE; if (se->addr && !(se->addr >= se->sym_info->Address && se->addr < se->sym_info->Address + se->sym_info->Size)) return FALSE; @@ -968,11 +968,7 @@ static BOOL symbol_enum_method_cb(symref_t symref, const char *name, void *user) sem->se->sym_info->SizeOfStruct = sizeof(SYMBOL_INFO); sem->se->sym_info->MaxNameLen = sizeof(sem->se->buffer) - sizeof(SYMBOL_INFO); - if (symt_is_symref_ptr(symref)) - { - if (send_symbol(sem->se, sem->pair, NULL, (struct symt*)symref)) return TRUE; - } - else FIXME("No support for this case yet %Ix\n", symref); + send_symbol(sem->se, sem->pair, NULL, symref); return TRUE; } @@ -1008,7 +1004,7 @@ static BOOL symt_enum_module(struct module_pair* pair, const WCHAR* match, { se->sym_info->SizeOfStruct = sizeof(SYMBOL_INFO); se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO); - if (send_symbol(se, pair, NULL, &sym->symt)) return TRUE; + if (send_symbol(se, pair, NULL, symt_ptr_to_symref(&sym->symt))) return TRUE; } } return FALSE; @@ -1176,7 +1172,7 @@ static struct symt_ht* symt_find_nearest_internal(struct module* module, DWORD_P return module->addr_sorttab[low]; } -struct symt_ht *symt_find_nearest(struct module *module, DWORD_PTR addr) +symref_t symt_find_nearest(struct module *module, DWORD_PTR addr) { static int recursive; struct module_format_vtable_iterator iter = {}; @@ -1192,31 +1188,45 @@ struct symt_ht *symt_find_nearest(struct module *module, DWORD_PTR addr) if (result == MR_SUCCESS) { recursive--; - if (symt_is_symref_ptr(symref)) return (struct symt_ht*)SYMT_SYMREF_TO_PTR(symref); - FIXME("No support for this case yet\n"); - return NULL; + if (!symt_is_symref_ptr(symref)) FIXME("No support for this case yet\n"); + return symref; } /* fall back in all the other cases */ } } recursive--; - return symt_find_nearest_internal(module, addr); + return symt_ptr_to_symref(&symt_find_nearest_internal(module, addr)->symt); } -struct symt_ht* symt_find_symbol_at(struct module* module, DWORD_PTR addr) +static symref_t symt_find_symref_at(struct module* module, DWORD_PTR addr) { - struct symt_ht* nearest = symt_find_nearest(module, addr); + symref_t nearest = symt_find_nearest(module, addr); if (nearest) { - ULONG64 symaddr, symsize; - symt_get_address(&nearest->symt, &symaddr); - symt_get_length(module, &nearest->symt, &symsize); + ULONG64 symaddr, symsize; + if (symt_get_info_from_symref(module, nearest, TI_GET_ADDRESS, &symaddr)) + { + /* some symbols are defined without size, so grab size for their type (if any) */ + if (!symt_get_info_from_symref(module, nearest, TI_GET_LENGTH, &symsize) || !symsize) + { + DWORD symtype; + if (!symt_get_info_from_symref(module, nearest, TI_GET_TYPE, &symtype) || + !symt_get_info_from_index(module, symtype, TI_GET_LENGTH, &symsize)) + symsize = 1; + } + } if (addr < symaddr || addr >= symaddr + symsize) - nearest = NULL; + nearest = 0; } return nearest; } +struct symt_ht* symt_find_symbol_at(struct module* module, DWORD_PTR addr) +{ + symref_t nearest = symt_find_symref_at(module, addr); + return (struct symt_ht*)SYMT_SYMREF_TO_PTR(nearest); +} + static BOOL symt_enum_locals_helper(struct module_pair* pair, const WCHAR* match, const struct sym_enum* se, struct symt_function* func, const struct vector* v) @@ -1254,7 +1264,7 @@ static BOOL symt_enum_locals_helper(struct module_pair* pair, HeapFree(GetProcessHeap(), 0, nameW); if (ret) { - if (send_symbol(se, pair, func, lsym)) return FALSE; + if (send_symbol(se, pair, func, symt_ptr_to_symref(lsym))) return FALSE; } break; case SymTagLabel: @@ -1609,16 +1619,16 @@ BOOL WINAPI SymEnumerateSymbols64(HANDLE hProcess, DWORD64 BaseOfDll, * SymFromAddr (DBGHELP.@) * */ -BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address, +BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address, DWORD64* Displacement, PSYMBOL_INFO Symbol) { struct module_pair pair; - struct symt_ht* sym; + symref_t symref; if (!module_init_pair(&pair, hProcess, Address)) return FALSE; - if ((sym = symt_find_symbol_at(pair.effective, Address)) == NULL) return FALSE; + if (!(symref = symt_find_symref_at(pair.effective, Address))) return FALSE; - symt_fill_sym_info(&pair, NULL, &sym->symt, Symbol); + symt_fill_sym_info_from_symref(&pair, NULL, symref, Symbol); if (Displacement) *Displacement = (Address >= Symbol->Address) ? (Address - Symbol->Address) : (DWORD64)-1; return TRUE; @@ -1725,13 +1735,8 @@ static BOOL find_name(struct process* pcs, struct module* module, const char* na enum method_result result = iter.modfmt->vtable->lookup_by_name(iter.modfmt, name, &symref); if (result == MR_SUCCESS) { - if (symt_is_symref_ptr(symref)) - { - symt_fill_sym_info(&pair, NULL, SYMT_SYMREF_TO_PTR(symref), symbol); - return TRUE; - } - FIXME("Not expected case\n"); - return FALSE; + symt_fill_sym_info_from_symref(&pair, NULL, symref, symbol); + return TRUE; } if (result != MR_NOT_FOUND) return FALSE; } @@ -2824,7 +2829,7 @@ BOOL WINAPI SymFromIndex(HANDLE hProcess, ULONG64 BaseOfDll, DWORD index, PSYMBO if (!module_init_pair(&pair, hProcess, BaseOfDll)) return FALSE; if ((symref = symt_index_to_symref(pair.effective, index)) == 0) return FALSE; - return symt_fill_sym_info_from_symref(&pair, symref, symbol); + return symt_fill_sym_info_from_symref(&pair, NULL, symref, symbol); } /****************************************************************** -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9957