Skip to content

Instantly share code, notes, and snippets.

@zhuyifei1999
Created January 20, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuyifei1999/ff2094d04b91c8ef704e79ab816993aa to your computer and use it in GitHub Desktop.
Save zhuyifei1999/ff2094d04b91c8ef704e79ab816993aa to your computer and use it in GitHub Desktop.
diff --git a/src/google_breakpad/common/minidump_format.h b/src/google_breakpad/common/minidump_format.h
index 7b36d112..0899b4a3 100644
--- a/src/google_breakpad/common/minidump_format.h
+++ b/src/google_breakpad/common/minidump_format.h
@@ -318,7 +318,7 @@ typedef enum {
MD_EXCEPTION_STREAM = 6, /* MDRawExceptionStream */
MD_SYSTEM_INFO_STREAM = 7, /* MDRawSystemInfo */
MD_THREAD_EX_LIST_STREAM = 8,
- MD_MEMORY_64_LIST_STREAM = 9,
+ MD_MEMORY_64_LIST_STREAM = 9, /* MDRawMemory64List */
MD_COMMENT_STREAM_A = 10,
MD_COMMENT_STREAM_W = 11,
MD_HANDLE_DATA_STREAM = 12,
@@ -529,6 +529,20 @@ static const size_t MDRawMemoryList_minsize = offsetof(MDRawMemoryList,
memory_ranges[0]);
+typedef struct {
+ uint64_t start_of_memory_range;
+ uint64_t data_size;
+} MDMemory64Descriptor; /* MINIDUMP_MEMORY_DESCRIPTOR64 */
+
+typedef struct {
+ uint64_t number_of_memory_ranges;
+ uint64_t base_rva;
+ MDMemory64Descriptor memory_ranges[1];
+} MDRawMemory64List; /* MINIDUMP_MEMORY64_LIST */
+
+static const size_t MDRawMemory64List_minsize = offsetof(MDRawMemory64List,
+ memory_ranges[0]);
+
#define MD_EXCEPTION_MAXIMUM_PARAMETERS 15u
typedef struct {
@@ -719,7 +733,7 @@ typedef struct {
uint16_t standard_name[32]; /* UTF-16-encoded, 0-terminated */
/* A MDSystemTime structure that contains a date and local time when the
* transition from daylight saving time to standard time occurs on this
- * operating system. If the time zone does not support daylight saving time,
+ * operating system. If the time zone does not support daylight saving time,
* the month member in the MDSystemTime structure is zero. */
MDSystemTime standard_date;
/* The bias value to be used during local time translations that occur during
@@ -731,7 +745,7 @@ typedef struct {
uint16_t daylight_name[32]; /* UTF-16-encoded, 0-terminated */
/* A MDSystemTime structure that contains a date and local time when the
* transition from standard time to daylight saving time occurs on this
- * operating system. If the time zone does not support daylight saving time,
+ * operating system. If the time zone does not support daylight saving time,
* the month member in the MDSystemTime structure is zero.*/
MDSystemTime daylight_date;
/* The bias value to be used during local time translations that occur during
@@ -810,7 +824,7 @@ typedef struct {
* 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
* MD_MISCINFO_FLAGS1_PROCESS_INTEGRITY. */
uint32_t process_integrity_level;
diff --git a/src/tools/linux/md2core/minidump-2-core.cc b/src/tools/linux/md2core/minidump-2-core.cc
index aade82c9..533a1bba 100644
--- a/src/tools/linux/md2core/minidump-2-core.cc
+++ b/src/tools/linux/md2core/minidump-2-core.cc
@@ -301,6 +301,13 @@ struct CrashedProcess {
string filename;
string data;
};
+
+ struct MemRange {
+ uint64_t start_address;
+ string data;
+ };
+ std::vector<MemRange> memranges;
+
std::map<uint64_t, Mapping> mappings;
pid_t crashing_tid;
@@ -570,6 +577,63 @@ ParseThreadList(const Options& options, CrashedProcess* crashinfo,
}
}
+static void
+ParseMemoryList(const Options& options, CrashedProcess* crashinfo,
+ const MinidumpMemoryRange& range,
+ const MinidumpMemoryRange& full_file) {
+ const uint32_t number_of_memory_ranges = *range.GetData<uint32_t>(0);
+ if (options.verbose) {
+ fprintf(stderr,
+ "MD_MEMORY_LIST_STREAM:\n"
+ "Found %d memory ranges\n"
+ "\n\n",
+ number_of_memory_ranges);
+ }
+ for (unsigned i = 0; i < number_of_memory_ranges; ++i) {
+ CrashedProcess::MemRange memrange;
+ memset(&memrange, 0, sizeof(memrange));
+ const MDMemoryDescriptor* desc =
+ range.GetArrayElement<MDMemoryDescriptor>(sizeof(uint32_t), i);
+ memrange.start_address = desc->start_of_memory_range;
+ MinidumpMemoryRange file_mem_range =
+ full_file.Subrange(desc->memory);
+
+ memrange.data = string(reinterpret_cast<const char*>(file_mem_range.data()),
+ file_mem_range.length());
+
+ crashinfo->memranges.push_back(memrange);
+ }
+}
+
+static void
+ParseMemory64List(const Options& options, CrashedProcess* crashinfo,
+ const MinidumpMemoryRange& range,
+ const MinidumpMemoryRange& full_file) {
+ const uint64_t number_of_memory_ranges = *range.GetData<uint64_t>(0);
+ uint64_t rva = *range.GetData<uint64_t>(sizeof(uint64_t));
+ if (options.verbose) {
+ fprintf(stderr,
+ "MD_MEMORY_64_LIST_STREAM:\n"
+ "Found %ld memory ranges\n"
+ "\n\n",
+ number_of_memory_ranges);
+ }
+ for (unsigned i = 0; i < number_of_memory_ranges; ++i) {
+ CrashedProcess::MemRange memrange;
+ memset(&memrange, 0, sizeof(memrange));
+ const MDMemory64Descriptor* desc =
+ range.GetArrayElement<MDMemory64Descriptor>(sizeof(uint64_t) * 2, i);
+ memrange.start_address = desc->start_of_memory_range;
+ MinidumpMemoryRange file_mem_range =
+ full_file.Subrange(rva, desc->data_size);
+ rva += desc->data_size;
+ memrange.data = string(reinterpret_cast<const char*>(file_mem_range.data()),
+ file_mem_range.length());
+
+ crashinfo->memranges.push_back(memrange);
+ }
+}
+
static void
ParseSystemInfo(const Options& options, CrashedProcess* crashinfo,
const MinidumpMemoryRange& range,
@@ -630,7 +694,7 @@ ParseSystemInfo(const Options& options, CrashedProcess* crashinfo,
"Linux") &&
sysinfo->platform_id != MD_OS_NACL) {
fprintf(stderr, "This minidump was not generated by Linux or NaCl.\n");
- exit(1);
+ // exit(1);
}
if (options.verbose) {
@@ -1073,11 +1137,9 @@ AugmentMappings(const Options& options, CrashedProcess* crashinfo,
const MinidumpMemoryRange& full_file) {
// For each thread, find the memory mapping that matches the thread's stack.
// Then adjust the mapping to include the stack dump.
- for (unsigned i = 0; i < crashinfo->threads.size(); ++i) {
- const CrashedProcess::Thread& thread = crashinfo->threads[i];
- AddDataToMapping(crashinfo,
- string((char*)thread.stack, thread.stack_length),
- thread.stack_addr);
+ for (unsigned i = 0; i < crashinfo->memranges.size(); ++i) {
+ const CrashedProcess::MemRange& memrange = crashinfo->memranges[i];
+ AddDataToMapping(crashinfo, memrange.data, memrange.start_address);
}
// Create a new link map with information about DSOs. We move this map to
@@ -1247,6 +1309,14 @@ main(int argc, const char* argv[]) {
ParseThreadList(options, &crashinfo, dump.Subrange(dirent->location),
dump);
break;
+ case MD_MEMORY_LIST_STREAM:
+ ParseMemoryList(options, &crashinfo, dump.Subrange(dirent->location),
+ dump);
+ break;
+ case MD_MEMORY_64_LIST_STREAM:
+ ParseMemory64List(options, &crashinfo, dump.Subrange(dirent->location),
+ dump);
+ break;
case MD_LINUX_CPU_INFO:
ParseCPUInfo(options, &crashinfo, dump.Subrange(dirent->location));
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment