toolkit/crashreporter/test/dumputils.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 #include <stdio.h>
michael@0 2
michael@0 3 #include "google_breakpad/processor/minidump.h"
michael@0 4 #include "nscore.h"
michael@0 5
michael@0 6 using namespace google_breakpad;
michael@0 7
michael@0 8 // Return true if the specified minidump contains a stream of |stream_type|.
michael@0 9 extern "C"
michael@0 10 NS_EXPORT bool
michael@0 11 DumpHasStream(const char* dump_file, uint32_t stream_type)
michael@0 12 {
michael@0 13 Minidump dump(dump_file);
michael@0 14 if (!dump.Read())
michael@0 15 return false;
michael@0 16
michael@0 17 uint32_t length;
michael@0 18 if (!dump.SeekToStreamType(stream_type, &length) || length == 0)
michael@0 19 return false;
michael@0 20
michael@0 21 return true;
michael@0 22 }
michael@0 23
michael@0 24 // Return true if the specified minidump contains a memory region
michael@0 25 // that contains the instruction pointer from the exception record.
michael@0 26 extern "C"
michael@0 27 NS_EXPORT bool
michael@0 28 DumpHasInstructionPointerMemory(const char* dump_file)
michael@0 29 {
michael@0 30 Minidump minidump(dump_file);
michael@0 31 if (!minidump.Read())
michael@0 32 return false;
michael@0 33
michael@0 34 MinidumpException* exception = minidump.GetException();
michael@0 35 MinidumpMemoryList* memory_list = minidump.GetMemoryList();
michael@0 36 if (!exception || !memory_list) {
michael@0 37 return false;
michael@0 38 }
michael@0 39
michael@0 40 MinidumpContext* context = exception->GetContext();
michael@0 41 if (!context)
michael@0 42 return false;
michael@0 43
michael@0 44 uint64_t instruction_pointer;
michael@0 45 if (!context->GetInstructionPointer(&instruction_pointer)) {
michael@0 46 return false;
michael@0 47 }
michael@0 48
michael@0 49 MinidumpMemoryRegion* region =
michael@0 50 memory_list->GetMemoryRegionForAddress(instruction_pointer);
michael@0 51 return region != nullptr;
michael@0 52 }
michael@0 53
michael@0 54 // This function tests for a very specific condition. It finds
michael@0 55 // an address in a file, "crash-addr", in the CWD. It checks
michael@0 56 // that the minidump has a memory region starting at that
michael@0 57 // address. The region must be 32 bytes long and contain the
michael@0 58 // values 0 to 31 as bytes, in ascending order.
michael@0 59 extern "C"
michael@0 60 NS_EXPORT bool
michael@0 61 DumpCheckMemory(const char* dump_file)
michael@0 62 {
michael@0 63 Minidump dump(dump_file);
michael@0 64 if (!dump.Read())
michael@0 65 return false;
michael@0 66
michael@0 67 MinidumpMemoryList* memory_list = dump.GetMemoryList();
michael@0 68 if (!memory_list) {
michael@0 69 return false;
michael@0 70 }
michael@0 71
michael@0 72 void *addr;
michael@0 73 FILE *fp = fopen("crash-addr", "r");
michael@0 74 if (!fp)
michael@0 75 return false;
michael@0 76 if (fscanf(fp, "%p", &addr) != 1)
michael@0 77 return false;
michael@0 78 fclose(fp);
michael@0 79
michael@0 80 remove("crash-addr");
michael@0 81
michael@0 82 MinidumpMemoryRegion* region =
michael@0 83 memory_list->GetMemoryRegionForAddress(uint64_t(addr));
michael@0 84 if(!region)
michael@0 85 return false;
michael@0 86
michael@0 87 const uint8_t* chars = region->GetMemory();
michael@0 88 if (region->GetSize() != 32)
michael@0 89 return false;
michael@0 90
michael@0 91 for (int i=0; i<32; i++) {
michael@0 92 if (chars[i] != i)
michael@0 93 return false;
michael@0 94 }
michael@0 95
michael@0 96 return true;
michael@0 97 }

mercurial