dbghelp: Improve the symbol loader for .DBG files.

When looking for a .DBG file, first look for a .DBG file matching all
attributes, then for a .DBG partially matching the attributes.
This commit is contained in:
Eric Pouech 2008-08-29 21:50:53 +02:00 committed by Alexandre Julliard
parent d600115387
commit 2994e98850
4 changed files with 57 additions and 41 deletions

View File

@ -303,7 +303,8 @@ enum module_type
DMT_UNKNOWN, /* for lookup, not actually used for a module */
DMT_ELF, /* a real ELF shared module */
DMT_PE, /* a native or builtin PE module */
DMT_PDB, /* PDB file */
DMT_PDB, /* .PDB file */
DMT_DBG, /* .DBG file */
};
struct process;

View File

@ -36,6 +36,7 @@ const WCHAR S_ElfW[] = {'<','e','l','f','>','\0'};
const WCHAR S_WineLoaderW[] = {'<','w','i','n','e','-','l','o','a','d','e','r','>','\0'};
static const WCHAR S_DotSoW[] = {'.','s','o','\0'};
static const WCHAR S_DotPdbW[] = {'.','p','d','b','\0'};
static const WCHAR S_DotDbgW[] = {'.','d','b','g','\0'};
const WCHAR S_WinePThreadW[] = {'w','i','n','e','-','p','t','h','r','e','a','d','\0'};
const WCHAR S_WineKThreadW[] = {'w','i','n','e','-','k','t','h','r','e','a','d','\0'};
const WCHAR S_SlashW[] = {'/','\0'};
@ -424,6 +425,9 @@ enum module_type module_get_type_by_name(const WCHAR* name)
if (len > 4 && !strncmpiW(name + len - 4, S_DotPdbW, 4))
return DMT_PDB;
if (len > 4 && !strncmpiW(name + len - 4, S_DotDbgW, 4))
return DMT_DBG;
/* wine-[kp]thread is also an ELF module */
if (((len > 12 && name[len - 13] == '/') || len == 12) &&
(!strncmpiW(name + len - 12, S_WinePThreadW, 12) ||

View File

@ -453,6 +453,9 @@ static BOOL CALLBACK sffip_cb(PCWSTR buffer, PVOID user)
}
}
break;
case DMT_DBG:
FIXME("NIY\n");
break;
default:
FIXME("What the heck??\n");
return FALSE;
@ -581,7 +584,7 @@ struct module_find
static BOOL CALLBACK module_find_cb(PCWSTR buffer, PVOID user)
{
struct module_find* mf = (struct module_find*)user;
DWORD size, checksum;
DWORD size, checksum, timestamp;
unsigned matched = 0;
/* the matching weights:
@ -685,6 +688,36 @@ static BOOL CALLBACK module_find_cb(PCWSTR buffer, PVOID user)
}
}
break;
case DMT_DBG:
{
HANDLE hFile, hMap;
void* mapping;
timestamp = ~mf->dw1;
hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return FALSE;
if ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
{
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
{
const IMAGE_SEPARATE_DEBUG_HEADER* hdr;
hdr = (const IMAGE_SEPARATE_DEBUG_HEADER*)mapping;
if (hdr->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
{
matched++;
timestamp = hdr->TimeDateStamp;
}
UnmapViewOfFile(mapping);
}
CloseHandle(hMap);
}
CloseHandle(hFile);
if (timestamp == mf->dw1) matched++;
else WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer));
}
break;
default:
FIXME("What the heck??\n");
return FALSE;

View File

@ -79,12 +79,6 @@ static BOOL pe_load_stabs(const struct process* pcs, struct module* module,
return ret;
}
static BOOL CALLBACK dbg_match(const char* file, void* user)
{
/* accept first file */
return FALSE;
}
/******************************************************************
* pe_load_dbg_file
*
@ -96,51 +90,35 @@ static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
char tmp[MAX_PATH];
HANDLE hFile = INVALID_HANDLE_VALUE, hMap = 0;
const BYTE* dbg_mapping = NULL;
const IMAGE_SEPARATE_DEBUG_HEADER* hdr;
const IMAGE_DEBUG_DIRECTORY* dbg;
BOOL ret = FALSE;
WINE_TRACE("Processing DBG file %s\n", debugstr_a(dbg_name));
TRACE("Processing DBG file %s\n", debugstr_a(dbg_name));
if (SymFindFileInPath(pcs->handle, NULL, dbg_name, NULL, 0, 0, 0, tmp, dbg_match, NULL) &&
if (path_find_symbol_file(pcs, dbg_name, NULL, timestamp, 0, tmp) &&
(hFile = CreateFileA(tmp, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE &&
((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
((dbg_mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
{
const IMAGE_SEPARATE_DEBUG_HEADER* hdr;
const IMAGE_SECTION_HEADER* sectp;
const IMAGE_DEBUG_DIRECTORY* dbg;
hdr = (const IMAGE_SEPARATE_DEBUG_HEADER*)dbg_mapping;
if (hdr->TimeDateStamp != timestamp)
{
WINE_ERR("Warning - %s has incorrect internal timestamp\n",
debugstr_a(dbg_name));
/*
* Well, sometimes this happens to DBG files which ARE REALLY the
* right .DBG files but nonetheless this check fails. Anyway,
* WINDBG (debugger for Windows by Microsoft) loads debug symbols
* which have incorrect timestamps.
*/
}
if (hdr->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
{
/* section headers come immediately after debug header */
const IMAGE_SECTION_HEADER *sectp =
(const IMAGE_SECTION_HEADER*)(hdr + 1);
/* and after that and the exported names comes the debug directory */
dbg = (const IMAGE_DEBUG_DIRECTORY*)
(dbg_mapping + sizeof(*hdr) +
hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
hdr->ExportedNamesSize);
/* section headers come immediately after debug header */
sectp = (const IMAGE_SECTION_HEADER*)(hdr + 1);
/* and after that and the exported names comes the debug directory */
dbg = (const IMAGE_DEBUG_DIRECTORY*)
(dbg_mapping + sizeof(*hdr) +
hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
hdr->ExportedNamesSize);
ret = pe_load_debug_directory(pcs, module, dbg_mapping, sectp,
hdr->NumberOfSections, dbg,
hdr->DebugDirectorySize / sizeof(*dbg));
}
else
ERR("Wrong signature in .DBG file %s\n", debugstr_a(tmp));
ret = pe_load_debug_directory(pcs, module, dbg_mapping, sectp,
hdr->NumberOfSections, dbg,
hdr->DebugDirectorySize / sizeof(*dbg));
}
else
WINE_ERR("-Unable to peruse .DBG file %s (%s)\n", debugstr_a(dbg_name), debugstr_a(tmp));
ERR("Couldn't find .DBG file %s (%s)\n", debugstr_a(dbg_name), debugstr_a(tmp));
if (dbg_mapping) UnmapViewOfFile(dbg_mapping);
if (hMap) CloseHandle(hMap);