dbghelp: Adjust minidump streams ordering and sizing.

To more closely match native format; this is required for windbg.
This commit is contained in:
Andrey Turkin 2007-12-22 04:21:56 +03:00 committed by Alexandre Julliard
parent 201fc77fd6
commit 33df0a7605
1 changed files with 29 additions and 26 deletions

View File

@ -351,7 +351,8 @@ static void append(struct dump_context* dc, void* data, unsigned size)
* Write in File the exception information from pcs
*/
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;
EXCEPTION_RECORD rec, *prec;
@ -390,6 +391,7 @@ static void dump_exception_info(struct dump_context* dc,
mdExcpt.ThreadContext.Rva = dc->rva + sizeof(mdExcpt);
append(dc, &mdExcpt, sizeof(mdExcpt));
*size = sizeof(mdExcpt);
append(dc, pctx, sizeof(*pctx));
}
@ -398,7 +400,7 @@ static void dump_exception_info(struct dump_context* dc,
*
* 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_LIST mdModuleList;
@ -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
*/
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++)
{
if ((dc->module[i].is_elf && !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
*/
static void dump_system_info(struct dump_context* dc)
static void dump_system_info(struct dump_context* dc, DWORD *size)
{
MINIDUMP_SYSTEM_INFO mdSysInfo;
SYSTEM_INFO sysInfo;
@ -525,6 +527,7 @@ static void dump_system_info(struct dump_context* dc)
memset(&mdSysInfo.Cpu, 0, sizeof(mdSysInfo.Cpu));
append(dc, &mdSysInfo, sizeof(mdSysInfo));
*size = sizeof(mdSysInfo);
slen = lstrlenW(osInfo.szCSDVersion) * sizeof(WCHAR);
WriteFile(dc->hFile, &slen, sizeof(slen), &written, NULL);
@ -538,7 +541,8 @@ static void dump_system_info(struct dump_context* dc)
* Dumps into File the information about running threads
*/
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_LIST mdThdList;
@ -618,6 +622,7 @@ static void dump_threads(struct dump_context* dc,
}
writeat(dc, rva_base,
&mdThdList.NumberOfThreads, sizeof(mdThdList.NumberOfThreads));
*size = dc->rva - rva_base;
}
/******************************************************************
@ -625,7 +630,7 @@ static void dump_threads(struct dump_context* dc,
*
* 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_DESCRIPTOR mdMem;
@ -639,6 +644,8 @@ static void dump_memory_info(struct dump_context* dc)
sizeof(mdMemList.NumberOfMemoryRanges));
rva_base = dc->rva;
dc->rva += mdMemList.NumberOfMemoryRanges * sizeof(mdMem);
*size = sizeof(mdMemList.NumberOfMemoryRanges) +
mdMemList.NumberOfMemoryRanges * sizeof(mdMem);
for (i = 0; i < dc->num_mem; i++)
{
@ -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;
@ -672,6 +679,7 @@ static void dump_misc_info(struct dump_context* dc)
mmi.ProcessId = dc->pid;
/* FIXME: create/user/kernel time */
append(dc, &mmi, sizeof(mmi));
*size = sizeof(mmi);
}
/******************************************************************
@ -725,6 +733,7 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
mdHead.StreamDirectoryRva = sizeof(mdHead);
mdHead.u.TimeDateStamp = time(NULL);
mdHead.Flags = DumpType;
mdHead.CheckSum = 0;
append(&dc, &mdHead, sizeof(mdHead));
/* 3) write stream directories */
@ -733,45 +742,40 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
/* 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.Location.Rva = dc.rva;
dump_threads(&dc, ExceptionParam);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
dump_threads(&dc, ExceptionParam, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
mdDir.StreamType = ModuleListStream;
mdDir.Location.Rva = dc.rva;
dump_modules(&dc, FALSE);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
dump_modules(&dc, FALSE, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
mdDir.StreamType = 0xfff0; /* FIXME: this is part of MS reserved streams */
mdDir.Location.Rva = dc.rva;
dump_modules(&dc, TRUE);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
dump_modules(&dc, TRUE, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
mdDir.StreamType = MemoryListStream;
mdDir.Location.Rva = dc.rva;
dump_memory_info(&dc);
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;
dump_memory_info(&dc, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
mdDir.StreamType = MiscInfoStream;
mdDir.Location.Rva = dc.rva;
dump_misc_info(&dc);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
dump_misc_info(&dc, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
@ -780,8 +784,7 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
{
mdDir.StreamType = ExceptionStream;
mdDir.Location.Rva = dc.rva;
dump_exception_info(&dc, ExceptionParam);
mdDir.Location.DataSize = dc.rva - mdDir.Location.Rva;
dump_exception_info(&dc, ExceptionParam, &mdDir.Location.DataSize);
writeat(&dc, mdHead.StreamDirectoryRva + idx_stream++ * sizeof(mdDir),
&mdDir, sizeof(mdDir));
}