* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#include "config.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#include <config.h>
+//#include <stdlib.h>
+//#include <stdio.h>
+//#include <string.h>
#include <assert.h>
#include "dbghelp_private.h"
-#include "psapi.h"
-#include "winternl.h"
-#include "wine/debug.h"
+
+#ifndef DBGHELP_STATIC_LIB
+#include <psapi.h>
+#include <wine/debug.h>
+#endif
+//#include "winternl.h"
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
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'};
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;
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
{
void module_set_module(struct module* module, const WCHAR* name)
{
module_fill_module(name, module->module.ModuleName, sizeof(module->module.ModuleName));
- WideCharToMultiByte(CP_ACP, 0, module->module.ModuleName, -1,
- module->module_name, sizeof(module->module_name),
- NULL, NULL);
+}
+
+const WCHAR *get_wine_loader_name(void)
+{
+ static const int is_win64 = sizeof(void *) > sizeof(int); /* FIXME: should depend on target process */
+ static const WCHAR wineW[] = {'w','i','n','e',0};
+ static const WCHAR suffixW[] = {'6','4',0};
+ static const WCHAR *loader;
+
+ if (!loader)
+ {
+ WCHAR *p, *buffer;
+ const char *ptr;
+
+ /* All binaries are loaded with WINELOADER (if run from tree) or by the
+ * main executable
+ */
+ if ((ptr = getenv("WINELOADER")))
+ {
+ DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
+ buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+ MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
+ }
+ else
+ {
+ buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(wineW) + 2 * sizeof(WCHAR) );
+ strcpyW( buffer, wineW );
+ }
+ p = buffer + strlenW( buffer ) - strlenW( suffixW );
+ if (p > buffer && !strcmpW( p, suffixW ))
+ {
+ if (!is_win64) *p = 0;
+ }
+ else if (is_win64) strcatW( buffer, suffixW );
+
+ TRACE( "returning %s\n", debugstr_w(buffer) );
+ loader = buffer;
+ }
+ return loader;
}
static const char* get_module_type(enum module_type type, BOOL virtual)
module->module.TimeDateStamp = stamp;
module->module.CheckSum = checksum;
- memset(module->module.LoadedPdbName, 0, sizeof(module->module.CVData));
+ memset(module->module.LoadedPdbName, 0, sizeof(module->module.LoadedPdbName));
module->module.CVSig = 0;
memset(module->module.CVData, 0, sizeof(module->module.CVData));
module->module.PdbSig = 0;
module->reloc_delta = 0;
module->type = type;
- module->is_virtual = virtual ? TRUE : FALSE;
+ module->is_virtual = virtual;
for (i = 0; i < DFI_LAST; i++) module->format_info[i] = NULL;
module->sortlist_valid = FALSE;
module->sorttab_size = 0;
*/
hash_table_init(&module->pool, &module->ht_symbols, 4096);
hash_table_init(&module->pool, &module->ht_types, 4096);
+#ifdef __x86_64__
+ hash_table_init(&module->pool, &module->ht_symaddr, 4096);
+#endif
vector_init(&module->vtypes, sizeof(struct symt*), 32);
module->sources_used = 0;
module->sources_alloc = 0;
module->sources = 0;
+ wine_rb_init(&module->sources_offsets_tree, &source_rb_functions);
return module;
}
/***********************************************************************
- * module_find_by_name
+ * module_find_by_nameW
*
*/
-static struct module* module_find_by_name(const struct process* pcs, const WCHAR* name)
+struct module* module_find_by_nameW(const struct process* pcs, const WCHAR* name)
{
struct module* module;
WCHAR wname[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, name, -1, wname, sizeof(wname) / sizeof(WCHAR));
- return module_find_by_name(pcs, wname);
+ return module_find_by_nameW(pcs, wname);
}
/***********************************************************************
if (pair->effective->is_virtual) ret = FALSE;
else switch (pair->effective->type)
{
+#ifndef DBGHELP_STATIC_LIB
case DMT_ELF:
- ret = elf_load_debug_info(pair->effective, NULL);
+ ret = elf_load_debug_info(pair->effective);
break;
+#endif
case DMT_PE:
idslW64.SizeOfStruct = sizeof(idslW64);
idslW64.BaseOfImage = pair->effective->module.BaseOfImage;
ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
&idslW64);
break;
+#ifndef DBGHELP_STATIC_LIB
case DMT_MACHO:
ret = macho_load_debug_info(pair->effective, NULL);
break;
+#endif
default:
ret = FALSE;
break;
* either the addr where module is loaded, or any address inside the
* module
*/
-struct module* module_find_by_addr(const struct process* pcs, unsigned long addr,
+struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr,
enum module_type type)
{
struct module* module;
*/
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
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;
/******************************************************************
* refresh_module_list
*/
+#ifndef DBGHELP_STATIC_LIB
static BOOL refresh_module_list(struct process* pcs)
{
/* force transparent ELF and Mach-O loading / unloading */
return elf_synchronize_module_list(pcs) || macho_synchronize_module_list(pcs);
}
+#endif
/***********************************************************************
* SymLoadModule (DBGHELP.@)
if (Flags & ~(SLMFLAG_VIRTUAL))
FIXME("Unsupported Flags %08x for %s\n", Flags, debugstr_w(wImageName));
+#ifndef DBGHELP_STATIC_LIB
refresh_module_list(pcs);
+#endif
/* this is a Wine extension to the API just to redo the synchronisation */
if (!wImageName && !hFile) return 0;
wImageName)
{
/* and finally an ELF or Mach-O module */
+#ifndef DBGHELP_STATIC_LIB
switch (module_get_type_by_name(wImageName))
{
case DMT_ELF:
/* Ignored */
break;
}
+#endif
}
}
if (!module)
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
{
- if (!validate_addr64(BaseOfDll)) return FALSE;
- return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, SizeOfDll);
+ return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll,
+ NULL, 0);
}
/******************************************************************
}
hash_table_destroy(&module->ht_symbols);
hash_table_destroy(&module->ht_types);
+ wine_rb_destroy(&module->sources_offsets_tree, NULL, NULL);
HeapFree(GetProcessHeap(), 0, module->sources);
HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
pool_destroy(&module->pool);
pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE;
if (!validate_addr64(BaseOfDll)) return FALSE;
- module = module_find_by_addr(pcs, (DWORD)BaseOfDll, DMT_UNKNOWN);
+ module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
if (!module) return FALSE;
return module_remove(pcs, module);
}
return TRUE;
}
+#ifndef DBGHELP_STATIC_LIB
/******************************************************************
* EnumerateLoadedModules64 (DBGHELP.@)
*
return sz != 0 && i == sz;
}
+#endif /* DBGHELP_STATIC_LIB */
/******************************************************************
* SymGetModuleInfo (DBGHELP.@)
if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
+#ifndef DBGHELP_STATIC_LIB
return refresh_module_list(pcs);
+#else
+ return TRUE;
+#endif
}
/***********************************************************************