LEFT | RIGHT |
1 // Copyright (c) 2014 Google Inc. | 1 // Copyright (c) 2014 Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // microdump.h: A microdump reader. Microdump is a minified variant of a | 30 // microdump.h: A microdump reader. Microdump is a minified variant of a |
31 // minidump (see minidump.h for documentation) which contains the minimum | 31 // minidump (see minidump.h for documentation) which contains the minimum |
32 // amount of information required to get a stack trace for the crashing thread. | 32 // amount of information required to get a stack trace for the crashing thread. |
33 // The information contained in a microdump is: | 33 // The information contained in a microdump is: |
34 // - the crashing thread stack | 34 // - the crashing thread stack |
| 35 // - system information (os type / version) |
35 // - cpu context (state of the registers) | 36 // - cpu context (state of the registers) |
36 // - list of mmaps | 37 // - list of mmaps |
37 | 38 |
38 #ifndef GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__ | 39 #ifndef GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__ |
39 #define GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__ | 40 #define GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__ |
40 | 41 |
41 #include <string> | 42 #include <string> |
42 #include <vector> | 43 #include <vector> |
43 | 44 |
44 #include "common/scoped_ptr.h" | 45 #include "common/scoped_ptr.h" |
45 #include "common/using_std_string.h" | 46 #include "common/using_std_string.h" |
46 #include "google_breakpad/processor/code_modules.h" | |
47 #include "google_breakpad/processor/dump_context.h" | 47 #include "google_breakpad/processor/dump_context.h" |
48 #include "google_breakpad/processor/memory_region.h" | 48 #include "google_breakpad/processor/memory_region.h" |
| 49 #include "processor/basic_code_modules.h" |
49 | 50 |
50 namespace google_breakpad { | 51 namespace google_breakpad { |
51 | 52 |
52 // MicrodumpModuleList contains all of the loaded code modules for a process | 53 // MicrodumpModuleList contains all of the loaded code modules for a process |
53 // in the form of MicrodumpModules. It maintains a vector of these modules | 54 // in the form of MicrodumpModules. It maintains a vector of these modules |
54 // and provides access to a code module corresponding to a specific address. | 55 // and provides access to a code module corresponding to a specific address. |
55 class MicrodumpModuleList: public CodeModules { | 56 class MicrodumpModules : public BasicCodeModules { |
56 public: | 57 public: |
| 58 // Takes over ownership of |module|. |
57 void Add(const CodeModule* module); | 59 void Add(const CodeModule* module); |
58 | |
59 virtual unsigned int module_count() const; | |
60 | |
61 virtual const CodeModule *GetModuleForAddress(uint64_t address) const; | |
62 | |
63 virtual const CodeModule *GetMainModule() const; | |
64 | |
65 virtual const CodeModule *GetModuleAtSequence(unsigned int sequence) const; | |
66 | |
67 virtual const CodeModule *GetModuleAtIndex(unsigned int index) const; | |
68 | |
69 virtual const CodeModules *Copy() const; | |
70 private: | |
71 typedef std::vector<const CodeModule*> MicrodumpModules; | |
72 MicrodumpModules modules_; | |
73 }; | 60 }; |
74 | 61 |
75 // MicrodumpContext carries a CPU-specific context. | 62 // MicrodumpContext carries a CPU-specific context. |
76 // See dump_context.h for documentation. | 63 // See dump_context.h for documentation. |
77 class MicrodumpContext : public DumpContext { | 64 class MicrodumpContext : public DumpContext { |
78 public: | 65 public: |
79 MicrodumpContext(); | 66 virtual void SetContextARM(MDRawContextARM* arm); |
80 | |
81 virtual ~MicrodumpContext(); | |
82 | |
83 // TODO(mmandlis): currently microdump is only implemented to support ARM. | |
84 // Provide generic initialization once the format is finalized. | |
85 void SetContextARM(MDRawContextARM* arm_context); | |
86 }; | 67 }; |
87 | 68 |
88 // This class provides access to microdump memory regions. | 69 // This class provides access to microdump memory regions. |
89 // See memory_region.h for documentation. | 70 // See memory_region.h for documentation. |
90 class MicrodumpMemoryRegion : public MemoryRegion { | 71 class MicrodumpMemoryRegion : public MemoryRegion { |
91 public: | 72 public: |
92 MicrodumpMemoryRegion(); | 73 MicrodumpMemoryRegion(); |
| 74 virtual ~MicrodumpMemoryRegion() {} |
93 | 75 |
94 // Set this region's address and contents. If we have placed an | 76 // Set this region's address and contents. If we have placed an |
95 // instance of this class in a test fixture class, individual tests | 77 // instance of this class in a test fixture class, individual tests |
96 // can use this to provide the region's contents. | 78 // can use this to provide the region's contents. |
97 void Init(uint64_t base_address, const string &contents); | 79 void Init(uint64_t base_address, const std::vector<uint8_t>& contents); |
98 | 80 |
99 uint64_t GetBase() const; | 81 virtual uint64_t GetBase() const; |
100 uint32_t GetSize() const; | 82 virtual uint32_t GetSize() const; |
101 | 83 |
102 bool GetMemoryAtAddress(uint64_t address, uint8_t *value) const; | 84 virtual bool GetMemoryAtAddress(uint64_t address, uint8_t* value) const; |
103 bool GetMemoryAtAddress(uint64_t address, uint16_t *value) const; | 85 virtual bool GetMemoryAtAddress(uint64_t address, uint16_t* value) const; |
104 bool GetMemoryAtAddress(uint64_t address, uint32_t *value) const; | 86 virtual bool GetMemoryAtAddress(uint64_t address, uint32_t* value) const; |
105 bool GetMemoryAtAddress(uint64_t address, uint64_t *value) const; | 87 virtual bool GetMemoryAtAddress(uint64_t address, uint64_t* value) const; |
106 | 88 |
107 // Print a human-readable representation of the object to stdout. | 89 // Print a human-readable representation of the object to stdout. |
108 void Print() const; | 90 virtual void Print() const; |
| 91 |
109 private: | 92 private: |
110 // Fetch a little-endian value from ADDRESS in contents_ whose size | 93 // Fetch a little-endian value from ADDRESS in contents_ whose size |
111 // is BYTES, and store it in *VALUE. Return true on success. | 94 // is BYTES, and store it in *VALUE. Returns true on success. |
112 template<typename ValueType> | 95 template<typename ValueType> |
113 bool GetMemoryLittleEndian(uint64_t address, ValueType *value) const; | 96 bool GetMemoryLittleEndian(uint64_t address, ValueType* value) const; |
114 | 97 |
115 uint64_t base_address_; | 98 uint64_t base_address_; |
116 string contents_; | 99 std::vector<uint8_t> contents_; |
117 }; | 100 }; |
118 | 101 |
119 // Microdump is the user's interface to a microdump file. It provides access to | 102 // Microdump is the user's interface to a microdump file. It provides access to |
120 // the microdump's context, memory regions and modules. | 103 // the microdump's context, memory regions and modules. |
121 class Microdump { | 104 class Microdump { |
122 public: | 105 public: |
123 static const char kStackKey[]; | |
124 static const char kCpuKey[]; | |
125 static const char kMmapKey[]; | |
126 | |
127 explicit Microdump(const string& contents); | 106 explicit Microdump(const string& contents); |
128 virtual ~Microdump() {} | 107 virtual ~Microdump() {} |
129 virtual DumpContext* GetContext() { return context_.get(); } | 108 |
130 virtual MicrodumpMemoryRegion* GetMemory() { return stack_region_.get(); } | 109 DumpContext* GetContext() { return context_.get(); } |
131 virtual MicrodumpModuleList* GetModuleList() { return modules_.get(); } | 110 MicrodumpMemoryRegion* GetMemory() { return stack_region_.get(); } |
| 111 MicrodumpModules* GetModules() { return modules_.get(); } |
132 | 112 |
133 private: | 113 private: |
134 scoped_ptr<MicrodumpContext> context_; | 114 scoped_ptr<MicrodumpContext> context_; |
135 scoped_ptr<MicrodumpMemoryRegion> stack_region_; | 115 scoped_ptr<MicrodumpMemoryRegion> stack_region_; |
136 scoped_ptr<MicrodumpModuleList> modules_; | 116 scoped_ptr<MicrodumpModules> modules_; |
137 }; | 117 }; |
138 | 118 |
139 } // namespace google_breakpad | 119 } // namespace google_breakpad |
140 | 120 |
141 #endif // GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__ | 121 #endif // GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__ |
142 | 122 |
LEFT | RIGHT |