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