OLD | NEW |
---|---|
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 | 46 |
47 namespace google_breakpad { | 47 namespace google_breakpad { |
48 | 48 |
49 // Forward declarations (for later friend declarations of specialized template). | 49 // Forward declarations (for later friend declarations of specialized template). |
50 template<class, class> class RangeMapSerializer; | 50 template<class, class> class RangeMapSerializer; |
51 | 51 |
52 template<typename AddressType, typename EntryType> | 52 template<typename AddressType, typename EntryType> |
53 class RangeMap { | 53 class RangeMap { |
54 public: | 54 public: |
55 RangeMap() : map_() {} | 55 RangeMap() : enable_shrink_down_(false), map_() {} |
56 | |
57 // |enable_shrink_down| tells whether overlapping ranges can be shrunk down. | |
58 // If true, then adding a new range that overlaps with an existing one can | |
59 // be a successful operation. The range which ends at the higher address | |
60 // will be shrunk down by moving its start position to a higher address so | |
61 // that it does not overlap anymore. | |
62 void SetEnableShrinkDown(bool enable_shrink_down); | |
56 | 63 |
57 // Inserts a range into the map. Returns false for a parameter error, | 64 // Inserts a range into the map. Returns false for a parameter error, |
58 // or if the location of the range would conflict with a range already | 65 // or if the location of the range would conflict with a range already |
59 // stored in the map. | 66 // stored in the map. If enable_shrink_down is true and there is an overlap |
60 bool StoreRange(const AddressType &base, | 67 // between the current range and some other range (already in the map), |
61 const AddressType &size, | 68 // shrink down the range which ends at a hugher address. |
62 const EntryType &entry); | 69 bool StoreRange(const AddressType &base, const AddressType &delta, |
Mark Mentovai
2016/06/02 21:43:53
Is anything ever stored with a delta other than 0,
ivanpe
2016/06/02 22:54:02
Yes, I agree that moving the delta to a private me
| |
70 const AddressType &size, const EntryType &entry); | |
63 | 71 |
64 // Locates the range encompassing the supplied address. If there is | 72 // Locates the range encompassing the supplied address. If there is no such |
65 // no such range, returns false. entry_base and entry_size, if non-NULL, | 73 // range, returns false. entry_base, entry_delta, and entry_size, if |
66 // are set to the base and size of the entry's range. | 74 // non-NULL, are set to the base, delta, and size of the entry's range. |
67 bool RetrieveRange(const AddressType &address, EntryType *entry, | 75 bool RetrieveRange(const AddressType &address, EntryType *entry, |
68 AddressType *entry_base, AddressType *entry_size) const; | 76 AddressType *entry_base, AddressType *entry_delta, |
77 AddressType *entry_size) const; | |
69 | 78 |
70 // Locates the range encompassing the supplied address, if one exists. | 79 // Locates the range encompassing the supplied address, if one exists. |
71 // If no range encompasses the supplied address, locates the nearest range | 80 // If no range encompasses the supplied address, locates the nearest range |
72 // to the supplied address that is lower than the address. Returns false | 81 // to the supplied address that is lower than the address. Returns false |
73 // if no range meets these criteria. entry_base and entry_size, if | 82 // if no range meets these criteria. entry_base, entry_delta, and entry_size, |
74 // non-NULL, are set to the base and size of the entry's range. | 83 // if non-NULL, are set to the base, delta, and size of the entry's range. |
75 bool RetrieveNearestRange(const AddressType &address, EntryType *entry, | 84 bool RetrieveNearestRange(const AddressType &address, EntryType *entry, |
76 AddressType *entry_base, AddressType *entry_size) | 85 AddressType *entry_base, AddressType *entry_delta, |
77 const; | 86 AddressType *entry_size) const; |
78 | 87 |
79 // Treating all ranges as a list ordered by the address spaces that they | 88 // Treating all ranges as a list ordered by the address spaces that they |
80 // occupy, locates the range at the index specified by index. Returns | 89 // occupy, locates the range at the index specified by index. Returns |
81 // false if index is larger than the number of ranges stored. entry_base | 90 // false if index is larger than the number of ranges stored. entry_base, |
82 // and entry_size, if non-NULL, are set to the base and size of the entry's | 91 // entry_delta, and entry_size, if non-NULL, are set to the base, delta, and |
83 // range. | 92 // size of the entry's range. |
84 // | 93 // |
85 // RetrieveRangeAtIndex is not optimized for speedy operation. | 94 // RetrieveRangeAtIndex is not optimized for speedy operation. |
86 bool RetrieveRangeAtIndex(int index, EntryType *entry, | 95 bool RetrieveRangeAtIndex(int index, EntryType *entry, |
87 AddressType *entry_base, AddressType *entry_size) | 96 AddressType *entry_base, AddressType *entry_delta, |
88 const; | 97 AddressType *entry_size) const; |
89 | 98 |
90 // Returns the number of ranges stored in the RangeMap. | 99 // Returns the number of ranges stored in the RangeMap. |
91 int GetCount() const; | 100 int GetCount() const; |
92 | 101 |
93 // Empties the range map, restoring it to the state it was when it was | 102 // Empties the range map, restoring it to the state it was when it was |
94 // initially created. | 103 // initially created. |
95 void Clear(); | 104 void Clear(); |
96 | 105 |
97 private: | 106 private: |
98 // Friend declarations. | 107 // Friend declarations. |
99 friend class ModuleComparer; | 108 friend class ModuleComparer; |
100 friend class RangeMapSerializer<AddressType, EntryType>; | 109 friend class RangeMapSerializer<AddressType, EntryType>; |
101 | 110 |
102 class Range { | 111 class Range { |
103 public: | 112 public: |
104 Range(const AddressType &base, const EntryType &entry) | 113 Range(const AddressType &base, const AddressType &delta, |
105 : base_(base), entry_(entry) {} | 114 const EntryType &entry) |
115 : base_(base), delta_(delta), entry_(entry) {} | |
106 | 116 |
107 AddressType base() const { return base_; } | 117 AddressType base() const { return base_; } |
118 AddressType delta() const { return delta_; } | |
108 EntryType entry() const { return entry_; } | 119 EntryType entry() const { return entry_; } |
109 | 120 |
110 private: | 121 private: |
111 // The base address of the range. The high address does not need to | 122 // The base address of the range. The high address does not need to |
112 // be stored, because RangeMap uses it as the key to the map. | 123 // be stored, because RangeMap uses it as the key to the map. |
113 const AddressType base_; | 124 const AddressType base_; |
114 | 125 |
126 // The delta when the range is shrunk down. | |
127 const AddressType delta_; | |
128 | |
115 // The entry corresponding to a range. | 129 // The entry corresponding to a range. |
116 const EntryType entry_; | 130 const EntryType entry_; |
117 }; | 131 }; |
118 | 132 |
119 // Convenience types. | 133 // Convenience types. |
120 typedef std::map<AddressType, Range> AddressToRangeMap; | 134 typedef std::map<AddressType, Range> AddressToRangeMap; |
121 typedef typename AddressToRangeMap::const_iterator MapConstIterator; | 135 typedef typename AddressToRangeMap::const_iterator MapConstIterator; |
122 typedef typename AddressToRangeMap::value_type MapValue; | 136 typedef typename AddressToRangeMap::value_type MapValue; |
123 | 137 |
138 // Whether overlapping ranges can be shrunk down. If true, then adding | |
Mark Mentovai
2016/06/02 21:43:53
Don’t duplicate the comment from the setter. Eithe
ivanpe
2016/06/02 22:54:02
Done.
| |
139 // a new range that overlaps with an existing one can be a successful | |
140 // operation. The range which ends at the higher address will be shrunk | |
141 // down by moving its start position to a higher address so that it does not | |
142 // overlap anymore. | |
143 bool enable_shrink_down_; | |
144 | |
124 // Maps the high address of each range to a EntryType. | 145 // Maps the high address of each range to a EntryType. |
125 AddressToRangeMap map_; | 146 AddressToRangeMap map_; |
126 }; | 147 }; |
127 | 148 |
128 | 149 |
129 } // namespace google_breakpad | 150 } // namespace google_breakpad |
130 | 151 |
131 | 152 |
132 #endif // PROCESSOR_RANGE_MAP_H__ | 153 #endif // PROCESSOR_RANGE_MAP_H__ |
154 | |
Mark Mentovai
2016/06/02 21:43:53
Lose the blank line here, and actually at the end
ivanpe
2016/06/02 22:54:02
Done.
| |
OLD | NEW |