Commit ad921b3c authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: Return matched information for path_find_symbol_file.

parent f824a72c
......@@ -758,9 +758,9 @@ extern DWORD pdb_get_file_indexinfo(void* image, DWORD size, SYMSRV_INDEX_INFOW*
extern DWORD dbg_get_file_indexinfo(void* image, DWORD size, SYMSRV_INDEX_INFOW* info);
/* path.c */
extern BOOL path_find_symbol_file(const struct process* pcs, const struct module* module,
extern BOOL path_find_symbol_file(const struct process *pcs, const struct module *module,
PCSTR full_path, BOOL is_pdb, const GUID* guid, DWORD dw1, DWORD dw2,
WCHAR *buffer, BOOL* is_unmatched);
SYMSRV_INDEX_INFOW *info, BOOL *unmatched);
extern WCHAR *get_dos_file_name(const WCHAR *filename) __WINE_DEALLOC(HeapFree, 3) __WINE_MALLOC;
extern BOOL search_dll_path(const struct process* process, const WCHAR *name, WORD machine,
BOOL (*match)(void*, HANDLE, const WCHAR*), void *param);
......
......@@ -455,7 +455,7 @@ BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR searchPath, PCSTR full_path
struct module_find
{
BOOL is_pdb;
BOOL is_pdb;
/* pdb: guid PDB guid (if DS PDB file)
* or dw1 PDB timestamp (if JG PDB file)
* dw2 PDB age
......@@ -465,7 +465,8 @@ struct module_find
const GUID* guid;
DWORD dw1;
DWORD dw2;
WCHAR filename[MAX_PATH];
SYMSRV_INDEX_INFOW *info;
WCHAR *buffer; /* MAX_PATH + 1 */
unsigned matched;
};
......@@ -483,48 +484,56 @@ static BOOL CALLBACK module_find_cb(PCWSTR buffer, PVOID user)
info.sizeofstruct = sizeof(info);
if (!SymSrvGetFileIndexInfoW(buffer, &info, 0))
return FALSE;
matched++;
if (!memcmp(&info.guid, mf->guid, sizeof(GUID))) matched++;
if (info.timestamp == mf->dw1) matched++;
if (info.age == mf->dw2) matched++;
if (matched > mf->matched)
{
lstrcpyW(mf->filename, buffer);
size_t len = min(wcslen(buffer), MAX_PATH);
memcpy(mf->buffer, buffer, len * sizeof(WCHAR));
mf->buffer[len] = L'\0';
mf->matched = matched;
mf->info->guid = info.guid;
mf->info->timestamp = info.timestamp;
mf->info->age = info.age;
}
/* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
* convention to stop/continue enumeration. sigh.
*/
return mf->matched == 3;
return mf->matched == 4;
}
BOOL path_find_symbol_file(const struct process* pcs, const struct module* module,
PCSTR full_path, BOOL is_pdb, const GUID* guid, DWORD dw1, DWORD dw2,
WCHAR *buffer, BOOL* is_unmatched)
SYMSRV_INDEX_INFOW *info, BOOL* is_unmatched)
{
struct module_find mf;
WCHAR full_pathW[MAX_PATH];
WCHAR* ptr;
WCHAR *ptr;
const WCHAR* filename;
WCHAR* searchPath = pcs->search_path;
WCHAR *searchPath = pcs->search_path;
WCHAR buffer[MAX_PATH];
TRACE("(pcs = %p, full_path = %s, guid = %s, dw1 = 0x%08lx, dw2 = 0x%08lx, buffer = %p)\n",
pcs, debugstr_a(full_path), debugstr_guid(guid), dw1, dw2, buffer);
TRACE("(pcs = %p, full_path = %s, guid = %s, dw1 = 0x%08lx, dw2 = 0x%08lx)\n",
pcs, debugstr_a(full_path), debugstr_guid(guid), dw1, dw2);
mf.info = info;
mf.guid = guid;
mf.dw1 = dw1;
mf.dw2 = dw2;
mf.matched = 0;
mf.buffer = is_pdb ? info->pdbfile : info->dbgfile;
MultiByteToWideChar(CP_ACP, 0, full_path, -1, full_pathW, MAX_PATH);
filename = file_name(full_pathW);
MultiByteToWideChar(CP_ACP, 0, full_path, -1, info->file, MAX_PATH);
filename = file_name(info->file);
mf.is_pdb = is_pdb;
*is_unmatched = FALSE;
/* first check full path to file */
if (module_find_cb(full_pathW, &mf))
if (is_pdb && module_find_cb(info->file, &mf))
{
lstrcpyW( buffer, full_pathW );
wcscpy( info->pdbfile, info->file );
return TRUE;
}
......@@ -548,28 +557,29 @@ BOOL path_find_symbol_file(const struct process* pcs, const struct module* modul
while (searchPath)
{
size_t len;
ptr = wcschr(searchPath, ';');
if (ptr)
len = (ptr) ? ptr - searchPath : wcslen(searchPath);
if (len < ARRAY_SIZE(buffer))
{
memcpy(buffer, searchPath, (ptr - searchPath) * sizeof(WCHAR));
buffer[ptr - searchPath] = '\0';
searchPath = ptr + 1;
memcpy(buffer, searchPath, len * sizeof(WCHAR));
buffer[len] = '\0';
/* return first fully matched file */
if (do_searchW(filename, buffer, FALSE, module_find_cb, &mf)) return TRUE;
}
else
{
lstrcpyW(buffer, searchPath);
searchPath = NULL;
}
/* return first fully matched file */
if (do_searchW(filename, buffer, FALSE, module_find_cb, &mf)) return TRUE;
ERR("Too long search element %ls\n", searchPath);
searchPath = ptr ? ptr + 1 : NULL;
}
/* if no fully matching file is found, return the best matching file if any */
if ((dbghelp_options & SYMOPT_LOAD_ANYTHING) && mf.matched)
{
lstrcpyW( buffer, mf.filename );
*is_unmatched = TRUE;
return TRUE;
}
mf.buffer[0] = L'\0';
return FALSE;
}
......
......@@ -542,15 +542,15 @@ static BOOL pe_load_dwarf(struct module* module)
static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
const char* dbg_name, DWORD timestamp)
{
WCHAR tmp[MAX_PATH];
HANDLE hFile = INVALID_HANDLE_VALUE, hMap = 0;
const BYTE* dbg_mapping = NULL;
BOOL ret = FALSE;
SYMSRV_INDEX_INFOW info;
TRACE("Processing DBG file %s\n", debugstr_a(dbg_name));
if (path_find_symbol_file(pcs, module, dbg_name, FALSE, NULL, timestamp, 0, tmp, &module->module.DbgUnmatched) &&
(hFile = CreateFileW(tmp, GENERIC_READ, FILE_SHARE_READ, NULL,
if (path_find_symbol_file(pcs, module, dbg_name, FALSE, NULL, timestamp, 0, &info, &module->module.DbgUnmatched) &&
(hFile = CreateFileW(info.dbgfile, 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))
......@@ -573,7 +573,7 @@ static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
hdr->DebugDirectorySize / sizeof(*dbg));
}
else
ERR("Couldn't find .DBG file %s (%s)\n", debugstr_a(dbg_name), debugstr_w(tmp));
ERR("Couldn't find .DBG file %s (%s)\n", debugstr_a(dbg_name), debugstr_w(info.dbgfile));
if (dbg_mapping) UnmapViewOfFile(dbg_mapping);
if (hMap) CloseHandle(hMap);
......
......@@ -1574,10 +1574,8 @@ static void test_load_modules_path(void)
"Expected %ls as loaded image file, got '%ls' instead\n", L"bar.dll", im.LoadedImageName);
if (test->found_file == -1)
{
todo_wine
ok(im.SymType == SymNone, "Unexpected symtype %x\n", im.SymType);
ok(!im.LoadedPdbName[0], "Expected empty loaded pdb file, got '%ls' instead\n", im.LoadedPdbName);
todo_wine
ok(im.PdbAge == 0x0030cafe, "Expected %x as pdb-age, got %lx instead\n", 0x0030cafe, im.PdbAge);
ok(!im.PdbUnmatched, "Expecting matched PDB\n");
}
......@@ -1586,16 +1584,15 @@ static void test_load_modules_path(void)
todo_wine_if(i == 4 || i == 5 || i == 7 || i == 8 || i == 11)
ok(im.SymType == SymPdb, "Unexpected symtype %x\n", im.SymType);
make_path(filename, topdir, NULL, test_files[test->found_file].module_path);
todo_wine
todo_wine_if(i == 2 || i == 4 || i == 5 || i == 7 || i == 8 || i == 11 || i == 21)
ok(!wcscmp(im.LoadedPdbName, filename),
"Expected %ls as loaded pdb file, got '%ls' instead\n", test_files[test->found_file].module_path, im.LoadedPdbName);
todo_wine
todo_wine_if(i == 11 || i == 21)
ok(im.PdbAge == test_files[test->found_file].age_or_timestamp,
"Expected %lx as pdb-age, got %lx instead\n", test_files[test->found_file].age_or_timestamp, im.PdbAge);
todo_wine_if(i == 11)
ok(im.PdbUnmatched == !(test_files[test->found_file].age_or_timestamp == 0x0030cafe), "Expecting matched PDB\n");
}
todo_wine_if(i == 4 || i == 5 || i == 7 || i == 8 || i == 9 || i == 10 || i == 11 || i == 13 || i == 18 || i == 19)
ok(IsEqualGUID(&im.PdbSig70, &guid1), "Unexpected PDB GUID\n");
ret = SymCleanup(dummy);
ok(ret, "SymCleanup failed: %lu\n", GetLastError());
......@@ -1811,7 +1808,7 @@ static void test_load_modules_details(void)
todo_wine_if(test->options & SYMOPT_DEFERRED_LOADS)
ok(!wcsicmp(im.LoadedImageName, (test->options & SYMOPT_DEFERRED_LOADS) ? L"" : loaded_img_name),
"Unexpected loaded image name '%ls' (%ls)\n", im.LoadedImageName, loaded_img_name);
todo_wine_if(i == 3 || i == 4 || i == 6 || i == 8 || i == 12 || i == 14)
todo_wine_if(i == 3 || i == 4 || i == 6 || i == 8)
ok(im.SymType == test->sym_type, "Unexpected module type %u\n", im.SymType);
todo_wine_if(i == 8 || i == 10)
ok(!im.TypeInfo, "No type info present\n");
......@@ -1839,10 +1836,8 @@ static void test_load_modules_details(void)
ok(val < ARRAY_SIZE(test_files), "Incorrect index\n");
ok(!im.PdbUnmatched, "Unexpected value\n");
ok(!im.DbgUnmatched, "Unexpected value\n");
todo_wine
ok(IsEqualGUID(&im.PdbSig70, test_files[val].guid), "Unexpected value %s %s\n",
wine_dbgstr_guid(&im.PdbSig70), wine_dbgstr_guid(test_files[val].guid));
todo_wine
ok(im.PdbAge == test_files[val].age_or_timestamp + 1, "Unexpected value\n");
}
else if (has_mismatch(test->mismatch_in, 'D', &val))
......@@ -1874,6 +1869,7 @@ static void test_load_modules_details(void)
SymFromNameW(dummy, L"foo", sym);
}
ret = SymAddSymbol(dummy, base, "winetest_symbol_virtual", base + 4242, 13, 0);
todo_wine_if(i >= 12 && i <= 15) { /* temp */
ok(ret, "Failed to add symbol\n");
memset(sym, 0, sizeof(*sym));
sym->SizeOfStruct = sizeof(*sym);
......@@ -1888,7 +1884,7 @@ static void test_load_modules_details(void)
ret = SymFromNameW(dummy, sym_name, (void*)sym);
ok(ret, "Couldn't find symbol %ls\n", sym_name);
}
} /* temp */
ret = SymCleanup(dummy);
ok(ret, "SymCleanup failed: %lu\n", GetLastError());
for (ptr = test->test_files; *ptr; ptr++)
......
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