Commit 33df0a76 authored by Andrey Turkin's avatar Andrey Turkin Committed by Alexandre Julliard

dbghelp: Adjust minidump streams ordering and sizing.

To more closely match native format; this is required for windbg.
parent 201fc77f
...@@ -351,7 +351,8 @@ static void append(struct dump_context* dc, void* data, unsigned size) ...@@ -351,7 +351,8 @@ static void append(struct dump_context* dc, void* data, unsigned size)
* Write in File the exception information from pcs * Write in File the exception information from pcs
*/ */
static void dump_exception_info(struct dump_context* dc, static void dump_exception_info(struct dump_context* dc,
const MINIDUMP_EXCEPTION_INFORMATION* except) const MINIDUMP_EXCEPTION_INFORMATION* except,
DWORD *size)
{ {
MINIDUMP_EXCEPTION_STREAM mdExcpt; MINIDUMP_EXCEPTION_STREAM mdExcpt;
EXCEPTION_RECORD rec, *prec; EXCEPTION_RECORD rec, *prec;
...@@ -390,6 +391,7 @@ static void dump_exception_info(struct dump_context* dc, ...@@ -390,6 +391,7 @@ static void dump_exception_info(struct dump_context* dc,
mdExcpt.ThreadContext.Rva = dc->rva + sizeof(mdExcpt); mdExcpt.ThreadContext.Rva = dc->rva + sizeof(mdExcpt);
append(dc, &mdExcpt, sizeof(mdExcpt)); append(dc, &mdExcpt, sizeof(mdExcpt));
*size = sizeof(mdExcpt);
append(dc, pctx, sizeof(*pctx)); append(dc, pctx, sizeof(*pctx));
} }
...@@ -398,7 +400,7 @@ static void dump_exception_info(struct dump_context* dc, ...@@ -398,7 +400,7 @@ static void dump_exception_info(struct dump_context* dc,
* *
* Write in File the modules from pcs * Write in File the modules from pcs
*/ */
static void dump_modules(struct dump_context* dc, BOOL dump_elf) static void dump_modules(struct dump_context* dc, BOOL dump_elf, DWORD *size)
{ {
MINIDUMP_MODULE mdModule; MINIDUMP_MODULE mdModule;
MINIDUMP_MODULE_LIST mdModuleList; MINIDUMP_MODULE_LIST mdModuleList;
...@@ -422,7 +424,7 @@ static void dump_modules(struct dump_context* dc, BOOL dump_elf) ...@@ -422,7 +424,7 @@ static void dump_modules(struct dump_context* dc, BOOL dump_elf)
* FIXME: if we don't ask for all modules in cb, we'll get a hole in the file * FIXME: if we don't ask for all modules in cb, we'll get a hole in the file
*/ */
rva_base = dc->rva; rva_base = dc->rva;
dc->rva += sizeof(mdModuleList.NumberOfModules) + sizeof(mdModule) * nmod; dc->rva += *size = sizeof(mdModuleList.NumberOfModules) + sizeof(mdModule) * nmod;
for (i = 0; i < dc->num_module; i++) for (i = 0; i < dc->num_module; i++)
{ {
if ((dc->module[i].is_elf && !dump_elf) || if ((dc->module[i].is_elf && !dump_elf) ||
...@@ -497,7 +499,7 @@ static void dump_modules(struct dump_context* dc, BOOL dump_elf) ...@@ -497,7 +499,7 @@ static void dump_modules(struct dump_context* dc, BOOL dump_elf)
* *
* Dumps into File the information about the system * Dumps into File the information about the system
*/ */
static void dump_system_info(struct dump_context* dc) static void dump_system_info(struct dump_context* dc, DWORD *size)
{ {
MINIDUMP_SYSTEM_INFO mdSysInfo; MINIDUMP_SYSTEM_INFO mdSysInfo;
SYSTEM_INFO sysInfo; SYSTEM_INFO sysInfo;
...@@ -525,6 +527,7 @@ static void dump_system_info(struct dump_context* dc) ...@@ -525,6 +527,7 @@ static void dump_system_info(struct dump_context* dc)
memset(&mdSysInfo.Cpu, 0, sizeof(mdSysInfo.Cpu)); memset(&mdSysInfo.Cpu, 0, sizeof(mdSysInfo.Cpu));
append(dc, &mdSysInfo, sizeof(mdSysInfo)); append(dc, &mdSysInfo, sizeof(mdSysInfo));
*size = sizeof(mdSysInfo);
slen = lstrlenW(osInfo.szCSDVersion) * sizeof(WCHAR); slen = lstrlenW(osInfo.szCSDVersion) * sizeof(WCHAR);
WriteFile(dc->hFile, &slen, sizeof(slen), &written, NULL); WriteFile(dc->hFile, &slen, sizeof(slen), &written, NULL);
...@@ -538,7 +541,8 @@ static void dump_system_info(struct dump_context* dc) ...@@ -538,7 +541,8 @@ static void dump_system_info(struct dump_context* dc)
* Dumps into File the information about running threads * Dumps into File the information about running threads
*/ */
static void dump_threads(struct dump_context* dc, static void dump_threads(struct dump_context* dc,
const MINIDUMP_EXCEPTION_INFORMATION* except) const MINIDUMP_EXCEPTION_INFORMATION* except,
DWORD *size)
{ {
MINIDUMP_THREAD mdThd; MINIDUMP_THREAD mdThd;
MINIDUMP_THREAD_LIST mdThdList; MINIDUMP_THREAD_LIST mdThdList;
...@@ -618,6 +622,7 @@ static void dump_threads(struct dump_context* dc, ...@@ -618,6 +622,7 @@ static void dump_threads(struct dump_context* dc,
} }
writeat(dc, rva_base, writeat(dc, rva_base,
&mdThdList.NumberOfThreads, sizeof(mdThdList.NumberOfThreads)); &mdThdList.NumberOfThreads, sizeof(mdThdList.NumberOfThreads));
*size = dc->rva - rva_base;
} }
/****************************************************************** /******************************************************************
...@@ -625,7 +630,7 @@ static void dump_threads(struct dump_context* dc, ...@@ -625,7 +630,7 @@ static void dump_threads(struct dump_context* dc,
* *
* dumps information about the memory of the process (stack of the threads) * dumps information about the memory of the process (stack of the threads)
*/ */
static void dump_memory_info(struct dump_context* dc) static void dump_memory_info(struct dump_context* dc, DWORD* size)
{ {
MINIDUMP_MEMORY_LIST mdMemList; MINIDUMP_MEMORY_LIST mdMemList;
MINIDUMP_MEMORY_DESCRIPTOR mdMem; MINIDUMP_MEMORY_DESCRIPTOR mdMem;
...@@ -639,6 +644,8 @@ static void dump_memory_info(struct dump_context* dc) ...@@ -639,6 +644,8 @@ static void dump_memory_info(struct dump_context* dc)
sizeof(mdMemList.NumberOfMemoryRanges)); sizeof(mdMemList.NumberOfMemoryRanges));
rva_base = dc->rva; rva_base = dc->rva;
dc->rva += mdMemList.NumberOfMemoryRanges * sizeof(mdMem); dc->rva += mdMemList.NumberOfMemoryRanges * sizeof(mdMem);
*size = sizeof(mdMemList.NumberOfMemoryRanges) +
mdMemList.NumberOfMemoryRanges * sizeof(mdMem);
for (i = 0; i < dc->num_mem; i++) for (i = 0; i < dc->num_mem; i++)
{ {
...@@ -663,7 +670,7 @@ static void dump_memory_info(struct dump_context* dc) ...@@ -663,7 +670,7 @@ static void dump_memory_info(struct dump_context* dc)
} }
} }
static void dump_misc_info(struct dump_context* dc) static void dump_misc_info(struct dump_context* dc, DWORD* size)
{ {
MINIDUMP_MISC_INFO mmi; MINIDUMP_MISC_INFO mmi;
...@@ -672,6 +679,7 @@ static void dump_misc_info(struct dump_context* dc) ...@@ -672,6 +679,7 @@ static void dump_misc_info(struct dump_context* dc)
mmi.ProcessId = dc->pid; mmi.ProcessId = dc->pid;
/* FIXME: create/user/kernel time */ /* FIXME: create/user/kernel time */
append(dc, &mmi, sizeof(mmi)); append(dc, &mmi, sizeof(mmi));
*size = sizeof(mmi);
} }
/****************************************************************** /******************************************************************
...@@ -725,6 +733,7 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile, ...@@ -725,6 +733,7 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
mdHead.StreamDirectoryRva = sizeof(mdHead); mdHead.StreamDirectoryRva = sizeof(mdHead);
mdHead.u.TimeDateStamp = time(NULL); mdHead.u.TimeDateStamp = time(NULL);
mdHead.Flags = DumpType; mdHead.Flags = DumpType;
mdHead.CheckSum = 0;
append(&dc, &mdHead, sizeof(mdHead)); append(&dc, &mdHead, sizeof(mdHead));
/* 3) write stream directories */ /* 3) write stream directories */
...@@ -733,45 +742,40 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile, ...@@ -733,45 +742,40 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
/* 3.1) write data stream directories */ /* 3.1) write data stream directories */
/* must be first in minidump */
mdDir.StreamType = SystemInfoStream;
mdDir.Location.Rva = dc.rva;
dump_system_info(&dc, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
mdDir.StreamType = ThreadListStream; mdDir.StreamType = ThreadListStream;
mdDir.Location.Rva = dc.rva; mdDir.Location.Rva = dc.rva;
dump_threads(&dc, ExceptionParam); dump_threads(&dc, ExceptionParam, &mdDir.Location.DataSize);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir), writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir)); &mdDir, sizeof(mdDir));
mdDir.StreamType = ModuleListStream; mdDir.StreamType = ModuleListStream;
mdDir.Location.Rva = dc.rva; mdDir.Location.Rva = dc.rva;
dump_modules(&dc, FALSE); dump_modules(&dc, FALSE, &mdDir.Location.DataSize);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir), writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir)); &mdDir, sizeof(mdDir));
mdDir.StreamType = 0xfff0; /* FIXME: this is part of MS reserved streams */ mdDir.StreamType = 0xfff0; /* FIXME: this is part of MS reserved streams */
mdDir.Location.Rva = dc.rva; mdDir.Location.Rva = dc.rva;
dump_modules(&dc, TRUE); dump_modules(&dc, TRUE, &mdDir.Location.DataSize);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir), writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir)); &mdDir, sizeof(mdDir));
mdDir.StreamType = MemoryListStream; mdDir.StreamType = MemoryListStream;
mdDir.Location.Rva = dc.rva; mdDir.Location.Rva = dc.rva;
dump_memory_info(&dc); dump_memory_info(&dc, &mdDir.Location.DataSize);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
mdDir.StreamType = SystemInfoStream;
mdDir.Location.Rva = dc.rva;
dump_system_info(&dc);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir), writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir)); &mdDir, sizeof(mdDir));
mdDir.StreamType = MiscInfoStream; mdDir.StreamType = MiscInfoStream;
mdDir.Location.Rva = dc.rva; mdDir.Location.Rva = dc.rva;
dump_misc_info(&dc); dump_misc_info(&dc, &mdDir.Location.DataSize);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir), writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir)); &mdDir, sizeof(mdDir));
...@@ -780,8 +784,7 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile, ...@@ -780,8 +784,7 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
{ {
mdDir.StreamType = ExceptionStream; mdDir.StreamType = ExceptionStream;
mdDir.Location.Rva = dc.rva; mdDir.Location.Rva = dc.rva;
dump_exception_info(&dc, ExceptionParam); dump_exception_info(&dc, ExceptionParam, &mdDir.Location.DataSize);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir), writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir)); &mdDir, sizeof(mdDir));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment