From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/dbghelp/dbghelp_private.h | 29 ++++++--- dlls/dbghelp/dwarf.c | 34 +++++----- dlls/dbghelp/elf_module.c | 9 +-- dlls/dbghelp/module.c | 12 ++-- dlls/dbghelp/msc.c | 17 ++--- dlls/dbghelp/symbol.c | 109 ++++++++++++++++++--------------- dlls/dbghelp/type.c | 39 ++++++------ 7 files changed, 138 insertions(+), 111 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 7b489f091fe..106d84cdde7 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -189,7 +189,7 @@ typedef ULONG_PTR symref_t; struct symt_block { struct symt symt; - struct symt* container; /* block, or func */ + symref_t container; /* block, or func */ struct vector vchildren; /* sub-blocks & local variables */ unsigned num_ranges; struct addr_range ranges[]; @@ -205,7 +205,7 @@ struct symt_module /* in fact any of .exe, .dll... */ struct symt_compiland { struct symt symt; - struct symt_module* container; /* symt_module */ + symref_t container; /* symt_module */ ULONG_PTR address; const char *filename; struct vector vchildren; /* global variables & functions */ @@ -217,7 +217,7 @@ struct symt_data struct symt symt; struct hash_table_elt hash_elt; /* if global symbol */ enum DataKind kind; - struct symt* container; + symref_t container; symref_t type; union /* depends on kind */ { @@ -294,7 +294,7 @@ struct symt_function { struct symt symt; /* SymTagFunction or SymTagInlineSite */ struct hash_table_elt hash_elt; /* if global symbol, inline site */ - struct symt* container; /* compiland (for SymTagFunction) or function (for SymTagInlineSite) */ + symref_t container; /* compiland (for SymTagFunction) or function (for SymTagInlineSite) */ symref_t type; /* points to function_signature */ struct vector vlines; struct vector vchildren; /* locals, params, blocks, start/end, labels, inline sites */ @@ -308,7 +308,7 @@ struct symt_hierarchy_point { struct symt symt; /* either SymTagFunctionDebugStart, SymTagFunctionDebugEnd, SymTagLabel */ struct hash_table_elt hash_elt; /* if label (and in compiland's hash table if global) */ - struct symt* parent; /* symt_function or symt_compiland */ + symref_t container; /* symt_function or symt_compiland */ struct location loc; };
@@ -316,7 +316,7 @@ struct symt_public { struct symt symt; struct hash_table_elt hash_elt; - struct symt* container; /* compiland */ + symref_t container; /* compiland */ BOOL is_function; ULONG_PTR address; ULONG_PTR size; @@ -326,7 +326,7 @@ struct symt_thunk { struct symt symt; struct hash_table_elt hash_elt; - struct symt* container; /* compiland */ + symref_t container; /* compiland */ ULONG_PTR address; ULONG_PTR size; THUNK_ORDINAL ordinal; /* FIXME: doesn't seem to be accessible */ @@ -978,12 +978,25 @@ extern struct symt_hierarchy_point* symt_new_label(struct module* module, struct symt_compiland* compiland, const char* name, ULONG_PTR address); +static inline BOOL symt_is_symref_ptr(symref_t ref) {return (ref & 3) == 0;} static inline symref_t symt_ptr_to_symref(const struct symt *symt) {return (ULONG_PTR)symt;} +static inline struct symt* + _symt_symref_to_ptr(const char *file, unsigned lineno, symref_t symref) +{ + if (!symt_is_symref_ptr(symref)) + { + MESSAGE("%s:%u can't convert symref to ptr\n", file, lineno); + return NULL; + } + return (struct symt*)symref; +} +/* this function shall be used with care as not all symref:s are actual pointers */ +#define SYMT_SYMREF_TO_PTR(s) _symt_symref_to_ptr(__FILE__, __LINE__, (s)) 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/dwarf.c b/dlls/dbghelp/dwarf.c index 3e77da64d9c..31ef65f158d 100644 --- a/dlls/dbghelp/dwarf.c +++ b/dlls/dbghelp/dwarf.c @@ -2280,7 +2280,7 @@ static void dwarf2_parse_inlined_subroutine(dwarf2_subprogram_t* subpgm, child->abbrev->tag, dwarf2_debug_di(di)); } } - subpgm->current_block = symt_check_tag(subpgm->current_func->container, SymTagBlock) ? + subpgm->current_block = symt_check_tag(SYMT_SYMREF_TO_PTR(subpgm->current_func->container), SymTagBlock) ? (struct symt_block*)subpgm->current_func->container : NULL; subpgm->current_func = (struct symt_function*)symt_get_upper_inlined(subpgm->current_func); } @@ -2924,22 +2924,22 @@ static BOOL dwarf2_parse_line_numbers(dwarf2_parse_context_t* ctx, return TRUE; }
-unsigned dwarf2_cache_cuhead(struct dwarf2_module_info_s* module, struct symt_compiland* c, const dwarf2_cuhead_t* head) +static unsigned dwarf2_cache_cuhead(struct module *module, struct dwarf2_module_info_s* module_info, struct symt_compiland* c, const dwarf2_cuhead_t* head) { dwarf2_cuhead_t* ah; unsigned i; - for (i = 0; i < module->num_cuheads; ++i) + for (i = 0; i < module_info->num_cuheads; ++i) { - if (memcmp(module->cuheads[i], head, sizeof(*head)) == 0) + if (memcmp(module_info->cuheads[i], head, sizeof(*head)) == 0) { - c->user = module->cuheads[i]; + c->user = module_info->cuheads[i]; return TRUE; } } - if (!(ah = pool_alloc(&c->container->module->pool, sizeof(*head)))) return FALSE; + if (!(ah = pool_alloc(&module->pool, sizeof(*head)))) return FALSE; memcpy(ah, head, sizeof(*head)); - module->cuheads = realloc(module->cuheads, ++module->num_cuheads * sizeof(head)); - module->cuheads[module->num_cuheads - 1] = ah; + module_info->cuheads = realloc(module_info->cuheads, ++module_info->num_cuheads * sizeof(head)); + module_info->cuheads[module_info->num_cuheads - 1] = ah; c->user = ah; return TRUE; } @@ -3069,7 +3069,7 @@ static BOOL dwarf2_parse_compilation_unit(dwarf2_parse_context_t* ctx) ctx->compiland = symt_new_compiland(ctx->module_ctx->module, tmp); HeapFree(GetProcessHeap(), 0, tmp); ctx->compiland->address = ctx->module_ctx->load_offset + low_pc.u.uvalue; - dwarf2_cache_cuhead(ctx->module_ctx->module->format_info[DFI_DWARF]->u.dwarf2_info, ctx->compiland, &ctx->head); + dwarf2_cache_cuhead(ctx->module_ctx->module, ctx->module_ctx->module->format_info[DFI_DWARF]->u.dwarf2_info, ctx->compiland, &ctx->head); di->symt = &ctx->compiland->symt; children = dwarf2_get_di_children(di); if (children) for (i = 0; i < vector_length(children); i++) @@ -3121,9 +3121,9 @@ static const dwarf2_cuhead_t* get_cuhead_from_func(const struct symt_function* f { if (symt_check_tag(&func->symt, SymTagInlineSite)) func = symt_get_function_from_inlined((struct symt_function*)func); - if (symt_check_tag(&func->symt, SymTagFunction) && symt_check_tag(func->container, SymTagCompiland)) + if (symt_check_tag(&func->symt, SymTagFunction) && symt_check_tag(SYMT_SYMREF_TO_PTR(func->container), SymTagCompiland)) { - struct symt_compiland* c = (struct symt_compiland*)func->container; + struct symt_compiland* c = (struct symt_compiland*)SYMT_SYMREF_TO_PTR(func->container); return (const dwarf2_cuhead_t*)c->user; } FIXME("Should have a compilation unit head\n"); @@ -3138,7 +3138,7 @@ static enum location_error loc_compute_frame(const struct module_format* modfmt, struct location* frame) { struct process *pcs = modfmt->module->process; - struct symt** psym = NULL; + struct symt* sym; struct location* pframe; dwarf2_traverse_context_t lctx; enum location_error err; @@ -3146,10 +3146,10 @@ static enum location_error loc_compute_frame(const struct module_format* modfmt,
for (i=0; i<vector_length(&func->vchildren); i++) { - psym = vector_at(&func->vchildren, i); - if (psym && symt_check_tag(*psym, SymTagCustom)) + sym = SYMT_SYMREF_TO_PTR(*(symref_t*)vector_at(&func->vchildren, i)); + if (symt_check_tag(sym, SymTagCustom)) { - pframe = &((struct symt_hierarchy_point*)*psym)->loc; + pframe = &((struct symt_hierarchy_point*)sym)->loc;
/* First, recompute the frame information, if needed */ switch (pframe->kind) @@ -3173,7 +3173,7 @@ static enum location_error loc_compute_frame(const struct module_format* modfmt, } break; case loc_dwarf2_frame_cfa: - err = compute_call_frame_cfa(modfmt->module, ip + ((struct symt_compiland*)func->container)->address, frame); + err = compute_call_frame_cfa(modfmt->module, ip + ((struct symt_compiland*)SYMT_SYMREF_TO_PTR(func->container))->address, frame); if (err < 0) return err; break; default: @@ -4030,7 +4030,7 @@ static void dwarf2_location_compute(const struct module_format* modfmt, { struct process *pcs = modfmt->module->process; /* instruction pointer relative to compiland's start */ - ip = pcs->localscope_pc - ((struct symt_compiland*)func->container)->address; + ip = pcs->localscope_pc - ((struct symt_compiland*)SYMT_SYMREF_TO_PTR(func->container))->address;
if ((err = loc_compute_frame(modfmt, func, ip, head, &frame)) == 0) { diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index dad0d459409..f6d17c7ebd9 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -762,7 +762,7 @@ static void elf_hash_symtab(struct module* module, struct pool* pool, */ static const struct elf_sym *elf_lookup_symtab(const struct module* module, const struct hash_table* ht_symtab, - const char* name, const struct symt* compiland) + const char* name, symref_t symref_compiland) { struct symtab_elt* weak_result = NULL; /* without compiland name */ struct symtab_elt* result = NULL; @@ -771,8 +771,9 @@ static const struct elf_sym *elf_lookup_symtab(const struct module* module, const char* compiland_name; const char* compiland_basename; const char* base; + struct symt_compiland *compiland = (struct symt_compiland*)SYMT_SYMREF_TO_PTR(symref_compiland);
- /* we need weak match up (at least) when symbols of same name, + /* we need weak match up (at least) when symbols of same name, * defined several times in different compilation units, * are merged in a single one (hence a different filename for c.u.) */ @@ -856,7 +857,7 @@ static void elf_finish_stabs_info(struct module* module, const struct hash_table { break; } - symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name, + symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name, ((struct symt_function*)sym)->container); if (symp) { @@ -885,7 +886,7 @@ static void elf_finish_stabs_info(struct module* module, const struct hash_table if (((struct symt_data*)sym)->u.var.kind != loc_absolute || ((struct symt_data*)sym)->u.var.offset != elf_info->elf_addr) break; - symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name, + symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name, ((struct symt_data*)sym)->container); if (symp) { diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index 750d0d08655..c5eafee4db5 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -1044,12 +1044,14 @@ BOOL module_remove(struct process* pcs, struct module* module) locsym = &symt_get_function_from_inlined((struct symt_function*)locsym)->symt; if (symt_check_tag(locsym, SymTagFunction)) { - locsym = ((struct symt_function*)locsym)->container; - if (symt_check_tag(locsym, SymTagCompiland) && - module == ((struct symt_compiland*)locsym)->container->module) + struct symt_compiland *compiland = (struct symt_compiland*)SYMT_SYMREF_TO_PTR(((struct symt_function*)locsym)->container); + if (symt_check_tag(&compiland->symt, SymTagCompiland)) { - pcs->localscope_pc = 0; - pcs->localscope_symt = NULL; + if (module == ((struct symt_module*)SYMT_SYMREF_TO_PTR(compiland->container))->module) + { + pcs->localscope_pc = 0; + pcs->localscope_symt = NULL; + } } } } diff --git a/dlls/dbghelp/msc.c b/dlls/dbghelp/msc.c index fbd7e29b531..d65b7707921 100644 --- a/dlls/dbghelp/msc.c +++ b/dlls/dbghelp/msc.c @@ -1814,8 +1814,9 @@ static BOOL func_has_local(struct symt_function* func, const char* name)
for (i = 0; i < func->vchildren.num_elts; ++i) { - struct symt* p = *(struct symt**)vector_at(&func->vchildren, i); - if (symt_check_tag(p, SymTagData) && !strcmp(((struct symt_data*)p)->hash_elt.name, name)) + struct symt *lsym = SYMT_SYMREF_TO_PTR(*(symref_t*)vector_at(&func->vchildren, i)); + + if (symt_check_tag(lsym, SymTagData) && !strcmp(((struct symt_data*)lsym)->hash_elt.name, name)) return TRUE; } return FALSE; @@ -1865,7 +1866,7 @@ static inline void codeview_add_variable(const struct msc_debug_info* msc_dbg, if (symdata->kind == (is_local ? DataIsFileStatic : DataIsGlobal) && symdata->u.var.kind == loc.kind && symdata->u.var.offset == loc.offset && - symdata->container == &compiland->symt) + symdata->container == symt_ptr_to_symref(&compiland->symt)) { /* We don't compare types yet... Unfortunately, they are not * always the same typeid... it'd require full type equivalence @@ -2320,9 +2321,9 @@ static struct symt_compiland* codeview_new_compiland(const struct msc_debug_info */ for (i = 0; i < msc_dbg->module->top->vchildren.num_elts; i++) { - struct symt_compiland** p = vector_at(&msc_dbg->module->top->vchildren, i); - if (symt_check_tag(&(*p)->symt, SymTagCompiland) && !strcmp((*p)->filename, objname)) - return *p; + struct symt_compiland* p = (struct symt_compiland*)SYMT_SYMREF_TO_PTR(*(symref_t*)vector_at(&msc_dbg->module->top->vchildren, i)); + if (symt_check_tag(&p->symt, SymTagCompiland) && !strcmp(p->filename, objname)) + return p; } return symt_new_compiland(msc_dbg->module, objname); } @@ -2783,8 +2784,8 @@ static BOOL codeview_snarf(const struct msc_debug_info* msc_dbg, break;
case S_INLINESITE_END: - block = symt_check_tag(curr_func->container, SymTagBlock) ? - (struct symt_block*)curr_func->container : NULL; + block = symt_check_tag(SYMT_SYMREF_TO_PTR(curr_func->container), SymTagBlock) ? + (struct symt_block *)((struct symt_block*)curr_func->container) : NULL; curr_func = (struct symt_function*)symt_get_upper_inlined(curr_func); break;
diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c index e4c5361f897..9f8049e3330 100644 --- a/dlls/dbghelp/symbol.c +++ b/dlls/dbghelp/symbol.c @@ -226,7 +226,7 @@ struct symt_module* symt_new_module(struct module* module) { sym->symt.tag = SymTagExe; sym->module = module; - vector_init(&sym->vchildren, sizeof(struct symt*), 0); + vector_init(&sym->vchildren, sizeof(symref_t), 0); } return sym; } @@ -234,20 +234,20 @@ struct symt_module* symt_new_module(struct module* module) struct symt_compiland* symt_new_compiland(struct module* module, const char *filename) { struct symt_compiland* sym; - struct symt_compiland** p; + symref_t* p;
TRACE_(dbghelp_symt)("Adding compiland symbol %s:%s\n", debugstr_w(module->modulename), debugstr_a(filename)); if ((sym = pool_alloc(&module->pool, sizeof(*sym)))) { sym->symt.tag = SymTagCompiland; - sym->container = module->top; + sym->container = symt_ptr_to_symref(&module->top->symt); sym->address = 0; sym->filename = pool_strdup(&module->pool, filename); - vector_init(&sym->vchildren, sizeof(struct symt*), 0); + vector_init(&sym->vchildren, sizeof(symref_t), 0); sym->user = NULL; p = vector_add(&module->top->vchildren, &module->pool); - *p = sym; + if (p) *p = symt_ptr_to_symref(&sym->symt); } return sym; } @@ -259,7 +259,7 @@ struct symt_public* symt_new_public(struct module* module, ULONG_PTR address, unsigned size) { struct symt_public* sym; - struct symt** p; + symref_t* p;
TRACE_(dbghelp_symt)("Adding public symbol %s:%s @%Ix\n", debugstr_w(module->modulename), debugstr_a(name), address); @@ -270,7 +270,7 @@ struct symt_public* symt_new_public(struct module* module, { sym->symt.tag = SymTagPublicSymbol; sym->hash_elt.name = pool_strdup(&module->pool, name); - sym->container = compiland ? &compiland->symt : NULL; + sym->container = compiland ? symt_ptr_to_symref(&compiland->symt) : 0; sym->is_function = is_function; sym->address = address; sym->size = size; @@ -278,7 +278,7 @@ struct symt_public* symt_new_public(struct module* module, if (compiland) { p = vector_add(&compiland->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } } return sym; @@ -291,7 +291,7 @@ struct symt_data* symt_new_global_variable(struct module* module, symref_t type) { struct symt_data* sym; - struct symt** p; + symref_t* p; DWORD64 tsz;
TRACE_(dbghelp_symt)("Adding global symbol %s:%s %d@%Ix %Ix\n", @@ -301,7 +301,7 @@ struct symt_data* symt_new_global_variable(struct module* module, sym->symt.tag = SymTagData; sym->hash_elt.name = pool_strdup(&module->pool, name); sym->kind = is_static ? DataIsFileStatic : DataIsGlobal; - sym->container = compiland ? &compiland->symt : &module->top->symt; + sym->container = symt_ptr_to_symref(compiland ? &compiland->symt : &module->top->symt); sym->type = type; sym->u.var = loc; if (type && size && symt_get_info_from_symref(module, type, TI_GET_LENGTH, &tsz)) @@ -312,7 +312,7 @@ struct symt_data* symt_new_global_variable(struct module* module, } symt_add_module_ht(module, (struct symt_ht*)sym); p = vector_add(compiland ? &compiland->vchildren : &module->top->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } return sym; } @@ -331,10 +331,10 @@ static struct symt_function* init_function_or_inlinesite(struct module* module, { sym->symt.tag = tag; sym->hash_elt.name = pool_strdup(&module->pool, name); - sym->container = container; + sym->container = symt_ptr_to_symref(container); sym->type = sig_type; vector_init(&sym->vlines, sizeof(struct line_info), 0); - vector_init(&sym->vchildren, sizeof(struct symt*), 0); + vector_init(&sym->vchildren, sizeof(symref_t), 0); sym->user = user; sym->num_ranges = num_ranges; } @@ -354,7 +354,7 @@ struct symt_function* symt_new_function(struct module* module,
if ((sym = init_function_or_inlinesite(module, SymTagFunction, &compiland->symt, name, sig_type, user, 1))) { - struct symt** p; + symref_t* p; sym->ranges[0].low = addr; sym->ranges[0].high = addr + size; sym->next_inlinesite = NULL; /* first of list */ @@ -362,7 +362,7 @@ struct symt_function* symt_new_function(struct module* module, if (compiland) { p = vector_add(&compiland->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } } return sym; @@ -381,7 +381,7 @@ struct symt_function* symt_new_inlinesite(struct module* module, TRACE_(dbghelp_symt)("Adding inline site %s\n", debugstr_a(name)); if ((sym = init_function_or_inlinesite(module, SymTagInlineSite, container, name, sig_type, user, num_ranges))) { - struct symt** p; + symref_t* p; assert(container);
/* chain inline sites */ @@ -394,7 +394,7 @@ struct symt_function* symt_new_inlinesite(struct module* module, assert(container->tag == SymTagBlock); p = vector_add(&((struct symt_block*)container)->vchildren, &module->pool); } - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } return sym; } @@ -472,7 +472,7 @@ struct symt_data* symt_add_func_local(struct module* module, symref_t type, const char* name) { struct symt_data* locsym; - struct symt** p; + symref_t* p;
TRACE_(dbghelp_symt)("Adding local symbol (%s:%s): %s %Ix\n", debugstr_w(module->modulename), debugstr_a(func->hash_elt.name), @@ -486,14 +486,14 @@ struct symt_data* symt_add_func_local(struct module* module, locsym->hash_elt.name = pool_strdup(&module->pool, name); locsym->hash_elt.next = NULL; locsym->kind = dt; - locsym->container = block ? &block->symt : &func->symt; + locsym->container = symt_ptr_to_symref(block ? &block->symt : &func->symt); locsym->type = type; locsym->u.var = *loc; if (block) p = vector_add(&block->vchildren, &module->pool); else p = vector_add(&func->vchildren, &module->pool); - *p = &locsym->symt; + if (p) *p = symt_ptr_to_symref(&locsym->symt); if (dt == DataIsStaticLocal) symt_add_module_addr(module, (struct symt_ht*)locsym); return locsym; @@ -511,7 +511,7 @@ struct symt_data* symt_add_func_constant(struct module* module, VARIANT* v) { struct symt_data* locsym; - struct symt** p; + symref_t* p;
TRACE_(dbghelp_symt)("Adding local constant (%s:%s): %s %Ix\n", debugstr_w(module->modulename), debugstr_a(func->hash_elt.name), @@ -524,14 +524,14 @@ struct symt_data* symt_add_func_constant(struct module* module, locsym->hash_elt.name = pool_strdup(&module->pool, name); locsym->hash_elt.next = NULL; locsym->kind = DataIsConstant; - locsym->container = block ? &block->symt : &func->symt; + locsym->container = symt_ptr_to_symref(block ? &block->symt : &func->symt); locsym->type = type; locsym->u.value = *v; if (block) p = vector_add(&block->vchildren, &module->pool); else p = vector_add(&func->vchildren, &module->pool); - *p = &locsym->symt; + if (p) *p = symt_ptr_to_symref(&locsym->symt); return locsym; }
@@ -541,7 +541,7 @@ struct symt_block* symt_open_func_block(struct module* module, unsigned num_ranges) { struct symt_block* block; - struct symt** p; + symref_t* p;
assert(symt_check_tag(&func->symt, SymTagFunction) || symt_check_tag(&func->symt, SymTagInlineSite)); assert(num_ranges > 0); @@ -550,13 +550,13 @@ struct symt_block* symt_open_func_block(struct module* module, block = pool_alloc(&module->pool, offsetof(struct symt_block, ranges[num_ranges])); block->symt.tag = SymTagBlock; block->num_ranges = num_ranges; - block->container = parent_block ? &parent_block->symt : &func->symt; - vector_init(&block->vchildren, sizeof(struct symt*), 0); + block->container = symt_ptr_to_symref(parent_block ? &parent_block->symt : &func->symt); + vector_init(&block->vchildren, sizeof(symref_t), 0); if (parent_block) p = vector_add(&parent_block->vchildren, &module->pool); else p = vector_add(&func->vchildren, &module->pool); - *p = &block->symt; + if (p) *p = symt_ptr_to_symref(&block->symt);
return block; } @@ -565,10 +565,15 @@ struct symt_block* symt_close_func_block(struct module* module, const struct symt_function* func, struct symt_block* block) { + struct symt *container; + assert(symt_check_tag(&func->symt, SymTagFunction) || symt_check_tag(&func->symt, SymTagInlineSite));
- return (block->container->tag == SymTagBlock) ? - CONTAINING_RECORD(block->container, struct symt_block, symt) : NULL; + container = SYMT_SYMREF_TO_PTR(block->container); + assert(container); + + return (container->tag == SymTagBlock) ? + CONTAINING_RECORD(container, struct symt_block, symt) : NULL; }
struct symt_hierarchy_point* symt_add_function_point(struct module* module, @@ -577,17 +582,17 @@ struct symt_hierarchy_point* symt_add_function_point(struct module* module, const struct location* loc, const char* name) { - struct symt_hierarchy_point*sym; - struct symt** p; + struct symt_hierarchy_point *sym; + symref_t *p;
if ((sym = pool_alloc(&module->pool, sizeof(*sym)))) { - sym->symt.tag = point; - sym->parent = &func->symt; - sym->loc = *loc; + sym->symt.tag = point; + sym->container = symt_ptr_to_symref(&func->symt); + sym->loc = *loc; sym->hash_elt.name = name ? pool_strdup(&module->pool, name) : NULL; p = vector_add(&func->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } return sym; } @@ -606,16 +611,16 @@ struct symt_thunk* symt_new_thunk(struct module* module, { sym->symt.tag = SymTagThunk; sym->hash_elt.name = pool_strdup(&module->pool, name); - sym->container = &compiland->symt; + sym->container = symt_ptr_to_symref(&compiland->symt); sym->address = addr; sym->size = size; sym->ordinal = ord; symt_add_module_ht(module, (struct symt_ht*)sym); if (compiland) { - struct symt** p; + symref_t *p; p = vector_add(&compiland->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } } return sym; @@ -636,15 +641,15 @@ struct symt_data* symt_new_constant(struct module* module, sym->symt.tag = SymTagData; sym->hash_elt.name = pool_strdup(&module->pool, name); sym->kind = DataIsConstant; - sym->container = compiland ? &compiland->symt : &module->top->symt; + sym->container = symt_ptr_to_symref(compiland ? &compiland->symt : &module->top->symt); sym->type = type; sym->u.value = *v; symt_add_module_ht(module, (struct symt_ht*)sym); if (compiland) { - struct symt** p; + symref_t *p; p = vector_add(&compiland->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } } return sym; @@ -665,13 +670,13 @@ struct symt_hierarchy_point* symt_new_label(struct module* module, sym->hash_elt.name = pool_strdup(&module->pool, name); sym->loc.kind = loc_absolute; sym->loc.offset = address; - sym->parent = compiland ? &compiland->symt : NULL; + sym->container = compiland ? symt_ptr_to_symref(&compiland->symt) : 0; symt_add_module_ht(module, (struct symt_ht*)sym); if (compiland) { - struct symt** p; + symref_t *p; p = vector_add(&compiland->vchildren, &module->pool); - *p = &sym->symt; + if (p) *p = symt_ptr_to_symref(&sym->symt); } } return sym; @@ -795,8 +800,8 @@ static BOOL symt_fill_sym_info(struct module_pair* pair, break; case DataIsConstant: sym_info->Flags |= SYMFLAG_VALUEPRESENT; - if (data->container && - (data->container->tag == SymTagFunction || data->container->tag == SymTagBlock)) + if (symt_check_tag(SYMT_SYMREF_TO_PTR(data->container), SymTagFunction) || + symt_check_tag(SYMT_SYMREF_TO_PTR(data->container), SymTagBlock)) sym_info->Flags |= SYMFLAG_LOCAL; switch (V_VT(&data->u.value)) { @@ -1093,7 +1098,7 @@ 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) { - struct symt* lsym = NULL; + const struct symt* lsym; DWORD_PTR pc = pair->pcs->localscope_pc; unsigned int i; WCHAR* nameW; @@ -1101,7 +1106,8 @@ static BOOL symt_enum_locals_helper(struct module_pair* pair,
for (i=0; i<vector_length(v); i++) { - lsym = *(struct symt**)vector_at(v, i); + lsym = SYMT_SYMREF_TO_PTR(*(symref_t*)vector_at(v, i)); + switch (lsym->tag) { case SymTagBlock: @@ -1240,9 +1246,9 @@ struct symt* symt_get_upper_inlined(struct symt_function* inlined) { assert(symt); if (symt->tag == SymTagBlock) - symt = ((struct symt_block*)symt)->container; + symt = SYMT_SYMREF_TO_PTR(((struct symt_block*)symt)->container); else - symt = ((struct symt_function*)symt)->container; + symt = SYMT_SYMREF_TO_PTR(((struct symt_function*)symt)->container); } while (symt->tag == SymTagBlock); assert(symt->tag == SymTagFunction || symt->tag == SymTagInlineSite); return symt; @@ -1638,7 +1644,8 @@ BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
for (i = 0; i < vector_length(v); i++) { - struct symt* lsym = *(struct symt**)vector_at(v, i); + struct symt* lsym = SYMT_SYMREF_TO_PTR(*(symref_t*)vector_at(v, i)); + switch (lsym->tag) { case SymTagBlock: /* no recursion */ diff --git a/dlls/dbghelp/type.c b/dlls/dbghelp/type.c index e0a79086ccf..f0469845277 100644 --- a/dlls/dbghelp/type.c +++ b/dlls/dbghelp/type.c @@ -159,10 +159,12 @@ BOOL symt_get_address(const struct symt* type, ULONG64* addr) case SymTagFuncDebugStart: case SymTagFuncDebugEnd: case SymTagLabel: - if (!((const struct symt_hierarchy_point*)type)->parent || - !symt_get_address(((const struct symt_hierarchy_point*)type)->parent, addr)) - *addr = 0; - *addr += ((const struct symt_hierarchy_point*)type)->loc.offset; + *addr = 0; + if (SYMT_SYMREF_TO_PTR(((const struct symt_hierarchy_point*)type)->container)) + { + if (symt_get_address(SYMT_SYMREF_TO_PTR(((const struct symt_hierarchy_point*)type)->container), addr)) + *addr += ((const struct symt_hierarchy_point*)type)->loc.offset; + } break; case SymTagThunk: *addr = ((const struct symt_thunk*)type)->address; @@ -308,13 +310,13 @@ BOOL symt_add_udt_element(struct module* module, struct symt_udt* udt_type, m->hash_elt.next = NULL;
m->kind = DataIsMember; - m->container = &module->top->symt; /* native defines lexical parent as module, not udt... */ + m->container = symt_ptr_to_symref(&module->top->symt); /* native defines lexical parent as module, not udt... */ m->type = elt_type; m->u.member.offset = offset; m->u.member.bit_offset = bit_offset; m->u.member.bit_length = bit_size; p = vector_add(&udt_type->vchildren, &module->pool); - *p = &m->symt; + if (p) *p = &m->symt;
return TRUE; } @@ -354,7 +356,7 @@ BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type, e->hash_elt.name = pool_strdup(&module->pool, name); e->hash_elt.next = NULL; e->kind = DataIsConstant; - e->container = &enum_type->symt; + e->container = symt_ptr_to_symref(&enum_type->symt); e->type = symt_ptr_to_symref(enum_type->base_type); e->u.value = *variant;
@@ -672,7 +674,7 @@ BOOL symt_get_info(struct module* module, const struct symt* type, case TI_FINDCHILDREN: { const struct vector* v; - struct symt** pt; + symref_t* symref; unsigned i; TI_FINDCHILDREN_PARAMS* tifp = pInfo;
@@ -699,14 +701,14 @@ BOOL symt_get_info(struct module* module, const struct symt* type, /* for those, CHILDRENCOUNT returns 0 */ return tifp->Count == 0; default: - FIXME("Unsupported sym-tag %s for find-children\n", + FIXME("Unsupported sym-tag %s for find-children\n", symt_get_tag_str(type->tag)); return FALSE; } for (i = 0; i < tifp->Count; i++) { - if (!(pt = vector_at(v, tifp->Start + i))) return FALSE; - tifp->ChildId[i] = symt_ptr_to_index(module, *pt); + if (!(symref = (symref_t *)vector_at(v, tifp->Start + i))) return FALSE; + tifp->ChildId[i] = symt_symref_to_index(module, *symref); } } break; @@ -885,25 +887,25 @@ BOOL symt_get_info(struct module* module, const struct symt* type, switch (type->tag) { case SymTagCompiland: - X(DWORD) = symt_ptr_to_index(module, &((const struct symt_compiland*)type)->container->symt); + X(DWORD) = symt_symref_to_index(module, ((const struct symt_compiland*)type)->container); break; case SymTagBlock: - X(DWORD) = symt_ptr_to_index(module, ((const struct symt_block*)type)->container); + X(DWORD) = symt_symref_to_index(module, ((const struct symt_block*)type)->container); break; case SymTagData: - X(DWORD) = symt_ptr_to_index(module, ((const struct symt_data*)type)->container); + X(DWORD) = symt_symref_to_index(module, ((const struct symt_data*)type)->container); break; case SymTagFunction: case SymTagInlineSite: - X(DWORD) = symt_ptr_to_index(module, ((const struct symt_function*)type)->container); + X(DWORD) = symt_symref_to_index(module, ((const struct symt_function*)type)->container); break; case SymTagThunk: - X(DWORD) = symt_ptr_to_index(module, ((const struct symt_thunk*)type)->container); + X(DWORD) = symt_symref_to_index(module, ((const struct symt_thunk*)type)->container); break; case SymTagFuncDebugStart: case SymTagFuncDebugEnd: case SymTagLabel: - X(DWORD) = symt_ptr_to_index(module, ((const struct symt_hierarchy_point*)type)->parent); + X(DWORD) = symt_symref_to_index(module, ((const struct symt_hierarchy_point*)type)->container); break; case SymTagUDT: case SymTagEnum: @@ -1086,7 +1088,8 @@ BOOL symt_get_info(struct module* module, const struct symt* type, MODULE_FORMAT_VTABLE_INDEX(loc_compute)))) { iter.modfmt->vtable->loc_compute(iter.modfmt, - (const struct symt_function*)((const struct symt_data*)type)->container, &loc); + (const struct symt_function*)SYMT_SYMREF_TO_PTR(((const struct symt_data*)type)->container), + &loc); break; } if (loc.kind != loc_absolute) return FALSE;