From: Eric Pouech epouech@codeweavers.com
It's a ptr when lower 2 bits are unset, an opaque backend value otherwise.
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/dbghelp/dbghelp.c | 5 ++++- dlls/dbghelp/dbghelp_private.h | 8 +++++--- dlls/dbghelp/module.c | 4 ++-- dlls/dbghelp/symbol.c | 34 +++++++++++++++------------------- dlls/dbghelp/type.c | 2 +- 5 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index 73c7f1eb969..75881473c2c 100644 --- a/dlls/dbghelp/dbghelp.c +++ b/dlls/dbghelp/dbghelp.c @@ -717,12 +717,15 @@ BOOL WINAPI SymSetScopeFromAddr(HANDLE hProcess, ULONG64 addr) BOOL WINAPI SymSetScopeFromIndex(HANDLE hProcess, ULONG64 addr, DWORD index) { struct module_pair pair; + symref_t symref; struct symt* sym;
TRACE("(%p %#I64x %lu)\n", hProcess, addr, index);
if (!module_init_pair(&pair, hProcess, addr)) return FALSE; - sym = symt_index_to_ptr(pair.effective, index); + symref = symt_index_to_symref(pair.effective, index); + if (!symt_is_symref_ptr(symref)) return FALSE; + sym = (struct symt*)symref; if (!symt_check_tag(sym, SymTagFunction)) return FALSE;
pair.pcs->localscope_pc = ((struct symt_function*)sym)->ranges[0].low; /* FIXME of FuncDebugStart when it exists? */ diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 1bb1f0e08cf..8589a2141d6 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -31,6 +31,7 @@ #include "winnls.h" #include "wine/list.h" #include "wine/rbtree.h" +#include "wine/debug.h"
#include "cvconst.h"
@@ -963,11 +964,12 @@ extern struct symt_hierarchy_point* symt_new_label(struct module* module, struct symt_compiland* compiland, const char* name, ULONG_PTR address); -extern struct symt* symt_index_to_ptr(struct module* module, DWORD id); -extern DWORD symt_ptr_to_index(struct module* module, const struct symt* sym); -extern DWORD symt_symref_to_index(struct module* module, symref_t ref); static inline symref_t symt_ptr_to_symref(const struct symt *symt) {return (ULONG_PTR)symt;} +extern symref_t symt_index_to_symref(struct module* module, DWORD id); +extern DWORD symt_symref_to_index(struct module* module, symref_t sym); +static inline DWORD symt_ptr_to_index(struct module *module, const struct symt *symt) {return symt_symref_to_index(module, symt_ptr_to_symref(symt));} +static inline BOOL symt_is_symref_ptr(symref_t ref) {return (ref & 3) == 0;} extern struct symt_custom* symt_new_custom(struct module* module, const char* name, DWORD64 addr, DWORD size); diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index 3d0c5ba7549..dee356e650a 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -197,8 +197,8 @@ struct module* module_new(struct process* pcs, const WCHAR* name, module->cpu = dbghelp_current_cpu; module->debug_format_bitmask = 0;
- vector_init(&module->vsymt, sizeof(struct symt*), 0); - vector_init(&module->vcustom_symt, sizeof(struct symt*), 0); + vector_init(&module->vsymt, sizeof(symref_t), 0); + vector_init(&module->vcustom_symt, sizeof(symref_t), 0); /* FIXME: this seems a bit too high (on a per module basis) * need some statistics about this */ diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c index 8bf8a5b35a6..ade18cc0a94 100644 --- a/dlls/dbghelp/symbol.c +++ b/dlls/dbghelp/symbol.c @@ -70,15 +70,15 @@ int __cdecl symt_cmp_addr(const void* p1, const void* p2) * which is exposed to the caller and index is the index of the symbol in * this array */ -DWORD symt_ptr_to_index(struct module* module, const struct symt* sym) +DWORD symt_symref_to_index(struct module* module, symref_t symref) { struct vector* vector; DWORD offset; - const struct symt** c; + symref_t *c; int len, i;
- if (!sym) return 0; - if (sym->tag == SymTagCustom) + if (!symref) return 0; + if (symt_is_symref_ptr(symref) && ((struct symt*)symref)->tag == SymTagCustom) { vector = &module->vcustom_symt; offset = BASE_CUSTOM_SYMT; @@ -89,23 +89,23 @@ DWORD symt_ptr_to_index(struct module* module, const struct symt* sy vector = &module->vsymt; offset = 1; #else - return (DWORD)sym; + return (DWORD)symref; #endif } len = vector_length(vector); /* FIXME: this is inefficient */ for (i = 0; i < len; i++) { - if (*(struct symt**)vector_at(vector, i) == sym) + if (*(symref_t*)vector_at(vector, i) == symref) return i + offset; } /* not found */ c = vector_add(vector, &module->pool); - if (c) *c = sym; + if (c) *c = symref; return len + offset; }
-struct symt* symt_index_to_ptr(struct module* module, DWORD id) +symref_t symt_index_to_symref(struct module* module, DWORD id) { struct vector* vector; if (id >= BASE_CUSTOM_SYMT) @@ -116,18 +116,13 @@ struct symt* symt_index_to_ptr(struct module* module, DWORD id) else { #ifdef _WIN64 - if (!id--) return NULL; + if (!id--) return 0; vector = &module->vsymt; #else - return (struct symt*)id; + return (symref_t)id; #endif } - return (id >= vector_length(vector)) ? NULL : *(struct symt**)vector_at(vector, id); -} - -DWORD symt_symref_to_index(struct module *module, symref_t ref) -{ - return symt_ptr_to_index(module, (struct symt*)ref); + return (id >= vector_length(vector)) ? 0 : *(symref_t *)vector_at(vector, id); }
static BOOL symt_grow_sorttab(struct module* module, unsigned sz) @@ -2653,14 +2648,15 @@ BOOL WINAPI SymGetLineFromNameW64(HANDLE hProcess, PCWSTR ModuleName, PCWSTR Fil BOOL WINAPI SymFromIndex(HANDLE hProcess, ULONG64 BaseOfDll, DWORD index, PSYMBOL_INFO symbol) { struct module_pair pair; - struct symt* sym; + symref_t symref;
TRACE("hProcess = %p, BaseOfDll = %I64x, index = %ld, symbol = %p\n", hProcess, BaseOfDll, index, symbol);
if (!module_init_pair(&pair, hProcess, BaseOfDll)) return FALSE; - if ((sym = symt_index_to_ptr(pair.effective, index)) == NULL) return FALSE; - symt_fill_sym_info(&pair, NULL, sym, symbol); + if ((symref = symt_index_to_symref(pair.effective, index)) == 0) return FALSE; + if (!symt_is_symref_ptr(symref)) return FALSE; + symt_fill_sym_info(&pair, NULL, (struct symt*)symref, symbol); return TRUE; }
diff --git a/dlls/dbghelp/type.c b/dlls/dbghelp/type.c index e47a04401c1..6d3312fa108 100644 --- a/dlls/dbghelp/type.c +++ b/dlls/dbghelp/type.c @@ -1114,7 +1114,7 @@ BOOL symt_get_info(struct module* module, const struct symt* type, BOOL symt_get_info_from_index(struct module* module, DWORD index, IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo) { - return symt_get_info(module, symt_index_to_ptr(module, index), req, pInfo); + return symt_get_info_from_symref(module, symt_index_to_symref(module, index), req, pInfo); }
BOOL symt_get_info_from_symref(struct module* module, symref_t ref,