2022-09-07 16:34:05 +02:00
|
|
|
// Copyright 2006 Google LLC
|
2006-12-05 23:52:28 +01:00
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
|
// met:
|
|
|
|
|
//
|
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
|
// distribution.
|
2022-09-07 16:34:05 +02:00
|
|
|
// * Neither the name of Google LLC nor the names of its
|
2006-12-05 23:52:28 +01:00
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
// basic_code_modules.cc: Contains all of the CodeModule objects that
|
|
|
|
|
// were loaded into a single process.
|
|
|
|
|
//
|
|
|
|
|
// See basic_code_modules.h for documentation.
|
|
|
|
|
//
|
|
|
|
|
// Author: Mark Mentovai
|
|
|
|
|
|
Add #include <config.h> to the beginning of all cc files
Added
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
to the beginning of all source files that didn't have it.
This ensures that configuration options are respected in all source
files. In particular, it ensures that the defines needed to fix Large
File System issues are set before including system headers.
More generally, it ensures consistency between the source files, and
avoids the possibility of ODR violations between source files that were
including config.h and source files that were not.
Process:
Ran
find . \( -name third_party -prune \) -o \( -name '.git*' -prune \) -o \( \( -name '*.cc' -o -name '*.c' \) -exec sed -i '0,/^#include/ s/^#include/#ifdef HAVE_CONFIG_H\n#include <config.h> \/\/ Must come first\n#endif\n\n#include/' {} + \)
and then manually fixed up src/common/linux/guid_creator.cc,
src/tools/solaris/dump_syms/testdata/dump_syms_regtest.cc,
src/tools/windows/dump_syms/testdata/dump_syms_regtest.cc,
src/common/stabs_reader.h, and src/common/linux/breakpad_getcontext.h.
BUG=google-breakpad:877
Fixed: google-breakpad:877
TEST=./configure && make && make check
TEST=Did the find/sed in ChromeOS's copy, ensured emerge-hana google-breakpad
worked and had fewer LFS violations.
TEST=Did the find/sed in Chrome's copy, ensured compiling hana, windows, linux, and
eve still worked (since Chrome doesn't used config.h)
Change-Id: I16cededbba0ea0c28e919b13243e35300999e799
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4289676
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2023-02-24 20:14:53 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h> // Must come first
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-12-05 23:52:28 +01:00
|
|
|
#include "processor/basic_code_modules.h"
|
2010-06-25 18:57:07 +02:00
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2016-06-20 20:14:47 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
2007-02-14 20:51:05 +01:00
|
|
|
#include "google_breakpad/processor/code_module.h"
|
2006-12-05 23:52:28 +01:00
|
|
|
#include "processor/linked_ptr.h"
|
2007-05-21 22:09:33 +02:00
|
|
|
#include "processor/logging.h"
|
2006-12-05 23:52:28 +01:00
|
|
|
#include "processor/range_map-inl.h"
|
|
|
|
|
|
2007-02-14 20:51:05 +01:00
|
|
|
namespace google_breakpad {
|
2006-12-05 23:52:28 +01:00
|
|
|
|
2016-06-20 20:14:47 +02:00
|
|
|
using std::vector;
|
|
|
|
|
|
2019-06-11 20:48:14 +02:00
|
|
|
BasicCodeModules::BasicCodeModules(const CodeModules* that,
|
|
|
|
|
MergeRangeStrategy strategy)
|
2016-06-06 07:41:10 +02:00
|
|
|
: main_address_(0), map_() {
|
2007-05-21 22:09:33 +02:00
|
|
|
BPLOG_IF(ERROR, !that) << "BasicCodeModules::BasicCodeModules requires "
|
|
|
|
|
"|that|";
|
2006-12-05 23:52:28 +01:00
|
|
|
assert(that);
|
|
|
|
|
|
2019-06-11 20:48:14 +02:00
|
|
|
map_.SetMergeStrategy(strategy);
|
2016-06-20 20:14:47 +02:00
|
|
|
|
2006-12-05 23:52:28 +01:00
|
|
|
const CodeModule *main_module = that->GetMainModule();
|
|
|
|
|
if (main_module)
|
|
|
|
|
main_address_ = main_module->base_address();
|
|
|
|
|
|
|
|
|
|
unsigned int count = that->module_count();
|
2016-06-20 20:14:47 +02:00
|
|
|
for (unsigned int i = 0; i < count; ++i) {
|
2006-12-05 23:52:28 +01:00
|
|
|
// Make a copy of the module and insert it into the map. Use
|
|
|
|
|
// GetModuleAtIndex because ordering is unimportant when slurping the
|
|
|
|
|
// entire list, and GetModuleAtIndex may be faster than
|
|
|
|
|
// GetModuleAtSequence.
|
2016-06-20 20:14:47 +02:00
|
|
|
linked_ptr<const CodeModule> module(that->GetModuleAtIndex(i)->Copy());
|
2016-06-06 07:41:10 +02:00
|
|
|
if (!map_.StoreRange(module->base_address(), module->size(), module)) {
|
2016-06-20 20:14:47 +02:00
|
|
|
BPLOG(ERROR) << "Module " << module->code_file()
|
|
|
|
|
<< " could not be stored";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Report modules with shrunk ranges.
|
|
|
|
|
for (unsigned int i = 0; i < count; ++i) {
|
|
|
|
|
linked_ptr<const CodeModule> module(that->GetModuleAtIndex(i)->Copy());
|
|
|
|
|
uint64_t delta = 0;
|
|
|
|
|
if (map_.RetrieveRange(module->base_address() + module->size() - 1,
|
|
|
|
|
&module, NULL /* base */, &delta, NULL /* size */) &&
|
|
|
|
|
delta > 0) {
|
|
|
|
|
BPLOG(INFO) << "The range for module " << module->code_file()
|
|
|
|
|
<< " was shrunk down by " << HexString(delta) << " bytes.";
|
|
|
|
|
linked_ptr<CodeModule> shrunk_range_module(module->Copy());
|
|
|
|
|
shrunk_range_module->SetShrinkDownDelta(delta);
|
|
|
|
|
shrunk_range_modules_.push_back(shrunk_range_module);
|
2007-05-21 22:09:33 +02:00
|
|
|
}
|
2006-12-05 23:52:28 +01:00
|
|
|
}
|
2016-06-20 20:14:47 +02:00
|
|
|
|
|
|
|
|
// TODO(ivanpe): Report modules with conflicting ranges. The list of such
|
|
|
|
|
// modules should be copied from |that|.
|
2006-12-05 23:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-06 07:41:10 +02:00
|
|
|
BasicCodeModules::BasicCodeModules() : main_address_(0), map_() { }
|
2014-11-19 22:33:26 +01:00
|
|
|
|
2006-12-05 23:52:28 +01:00
|
|
|
BasicCodeModules::~BasicCodeModules() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int BasicCodeModules::module_count() const {
|
2016-06-06 07:41:10 +02:00
|
|
|
return map_.GetCount();
|
2006-12-05 23:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CodeModule* BasicCodeModules::GetModuleForAddress(
|
2013-03-06 15:04:42 +01:00
|
|
|
uint64_t address) const {
|
2006-12-05 23:52:28 +01:00
|
|
|
linked_ptr<const CodeModule> module;
|
2016-06-06 07:41:10 +02:00
|
|
|
if (!map_.RetrieveRange(address, &module, NULL /* base */, NULL /* delta */,
|
|
|
|
|
NULL /* size */)) {
|
2007-05-21 22:09:33 +02:00
|
|
|
BPLOG(INFO) << "No module at " << HexString(address);
|
2006-12-05 23:52:28 +01:00
|
|
|
return NULL;
|
2007-05-21 22:09:33 +02:00
|
|
|
}
|
2006-12-05 23:52:28 +01:00
|
|
|
|
|
|
|
|
return module.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CodeModule* BasicCodeModules::GetMainModule() const {
|
|
|
|
|
return GetModuleForAddress(main_address_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CodeModule* BasicCodeModules::GetModuleAtSequence(
|
|
|
|
|
unsigned int sequence) const {
|
|
|
|
|
linked_ptr<const CodeModule> module;
|
2016-06-06 07:41:10 +02:00
|
|
|
if (!map_.RetrieveRangeAtIndex(sequence, &module, NULL /* base */,
|
|
|
|
|
NULL /* delta */, NULL /* size */)) {
|
2007-05-21 22:09:33 +02:00
|
|
|
BPLOG(ERROR) << "RetrieveRangeAtIndex failed for sequence " << sequence;
|
2006-12-05 23:52:28 +01:00
|
|
|
return NULL;
|
2007-05-21 22:09:33 +02:00
|
|
|
}
|
2006-12-05 23:52:28 +01:00
|
|
|
|
|
|
|
|
return module.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CodeModule* BasicCodeModules::GetModuleAtIndex(
|
|
|
|
|
unsigned int index) const {
|
|
|
|
|
// This class stores everything in a RangeMap, without any more-efficient
|
|
|
|
|
// way to walk the list of CodeModule objects. Implement GetModuleAtIndex
|
|
|
|
|
// using GetModuleAtSequence, which meets all of the requirements, and
|
|
|
|
|
// in addition, guarantees ordering.
|
|
|
|
|
return GetModuleAtSequence(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CodeModules* BasicCodeModules::Copy() const {
|
2019-06-11 20:48:14 +02:00
|
|
|
return new BasicCodeModules(this, map_.GetMergeStrategy());
|
2006-12-05 23:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-20 20:14:47 +02:00
|
|
|
vector<linked_ptr<const CodeModule> >
|
|
|
|
|
BasicCodeModules::GetShrunkRangeModules() const {
|
|
|
|
|
return shrunk_range_modules_;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-14 20:51:05 +01:00
|
|
|
} // namespace google_breakpad
|