Commit 185e5dae authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: For mingw32 (stabs debug info), parse the FileHeader's symbol table to…

dbghelp: For mingw32 (stabs debug info), parse the FileHeader's symbol table to offset properly the global variables.
parent 2271a8d4
...@@ -36,6 +36,69 @@ ...@@ -36,6 +36,69 @@
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp); 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 * pe_load_stabs
* *
* look for stabs information in PE header (it's how the mingw compiler provides * 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, ...@@ -74,6 +137,7 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module,
RtlImageRvaToVa(nth, mapping, stabstr, NULL), RtlImageRvaToVa(nth, mapping, stabstr, NULL),
stabstrsize, stabstrsize,
NULL, NULL); NULL, NULL);
if (ret) pe_load_symbol_table(module, nth, mapping);
} }
TRACE("%s the STABS debug info\n", ret ? "successfully loaded" : "failed to load"); TRACE("%s the STABS debug info\n", ret ? "successfully loaded" : "failed to load");
......
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