Jacek Caban : dbghelp: Use WINELOADER environment variable from debuggee process in get_wine_loader_name.
Alexandre Julliard
julliard at winehq.org
Tue Dec 8 15:38:14 CST 2020
Module: wine
Branch: master
Commit: 310019789f7bde12ae3f25f723957c975fb2f804
URL: https://source.winehq.org/git/wine.git/?a=commit;h=310019789f7bde12ae3f25f723957c975fb2f804
Author: Jacek Caban <jacek at codeweavers.com>
Date: Tue Dec 8 20:19:12 2020 +0100
dbghelp: Use WINELOADER environment variable from debuggee process in get_wine_loader_name.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49838
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dbghelp/dbghelp_private.h | 2 +-
dlls/dbghelp/elf_module.c | 5 +----
dlls/dbghelp/macho_module.c | 7 +------
dlls/dbghelp/module.c | 35 +++++------------------------------
4 files changed, 8 insertions(+), 41 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 13e98b3b5f6..b51e8800403 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -651,7 +651,7 @@ extern void module_reset_debug_info(struct module* module) DECLSPEC_HIDD
extern BOOL module_remove(struct process* pcs,
struct module* module) DECLSPEC_HIDDEN;
extern void module_set_module(struct module* module, const WCHAR* name) DECLSPEC_HIDDEN;
-extern WCHAR * get_wine_loader_name(struct process *pcs) DECLSPEC_HIDDEN;
+extern const WCHAR *get_wine_loader_name(struct process *pcs) DECLSPEC_HIDDEN;
/* msc.c */
extern BOOL pe_load_debug_directory(const struct process* pcs,
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index e44629f016e..d1a4454e043 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -1752,13 +1752,10 @@ static const struct loader_ops elf_loader_ops =
BOOL elf_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr)
{
struct elf_info elf_info;
- WCHAR *loader;
BOOL ret;
elf_info.flags = ELF_INFO_DEBUG_HEADER | ELF_INFO_MODULE;
- loader = get_wine_loader_name(pcs);
- ret = elf_search_and_load_file(pcs, loader, addr, 0, &elf_info);
- heap_free(loader);
+ ret = elf_search_and_load_file(pcs, get_wine_loader_name(pcs), addr, 0, &elf_info);
if (!ret || !elf_info.dbg_hdr_addr) return FALSE;
TRACE("Found ELF debug header %#lx\n", elf_info.dbg_hdr_addr);
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c
index 8e91577e449..602f7e45c14 100644
--- a/dlls/dbghelp/macho_module.c
+++ b/dlls/dbghelp/macho_module.c
@@ -1885,12 +1885,7 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in
}
}
- if (!ret)
- {
- WCHAR *loader = get_wine_loader_name(pcs);
- ret = loader && macho_search_and_load_file(pcs, loader, 0, macho_info);
- heap_free(loader);
- }
+ if (!ret) ret = macho_search_and_load_file(pcs, get_wine_loader_name(pcs), 0, macho_info);
return ret;
}
diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index 23e67390185..cadb285accb 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -138,37 +138,12 @@ void module_set_module(struct module* module, const WCHAR* name)
}
/* Returned string must be freed by caller */
-WCHAR *get_wine_loader_name(struct process *pcs)
+const WCHAR *get_wine_loader_name(struct process *pcs)
{
- static const WCHAR wineW[] = {'w','i','n','e',0};
- static const WCHAR suffixW[] = {'6','4',0};
- WCHAR *buffer, *p;
- const char *env;
-
- /* All binaries are loaded with WINELOADER (if run from tree) or by the
- * main executable
- */
- if ((env = getenv("WINELOADER")))
- {
- DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, env, -1, NULL, 0 );
- buffer = heap_alloc( len * sizeof(WCHAR) );
- MultiByteToWideChar( CP_UNIXCP, 0, env, -1, buffer, len );
- }
- else
- {
- buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
- lstrcpyW( buffer, wineW );
- }
-
- p = buffer + lstrlenW( buffer ) - lstrlenW( suffixW );
- if (p > buffer && !wcscmp( p, suffixW ))
- *p = 0;
-
- if (pcs->is_64bit)
- lstrcatW(buffer, suffixW);
-
- TRACE( "returning %s\n", debugstr_w(buffer) );
- return buffer;
+ const WCHAR *name = process_getenv(pcs, L"WINELOADER");
+ if (!name) name = pcs->is_64bit ? L"wine64" : L"wine";
+ TRACE("returning %s\n", debugstr_w(name));
+ return name;
}
static const char* get_module_type(enum module_type type, BOOL virtual)
More information about the wine-cvs
mailing list