Skip to content

Commit

Permalink
Update dependencies (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 authored Apr 16, 2022
1 parent b4fd022 commit b845943
Show file tree
Hide file tree
Showing 22 changed files with 514 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Celestia/src/main/cpp/dependency
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ class DwarfCUToModule: public RootDIEHandler {
DwarfCUToModule(FileContext* file_context,
LineToModuleHandler* line_reader,
RangesHandler* ranges_handler,
WarningReporter* reporter);
WarningReporter* reporter,
bool handle_inline = false);
~DwarfCUToModule();

void ProcessAttributeSigned(enum DwarfAttribute attr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "common/using_std_string.h"

namespace google_breakpad {
namespace elf {

// GNU binutils' ld defaults to 'sha1', which is 160 bits == 20 bytes,
// so this is enough to fit that, which most binaries will use.
Expand Down Expand Up @@ -83,6 +84,7 @@ class FileID {
string path_;
};

} // namespace elf
} // namespace google_breakpad

#endif // COMMON_LINUX_FILE_ID_H__
87 changes: 73 additions & 14 deletions app/src/main/cpp/crash/include/breakpad/common/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#ifndef COMMON_LINUX_MODULE_H__
#define COMMON_LINUX_MODULE_H__

#include <functional>
#include <iostream>
#include <limits>
#include <map>
Expand All @@ -46,7 +47,9 @@
#include <string>
#include <vector>

#include "common/string_view.h"
#include "common/symbol_data.h"
#include "common/unordered.h"
#include "common/using_std_string.h"
#include "google_breakpad/common/breakpad_types.h"

Expand Down Expand Up @@ -101,7 +104,7 @@ class Module {

// A function.
struct Function {
Function(const string& name_input, const Address& address_input) :
Function(StringView name_input, const Address& address_input) :
name(name_input), address(address_input), parameter_size(0) {}

// For sorting by address. (Not style-guide compliant, but it's
Expand All @@ -111,7 +114,7 @@ class Module {
}

// The function's name.
string name;
StringView name;

// The start address and the address ranges covered by the function.
const Address address;
Expand All @@ -129,14 +132,14 @@ class Module {
};

struct InlineOrigin {
InlineOrigin(const string& name): id(-1), name(name), file(NULL) {}
explicit InlineOrigin(StringView name) : id(-1), name(name) {}

// A unique id for each InlineOrigin object. INLINE records use the id to
// refer to its INLINE_ORIGIN record.
int id;

// The inlined function's name.
string name;
StringView name;

File* file;

Expand All @@ -148,11 +151,14 @@ class Module {
Inline(InlineOrigin* origin,
const vector<Range>& ranges,
int call_site_line,
int call_site_file_id,
int inline_nest_level,
vector<std::unique_ptr<Inline>> child_inlines)
: origin(origin),
ranges(ranges),
call_site_line(call_site_line),
call_site_file_id(call_site_file_id),
call_site_file(nullptr),
inline_nest_level(inline_nest_level),
child_inlines(std::move(child_inlines)) {}

Expand All @@ -163,12 +169,61 @@ class Module {

int call_site_line;

// The id is only meanful inside a CU. It's only used for looking up real
// File* after scanning a CU.
int call_site_file_id;

File* call_site_file;

int inline_nest_level;

// A list of inlines which are children of this inline.
vector<std::unique_ptr<Inline>> child_inlines;

int getCallSiteFileID() const {
return call_site_file ? call_site_file->source_id : -1;
}

static void InlineDFS(
vector<std::unique_ptr<Module::Inline>>& inlines,
std::function<void(std::unique_ptr<Module::Inline>&)> const& forEach) {
for (std::unique_ptr<Module::Inline>& in : inlines) {
forEach(in);
InlineDFS(in->child_inlines, forEach);
}
}
};

typedef map<uint64_t, InlineOrigin*> InlineOriginByOffset;

class InlineOriginMap {
public:
// Add INLINE ORIGIN to the module. Return a pointer to origin .
InlineOrigin* GetOrCreateInlineOrigin(uint64_t offset, StringView name);

// offset is the offset of a DW_TAG_subprogram. specification_offset is the
// value of its DW_AT_specification or equals to offset if
// DW_AT_specification doesn't exist in that DIE.
void SetReference(uint64_t offset, uint64_t specification_offset);

~InlineOriginMap() {
for (const auto& iter : inline_origins_) {
delete iter.second;
}
}

private:
// A map from a DW_TAG_subprogram's offset to the DW_TAG_subprogram.
InlineOriginByOffset inline_origins_;

// A map from a DW_TAG_subprogram's offset to the offset of its
// specification or abstract origin subprogram. The set of values in this
// map should always be the same set of keys in inline_origins_.
map<uint64_t, uint64_t> references_;
};

InlineOriginMap inline_origin_map;

// A source line.
struct Line {
// For sorting by address. (Not style-guide compliant, but it's
Expand Down Expand Up @@ -227,10 +282,8 @@ class Module {
};

struct InlineOriginCompare {
bool operator() (const InlineOrigin* lhs, const InlineOrigin* rhs) const {
if (lhs->getFileID() == rhs->getFileID())
return lhs->name < rhs->name;
return lhs->getFileID() < rhs->getFileID();
bool operator()(const InlineOrigin* lhs, const InlineOrigin* rhs) const {
return lhs->name < rhs->name;
}
};

Expand Down Expand Up @@ -328,11 +381,12 @@ class Module {
// Set the source id numbers for all other files --- unused by the
// source line data --- to -1. We do this before writing out the
// symbol file, at which point we omit any unused files.
void AssignSourceIds();
void AssignSourceIds(set<InlineOrigin*, InlineOriginCompare>& inline_origins);

// This function should be called before AssignSourceIds() to get the set of
// valid InlineOrigins*.
void CreateInlineOrigins();
void CreateInlineOrigins(
set<InlineOrigin*, InlineOriginCompare>& inline_origins);

// Call AssignSourceIds, and write this module to STREAM in the
// breakpad symbol format. Return true if all goes well, or false if
Expand All @@ -348,6 +402,13 @@ class Module {
// established by SetLoadAddress.
bool Write(std::ostream& stream, SymbolData symbol_data);

// Place the name in the global set of strings. Return a StringView points to
// a string inside the pool.
StringView AddStringToPool(const string& str) {
auto result = common_strings_.insert(str);
return *(result.first);
}

string name() const { return name_; }
string os() const { return os_; }
string architecture() const { return architecture_; }
Expand Down Expand Up @@ -393,9 +454,6 @@ class Module {
// A set containing Function structures, sorted by address.
typedef set<Function*, FunctionCompare> FunctionSet;

// A set containing Function structures, sorted by address.
typedef set<InlineOrigin*, InlineOriginCompare> InlineOriginSet;

// A set containing Extern structures, sorted by address.
typedef set<Extern*, ExternCompare> ExternSet;

Expand All @@ -404,7 +462,6 @@ class Module {
// point to.
FileByNameMap files_; // This module's source files.
FunctionSet functions_; // This module's functions.
InlineOriginSet inline_origins_; // This module's inline origins.

// The module owns all the call frame info entries that have been
// added to it.
Expand All @@ -413,6 +470,8 @@ class Module {
// The module owns all the externs that have been added to it;
// destroying the module frees the Externs these point to.
ExternSet externs_;

unordered_set<string> common_strings_;
};

} // namespace google_breakpad
Expand Down
114 changes: 114 additions & 0 deletions app/src/main/cpp/crash/include/breakpad/common/string_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) 2021 Google Inc.
// 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.

#ifndef COMMON_STRING_VIEW_H__
#define COMMON_STRING_VIEW_H__

#include <cassert>
#include <cstring>
#include <ostream>
#include "common/using_std_string.h"

namespace google_breakpad {

// A StringView is a string reference to a string object, but not own the
// string object. It's a compatibile layer until we can use std::string_view in
// C++17.
class StringView {
private:
// The start of the string, in an external buffer. It doesn't have to be
// null-terminated.
const char* data_ = "";

size_t length_ = 0;

public:
// Construct an empty StringView.
StringView() = default;

// Disallow construct StringView from nullptr.
StringView(std::nullptr_t) = delete;

// Construct a StringView from a cstring.
StringView(const char* str) : data_(str) {
assert(str);
length_ = strlen(str);
}

// Construct a StringView from a cstring with fixed length.
StringView(const char* str, size_t length) : data_(str), length_(length) {
assert(str);
}

// Construct a StringView from an std::string.
StringView(const string& str) : data_(str.data()), length_(str.length()) {}

string str() const { return string(data_, length_); }

const char* data() const { return data_; }

bool empty() const { return length_ == 0; }

size_t size() const { return length_; }

int compare(StringView rhs) const {
size_t min_len = std::min(size(), rhs.size());
int res = memcmp(data_, rhs.data(), min_len);
if (res != 0)
return res;
if (size() == rhs.size())
return 0;
return size() < rhs.size() ? -1 : 1;
}
};

inline bool operator==(StringView lhs, StringView rhs) {
return lhs.compare(rhs) == 0;
}

inline bool operator!=(StringView lhs, StringView rhs) {
return lhs.compare(rhs) != 0;
}

inline bool operator<(StringView lhs, StringView rhs) {
return lhs.compare(rhs) < 0;
}

inline bool operator>(StringView lhs, StringView rhs) {
return lhs.compare(rhs) > 0;
}

inline std::ostream& operator<<(std::ostream& os, StringView s) {
os << s.str();
return os;
}

} // namespace google_breakpad

#endif // COMMON_STRING_VIEW_H__
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ typedef enum {
/* EXC_MACH_SYSCALL */
MD_EXCEPTION_MAC_RPC_ALERT = 9,
/* EXC_RPC_ALERT */
MD_EXCEPTION_MAC_SIMULATED = 0x43507378
MD_EXCEPTION_MAC_SIMULATED = 0x43507378,
/* Fake exception code used by Crashpad's SimulateCrash ('CPsx'). */
MD_NS_EXCEPTION_SIMULATED = 0x43506E78
/* Fake exception code used by Crashpad's uncaught exceptions ('CPnx'). */
} MDExceptionMac;

/* For (MDException).exception_flags. Breakpad minidump extension for Mac OS X
Expand Down
Loading

0 comments on commit b845943

Please sign in to comment.