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