Commit 2e7d3c38 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: SymInitializeW.

- implemented SymInitializeW (and made SymInitialize call it) - implemented Sym{SG}etSearchPathW (and made Sym{SG}etSearchPath call them) - per process search path is now stored as unicode string
parent 572e18ef
......@@ -25,6 +25,7 @@
#include "psapi.h"
#include "wine/debug.h"
#include "wdbgexts.h"
#include "winnls.h"
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
......@@ -115,10 +116,10 @@ BOOL validate_addr64(DWORD64 addr)
}
/******************************************************************
* SymSetSearchPath (DBGHELP.@)
* SymSetSearchPathW (DBGHELP.@)
*
*/
BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath)
BOOL WINAPI SymSetSearchPathW(HANDLE hProcess, PCWSTR searchPath)
{
struct process* pcs = process_find_by_handle(hProcess);
......@@ -126,24 +127,67 @@ BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath)
if (!searchPath) return FALSE;
HeapFree(GetProcessHeap(), 0, pcs->search_path);
pcs->search_path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(searchPath) + 1),
searchPath);
pcs->search_path = lstrcpyW(HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(searchPath) + 1) * sizeof(WCHAR)),
searchPath);
return TRUE;
}
/******************************************************************
* SymSetSearchPath (DBGHELP.@)
*
*/
BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath)
{
BOOL ret = FALSE;
unsigned len;
WCHAR* sp;
len = MultiByteToWideChar(CP_ACP, 0, searchPath, -1, NULL, 0);
if ((sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
{
MultiByteToWideChar(CP_ACP, 0, searchPath, -1, sp, len);
ret = SymSetSearchPathW(hProcess, sp);
HeapFree(GetProcessHeap(), 0, sp);
}
return ret;
}
/***********************************************************************
* SymGetSearchPath (DBGHELP.@)
* SymGetSearchPathW (DBGHELP.@)
*/
BOOL WINAPI SymGetSearchPath(HANDLE hProcess, LPSTR szSearchPath,
DWORD SearchPathLength)
BOOL WINAPI SymGetSearchPathW(HANDLE hProcess, LPWSTR szSearchPath,
DWORD SearchPathLength)
{
struct process* pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE;
lstrcpynA(szSearchPath, pcs->search_path, SearchPathLength);
lstrcpynW(szSearchPath, pcs->search_path, SearchPathLength);
return TRUE;
}
/***********************************************************************
* SymGetSearchPath (DBGHELP.@)
*/
BOOL WINAPI SymGetSearchPath(HANDLE hProcess, LPSTR szSearchPath,
DWORD SearchPathLength)
{
WCHAR* buffer = HeapAlloc(GetProcessHeap(), 0, SearchPathLength);
BOOL ret = FALSE;
if (buffer)
{
ret = SymGetSearchPathW(hProcess, buffer,
SearchPathLength * sizeof(WCHAR));
if (ret)
WideCharToMultiByte(CP_ACP, 0, buffer, SearchPathLength,
szSearchPath, SearchPathLength, NULL, NULL);
HeapFree(GetProcessHeap(), 0, buffer);
}
return ret;
}
/******************************************************************
* invade_process
*
......@@ -176,7 +220,7 @@ static BOOL check_live_target(struct process* pcs)
}
/******************************************************************
* SymInitialize (DBGHELP.@)
* SymInitializeW (DBGHELP.@)
*
* The initialisation of a dbghelp's context.
* Note that hProcess doesn't need to be a valid process handle (except
......@@ -201,11 +245,11 @@ static BOOL check_live_target(struct process* pcs)
* Note also that this scheme can be intertwined with the deferred loading
* mechanism (ie only load the debug information when we actually need it).
*/
BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess)
BOOL WINAPI SymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeProcess)
{
struct process* pcs;
TRACE("(%p %s %u)\n", hProcess, debugstr_a(UserSearchPath), fInvadeProcess);
TRACE("(%p %s %u)\n", hProcess, debugstr_w(UserSearchPath), fInvadeProcess);
if (process_find_by_handle(hProcess))
FIXME("what to do ??\n");
......@@ -217,33 +261,36 @@ BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadePro
if (UserSearchPath)
{
pcs->search_path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(UserSearchPath) + 1),
UserSearchPath);
pcs->search_path = lstrcpyW(HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(UserSearchPath) + 1) * sizeof(WCHAR)),
UserSearchPath);
}
else
{
unsigned size;
unsigned len;
static const WCHAR sym_path[] = {'_','N','T','_','S','Y','M','B','O','L','_','P','A','T','H',0};
static const WCHAR alt_sym_path[] = {'_','N','T','_','A','L','T','E','R','N','A','T','E','_','S','Y','M','B','O','L','_','P','A','T','H',0};
pcs->search_path = HeapAlloc(GetProcessHeap(), 0, len = MAX_PATH);
while ((size = GetCurrentDirectoryA(len, pcs->search_path)) >= len)
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, len *= 2);
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, size + 1);
pcs->search_path = HeapAlloc(GetProcessHeap(), 0, (len = MAX_PATH) * sizeof(WCHAR));
while ((size = GetCurrentDirectoryW(len, pcs->search_path)) >= len)
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (len *= 2) * sizeof(WCHAR));
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1) * sizeof(WCHAR));
len = GetEnvironmentVariableA("_NT_SYMBOL_PATH", NULL, 0);
len = GetEnvironmentVariableW(sym_path, NULL, 0);
if (len)
{
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, size + 1 + len + 1);
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1 + len + 1) * sizeof(WCHAR));
pcs->search_path[size] = ';';
GetEnvironmentVariableA("_NT_SYMBOL_PATH", pcs->search_path + size + 1, len);
GetEnvironmentVariableW(sym_path, pcs->search_path + size + 1, len);
size += 1 + len;
}
len = GetEnvironmentVariableA("_NT_ALTERNATE_SYMBOL_PATH", NULL, 0);
len = GetEnvironmentVariableW(alt_sym_path, NULL, 0);
if (len)
{
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, size + 1 + len + 1);
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1 + len + 1) * sizeof(WCHAR));
pcs->search_path[size] = ';';
GetEnvironmentVariableA("_NT_ALTERNATE_SYMBOL_PATH", pcs->search_path + size + 1, len);
GetEnvironmentVariableW(alt_sym_path, pcs->search_path + size + 1, len);
size += 1 + len;
}
}
......@@ -270,6 +317,30 @@ BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadePro
}
/******************************************************************
* SymInitialize (DBGHELP.@)
*
*
*/
BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess)
{
WCHAR* sp = NULL;
BOOL ret;
if (UserSearchPath)
{
unsigned len;
len = MultiByteToWideChar(CP_ACP, 0, UserSearchPath, -1, NULL, 0);
sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, UserSearchPath, -1, sp, len);
}
ret = SymInitializeW(hProcess, sp, fInvadeProcess);
HeapFree(GetProcessHeap(), 0, sp);
return ret;
}
/******************************************************************
* SymCleanup (DBGHELP.@)
*
*/
......
......@@ -89,7 +89,8 @@
@ stdcall SymGetOptions()
@ stub SymGetScope
@ stub SymGetScopeW
@ stdcall SymGetSearchPath(long str long)
@ stdcall SymGetSearchPath(long ptr long)
@ stdcall SymGetSearchPathW(long ptr long)
@ stub SymGetSourceFileFromToken
@ stub SymGetSourceFileFromTokenW
@ stdcall SymGetSourceFileToken(ptr double str ptr ptr)
......@@ -112,7 +113,7 @@
@ stdcall SymGetTypeInfo(ptr double long long ptr)
@ stub SymGetTypeInfoEx
@ stdcall SymInitialize(long str long)
@ stub SymInitializeW
@ stdcall SymInitializeW(long wstr long)
@ stdcall SymLoadModule(long long str str long long)
@ stdcall SymLoadModule64(long long str str double long)
@ stdcall SymLoadModuleEx(long long str str double long ptr long)
......@@ -140,7 +141,7 @@
@ stdcall SymSetOptions(long)
@ stdcall SymSetParentWindow(long)
@ stdcall SymSetSearchPath(long str)
@ stub SymSetSearchPathW
@ stdcall SymSetSearchPathW(long wstr)
@ stub SymSetSymWithAddr64
@ stub SymSrvDeltaName
@ stub SymSrvDeltaNameW
......
......@@ -291,7 +291,7 @@ struct process
{
struct process* next;
HANDLE handle;
char* search_path;
WCHAR* search_path;
PSYMBOL_REGISTERED_CALLBACK64 reg_cb;
DWORD64 reg_user;
......
......@@ -298,7 +298,7 @@ static BOOL CALLBACK sffip_cb(LPCSTR buffer, void* user)
* SymFindFileInPath (DBGHELP.@)
*
*/
BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR searchPath, PCSTR full_path,
BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR inSearchPath, PCSTR full_path,
PVOID id, DWORD two, DWORD three, DWORD flags,
LPSTR buffer, PFINDFILEINPATHCALLBACK cb,
PVOID user)
......@@ -308,13 +308,22 @@ BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR searchPath, PCSTR full_path
char tmp[MAX_PATH];
char* ptr;
const char* filename;
const char* searchPath = inSearchPath;
TRACE("(%p %s %s %p %08lx %08lx %08lx %p %p %p)\n",
hProcess, searchPath, full_path, id, two, three, flags,
buffer, cb, user);
if (!pcs) return FALSE;
if (!searchPath) searchPath = pcs->search_path;
if (!searchPath)
{
unsigned len = WideCharToMultiByte(CP_ACP, 0, pcs->search_path, -1, NULL, 0, NULL, NULL);
char* buf;
searchPath = buf = HeapAlloc(GetProcessHeap(), 0, len);
if (!searchPath) return FALSE;
WideCharToMultiByte(CP_ACP, 0, pcs->search_path, -1, buf, len, NULL, NULL);
}
s.id = id;
s.two = two;
......@@ -330,6 +339,8 @@ BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR searchPath, PCSTR full_path
if (sffip_cb(full_path, &s))
{
strcpy(buffer, full_path);
if (searchPath != inSearchPath)
HeapFree(GetProcessHeap(), 0, (char*)searchPath);
return TRUE;
}
......@@ -350,8 +361,12 @@ BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR searchPath, PCSTR full_path
if (do_search(filename, tmp, FALSE, sffip_cb, &s))
{
strcpy(buffer, tmp);
if (searchPath != inSearchPath)
HeapFree(GetProcessHeap(), 0, (char*)searchPath);
return TRUE;
}
}
if (searchPath != inSearchPath)
HeapFree(GetProcessHeap(), 0, (char*)searchPath);
return FALSE;
}
......@@ -31,6 +31,7 @@
#include "winreg.h"
#include "winternl.h"
#include "wine/debug.h"
#include "winnls.h"
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
......@@ -336,12 +337,19 @@ struct module* pe_load_module(struct process* pcs, const char* name,
loaded_name[0] = '\0';
if (!hFile)
{
unsigned len = WideCharToMultiByte(CP_ACP,0, pcs->search_path, -1, NULL, 0, NULL, NULL);
char* sp;
if (!name)
{
/* FIXME SetLastError */
return NULL;
}
if ((hFile = FindExecutableImage(name, pcs->search_path, loaded_name)) == NULL)
sp = HeapAlloc(GetProcessHeap(), 0, len);
if (!sp) return FALSE;
WideCharToMultiByte(CP_ACP,0, pcs->search_path, -1, sp, len, NULL, NULL);
if ((hFile = FindExecutableImage(name, sp, loaded_name)) == NULL)
return NULL;
opened = TRUE;
}
......
......@@ -941,6 +941,7 @@ BOOL WINAPI SymEnumLines(HANDLE, ULONG64, PCSTR, PCSTR, PSYM_ENUMLINES_CALLBACK,
* File & image handling *
*************************/
BOOL WINAPI SymInitialize(HANDLE, PCSTR, BOOL);
BOOL WINAPI SymInitializeW(HANDLE, PCWSTR, BOOL);
BOOL WINAPI SymCleanup(HANDLE);
HANDLE WINAPI FindDebugInfoFile(PCSTR, PCSTR, PSTR);
......@@ -959,7 +960,9 @@ PVOID WINAPI ImageDirectoryEntryToData(PVOID, BOOLEAN, USHORT, PULONG);
PIMAGE_SECTION_HEADER WINAPI ImageRvaToSection(PIMAGE_NT_HEADERS, PVOID, ULONG);
PVOID WINAPI ImageRvaToVa(PIMAGE_NT_HEADERS, PVOID, ULONG, PIMAGE_SECTION_HEADER*);
BOOL WINAPI SymGetSearchPath(HANDLE, PSTR, DWORD);
BOOL WINAPI SymGetSearchPathW(HANDLE, PWSTR, DWORD);
BOOL WINAPI SymSetSearchPath(HANDLE, PCSTR);
BOOL WINAPI SymSetSearchPathW(HANDLE, PCWSTR);
DWORD WINAPI GetTimestampForLoadedLibrary(HMODULE);
BOOL WINAPI MakeSureDirectoryPathExists(PCSTR);
BOOL WINAPI SearchTreeForFile(PCSTR, PCSTR, PSTR);
......
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