[PATCH 3/3] [DbgHelp]: for mingw32 (stabs debug info), parse the FileHeader's symbol table to offset properly the global variables
Eric Pouech
eric.pouech at orange.fr
Wed Dec 9 13:55:27 CST 2009
A+
---
dlls/dbghelp/pe_module.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c
index 44a4d6a..3b9cceb 100644
--- a/dlls/dbghelp/pe_module.c
+++ b/dlls/dbghelp/pe_module.c
@@ -36,6 +36,69 @@
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
/******************************************************************
+ * pe_load_symbol_table
+ *
+ * Use the COFF symbol table (if any) from the IMAGE_FILE_HEADER to set the absolute address
+ * of global symbols.
+ * Mingw32 requires this for stabs debug information as address for global variables isn't filled in
+ * (this is similar to what is done in elf_module.c when using the .symtab ELF section)
+ */
+static BOOL pe_load_symbol_table(struct module* module, IMAGE_NT_HEADERS* nth, void* mapping)
+{
+ const IMAGE_SYMBOL* isym;
+ int i, numsym, naux;
+ const char* strtable;
+ char tmp[9];
+ const char* name;
+ struct hash_table_iter hti;
+ void* ptr;
+ struct symt_data* sym;
+ const IMAGE_SECTION_HEADER* sect;
+
+ numsym = nth->FileHeader.NumberOfSymbols;
+ if (!nth->FileHeader.PointerToSymbolTable || !numsym)
+ return TRUE;
+ isym = (const IMAGE_SYMBOL*)((char*)mapping + nth->FileHeader.PointerToSymbolTable);
+ /* FIXME: no way to get strtable size */
+ strtable = (const char*)&isym[numsym];
+ sect = IMAGE_FIRST_SECTION(nth);
+
+ for (i = 0; i < numsym; i+= naux, isym += naux)
+ {
+ if (isym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL &&
+ isym->SectionNumber > 0 && isym->SectionNumber <= nth->FileHeader.NumberOfSections)
+ {
+ if (isym->N.Name.Short)
+ {
+ name = memcpy(tmp, isym->N.ShortName, 8);
+ tmp[8] = '\0';
+ }
+ else name = strtable + isym->N.Name.Long;
+ if (name[0] == '_') name++;
+ hash_table_iter_init(&module->ht_symbols, &hti, name);
+ while ((ptr = hash_table_iter_up(&hti)))
+ {
+ sym = GET_ENTRY(ptr, struct symt_data, hash_elt);
+ if (sym->symt.tag == SymTagData &&
+ (sym->kind == DataIsGlobal || sym->kind == DataIsFileStatic) &&
+ !strcmp(sym->hash_elt.name, name))
+ {
+ TRACE("Changing absolute address for %d.%s: %lx -> %s\n",
+ isym->SectionNumber, name, sym->u.var.offset,
+ wine_dbgstr_longlong(module->module.BaseOfImage +
+ sect[isym->SectionNumber - 1].VirtualAddress + isym->Value));
+ sym->u.var.offset = module->module.BaseOfImage +
+ sect[isym->SectionNumber - 1].VirtualAddress + isym->Value;
+ break;
+ }
+ }
+ }
+ naux = isym->NumberOfAuxSymbols + 1;
+ }
+ return TRUE;
+}
+
+/******************************************************************
* pe_load_stabs
*
* look for stabs information in PE header (it's how the mingw compiler provides
@@ -74,6 +137,7 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module,
RtlImageRvaToVa(nth, mapping, stabstr, NULL),
stabstrsize,
NULL, NULL);
+ if (ret) pe_load_symbol_table(module, nth, mapping);
}
TRACE("%s the STABS debug info\n", ret ? "successfully loaded" : "failed to load");
More information about the wine-patches
mailing list