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 20 matching lines...) Expand all Loading... |
31 // were loaded into a single process. | 31 // were loaded into a single process. |
32 // | 32 // |
33 // See basic_code_modules.h for documentation. | 33 // See basic_code_modules.h for documentation. |
34 // | 34 // |
35 // Author: Mark Mentovai | 35 // Author: Mark Mentovai |
36 | 36 |
37 #include "processor/basic_code_modules.h" | 37 #include "processor/basic_code_modules.h" |
38 | 38 |
39 #include <assert.h> | 39 #include <assert.h> |
40 | 40 |
| 41 #include <vector> |
| 42 |
41 #include "google_breakpad/processor/code_module.h" | 43 #include "google_breakpad/processor/code_module.h" |
42 #include "processor/linked_ptr.h" | 44 #include "processor/linked_ptr.h" |
43 #include "processor/logging.h" | 45 #include "processor/logging.h" |
44 #include "processor/range_map-inl.h" | 46 #include "processor/range_map-inl.h" |
45 | 47 |
46 namespace google_breakpad { | 48 namespace google_breakpad { |
47 | 49 |
| 50 using std::vector; |
| 51 |
48 BasicCodeModules::BasicCodeModules(const CodeModules *that) | 52 BasicCodeModules::BasicCodeModules(const CodeModules *that) |
49 : main_address_(0), map_() { | 53 : main_address_(0), map_() { |
50 BPLOG_IF(ERROR, !that) << "BasicCodeModules::BasicCodeModules requires " | 54 BPLOG_IF(ERROR, !that) << "BasicCodeModules::BasicCodeModules requires " |
51 "|that|"; | 55 "|that|"; |
52 assert(that); | 56 assert(that); |
53 | 57 |
| 58 map_.SetEnableShrinkDown(that->IsModuleShrinkEnabled()); |
| 59 |
54 const CodeModule *main_module = that->GetMainModule(); | 60 const CodeModule *main_module = that->GetMainModule(); |
55 if (main_module) | 61 if (main_module) |
56 main_address_ = main_module->base_address(); | 62 main_address_ = main_module->base_address(); |
57 | 63 |
58 unsigned int count = that->module_count(); | 64 unsigned int count = that->module_count(); |
59 for (unsigned int module_sequence = 0; | 65 for (unsigned int i = 0; i < count; ++i) { |
60 module_sequence < count; | |
61 ++module_sequence) { | |
62 // Make a copy of the module and insert it into the map. Use | 66 // Make a copy of the module and insert it into the map. Use |
63 // GetModuleAtIndex because ordering is unimportant when slurping the | 67 // GetModuleAtIndex because ordering is unimportant when slurping the |
64 // entire list, and GetModuleAtIndex may be faster than | 68 // entire list, and GetModuleAtIndex may be faster than |
65 // GetModuleAtSequence. | 69 // GetModuleAtSequence. |
66 linked_ptr<const CodeModule> module( | 70 linked_ptr<const CodeModule> module(that->GetModuleAtIndex(i)->Copy()); |
67 that->GetModuleAtIndex(module_sequence)->Copy()); | |
68 if (!map_.StoreRange(module->base_address(), module->size(), module)) { | 71 if (!map_.StoreRange(module->base_address(), module->size(), module)) { |
69 BPLOG(ERROR) << "Module " << module->code_file() << | 72 BPLOG(ERROR) << "Module " << module->code_file() |
70 " could not be stored"; | 73 << " could not be stored"; |
71 } | 74 } |
72 } | 75 } |
| 76 |
| 77 // Report modules with shrunk ranges. |
| 78 for (unsigned int i = 0; i < count; ++i) { |
| 79 linked_ptr<const CodeModule> module(that->GetModuleAtIndex(i)->Copy()); |
| 80 uint64_t delta = 0; |
| 81 if (map_.RetrieveRange(module->base_address() + module->size() - 1, |
| 82 &module, NULL /* base */, &delta, NULL /* size */) && |
| 83 delta > 0) { |
| 84 BPLOG(INFO) << "The range for module " << module->code_file() |
| 85 << " was shrunk down by " << HexString(delta) << " bytes."; |
| 86 linked_ptr<CodeModule> shrunk_range_module(module->Copy()); |
| 87 shrunk_range_module->SetShrinkDownDelta(delta); |
| 88 shrunk_range_modules_.push_back(shrunk_range_module); |
| 89 } |
| 90 } |
| 91 |
| 92 // TODO(ivanpe): Report modules with conflicting ranges. The list of such |
| 93 // modules should be copied from |that|. |
73 } | 94 } |
74 | 95 |
75 BasicCodeModules::BasicCodeModules() : main_address_(0), map_() { } | 96 BasicCodeModules::BasicCodeModules() : main_address_(0), map_() { } |
76 | 97 |
77 BasicCodeModules::~BasicCodeModules() { | 98 BasicCodeModules::~BasicCodeModules() { |
78 } | 99 } |
79 | 100 |
80 unsigned int BasicCodeModules::module_count() const { | 101 unsigned int BasicCodeModules::module_count() const { |
81 return map_.GetCount(); | 102 return map_.GetCount(); |
82 } | 103 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // way to walk the list of CodeModule objects. Implement GetModuleAtIndex | 136 // way to walk the list of CodeModule objects. Implement GetModuleAtIndex |
116 // using GetModuleAtSequence, which meets all of the requirements, and | 137 // using GetModuleAtSequence, which meets all of the requirements, and |
117 // in addition, guarantees ordering. | 138 // in addition, guarantees ordering. |
118 return GetModuleAtSequence(index); | 139 return GetModuleAtSequence(index); |
119 } | 140 } |
120 | 141 |
121 const CodeModules* BasicCodeModules::Copy() const { | 142 const CodeModules* BasicCodeModules::Copy() const { |
122 return new BasicCodeModules(this); | 143 return new BasicCodeModules(this); |
123 } | 144 } |
124 | 145 |
| 146 vector<linked_ptr<const CodeModule> > |
| 147 BasicCodeModules::GetShrunkRangeModules() const { |
| 148 return shrunk_range_modules_; |
| 149 } |
| 150 |
| 151 bool BasicCodeModules::IsModuleShrinkEnabled() const { |
| 152 return map_.IsShrinkDownEnabled(); |
| 153 } |
| 154 |
125 } // namespace google_breakpad | 155 } // namespace google_breakpad |
OLD | NEW |