dbghelp: Add a helper function to determine the name of the wine loader.

oldstable
Alexandre Julliard 2011-01-28 11:41:14 +01:00
parent 22cd7e0e5e
commit 3bae7d0383
4 changed files with 34 additions and 41 deletions

View File

@ -528,7 +528,6 @@ extern BOOL macho_synchronize_module_list(struct process* pcs);
/* module.c */
extern const WCHAR S_ElfW[];
extern const WCHAR S_WineLoaderW[];
extern const WCHAR S_WineW[];
extern const WCHAR S_SlashW[];
extern struct module*
@ -555,6 +554,7 @@ extern void module_reset_debug_info(struct module* module);
extern BOOL module_remove(struct process* pcs,
struct module* module);
extern void module_set_module(struct module* module, const WCHAR* name);
extern const WCHAR *get_wine_loader_name(void);
/* msc.c */
extern BOOL pe_load_debug_directory(const struct process* pcs,

View File

@ -1458,23 +1458,7 @@ static BOOL elf_enum_modules_internal(const struct process* pcs,
*/
static BOOL elf_search_loader(struct process* pcs, struct elf_info* elf_info)
{
BOOL ret;
const char* ptr;
/* All binaries are loaded with WINELOADER (if run from tree) or by the
* main executable
*/
if ((ptr = getenv("WINELOADER")))
{
WCHAR tmp[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp) / sizeof(WCHAR));
ret = elf_search_and_load_file(pcs, tmp, 0, 0, elf_info);
}
else
{
ret = elf_search_and_load_file(pcs, S_WineW, 0, 0, elf_info);
}
return ret;
return elf_search_and_load_file(pcs, get_wine_loader_name(), 0, 0, elf_info);
}
/******************************************************************

View File

@ -1274,25 +1274,7 @@ BOOL macho_synchronize_module_list(struct process* pcs)
*/
static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info)
{
BOOL ret;
const char* ptr;
TRACE("(%p/%p, %p)\n", pcs, pcs->handle, macho_info);
/* All binaries are loaded with WINELOADER (if run from tree) or by the
* main executable
*/
if ((ptr = getenv("WINELOADER")))
{
WCHAR tmp[MAX_PATH];
MultiByteToWideChar(CP_UNIXCP, 0, ptr, -1, tmp, sizeof(tmp) / sizeof(WCHAR));
ret = macho_search_and_load_file(pcs, tmp, 0, macho_info);
}
else
{
ret = macho_search_and_load_file(pcs, S_WineW, 0, macho_info);
}
return ret;
return macho_search_and_load_file(pcs, get_wine_loader_name(), 0, macho_info);
}
/******************************************************************

View File

@ -38,7 +38,6 @@ static const WCHAR S_DotSoW[] = {'.','s','o','\0'};
static const WCHAR S_DotDylibW[] = {'.','d','y','l','i','b','\0'};
static const WCHAR S_DotPdbW[] = {'.','p','d','b','\0'};
static const WCHAR S_DotDbgW[] = {'.','d','b','g','\0'};
const WCHAR S_WineW[] = {'w','i','n','e',0};
const WCHAR S_SlashW[] = {'/','\0'};
static const WCHAR S_AcmW[] = {'.','a','c','m','\0'};
@ -78,6 +77,7 @@ static const WCHAR* get_filename(const WCHAR* name, const WCHAR* endptr)
static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
{
const WCHAR *loader = get_wine_loader_name();
const WCHAR *ptr, *endptr;
size_t len, l;
@ -87,7 +87,7 @@ static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
out[len] = '\0';
if (len > 4 && (l = match_ext(out, len)))
out[len - l] = '\0';
else if (len > 4 && !strcmpiW(out + len - 4, S_WineW))
else if (len > strlenW(loader) && !strcmpiW(out + len - strlenW(loader), loader))
lstrcpynW(out, S_WineLoaderW, size);
else
{
@ -106,6 +106,29 @@ void module_set_module(struct module* module, const WCHAR* name)
NULL, NULL);
}
const WCHAR *get_wine_loader_name(void)
{
static const WCHAR wineW[] = {'w','i','n','e',0};
static const WCHAR *loader;
const char *ptr;
if (!loader)
{
/* All binaries are loaded with WINELOADER (if run from tree) or by the
* main executable
*/
if ((ptr = getenv("WINELOADER")))
{
DWORD len = MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
loader = buffer;
}
else loader = wineW;
}
return loader;
}
static const char* get_module_type(enum module_type type, BOOL virtual)
{
switch (type)
@ -417,7 +440,8 @@ static BOOL module_is_container_loaded(const struct process* pcs,
*/
enum module_type module_get_type_by_name(const WCHAR* name)
{
int len = strlenW(name);
int loader_len, len = strlenW(name);
const WCHAR *loader;
/* Skip all version extensions (.[digits]) regex: "(\.\d+)*$" */
do
@ -452,7 +476,10 @@ enum module_type module_get_type_by_name(const WCHAR* name)
return DMT_DBG;
/* wine is also a native module (Mach-O on Mac OS X, ELF elsewhere) */
if (((len > 4 && name[len - 5] == '/') || len == 4) && !strcmpiW(name + len - 4, S_WineW))
loader = get_wine_loader_name();
loader_len = strlenW( loader );
if ((len == loader_len || (len > loader_len && name[len - loader_len - 1] == '/')) &&
!strcmpiW(name + len - loader_len, loader))
{
#ifdef __APPLE__
return DMT_MACHO;