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 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 #include <assert.h> | 39 #include <assert.h> |
40 | 40 |
41 #include "google_breakpad/processor/code_module.h" | 41 #include "google_breakpad/processor/code_module.h" |
42 #include "processor/linked_ptr.h" | 42 #include "processor/linked_ptr.h" |
43 #include "processor/logging.h" | 43 #include "processor/logging.h" |
44 #include "processor/range_map-inl.h" | 44 #include "processor/range_map-inl.h" |
45 | 45 |
46 namespace google_breakpad { | 46 namespace google_breakpad { |
47 | 47 |
48 BasicCodeModules::BasicCodeModules(const CodeModules *that) | 48 BasicCodeModules::BasicCodeModules(const CodeModules *that) : main_address_(0) { |
Mark Mentovai
2016/06/02 21:43:53
Explicitly initialize map_ even if it’s just to _(
ivanpe
2016/06/02 22:54:02
Done.
| |
49 : main_address_(0), | |
50 map_(new RangeMap<uint64_t, linked_ptr<const CodeModule> >()) { | |
51 BPLOG_IF(ERROR, !that) << "BasicCodeModules::BasicCodeModules requires " | 49 BPLOG_IF(ERROR, !that) << "BasicCodeModules::BasicCodeModules requires " |
52 "|that|"; | 50 "|that|"; |
53 assert(that); | 51 assert(that); |
54 | 52 |
55 const CodeModule *main_module = that->GetMainModule(); | 53 const CodeModule *main_module = that->GetMainModule(); |
56 if (main_module) | 54 if (main_module) |
57 main_address_ = main_module->base_address(); | 55 main_address_ = main_module->base_address(); |
58 | 56 |
59 unsigned int count = that->module_count(); | 57 unsigned int count = that->module_count(); |
60 for (unsigned int module_sequence = 0; | 58 for (unsigned int module_sequence = 0; |
61 module_sequence < count; | 59 module_sequence < count; |
62 ++module_sequence) { | 60 ++module_sequence) { |
63 // Make a copy of the module and insert it into the map. Use | 61 // Make a copy of the module and insert it into the map. Use |
64 // GetModuleAtIndex because ordering is unimportant when slurping the | 62 // GetModuleAtIndex because ordering is unimportant when slurping the |
65 // entire list, and GetModuleAtIndex may be faster than | 63 // entire list, and GetModuleAtIndex may be faster than |
66 // GetModuleAtSequence. | 64 // GetModuleAtSequence. |
67 linked_ptr<const CodeModule> module( | 65 linked_ptr<const CodeModule> module( |
68 that->GetModuleAtIndex(module_sequence)->Copy()); | 66 that->GetModuleAtIndex(module_sequence)->Copy()); |
69 if (!map_->StoreRange(module->base_address(), module->size(), module)) { | 67 if (!map_.StoreRange(module->base_address(), 0 /* delta */, module->size(), |
68 module)) { | |
70 BPLOG(ERROR) << "Module " << module->code_file() << | 69 BPLOG(ERROR) << "Module " << module->code_file() << |
71 " could not be stored"; | 70 " could not be stored"; |
72 } | 71 } |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 BasicCodeModules::BasicCodeModules() | 75 BasicCodeModules::BasicCodeModules() : main_address_(0) { } |
77 : main_address_(0), | |
78 map_(new RangeMap<uint64_t, linked_ptr<const CodeModule> >()) { | |
79 } | |
80 | 76 |
81 BasicCodeModules::~BasicCodeModules() { | 77 BasicCodeModules::~BasicCodeModules() { |
82 delete map_; | |
83 } | 78 } |
84 | 79 |
85 unsigned int BasicCodeModules::module_count() const { | 80 unsigned int BasicCodeModules::module_count() const { |
86 return map_->GetCount(); | 81 return map_.GetCount(); |
87 } | 82 } |
88 | 83 |
89 const CodeModule* BasicCodeModules::GetModuleForAddress( | 84 const CodeModule* BasicCodeModules::GetModuleForAddress( |
90 uint64_t address) const { | 85 uint64_t address) const { |
91 linked_ptr<const CodeModule> module; | 86 linked_ptr<const CodeModule> module; |
92 if (!map_->RetrieveRange(address, &module, NULL, NULL)) { | 87 if (!map_.RetrieveRange(address, &module, NULL, NULL, NULL)) { |
93 BPLOG(INFO) << "No module at " << HexString(address); | 88 BPLOG(INFO) << "No module at " << HexString(address); |
94 return NULL; | 89 return NULL; |
95 } | 90 } |
96 | 91 |
97 return module.get(); | 92 return module.get(); |
98 } | 93 } |
99 | 94 |
100 const CodeModule* BasicCodeModules::GetMainModule() const { | 95 const CodeModule* BasicCodeModules::GetMainModule() const { |
101 return GetModuleForAddress(main_address_); | 96 return GetModuleForAddress(main_address_); |
102 } | 97 } |
103 | 98 |
104 const CodeModule* BasicCodeModules::GetModuleAtSequence( | 99 const CodeModule* BasicCodeModules::GetModuleAtSequence( |
105 unsigned int sequence) const { | 100 unsigned int sequence) const { |
106 linked_ptr<const CodeModule> module; | 101 linked_ptr<const CodeModule> module; |
107 if (!map_->RetrieveRangeAtIndex(sequence, &module, NULL, NULL)) { | 102 if (!map_.RetrieveRangeAtIndex(sequence, &module, NULL, NULL, NULL)) { |
108 BPLOG(ERROR) << "RetrieveRangeAtIndex failed for sequence " << sequence; | 103 BPLOG(ERROR) << "RetrieveRangeAtIndex failed for sequence " << sequence; |
109 return NULL; | 104 return NULL; |
110 } | 105 } |
111 | 106 |
112 return module.get(); | 107 return module.get(); |
113 } | 108 } |
114 | 109 |
115 const CodeModule* BasicCodeModules::GetModuleAtIndex( | 110 const CodeModule* BasicCodeModules::GetModuleAtIndex( |
116 unsigned int index) const { | 111 unsigned int index) const { |
117 // This class stores everything in a RangeMap, without any more-efficient | 112 // This class stores everything in a RangeMap, without any more-efficient |
118 // way to walk the list of CodeModule objects. Implement GetModuleAtIndex | 113 // way to walk the list of CodeModule objects. Implement GetModuleAtIndex |
119 // using GetModuleAtSequence, which meets all of the requirements, and | 114 // using GetModuleAtSequence, which meets all of the requirements, and |
120 // in addition, guarantees ordering. | 115 // in addition, guarantees ordering. |
121 return GetModuleAtSequence(index); | 116 return GetModuleAtSequence(index); |
122 } | 117 } |
123 | 118 |
124 const CodeModules* BasicCodeModules::Copy() const { | 119 const CodeModules* BasicCodeModules::Copy() const { |
125 return new BasicCodeModules(this); | 120 return new BasicCodeModules(this); |
126 } | 121 } |
127 | 122 |
128 } // namespace google_breakpad | 123 } // namespace google_breakpad |
OLD | NEW |