From ca7d01b33f8ba90f8ce5a62e58578b01d907ef5b Mon Sep 17 00:00:00 2001 From: winesync Date: Fri, 11 Sep 2020 17:10:42 +0200 Subject: [PATCH] [WINESYNC] dbghelp: Store process struct pointer in dump context. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard wine commit id 6b3018d03da983050516821caa2aada2f4814678 by Jacek Caban --- dll/win32/dbghelp/cpu_x86_64.c | 4 +-- dll/win32/dbghelp/dbghelp_private.h | 2 +- dll/win32/dbghelp/minidump.c | 49 ++++++++++++++++++----------- sdk/tools/winesync/dbghelp.cfg | 2 +- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/dll/win32/dbghelp/cpu_x86_64.c b/dll/win32/dbghelp/cpu_x86_64.c index 83c1fb16bf7..57cfa112446 100644 --- a/dll/win32/dbghelp/cpu_x86_64.c +++ b/dll/win32/dbghelp/cpu_x86_64.c @@ -929,7 +929,7 @@ static BOOL x86_64_fetch_minidump_module(struct dump_context* dc, unsigned index const RUNTIME_FUNCTION* rtf; ULONG size; - if (!(pcs = process_find_by_handle(dc->hProcess)) || + if (!(pcs = process_find_by_handle(dc->process->handle)) || !(module = module_find_by_addr(pcs, dc->modules[index].base, DMT_UNKNOWN))) return FALSE; rtf = (const RUNTIME_FUNCTION*)pe_map_directory(module, IMAGE_DIRECTORY_ENTRY_EXCEPTION, &size); @@ -947,7 +947,7 @@ static BOOL x86_64_fetch_minidump_module(struct dump_context* dc, unsigned index /* we need to read into the other process */ /* rtf = (RUNTIME_FUNCTION*)(module->module.BaseOfImage + (rtf->UnwindData & ~1)); */ } - if (ReadProcessMemory(dc->hProcess, + if (ReadProcessMemory(dc->process->handle, (void*)(dc->modules[index].base + rtf->UnwindData), &ui, sizeof(ui), NULL)) minidump_add_memory_block(dc, dc->modules[index].base + rtf->UnwindData, diff --git a/dll/win32/dbghelp/dbghelp_private.h b/dll/win32/dbghelp/dbghelp_private.h index d98ccedf64a..4e2d9f414f9 100644 --- a/dll/win32/dbghelp/dbghelp_private.h +++ b/dll/win32/dbghelp/dbghelp_private.h @@ -529,7 +529,7 @@ struct dump_thread struct dump_context { /* process & thread information */ - HANDLE hProcess; + struct process *process; DWORD pid; unsigned flags_out; /* thread information */ diff --git a/dll/win32/dbghelp/minidump.c b/dll/win32/dbghelp/minidump.c index a6524771a80..04652c040cf 100644 --- a/dll/win32/dbghelp/minidump.c +++ b/dll/win32/dbghelp/minidump.c @@ -93,7 +93,7 @@ static void fetch_thread_stack(struct dump_context* dc, const void* teb_addr, NT_TIB tib; ADDRESS64 addr; - if (ReadProcessMemory(dc->hProcess, teb_addr, &tib, sizeof(tib), NULL) && + if (ReadProcessMemory(dc->process->handle, teb_addr, &tib, sizeof(tib), NULL) && dbghelp_current_cpu && dbghelp_current_cpu->get_addr(NULL /* FIXME */, ctx, cpu_addr_stack, &addr) && addr.Mode == AddrModeFlat) { @@ -170,9 +170,9 @@ static BOOL fetch_thread_info(struct dump_context* dc, int thd_idx, { EXCEPTION_POINTERS ep; - ReadProcessMemory(dc->hProcess, except->ExceptionPointers, + ReadProcessMemory(dc->process->handle, except->ExceptionPointers, &ep, sizeof(ep), NULL); - ReadProcessMemory(dc->hProcess, ep.ContextRecord, + ReadProcessMemory(dc->process->handle, ep.ContextRecord, &lctx, sizeof(lctx), NULL); pctx = &lctx; } @@ -215,7 +215,7 @@ static BOOL add_module(struct dump_context* dc, const WCHAR* name, return FALSE; } if (is_elf || - !GetModuleFileNameExW(dc->hProcess, (HMODULE)(DWORD_PTR)base, + !GetModuleFileNameExW(dc->process->handle, (HMODULE)(DWORD_PTR)base, dc->modules[dc->num_modules].name, ARRAY_SIZE(dc->modules[dc->num_modules].name))) lstrcpynW(dc->modules[dc->num_modules].name, name, @@ -243,7 +243,7 @@ static BOOL WINAPI fetch_pe_module_info_cb(PCWSTR name, DWORD64 base, ULONG size if (!validate_addr64(base)) return FALSE; - if (pe_load_nt_header(dc->hProcess, base, &nth)) + if (pe_load_nt_header(dc->process->handle, base, &nth)) add_module(user, name, base, size, nth.FileHeader.TimeDateStamp, nth.OptionalHeader.CheckSum, FALSE); @@ -289,7 +289,7 @@ static BOOL fetch_macho_module_info_cb(const WCHAR* name, unsigned long base, /* NB: if we have a non-null base from the live-target use it. If we have * a null base, then grab its base address from Mach-O file. */ - if (!macho_fetch_file_info(dc->hProcess, name, base, &rbase, &size, &checksum)) + if (!macho_fetch_file_info(dc->process->handle, name, base, &rbase, &size, &checksum)) size = checksum = 0; add_module(dc, name, base ? base : rbase, size, 0 /* FIXME */, checksum, TRUE); return TRUE; @@ -323,7 +323,7 @@ static void fetch_memory64_info(struct dump_context* dc) MEMORY_BASIC_INFORMATION mbi; addr = 0; - while (VirtualQueryEx(dc->hProcess, (LPCVOID)addr, &mbi, sizeof(mbi)) != 0) + while (VirtualQueryEx(dc->process->handle, (LPCVOID)addr, &mbi, sizeof(mbi)) != 0) { /* Memory regions with state MEM_COMMIT will be added to the dump */ if (mbi.State == MEM_COMMIT) @@ -340,14 +340,14 @@ static void fetch_memory64_info(struct dump_context* dc) static void fetch_modules_info(struct dump_context* dc) { - EnumerateLoadedModulesW64(dc->hProcess, fetch_pe_module_info_cb, dc); + EnumerateLoadedModulesW64(dc->process->handle, fetch_pe_module_info_cb, dc); /* Since we include ELF modules in a separate stream from the regular PE ones, * we can always include those ELF modules (they don't eat lots of space) * And it's always a good idea to have a trace of the loaded ELF modules for * a given application in a post mortem debugging condition. */ - elf_enum_modules(dc->hProcess, fetch_elf_module_info_cb, dc); - macho_enum_modules(dc->hProcess, fetch_macho_module_info_cb, dc); + elf_enum_modules(dc->process->handle, fetch_elf_module_info_cb, dc); + macho_enum_modules(dc->process->handle, fetch_macho_module_info_cb, dc); } static void fetch_module_versioninfo(LPCWSTR filename, VS_FIXEDFILEINFO* ffi) @@ -447,11 +447,11 @@ static unsigned dump_exception_info(struct dump_context* dc, { EXCEPTION_POINTERS ep; - ReadProcessMemory(dc->hProcess, + ReadProcessMemory(dc->process->handle, except->ExceptionPointers, &ep, sizeof(ep), NULL); - ReadProcessMemory(dc->hProcess, + ReadProcessMemory(dc->process->handle, ep.ExceptionRecord, &rec, sizeof(rec), NULL); - ReadProcessMemory(dc->hProcess, + ReadProcessMemory(dc->process->handle, ep.ContextRecord, &ctx, sizeof(ctx), NULL); prec = &rec; pctx = &ctx; @@ -537,7 +537,7 @@ static unsigned dump_modules(struct dump_context* dc, BOOL dump_elf) MINIDUMP_CALLBACK_OUTPUT cbout; cbin.ProcessId = dc->pid; - cbin.ProcessHandle = dc->hProcess; + cbin.ProcessHandle = dc->process->handle; cbin.CallbackType = ModuleCallback; cbin.u.Module.FullPath = ms->Buffer; @@ -804,7 +804,7 @@ static unsigned dump_threads(struct dump_context* dc, MINIDUMP_CALLBACK_OUTPUT cbout; cbin.ProcessId = dc->pid; - cbin.ProcessHandle = dc->hProcess; + cbin.ProcessHandle = dc->process->handle; cbin.CallbackType = ThreadCallback; cbin.u.Thread.ThreadId = dc->threads[i].tid; cbin.u.Thread.ThreadHandle = 0; /* FIXME */ @@ -881,7 +881,7 @@ static unsigned dump_memory_info(struct dump_context* dc) for (pos = 0; pos < dc->mem[i].size; pos += sizeof(tmp)) { len = min(dc->mem[i].size - pos, sizeof(tmp)); - if (ReadProcessMemory(dc->hProcess, + if (ReadProcessMemory(dc->process->handle, (void*)(DWORD_PTR)(dc->mem[i].base + pos), tmp, len, NULL)) WriteFile(dc->hFile, tmp, len, &written, NULL); @@ -939,7 +939,7 @@ static unsigned dump_memory64_info(struct dump_context* dc) for (pos = 0; pos < dc->mem64[i].size; pos += sizeof(tmp)) { len = min(dc->mem64[i].size - pos, sizeof(tmp)); - if (ReadProcessMemory(dc->hProcess, + if (ReadProcessMemory(dc->process->handle, (void*)(ULONG_PTR)(dc->mem64[i].base + pos), tmp, len, NULL)) WriteFile(dc->hFile, tmp, len, &written, NULL); @@ -982,8 +982,18 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile, MINIDUMP_DIRECTORY mdDir; DWORD i, nStreams, idx_stream; struct dump_context dc; + BOOL sym_initialized = FALSE; + + if (!(dc.process = process_find_by_handle(hProcess))) + { + if (!(sym_initialized = SymInitializeW(hProcess, NULL, TRUE))) + { + WARN("failed to initialize process\n"); + return FALSE; + } + dc.process = process_find_by_handle(hProcess); + } - dc.hProcess = hProcess; dc.hFile = hFile; dc.pid = pid; dc.modules = NULL; @@ -1119,6 +1129,9 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile, for (i = idx_stream; i < nStreams; i++) writeat(&dc, mdHead.StreamDirectoryRva + i * sizeof(emptyDir), &emptyDir, sizeof(emptyDir)); + if (sym_initialized) + SymCleanup(hProcess); + HeapFree(GetProcessHeap(), 0, dc.mem); HeapFree(GetProcessHeap(), 0, dc.mem64); HeapFree(GetProcessHeap(), 0, dc.modules); diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg index b103048082c..00802ca02d5 100644 --- a/sdk/tools/winesync/dbghelp.cfg +++ b/sdk/tools/winesync/dbghelp.cfg @@ -4,4 +4,4 @@ files: include/dbghelp.h: sdk/include/psdk/dbghelp.h include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h tags: - wine: be9072ec743e22ed6a20288e5539b8ba307f9280 + wine: 6b3018d03da983050516821caa2aada2f4814678