2005-05-23 18:22:44 +02:00
|
|
|
/*
|
|
|
|
* Wine debugger - minidump handling
|
|
|
|
*
|
|
|
|
* Copyright 2005 Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-23 18:22:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
|
|
|
#include "config.h"
|
2008-04-29 20:18:49 +02:00
|
|
|
#include "wine/port.h"
|
2005-05-23 18:22:44 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "debugger.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "tlhelp32.h"
|
|
|
|
#include "wine/debug.h"
|
2006-03-01 21:05:35 +01:00
|
|
|
#include "wine/exception.h"
|
2005-05-23 18:22:44 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
|
|
|
|
|
2006-03-01 21:05:35 +01:00
|
|
|
static struct be_process_io be_process_minidump_io;
|
|
|
|
|
2010-04-15 22:17:04 +02:00
|
|
|
/* we need this function on 32bit hosts to ensure we zero out the higher DWORD
|
|
|
|
* stored in the minidump file (sometimes it's not cleared, or the conversion from
|
|
|
|
* 32bit to 64bit wide integers is done as signed, which is wrong)
|
|
|
|
* So we clamp on 32bit CPUs (as stored in minidump information) all addresses to
|
|
|
|
* keep only the lower 32 bits.
|
|
|
|
* FIXME: as of today, since we don't support a backend CPU which is different from
|
|
|
|
* CPU this process is running on, casting to (DWORD_PTR) will do just fine.
|
|
|
|
*/
|
|
|
|
static inline DWORD64 get_addr64(DWORD64 addr)
|
2008-01-13 17:02:49 +01:00
|
|
|
{
|
2010-04-15 22:17:04 +02:00
|
|
|
return (DWORD_PTR)addr;
|
2008-01-13 17:02:49 +01:00
|
|
|
}
|
|
|
|
|
2005-05-23 18:22:44 +02:00
|
|
|
void minidump_write(const char* file, const EXCEPTION_RECORD* rec)
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION mei;
|
|
|
|
EXCEPTION_POINTERS ep;
|
|
|
|
|
2009-12-09 18:14:07 +01:00
|
|
|
hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
2005-05-23 18:22:44 +02:00
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
if (rec)
|
|
|
|
{
|
|
|
|
mei.ThreadId = dbg_curr_thread->tid;
|
|
|
|
mei.ExceptionPointers = &ep;
|
|
|
|
ep.ExceptionRecord = (EXCEPTION_RECORD*)rec;
|
|
|
|
ep.ContextRecord = &dbg_context;
|
|
|
|
mei.ClientPointers = FALSE;
|
|
|
|
}
|
|
|
|
MiniDumpWriteDump(dbg_curr_process->handle, dbg_curr_process->pid,
|
|
|
|
hFile, MiniDumpNormal/*|MiniDumpWithDataSegs*/,
|
|
|
|
rec ? &mei : NULL, NULL, NULL);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
2006-03-01 21:05:35 +01:00
|
|
|
|
|
|
|
#define Wine_ElfModuleListStream 0xFFF0
|
|
|
|
|
|
|
|
struct tgt_process_minidump_data
|
|
|
|
{
|
|
|
|
void* mapping;
|
|
|
|
HANDLE hFile;
|
|
|
|
HANDLE hMap;
|
|
|
|
};
|
|
|
|
|
2009-03-12 14:29:53 +01:00
|
|
|
static inline struct tgt_process_minidump_data* private_data(struct dbg_process* pcs)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
return pcs->pio_data;
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
|
2009-06-05 15:16:14 +02:00
|
|
|
static BOOL tgt_process_minidump_read(HANDLE hProcess, const void* addr,
|
|
|
|
void* buffer, SIZE_T len, SIZE_T* rlen)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
|
|
|
void* stream;
|
|
|
|
|
2009-03-12 14:29:53 +01:00
|
|
|
if (!private_data(dbg_curr_process)->mapping) return FALSE;
|
|
|
|
if (MiniDumpReadDumpStream(private_data(dbg_curr_process)->mapping,
|
2009-05-30 14:19:26 +02:00
|
|
|
MemoryListStream, NULL, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
MINIDUMP_MEMORY_LIST* mml = stream;
|
2012-07-27 14:09:40 +02:00
|
|
|
MINIDUMP_MEMORY_DESCRIPTOR* mmd = mml->MemoryRanges;
|
2012-01-23 21:37:22 +01:00
|
|
|
int i, found = -1;
|
|
|
|
SIZE_T ilen, prev_len = 0;
|
|
|
|
|
|
|
|
/* There's no reason that memory ranges inside a minidump do not overlap.
|
|
|
|
* So be smart when looking for a given memory range (either grab a
|
|
|
|
* range that covers the whole requested area, or if none, the range that
|
|
|
|
* has the largest overlap with requested area)
|
|
|
|
*/
|
2006-03-01 21:05:35 +01:00
|
|
|
for (i = 0; i < mml->NumberOfMemoryRanges; i++, mmd++)
|
|
|
|
{
|
2008-01-13 17:02:49 +01:00
|
|
|
if (get_addr64(mmd->StartOfMemoryRange) <= (DWORD_PTR)addr &&
|
|
|
|
(DWORD_PTR)addr < get_addr64(mmd->StartOfMemoryRange) + mmd->Memory.DataSize)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2012-01-23 21:37:22 +01:00
|
|
|
ilen = min(len,
|
|
|
|
get_addr64(mmd->StartOfMemoryRange) + mmd->Memory.DataSize - (DWORD_PTR)addr);
|
|
|
|
if (ilen == len) /* whole range is matched */
|
|
|
|
{
|
|
|
|
found = i;
|
|
|
|
prev_len = ilen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (found == -1 || ilen > prev_len) /* partial match, keep largest one */
|
|
|
|
{
|
|
|
|
found = i;
|
|
|
|
prev_len = ilen;
|
|
|
|
}
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-23 21:37:22 +01:00
|
|
|
if (found != -1)
|
|
|
|
{
|
|
|
|
mmd = &mml->MemoryRanges[found];
|
|
|
|
memcpy(buffer,
|
|
|
|
(char*)private_data(dbg_curr_process)->mapping + mmd->Memory.Rva + (DWORD_PTR)addr - get_addr64(mmd->StartOfMemoryRange),
|
|
|
|
prev_len);
|
|
|
|
if (rlen) *rlen = prev_len;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
/* FIXME: this is a dirty hack to let the last frame in a bt to work
|
|
|
|
* However, we need to check who's to blame, this code or the current
|
|
|
|
* dbghelp!StackWalk implementation
|
|
|
|
*/
|
|
|
|
if ((DWORD_PTR)addr < 32)
|
|
|
|
{
|
|
|
|
memset(buffer, 0, len);
|
|
|
|
if (rlen) *rlen = len;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-06-05 15:16:14 +02:00
|
|
|
static BOOL tgt_process_minidump_write(HANDLE hProcess, void* addr,
|
|
|
|
const void* buffer, SIZE_T len, SIZE_T* wlen)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-20 09:13:23 +01:00
|
|
|
static BOOL CALLBACK validate_file(PCWSTR name, void* user)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
|
|
|
return FALSE; /* get the first file we find !! */
|
|
|
|
}
|
|
|
|
|
2007-04-01 12:31:57 +02:00
|
|
|
static BOOL is_pe_module_embedded(struct tgt_process_minidump_data* data,
|
|
|
|
MINIDUMP_MODULE* pe_mm)
|
|
|
|
{
|
|
|
|
MINIDUMP_MODULE_LIST* mml;
|
|
|
|
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, Wine_ElfModuleListStream, NULL,
|
|
|
|
(void**)&mml, NULL))
|
2007-04-01 12:31:57 +02:00
|
|
|
{
|
|
|
|
MINIDUMP_MODULE* mm;
|
|
|
|
unsigned i;
|
|
|
|
|
2012-07-27 14:09:40 +02:00
|
|
|
for (i = 0, mm = mml->Modules; i < mml->NumberOfModules; i++, mm++)
|
2007-04-01 12:31:57 +02:00
|
|
|
{
|
2008-01-13 17:02:49 +01:00
|
|
|
if (get_addr64(mm->BaseOfImage) <= get_addr64(pe_mm->BaseOfImage) &&
|
|
|
|
get_addr64(mm->BaseOfImage) + mm->SizeOfImage >= get_addr64(pe_mm->BaseOfImage) + pe_mm->SizeOfImage)
|
2007-04-01 12:31:57 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-03-01 21:05:35 +01:00
|
|
|
static enum dbg_start minidump_do_reload(struct tgt_process_minidump_data* data)
|
|
|
|
{
|
|
|
|
void* stream;
|
|
|
|
DWORD pid = 1; /* by default */
|
|
|
|
HANDLE hProc = (HANDLE)0x900DBAAD;
|
|
|
|
int i;
|
|
|
|
MINIDUMP_MODULE_LIST* mml;
|
|
|
|
MINIDUMP_MODULE* mm;
|
|
|
|
MINIDUMP_STRING* mds;
|
2012-01-23 21:36:59 +01:00
|
|
|
MINIDUMP_DIRECTORY* dir;
|
2008-10-18 09:15:10 +02:00
|
|
|
WCHAR exec_name[1024];
|
2007-02-21 21:56:06 +01:00
|
|
|
WCHAR nameW[1024];
|
2006-03-01 21:05:35 +01:00
|
|
|
unsigned len;
|
2008-10-18 09:15:10 +02:00
|
|
|
static WCHAR default_exec_name[] = {'<','m','i','n','i','d','u','m','p','-','e','x','e','c','>',0};
|
2006-03-01 21:05:35 +01:00
|
|
|
|
|
|
|
/* fetch PID */
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, MiscInfoStream, NULL, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
MINIDUMP_MISC_INFO* mmi = stream;
|
2006-03-01 21:05:35 +01:00
|
|
|
if (mmi->Flags1 & MINIDUMP_MISC1_PROCESS_ID)
|
|
|
|
pid = mmi->ProcessId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fetch executable name (it's normally the first one in module list) */
|
2008-10-18 09:15:10 +02:00
|
|
|
lstrcpyW(exec_name, default_exec_name);
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, ModuleListStream, NULL, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
mml = stream;
|
2006-03-01 21:05:35 +01:00
|
|
|
if (mml->NumberOfModules)
|
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
WCHAR* ptr;
|
2006-03-01 21:05:35 +01:00
|
|
|
|
2012-07-27 14:09:40 +02:00
|
|
|
mm = mml->Modules;
|
2006-03-01 21:05:35 +01:00
|
|
|
mds = (MINIDUMP_STRING*)((char*)data->mapping + mm->ModuleNameRva);
|
2008-10-18 09:15:10 +02:00
|
|
|
len = mds->Length / 2;
|
|
|
|
memcpy(exec_name, mds->Buffer, mds->Length);
|
2007-02-21 21:56:06 +01:00
|
|
|
exec_name[len] = 0;
|
|
|
|
for (ptr = exec_name + len - 1; ptr >= exec_name; ptr--)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
|
|
|
if (*ptr == '/' || *ptr == '\\')
|
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
memmove(exec_name, ptr + 1, (lstrlenW(ptr + 1) + 1) * sizeof(WCHAR));
|
2006-03-01 21:05:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-23 21:36:59 +01:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, SystemInfoStream, &dir, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
MINIDUMP_SYSTEM_INFO* msi = stream;
|
2006-06-09 22:44:44 +02:00
|
|
|
const char *str;
|
|
|
|
char tmp[128];
|
2006-03-01 21:05:35 +01:00
|
|
|
|
2006-12-20 14:17:27 +01:00
|
|
|
dbg_printf("WineDbg starting on minidump on pid %04x\n", pid);
|
2006-03-01 21:05:35 +01:00
|
|
|
switch (msi->ProcessorArchitecture)
|
|
|
|
{
|
2007-04-01 12:32:04 +02:00
|
|
|
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
2006-03-01 21:05:35 +01:00
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
|
|
|
strcpy(tmp, "Intel ");
|
|
|
|
switch (msi->ProcessorLevel)
|
|
|
|
{
|
2007-04-01 12:32:04 +02:00
|
|
|
case 3: str = "80386"; break;
|
|
|
|
case 4: str = "80486"; break;
|
|
|
|
case 5: str = "Pentium"; break;
|
|
|
|
case 6: str = "Pentium Pro/II or AMD Athlon"; break;
|
|
|
|
case 15: str = "Pentium 4 or AMD Athlon64"; break;
|
2006-03-01 21:05:35 +01:00
|
|
|
default: str = "???"; break;
|
|
|
|
}
|
|
|
|
strcat(tmp, str);
|
|
|
|
if (msi->ProcessorLevel == 3 || msi->ProcessorLevel == 4)
|
|
|
|
{
|
2011-05-05 15:27:06 +02:00
|
|
|
if (HIBYTE(msi->ProcessorRevision) == 0xFF)
|
2007-04-01 12:32:04 +02:00
|
|
|
sprintf(tmp + strlen(tmp), " (%c%d)",
|
2011-05-05 15:27:06 +02:00
|
|
|
'A' + ((msi->ProcessorRevision>>4)&0xf)-0x0a,
|
|
|
|
((msi->ProcessorRevision&0xf)));
|
2006-03-01 21:05:35 +01:00
|
|
|
else
|
2007-04-01 12:32:04 +02:00
|
|
|
sprintf(tmp + strlen(tmp), " (%c%d)",
|
2011-05-05 15:27:06 +02:00
|
|
|
'A' + HIBYTE(msi->ProcessorRevision),
|
|
|
|
LOBYTE(msi->ProcessorRevision));
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
2007-04-01 12:32:04 +02:00
|
|
|
else sprintf(tmp + strlen(tmp), " (%d.%d)",
|
2011-05-05 15:27:06 +02:00
|
|
|
HIBYTE(msi->ProcessorRevision),
|
|
|
|
LOBYTE(msi->ProcessorRevision));
|
2006-03-01 21:05:35 +01:00
|
|
|
str = tmp;
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_MIPS:
|
|
|
|
str = "Mips";
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_ALPHA:
|
|
|
|
str = "Alpha";
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_PPC:
|
|
|
|
str = "PowerPC";
|
|
|
|
break;
|
2010-04-15 22:16:58 +02:00
|
|
|
case PROCESSOR_ARCHITECTURE_AMD64:
|
|
|
|
str = "X86_64";
|
|
|
|
break;
|
2011-04-15 19:19:38 +02:00
|
|
|
case PROCESSOR_ARCHITECTURE_ARM:
|
|
|
|
str = "ARM";
|
|
|
|
break;
|
2006-03-01 21:05:35 +01:00
|
|
|
default:
|
|
|
|
str = "???";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dbg_printf(" %s was running on #%d %s CPU%s",
|
2008-10-18 09:15:10 +02:00
|
|
|
dbg_W2A(exec_name, -1), msi->u.s.NumberOfProcessors, str,
|
2006-03-01 21:05:35 +01:00
|
|
|
msi->u.s.NumberOfProcessors < 2 ? "" : "s");
|
|
|
|
switch (msi->MajorVersion)
|
|
|
|
{
|
|
|
|
case 3:
|
|
|
|
switch (msi->MinorVersion)
|
|
|
|
{
|
|
|
|
case 51: str = "NT 3.51"; break;
|
|
|
|
default: str = "3-????"; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
switch (msi->MinorVersion)
|
|
|
|
{
|
|
|
|
case 0: str = (msi->PlatformId == VER_PLATFORM_WIN32_NT) ? "NT 4.0" : "95"; break;
|
|
|
|
case 10: str = "98"; break;
|
|
|
|
case 90: str = "ME"; break;
|
|
|
|
default: str = "5-????"; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
switch (msi->MinorVersion)
|
|
|
|
{
|
|
|
|
case 0: str = "2000"; break;
|
|
|
|
case 1: str = "XP"; break;
|
|
|
|
case 2: str = "Server 2003"; break;
|
|
|
|
default: str = "5-????"; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: str = "???"; break;
|
|
|
|
}
|
2006-12-20 14:17:27 +01:00
|
|
|
dbg_printf(" on Windows %s (%u)\n", str, msi->BuildNumber);
|
2006-03-01 21:05:35 +01:00
|
|
|
/* FIXME CSD: msi->CSDVersionRva */
|
2012-01-23 21:36:59 +01:00
|
|
|
|
|
|
|
if (sizeof(MINIDUMP_SYSTEM_INFO) + 4 > dir->Location.DataSize &&
|
|
|
|
msi->CSDVersionRva >= dir->Location.Rva + sizeof(MINIDUMP_SYSTEM_INFO) + 4)
|
|
|
|
{
|
|
|
|
const char* code = (const char*)stream + sizeof(MINIDUMP_SYSTEM_INFO);
|
|
|
|
const DWORD* wes;
|
|
|
|
|
|
|
|
if (code[0] == 'W' && code[1] == 'I' && code[2] == 'N' && code[3] == 'E' &&
|
|
|
|
*(wes = (const DWORD*)(code += 4)) >= 3)
|
|
|
|
{
|
|
|
|
/* assume we have wine extensions */
|
|
|
|
dbg_printf(" [on %s, on top of %s (%s)]\n",
|
|
|
|
code + wes[1], code + wes[2], code + wes[3]);
|
|
|
|
}
|
|
|
|
}
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dbg_curr_process = dbg_add_process(&be_process_minidump_io, pid, hProc);
|
|
|
|
dbg_curr_pid = pid;
|
|
|
|
dbg_curr_process->pio_data = data;
|
|
|
|
dbg_set_process_name(dbg_curr_process, exec_name);
|
|
|
|
|
2008-08-30 08:44:48 +02:00
|
|
|
dbg_init(hProc, NULL, FALSE);
|
2006-03-01 21:05:35 +01:00
|
|
|
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, ThreadListStream, NULL, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
MINIDUMP_THREAD_LIST* mtl = stream;
|
2007-03-04 20:10:41 +01:00
|
|
|
ULONG i;
|
2006-03-01 21:05:35 +01:00
|
|
|
|
2007-03-04 20:10:41 +01:00
|
|
|
for (i = 0; i < mtl->NumberOfThreads; i++)
|
|
|
|
{
|
|
|
|
dbg_add_thread(dbg_curr_process, mtl->Threads[i].ThreadId, NULL,
|
2008-01-13 17:02:49 +01:00
|
|
|
(void*)(DWORD_PTR)get_addr64(mtl->Threads[i].Teb));
|
2007-03-04 20:10:41 +01:00
|
|
|
}
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
/* first load ELF modules, then do the PE ones */
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, Wine_ElfModuleListStream, NULL,
|
|
|
|
&stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2007-02-21 21:56:06 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2006-03-01 21:05:35 +01:00
|
|
|
|
2009-04-21 09:59:59 +02:00
|
|
|
mml = stream;
|
2012-07-27 14:09:40 +02:00
|
|
|
for (i = 0, mm = mml->Modules; i < mml->NumberOfModules; i++, mm++)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
|
|
|
mds = (MINIDUMP_STRING*)((char*)data->mapping + mm->ModuleNameRva);
|
2007-02-21 21:56:06 +01:00
|
|
|
memcpy(nameW, mds->Buffer, mds->Length);
|
|
|
|
nameW[mds->Length / sizeof(WCHAR)] = 0;
|
|
|
|
if (SymFindFileInPathW(hProc, NULL, nameW, (void*)(DWORD_PTR)mm->CheckSum,
|
|
|
|
0, 0, SSRVOPT_DWORD, buffer, validate_file, NULL))
|
2008-10-18 09:15:19 +02:00
|
|
|
dbg_load_module(hProc, NULL, buffer, get_addr64(mm->BaseOfImage),
|
|
|
|
mm->SizeOfImage);
|
2006-03-01 21:05:35 +01:00
|
|
|
else
|
2008-01-13 17:02:49 +01:00
|
|
|
SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
|
|
|
|
mm->SizeOfImage, NULL, SLMFLAG_VIRTUAL);
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
}
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, ModuleListStream, NULL, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2007-04-01 12:31:57 +02:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2009-04-21 09:59:59 +02:00
|
|
|
mml = stream;
|
2012-07-27 14:09:40 +02:00
|
|
|
for (i = 0, mm = mml->Modules; i < mml->NumberOfModules; i++, mm++)
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
|
|
|
mds = (MINIDUMP_STRING*)((char*)data->mapping + mm->ModuleNameRva);
|
2007-02-21 21:56:06 +01:00
|
|
|
memcpy(nameW, mds->Buffer, mds->Length);
|
|
|
|
nameW[mds->Length / sizeof(WCHAR)] = 0;
|
2007-04-01 12:31:57 +02:00
|
|
|
if (SymFindFileInPathW(hProc, NULL, nameW, (void*)(DWORD_PTR)mm->TimeDateStamp,
|
|
|
|
mm->SizeOfImage, 0, SSRVOPT_DWORD, buffer, validate_file, NULL))
|
2008-10-18 09:15:19 +02:00
|
|
|
dbg_load_module(hProc, NULL, buffer, get_addr64(mm->BaseOfImage),
|
|
|
|
mm->SizeOfImage);
|
2007-04-01 12:31:57 +02:00
|
|
|
else if (is_pe_module_embedded(data, mm))
|
2008-10-18 09:15:19 +02:00
|
|
|
dbg_load_module(hProc, NULL, nameW, get_addr64(mm->BaseOfImage),
|
|
|
|
mm->SizeOfImage);
|
2007-04-01 12:31:57 +02:00
|
|
|
else
|
2008-01-13 17:02:49 +01:00
|
|
|
SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
|
|
|
|
mm->SizeOfImage, NULL, SLMFLAG_VIRTUAL);
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
}
|
2009-05-30 14:19:26 +02:00
|
|
|
if (MiniDumpReadDumpStream(data->mapping, ExceptionStream, NULL, &stream, NULL))
|
2006-03-01 21:05:35 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
MINIDUMP_EXCEPTION_STREAM* mes = stream;
|
2006-03-01 21:05:35 +01:00
|
|
|
|
|
|
|
if ((dbg_curr_thread = dbg_get_thread(dbg_curr_process, mes->ThreadId)))
|
|
|
|
{
|
2006-07-26 11:57:27 +02:00
|
|
|
ADDRESS64 addr;
|
2006-03-01 21:05:35 +01:00
|
|
|
|
|
|
|
dbg_curr_tid = mes->ThreadId;
|
|
|
|
dbg_curr_thread->in_exception = TRUE;
|
|
|
|
dbg_curr_thread->excpt_record.ExceptionCode = mes->ExceptionRecord.ExceptionCode;
|
|
|
|
dbg_curr_thread->excpt_record.ExceptionFlags = mes->ExceptionRecord.ExceptionFlags;
|
2008-01-13 17:02:49 +01:00
|
|
|
dbg_curr_thread->excpt_record.ExceptionRecord = (void*)(DWORD_PTR)get_addr64(mes->ExceptionRecord.ExceptionRecord);
|
|
|
|
dbg_curr_thread->excpt_record.ExceptionAddress = (void*)(DWORD_PTR)get_addr64(mes->ExceptionRecord.ExceptionAddress);
|
2006-03-01 21:05:35 +01:00
|
|
|
dbg_curr_thread->excpt_record.NumberParameters = mes->ExceptionRecord.NumberParameters;
|
|
|
|
for (i = 0; i < dbg_curr_thread->excpt_record.NumberParameters; i++)
|
|
|
|
{
|
|
|
|
dbg_curr_thread->excpt_record.ExceptionInformation[i] = mes->ExceptionRecord.ExceptionInformation[i];
|
|
|
|
}
|
|
|
|
memcpy(&dbg_context, (char*)data->mapping + mes->ThreadContext.Rva,
|
|
|
|
min(sizeof(dbg_context), mes->ThreadContext.DataSize));
|
|
|
|
memory_get_current_pc(&addr);
|
2010-03-30 21:37:01 +02:00
|
|
|
stack_fetch_frames(&dbg_context);
|
2006-03-21 13:54:41 +01:00
|
|
|
be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0);
|
2010-05-25 00:48:36 +02:00
|
|
|
stack_info(-1);
|
2006-03-01 21:05:35 +01:00
|
|
|
be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context);
|
|
|
|
stack_backtrace(mes->ThreadId);
|
|
|
|
source_list_from_addr(&addr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return start_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup(struct tgt_process_minidump_data* data)
|
|
|
|
{
|
|
|
|
if (data->mapping) UnmapViewOfFile(data->mapping);
|
|
|
|
if (data->hMap) CloseHandle(data->hMap);
|
|
|
|
if (data->hFile != INVALID_HANDLE_VALUE) CloseHandle(data->hFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct be_process_io be_process_minidump_io;
|
|
|
|
|
|
|
|
enum dbg_start minidump_reload(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
struct tgt_process_minidump_data* data;
|
|
|
|
enum dbg_start ret = start_error_parse;
|
|
|
|
|
|
|
|
/* try the form <myself> minidump-file */
|
|
|
|
if (argc != 1) return start_error_parse;
|
|
|
|
|
|
|
|
WINE_TRACE("Processing Minidump file %s\n", argv[0]);
|
|
|
|
|
|
|
|
data = HeapAlloc(GetProcessHeap(), 0, sizeof(struct tgt_process_minidump_data));
|
|
|
|
if (!data) return start_error_init;
|
|
|
|
data->mapping = NULL;
|
|
|
|
data->hMap = NULL;
|
|
|
|
data->hFile = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
if ((data->hFile = CreateFileA(argv[0], GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE &&
|
|
|
|
((data->hMap = CreateFileMappingA(data->hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
|
|
|
|
((data->mapping = MapViewOfFile(data->hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
if (((MINIDUMP_HEADER*)data->mapping)->Signature == MINIDUMP_SIGNATURE)
|
|
|
|
{
|
|
|
|
ret = minidump_do_reload(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__EXCEPT_PAGE_FAULT
|
|
|
|
{
|
|
|
|
dbg_printf("Unexpected fault while reading minidump %s\n", argv[0]);
|
|
|
|
dbg_curr_pid = 0;
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
|
|
|
}
|
|
|
|
if (ret != start_ok) cleanup(data);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tgt_process_minidump_close_process(struct dbg_process* pcs, BOOL kill)
|
|
|
|
{
|
2009-03-12 14:29:53 +01:00
|
|
|
struct tgt_process_minidump_data* data = private_data(pcs);
|
2006-03-01 21:05:35 +01:00
|
|
|
|
|
|
|
cleanup(data);
|
|
|
|
pcs->pio_data = NULL;
|
|
|
|
SymCleanup(pcs->handle);
|
|
|
|
dbg_del_process(pcs);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-05 15:16:14 +02:00
|
|
|
static BOOL tgt_process_minidump_get_selector(HANDLE hThread, DWORD sel, LDT_ENTRY* le)
|
2008-01-13 17:02:55 +01:00
|
|
|
{
|
|
|
|
/* so far, pretend all selectors are valid, and mapped to a 32bit flat address space */
|
|
|
|
memset(le, 0, sizeof(*le));
|
|
|
|
le->HighWord.Bits.Default_Big = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-03-01 21:05:35 +01:00
|
|
|
static struct be_process_io be_process_minidump_io =
|
|
|
|
{
|
|
|
|
tgt_process_minidump_close_process,
|
|
|
|
tgt_process_minidump_read,
|
|
|
|
tgt_process_minidump_write,
|
2008-01-13 17:02:55 +01:00
|
|
|
tgt_process_minidump_get_selector,
|
2006-03-01 21:05:35 +01:00
|
|
|
};
|