1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/basic_code_modules.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 1.4 +// Copyright (c) 2006, Google Inc. 1.5 +// All rights reserved. 1.6 +// 1.7 +// Redistribution and use in source and binary forms, with or without 1.8 +// modification, are permitted provided that the following conditions are 1.9 +// met: 1.10 +// 1.11 +// * Redistributions of source code must retain the above copyright 1.12 +// notice, this list of conditions and the following disclaimer. 1.13 +// * Redistributions in binary form must reproduce the above 1.14 +// copyright notice, this list of conditions and the following disclaimer 1.15 +// in the documentation and/or other materials provided with the 1.16 +// distribution. 1.17 +// * Neither the name of Google Inc. nor the names of its 1.18 +// contributors may be used to endorse or promote products derived from 1.19 +// this software without specific prior written permission. 1.20 +// 1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 + 1.33 +// basic_code_modules.cc: Contains all of the CodeModule objects that 1.34 +// were loaded into a single process. 1.35 +// 1.36 +// See basic_code_modules.h for documentation. 1.37 +// 1.38 +// Author: Mark Mentovai 1.39 + 1.40 +#include "processor/basic_code_modules.h" 1.41 + 1.42 +#include <assert.h> 1.43 + 1.44 +#include "google_breakpad/processor/code_module.h" 1.45 +#include "processor/linked_ptr.h" 1.46 +#include "common/logging.h" 1.47 +#include "processor/range_map-inl.h" 1.48 + 1.49 +namespace google_breakpad { 1.50 + 1.51 +BasicCodeModules::BasicCodeModules(const CodeModules *that) 1.52 + : main_address_(0), 1.53 + map_(new RangeMap<uint64_t, linked_ptr<const CodeModule> >()) { 1.54 + BPLOG_IF(ERROR, !that) << "BasicCodeModules::BasicCodeModules requires " 1.55 + "|that|"; 1.56 + assert(that); 1.57 + 1.58 + const CodeModule *main_module = that->GetMainModule(); 1.59 + if (main_module) 1.60 + main_address_ = main_module->base_address(); 1.61 + 1.62 + unsigned int count = that->module_count(); 1.63 + for (unsigned int module_sequence = 0; 1.64 + module_sequence < count; 1.65 + ++module_sequence) { 1.66 + // Make a copy of the module and insert it into the map. Use 1.67 + // GetModuleAtIndex because ordering is unimportant when slurping the 1.68 + // entire list, and GetModuleAtIndex may be faster than 1.69 + // GetModuleAtSequence. 1.70 + const CodeModule *module = that->GetModuleAtIndex(module_sequence)->Copy(); 1.71 + if (!map_->StoreRange(module->base_address(), module->size(), 1.72 + linked_ptr<const CodeModule>(module))) { 1.73 + BPLOG(ERROR) << "Module " << module->code_file() << 1.74 + " could not be stored"; 1.75 + } 1.76 + } 1.77 +} 1.78 + 1.79 +BasicCodeModules::~BasicCodeModules() { 1.80 + delete map_; 1.81 +} 1.82 + 1.83 +unsigned int BasicCodeModules::module_count() const { 1.84 + return map_->GetCount(); 1.85 +} 1.86 + 1.87 +const CodeModule* BasicCodeModules::GetModuleForAddress( 1.88 + uint64_t address) const { 1.89 + linked_ptr<const CodeModule> module; 1.90 + if (!map_->RetrieveRange(address, &module, NULL, NULL)) { 1.91 + BPLOG(INFO) << "No module at " << HexString(address); 1.92 + return NULL; 1.93 + } 1.94 + 1.95 + return module.get(); 1.96 +} 1.97 + 1.98 +const CodeModule* BasicCodeModules::GetMainModule() const { 1.99 + return GetModuleForAddress(main_address_); 1.100 +} 1.101 + 1.102 +const CodeModule* BasicCodeModules::GetModuleAtSequence( 1.103 + unsigned int sequence) const { 1.104 + linked_ptr<const CodeModule> module; 1.105 + if (!map_->RetrieveRangeAtIndex(sequence, &module, NULL, NULL)) { 1.106 + BPLOG(ERROR) << "RetrieveRangeAtIndex failed for sequence " << sequence; 1.107 + return NULL; 1.108 + } 1.109 + 1.110 + return module.get(); 1.111 +} 1.112 + 1.113 +const CodeModule* BasicCodeModules::GetModuleAtIndex( 1.114 + unsigned int index) const { 1.115 + // This class stores everything in a RangeMap, without any more-efficient 1.116 + // way to walk the list of CodeModule objects. Implement GetModuleAtIndex 1.117 + // using GetModuleAtSequence, which meets all of the requirements, and 1.118 + // in addition, guarantees ordering. 1.119 + return GetModuleAtSequence(index); 1.120 +} 1.121 + 1.122 +const CodeModules* BasicCodeModules::Copy() const { 1.123 + return new BasicCodeModules(this); 1.124 +} 1.125 + 1.126 +} // namespace google_breakpad