diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-12-18 20:30:12 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2024-04-06 20:11:55 +0000 |
| commit | 5f757f3ff9144b609b3c433dfd370cc6bdc191ad (patch) | |
| tree | 1b4e980b866cd26a00af34c0a653eb640bd09caf /contrib/llvm-project/lldb/source/Utility | |
| parent | 3e1c8a35f741a5d114d0ba670b15191355711fe9 (diff) | |
| parent | 312c0ed19cc5276a17bacf2120097bec4515b0f1 (diff) | |
Diffstat (limited to 'contrib/llvm-project/lldb/source/Utility')
20 files changed, 283 insertions, 108 deletions
diff --git a/contrib/llvm-project/lldb/source/Utility/AddressableBits.cpp b/contrib/llvm-project/lldb/source/Utility/AddressableBits.cpp new file mode 100644 index 000000000000..c6e25f608da7 --- /dev/null +++ b/contrib/llvm-project/lldb/source/Utility/AddressableBits.cpp @@ -0,0 +1,51 @@ +//===-- AddressableBits.cpp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/AddressableBits.h" +#include "lldb/Target/Process.h" +#include "lldb/lldb-types.h" + +using namespace lldb; +using namespace lldb_private; + +void AddressableBits::SetAddressableBits(uint32_t addressing_bits) { + m_low_memory_addr_bits = m_high_memory_addr_bits = addressing_bits; +} + +void AddressableBits::SetAddressableBits(uint32_t lowmem_addressing_bits, + uint32_t highmem_addressing_bits) { + m_low_memory_addr_bits = lowmem_addressing_bits; + m_high_memory_addr_bits = highmem_addressing_bits; +} + +void AddressableBits::SetLowmemAddressableBits( + uint32_t lowmem_addressing_bits) { + m_low_memory_addr_bits = lowmem_addressing_bits; +} + +void AddressableBits::SetHighmemAddressableBits( + uint32_t highmem_addressing_bits) { + m_high_memory_addr_bits = highmem_addressing_bits; +} + +void AddressableBits::SetProcessMasks(Process &process) { + if (m_low_memory_addr_bits == 0 && m_high_memory_addr_bits == 0) + return; + + if (m_low_memory_addr_bits != 0) { + addr_t low_addr_mask = ~((1ULL << m_low_memory_addr_bits) - 1); + process.SetCodeAddressMask(low_addr_mask); + process.SetDataAddressMask(low_addr_mask); + } + + if (m_high_memory_addr_bits != 0) { + addr_t hi_addr_mask = ~((1ULL << m_high_memory_addr_bits) - 1); + process.SetHighmemCodeAddressMask(hi_addr_mask); + process.SetHighmemDataAddressMask(hi_addr_mask); + } +} diff --git a/contrib/llvm-project/lldb/source/Utility/Args.cpp b/contrib/llvm-project/lldb/source/Utility/Args.cpp index d34433996021..13b993bc74c9 100644 --- a/contrib/llvm-project/lldb/source/Utility/Args.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Args.cpp @@ -25,7 +25,7 @@ static llvm::StringRef ParseDoubleQuotes(llvm::StringRef quoted, // Inside double quotes, '\' and '"' are special. static const char *k_escapable_characters = "\"\\"; while (true) { - // Skip over over regular characters and append them. + // Skip over regular characters and append them. size_t regular = quoted.find_first_of(k_escapable_characters); result += quoted.substr(0, regular); quoted = quoted.substr(regular); @@ -93,7 +93,7 @@ ParseSingleArgument(llvm::StringRef command) { bool arg_complete = false; do { - // Skip over over regular characters and append them. + // Skip over regular characters and append them. size_t regular = command.find_first_of(" \t\r\"'`\\"); arg += command.substr(0, regular); command = command.substr(regular); @@ -445,6 +445,7 @@ uint32_t Args::StringToGenericRegister(llvm::StringRef s) { .Case("arg6", LLDB_REGNUM_GENERIC_ARG6) .Case("arg7", LLDB_REGNUM_GENERIC_ARG7) .Case("arg8", LLDB_REGNUM_GENERIC_ARG8) + .Case("tp", LLDB_REGNUM_GENERIC_TP) .Default(LLDB_INVALID_REGNUM); return result; } @@ -640,7 +641,7 @@ void OptionsWithRaw::SetFromString(llvm::StringRef arg_string) { // If the string doesn't start with a dash, we just have no options and just // a raw part. - if (!arg_string.startswith("-")) { + if (!arg_string.starts_with("-")) { m_suffix = std::string(original_args); return; } diff --git a/contrib/llvm-project/lldb/source/Utility/Broadcaster.cpp b/contrib/llvm-project/lldb/source/Utility/Broadcaster.cpp index c9ecd4a7d2a9..914812d78577 100644 --- a/contrib/llvm-project/lldb/source/Utility/Broadcaster.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Broadcaster.cpp @@ -50,22 +50,42 @@ void Broadcaster::CheckInWithManager() { } llvm::SmallVector<std::pair<ListenerSP, uint32_t &>, 4> -Broadcaster::BroadcasterImpl::GetListeners() { +Broadcaster::BroadcasterImpl::GetListeners(uint32_t event_mask, + bool include_primary) { llvm::SmallVector<std::pair<ListenerSP, uint32_t &>, 4> listeners; - listeners.reserve(m_listeners.size()); + size_t max_count = m_listeners.size(); + if (include_primary) + max_count++; + listeners.reserve(max_count); for (auto it = m_listeners.begin(); it != m_listeners.end();) { lldb::ListenerSP curr_listener_sp(it->first.lock()); - if (curr_listener_sp && it->second) { - listeners.emplace_back(std::move(curr_listener_sp), it->second); + if (curr_listener_sp) { + if (it->second & event_mask) + listeners.emplace_back(std::move(curr_listener_sp), it->second); ++it; } else + // If our listener_wp didn't resolve, then we should remove this entry. it = m_listeners.erase(it); } + if (include_primary && m_primary_listener_sp) + listeners.emplace_back(m_primary_listener_sp, m_primary_listener_mask); return listeners; } +bool Broadcaster::BroadcasterImpl::HasListeners(uint32_t event_mask) { + if (m_primary_listener_sp) + return true; + for (auto it = m_listeners.begin(); it != m_listeners.end(); it++) { + // Don't return a listener if the other end of the WP is gone: + lldb::ListenerSP curr_listener_sp(it->first.lock()); + if (curr_listener_sp && (it->second & event_mask)) + return true; + } + return false; +} + void Broadcaster::BroadcasterImpl::Clear() { std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); @@ -75,6 +95,7 @@ void Broadcaster::BroadcasterImpl::Clear() { pair.first->BroadcasterWillDestruct(&m_broadcaster); m_listeners.clear(); + m_primary_listener_sp.reset(); } Broadcaster *Broadcaster::BroadcasterImpl::GetBroadcaster() { @@ -122,7 +143,11 @@ Broadcaster::BroadcasterImpl::AddListener(const lldb::ListenerSP &listener_sp, bool handled = false; - for (auto &pair : GetListeners()) { + if (listener_sp == m_primary_listener_sp) + // This already handles all bits so just return the mask: + return event_mask; + + for (auto &pair : GetListeners(UINT32_MAX, false)) { if (pair.first == listener_sp) { handled = true; pair.second |= event_mask; @@ -151,11 +176,11 @@ bool Broadcaster::BroadcasterImpl::EventTypeHasListeners(uint32_t event_type) { if (!m_hijacking_listeners.empty() && event_type & m_hijacking_masks.back()) return true; - for (auto &pair : GetListeners()) { - if (pair.second & event_type) - return true; - } - return false; + // The primary listener listens for all event bits: + if (m_primary_listener_sp) + return true; + + return HasListeners(event_type); } bool Broadcaster::BroadcasterImpl::RemoveListener( @@ -163,12 +188,33 @@ bool Broadcaster::BroadcasterImpl::RemoveListener( if (!listener) return false; + if (listener == m_primary_listener_sp.get()) { + // Primary listeners listen for all the event bits for their broadcaster, + // so remove this altogether if asked: + m_primary_listener_sp.reset(); + return true; + } + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); - for (auto &pair : GetListeners()) { - if (pair.first.get() == listener) { - pair.second &= ~event_mask; - return true; + for (auto it = m_listeners.begin(); it != m_listeners.end();) { + lldb::ListenerSP curr_listener_sp(it->first.lock()); + + if (!curr_listener_sp) { + // The weak pointer for this listener didn't resolve, lets' prune it + // as we go. + m_listeners.erase(it); + continue; } + + if (curr_listener_sp.get() == listener) { + it->second &= ~event_mask; + // If we removed all the event bits from a listener, remove it from + // the list as well. + if (!it->second) + m_listeners.erase(it); + return true; + } else + it++; } return false; } @@ -222,25 +268,34 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp, event_description.GetData(), unique, static_cast<void *>(hijacking_listener_sp.get())); } + ListenerSP primary_listener_sp + = hijacking_listener_sp ? hijacking_listener_sp : m_primary_listener_sp; - if (hijacking_listener_sp) { - if (unique && hijacking_listener_sp->PeekAtNextEventForBroadcasterWithType( + if (primary_listener_sp) { + if (unique && primary_listener_sp->PeekAtNextEventForBroadcasterWithType( &m_broadcaster, event_type)) return; - hijacking_listener_sp->AddEvent(event_sp); - if (m_shadow_listener) - m_shadow_listener->AddEvent(event_sp); + // Add the pending listeners but not if the event is hijacked, since that + // is given sole access to the event stream it is hijacking. + // Make sure to do this before adding the event to the primary or it might + // start handling the event before we're done adding all the pending + // listeners. + // Also, don't redo the check for unique here, since otherwise that could + // be racy, and if we send the event to the primary listener then we SHOULD + // send it to the secondary listeners or they will get out of sync with the + // primary listener. + if (!hijacking_listener_sp) { + for (auto &pair : GetListeners(event_type, false)) + event_sp->AddPendingListener(pair.first); + } + primary_listener_sp->AddEvent(event_sp); } else { - for (auto &pair : GetListeners()) { - if (!(pair.second & event_type)) - continue; + for (auto &pair : GetListeners(event_type)) { if (unique && pair.first->PeekAtNextEventForBroadcasterWithType( &m_broadcaster, event_type)) continue; pair.first->AddEvent(event_sp); - if (m_shadow_listener) - m_shadow_listener->AddEvent(event_sp); } } } @@ -263,6 +318,15 @@ void Broadcaster::BroadcasterImpl::BroadcastEventIfUnique( PrivateBroadcastEvent(event_sp, true); } +void Broadcaster::BroadcasterImpl::SetPrimaryListener(lldb::ListenerSP + listener_sp) { + // This might have already been added as a normal listener, make sure we + // don't hold two copies. + RemoveListener(listener_sp.get(), UINT32_MAX); + m_primary_listener_sp = listener_sp; + +} + bool Broadcaster::BroadcasterImpl::HijackBroadcaster( const lldb::ListenerSP &listener_sp, uint32_t event_mask) { std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); diff --git a/contrib/llvm-project/lldb/source/Utility/Checksum.cpp b/contrib/llvm-project/lldb/source/Utility/Checksum.cpp new file mode 100644 index 000000000000..8943b4e12852 --- /dev/null +++ b/contrib/llvm-project/lldb/source/Utility/Checksum.cpp @@ -0,0 +1,44 @@ +//===-- Checksum.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/Checksum.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" + +using namespace lldb_private; + +Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); } + +Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); } + +Checksum &Checksum::operator=(const Checksum &checksum) { + SetMD5(checksum.m_checksum); + return *this; +} + +void Checksum::SetMD5(llvm::MD5::MD5Result md5) { + const constexpr size_t md5_length = 16; + std::uninitialized_copy_n(md5.begin(), md5_length, m_checksum.begin()); +} + +Checksum::operator bool() const { return !llvm::equal(m_checksum, g_sentinel); } + +bool Checksum::operator==(const Checksum &checksum) const { + return llvm::equal(m_checksum, checksum.m_checksum); +} + +bool Checksum::operator!=(const Checksum &checksum) const { + return !(*this == checksum); +} + +std::string Checksum::digest() const { + return std::string(m_checksum.digest()); +} + +llvm::MD5::MD5Result Checksum::g_sentinel = { + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; diff --git a/contrib/llvm-project/lldb/source/Utility/CompletionRequest.cpp b/contrib/llvm-project/lldb/source/Utility/CompletionRequest.cpp index 8f9dbb79d37b..e12609ca75e7 100644 --- a/contrib/llvm-project/lldb/source/Utility/CompletionRequest.cpp +++ b/contrib/llvm-project/lldb/source/Utility/CompletionRequest.cpp @@ -36,8 +36,8 @@ CompletionRequest::CompletionRequest(llvm::StringRef command_line, // The cursor is after a space but the space is not part of the argument. // Let's add an empty fake argument to the end to make sure the completion // code. Note: The space could be part of the last argument when it's quoted. - if (partial_command.endswith(" ") && - !GetCursorArgumentPrefix().endswith(" ")) + if (partial_command.ends_with(" ") && + !GetCursorArgumentPrefix().ends_with(" ")) AppendEmptyArgument(); } diff --git a/contrib/llvm-project/lldb/source/Utility/Diagnostics.cpp b/contrib/llvm-project/lldb/source/Utility/Diagnostics.cpp index 1632ae0f9dfd..b2a08165dd6c 100644 --- a/contrib/llvm-project/lldb/source/Utility/Diagnostics.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Diagnostics.cpp @@ -52,10 +52,8 @@ Diagnostics::CallbackID Diagnostics::AddCallback(Callback callback) { void Diagnostics::RemoveCallback(CallbackID id) { std::lock_guard<std::mutex> guard(m_callbacks_mutex); - m_callbacks.erase( - std::remove_if(m_callbacks.begin(), m_callbacks.end(), - [id](const CallbackEntry &e) { return e.id == id; }), - m_callbacks.end()); + llvm::erase_if(m_callbacks, + [id](const CallbackEntry &e) { return e.id == id; }); } bool Diagnostics::Dump(raw_ostream &stream) { diff --git a/contrib/llvm-project/lldb/source/Utility/Event.cpp b/contrib/llvm-project/lldb/source/Utility/Event.cpp index fcc367f43f93..cac118182c75 100644 --- a/contrib/llvm-project/lldb/source/Utility/Event.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Event.cpp @@ -11,6 +11,7 @@ #include "lldb/Utility/Broadcaster.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Endian.h" +#include "lldb/Utility/Listener.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/StreamString.h" #include "lldb/lldb-enumerations.h" @@ -80,8 +81,16 @@ void Event::Dump(Stream *s) const { } void Event::DoOnRemoval() { + std::lock_guard<std::mutex> guard(m_listeners_mutex); + if (m_data_sp) m_data_sp->DoOnRemoval(this); + // Now that the event has been handled by the primary event Listener, forward + // it to the other Listeners. + EventSP me_sp = shared_from_this(); + for (auto listener_sp : m_pending_listeners) + listener_sp->AddEvent(me_sp); + m_pending_listeners.clear(); } #pragma mark - diff --git a/contrib/llvm-project/lldb/source/Utility/FileSpec.cpp b/contrib/llvm-project/lldb/source/Utility/FileSpec.cpp index eb34ef97cea0..5387be9a681f 100644 --- a/contrib/llvm-project/lldb/source/Utility/FileSpec.cpp +++ b/contrib/llvm-project/lldb/source/Utility/FileSpec.cpp @@ -68,8 +68,9 @@ void Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::Style style) { FileSpec::FileSpec() : m_style(GetNativeStyle()) {} // Default constructor that can take an optional full path to a file on disk. -FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) { - SetFile(path, style); +FileSpec::FileSpec(llvm::StringRef path, Style style, const Checksum &checksum) + : m_checksum(checksum), m_style(style) { + SetFile(path, style, checksum); } FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple) @@ -171,9 +172,11 @@ void FileSpec::SetFile(llvm::StringRef pathname) { SetFile(pathname, m_style); } // Update the contents of this object with a new path. The path will be split // up into a directory and filename and stored as uniqued string values for // quick comparison and efficient memory usage. -void FileSpec::SetFile(llvm::StringRef pathname, Style style) { +void FileSpec::SetFile(llvm::StringRef pathname, Style style, + const Checksum &checksum) { Clear(); m_style = (style == Style::native) ? GetNativeStyle() : style; + m_checksum = checksum; if (pathname.empty()) return; @@ -308,9 +311,9 @@ bool FileSpec::Match(const FileSpec &pattern, const FileSpec &file) { std::optional<FileSpec::Style> FileSpec::GuessPathStyle(llvm::StringRef absolute_path) { - if (absolute_path.startswith("/")) + if (absolute_path.starts_with("/")) return Style::posix; - if (absolute_path.startswith(R"(\\)")) + if (absolute_path.starts_with(R"(\\)")) return Style::windows; if (absolute_path.size() >= 3 && llvm::isAlpha(absolute_path[0]) && (absolute_path.substr(1, 2) == R"(:\)" || diff --git a/contrib/llvm-project/lldb/source/Utility/FileSpecList.cpp b/contrib/llvm-project/lldb/source/Utility/FileSpecList.cpp index e5e0ac3e5981..e3d8ea650c75 100644 --- a/contrib/llvm-project/lldb/source/Utility/FileSpecList.cpp +++ b/contrib/llvm-project/lldb/source/Utility/FileSpecList.cpp @@ -117,7 +117,7 @@ size_t FileSpecList::FindCompatibleIndex(size_t start_idx, auto is_suffix = [](llvm::StringRef a, llvm::StringRef b, bool case_sensitive) -> bool { if (case_sensitive ? a.consume_back(b) : a.consume_back_insensitive(b)) - return a.empty() || a.endswith("/"); + return a.empty() || a.ends_with("/"); return false; }; const bool case_sensitive = @@ -140,12 +140,6 @@ const FileSpec &FileSpecList::GetFileSpecAtIndex(size_t idx) const { return g_empty_file_spec; } -const FileSpec *FileSpecList::GetFileSpecPointerAtIndex(size_t idx) const { - if (idx < m_files.size()) - return &m_files[idx]; - return nullptr; -} - // Return the size in bytes that this object takes in memory. This returns the // size in bytes of this object's member variables and any FileSpec objects its // member variables contain, the result doesn't not include the string values @@ -162,9 +156,3 @@ size_t FileSpecList::MemorySize() const { // Return the number of files in the file spec list. size_t FileSpecList::GetSize() const { return m_files.size(); } - -size_t FileSpecList::GetFilesMatchingPartialPath(const char *path, - bool dir_okay, - FileSpecList &matches) { - return 0; -} diff --git a/contrib/llvm-project/lldb/source/Utility/Listener.cpp b/contrib/llvm-project/lldb/source/Utility/Listener.cpp index 48ea5fca899e..6a74c530ad25 100644 --- a/contrib/llvm-project/lldb/source/Utility/Listener.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Listener.cpp @@ -231,8 +231,7 @@ bool Listener::FindNextEventInternal( // to return it so it should be okay to get the next event off the queue // here - and it might be useful to do that in the "DoOnRemoval". lock.unlock(); - if (!m_is_shadow) - event_sp->DoOnRemoval(); + event_sp->DoOnRemoval(); } return true; } diff --git a/contrib/llvm-project/lldb/source/Utility/Log.cpp b/contrib/llvm-project/lldb/source/Utility/Log.cpp index 75912683e233..3a45a0285d3e 100644 --- a/contrib/llvm-project/lldb/source/Utility/Log.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Log.cpp @@ -210,7 +210,7 @@ void Log::Warning(const char *format, ...) { void Log::Register(llvm::StringRef name, Channel &channel) { auto iter = g_channel_map->try_emplace(name, channel); assert(iter.second == true); - (void)iter; + UNUSED_IF_ASSERT_DISABLED(iter); } void Log::Unregister(llvm::StringRef name) { diff --git a/contrib/llvm-project/lldb/source/Utility/NameMatches.cpp b/contrib/llvm-project/lldb/source/Utility/NameMatches.cpp index 1c8cd6a0ca31..f002b86f163b 100644 --- a/contrib/llvm-project/lldb/source/Utility/NameMatches.cpp +++ b/contrib/llvm-project/lldb/source/Utility/NameMatches.cpp @@ -22,9 +22,9 @@ bool lldb_private::NameMatches(llvm::StringRef name, NameMatch match_type, case NameMatch::Contains: return name.contains(match); case NameMatch::StartsWith: - return name.startswith(match); + return name.starts_with(match); case NameMatch::EndsWith: - return name.endswith(match); + return name.ends_with(match); case NameMatch::RegularExpression: { RegularExpression regex(match); return regex.Execute(name); diff --git a/contrib/llvm-project/lldb/source/Utility/Scalar.cpp b/contrib/llvm-project/lldb/source/Utility/Scalar.cpp index 791c0fb74352..5ad68065bce1 100644 --- a/contrib/llvm-project/lldb/source/Utility/Scalar.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Scalar.cpp @@ -153,20 +153,20 @@ bool Scalar::IsZero() const { return false; } -void Scalar::GetValue(Stream *s, bool show_type) const { +void Scalar::GetValue(Stream &s, bool show_type) const { if (show_type) - s->Printf("(%s) ", GetTypeAsCString()); + s.Printf("(%s) ", GetTypeAsCString()); switch (m_type) { case e_void: break; case e_int: - s->PutCString(llvm::toString(m_integer, 10)); + s.PutCString(llvm::toString(m_integer, 10)); break; case e_float: llvm::SmallString<24> string; m_float.toString(string); - s->PutCString(string); + s.PutCString(string); break; } } @@ -894,6 +894,6 @@ bool Scalar::SetBit(uint32_t bit) { llvm::raw_ostream &lldb_private::operator<<(llvm::raw_ostream &os, const Scalar &scalar) { StreamString s; - scalar.GetValue(&s, /*show_type*/ true); + scalar.GetValue(s, /*show_type*/ true); return os << s.GetString(); } diff --git a/contrib/llvm-project/lldb/source/Utility/Status.cpp b/contrib/llvm-project/lldb/source/Utility/Status.cpp index 4498961d83e7..3bd00bb20da2 100644 --- a/contrib/llvm-project/lldb/source/Utility/Status.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Status.cpp @@ -180,14 +180,6 @@ ErrorType Status::GetType() const { return m_type; } // otherwise non-success result. bool Status::Fail() const { return m_code != 0; } -// Set accessor for the error value to "err" and the type to -// "eErrorTypeMachKernel" -void Status::SetMachError(uint32_t err) { - m_code = err; - m_type = eErrorTypeMachKernel; - m_string.clear(); -} - void Status::SetExpressionError(lldb::ExpressionResults result, const char *mssg) { m_code = result; diff --git a/contrib/llvm-project/lldb/source/Utility/Stream.cpp b/contrib/llvm-project/lldb/source/Utility/Stream.cpp index af28a49a1f0c..62e061e9d09c 100644 --- a/contrib/llvm-project/lldb/source/Utility/Stream.cpp +++ b/contrib/llvm-project/lldb/source/Utility/Stream.cpp @@ -8,11 +8,13 @@ #include "lldb/Utility/Stream.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/Endian.h" #include "lldb/Utility/VASPrintf.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Format.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/Regex.h" #include <string> @@ -70,6 +72,34 @@ size_t Stream::PutCString(llvm::StringRef str) { return bytes_written; } +void Stream::PutCStringColorHighlighted(llvm::StringRef text, + llvm::StringRef pattern, + llvm::StringRef prefix, + llvm::StringRef suffix) { + // Only apply color formatting when a pattern is present and both prefix and + // suffix are specified. In the absence of these conditions, output the text + // without color formatting. + if (pattern.empty() || (prefix.empty() && suffix.empty())) { + PutCString(text); + return; + } + + llvm::Regex reg_pattern(pattern); + llvm::SmallVector<llvm::StringRef, 1> matches; + llvm::StringRef remaining = text; + std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes( + prefix.str() + "%.*s" + suffix.str()); + while (reg_pattern.match(remaining, &matches)) { + llvm::StringRef match = matches[0]; + size_t match_start_pos = match.data() - remaining.data(); + PutCString(remaining.take_front(match_start_pos)); + Printf(format_str.c_str(), match.size(), match.data()); + remaining = remaining.drop_front(match_start_pos + match.size()); + } + if (remaining.size()) + PutCString(remaining); +} + // Print a double quoted NULL terminated C string to the stream using the // printf format in "format". void Stream::QuotedCString(const char *cstr, const char *format) { diff --git a/contrib/llvm-project/lldb/source/Utility/StringExtractor.cpp b/contrib/llvm-project/lldb/source/Utility/StringExtractor.cpp index c7e4ac794284..579faa3da42f 100644 --- a/contrib/llvm-project/lldb/source/Utility/StringExtractor.cpp +++ b/contrib/llvm-project/lldb/source/Utility/StringExtractor.cpp @@ -254,7 +254,7 @@ uint64_t StringExtractor::GetHexMaxU64(bool little_endian, bool StringExtractor::ConsumeFront(const llvm::StringRef &str) { llvm::StringRef S = GetStringRef(); - if (!S.startswith(str)) + if (!S.starts_with(str)) return false; else m_index += str.size(); diff --git a/contrib/llvm-project/lldb/source/Utility/StructuredData.cpp b/contrib/llvm-project/lldb/source/Utility/StructuredData.cpp index c0ed1e5a5c73..7686d052c599 100644 --- a/contrib/llvm-project/lldb/source/Utility/StructuredData.cpp +++ b/contrib/llvm-project/lldb/source/Utility/StructuredData.cpp @@ -162,8 +162,18 @@ void StructuredData::String::Serialize(json::OStream &s) const { void StructuredData::Dictionary::Serialize(json::OStream &s) const { s.objectBegin(); - for (const auto &pair : m_dict) { - s.attributeBegin(pair.first.GetStringRef()); + + // To ensure the output format is always stable, we sort the dictionary by key + // first. + using Entry = std::pair<llvm::StringRef, ObjectSP>; + std::vector<Entry> sorted_entries; + for (const auto &pair : m_dict) + sorted_entries.push_back({pair.first(), pair.second}); + + llvm::sort(sorted_entries); + + for (const auto &pair : sorted_entries) { + s.attributeBegin(pair.first); pair.second->Serialize(s); s.attributeEnd(); } @@ -228,9 +238,20 @@ void StructuredData::Array::GetDescription(lldb_private::Stream &s) const { void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const { size_t indentation_level = s.GetIndentLevel(); - for (const auto &pair : m_dict) { + + // To ensure the output format is always stable, we sort the dictionary by key + // first. + using Entry = std::pair<llvm::StringRef, ObjectSP>; + std::vector<Entry> sorted_entries; + for (const auto &pair : m_dict) + sorted_entries.push_back({pair.first(), pair.second}); + + llvm::sort(sorted_entries); + + for (auto iter = sorted_entries.begin(); iter != sorted_entries.end(); + iter++) { // Sanitize. - if (pair.first.IsNull() || pair.first.IsEmpty() || !pair.second) + if (iter->first.empty() || !iter->second) continue; // Reset original indentation level. @@ -238,11 +259,11 @@ void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const { s.Indent(); // Print key. - s.Printf("%s:", pair.first.AsCString()); + s.Format("{0}:", iter->first); // Return to new line and increase indentation if value is record type. // Otherwise add spacing. - bool should_indent = IsRecordType(pair.second); + bool should_indent = IsRecordType(iter->second); if (should_indent) { s.EOL(); s.IndentMore(); @@ -251,8 +272,8 @@ void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const { } // Print value and new line if now last pair. - pair.second->GetDescription(s); - if (pair != *(--m_dict.end())) + iter->second->GetDescription(s); + if (std::next(iter) != sorted_entries.end()) s.EOL(); // Reset indentation level if it was incremented previously. diff --git a/contrib/llvm-project/lldb/source/Utility/TildeExpressionResolver.cpp b/contrib/llvm-project/lldb/source/Utility/TildeExpressionResolver.cpp index 6311ae062f1f..2e334b2aae54 100644 --- a/contrib/llvm-project/lldb/source/Utility/TildeExpressionResolver.cpp +++ b/contrib/llvm-project/lldb/source/Utility/TildeExpressionResolver.cpp @@ -60,7 +60,7 @@ bool StandardTildeExpressionResolver::ResolvePartial(StringRef Expr, while ((user_entry = getpwent()) != nullptr) { StringRef ThisName(user_entry->pw_name); - if (!ThisName.startswith(Expr)) + if (!ThisName.starts_with(Expr)) continue; Buffer.resize(1); @@ -75,7 +75,7 @@ bool StandardTildeExpressionResolver::ResolvePartial(StringRef Expr, bool TildeExpressionResolver::ResolveFullPath( StringRef Expr, llvm::SmallVectorImpl<char> &Output) { - if (!Expr.startswith("~")) { + if (!Expr.starts_with("~")) { Output.assign(Expr.begin(), Expr.end()); return false; } diff --git a/contrib/llvm-project/lldb/source/Utility/UuidCompatibility.h b/contrib/llvm-project/lldb/source/Utility/UuidCompatibility.h deleted file mode 100644 index 40ebc1de24e4..000000000000 --- a/contrib/llvm-project/lldb/source/Utility/UuidCompatibility.h +++ /dev/null @@ -1,25 +0,0 @@ -//===-- UuidCompatibility.h -------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Include this header if your system does not have a definition of uuid_t - -#ifndef utility_UUID_COMPATIBILITY_H -#define utility_UUID_COMPATIBILITY_H - -// uuid_t is guaranteed to always be a 16-byte array -typedef unsigned char uuid_t[16]; - -// Return 1 if uuid is null, that is, all zeroes. -inline __attribute__((always_inline)) int uuid_is_null(uuid_t uuid) { - for (int i = 0; i < 16; i++) - if (uuid[i]) - return 0; - return 1; -} - -#endif // utility_UUID_COMPATIBILITY_H diff --git a/contrib/llvm-project/lldb/source/Utility/XcodeSDK.cpp b/contrib/llvm-project/lldb/source/Utility/XcodeSDK.cpp index 84f3ccbd01e2..d744336373b2 100644 --- a/contrib/llvm-project/lldb/source/Utility/XcodeSDK.cpp +++ b/contrib/llvm-project/lldb/source/Utility/XcodeSDK.cpp @@ -56,7 +56,7 @@ XcodeSDK::XcodeSDK(XcodeSDK::Info info) : m_name(GetName(info.type).str()) { XcodeSDK &XcodeSDK::operator=(const XcodeSDK &other) = default; -bool XcodeSDK::operator==(const XcodeSDK &other) { +bool XcodeSDK::operator==(const XcodeSDK &other) const { return m_name == other.m_name; } @@ -152,7 +152,7 @@ void XcodeSDK::Merge(const XcodeSDK &other) { *this = other; else { // The Internal flag always wins. - if (llvm::StringRef(m_name).endswith(".sdk")) + if (llvm::StringRef(m_name).ends_with(".sdk")) if (!l.internal && r.internal) m_name = m_name.substr(0, m_name.size() - 3) + std::string("Internal.sdk"); @@ -291,7 +291,7 @@ std::string XcodeSDK::FindXcodeContentsDirectoryInPath(llvm::StringRef path) { // .app. If the next component is Contents then we've found the Contents // directory. for (auto it = begin; it != end; ++it) { - if (it->endswith(".app")) { + if (it->ends_with(".app")) { auto next = it; if (++next != end && *next == "Contents") { llvm::SmallString<128> buffer; |
