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

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

mercurial