/ src / processor / basic_code_module.h
basic_code_module.h
  1  // Copyright 2006 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  // basic_code_module.h: Carries information about code modules that are loaded
 30  // into a process.
 31  //
 32  // This is a basic concrete implementation of CodeModule.  It cannot be
 33  // instantiated directly, only based on other objects that implement
 34  // the CodeModule interface.  It exists to provide a CodeModule implementation
 35  // a place to store information when the life of the original object (such as
 36  // a MinidumpModule) cannot be guaranteed.
 37  //
 38  // Author: Mark Mentovai
 39  
 40  #ifndef PROCESSOR_BASIC_CODE_MODULE_H__
 41  #define PROCESSOR_BASIC_CODE_MODULE_H__
 42  
 43  #include <string>
 44  
 45  #include "common/using_std_string.h"
 46  #include "google_breakpad/processor/code_module.h"
 47  
 48  namespace google_breakpad {
 49  
 50  class BasicCodeModule : public CodeModule {
 51   public:
 52    // Creates a new BasicCodeModule given any existing CodeModule
 53    // implementation.  This is useful to make a copy of the data relevant to
 54    // the CodeModule interface without requiring all of the resources that
 55    // other CodeModule implementations may require.
 56    explicit BasicCodeModule(const CodeModule *that)
 57        : base_address_(that->base_address()),
 58          size_(that->size()),
 59          shrink_down_delta_(that->shrink_down_delta()),
 60          code_file_(that->code_file()),
 61          code_identifier_(that->code_identifier()),
 62          debug_file_(that->debug_file()),
 63          debug_identifier_(that->debug_identifier()),
 64          version_(that->version()),
 65          is_unloaded_(that->is_unloaded()) {}
 66  
 67    BasicCodeModule(uint64_t base_address, uint64_t size,
 68                    const string& code_file,
 69                    const string& code_identifier,
 70                    const string& debug_file,
 71                    const string& debug_identifier,
 72                    const string& version,
 73                    const bool is_unloaded = false)
 74        : base_address_(base_address),
 75          size_(size),
 76          shrink_down_delta_(0),
 77          code_file_(code_file),
 78          code_identifier_(code_identifier),
 79          debug_file_(debug_file),
 80          debug_identifier_(debug_identifier),
 81          version_(version),
 82          is_unloaded_(is_unloaded)
 83      {}
 84    virtual ~BasicCodeModule() {}
 85  
 86    // See code_module.h for descriptions of these methods and the associated
 87    // members.
 88    virtual uint64_t base_address() const { return base_address_; }
 89    virtual uint64_t size() const { return size_; }
 90    virtual uint64_t shrink_down_delta() const { return shrink_down_delta_; }
 91    virtual void SetShrinkDownDelta(uint64_t shrink_down_delta) {
 92      shrink_down_delta_ = shrink_down_delta;
 93    }
 94    virtual string code_file() const { return code_file_; }
 95    virtual string code_identifier() const { return code_identifier_; }
 96    virtual string debug_file() const { return debug_file_; }
 97    virtual string debug_identifier() const { return debug_identifier_; }
 98    virtual string version() const { return version_; }
 99    virtual CodeModule* Copy() const { return new BasicCodeModule(this); }
100    virtual bool is_unloaded() const { return is_unloaded_; }
101  
102   private:
103    uint64_t base_address_;
104    uint64_t size_;
105    uint64_t shrink_down_delta_;
106    string code_file_;
107    string code_identifier_;
108    string debug_file_;
109    string debug_identifier_;
110    string version_;
111    bool is_unloaded_;
112  
113    // Disallow copy constructor and assignment operator.
114    BasicCodeModule(const BasicCodeModule& that);
115    void operator=(const BasicCodeModule& that);
116  };
117  
118  }  // namespace google_breakpad
119  
120  #endif  // PROCESSOR_BASIC_CODE_MODULE_H__