diff --git a/lldb/source/Core/SourceLocationSpec.cpp b/lldb/source/Core/SourceLocationSpec.cpp --- a/lldb/source/Core/SourceLocationSpec.cpp +++ b/lldb/source/Core/SourceLocationSpec.cpp @@ -8,72 +8,73 @@ #include "lldb/Core/SourceLocationSpec.h" #include "lldb/Utility/StreamString.h" +#include "llvm/ADT/StringExtras.h" #include using namespace lldb; using namespace lldb_private; SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line, std::optional column, bool check_inlines, bool exact_match) : m_declaration(file_spec, line, column.value_or(LLDB_INVALID_COLUMN_NUMBER)), m_check_inlines(check_inlines), m_exact_match(exact_match) {} SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); } bool SourceLocationSpec::operator!() const { return !operator bool(); } bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const { return m_declaration == rhs.m_declaration && m_check_inlines == rhs.GetCheckInlines() && m_exact_match == rhs.GetExactMatch(); } bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const { return !(*this == rhs); } bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const { return SourceLocationSpec::Compare(*this, rhs) < 0; } Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) { loc.Dump(s); return s; } int SourceLocationSpec::Compare(const SourceLocationSpec &lhs, const SourceLocationSpec &rhs) { return Declaration::Compare(lhs.m_declaration, rhs.m_declaration); } bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs, const SourceLocationSpec &rhs, bool full) { return full ? lhs == rhs : (lhs.GetFileSpec() == rhs.GetFileSpec() && lhs.GetLine() == rhs.GetLine()); } void SourceLocationSpec::Dump(Stream &s) const { s << "check inlines = " << llvm::toStringRef(m_check_inlines); s << ", exact match = " << llvm::toStringRef(m_exact_match); m_declaration.Dump(&s, true); } std::string SourceLocationSpec::GetString() const { StreamString ss; Dump(ss); return ss.GetString().str(); } std::optional SourceLocationSpec::GetLine() const { uint32_t line = m_declaration.GetLine(); if (line == 0 || line == LLDB_INVALID_LINE_NUMBER) return std::nullopt; return line; } std::optional SourceLocationSpec::GetColumn() const { uint16_t column = m_declaration.GetColumn(); if (column == LLDB_INVALID_COLUMN_NUMBER) diff --git a/lldb/source/Plugins/Process/Linux/Procfs.cpp b/lldb/source/Plugins/Process/Linux/Procfs.cpp --- a/lldb/source/Plugins/Process/Linux/Procfs.cpp +++ b/lldb/source/Plugins/Process/Linux/Procfs.cpp @@ -8,33 +8,34 @@ #include "Procfs.h" #include "lldb/Host/linux/Support.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Threading.h" #include using namespace lldb; using namespace lldb_private; using namespace process_linux; using namespace llvm; Expected> lldb_private::process_linux::GetProcfsCpuInfo() { static ErrorOr> cpu_info_or_err = getProcFile("cpuinfo"); if (!*cpu_info_or_err) cpu_info_or_err.getError(); MemoryBuffer &buffer = **cpu_info_or_err; return arrayRefFromStringRef(buffer.getBuffer()); } Expected> lldb_private::process_linux::GetAvailableLogicalCoreIDs(StringRef cpuinfo) { SmallVector lines; cpuinfo.split(lines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); std::vector logical_cores; for (StringRef line : lines) { std::pair key_value = line.split(':'); auto key = key_value.first.trim(); diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h --- a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h @@ -13,6 +13,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/IntervalMap.h" +#include "llvm/ADT/SmallString.h" #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" diff --git a/lldb/source/Utility/DataExtractor.cpp b/lldb/source/Utility/DataExtractor.cpp --- a/lldb/source/Utility/DataExtractor.cpp +++ b/lldb/source/Utility/DataExtractor.cpp @@ -23,88 +23,89 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/MD5.h" #include "llvm/Support/MathExtras.h" #include #include #include #include #include #include #include #include using namespace lldb; using namespace lldb_private; static inline uint16_t ReadInt16(const unsigned char *ptr, offset_t offset) { uint16_t value; memcpy(&value, ptr + offset, 2); return value; } static inline uint32_t ReadInt32(const unsigned char *ptr, offset_t offset = 0) { uint32_t value; memcpy(&value, ptr + offset, 4); return value; } static inline uint64_t ReadInt64(const unsigned char *ptr, offset_t offset = 0) { uint64_t value; memcpy(&value, ptr + offset, 8); return value; } static inline uint16_t ReadInt16(const void *ptr) { uint16_t value; memcpy(&value, ptr, 2); return value; } static inline uint16_t ReadSwapInt16(const unsigned char *ptr, offset_t offset) { uint16_t value; memcpy(&value, ptr + offset, 2); return llvm::byteswap(value); } static inline uint32_t ReadSwapInt32(const unsigned char *ptr, offset_t offset) { uint32_t value; memcpy(&value, ptr + offset, 4); return llvm::byteswap(value); } static inline uint64_t ReadSwapInt64(const unsigned char *ptr, offset_t offset) { uint64_t value; memcpy(&value, ptr + offset, 8); return llvm::byteswap(value); } static inline uint16_t ReadSwapInt16(const void *ptr) { uint16_t value; memcpy(&value, ptr, 2); return llvm::byteswap(value); } static inline uint32_t ReadSwapInt32(const void *ptr) { uint32_t value; memcpy(&value, ptr, 4); return llvm::byteswap(value); } static inline uint64_t ReadSwapInt64(const void *ptr) { uint64_t value; memcpy(&value, ptr, 8); return llvm::byteswap(value); } static inline uint64_t ReadMaxInt64(const uint8_t *data, size_t byte_size, ByteOrder byte_order) { uint64_t res = 0; diff --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp --- a/lldb/source/Utility/Event.cpp +++ b/lldb/source/Utility/Event.cpp @@ -15,35 +15,37 @@ #include "lldb/Utility/StreamString.h" #include "lldb/lldb-enumerations.h" +#include "llvm/ADT/StringExtras.h" + #include #include using namespace lldb; using namespace lldb_private; #pragma mark - #pragma mark Event // Event functions Event::Event(Broadcaster *broadcaster, uint32_t event_type, EventData *data) : m_broadcaster_wp(broadcaster->GetBroadcasterImpl()), m_type(event_type), m_data_sp(data) {} Event::Event(Broadcaster *broadcaster, uint32_t event_type, const EventDataSP &event_data_sp) : m_broadcaster_wp(broadcaster->GetBroadcasterImpl()), m_type(event_type), m_data_sp(event_data_sp) {} Event::Event(uint32_t event_type, EventData *data) : m_broadcaster_wp(), m_type(event_type), m_data_sp(data) {} Event::Event(uint32_t event_type, const EventDataSP &event_data_sp) : m_broadcaster_wp(), m_type(event_type), m_data_sp(event_data_sp) {} Event::~Event() = default; void Event::Dump(Stream *s) const { Broadcaster *broadcaster; Broadcaster::BroadcasterImplSP broadcaster_impl_sp(m_broadcaster_wp.lock()); diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorOr.h" diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp --- a/lldb/source/Utility/Scalar.cpp +++ b/lldb/source/Utility/Scalar.cpp @@ -16,17 +16,18 @@ #include "lldb/lldb-types.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include #include using namespace lldb; using namespace lldb_private; using llvm::APFloat; using llvm::APInt; using llvm::APSInt; Scalar::PromotionKey Scalar::GetPromoKey() const { switch (m_type) { case e_void: diff --git a/lldb/source/Utility/StructuredData.cpp b/lldb/source/Utility/StructuredData.cpp --- a/lldb/source/Utility/StructuredData.cpp +++ b/lldb/source/Utility/StructuredData.cpp @@ -9,18 +9,19 @@ #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Status.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/MemoryBuffer.h" #include #include #include using namespace lldb_private; using namespace llvm; static StructuredData::ObjectSP ParseJSONValue(json::Value &value); static StructuredData::ObjectSP ParseJSONObject(json::Object *object); static StructuredData::ObjectSP ParseJSONArray(json::Array *array); StructuredData::ObjectSP StructuredData::ParseJSON(llvm::StringRef json_text) { llvm::Expected value = json::parse(json_text); if (!value) { diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -14,8 +14,6 @@ #define LLVM_SUPPORT_ERROR_H #include "llvm-c/Error.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/abi-breaking.h" #include "llvm/Support/AlignOf.h" @@ -1025,14 +1023,8 @@ /// Write all error messages (if any) in E to a string. The newline character /// is used to separate error messages. -inline std::string toString(Error E) { - SmallVector Errors; - handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { - Errors.push_back(EI.message()); - }); - return join(Errors.begin(), Errors.end(), "\n"); -} +std::string toString(Error E); /// Consume a Error without doing anything. This method should be used /// only where an error can be considered a reasonable and expected return /// value. diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp --- a/llvm/lib/Support/Error.cpp +++ b/llvm/lib/Support/Error.cpp @@ -7,27 +7,29 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Error.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorHandling.h" #include using namespace llvm; namespace { enum class ErrorErrorCode : int { MultipleErrors = 1, FileError, InconvertibleError }; // FIXME: This class is only here to support the transition to llvm::Error. It // will be removed once this transition is complete. Clients should prefer to // deal with the Error value directly, rather than converting to error_code. class ErrorErrorCategory : public std::error_category { public: const char *name() const noexcept override { return "Error"; } std::string message(int condition) const override { switch (static_cast(condition)) { case ErrorErrorCode::MultipleErrors: @@ -70,17 +72,26 @@ }); } +/// Write all error messages (if any) in E to a string. The newline character +/// is used to separate error messages. +std::string toString(Error E) { + SmallVector Errors; + handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { + Errors.push_back(EI.message()); + }); + return join(Errors.begin(), Errors.end(), "\n"); +} std::error_code ErrorList::convertToErrorCode() const { return std::error_code(static_cast(ErrorErrorCode::MultipleErrors), getErrorErrorCat()); } std::error_code inconvertibleErrorCode() { return std::error_code(static_cast(ErrorErrorCode::InconvertibleError), getErrorErrorCat()); } std::error_code FileError::convertToErrorCode() const { std::error_code NestedEC = Err->convertToErrorCode(); if (NestedEC == inconvertibleErrorCode())