From 91f746ec818f9f9a40c876210d67e78880684b84 Mon Sep 17 00:00:00 2001 From: "mark@chromium.org" Date: Tue, 3 Jun 2014 19:35:41 +0000 Subject: [PATCH] Add missing MD_MISCINFO_FLAGS1_BUILDSTRING. Revise documentation to clarify that it is not enough to check the size of an MDRawMiscInfo stream to verify member validity, the flags1 field needs to be consulted as well. Update minidump_dump to correctly consider the validity of all fields in this structure. R=ivanpe@chromium.org Review URL: https://breakpad.appspot.com/3694002 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1336 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/google_breakpad/common/minidump_format.h | 25 +-- src/processor/minidump.cc | 188 ++++++++++++++----- 2 files changed, 158 insertions(+), 55 deletions(-) diff --git a/src/google_breakpad/common/minidump_format.h b/src/google_breakpad/common/minidump_format.h index b7ad7bda..109c72e6 100644 --- a/src/google_breakpad/common/minidump_format.h +++ b/src/google_breakpad/common/minidump_format.h @@ -724,8 +724,8 @@ typedef struct { uint32_t process_kernel_time; /* seconds of kernel CPU time */ /* The following fields are not present in MINIDUMP_MISC_INFO but are - * in MINIDUMP_MISC_INFO_2. When this struct is populated, these value - * may not be set. Use flags1 or size_of_info to determine whether these + * in MINIDUMP_MISC_INFO_2. When this struct is populated, these values + * may not be set. Use flags1 and size_of_info to determine whether these * values are present. These are only valid when flags1 contains * MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO. */ uint32_t processor_max_mhz; @@ -735,8 +735,8 @@ typedef struct { uint32_t processor_current_idle_state; /* The following fields are not present in MINIDUMP_MISC_INFO_2 but are - * in MINIDUMP_MISC_INFO_3. When this struct is populated, these value - * may not be set. Use flags1 or size_of_info to determine whether these + * in MINIDUMP_MISC_INFO_3. When this struct is populated, these values + * may not be set. Use flags1 and size_of_info to determine whether these * values are present. */ /* The following field is only valid if flags1 contains @@ -757,16 +757,17 @@ typedef struct { MDTimeZoneInformation time_zone; /* The following fields are not present in MINIDUMP_MISC_INFO_3 but are - * in MINIDUMP_MISC_INFO_4. When this struct is populated, these value - * may not be set. Use size_of_info to determine whether these values are - * present. */ + * in MINIDUMP_MISC_INFO_4. When this struct is populated, these values + * may not be set. Use flags1 and size_of_info to determine whether these + * values are present. */ - /* The following 2 fields are only valid if - * size_of_info is >= MD_MISCINFO4_SIZE */ + /* The following 2 fields are only valid if flags1 contains + * MD_MISCINFO_FLAGS1_BUILDSTRING. */ uint16_t build_string[MD_MAX_PATH]; /* UTF-16-encoded, 0-terminated */ uint16_t dbg_bld_str[40]; /* UTF-16-encoded, 0-terminated */ -} MDRawMiscInfo; /* MINIDUMP_MISC_INFO, MINIDUMP_MISC_INFO2, - * MINIDUMP_MISC_INFO3, MINIDUMP_MISC_INFO4 */ +} MDRawMiscInfo; /* MINIDUMP_MISC_INFO, MINIDUMP_MISC_INFO_2, + * MINIDUMP_MISC_INFO_3, MINIDUMP_MISC_INFO_4, + * MINIDUMP_MISC_INFO_N */ static const size_t MD_MISCINFO_SIZE = offsetof(MDRawMiscInfo, processor_max_mhz); @@ -793,6 +794,8 @@ typedef enum { /* MINIDUMP_MISC3_TIMEZONE */ MD_MISCINFO_FLAGS1_PROTECTED_PROCESS = 0x00000080, /* MINIDUMP_MISC3_PROTECTED_PROCESS */ + MD_MISCINFO_FLAGS1_BUILDSTRING = 0x00000100, + /* MINIDUMP_MISC4_BUILDSTRING */ } MDMiscInfoFlags1; /* diff --git a/src/processor/minidump.cc b/src/processor/minidump.cc index 5e81e67e..911fe9ba 100644 --- a/src/processor/minidump.cc +++ b/src/processor/minidump.cc @@ -344,6 +344,29 @@ static void ConvertUTF16BufferToUTF8String(const uint16_t* utf16_data, } } + +// For fields that may or may not be valid, PrintValueOrInvalid will print the +// string "(invalid)" if the field is not valid, and will print the value if +// the field is valid. The value is printed as hexadecimal or decimal. + +enum NumberFormat { + kNumberFormatDecimal, + kNumberFormatHexadecimal, +}; + +static void PrintValueOrInvalid(bool valid, + NumberFormat number_format, + uint32_t value) { + if (!valid) { + printf("(invalid)\n"); + } else if (number_format == kNumberFormatDecimal) { + printf("%d\n", value); + } else { + printf("0x%x\n", value); + } +} + + // // MinidumpObject // @@ -3785,7 +3808,7 @@ void MinidumpSystemInfo::Print() { } printf("MDRawSystemInfo\n"); - printf(" processor_architecture = %d\n", + printf(" processor_architecture = 0x%x\n", system_info_.processor_architecture); printf(" processor_level = %d\n", system_info_.processor_level); @@ -3801,7 +3824,7 @@ void MinidumpSystemInfo::Print() { system_info_.minor_version); printf(" build_number = %d\n", system_info_.build_number); - printf(" platform_id = %d\n", + printf(" platform_id = 0x%x\n", system_info_.platform_id); printf(" csd_version_rva = 0x%x\n", system_info_.csd_version_rva); @@ -3937,43 +3960,124 @@ void MinidumpMiscInfo::Print() { // Print version 1 fields printf(" size_of_info = %d\n", misc_info_.size_of_info); printf(" flags1 = 0x%x\n", misc_info_.flags1); - printf(" process_id = 0x%x\n", misc_info_.process_id); - printf(" process_create_time = 0x%x\n", - misc_info_.process_create_time); - printf(" process_user_time = 0x%x\n", - misc_info_.process_user_time); - printf(" process_kernel_time = 0x%x\n", - misc_info_.process_kernel_time); + printf(" process_id = "); + PrintValueOrInvalid(misc_info_.flags1 & MD_MISCINFO_FLAGS1_PROCESS_ID, + kNumberFormatDecimal, misc_info_.process_id); + if (misc_info_.flags1 & MD_MISCINFO_FLAGS1_PROCESS_TIMES) { + struct tm timestruct; +#ifdef _WIN32 + gmtime_s(×truct, + reinterpret_cast(&misc_info_.process_create_time)); +#else + gmtime_r(reinterpret_cast(&misc_info_.process_create_time), + ×truct); +#endif + char timestr[20]; + strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", ×truct); + printf(" process_create_time = 0x%x %s\n", + misc_info_.process_create_time, + timestr); + } else { + printf(" process_create_time = (invalid)\n"); + } + printf(" process_user_time = "); + PrintValueOrInvalid(misc_info_.flags1 & MD_MISCINFO_FLAGS1_PROCESS_TIMES, + kNumberFormatDecimal, misc_info_.process_user_time); + printf(" process_kernel_time = "); + PrintValueOrInvalid(misc_info_.flags1 & MD_MISCINFO_FLAGS1_PROCESS_TIMES, + kNumberFormatDecimal, misc_info_.process_kernel_time); if (misc_info_.size_of_info > MD_MISCINFO_SIZE) { // Print version 2 fields - printf(" processor_max_mhz = %d\n", - misc_info_.processor_max_mhz); - printf(" processor_current_mhz = %d\n", - misc_info_.processor_current_mhz); - printf(" processor_mhz_limit = %d\n", - misc_info_.processor_mhz_limit); - printf(" processor_max_idle_state = 0x%x\n", - misc_info_.processor_max_idle_state); - printf(" processor_current_idle_state = 0x%x\n", - misc_info_.processor_current_idle_state); + printf(" processor_max_mhz = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO, + kNumberFormatDecimal, misc_info_.processor_max_mhz); + printf(" processor_current_mhz = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO, + kNumberFormatDecimal, misc_info_.processor_current_mhz); + printf(" processor_mhz_limit = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO, + kNumberFormatDecimal, misc_info_.processor_mhz_limit); + printf(" processor_max_idle_state = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO, + kNumberFormatDecimal, + misc_info_.processor_max_idle_state); + printf(" processor_current_idle_state = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO, + kNumberFormatDecimal, + misc_info_.processor_current_idle_state); } if (misc_info_.size_of_info > MD_MISCINFO2_SIZE) { // Print version 3 fields - printf(" process_integrity_level = 0x%x\n", - misc_info_.process_integrity_level); - printf(" process_execute_flags = 0x%x\n", - misc_info_.process_execute_flags); - printf(" protected_process = %d\n", - misc_info_.protected_process); - printf(" time_zone_id = %d\n", misc_info_.time_zone_id); - printf(" time_zone.bias = %d\n", misc_info_.time_zone.bias); - printf(" time_zone.standard_name = %s\n", standard_name_.c_str()); - printf(" time_zone.daylight_name = %s\n", daylight_name_.c_str()); + printf(" process_integrity_level = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESS_INTEGRITY, + kNumberFormatHexadecimal, + misc_info_.process_integrity_level); + printf(" process_execute_flags = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROCESS_EXECUTE_FLAGS, + kNumberFormatHexadecimal, + misc_info_.process_execute_flags); + printf(" protected_process = "); + PrintValueOrInvalid(misc_info_.flags1 & + MD_MISCINFO_FLAGS1_PROTECTED_PROCESS, + kNumberFormatDecimal, misc_info_.protected_process); + printf(" time_zone_id = "); + PrintValueOrInvalid(misc_info_.flags1 & MD_MISCINFO_FLAGS1_TIMEZONE, + kNumberFormatDecimal, misc_info_.time_zone_id); + if (misc_info_.flags1 & MD_MISCINFO_FLAGS1_TIMEZONE) { + printf(" time_zone.bias = %d\n", + misc_info_.time_zone.bias); + printf(" time_zone.standard_name = %s\n", standard_name_.c_str()); + printf(" time_zone.standard_date = " + "%04d-%02d-%02d (%d) %02d:%02d:%02d.%03d\n", + misc_info_.time_zone.standard_date.year, + misc_info_.time_zone.standard_date.month, + misc_info_.time_zone.standard_date.day, + misc_info_.time_zone.standard_date.day_of_week, + misc_info_.time_zone.standard_date.hour, + misc_info_.time_zone.standard_date.minute, + misc_info_.time_zone.standard_date.second, + misc_info_.time_zone.standard_date.milliseconds); + printf(" time_zone.standard_bias = %d\n", + misc_info_.time_zone.standard_bias); + printf(" time_zone.daylight_name = %s\n", daylight_name_.c_str()); + printf(" time_zone.daylight_date = " + "%04d-%02d-%02d (%d) %02d:%02d:%02d.%03d\n", + misc_info_.time_zone.daylight_date.year, + misc_info_.time_zone.daylight_date.month, + misc_info_.time_zone.daylight_date.day, + misc_info_.time_zone.daylight_date.day_of_week, + misc_info_.time_zone.daylight_date.hour, + misc_info_.time_zone.daylight_date.minute, + misc_info_.time_zone.daylight_date.second, + misc_info_.time_zone.daylight_date.milliseconds); + printf(" time_zone.daylight_bias = %d\n", + misc_info_.time_zone.daylight_bias); + } else { + printf(" time_zone.bias = (invalid)\n"); + printf(" time_zone.standard_name = (invalid)\n"); + printf(" time_zone.standard_date = (invalid)\n"); + printf(" time_zone.standard_bias = (invalid)\n"); + printf(" time_zone.daylight_name = (invalid)\n"); + printf(" time_zone.daylight_date = (invalid)\n"); + printf(" time_zone.daylight_bias = (invalid)\n"); + } } if (misc_info_.size_of_info > MD_MISCINFO3_SIZE) { // Print version 4 fields - printf(" build_string = %s\n", build_string_.c_str()); - printf(" dbg_bld_str = %s\n", dbg_bld_str_.c_str()); + if (misc_info_.flags1 & MD_MISCINFO_FLAGS1_BUILDSTRING) { + printf(" build_string = %s\n", build_string_.c_str()); + printf(" dbg_bld_str = %s\n", dbg_bld_str_.c_str()); + } else { + printf(" build_string = (invalid)\n"); + printf(" dbg_bld_str = (invalid)\n"); + } } printf("\n"); } @@ -4067,19 +4171,15 @@ void MinidumpBreakpadInfo::Print() { printf("MDRawBreakpadInfo\n"); printf(" validity = 0x%x\n", breakpad_info_.validity); - - if (breakpad_info_.validity & MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID) { - printf(" dump_thread_id = 0x%x\n", breakpad_info_.dump_thread_id); - } else { - printf(" dump_thread_id = (invalid)\n"); - } - - if (breakpad_info_.validity & MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID) { - printf(" requesting_thread_id = 0x%x\n", - breakpad_info_.requesting_thread_id); - } else { - printf(" requesting_thread_id = (invalid)\n"); - } + printf(" dump_thread_id = "); + PrintValueOrInvalid(breakpad_info_.validity & + MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID, + kNumberFormatHexadecimal, breakpad_info_.dump_thread_id); + printf(" requesting_thread_id = "); + PrintValueOrInvalid(breakpad_info_.validity & + MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID, + kNumberFormatHexadecimal, + breakpad_info_.requesting_thread_id); printf("\n"); }