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 // microdump.h: A microdump reader.  Microdump is a minified variant of a
     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.
     33 // The information contained in a microdump is:
     34 // - the crashing thread stack
     35 // - system information (os type / version)
     36 // - cpu context (state of the registers)
     37 // - list of mmaps
     38 
     39 #ifndef GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__
     40 #define GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__
     41 
     42 #include <string>
     43 #include <vector>
     44 
     45 #include "common/scoped_ptr.h"
     46 #include "common/using_std_string.h"
     47 #include "google_breakpad/processor/dump_context.h"
     48 #include "google_breakpad/processor/memory_region.h"
     49 #include "google_breakpad/processor/system_info.h"
     50 #include "processor/basic_code_modules.h"
     51 
     52 namespace google_breakpad {
     53 
     54 // MicrodumpModuleList contains all of the loaded code modules for a process
     55 // in the form of MicrodumpModules.  It maintains a vector of these modules
     56 // and provides access to a code module corresponding to a specific address.
     57 class MicrodumpModules : public BasicCodeModules {
     58  public:
     59   // Takes over ownership of |module|.
     60   void Add(const CodeModule* module);
     61 };
     62 
     63 // MicrodumpContext carries a CPU-specific context.
     64 // See dump_context.h for documentation.
     65 class MicrodumpContext : public DumpContext {
     66  public:
     67   virtual void SetContextARM(MDRawContextARM* arm);
     68   virtual void SetContextARM64(MDRawContextARM64* arm64);
     69 };
     70 
     71 // This class provides access to microdump memory regions.
     72 // See memory_region.h for documentation.
     73 class MicrodumpMemoryRegion : public MemoryRegion {
     74  public:
     75   MicrodumpMemoryRegion();
     76   virtual ~MicrodumpMemoryRegion() {}
     77 
     78   // Set this region's address and contents. If we have placed an
     79   // instance of this class in a test fixture class, individual tests
     80   // can use this to provide the region's contents.
     81   void Init(uint64_t base_address, const std::vector<uint8_t>& contents);
     82 
     83   virtual uint64_t GetBase() const;
     84   virtual uint32_t GetSize() const;
     85 
     86   virtual bool GetMemoryAtAddress(uint64_t address, uint8_t* value) const;
     87   virtual bool GetMemoryAtAddress(uint64_t address, uint16_t* value) const;
     88   virtual bool GetMemoryAtAddress(uint64_t address, uint32_t* value) const;
     89   virtual bool GetMemoryAtAddress(uint64_t address, uint64_t* value) const;
     90 
     91   // Print a human-readable representation of the object to stdout.
     92   virtual void Print() const;
     93 
     94  private:
     95   // Fetch a little-endian value from ADDRESS in contents_ whose size
     96   // is BYTES, and store it in *VALUE.  Returns true on success.
     97   template<typename ValueType>
     98   bool GetMemoryLittleEndian(uint64_t address, ValueType* value) const;
     99 
    100   uint64_t base_address_;
    101   std::vector<uint8_t> contents_;
    102 };
    103 
    104 // Microdump is the user's interface to a microdump file.  It provides access to
    105 // the microdump's context, memory regions and modules.
    106 class Microdump {
    107  public:
    108   explicit Microdump(const string& contents);
    109   virtual ~Microdump() {}
    110 
    111   DumpContext* GetContext() { return context_.get(); }
    112   MicrodumpMemoryRegion* GetMemory() { return stack_region_.get(); }
    113   MicrodumpModules* GetModules() { return modules_.get(); }
    114   SystemInfo* GetSystemInfo() { return system_info_.get(); }
    115 
    116  private:
    117   scoped_ptr<MicrodumpContext> context_;
    118   scoped_ptr<MicrodumpMemoryRegion> stack_region_;
    119   scoped_ptr<MicrodumpModules> modules_;
    120   scoped_ptr<SystemInfo> system_info_;
    121 };
    122 
    123 }  // namespace google_breakpad
    124 
    125 #endif  // GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__
    126 
    127