2011-09-14 03:02:55 +02:00
|
|
|
// Copyright (c) 2011 Google Inc.
|
2009-08-07 21:28:45 +02:00
|
|
|
// All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
|
// 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.
|
|
|
|
|
|
2010-02-09 18:10:57 +01:00
|
|
|
// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
|
|
|
|
|
|
|
|
|
|
// module.cc: Implement google_breakpad::Module. See module.h.
|
|
|
|
|
|
2010-04-05 21:40:17 +02:00
|
|
|
#include "common/module.h"
|
2009-08-07 21:28:45 +02:00
|
|
|
|
2011-03-11 23:16:12 +01:00
|
|
|
#include <assert.h>
|
2010-06-25 18:57:07 +02:00
|
|
|
#include <errno.h>
|
2011-07-06 19:05:59 +02:00
|
|
|
#include <stdio.h>
|
2010-06-25 18:57:07 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2021-08-03 23:26:38 +02:00
|
|
|
#include <functional>
|
2011-07-06 19:05:59 +02:00
|
|
|
#include <iostream>
|
2021-08-03 23:26:38 +02:00
|
|
|
#include <memory>
|
2011-09-14 03:02:55 +02:00
|
|
|
#include <utility>
|
2011-07-06 19:05:59 +02:00
|
|
|
|
2009-08-07 21:28:45 +02:00
|
|
|
namespace google_breakpad {
|
|
|
|
|
|
2011-07-06 19:05:59 +02:00
|
|
|
using std::dec;
|
|
|
|
|
using std::hex;
|
2021-08-03 23:26:38 +02:00
|
|
|
using std::unique_ptr;
|
2011-07-06 19:05:59 +02:00
|
|
|
|
2021-09-24 22:27:13 +02:00
|
|
|
Module::InlineOrigin* Module::InlineOriginMap::GetOrCreateInlineOrigin(
|
|
|
|
|
uint64_t offset,
|
|
|
|
|
const string& name) {
|
|
|
|
|
uint64_t specification_offset = references_[offset];
|
|
|
|
|
// Find the root offset.
|
|
|
|
|
auto iter = references_.find(specification_offset);
|
|
|
|
|
while (iter != references_.end() &&
|
|
|
|
|
specification_offset != references_[specification_offset]) {
|
|
|
|
|
specification_offset = references_[specification_offset];
|
|
|
|
|
iter = references_.find(specification_offset);
|
|
|
|
|
}
|
|
|
|
|
if (inline_origins_.find(specification_offset) != inline_origins_.end()) {
|
|
|
|
|
if (inline_origins_[specification_offset]->name == "<name omitted>") {
|
|
|
|
|
inline_origins_[specification_offset]->name = name;
|
|
|
|
|
}
|
|
|
|
|
return inline_origins_[specification_offset];
|
|
|
|
|
}
|
|
|
|
|
inline_origins_[specification_offset] = new Module::InlineOrigin(name);
|
|
|
|
|
return inline_origins_[specification_offset];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::InlineOriginMap::SetReference(uint64_t offset,
|
|
|
|
|
uint64_t specification_offset) {
|
|
|
|
|
// If we haven't seen this doesn't exist in reference map, always add it.
|
|
|
|
|
if (references_.find(offset) == references_.end()) {
|
|
|
|
|
references_[offset] = specification_offset;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// If offset equals specification_offset and offset exists in
|
|
|
|
|
// references_, there is no need to update the references_ map.
|
|
|
|
|
// This early return is necessary because the call to erase in following if
|
|
|
|
|
// will remove the entry of specification_offset in inline_origins_. If
|
|
|
|
|
// specification_offset equals to references_[offset], it might be
|
|
|
|
|
// duplicate debug info.
|
|
|
|
|
if (offset == specification_offset ||
|
|
|
|
|
specification_offset == references_[offset])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Fix up mapping in inline_origins_.
|
|
|
|
|
auto remove = inline_origins_.find(references_[offset]);
|
|
|
|
|
if (remove != inline_origins_.end()) {
|
|
|
|
|
inline_origins_[specification_offset] = std::move(remove->second);
|
|
|
|
|
inline_origins_.erase(remove);
|
|
|
|
|
}
|
|
|
|
|
references_[offset] = specification_offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::InlineOriginMap::AssignFilesToInlineOrigins(
|
2021-09-25 00:46:03 +02:00
|
|
|
const vector<uint64_t>& inline_origin_offsets,
|
2021-09-24 22:27:13 +02:00
|
|
|
Module::File* file) {
|
|
|
|
|
for (uint64_t offset : inline_origin_offsets)
|
|
|
|
|
if (references_.find(offset) != references_.end()) {
|
|
|
|
|
auto origin = inline_origins_.find(references_[offset]);
|
|
|
|
|
if (origin != inline_origins_.end())
|
|
|
|
|
origin->second->file = file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
Module::Module(const string& name, const string& os,
|
|
|
|
|
const string& architecture, const string& id,
|
|
|
|
|
const string& code_id /* = "" */) :
|
2009-08-07 21:28:45 +02:00
|
|
|
name_(name),
|
|
|
|
|
os_(os),
|
|
|
|
|
architecture_(architecture),
|
|
|
|
|
id_(id),
|
2016-06-10 19:23:29 +02:00
|
|
|
code_id_(code_id),
|
2009-08-07 21:28:45 +02:00
|
|
|
load_address_(0) { }
|
|
|
|
|
|
|
|
|
|
Module::~Module() {
|
2011-09-14 03:02:55 +02:00
|
|
|
for (FileByNameMap::iterator it = files_.begin(); it != files_.end(); ++it)
|
2009-08-07 21:28:45 +02:00
|
|
|
delete it->second;
|
2010-07-19 22:43:49 +02:00
|
|
|
for (FunctionSet::iterator it = functions_.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
it != functions_.end(); ++it) {
|
2009-08-07 21:28:45 +02:00
|
|
|
delete *it;
|
2011-09-14 03:02:55 +02:00
|
|
|
}
|
2020-06-24 00:55:43 +02:00
|
|
|
for (vector<StackFrameEntry*>::iterator it = stack_frame_entries_.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
it != stack_frame_entries_.end(); ++it) {
|
2010-03-16 17:31:49 +01:00
|
|
|
delete *it;
|
2011-09-14 03:02:55 +02:00
|
|
|
}
|
|
|
|
|
for (ExternSet::iterator it = externs_.begin(); it != externs_.end(); ++it)
|
2011-03-04 17:08:39 +01:00
|
|
|
delete *it;
|
2009-08-07 21:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::SetLoadAddress(Address address) {
|
|
|
|
|
load_address_ = address;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 19:56:38 +01:00
|
|
|
void Module::SetAddressRanges(const vector<Range>& ranges) {
|
|
|
|
|
address_ranges_ = ranges;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 20:09:24 +02:00
|
|
|
bool Module::AddFunction(Function* function) {
|
2011-03-11 23:16:12 +01:00
|
|
|
// FUNC lines must not hold an empty name, so catch the problem early if
|
|
|
|
|
// callers try to add one.
|
|
|
|
|
assert(!function->name.empty());
|
2015-02-03 08:16:04 +01:00
|
|
|
|
2019-10-29 19:56:38 +01:00
|
|
|
if (!AddressIsInModule(function->address)) {
|
2021-06-10 20:09:24 +02:00
|
|
|
return false;
|
2019-10-29 19:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 08:16:04 +01:00
|
|
|
// FUNCs are better than PUBLICs as they come with sizes, so remove an extern
|
|
|
|
|
// with the same address if present.
|
|
|
|
|
Extern ext(function->address);
|
2015-02-04 00:13:04 +01:00
|
|
|
ExternSet::iterator it_ext = externs_.find(&ext);
|
|
|
|
|
if (it_ext == externs_.end() &&
|
|
|
|
|
architecture_ == "arm" &&
|
|
|
|
|
(function->address & 0x1) == 0) {
|
|
|
|
|
// ARM THUMB functions have bit 0 set. ARM64 does not have THUMB.
|
|
|
|
|
Extern arm_thumb_ext(function->address | 0x1);
|
|
|
|
|
it_ext = externs_.find(&arm_thumb_ext);
|
|
|
|
|
}
|
|
|
|
|
if (it_ext != externs_.end()) {
|
2015-02-03 08:16:04 +01:00
|
|
|
delete *it_ext;
|
|
|
|
|
externs_.erase(it_ext);
|
|
|
|
|
}
|
2015-02-04 00:13:04 +01:00
|
|
|
#if _DEBUG
|
|
|
|
|
{
|
|
|
|
|
// There should be no other PUBLIC symbols that overlap with the function.
|
2018-08-18 03:27:24 +02:00
|
|
|
for (const Range& range : function->ranges) {
|
|
|
|
|
Extern debug_ext(range.address);
|
|
|
|
|
ExternSet::iterator it_debug = externs_.lower_bound(&ext);
|
|
|
|
|
assert(it_debug == externs_.end() ||
|
|
|
|
|
(*it_debug)->address >= range.address + range.size);
|
|
|
|
|
}
|
2015-02-04 00:13:04 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
2015-02-03 08:16:04 +01:00
|
|
|
|
2010-07-19 22:43:49 +02:00
|
|
|
std::pair<FunctionSet::iterator,bool> ret = functions_.insert(function);
|
2015-01-27 02:20:59 +01:00
|
|
|
if (!ret.second && (*ret.first != function)) {
|
2011-03-04 17:08:39 +01:00
|
|
|
// Free the duplicate that was not inserted because this Module
|
|
|
|
|
// now owns it.
|
2021-06-10 20:09:24 +02:00
|
|
|
return false;
|
2010-07-13 20:14:27 +02:00
|
|
|
}
|
2021-06-10 20:09:24 +02:00
|
|
|
return true;
|
2009-08-07 21:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
void Module::AddStackFrameEntry(StackFrameEntry* stack_frame_entry) {
|
2019-10-29 19:56:38 +01:00
|
|
|
if (!AddressIsInModule(stack_frame_entry->address)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 17:31:49 +01:00
|
|
|
stack_frame_entries_.push_back(stack_frame_entry);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
void Module::AddExtern(Extern* ext) {
|
2019-10-29 19:56:38 +01:00
|
|
|
if (!AddressIsInModule(ext->address)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 08:16:04 +01:00
|
|
|
std::pair<ExternSet::iterator,bool> ret = externs_.insert(ext);
|
|
|
|
|
if (!ret.second) {
|
|
|
|
|
// Free the duplicate that was not inserted because this Module
|
|
|
|
|
// now owns it.
|
2011-03-04 17:08:39 +01:00
|
|
|
delete ext;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
void Module::GetFunctions(vector<Function*>* vec,
|
|
|
|
|
vector<Function*>::iterator i) {
|
2009-12-23 22:46:00 +01:00
|
|
|
vec->insert(i, functions_.begin(), functions_.end());
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
void Module::GetExterns(vector<Extern*>* vec,
|
|
|
|
|
vector<Extern*>::iterator i) {
|
2011-03-04 17:08:39 +01:00
|
|
|
vec->insert(i, externs_.begin(), externs_.end());
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
Module::File* Module::FindFile(const string& name) {
|
2009-08-07 21:28:45 +02:00
|
|
|
// A tricky bit here. The key of each map entry needs to be a
|
|
|
|
|
// pointer to the entry's File's name string. This means that we
|
|
|
|
|
// can't do the initial lookup with any operation that would create
|
|
|
|
|
// an empty entry for us if the name isn't found (like, say,
|
|
|
|
|
// operator[] or insert do), because such a created entry's key will
|
|
|
|
|
// be a pointer the string passed as our argument. Since the key of
|
|
|
|
|
// a map's value type is const, we can't fix it up once we've
|
|
|
|
|
// created our file. lower_bound does the lookup without doing an
|
|
|
|
|
// insertion, and returns a good hint iterator to pass to insert.
|
|
|
|
|
// Our "destiny" is where we belong, whether we're there or not now.
|
|
|
|
|
FileByNameMap::iterator destiny = files_.lower_bound(&name);
|
|
|
|
|
if (destiny == files_.end()
|
|
|
|
|
|| *destiny->first != name) { // Repeated string comparison, boo hoo.
|
2020-06-24 00:55:43 +02:00
|
|
|
File* file = new File(name);
|
2010-01-28 23:59:15 +01:00
|
|
|
file->source_id = -1;
|
2009-08-07 21:28:45 +02:00
|
|
|
destiny = files_.insert(destiny,
|
2010-01-28 23:59:15 +01:00
|
|
|
FileByNameMap::value_type(&file->name, file));
|
2009-08-07 21:28:45 +02:00
|
|
|
}
|
|
|
|
|
return destiny->second;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
Module::File* Module::FindFile(const char* name) {
|
2009-08-07 21:28:45 +02:00
|
|
|
string name_string = name;
|
|
|
|
|
return FindFile(name_string);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
Module::File* Module::FindExistingFile(const string& name) {
|
2009-12-23 22:46:00 +01:00
|
|
|
FileByNameMap::iterator it = files_.find(&name);
|
|
|
|
|
return (it == files_.end()) ? NULL : it->second;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
void Module::GetFiles(vector<File*>* vec) {
|
2009-12-23 22:46:00 +01:00
|
|
|
vec->clear();
|
2011-09-14 03:02:55 +02:00
|
|
|
for (FileByNameMap::iterator it = files_.begin(); it != files_.end(); ++it)
|
2009-12-23 22:46:00 +01:00
|
|
|
vec->push_back(it->second);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
void Module::GetStackFrameEntries(vector<StackFrameEntry*>* vec) const {
|
2010-03-16 17:31:49 +01:00
|
|
|
*vec = stack_frame_entries_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 22:27:13 +02:00
|
|
|
void Module::AssignSourceIds(
|
|
|
|
|
set<InlineOrigin*, InlineOriginCompare>& inline_origins) {
|
2009-08-07 21:28:45 +02:00
|
|
|
// First, give every source file an id of -1.
|
|
|
|
|
for (FileByNameMap::iterator file_it = files_.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
file_it != files_.end(); ++file_it) {
|
2010-01-28 23:59:15 +01:00
|
|
|
file_it->second->source_id = -1;
|
2011-09-14 03:02:55 +02:00
|
|
|
}
|
2009-08-07 21:28:45 +02:00
|
|
|
|
|
|
|
|
// Next, mark all files actually cited by our functions' line number
|
|
|
|
|
// info, by setting each one's source id to zero.
|
2010-07-19 22:43:49 +02:00
|
|
|
for (FunctionSet::const_iterator func_it = functions_.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
func_it != functions_.end(); ++func_it) {
|
2020-06-24 00:55:43 +02:00
|
|
|
Function* func = *func_it;
|
2010-01-28 23:59:15 +01:00
|
|
|
for (vector<Line>::iterator line_it = func->lines.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
line_it != func->lines.end(); ++line_it)
|
2010-01-28 23:59:15 +01:00
|
|
|
line_it->file->source_id = 0;
|
2009-08-07 21:28:45 +02:00
|
|
|
}
|
2021-08-03 23:26:38 +02:00
|
|
|
// Also mark all files cited by inline functions by setting each one's source
|
|
|
|
|
// id to zero.
|
2021-09-24 22:27:13 +02:00
|
|
|
for (InlineOrigin* origin : inline_origins)
|
2021-08-03 23:26:38 +02:00
|
|
|
// There are some artificial inline functions which don't belong to
|
|
|
|
|
// any file. Those will have file id -1.
|
|
|
|
|
if (origin->file)
|
|
|
|
|
origin->file->source_id = 0;
|
2009-08-07 21:28:45 +02:00
|
|
|
|
|
|
|
|
// Finally, assign source ids to those files that have been marked.
|
|
|
|
|
// We could have just assigned source id numbers while traversing
|
|
|
|
|
// the line numbers, but doing it this way numbers the files in
|
|
|
|
|
// lexicographical order by name, which is neat.
|
|
|
|
|
int next_source_id = 0;
|
|
|
|
|
for (FileByNameMap::iterator file_it = files_.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
file_it != files_.end(); ++file_it) {
|
2010-07-13 20:14:27 +02:00
|
|
|
if (!file_it->second->source_id)
|
2010-01-28 23:59:15 +01:00
|
|
|
file_it->second->source_id = next_source_id++;
|
2011-09-14 03:02:55 +02:00
|
|
|
}
|
2009-08-07 21:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-03 23:26:38 +02:00
|
|
|
static void InlineDFS(
|
|
|
|
|
vector<unique_ptr<Module::Inline>>& inlines,
|
|
|
|
|
std::function<void(unique_ptr<Module::Inline>&)> const& forEach) {
|
|
|
|
|
for (unique_ptr<Module::Inline>& in : inlines) {
|
|
|
|
|
forEach(in);
|
|
|
|
|
InlineDFS(in->child_inlines, forEach);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 22:27:13 +02:00
|
|
|
void Module::CreateInlineOrigins(
|
|
|
|
|
set<InlineOrigin*, InlineOriginCompare>& inline_origins) {
|
2021-08-03 23:26:38 +02:00
|
|
|
// Only add origins that have file and deduplicate origins with same name and
|
|
|
|
|
// file id by doing a DFS.
|
2021-09-24 22:27:13 +02:00
|
|
|
auto addInlineOrigins = [&](unique_ptr<Inline>& in) {
|
|
|
|
|
auto it = inline_origins.find(in->origin);
|
|
|
|
|
if (it == inline_origins.end())
|
|
|
|
|
inline_origins.insert(in->origin);
|
2021-08-03 23:26:38 +02:00
|
|
|
else
|
|
|
|
|
in->origin = *it;
|
|
|
|
|
};
|
|
|
|
|
for (Function* func : functions_)
|
|
|
|
|
InlineDFS(func->inlines, addInlineOrigins);
|
|
|
|
|
int next_id = 0;
|
2021-09-24 22:27:13 +02:00
|
|
|
for (InlineOrigin* origin : inline_origins) {
|
2021-08-03 23:26:38 +02:00
|
|
|
origin->id = next_id++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-07 21:28:45 +02:00
|
|
|
bool Module::ReportError() {
|
|
|
|
|
fprintf(stderr, "error writing symbol file: %s\n",
|
2010-07-13 20:14:27 +02:00
|
|
|
strerror(errno));
|
2009-08-07 21:28:45 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
bool Module::WriteRuleMap(const RuleMap& rule_map, std::ostream& stream) {
|
2010-03-16 17:31:49 +01:00
|
|
|
for (RuleMap::const_iterator it = rule_map.begin();
|
2011-09-14 03:02:55 +02:00
|
|
|
it != rule_map.end(); ++it) {
|
2011-07-06 19:05:59 +02:00
|
|
|
if (it != rule_map.begin())
|
|
|
|
|
stream << ' ';
|
|
|
|
|
stream << it->first << ": " << it->second;
|
2010-03-16 17:31:49 +01:00
|
|
|
}
|
2011-07-06 19:05:59 +02:00
|
|
|
return stream.good();
|
2010-03-16 17:31:49 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-29 19:56:38 +01:00
|
|
|
bool Module::AddressIsInModule(Address address) const {
|
|
|
|
|
if (address_ranges_.empty()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
for (const auto& segment : address_ranges_) {
|
|
|
|
|
if (address >= segment.address &&
|
|
|
|
|
address < segment.address + segment.size) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:55:43 +02:00
|
|
|
bool Module::Write(std::ostream& stream, SymbolData symbol_data) {
|
2011-07-06 19:05:59 +02:00
|
|
|
stream << "MODULE " << os_ << " " << architecture_ << " "
|
2018-05-30 01:53:53 +02:00
|
|
|
<< id_ << " " << name_ << "\n";
|
2011-07-06 19:05:59 +02:00
|
|
|
if (!stream.good())
|
2009-08-07 21:28:45 +02:00
|
|
|
return ReportError();
|
|
|
|
|
|
2016-06-10 19:23:29 +02:00
|
|
|
if (!code_id_.empty()) {
|
2018-05-30 01:53:53 +02:00
|
|
|
stream << "INFO CODE_ID " << code_id_ << "\n";
|
2016-06-10 19:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-30 21:27:45 +02:00
|
|
|
if (symbol_data & SYMBOLS_AND_FILES) {
|
2021-09-24 22:27:13 +02:00
|
|
|
// Get all referenced inline origins.
|
|
|
|
|
set<InlineOrigin*, InlineOriginCompare> inline_origins;
|
|
|
|
|
CreateInlineOrigins(inline_origins);
|
|
|
|
|
AssignSourceIds(inline_origins);
|
2013-03-06 16:32:53 +01:00
|
|
|
|
|
|
|
|
// Write out files.
|
|
|
|
|
for (FileByNameMap::iterator file_it = files_.begin();
|
|
|
|
|
file_it != files_.end(); ++file_it) {
|
2020-06-24 00:55:43 +02:00
|
|
|
File* file = file_it->second;
|
2013-03-06 16:32:53 +01:00
|
|
|
if (file->source_id >= 0) {
|
2018-05-30 01:53:53 +02:00
|
|
|
stream << "FILE " << file->source_id << " " << file->name << "\n";
|
2013-03-06 16:32:53 +01:00
|
|
|
if (!stream.good())
|
|
|
|
|
return ReportError();
|
|
|
|
|
}
|
2009-08-07 21:28:45 +02:00
|
|
|
}
|
2021-08-03 23:26:38 +02:00
|
|
|
// Write out inline origins.
|
2021-09-24 22:27:13 +02:00
|
|
|
for (InlineOrigin* origin : inline_origins) {
|
2021-09-17 00:50:35 +02:00
|
|
|
stream << "INLINE_ORIGIN " << origin->id << " " << origin->getFileID()
|
|
|
|
|
<< " " << origin->name << "\n";
|
|
|
|
|
if (!stream.good())
|
|
|
|
|
return ReportError();
|
2021-08-03 23:26:38 +02:00
|
|
|
}
|
2009-08-07 21:28:45 +02:00
|
|
|
|
2021-08-03 23:26:38 +02:00
|
|
|
// Write out functions and their inlines and lines.
|
2013-03-06 16:32:53 +01:00
|
|
|
for (FunctionSet::const_iterator func_it = functions_.begin();
|
|
|
|
|
func_it != functions_.end(); ++func_it) {
|
2020-06-24 00:55:43 +02:00
|
|
|
Function* func = *func_it;
|
2018-08-04 00:59:34 +02:00
|
|
|
vector<Line>::iterator line_it = func->lines.begin();
|
|
|
|
|
for (auto range_it = func->ranges.cbegin();
|
|
|
|
|
range_it != func->ranges.cend(); ++range_it) {
|
|
|
|
|
stream << "FUNC " << hex
|
|
|
|
|
<< (range_it->address - load_address_) << " "
|
|
|
|
|
<< range_it->size << " "
|
|
|
|
|
<< func->parameter_size << " "
|
|
|
|
|
<< func->name << dec << "\n";
|
|
|
|
|
|
2013-03-06 16:32:53 +01:00
|
|
|
if (!stream.good())
|
|
|
|
|
return ReportError();
|
2018-08-04 00:59:34 +02:00
|
|
|
|
2021-08-03 23:26:38 +02:00
|
|
|
// Write out inlines.
|
2021-09-17 00:50:35 +02:00
|
|
|
auto write_inline = [&](unique_ptr<Inline>& in) {
|
|
|
|
|
stream << "INLINE ";
|
|
|
|
|
stream << in->inline_nest_level << " " << in->call_site_line << " "
|
|
|
|
|
<< in->origin->id << hex;
|
|
|
|
|
for (const Range& r : in->ranges)
|
|
|
|
|
stream << " " << (r.address - load_address_) << " " << r.size;
|
|
|
|
|
stream << dec << "\n";
|
|
|
|
|
};
|
|
|
|
|
InlineDFS(func->inlines, write_inline);
|
|
|
|
|
if (!stream.good())
|
|
|
|
|
return ReportError();
|
2021-08-03 23:26:38 +02:00
|
|
|
|
2018-08-04 00:59:34 +02:00
|
|
|
while ((line_it != func->lines.end()) &&
|
|
|
|
|
(line_it->address >= range_it->address) &&
|
|
|
|
|
(line_it->address < (range_it->address + range_it->size))) {
|
|
|
|
|
stream << hex
|
|
|
|
|
<< (line_it->address - load_address_) << " "
|
|
|
|
|
<< line_it->size << " "
|
|
|
|
|
<< dec
|
|
|
|
|
<< line_it->number << " "
|
|
|
|
|
<< line_it->file->source_id << "\n";
|
|
|
|
|
|
|
|
|
|
if (!stream.good())
|
|
|
|
|
return ReportError();
|
|
|
|
|
|
|
|
|
|
++line_it;
|
|
|
|
|
}
|
2013-03-06 16:32:53 +01:00
|
|
|
}
|
2011-07-06 19:05:59 +02:00
|
|
|
}
|
2009-08-07 21:28:45 +02:00
|
|
|
|
2013-03-06 16:32:53 +01:00
|
|
|
// Write out 'PUBLIC' records.
|
|
|
|
|
for (ExternSet::const_iterator extern_it = externs_.begin();
|
|
|
|
|
extern_it != externs_.end(); ++extern_it) {
|
2020-06-24 00:55:43 +02:00
|
|
|
Extern* ext = *extern_it;
|
2013-03-06 16:32:53 +01:00
|
|
|
stream << "PUBLIC " << hex
|
|
|
|
|
<< (ext->address - load_address_) << " 0 "
|
2018-05-30 01:53:53 +02:00
|
|
|
<< ext->name << dec << "\n";
|
2013-03-06 16:32:53 +01:00
|
|
|
}
|
2011-03-04 17:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-30 21:27:45 +02:00
|
|
|
if (symbol_data & CFI) {
|
2011-09-14 03:02:55 +02:00
|
|
|
// Write out 'STACK CFI INIT' and 'STACK CFI' records.
|
2020-06-24 00:55:43 +02:00
|
|
|
vector<StackFrameEntry*>::const_iterator frame_it;
|
2011-09-14 03:02:55 +02:00
|
|
|
for (frame_it = stack_frame_entries_.begin();
|
|
|
|
|
frame_it != stack_frame_entries_.end(); ++frame_it) {
|
2020-06-24 00:55:43 +02:00
|
|
|
StackFrameEntry* entry = *frame_it;
|
2011-09-14 03:02:55 +02:00
|
|
|
stream << "STACK CFI INIT " << hex
|
|
|
|
|
<< (entry->address - load_address_) << " "
|
|
|
|
|
<< entry->size << " " << dec;
|
2011-07-06 19:05:59 +02:00
|
|
|
if (!stream.good()
|
2011-09-14 03:02:55 +02:00
|
|
|
|| !WriteRuleMap(entry->initial_rules, stream))
|
2010-03-16 17:31:49 +01:00
|
|
|
return ReportError();
|
2011-07-06 19:05:59 +02:00
|
|
|
|
2018-05-30 01:53:53 +02:00
|
|
|
stream << "\n";
|
2011-09-14 03:02:55 +02:00
|
|
|
|
|
|
|
|
// Write out this entry's delta rules as 'STACK CFI' records.
|
|
|
|
|
for (RuleChangeMap::const_iterator delta_it = entry->rule_changes.begin();
|
|
|
|
|
delta_it != entry->rule_changes.end(); ++delta_it) {
|
|
|
|
|
stream << "STACK CFI " << hex
|
|
|
|
|
<< (delta_it->first - load_address_) << " " << dec;
|
|
|
|
|
if (!stream.good()
|
|
|
|
|
|| !WriteRuleMap(delta_it->second, stream))
|
|
|
|
|
return ReportError();
|
|
|
|
|
|
2018-05-30 01:53:53 +02:00
|
|
|
stream << "\n";
|
2011-09-14 03:02:55 +02:00
|
|
|
}
|
2010-03-16 17:31:49 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-07 21:28:45 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 03:02:55 +02:00
|
|
|
} // namespace google_breakpad
|