mirror of
https://github.com/reactos/reactos.git
synced 2025-05-25 20:18:22 +00:00
[WINESYNC] dbghelp: Move reading debug base address from PEB to check_live_target.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id e3354e44f17d74f0ac4547d8a4494c83ea3d6d37 by Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
parent
ab49d97a84
commit
e0db46fa2e
5 changed files with 50 additions and 103 deletions
|
@ -284,20 +284,36 @@ static BOOL WINAPI process_invade_cb(PCWSTR name, ULONG64 base, ULONG size, PVOI
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef DBGHELP_STATIC_LIB
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* check_live_target
|
* check_live_target
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static BOOL check_live_target(struct process* pcs)
|
static BOOL check_live_target(struct process* pcs)
|
||||||
{
|
{
|
||||||
|
PROCESS_BASIC_INFORMATION pbi;
|
||||||
|
ULONG_PTR base = 0;
|
||||||
|
|
||||||
if (!GetProcessId(pcs->handle)) return FALSE;
|
if (!GetProcessId(pcs->handle)) return FALSE;
|
||||||
if (GetEnvironmentVariableA("DBGHELP_NOLIVE", NULL, 0)) return FALSE;
|
if (GetEnvironmentVariableA("DBGHELP_NOLIVE", NULL, 0)) return FALSE;
|
||||||
#ifndef DBGHELP_STATIC_LIB
|
|
||||||
if (!elf_read_wine_loader_dbg_info(pcs))
|
if (NtQueryInformationProcess( pcs->handle, ProcessBasicInformation,
|
||||||
macho_read_wine_loader_dbg_info(pcs);
|
&pbi, sizeof(pbi), NULL ))
|
||||||
#endif
|
return FALSE;
|
||||||
return TRUE;
|
|
||||||
|
if (!pcs->is_64bit)
|
||||||
|
{
|
||||||
|
PEB32 *peb32 = (PEB32 *)pbi.PebBaseAddress;
|
||||||
|
DWORD base32 = 0;
|
||||||
|
ReadProcessMemory(pcs->handle, &peb32->Reserved[0], &base32, sizeof(base32), NULL);
|
||||||
|
base = base32;
|
||||||
}
|
}
|
||||||
|
else ReadProcessMemory(pcs->handle, &pbi.PebBaseAddress->Reserved[0], &base, sizeof(base), NULL);
|
||||||
|
|
||||||
|
TRACE("got debug info address %#lx from PEB %p\n", base, pbi.PebBaseAddress);
|
||||||
|
return elf_read_wine_loader_dbg_info(pcs, base) || macho_read_wine_loader_dbg_info(pcs, base);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* SymInitializeW (DBGHELP.@)
|
* SymInitializeW (DBGHELP.@)
|
||||||
|
|
|
@ -635,12 +635,12 @@ extern struct cpu* cpu_find(DWORD) DECLSPEC_HIDDEN;
|
||||||
extern DWORD calc_crc32(HANDLE handle) DECLSPEC_HIDDEN;
|
extern DWORD calc_crc32(HANDLE handle) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/* elf_module.c */
|
/* elf_module.c */
|
||||||
extern BOOL elf_read_wine_loader_dbg_info(struct process* pcs) DECLSPEC_HIDDEN;
|
extern BOOL elf_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr) DECLSPEC_HIDDEN;
|
||||||
struct elf_thunk_area;
|
struct elf_thunk_area;
|
||||||
extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_thunk_area* thunks) DECLSPEC_HIDDEN;
|
extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_thunk_area* thunks) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/* macho_module.c */
|
/* macho_module.c */
|
||||||
extern BOOL macho_read_wine_loader_dbg_info(struct process* pcs) DECLSPEC_HIDDEN;
|
extern BOOL macho_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/* minidump.c */
|
/* minidump.c */
|
||||||
void minidump_add_memory_block(struct dump_context* dc, ULONG64 base, ULONG size, ULONG rva) DECLSPEC_HIDDEN;
|
void minidump_add_memory_block(struct dump_context* dc, ULONG64 base, ULONG size, ULONG rva) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -1661,48 +1661,6 @@ static BOOL elf_synchronize_module_list(struct process* pcs)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
|
||||||
* elf_search_loader
|
|
||||||
*
|
|
||||||
* Lookup in a running ELF process the loader, and sets its ELF link
|
|
||||||
* address (for accessing the list of loaded .so libs) in pcs.
|
|
||||||
* If flags is ELF_INFO_MODULE, the module for the loader is also
|
|
||||||
* added as a module into pcs.
|
|
||||||
*/
|
|
||||||
static BOOL elf_search_loader(struct process* pcs, struct elf_info* elf_info)
|
|
||||||
{
|
|
||||||
WCHAR *loader = get_wine_loader_name(pcs);
|
|
||||||
PROCESS_BASIC_INFORMATION pbi;
|
|
||||||
ULONG_PTR base = 0;
|
|
||||||
BOOL ret;
|
|
||||||
|
|
||||||
if (NtQueryInformationProcess( pcs->handle, ProcessBasicInformation,
|
|
||||||
&pbi, sizeof(pbi), NULL ))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!pcs->is_64bit)
|
|
||||||
{
|
|
||||||
PEB32 *peb32 = (PEB32 *)pbi.PebBaseAddress;
|
|
||||||
DWORD base32;
|
|
||||||
|
|
||||||
if (!ReadProcessMemory( pcs->handle, &peb32->Reserved[0], &base32,
|
|
||||||
sizeof(base32), NULL ))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
base = base32;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!ReadProcessMemory( pcs->handle, &pbi.PebBaseAddress->Reserved[0],
|
|
||||||
&base, sizeof(base), NULL ))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = elf_search_and_load_file(pcs, loader, base, 0, elf_info);
|
|
||||||
heap_free(loader);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct loader_ops elf_loader_ops =
|
static const struct loader_ops elf_loader_ops =
|
||||||
{
|
{
|
||||||
elf_synchronize_module_list,
|
elf_synchronize_module_list,
|
||||||
|
@ -1717,12 +1675,19 @@ static const struct loader_ops elf_loader_ops =
|
||||||
*
|
*
|
||||||
* Try to find a decent wine executable which could have loaded the debuggee
|
* Try to find a decent wine executable which could have loaded the debuggee
|
||||||
*/
|
*/
|
||||||
BOOL elf_read_wine_loader_dbg_info(struct process* pcs)
|
BOOL elf_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr)
|
||||||
{
|
{
|
||||||
struct elf_info elf_info;
|
struct elf_info elf_info;
|
||||||
|
WCHAR *loader;
|
||||||
|
BOOL ret;
|
||||||
|
|
||||||
elf_info.flags = ELF_INFO_DEBUG_HEADER | ELF_INFO_MODULE;
|
elf_info.flags = ELF_INFO_DEBUG_HEADER | ELF_INFO_MODULE;
|
||||||
if (!elf_search_loader(pcs, &elf_info) || !elf_info.dbg_hdr_addr) return FALSE;
|
loader = get_wine_loader_name(pcs);
|
||||||
|
ret = elf_search_and_load_file(pcs, loader, addr, 0, &elf_info);
|
||||||
|
heap_free(loader);
|
||||||
|
if (!ret || !elf_info.dbg_hdr_addr) return FALSE;
|
||||||
|
|
||||||
|
TRACE("Found ELF debug header %#lx\n", elf_info.dbg_hdr_addr);
|
||||||
elf_info.module->format_info[DFI_ELF]->u.elf_info->elf_loader = 1;
|
elf_info.module->format_info[DFI_ELF]->u.elf_info->elf_loader = 1;
|
||||||
module_set_module(elf_info.module, S_WineLoaderW);
|
module_set_module(elf_info.module, S_WineLoaderW);
|
||||||
pcs->dbg_hdr_addr = elf_info.dbg_hdr_addr;
|
pcs->dbg_hdr_addr = elf_info.dbg_hdr_addr;
|
||||||
|
@ -1737,7 +1702,7 @@ BOOL elf_map_handle(HANDLE handle, struct image_file_map* fmap)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL elf_read_wine_loader_dbg_info(struct process* pcs)
|
BOOL elf_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,14 +129,12 @@ struct section_info
|
||||||
unsigned int section_index;
|
unsigned int section_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MACHO_INFO_DEBUG_HEADER 0x0001
|
#define MACHO_INFO_MODULE 0x0001
|
||||||
#define MACHO_INFO_MODULE 0x0002
|
#define MACHO_INFO_NAME 0x0002
|
||||||
#define MACHO_INFO_NAME 0x0004
|
|
||||||
|
|
||||||
struct macho_info
|
struct macho_info
|
||||||
{
|
{
|
||||||
unsigned flags; /* IN one (or several) of the MACHO_INFO constants */
|
unsigned flags; /* IN one (or several) of the MACHO_INFO constants */
|
||||||
unsigned long dbg_hdr_addr; /* OUT address of debug header (if MACHO_INFO_DEBUG_HEADER is set) */
|
|
||||||
struct module* module; /* OUT loaded module (if MACHO_INFO_MODULE is set) */
|
struct module* module; /* OUT loaded module (if MACHO_INFO_MODULE is set) */
|
||||||
const WCHAR* module_name; /* OUT found module name (if MACHO_INFO_NAME is set) */
|
const WCHAR* module_name; /* OUT found module name (if MACHO_INFO_NAME is set) */
|
||||||
};
|
};
|
||||||
|
@ -1373,32 +1371,7 @@ static void macho_module_remove(struct process* pcs, struct module_format* modfm
|
||||||
*/
|
*/
|
||||||
static ULONG_PTR get_dyld_image_info_address(struct process* pcs)
|
static ULONG_PTR get_dyld_image_info_address(struct process* pcs)
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
|
||||||
PROCESS_BASIC_INFORMATION pbi;
|
|
||||||
ULONG_PTR dyld_image_info_address = 0;
|
ULONG_PTR dyld_image_info_address = 0;
|
||||||
BOOL ret;
|
|
||||||
|
|
||||||
/* Get address of PEB */
|
|
||||||
status = NtQueryInformationProcess(pcs->handle, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
|
|
||||||
if (status == STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
/* Read dyld image info address from PEB */
|
|
||||||
if (pcs->is_64bit)
|
|
||||||
ret = ReadProcessMemory(pcs->handle, &pbi.PebBaseAddress->Reserved[0],
|
|
||||||
&dyld_image_info_address, sizeof(dyld_image_info_address), NULL);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PEB32 *peb32 = (PEB32 *)pbi.PebBaseAddress;
|
|
||||||
ULONG addr32;
|
|
||||||
ret = ReadProcessMemory(pcs->handle, &peb32->Reserved[0], &addr32,
|
|
||||||
sizeof(addr32), NULL);
|
|
||||||
dyld_image_info_address = addr32;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
TRACE("got dyld_image_info_address %#lx from PEB %p\n",
|
|
||||||
dyld_image_info_address, pbi.PebBaseAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef __LP64__ /* No reading the symtab with nlist(3) in LP64 */
|
#ifndef __LP64__ /* No reading the symtab with nlist(3) in LP64 */
|
||||||
if (!dyld_image_info_address)
|
if (!dyld_image_info_address)
|
||||||
|
@ -1451,14 +1424,6 @@ static BOOL macho_load_file(struct process* pcs, const WCHAR* filename,
|
||||||
split_segs = image_uses_split_segs(pcs, load_addr);
|
split_segs = image_uses_split_segs(pcs, load_addr);
|
||||||
if (!macho_map_file(pcs, filename, split_segs, &fmap)) return FALSE;
|
if (!macho_map_file(pcs, filename, split_segs, &fmap)) return FALSE;
|
||||||
|
|
||||||
/* Find the dynamic loader's table of images loaded into the process.
|
|
||||||
*/
|
|
||||||
if (macho_info->flags & MACHO_INFO_DEBUG_HEADER)
|
|
||||||
{
|
|
||||||
macho_info->dbg_hdr_addr = (unsigned long)get_dyld_image_info_address(pcs);
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (macho_info->flags & MACHO_INFO_MODULE)
|
if (macho_info->flags & MACHO_INFO_MODULE)
|
||||||
{
|
{
|
||||||
struct macho_module_info *macho_module_info;
|
struct macho_module_info *macho_module_info;
|
||||||
|
@ -1736,7 +1701,7 @@ static BOOL macho_enum_modules(struct process* process, enum_modules_cb cb, void
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
TRACE("(%p, %p, %p)\n", process->handle, cb, user);
|
TRACE("(%p, %p, %p)\n", process->handle, cb, user);
|
||||||
macho_info.flags = MACHO_INFO_DEBUG_HEADER | MACHO_INFO_NAME;
|
macho_info.flags = MACHO_INFO_NAME;
|
||||||
ret = macho_enum_modules_internal(process, macho_info.module_name, cb, user);
|
ret = macho_enum_modules_internal(process, macho_info.module_name, cb, user);
|
||||||
HeapFree(GetProcessHeap(), 0, (char*)macho_info.module_name);
|
HeapFree(GetProcessHeap(), 0, (char*)macho_info.module_name);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1823,9 +1788,7 @@ static struct module* macho_load_module(struct process* pcs, const WCHAR* name,
|
||||||
*/
|
*/
|
||||||
static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info)
|
static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info)
|
||||||
{
|
{
|
||||||
WCHAR *loader = get_wine_loader_name(pcs);
|
|
||||||
BOOL ret = FALSE;
|
BOOL ret = FALSE;
|
||||||
ULONG_PTR dyld_image_info_address;
|
|
||||||
union wine_all_image_infos image_infos;
|
union wine_all_image_infos image_infos;
|
||||||
union wine_image_info image_info;
|
union wine_image_info image_info;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
@ -1836,9 +1799,8 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in
|
||||||
len = sizeof(image_infos.infos64);
|
len = sizeof(image_infos.infos64);
|
||||||
else
|
else
|
||||||
len = sizeof(image_infos.infos32);
|
len = sizeof(image_infos.infos32);
|
||||||
dyld_image_info_address = get_dyld_image_info_address(pcs);
|
if (pcs->dbg_hdr_addr &&
|
||||||
if (dyld_image_info_address &&
|
ReadProcessMemory(pcs->handle, (void*)pcs->dbg_hdr_addr, &image_infos, len, NULL))
|
||||||
ReadProcessMemory(pcs->handle, (void*)dyld_image_info_address, &image_infos, len, NULL))
|
|
||||||
{
|
{
|
||||||
if (pcs->is_64bit)
|
if (pcs->is_64bit)
|
||||||
len = sizeof(image_info.info64);
|
len = sizeof(image_info.info64);
|
||||||
|
@ -1898,8 +1860,11 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = macho_search_and_load_file(pcs, loader, 0, macho_info);
|
{
|
||||||
|
WCHAR *loader = get_wine_loader_name(pcs);
|
||||||
|
ret = loader && macho_search_and_load_file(pcs, loader, 0, macho_info);
|
||||||
heap_free(loader);
|
heap_free(loader);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1917,23 +1882,24 @@ static const struct loader_ops macho_loader_ops =
|
||||||
*
|
*
|
||||||
* Try to find a decent wine executable which could have loaded the debuggee
|
* Try to find a decent wine executable which could have loaded the debuggee
|
||||||
*/
|
*/
|
||||||
BOOL macho_read_wine_loader_dbg_info(struct process* pcs)
|
BOOL macho_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr)
|
||||||
{
|
{
|
||||||
struct macho_info macho_info;
|
struct macho_info macho_info;
|
||||||
|
|
||||||
TRACE("(%p/%p)\n", pcs, pcs->handle);
|
TRACE("(%p/%p)\n", pcs, pcs->handle);
|
||||||
macho_info.flags = MACHO_INFO_DEBUG_HEADER | MACHO_INFO_MODULE;
|
pcs->dbg_hdr_addr = addr ? addr : get_dyld_image_info_address(pcs);
|
||||||
if (!macho_search_loader(pcs, &macho_info) || !macho_info.dbg_hdr_addr) return FALSE;
|
macho_info.flags = MACHO_INFO_MODULE;
|
||||||
|
if (!macho_search_loader(pcs, &macho_info)) return FALSE;
|
||||||
macho_info.module->format_info[DFI_MACHO]->u.macho_info->is_loader = 1;
|
macho_info.module->format_info[DFI_MACHO]->u.macho_info->is_loader = 1;
|
||||||
module_set_module(macho_info.module, S_WineLoaderW);
|
module_set_module(macho_info.module, S_WineLoaderW);
|
||||||
pcs->dbg_hdr_addr = macho_info.dbg_hdr_addr;
|
|
||||||
pcs->loader = &macho_loader_ops;
|
pcs->loader = &macho_loader_ops;
|
||||||
|
TRACE("Found macho debug header %#lx\n", pcs->dbg_hdr_addr);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* HAVE_MACH_O_LOADER_H */
|
#else /* HAVE_MACH_O_LOADER_H */
|
||||||
|
|
||||||
BOOL macho_read_wine_loader_dbg_info(struct process* pcs)
|
BOOL macho_read_wine_loader_dbg_info(struct process* pcs, ULONG_PTR addr)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,4 @@ files:
|
||||||
include/dbghelp.h: sdk/include/psdk/dbghelp.h
|
include/dbghelp.h: sdk/include/psdk/dbghelp.h
|
||||||
include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
|
include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
|
||||||
tags:
|
tags:
|
||||||
wine: 635506921a28c65bfc9b339d59c63d96092d97d8
|
wine: e3354e44f17d74f0ac4547d8a4494c83ea3d6d37
|
||||||
|
|
Loading…
Reference in a new issue