Index: source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h =================================================================== --- source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h +++ source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h @@ -52,17 +52,14 @@ ModuleRecord(llvm::Triple::OSType OS, llvm::Triple::ArchType Arch, UUID ID) : Record(Module), OS(OS), Arch(Arch), ID(std::move(ID)) {} - llvm::Triple::OSType getOS() const { return OS; } - llvm::Triple::ArchType getArch() const { return Arch; } - const UUID &getID() const { return ID; } - -private: llvm::Triple::OSType OS; llvm::Triple::ArchType Arch; UUID ID; }; -bool operator==(const ModuleRecord &L, const ModuleRecord &R); +bool operator==(const ModuleRecord &L, const ModuleRecord &R) { + return L.OS == R.OS && L.Arch == R.Arch && L.ID == R.ID; +} llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const ModuleRecord &R); class InfoRecord : public Record { @@ -70,14 +67,11 @@ static llvm::Optional parse(llvm::StringRef Line); InfoRecord(UUID ID) : Record(Info), ID(std::move(ID)) {} - const UUID &getID() const { return ID; } - -private: UUID ID; }; inline bool operator==(const InfoRecord &L, const InfoRecord &R) { - return L.getID() == R.getID(); + return L.ID == R.ID; } llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const InfoRecord &R); @@ -89,12 +83,6 @@ : Record(Module), Multiple(Multiple), Address(Address), ParamSize(ParamSize), Name(Name) {} - bool getMultiple() const { return Multiple; } - lldb::addr_t getAddress() const { return Address; } - lldb::addr_t getParamSize() const { return ParamSize; } - llvm::StringRef getName() const { return Name; } - -private: bool Multiple; lldb::addr_t Address; lldb::addr_t ParamSize; Index: source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp =================================================================== --- source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp +++ source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp @@ -57,17 +57,31 @@ .Default(Triple::UnknownArch); } -static llvm::StringRef consume_front(llvm::StringRef &str, size_t n) { - llvm::StringRef result = str.take_front(n); - str = str.drop_front(n); - return result; +/// Return the number of hex digits needed to encode an (POD) object of a given +/// type. +template static constexpr size_t hex_digits() { + return 2 * sizeof(T); +} + +/// Consume the right number of digits from the input StringRef and convert it +/// to the endian-specific integer N. Return true on success. +template static bool consume_integer(llvm::StringRef &str, T &N) { + llvm::StringRef chunk = str.take_front(hex_digits()); + uintmax_t t; + if (!to_integer(chunk, t, 16)) + return false; + N = t; + str = str.drop_front(hex_digits()); + return true; } static UUID parseModuleId(llvm::Triple::OSType os, llvm::StringRef str) { - struct uuid_data { - llvm::support::ulittle32_t uuid1; - llvm::support::ulittle16_t uuid2[2]; - uint8_t uuid3[8]; + struct data_t { + struct uuid_t { + llvm::support::ulittle32_t part1; + llvm::support::ulittle16_t part2[2]; + uint8_t part3[8]; + } uuid; llvm::support::ulittle32_t age; } data; static_assert(sizeof(data) == 20, ""); @@ -75,31 +89,28 @@ // depending on the size of the age field, which is of variable length. // The first three chunks of the id are encoded in big endian, so we need to // byte-swap those. - if (str.size() < 33 || str.size() > 40) + if (str.size() <= hex_digits() || + str.size() > hex_digits()) return UUID(); - uint32_t t; - if (to_integer(consume_front(str, 8), t, 16)) - data.uuid1 = t; - else + if (!consume_integer(str, data.uuid.part1)) return UUID(); - for (int i = 0; i < 2; ++i) { - if (to_integer(consume_front(str, 4), t, 16)) - data.uuid2[i] = t; - else + for (auto &t : data.uuid.part2) { + if (!consume_integer(str, t)) return UUID(); } - for (int i = 0; i < 8; ++i) { - if (!to_integer(consume_front(str, 2), data.uuid3[i], 16)) + for (auto &t : data.uuid.part3) { + if (!consume_integer(str, t)) return UUID(); } - if (to_integer(str, t, 16)) - data.age = t; - else + uint32_t age; + if (!to_integer(str, age, 16)) return UUID(); + data.age = age; // On non-windows, the age field should always be zero, so we don't include to // match the native uuid format of these platforms. - return UUID::fromData(&data, os == llvm::Triple::Win32 ? 20 : 16); + return UUID::fromData(&data, os == llvm::Triple::Win32 ? sizeof(data) + : sizeof(data.uuid)); } Record::Kind Record::classify(llvm::StringRef Line) { @@ -154,15 +165,11 @@ return ModuleRecord(OS, Arch, std::move(ID)); } -bool breakpad::operator==(const ModuleRecord &L, const ModuleRecord &R) { - return L.getOS() == R.getOS() && L.getArch() == R.getArch() && - L.getID() == R.getID(); -} llvm::raw_ostream &breakpad::operator<<(llvm::raw_ostream &OS, const ModuleRecord &R) { - return OS << "MODULE " << llvm::Triple::getOSTypeName(R.getOS()) << " " - << llvm::Triple::getArchTypeName(R.getArch()) << " " - << R.getID().GetAsString(); + return OS << "MODULE " << llvm::Triple::getOSTypeName(R.OS) << " " + << llvm::Triple::getArchTypeName(R.Arch) << " " + << R.ID.GetAsString(); } llvm::Optional InfoRecord::parse(llvm::StringRef Line) { @@ -189,7 +196,7 @@ llvm::raw_ostream &breakpad::operator<<(llvm::raw_ostream &OS, const InfoRecord &R) { - return OS << "INFO CODE_ID " << R.getID().GetAsString(); + return OS << "INFO CODE_ID " << R.ID.GetAsString(); } llvm::Optional PublicRecord::parse(llvm::StringRef Line) { @@ -221,15 +228,14 @@ } bool breakpad::operator==(const PublicRecord &L, const PublicRecord &R) { - return L.getMultiple() == R.getMultiple() && - L.getAddress() == R.getAddress() && - L.getParamSize() == R.getParamSize() && L.getName() == R.getName(); + return L.Multiple == R.Multiple && L.Address == R.Address && + L.ParamSize == R.ParamSize && L.Name == R.Name; } llvm::raw_ostream &breakpad::operator<<(llvm::raw_ostream &OS, const PublicRecord &R) { return OS << llvm::formatv("PUBLIC {0}{1:x-} {2:x-} {3}", - R.getMultiple() ? "m " : "", R.getAddress(), - R.getParamSize(), R.getName()); + R.Multiple ? "m " : "", R.Address, R.ParamSize, + R.Name); } llvm::StringRef breakpad::toString(Record::Kind K) { Index: source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp =================================================================== --- source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp +++ source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp @@ -33,13 +33,13 @@ return llvm::None; llvm::Triple triple; - triple.setArch(Module->getArch()); - triple.setOS(Module->getOS()); + triple.setArch(Module->Arch); + triple.setOS(Module->OS); std::tie(line, text) = text.split('\n'); auto Info = InfoRecord::parse(line); - UUID uuid = Info && Info->getID() ? Info->getID() : Module->getID(); + UUID uuid = Info && Info->ID ? Info->ID : Module->ID; return Header{ArchSpec(triple), std::move(uuid)}; } Index: source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp =================================================================== --- source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp +++ source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp @@ -187,19 +187,19 @@ LLDB_LOG(log, "Failed to parse: {0}. Skipping record.", line); continue; } - addr_t file_address = base + record->getAddress(); + addr_t file_address = base + record->Address; SectionSP section_sp = list.FindSectionContainingFileAddress(file_address); if (!section_sp) { LLDB_LOG(log, "Ignoring symbol {0}, whose address ({1}) is outside of the " "object file. Mismatched symbol file?", - record->getName(), file_address); + record->Name, file_address); continue; } symtab.AddSymbol(Symbol( - /*symID*/ 0, Mangled(record->getName(), /*is_mangled*/ false), + /*symID*/ 0, Mangled(record->Name, /*is_mangled*/ false), eSymbolTypeCode, /*is_global*/ true, /*is_debug*/ false, /*is_trampoline*/ false, /*is_artificial*/ false,