|
1 #include <stdio.h> |
|
2 |
|
3 #include "google_breakpad/processor/minidump.h" |
|
4 #include "nscore.h" |
|
5 |
|
6 using namespace google_breakpad; |
|
7 |
|
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; |
|
16 |
|
17 uint32_t length; |
|
18 if (!dump.SeekToStreamType(stream_type, &length) || length == 0) |
|
19 return false; |
|
20 |
|
21 return true; |
|
22 } |
|
23 |
|
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; |
|
33 |
|
34 MinidumpException* exception = minidump.GetException(); |
|
35 MinidumpMemoryList* memory_list = minidump.GetMemoryList(); |
|
36 if (!exception || !memory_list) { |
|
37 return false; |
|
38 } |
|
39 |
|
40 MinidumpContext* context = exception->GetContext(); |
|
41 if (!context) |
|
42 return false; |
|
43 |
|
44 uint64_t instruction_pointer; |
|
45 if (!context->GetInstructionPointer(&instruction_pointer)) { |
|
46 return false; |
|
47 } |
|
48 |
|
49 MinidumpMemoryRegion* region = |
|
50 memory_list->GetMemoryRegionForAddress(instruction_pointer); |
|
51 return region != nullptr; |
|
52 } |
|
53 |
|
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; |
|
66 |
|
67 MinidumpMemoryList* memory_list = dump.GetMemoryList(); |
|
68 if (!memory_list) { |
|
69 return false; |
|
70 } |
|
71 |
|
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); |
|
79 |
|
80 remove("crash-addr"); |
|
81 |
|
82 MinidumpMemoryRegion* region = |
|
83 memory_list->GetMemoryRegionForAddress(uint64_t(addr)); |
|
84 if(!region) |
|
85 return false; |
|
86 |
|
87 const uint8_t* chars = region->GetMemory(); |
|
88 if (region->GetSize() != 32) |
|
89 return false; |
|
90 |
|
91 for (int i=0; i<32; i++) { |
|
92 if (chars[i] != i) |
|
93 return false; |
|
94 } |
|
95 |
|
96 return true; |
|
97 } |