1 // Copyright 2014 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 // dump_context.h: A (mini/micro) dump CPU-specific context. 30 31 #ifndef GOOGLE_BREAKPAD_PROCESSOR_DUMP_CONTEXT_H__ 32 #define GOOGLE_BREAKPAD_PROCESSOR_DUMP_CONTEXT_H__ 33 34 #include "google_breakpad/common/minidump_format.h" 35 #include "google_breakpad/processor/dump_object.h" 36 37 namespace google_breakpad { 38 39 // DumpContext carries a CPU-specific MDRawContext structure, which contains CPU 40 // context such as register states. 41 class DumpContext : public DumpObject { 42 public: 43 virtual ~DumpContext(); 44 45 // Returns an MD_CONTEXT_* value such as MD_CONTEXT_X86 or MD_CONTEXT_PPC 46 // identifying the CPU type that the context was collected from. The 47 // returned value will identify the CPU only, and will have any other 48 // MD_CONTEXT_* bits masked out. Returns 0 on failure. 49 uint32_t GetContextCPU() const; 50 51 // Return the raw value of |context_flags_| 52 uint32_t GetContextFlags() const; 53 54 // Returns raw CPU-specific context data for the named CPU type. If the 55 // context data does not match the CPU type or does not exist, returns NULL. 56 const MDRawContextAMD64* GetContextAMD64() const; 57 const MDRawContextARM* GetContextARM() const; 58 const MDRawContextARM64* GetContextARM64() const; 59 const MDRawContextMIPS* GetContextMIPS() const; 60 const MDRawContextPPC* GetContextPPC() const; 61 const MDRawContextPPC64* GetContextPPC64() const; 62 const MDRawContextSPARC* GetContextSPARC() const; 63 const MDRawContextX86* GetContextX86() const; 64 const MDRawContextRISCV* GetContextRISCV() const; 65 const MDRawContextRISCV64* GetContextRISCV64() const; 66 67 // A convenience method to get the instruction pointer out of the 68 // MDRawContext, since it varies per-CPU architecture. 69 bool GetInstructionPointer(uint64_t* ip) const; 70 71 // Similar to the GetInstructionPointer method, this method gets the stack 72 // pointer for all CPU architectures. 73 bool GetStackPointer(uint64_t* sp) const; 74 75 // Print a human-readable representation of the object to stdout. 76 void Print(); 77 78 protected: 79 DumpContext(); 80 81 // Sets row CPU-specific context data for the names CPU type. 82 void SetContextFlags(uint32_t context_flags); 83 void SetContextX86(MDRawContextX86* x86); 84 void SetContextPPC(MDRawContextPPC* ppc); 85 void SetContextPPC64(MDRawContextPPC64* ppc64); 86 void SetContextAMD64(MDRawContextAMD64* amd64); 87 void SetContextSPARC(MDRawContextSPARC* ctx_sparc); 88 void SetContextARM(MDRawContextARM* arm); 89 void SetContextARM64(MDRawContextARM64* arm64); 90 void SetContextMIPS(MDRawContextMIPS* ctx_mips); 91 void SetContextRISCV(MDRawContextRISCV* riscv); 92 void SetContextRISCV64(MDRawContextRISCV64* riscv64); 93 94 // Free the CPU-specific context structure. 95 void FreeContext(); 96 97 private: 98 // The CPU-specific context structure. 99 union { 100 MDRawContextBase* base; 101 MDRawContextX86* x86; 102 MDRawContextPPC* ppc; 103 MDRawContextPPC64* ppc64; 104 MDRawContextAMD64* amd64; 105 // on Solaris SPARC, sparc is defined as a numeric constant, 106 // so variables can NOT be named as sparc 107 MDRawContextSPARC* ctx_sparc; 108 MDRawContextARM* arm; 109 MDRawContextARM64* arm64; 110 MDRawContextMIPS* ctx_mips; 111 MDRawContextRISCV* riscv; 112 MDRawContextRISCV64* riscv64; 113 } context_; 114 115 // Store this separately because of the weirdo AMD64 context 116 uint32_t context_flags_; 117 }; 118 119 } // namespace google_breakpad 120 121 #endif // GOOGLE_BREAKPAD_PROCESSOR_DUMP_CONTEXT_H__ 122