From 2915feb81e5178700d070324a9888e8fcf70a7d6 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Tue, 13 May 2014 10:26:26 +0000 Subject: [PATCH] * minidumper.cc (filter_minidump_type): New function. (minidump): Change default dump type from MiniDumpNormal to something with more useful information without getting too big. Use filter_minidump_type() to filter out unsupported dump types. --- winsup/utils/ChangeLog | 8 +++++ winsup/utils/minidumper.cc | 65 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index 9ca783c1a..c37d5d016 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,11 @@ +2014-04-21 Jon TURNEY + + * minidumper.cc (filter_minidump_type): New function. + (minidump): Change default dump type from MiniDumpNormal to + something with more useful information without getting too + big. Use filter_minidump_type() to filter out unsupported dump + types. + 2014-04-21 Jon TURNEY * Makefile.in (minidumper.exe): Link directly with dbghelp. diff --git a/winsup/utils/minidumper.cc b/winsup/utils/minidumper.cc index ea1e193c2..04685665e 100644 --- a/winsup/utils/minidumper.cc +++ b/winsup/utils/minidumper.cc @@ -28,9 +28,57 @@ #include #include +DEFINE_ENUM_FLAG_OPERATORS(MINIDUMP_TYPE); + BOOL verbose = FALSE; BOOL nokill = FALSE; +/* Not yet in dbghelp.h */ +#define MiniDumpWithModuleHeaders (static_cast(0x00080000)) +#define MiniDumpFilterTriage (static_cast(0x00100000)) + +static MINIDUMP_TYPE +filter_minidump_type(MINIDUMP_TYPE dump_type) +{ + API_VERSION build_version = { 6, 0, API_VERSION_NUMBER, 0 }; + API_VERSION *v = ImagehlpApiVersionEx(&build_version); + + if (verbose) + printf ("dbghelp version %d.%d.%d.%d\n", v->MajorVersion, + v->MinorVersion, v->Revision, v->Reserved); + + MINIDUMP_TYPE supported_types = MiniDumpNormal | MiniDumpWithDataSegs + | MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpFilterMemory + | MiniDumpScanMemory; + + /* + This mainly trial and error and guesswork, as the MSDN documentation only + says what version of "Debugging Tools for Windows" added these flags, but + doesn't actually tell us the dbghelp.dll version which was contained in that + (and seems to have errors as well) + */ + + if (v->MajorVersion >= 5) + supported_types |= MiniDumpWithUnloadedModules + | MiniDumpWithIndirectlyReferencedMemory | MiniDumpFilterModulePaths + | MiniDumpWithProcessThreadData | MiniDumpWithPrivateReadWriteMemory; + + if (v->MajorVersion >= 6) + supported_types |= MiniDumpWithoutOptionalData | MiniDumpWithFullMemoryInfo + | MiniDumpWithThreadInfo | MiniDumpWithCodeSegs + | MiniDumpWithoutAuxiliaryState | MiniDumpWithFullAuxiliaryState // seems to be documentation error that these two aren't listed as 'Not supported prior to 6.1' + | MiniDumpWithPrivateWriteCopyMemory | MiniDumpIgnoreInaccessibleMemory + | MiniDumpWithTokenInformation; + + if ((v->MajorVersion*10 + v->MinorVersion) >= 62) + supported_types |= MiniDumpWithModuleHeaders | MiniDumpFilterTriage; // seems to be documentation error that these two are listed as 'Not supported prior to 6.1' + + if (verbose) + printf ("supported MINIDUMP_TYPE flags 0x%x\n", supported_types); + + return (dump_type & supported_types); +} + static void minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file) { @@ -137,6 +185,7 @@ main (int argc, char **argv) int opt; const char *p = ""; DWORD pid; + BOOL default_dump_type = TRUE; MINIDUMP_TYPE dump_type = MiniDumpNormal; while ((opt = getopt_long (argc, argv, opts, longopts, NULL) ) != EOF) @@ -145,6 +194,7 @@ main (int argc, char **argv) case 't': { char *endptr; + default_dump_type = FALSE; dump_type = (MINIDUMP_TYPE)strtoul(optarg, &endptr, 0); if (*endptr != '\0') { @@ -201,6 +251,21 @@ main (int argc, char **argv) } sprintf (minidump_file, "%s.dmp", p); + if (default_dump_type) + { + dump_type = MiniDumpWithHandleData | MiniDumpWithFullMemoryInfo + | MiniDumpWithThreadInfo | MiniDumpWithFullAuxiliaryState + | MiniDumpIgnoreInaccessibleMemory | MiniDumpWithTokenInformation + | MiniDumpWithIndirectlyReferencedMemory; + + /* + Only filter out unsupported dump_type flags if we are using the default + dump type, so that future dump_type flags can be explicitly used even if + we don't know about them + */ + dump_type = filter_minidump_type(dump_type); + } + if (verbose) printf ("dumping process %u to %s using dump type flags 0x%x\n", (unsigned int)pid, minidump_file, (unsigned int)dump_type); -- 2.43.5