1// Copyright (c) 2006, 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// basic_code_modules.h: Contains all of the CodeModule objects that
31// were loaded into a single process.
32//
33// This is a basic concrete implementation of CodeModules. It cannot be
34// instantiated directly, only based on other objects that implement
35// the CodeModules interface. It exists to provide a CodeModules
36// implementation a place to store information when the life of the original
37// object (such as a MinidumpModuleList) cannot be guaranteed.
38//
39// Author: Mark Mentovai
40
41#ifndef PROCESSOR_BASIC_CODE_MODULES_H__
42#define PROCESSOR_BASIC_CODE_MODULES_H__
43
44#include <stddef.h>
45
46#include <vector>
47
48#include "google_breakpad/processor/code_modules.h"
49#include "processor/linked_ptr.h"
50#include "processor/range_map.h"
51
52namespace google_breakpad {
53
54class BasicCodeModules : public CodeModules {
55 public:
56 // Creates a new BasicCodeModules object given any existing CodeModules
57 // implementation. This is useful to make a copy of the data relevant to
58 // the CodeModules and CodeModule interfaces without requiring all of the
59 // resources that other implementations may require. A copy will be
60 // made of each contained CodeModule using CodeModule::Copy.
61 BasicCodeModules(const CodeModules *that, MergeRangeStrategy strategy);
62
63 virtual ~BasicCodeModules();
64
65 // See code_modules.h for descriptions of these methods.
66 virtual unsigned int module_count() const;
67 virtual const CodeModule* GetModuleForAddress(uint64_t address) const;
68 virtual const CodeModule* GetMainModule() const;
69 virtual const CodeModule* GetModuleAtSequence(unsigned int sequence) const;
70 virtual const CodeModule* GetModuleAtIndex(unsigned int index) const;
71 virtual const CodeModules* Copy() const;
72 virtual std::vector<linked_ptr<const CodeModule> >
73 GetShrunkRangeModules() const;
74
75 protected:
76 BasicCodeModules();
77
78 // The base address of the main module.
79 uint64_t main_address_;
80
81 // The map used to contain each CodeModule, keyed by each CodeModule's
82 // address range.
83 RangeMap<uint64_t, linked_ptr<const CodeModule> > map_;
84
85 // A vector of all CodeModules that were shrunk downs due to
86 // address range conflicts.
87 std::vector<linked_ptr<const CodeModule> > shrunk_range_modules_;
88
89 private:
90 // Disallow copy constructor and assignment operator.
91 BasicCodeModules(const BasicCodeModules& that);
92 void operator=(const BasicCodeModules& that);
93};
94
95} // namespace google_breakpad
96
97#endif // PROCESSOR_BASIC_CODE_MODULES_H__
98