diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:52 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:52 +0000 |
commit | 5f29bb8a675e8f96452b632e7129113f7dec850e (patch) | |
tree | 3d3f2a0d3ad10872a4dcaba8ec8d1d20c87ab147 /source/Utility | |
parent | 88c643b6fec27eec436c8d138fee6346e92337d6 (diff) |
Notes
Diffstat (limited to 'source/Utility')
57 files changed, 1509 insertions, 994 deletions
diff --git a/source/Utility/ARM64_DWARF_Registers.h b/source/Utility/ARM64_DWARF_Registers.h index ce548a2aee80..64f69d643565 100644 --- a/source/Utility/ARM64_DWARF_Registers.h +++ b/source/Utility/ARM64_DWARF_Registers.h @@ -1,9 +1,8 @@ //===-- ARM64_DWARF_Registers.h ---------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/ARM64_ehframe_Registers.h b/source/Utility/ARM64_ehframe_Registers.h index 7f49314b3539..9b5cd931bf28 100644 --- a/source/Utility/ARM64_ehframe_Registers.h +++ b/source/Utility/ARM64_ehframe_Registers.h @@ -1,10 +1,9 @@ //===-- ARM64_ehframe_Registers.h -------------------------------------*- C++ //-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/ARM_DWARF_Registers.h b/source/Utility/ARM_DWARF_Registers.h index ab91d8c99aa3..e33210dfbfbd 100644 --- a/source/Utility/ARM_DWARF_Registers.h +++ b/source/Utility/ARM_DWARF_Registers.h @@ -1,9 +1,8 @@ //===-- ARM_DWARF_Registers.h -----------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/ARM_ehframe_Registers.h b/source/Utility/ARM_ehframe_Registers.h index 2a4242314d52..1816b1d97497 100644 --- a/source/Utility/ARM_ehframe_Registers.h +++ b/source/Utility/ARM_ehframe_Registers.h @@ -1,10 +1,9 @@ //===-- ARM_ehframe_Registers.h -------------------------------------*- C++ //-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/ArchSpec.cpp b/source/Utility/ArchSpec.cpp index 752fb182d79a..81b87fff88d4 100644 --- a/source/Utility/ArchSpec.cpp +++ b/source/Utility/ArchSpec.cpp @@ -1,9 +1,8 @@ //===-- ArchSpec.cpp --------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -215,13 +214,7 @@ static const CoreDefinition g_core_definitions[] = { ArchSpec::eCore_uknownMach32, "unknown-mach-32"}, {eByteOrderLittle, 8, 4, 4, llvm::Triple::UnknownArch, ArchSpec::eCore_uknownMach64, "unknown-mach-64"}, - - {eByteOrderBig, 4, 1, 1, llvm::Triple::kalimba, ArchSpec::eCore_kalimba3, - "kalimba3"}, - {eByteOrderLittle, 4, 1, 1, llvm::Triple::kalimba, ArchSpec::eCore_kalimba4, - "kalimba4"}, - {eByteOrderLittle, 4, 1, 1, llvm::Triple::kalimba, ArchSpec::eCore_kalimba5, - "kalimba5"}}; +}; // Ensure that we have an entry in the g_core_definitions for each core. If you // comment out an entry above, you will need to comment out the corresponding @@ -453,12 +446,6 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = { ArchSpec::eMIPSSubType_mips64r6el, 0xFFFFFFFFu, 0xFFFFFFFFu}, // mips64r6el {ArchSpec::eCore_hexagon_generic, llvm::ELF::EM_HEXAGON, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu}, // HEXAGON - {ArchSpec::eCore_kalimba3, llvm::ELF::EM_CSR_KALIMBA, - llvm::Triple::KalimbaSubArch_v3, 0xFFFFFFFFu, 0xFFFFFFFFu}, // KALIMBA - {ArchSpec::eCore_kalimba4, llvm::ELF::EM_CSR_KALIMBA, - llvm::Triple::KalimbaSubArch_v4, 0xFFFFFFFFu, 0xFFFFFFFFu}, // KALIMBA - {ArchSpec::eCore_kalimba5, llvm::ELF::EM_CSR_KALIMBA, - llvm::Triple::KalimbaSubArch_v5, 0xFFFFFFFFu, 0xFFFFFFFFu} // KALIMBA }; static const ArchDefinition g_elf_arch_def = { @@ -608,11 +595,7 @@ const char *ArchSpec::GetArchitectureName() const { return "unknown"; } -bool ArchSpec::IsMIPS() const { - const llvm::Triple::ArchType machine = GetMachine(); - return machine == llvm::Triple::mips || machine == llvm::Triple::mipsel || - machine == llvm::Triple::mips64 || machine == llvm::Triple::mips64el; -} +bool ArchSpec::IsMIPS() const { return GetTriple().isMIPS(); } std::string ArchSpec::GetTargetABI() const { @@ -652,10 +635,8 @@ void ArchSpec::SetFlags(std::string elf_abi) { std::string ArchSpec::GetClangTargetCPU() const { std::string cpu; - const llvm::Triple::ArchType machine = GetMachine(); - if (machine == llvm::Triple::mips || machine == llvm::Triple::mipsel || - machine == llvm::Triple::mips64 || machine == llvm::Triple::mips64el) { + if (IsMIPS()) { switch (m_core) { case ArchSpec::eCore_mips32: case ArchSpec::eCore_mips32el: @@ -729,30 +710,10 @@ uint32_t ArchSpec::GetMachOCPUSubType() const { } uint32_t ArchSpec::GetDataByteSize() const { - switch (m_core) { - case eCore_kalimba3: - return 4; - case eCore_kalimba4: - return 1; - case eCore_kalimba5: - return 4; - default: - return 1; - } return 1; } uint32_t ArchSpec::GetCodeByteSize() const { - switch (m_core) { - case eCore_kalimba3: - return 4; - case eCore_kalimba4: - return 1; - case eCore_kalimba5: - return 1; - default: - return 1; - } return 1; } @@ -764,7 +725,7 @@ llvm::Triple::ArchType ArchSpec::GetMachine() const { return llvm::Triple::UnknownArch; } -const ConstString &ArchSpec::GetDistributionId() const { +ConstString ArchSpec::GetDistributionId() const { return m_distribution_id; } @@ -890,10 +851,9 @@ bool ArchSpec::ContainsOnlyArch(const llvm::Triple &normalized_triple) { } void ArchSpec::MergeFrom(const ArchSpec &other) { - if (TripleVendorIsUnspecifiedUnknown() && - !other.TripleVendorIsUnspecifiedUnknown()) + if (!TripleVendorWasSpecified() && other.TripleVendorWasSpecified()) GetTriple().setVendor(other.GetTriple().getVendor()); - if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown()) + if (!TripleOSWasSpecified() && other.TripleOSWasSpecified()) GetTriple().setOS(other.GetTriple().getOS()); if (GetTriple().getArch() == llvm::Triple::UnknownArch) { GetTriple().setArch(other.GetTriple().getArch()); @@ -904,10 +864,9 @@ void ArchSpec::MergeFrom(const ArchSpec &other) { if (other.GetCore() != eCore_uknownMach64) UpdateCore(); } - if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment && - !TripleVendorWasSpecified()) { - if (other.TripleVendorWasSpecified()) - GetTriple().setEnvironment(other.GetTriple().getEnvironment()); + if (!TripleEnvironmentWasSpecified() && + other.TripleEnvironmentWasSpecified()) { + GetTriple().setEnvironment(other.GetTriple().getEnvironment()); } // If this and other are both arm ArchSpecs and this ArchSpec is a generic // "some kind of arm" spec but the other ArchSpec is a specific arm core, @@ -945,13 +904,13 @@ bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu, m_triple.setVendor(llvm::Triple::Apple); // Don't set the OS. It could be simulator, macosx, ios, watchos, - // tvos, bridgeos. We could get close with the cpu type - but we - // can't get it right all of the time. Better to leave this unset - // so other sections of code will set it when they have more - // information. NB: don't call m_triple.setOS (llvm::Triple::UnknownOS). - // That sets the OSName to "unknown" and the - // ArchSpec::TripleVendorWasSpecified() method says that any OSName - // setting means it was specified. + // tvos, bridgeos. We could get close with the cpu type - but we + // can't get it right all of the time. Better to leave this unset + // so other sections of code will set it when they have more + // information. NB: don't call m_triple.setOS + // (llvm::Triple::UnknownOS). That sets the OSName to "unknown" and + // the ArchSpec::TripleVendorWasSpecified() method says that any + // OSName setting means it was specified. } else if (arch_type == eArchTypeELF) { switch (os) { case llvm::ELF::ELFOSABI_AIX: diff --git a/source/Utility/Args.cpp b/source/Utility/Args.cpp index 3b5cf1715fb3..77b0d43254a1 100644 --- a/source/Utility/Args.cpp +++ b/source/Utility/Args.cpp @@ -1,9 +1,8 @@ //===-- Args.cpp ------------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -96,7 +95,7 @@ ParseSingleArgument(llvm::StringRef command) { bool arg_complete = false; do { // Skip over over regular characters and append them. - size_t regular = command.find_first_of(" \t\"'`\\"); + size_t regular = command.find_first_of(" \t\r\"'`\\"); arg += command.substr(0, regular); command = command.substr(regular); @@ -124,6 +123,7 @@ ParseSingleArgument(llvm::StringRef command) { case ' ': case '\t': + case '\r': // We are not inside any quotes, we just found a space after an argument. // We are done. arg_complete = true; @@ -166,9 +166,7 @@ Args::ArgEntry::ArgEntry(llvm::StringRef str, char quote) : quote(quote) { ref = llvm::StringRef(c_str(), size); } -//---------------------------------------------------------------------- // Args constructor -//---------------------------------------------------------------------- Args::Args(llvm::StringRef command) { SetCommandString(command); } Args::Args(const Args &rhs) { *this = rhs; } @@ -191,9 +189,7 @@ Args &Args::operator=(const Args &rhs) { return *this; } -//---------------------------------------------------------------------- // Destructor -//---------------------------------------------------------------------- Args::~Args() {} void Args::Dump(Stream &s, const char *label_name) const { @@ -546,7 +542,7 @@ void Args::EncodeEscapeSequences(const char *src, std::string &dst) { p += i - 1; unsigned long octal_value = ::strtoul(oct_str, nullptr, 8); if (octal_value <= UINT8_MAX) { - dst.append(1, (char)octal_value); + dst.append(1, static_cast<char>(octal_value)); } } break; @@ -566,7 +562,7 @@ void Args::EncodeEscapeSequences(const char *src, std::string &dst) { unsigned long hex_value = strtoul(hex_str, nullptr, 16); if (hex_value <= UINT8_MAX) - dst.append(1, (char)hex_value); + dst.append(1, static_cast<char>(hex_value)); } else { dst.append(1, 'x'); } @@ -641,14 +637,15 @@ std::string Args::EscapeLLDBCommandArgument(const std::string &arg, case '\0': chars_to_escape = " \t\\'\"`"; break; - case '\'': - chars_to_escape = ""; - break; case '"': chars_to_escape = "$\"`\\"; break; + case '`': + case '\'': + return arg; default: assert(false && "Unhandled quote character"); + return arg; } std::string res; diff --git a/source/Utility/Baton.cpp b/source/Utility/Baton.cpp index 786be2fe9981..84e295e24686 100644 --- a/source/Utility/Baton.cpp +++ b/source/Utility/Baton.cpp @@ -1,9 +1,8 @@ //===-- Baton.cpp -----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/Broadcaster.cpp b/source/Utility/Broadcaster.cpp index 5b9b99801b22..597888cfa0e2 100644 --- a/source/Utility/Broadcaster.cpp +++ b/source/Utility/Broadcaster.cpp @@ -1,9 +1,8 @@ //===-- Broadcaster.cpp -----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -19,6 +18,7 @@ #include <algorithm> #include <memory> #include <type_traits> +#include <utility> #include <assert.h> #include <stddef.h> @@ -28,11 +28,10 @@ using namespace lldb_private; Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name) : m_broadcaster_sp(std::make_shared<BroadcasterImpl>(*this)), - m_manager_sp(manager_sp), m_broadcaster_name(name) { + m_manager_sp(std::move(manager_sp)), m_broadcaster_name(name) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("%p Broadcaster::Broadcaster(\"%s\")", - static_cast<void *>(this), GetBroadcasterName().AsCString()); + LLDB_LOG(log, "{0} Broadcaster::Broadcaster(\"{1}\")", + static_cast<void *>(this), GetBroadcasterName().AsCString()); } Broadcaster::BroadcasterImpl::BroadcasterImpl(Broadcaster &broadcaster) @@ -41,9 +40,8 @@ Broadcaster::BroadcasterImpl::BroadcasterImpl(Broadcaster &broadcaster) Broadcaster::~Broadcaster() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("%p Broadcaster::~Broadcaster(\"%s\")", - static_cast<void *>(this), m_broadcaster_name.AsCString()); + LLDB_LOG(log, "{0} Broadcaster::~Broadcaster(\"{1}\")", + static_cast<void *>(this), GetBroadcasterName().AsCString()); Clear(); } @@ -213,8 +211,7 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp, hijacking_listener_sp.reset(); } - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EVENTS)); - if (log) { + if (Log *log = lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EVENTS)) { StreamString event_description; event_sp->Dump(&event_description); log->Printf("%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, " @@ -225,18 +222,16 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp, } if (hijacking_listener_sp) { - if (unique && - hijacking_listener_sp->PeekAtNextEventForBroadcasterWithType( - &m_broadcaster, event_type)) + if (unique && hijacking_listener_sp->PeekAtNextEventForBroadcasterWithType( + &m_broadcaster, event_type)) return; hijacking_listener_sp->AddEvent(event_sp); } else { for (auto &pair : GetListeners()) { if (!(pair.second & event_type)) continue; - if (unique && - pair.first->PeekAtNextEventForBroadcasterWithType(&m_broadcaster, - event_type)) + if (unique && pair.first->PeekAtNextEventForBroadcasterWithType( + &m_broadcaster, event_type)) continue; pair.first->AddEvent(event_sp); @@ -267,11 +262,11 @@ bool Broadcaster::BroadcasterImpl::HijackBroadcaster( std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EVENTS)); - if (log) - log->Printf( - "%p Broadcaster(\"%s\")::HijackBroadcaster (listener(\"%s\")=%p)", - static_cast<void *>(this), GetBroadcasterName(), - listener_sp->m_name.c_str(), static_cast<void *>(listener_sp.get())); + LLDB_LOG( + log, + "{0} Broadcaster(\"{1}\")::HijackBroadcaster (listener(\"{2}\")={3})", + static_cast<void *>(this), GetBroadcasterName(), + listener_sp->m_name.c_str(), static_cast<void *>(listener_sp.get())); m_hijacking_listeners.push_back(listener_sp); m_hijacking_masks.push_back(event_mask); return true; @@ -288,24 +283,22 @@ bool Broadcaster::BroadcasterImpl::IsHijackedForEvent(uint32_t event_mask) { const char *Broadcaster::BroadcasterImpl::GetHijackingListenerName() { if (m_hijacking_listeners.size()) { return m_hijacking_listeners.back()->GetName(); - } else { - return nullptr; } + return nullptr; } void Broadcaster::BroadcasterImpl::RestoreBroadcaster() { std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); if (!m_hijacking_listeners.empty()) { + ListenerSP listener_sp = m_hijacking_listeners.back(); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EVENTS)); - if (log) { - ListenerSP listener_sp = m_hijacking_listeners.back(); - log->Printf("%p Broadcaster(\"%s\")::RestoreBroadcaster (about to pop " - "listener(\"%s\")=%p)", - static_cast<void *>(this), GetBroadcasterName(), - listener_sp->m_name.c_str(), - static_cast<void *>(listener_sp.get())); - } + LLDB_LOG(log, + "{0} Broadcaster(\"{1}\")::RestoreBroadcaster (about to pop " + "listener(\"{2}\")={3})", + static_cast<void *>(this), GetBroadcasterName(), + listener_sp->m_name.c_str(), + static_cast<void *>(listener_sp.get())); m_hijacking_listeners.pop_back(); } if (!m_hijacking_masks.empty()) @@ -317,14 +310,11 @@ ConstString &Broadcaster::GetBroadcasterClass() const { return class_name; } -BroadcastEventSpec::BroadcastEventSpec(const BroadcastEventSpec &rhs) = default; - bool BroadcastEventSpec::operator<(const BroadcastEventSpec &rhs) const { if (GetBroadcasterClass() == rhs.GetBroadcasterClass()) { return GetEventBits() < rhs.GetEventBits(); - } else { - return GetBroadcasterClass() < rhs.GetBroadcasterClass(); } + return GetBroadcasterClass() < rhs.GetBroadcasterClass(); } BroadcastEventSpec &BroadcastEventSpec:: @@ -337,7 +327,7 @@ lldb::BroadcasterManagerSP BroadcasterManager::MakeBroadcasterManager() { } uint32_t BroadcasterManager::RegisterListenerForEvents( - const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec) { + const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec) { std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end(); @@ -362,7 +352,7 @@ uint32_t BroadcasterManager::RegisterListenerForEvents( } bool BroadcasterManager::UnregisterListenerForEvents( - const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec) { + const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec) { std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); bool removed_some = false; @@ -380,17 +370,16 @@ bool BroadcasterManager::UnregisterListenerForEvents( iter = find_if(m_event_map.begin(), end_iter, predicate); if (iter == end_iter) { break; - } else { - uint32_t iter_event_bits = (*iter).first.GetEventBits(); - removed_some = true; - - if (event_bits_to_remove != iter_event_bits) { - uint32_t new_event_bits = iter_event_bits & ~event_bits_to_remove; - to_be_readded.push_back(BroadcastEventSpec( - event_spec.GetBroadcasterClass(), new_event_bits)); - } - m_event_map.erase(iter); } + uint32_t iter_event_bits = (*iter).first.GetEventBits(); + removed_some = true; + + if (event_bits_to_remove != iter_event_bits) { + uint32_t new_event_bits = iter_event_bits & ~event_bits_to_remove; + to_be_readded.push_back( + BroadcastEventSpec(event_spec.GetBroadcasterClass(), new_event_bits)); + } + m_event_map.erase(iter); } // Okay now add back the bits that weren't completely removed: @@ -402,7 +391,7 @@ bool BroadcasterManager::UnregisterListenerForEvents( } ListenerSP BroadcasterManager::GetListenerForEventSpec( - BroadcastEventSpec event_spec) const { + const BroadcastEventSpec &event_spec) const { std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); collection::const_iterator iter, end_iter = m_event_map.end(); @@ -410,8 +399,8 @@ ListenerSP BroadcasterManager::GetListenerForEventSpec( BroadcastEventSpecMatches(event_spec)); if (iter != end_iter) return (*iter).second; - else - return nullptr; + + return nullptr; } void BroadcasterManager::RemoveListener(Listener *listener) { @@ -429,8 +418,8 @@ void BroadcasterManager::RemoveListener(Listener *listener) { iter = find_if(m_event_map.begin(), end_iter, predicate); if (iter == end_iter) break; - else - m_event_map.erase(iter); + + m_event_map.erase(iter); } } @@ -446,8 +435,8 @@ void BroadcasterManager::RemoveListener(const lldb::ListenerSP &listener_sp) { iter = find_if(m_event_map.begin(), end_iter, predicate); if (iter == end_iter) break; - else - m_event_map.erase(iter); + + m_event_map.erase(iter); } } diff --git a/source/Utility/CompletionRequest.cpp b/source/Utility/CompletionRequest.cpp index 096661b7e99f..c62ec4f56ffa 100644 --- a/source/Utility/CompletionRequest.cpp +++ b/source/Utility/CompletionRequest.cpp @@ -1,9 +1,8 @@ //===-- CompletionRequest.cpp -----------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/Connection.cpp b/source/Utility/Connection.cpp index 9f6114f6ed5d..483a0c941be4 100644 --- a/source/Utility/Connection.cpp +++ b/source/Utility/Connection.cpp @@ -1,9 +1,8 @@ //===-- Connection.cpp ------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/ConstString.cpp b/source/Utility/ConstString.cpp index 9b8bea71e2ad..46b7ab259383 100644 --- a/source/Utility/ConstString.cpp +++ b/source/Utility/ConstString.cpp @@ -1,9 +1,8 @@ //===-- ConstString.cpp -----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -144,16 +143,14 @@ public: const char *GetConstTrimmedCStringWithLength(const char *cstr, size_t cstr_len) { if (cstr != nullptr) { - const size_t trimmed_len = std::min<size_t>(strlen(cstr), cstr_len); + const size_t trimmed_len = strnlen(cstr, cstr_len); return GetConstCStringWithLength(cstr, trimmed_len); } return nullptr; } - //------------------------------------------------------------------ // Return the size in bytes that this object and any items in its collection // of uniqued strings + data count values takes in memory. - //------------------------------------------------------------------ size_t MemorySize() const { size_t mem_size = sizeof(Pool); for (const auto &pool : m_string_pools) { @@ -178,7 +175,6 @@ protected: std::array<PoolEntry, 256> m_string_pools; }; -//---------------------------------------------------------------------- // Frameworks and dylibs aren't supposed to have global C++ initializers so we // hide the string pool in a static function so that it will get initialized on // the first call to this static function. @@ -187,7 +183,6 @@ protected: // can't guarantee that some objects won't get destroyed after the global // destructor chain is run, and trying to make sure no destructors touch // ConstStrings is difficult. So we leak the pool instead. -//---------------------------------------------------------------------- static Pool &StringPool() { static llvm::once_flag g_pool_initialization_flag; static Pool *g_string_pool = nullptr; @@ -205,9 +200,9 @@ ConstString::ConstString(const char *cstr, size_t cstr_len) : m_string(StringPool().GetConstCStringWithLength(cstr, cstr_len)) {} ConstString::ConstString(const llvm::StringRef &s) - : m_string(StringPool().GetConstCStringWithLength(s.data(), s.size())) {} + : m_string(StringPool().GetConstCStringWithStringRef(s)) {} -bool ConstString::operator<(const ConstString &rhs) const { +bool ConstString::operator<(ConstString rhs) const { if (m_string == rhs.m_string) return false; @@ -222,7 +217,7 @@ bool ConstString::operator<(const ConstString &rhs) const { return lhs_string_ref.data() == nullptr; } -Stream &lldb_private::operator<<(Stream &s, const ConstString &str) { +Stream &lldb_private::operator<<(Stream &s, ConstString str) { const char *cstr = str.GetCString(); if (cstr != nullptr) s << cstr; @@ -234,7 +229,7 @@ size_t ConstString::GetLength() const { return Pool::GetConstCStringLength(m_string); } -bool ConstString::Equals(const ConstString &lhs, const ConstString &rhs, +bool ConstString::Equals(ConstString lhs, ConstString rhs, const bool case_sensitive) { if (lhs.m_string == rhs.m_string) return true; @@ -251,7 +246,7 @@ bool ConstString::Equals(const ConstString &lhs, const ConstString &rhs, return lhs_string_ref.equals_lower(rhs_string_ref); } -int ConstString::Compare(const ConstString &lhs, const ConstString &rhs, +int ConstString::Compare(ConstString lhs, ConstString rhs, const bool case_sensitive) { // If the iterators are the same, this is the same string const char *lhs_cstr = lhs.m_string; @@ -303,7 +298,7 @@ void ConstString::SetString(const llvm::StringRef &s) { } void ConstString::SetStringWithMangledCounterpart(llvm::StringRef demangled, - const ConstString &mangled) { + ConstString mangled) { m_string = StringPool().GetConstCStringAndSetMangledCounterPart( demangled, mangled.m_string); } diff --git a/source/Utility/DataBufferHeap.cpp b/source/Utility/DataBufferHeap.cpp index 36cac0079ac0..5bff7775f138 100644 --- a/source/Utility/DataBufferHeap.cpp +++ b/source/Utility/DataBufferHeap.cpp @@ -1,9 +1,8 @@ //===-- DataBufferHeap.cpp --------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -12,64 +11,48 @@ using namespace lldb_private; -//---------------------------------------------------------------------- // Default constructor -//---------------------------------------------------------------------- DataBufferHeap::DataBufferHeap() : m_data() {} -//---------------------------------------------------------------------- // Initialize this class with "n" characters and fill the buffer with "ch". -//---------------------------------------------------------------------- DataBufferHeap::DataBufferHeap(lldb::offset_t n, uint8_t ch) : m_data() { if (n < m_data.max_size()) m_data.assign(n, ch); } -//---------------------------------------------------------------------- // Initialize this class with a copy of the "n" bytes from the "bytes" buffer. -//---------------------------------------------------------------------- DataBufferHeap::DataBufferHeap(const void *src, lldb::offset_t src_len) : m_data() { CopyData(src, src_len); } -//---------------------------------------------------------------------- // Virtual destructor since this class inherits from a pure virtual base class. -//---------------------------------------------------------------------- DataBufferHeap::~DataBufferHeap() = default; -//---------------------------------------------------------------------- // Return a pointer to the bytes owned by this object, or nullptr if the object // contains no bytes. -//---------------------------------------------------------------------- uint8_t *DataBufferHeap::GetBytes() { return (m_data.empty() ? nullptr : m_data.data()); } -//---------------------------------------------------------------------- // Return a const pointer to the bytes owned by this object, or nullptr if the // object contains no bytes. -//---------------------------------------------------------------------- const uint8_t *DataBufferHeap::GetBytes() const { return (m_data.empty() ? nullptr : m_data.data()); } -//---------------------------------------------------------------------- // Return the number of bytes this object currently contains. -//---------------------------------------------------------------------- uint64_t DataBufferHeap::GetByteSize() const { return m_data.size(); } -//---------------------------------------------------------------------- // Sets the number of bytes that this object should be able to contain. This // can be used prior to copying data into the buffer. -//---------------------------------------------------------------------- uint64_t DataBufferHeap::SetByteSize(uint64_t new_size) { m_data.resize(new_size); return m_data.size(); } void DataBufferHeap::CopyData(const void *src, uint64_t src_len) { - const uint8_t *src_u8 = (const uint8_t *)src; + const uint8_t *src_u8 = static_cast<const uint8_t *>(src); if (src && src_len > 0) m_data.assign(src_u8, src_u8 + src_len); else @@ -77,8 +60,8 @@ void DataBufferHeap::CopyData(const void *src, uint64_t src_len) { } void DataBufferHeap::AppendData(const void *src, uint64_t src_len) { - m_data.insert(m_data.end(), (const uint8_t *)src, - (const uint8_t *)src + src_len); + m_data.insert(m_data.end(), static_cast<const uint8_t *>(src), + static_cast<const uint8_t *>(src) + src_len); } void DataBufferHeap::Clear() { diff --git a/source/Utility/DataBufferLLVM.cpp b/source/Utility/DataBufferLLVM.cpp index 0ab3fe5afd46..4227e9b39960 100644 --- a/source/Utility/DataBufferLLVM.cpp +++ b/source/Utility/DataBufferLLVM.cpp @@ -1,9 +1,8 @@ //===--- DataBufferLLVM.cpp -------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/DataEncoder.cpp b/source/Utility/DataEncoder.cpp index c26c0fa63ab3..13c505e34e82 100644 --- a/source/Utility/DataEncoder.cpp +++ b/source/Utility/DataEncoder.cpp @@ -1,9 +1,8 @@ //===-- DataEncoder.cpp -----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -25,29 +24,24 @@ using namespace lldb; using namespace lldb_private; using namespace llvm::support::endian; -//---------------------------------------------------------------------- // Default constructor. -//---------------------------------------------------------------------- DataEncoder::DataEncoder() : m_start(nullptr), m_end(nullptr), m_byte_order(endian::InlHostByteOrder()), m_addr_size(sizeof(void *)), m_data_sp() {} -//---------------------------------------------------------------------- // This constructor allows us to use data that is owned by someone else. The // data must stay around as long as this object is valid. -//---------------------------------------------------------------------- DataEncoder::DataEncoder(void *data, uint32_t length, ByteOrder endian, uint8_t addr_size) - : m_start((uint8_t *)data), m_end((uint8_t *)data + length), - m_byte_order(endian), m_addr_size(addr_size), m_data_sp() {} + : m_start(static_cast<uint8_t *>(data)), + m_end(static_cast<uint8_t *>(data) + length), m_byte_order(endian), + m_addr_size(addr_size), m_data_sp() {} -//---------------------------------------------------------------------- // Make a shared pointer reference to the shared data in "data_sp" and set the // endian swapping setting to "swap", and the address size to "addr_size". The // shared data reference will ensure the data lives as long as any DataEncoder // objects exist that have a reference to this data. -//---------------------------------------------------------------------- DataEncoder::DataEncoder(const DataBufferSP &data_sp, ByteOrder endian, uint8_t addr_size) : m_start(nullptr), m_end(nullptr), m_byte_order(endian), @@ -57,10 +51,8 @@ DataEncoder::DataEncoder(const DataBufferSP &data_sp, ByteOrder endian, DataEncoder::~DataEncoder() = default; -//------------------------------------------------------------------ // Clears the object contents back to a default invalid state, and release any // references to shared data that this object may contain. -//------------------------------------------------------------------ void DataEncoder::Clear() { m_start = nullptr; m_end = nullptr; @@ -69,10 +61,8 @@ void DataEncoder::Clear() { m_data_sp.reset(); } -//------------------------------------------------------------------ // If this object contains shared data, this function returns the offset into // that shared data. Else zero is returned. -//------------------------------------------------------------------ size_t DataEncoder::GetSharedDataOffset() const { if (m_start != nullptr) { const DataBuffer *data = m_data_sp.get(); @@ -87,7 +77,6 @@ size_t DataEncoder::GetSharedDataOffset() const { return 0; } -//---------------------------------------------------------------------- // Set the data with which this object will extract from to data starting at // BYTES and set the length of the data to LENGTH bytes long. The data is // externally owned must be around at least as long as this object points to @@ -95,7 +84,6 @@ size_t DataEncoder::GetSharedDataOffset() const { // and can extract from it. If this object refers to any shared data upon // entry, the reference to that data will be released. Is SWAP is set to true, // any data extracted will be endian swapped. -//---------------------------------------------------------------------- uint32_t DataEncoder::SetData(void *bytes, uint32_t length, ByteOrder endian) { m_byte_order = endian; m_data_sp.reset(); @@ -103,13 +91,12 @@ uint32_t DataEncoder::SetData(void *bytes, uint32_t length, ByteOrder endian) { m_start = nullptr; m_end = nullptr; } else { - m_start = (uint8_t *)bytes; + m_start = static_cast<uint8_t *>(bytes); m_end = m_start + length; } return GetByteSize(); } -//---------------------------------------------------------------------- // Assign the data for this object to be a subrange of the shared data in // "data_sp" starting "data_offset" bytes into "data_sp" and ending // "data_length" bytes later. If "data_offset" is not a valid offset into @@ -121,7 +108,6 @@ uint32_t DataEncoder::SetData(void *bytes, uint32_t length, ByteOrder endian) { // starting at "data_offset") to ensure the data stays around as long as it is // needed. The address size and endian swap settings will remain unchanged from // their current settings. -//---------------------------------------------------------------------- uint32_t DataEncoder::SetData(const DataBufferSP &data_sp, uint32_t data_offset, uint32_t data_length) { m_start = m_end = nullptr; @@ -153,12 +139,10 @@ uint32_t DataEncoder::SetData(const DataBufferSP &data_sp, uint32_t data_offset, return new_size; } -//---------------------------------------------------------------------- // Extract a single unsigned char from the binary data and update the offset // pointed to by "offset_ptr". // // RETURNS the byte that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint32_t DataEncoder::PutU8(uint32_t offset, uint8_t value) { if (ValidOffset(offset)) { m_start[offset] = value; @@ -203,7 +187,6 @@ uint32_t DataEncoder::PutU64(uint32_t offset, uint64_t value) { return UINT32_MAX; } -//---------------------------------------------------------------------- // Extract a single integer value from the data and update the offset pointed // to by "offset_ptr". The size of the extracted integer is specified by the // "byte_size" argument. "byte_size" should have a value >= 1 and <= 8 since @@ -212,7 +195,6 @@ uint32_t DataEncoder::PutU64(uint32_t offset, uint64_t value) { // returned. // // RETURNS the integer value that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint32_t DataEncoder::PutMaxU64(uint32_t offset, uint32_t byte_size, uint64_t value) { switch (byte_size) { diff --git a/source/Utility/DataExtractor.cpp b/source/Utility/DataExtractor.cpp index ae5a3f9b7d8f..79a1f75d737c 100644 --- a/source/Utility/DataExtractor.cpp +++ b/source/Utility/DataExtractor.cpp @@ -1,9 +1,8 @@ //===-- DataExtractor.cpp ---------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -125,10 +124,8 @@ DataExtractor::DataExtractor() m_byte_order(endian::InlHostByteOrder()), m_addr_size(sizeof(void *)), m_data_sp(), m_target_byte_size(1) {} -//---------------------------------------------------------------------- // This constructor allows us to use data that is owned by someone else. The // data must stay around as long as this object is valid. -//---------------------------------------------------------------------- DataExtractor::DataExtractor(const void *data, offset_t length, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size /*=1*/) @@ -137,44 +134,34 @@ DataExtractor::DataExtractor(const void *data, offset_t length, length), m_byte_order(endian), m_addr_size(addr_size), m_data_sp(), m_target_byte_size(target_byte_size) { -#ifdef LLDB_CONFIGURATION_DEBUG assert(addr_size == 4 || addr_size == 8); -#endif } -//---------------------------------------------------------------------- // Make a shared pointer reference to the shared data in "data_sp" and set the // endian swapping setting to "swap", and the address size to "addr_size". The // shared data reference will ensure the data lives as long as any // DataExtractor objects exist that have a reference to this data. -//---------------------------------------------------------------------- DataExtractor::DataExtractor(const DataBufferSP &data_sp, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size /*=1*/) : m_start(nullptr), m_end(nullptr), m_byte_order(endian), m_addr_size(addr_size), m_data_sp(), m_target_byte_size(target_byte_size) { -#ifdef LLDB_CONFIGURATION_DEBUG assert(addr_size == 4 || addr_size == 8); -#endif SetData(data_sp); } -//---------------------------------------------------------------------- // Initialize this object with a subset of the data bytes in "data". If "data" // contains shared data, then a reference to this shared data will added and // the shared data will stay around as long as any object contains a reference // to that data. The endian swap and address size settings are copied from // "data". -//---------------------------------------------------------------------- DataExtractor::DataExtractor(const DataExtractor &data, offset_t offset, offset_t length, uint32_t target_byte_size /*=1*/) : m_start(nullptr), m_end(nullptr), m_byte_order(data.m_byte_order), m_addr_size(data.m_addr_size), m_data_sp(), m_target_byte_size(target_byte_size) { -#ifdef LLDB_CONFIGURATION_DEBUG assert(m_addr_size == 4 || m_addr_size == 8); -#endif if (data.ValidOffset(offset)) { offset_t bytes_available = data.GetByteSize() - offset; if (length > bytes_available) @@ -187,14 +174,10 @@ DataExtractor::DataExtractor(const DataExtractor &rhs) : m_start(rhs.m_start), m_end(rhs.m_end), m_byte_order(rhs.m_byte_order), m_addr_size(rhs.m_addr_size), m_data_sp(rhs.m_data_sp), m_target_byte_size(rhs.m_target_byte_size) { -#ifdef LLDB_CONFIGURATION_DEBUG assert(m_addr_size == 4 || m_addr_size == 8); -#endif } -//---------------------------------------------------------------------- // Assignment operator -//---------------------------------------------------------------------- const DataExtractor &DataExtractor::operator=(const DataExtractor &rhs) { if (this != &rhs) { m_start = rhs.m_start; @@ -208,10 +191,8 @@ const DataExtractor &DataExtractor::operator=(const DataExtractor &rhs) { DataExtractor::~DataExtractor() = default; -//------------------------------------------------------------------ // Clears the object contents back to a default invalid state, and release any // references to shared data that this object may contain. -//------------------------------------------------------------------ void DataExtractor::Clear() { m_start = nullptr; m_end = nullptr; @@ -220,10 +201,8 @@ void DataExtractor::Clear() { m_data_sp.reset(); } -//------------------------------------------------------------------ // If this object contains shared data, this function returns the offset into // that shared data. Else zero is returned. -//------------------------------------------------------------------ size_t DataExtractor::GetSharedDataOffset() const { if (m_start != nullptr) { const DataBuffer *data = m_data_sp.get(); @@ -238,7 +217,6 @@ size_t DataExtractor::GetSharedDataOffset() const { return 0; } -//---------------------------------------------------------------------- // Set the data with which this object will extract from to data starting at // BYTES and set the length of the data to LENGTH bytes long. The data is // externally owned must be around at least as long as this object points to @@ -246,7 +224,6 @@ size_t DataExtractor::GetSharedDataOffset() const { // and can extract from it. If this object refers to any shared data upon // entry, the reference to that data will be released. Is SWAP is set to true, // any data extracted will be endian swapped. -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::SetData(const void *bytes, offset_t length, ByteOrder endian) { m_byte_order = endian; @@ -261,7 +238,6 @@ lldb::offset_t DataExtractor::SetData(const void *bytes, offset_t length, return GetByteSize(); } -//---------------------------------------------------------------------- // Assign the data for this object to be a subrange in "data" starting // "data_offset" bytes into "data" and ending "data_length" bytes later. If // "data_offset" is not a valid offset into "data", then this object will @@ -272,14 +248,11 @@ lldb::offset_t DataExtractor::SetData(const void *bytes, offset_t length, // a shared pointer to data, then the bytes referred to in "data" will need to // exist at least as long as this object refers to those bytes. The address // size and endian swap settings are copied from the current values in "data". -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::SetData(const DataExtractor &data, offset_t data_offset, offset_t data_length) { m_addr_size = data.m_addr_size; -#ifdef LLDB_CONFIGURATION_DEBUG assert(m_addr_size == 4 || m_addr_size == 8); -#endif // If "data" contains shared pointer to data, then we can use that if (data.m_data_sp) { m_byte_order = data.m_byte_order; @@ -297,7 +270,6 @@ lldb::offset_t DataExtractor::SetData(const DataExtractor &data, return 0; } -//---------------------------------------------------------------------- // Assign the data for this object to be a subrange of the shared data in // "data_sp" starting "data_offset" bytes into "data_sp" and ending // "data_length" bytes later. If "data_offset" is not a valid offset into @@ -309,7 +281,6 @@ lldb::offset_t DataExtractor::SetData(const DataExtractor &data, // starting at "data_offset") to ensure the data stays around as long as it is // needed. The address size and endian swap settings will remain unchanged from // their current settings. -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::SetData(const DataBufferSP &data_sp, offset_t data_offset, offset_t data_length) { @@ -342,30 +313,27 @@ lldb::offset_t DataExtractor::SetData(const DataBufferSP &data_sp, return new_size; } -//---------------------------------------------------------------------- // Extract a single unsigned char from the binary data and update the offset // pointed to by "offset_ptr". // // RETURNS the byte that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const { - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, 1); + const uint8_t *data = static_cast<const uint8_t *>(GetData(offset_ptr, 1)); if (data) return *data; return 0; } -//---------------------------------------------------------------------- // Extract "count" unsigned chars from the binary data and update the offset // pointed to by "offset_ptr". The extracted data is copied into "dst". // // RETURNS the non-nullptr buffer pointer upon successful extraction of // all the requested bytes, or nullptr when the data is not available in the // buffer due to being out of bounds, or insufficient data. -//---------------------------------------------------------------------- void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst, uint32_t count) const { - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, count); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, count)); if (data) { // Copy the data into the buffer memcpy(dst, data, count); @@ -376,15 +344,14 @@ void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst, return nullptr; } -//---------------------------------------------------------------------- // Extract a single uint16_t from the data and update the offset pointed to by // "offset_ptr". // // RETURNS the uint16_t that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint16_t DataExtractor::GetU16(offset_t *offset_ptr) const { uint16_t val = 0; - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val))); if (data) { if (m_byte_order != endian::InlHostByteOrder()) val = ReadSwapInt16(data); @@ -424,21 +391,20 @@ uint64_t DataExtractor::GetU64_unchecked(offset_t *offset_ptr) const { return val; } -//---------------------------------------------------------------------- // Extract "count" uint16_t values from the binary data and update the offset // pointed to by "offset_ptr". The extracted data is copied into "dst". // // RETURNS the non-nullptr buffer pointer upon successful extraction of // all the requested bytes, or nullptr when the data is not available in the // buffer due to being out of bounds, or insufficient data. -//---------------------------------------------------------------------- void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint16_t) * count; - const uint16_t *src = (const uint16_t *)GetData(offset_ptr, src_size); + const uint16_t *src = + static_cast<const uint16_t *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - uint16_t *dst_pos = (uint16_t *)void_dst; + uint16_t *dst_pos = static_cast<uint16_t *>(void_dst); uint16_t *dst_end = dst_pos + count; const uint16_t *src_pos = src; while (dst_pos < dst_end) { @@ -456,15 +422,14 @@ void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst, return nullptr; } -//---------------------------------------------------------------------- // Extract a single uint32_t from the data and update the offset pointed to by // "offset_ptr". // // RETURNS the uint32_t that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const { uint32_t val = 0; - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val))); if (data) { if (m_byte_order != endian::InlHostByteOrder()) { val = ReadSwapInt32(data); @@ -475,21 +440,20 @@ uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const { return val; } -//---------------------------------------------------------------------- // Extract "count" uint32_t values from the binary data and update the offset // pointed to by "offset_ptr". The extracted data is copied into "dst". // // RETURNS the non-nullptr buffer pointer upon successful extraction of // all the requested bytes, or nullptr when the data is not available in the // buffer due to being out of bounds, or insufficient data. -//---------------------------------------------------------------------- void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint32_t) * count; - const uint32_t *src = (const uint32_t *)GetData(offset_ptr, src_size); + const uint32_t *src = + static_cast<const uint32_t *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - uint32_t *dst_pos = (uint32_t *)void_dst; + uint32_t *dst_pos = static_cast<uint32_t *>(void_dst); uint32_t *dst_end = dst_pos + count; const uint32_t *src_pos = src; while (dst_pos < dst_end) { @@ -507,15 +471,14 @@ void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst, return nullptr; } -//---------------------------------------------------------------------- // Extract a single uint64_t from the data and update the offset pointed to by // "offset_ptr". // // RETURNS the uint64_t that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const { uint64_t val = 0; - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val))); if (data) { if (m_byte_order != endian::InlHostByteOrder()) { val = ReadSwapInt64(data); @@ -526,20 +489,19 @@ uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const { return val; } -//---------------------------------------------------------------------- // GetU64 // // Get multiple consecutive 64 bit values. Return true if the entire read // succeeds and increment the offset pointed to by offset_ptr, else return // false and leave the offset pointed to by offset_ptr unchanged. -//---------------------------------------------------------------------- void *DataExtractor::GetU64(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint64_t) * count; - const uint64_t *src = (const uint64_t *)GetData(offset_ptr, src_size); + const uint64_t *src = + static_cast<const uint64_t *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - uint64_t *dst_pos = (uint64_t *)void_dst; + uint64_t *dst_pos = static_cast<uint64_t *>(void_dst); uint64_t *dst_end = dst_pos + count; const uint64_t *src_pos = src; while (dst_pos < dst_end) { @@ -640,10 +602,11 @@ int64_t DataExtractor::GetMaxS64Bitfield(offset_t *offset_ptr, size_t size, lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size; if (lsbcount > 0) sval64 >>= lsbcount; - uint64_t bitfield_mask = (((uint64_t)1) << bitfield_bit_size) - 1; + uint64_t bitfield_mask = + ((static_cast<uint64_t>(1)) << bitfield_bit_size) - 1; sval64 &= bitfield_mask; // sign extend if needed - if (sval64 & (((uint64_t)1) << (bitfield_bit_size - 1))) + if (sval64 & ((static_cast<uint64_t>(1)) << (bitfield_bit_size - 1))) sval64 |= ~bitfield_mask; } return sval64; @@ -653,11 +616,12 @@ float DataExtractor::GetFloat(offset_t *offset_ptr) const { typedef float float_type; float_type val = 0.0; const size_t src_size = sizeof(float_type); - const float_type *src = (const float_type *)GetData(offset_ptr, src_size); + const float_type *src = + static_cast<const float_type *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - const uint8_t *src_data = (const uint8_t *)src; - uint8_t *dst_data = (uint8_t *)&val; + const uint8_t *src_data = reinterpret_cast<const uint8_t *>(src); + uint8_t *dst_data = reinterpret_cast<uint8_t *>(&val); for (size_t i = 0; i < sizeof(float_type); ++i) dst_data[sizeof(float_type) - 1 - i] = src_data[i]; } else { @@ -671,11 +635,12 @@ double DataExtractor::GetDouble(offset_t *offset_ptr) const { typedef double float_type; float_type val = 0.0; const size_t src_size = sizeof(float_type); - const float_type *src = (const float_type *)GetData(offset_ptr, src_size); + const float_type *src = + static_cast<const float_type *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - const uint8_t *src_data = (const uint8_t *)src; - uint8_t *dst_data = (uint8_t *)&val; + const uint8_t *src_data = reinterpret_cast<const uint8_t *>(src); + uint8_t *dst_data = reinterpret_cast<uint8_t *>(&val); for (size_t i = 0; i < sizeof(float_type); ++i) dst_data[sizeof(float_type) - 1 - i] = src_data[i]; } else { @@ -698,40 +663,30 @@ long double DataExtractor::GetLongDouble(offset_t *offset_ptr) const { return val; } -//------------------------------------------------------------------ // Extract a single address from the data and update the offset pointed to by // "offset_ptr". The size of the extracted address comes from the // "this->m_addr_size" member variable and should be set correctly prior to // extracting any address values. // // RETURNS the address that was extracted, or zero on failure. -//------------------------------------------------------------------ uint64_t DataExtractor::GetAddress(offset_t *offset_ptr) const { -#ifdef LLDB_CONFIGURATION_DEBUG assert(m_addr_size == 4 || m_addr_size == 8); -#endif return GetMaxU64(offset_ptr, m_addr_size); } uint64_t DataExtractor::GetAddress_unchecked(offset_t *offset_ptr) const { -#ifdef LLDB_CONFIGURATION_DEBUG assert(m_addr_size == 4 || m_addr_size == 8); -#endif return GetMaxU64_unchecked(offset_ptr, m_addr_size); } -//------------------------------------------------------------------ // Extract a single pointer from the data and update the offset pointed to by // "offset_ptr". The size of the extracted pointer comes from the // "this->m_addr_size" member variable and should be set correctly prior to // extracting any pointer values. // // RETURNS the pointer that was extracted, or zero on failure. -//------------------------------------------------------------------ uint64_t DataExtractor::GetPointer(offset_t *offset_ptr) const { -#ifdef LLDB_CONFIGURATION_DEBUG assert(m_addr_size == 4 || m_addr_size == 8); -#endif return GetMaxU64(offset_ptr, m_addr_size); } @@ -745,7 +700,7 @@ size_t DataExtractor::ExtractBytes(offset_t offset, offset_t length, length == 10 || length == 16 || length == 32); for (uint32_t i = 0; i < length; ++i) - ((uint8_t *)dst)[i] = src[length - i - 1]; + (static_cast<uint8_t *>(dst))[i] = src[length - i - 1]; } else ::memcpy(dst, src, length); return length; @@ -791,8 +746,8 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, !(m_byte_order == eByteOrderBig || m_byte_order == eByteOrderLittle)) return 0; - uint8_t *dst = (uint8_t *)dst_void_ptr; - const uint8_t *src = (const uint8_t *)PeekData(src_offset, src_len); + uint8_t *dst = static_cast<uint8_t *>(dst_void_ptr); + const uint8_t *src = PeekData(src_offset, src_len); if (src) { if (dst_len >= src_len) { // We are copying the entire value from src into dst. Calculate how many, @@ -853,7 +808,6 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, return 0; } -//---------------------------------------------------------------------- // Extracts a variable length NULL terminated C string from the data at the // offset pointed to by "offset_ptr". The "offset_ptr" will be updated with // the offset of the byte that follows the NULL terminator byte. @@ -861,12 +815,11 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, // If the offset pointed to by "offset_ptr" is out of bounds, or if "length" is // non-zero and there aren't enough available bytes, nullptr will be returned // and "offset_ptr" will not be updated. -//---------------------------------------------------------------------- const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { - const char *cstr = (const char *)PeekData(*offset_ptr, 1); + const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, 1)); if (cstr) { const char *cstr_end = cstr; - const char *end = (const char *)m_end; + const char *end = reinterpret_cast<const char *>(m_end); while (cstr_end < end && *cstr_end) ++cstr_end; @@ -885,7 +838,6 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { return nullptr; } -//---------------------------------------------------------------------- // Extracts a NULL terminated C string from the fixed length field of length // "len" at the offset pointed to by "offset_ptr". The "offset_ptr" will be // updated with the offset of the byte that follows the fixed length field. @@ -894,9 +846,8 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { // plus the length of the field is out of bounds, or if the field does not // contain a NULL terminator byte, nullptr will be returned and "offset_ptr" // will not be updated. -//---------------------------------------------------------------------- const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const { - const char *cstr = (const char *)PeekData(*offset_ptr, len); + const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, len)); if (cstr != nullptr) { if (memchr(cstr, '\0', len) == nullptr) { return nullptr; @@ -907,28 +858,24 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const { return nullptr; } -//------------------------------------------------------------------ // Peeks at a string in the contained data. No verification is done to make // sure the entire string lies within the bounds of this object's data, only // "offset" is verified to be a valid offset. // // Returns a valid C string pointer if "offset" is a valid offset in this // object's data, else nullptr is returned. -//------------------------------------------------------------------ const char *DataExtractor::PeekCStr(offset_t offset) const { - return (const char *)PeekData(offset, 1); + return reinterpret_cast<const char *>(PeekData(offset, 1)); } -//---------------------------------------------------------------------- // Extracts an unsigned LEB128 number from this object's data starting at the // offset pointed to by "offset_ptr". The offset pointed to by "offset_ptr" // will be updated with the offset of the byte following the last extracted // byte. // // Returned the extracted integer value. -//---------------------------------------------------------------------- uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { - const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); + const uint8_t *src = PeekData(*offset_ptr, 1); if (src == nullptr) return 0; @@ -941,7 +888,7 @@ uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { int shift = 7; while (src < end) { uint8_t byte = *src++; - result |= (uint64_t)(byte & 0x7f) << shift; + result |= static_cast<uint64_t>(byte & 0x7f) << shift; if ((byte & 0x80) == 0) break; shift += 7; @@ -954,16 +901,14 @@ uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { return 0; } -//---------------------------------------------------------------------- // Extracts an signed LEB128 number from this object's data starting at the // offset pointed to by "offset_ptr". The offset pointed to by "offset_ptr" // will be updated with the offset of the byte following the last extracted // byte. // // Returned the extracted integer value. -//---------------------------------------------------------------------- int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { - const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); + const uint8_t *src = PeekData(*offset_ptr, 1); if (src == nullptr) return 0; @@ -980,7 +925,7 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { while (src < end) { bytecount++; byte = *src++; - result |= (int64_t)(byte & 0x7f) << shift; + result |= static_cast<int64_t>(byte & 0x7f) << shift; shift += 7; if ((byte & 0x80) == 0) break; @@ -996,17 +941,15 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { return 0; } -//---------------------------------------------------------------------- // Skips a ULEB128 number (signed or unsigned) from this object's data starting // at the offset pointed to by "offset_ptr". The offset pointed to by // "offset_ptr" will be updated with the offset of the byte following the last // extracted byte. // // Returns the number of bytes consumed during the extraction. -//---------------------------------------------------------------------- uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { uint32_t bytes_consumed = 0; - const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); + const uint8_t *src = PeekData(*offset_ptr, 1); if (src == nullptr) return 0; @@ -1021,7 +964,6 @@ uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { return bytes_consumed; } -//---------------------------------------------------------------------- // Dumps bytes from this object's data to the stream "s" starting // "start_offset" bytes into this data, and ending with the byte before // "end_offset". "base_addr" will be added to the offset into the dumped data @@ -1031,7 +973,6 @@ uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { // printf style formatting string. If "type_format" is nullptr, then an // appropriate format string will be used for the supplied "type". If the // stream "s" is nullptr, then the output will be send to Log(). -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::PutToLog(Log *log, offset_t start_offset, offset_t length, uint64_t base_addr, uint32_t num_per_line, @@ -1055,7 +996,7 @@ lldb::offset_t DataExtractor::PutToLog(Log *log, offset_t start_offset, // Reset string offset and fill the current line string with address: if (base_addr != LLDB_INVALID_ADDRESS) sstr.Printf("0x%8.8" PRIx64 ":", - (uint64_t)(base_addr + (offset - start_offset))); + static_cast<uint64_t>(base_addr + (offset - start_offset))); } switch (type) { diff --git a/source/Utility/Environment.cpp b/source/Utility/Environment.cpp index ea20267a2362..140533600712 100644 --- a/source/Utility/Environment.cpp +++ b/source/Utility/Environment.cpp @@ -1,9 +1,8 @@ //===-- Environment.cpp -----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/Event.cpp b/source/Utility/Event.cpp index ad9f6e340f8c..579d0dac86ed 100644 --- a/source/Utility/Event.cpp +++ b/source/Utility/Event.cpp @@ -1,9 +1,8 @@ //===-- Event.cpp -----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -26,9 +25,7 @@ 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), @@ -88,9 +85,7 @@ void Event::DoOnRemoval() { #pragma mark - #pragma mark EventData -//------------------------------------------------------------------ // EventData functions -//------------------------------------------------------------------ EventData::EventData() = default; @@ -101,9 +96,7 @@ void EventData::Dump(Stream *s) const { s->PutCString("Generic Event Data"); } #pragma mark - #pragma mark EventDataBytes -//------------------------------------------------------------------ // EventDataBytes functions -//------------------------------------------------------------------ EventDataBytes::EventDataBytes() : m_bytes() {} @@ -121,12 +114,12 @@ EventDataBytes::EventDataBytes(const void *src, size_t src_len) : m_bytes() { EventDataBytes::~EventDataBytes() = default; -const ConstString &EventDataBytes::GetFlavorString() { +ConstString EventDataBytes::GetFlavorString() { static ConstString g_flavor("EventDataBytes"); return g_flavor; } -const ConstString &EventDataBytes::GetFlavor() const { +ConstString EventDataBytes::GetFlavor() const { return EventDataBytes::GetFlavorString(); } @@ -150,7 +143,7 @@ size_t EventDataBytes::GetByteSize() const { return m_bytes.size(); } void EventDataBytes::SetBytes(const void *src, size_t src_len) { if (src != nullptr && src_len > 0) - m_bytes.assign((const char *)src, src_len); + m_bytes.assign(static_cast<const char *>(src), src_len); else m_bytes.clear(); } @@ -194,9 +187,7 @@ void EventDataBytes::SwapBytes(std::string &new_bytes) { #pragma mark - #pragma mark EventStructuredData -//------------------------------------------------------------------ // EventDataStructuredData definitions -//------------------------------------------------------------------ EventDataStructuredData::EventDataStructuredData() : EventData(), m_process_sp(), m_object_sp(), m_plugin_sp() {} @@ -209,11 +200,9 @@ EventDataStructuredData::EventDataStructuredData( EventDataStructuredData::~EventDataStructuredData() {} -//------------------------------------------------------------------ // EventDataStructuredData member functions -//------------------------------------------------------------------ -const ConstString &EventDataStructuredData::GetFlavor() const { +ConstString EventDataStructuredData::GetFlavor() const { return EventDataStructuredData::GetFlavorString(); } @@ -252,9 +241,7 @@ void EventDataStructuredData::SetStructuredDataPlugin( m_plugin_sp = plugin_sp; } -//------------------------------------------------------------------ // EventDataStructuredData static functions -//------------------------------------------------------------------ const EventDataStructuredData * EventDataStructuredData::GetEventDataFromEvent(const Event *event_ptr) { @@ -295,7 +282,7 @@ EventDataStructuredData::GetPluginFromEvent(const Event *event_ptr) { return StructuredDataPluginSP(); } -const ConstString &EventDataStructuredData::GetFlavorString() { +ConstString EventDataStructuredData::GetFlavorString() { static ConstString s_flavor("EventDataStructuredData"); return s_flavor; } diff --git a/source/Utility/FileCollector.cpp b/source/Utility/FileCollector.cpp new file mode 100644 index 000000000000..ed9359192205 --- /dev/null +++ b/source/Utility/FileCollector.cpp @@ -0,0 +1,182 @@ +//===-- FileCollector.cpp ---------------------------------------*- 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 "lldb/Utility/FileCollector.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" + +using namespace lldb_private; +using namespace llvm; + +static bool IsCaseSensitivePath(StringRef path) { + SmallString<256> tmp_dest = path, upper_dest, real_dest; + + // Remove component traversals, links, etc. + if (!sys::fs::real_path(path, tmp_dest)) + return true; // Current default value in vfs.yaml + path = tmp_dest; + + // Change path to all upper case and ask for its real path, if the latter + // exists and is equal to path, it's not case sensitive. Default to case + // sensitive in the absence of real_path, since this is the YAMLVFSWriter + // default. + upper_dest = path.upper(); + if (sys::fs::real_path(upper_dest, real_dest) && path.equals(real_dest)) + return false; + return true; +} + +FileCollector::FileCollector(const FileSpec &root, const FileSpec &overlay_root) + : m_root(root), m_overlay_root(overlay_root) { + sys::fs::create_directories(m_root.GetPath(), true); +} + +bool FileCollector::GetRealPath(StringRef src_path, + SmallVectorImpl<char> &result) { + SmallString<256> real_path; + StringRef FileName = sys::path::filename(src_path); + std::string directory = sys::path::parent_path(src_path).str(); + auto dir_with_symlink = m_symlink_map.find(directory); + + // Use real_path to fix any symbolic link component present in a path. + // Computing the real path is expensive, cache the search through the + // parent path directory. + if (dir_with_symlink == m_symlink_map.end()) { + auto ec = sys::fs::real_path(directory, real_path); + if (ec) + return false; + m_symlink_map[directory] = real_path.str(); + } else { + real_path = dir_with_symlink->second; + } + + sys::path::append(real_path, FileName); + result.swap(real_path); + return true; +} + +void FileCollector::AddFile(const Twine &file) { + std::lock_guard<std::mutex> lock(m_mutex); + std::string file_str = file.str(); + if (MarkAsSeen(file_str)) + AddFileImpl(file_str); +} + +void FileCollector::AddFileImpl(StringRef src_path) { + std::string root = m_root.GetPath(); + + // We need an absolute src path to append to the root. + SmallString<256> absolute_src = src_path; + sys::fs::make_absolute(absolute_src); + + // Canonicalize src to a native path to avoid mixed separator styles. + sys::path::native(absolute_src); + + // Remove redundant leading "./" pieces and consecutive separators. + absolute_src = sys::path::remove_leading_dotslash(absolute_src); + + // Canonicalize the source path by removing "..", "." components. + SmallString<256> virtual_path = absolute_src; + sys::path::remove_dots(virtual_path, /*remove_dot_dot=*/true); + + // If a ".." component is present after a symlink component, remove_dots may + // lead to the wrong real destination path. Let the source be canonicalized + // like that but make sure we always use the real path for the destination. + SmallString<256> copy_from; + if (!GetRealPath(absolute_src, copy_from)) + copy_from = virtual_path; + + SmallString<256> dst_path = StringRef(root); + sys::path::append(dst_path, sys::path::relative_path(copy_from)); + + // Always map a canonical src path to its real path into the YAML, by doing + // this we map different virtual src paths to the same entry in the VFS + // overlay, which is a way to emulate symlink inside the VFS; this is also + // needed for correctness, not doing that can lead to module redefinition + // errors. + AddFileToMapping(virtual_path, dst_path); +} + +/// Set the access and modification time for the given file from the given +/// status object. +static std::error_code +CopyAccessAndModificationTime(StringRef filename, + const sys::fs::file_status &stat) { + int fd; + + if (auto ec = + sys::fs::openFileForWrite(filename, fd, sys::fs::CD_OpenExisting)) + return ec; + + if (auto ec = sys::fs::setLastAccessAndModificationTime( + fd, stat.getLastAccessedTime(), stat.getLastModificationTime())) + return ec; + + if (auto ec = sys::Process::SafelyCloseFileDescriptor(fd)) + return ec; + + return {}; +} + +std::error_code FileCollector::CopyFiles(bool stop_on_error) { + for (auto &entry : m_vfs_writer.getMappings()) { + // Create directory tree. + if (std::error_code ec = + sys::fs::create_directories(sys::path::parent_path(entry.RPath), + /*IgnoreExisting=*/true)) { + if (stop_on_error) + return ec; + } + + // Copy file over. + if (std::error_code ec = sys::fs::copy_file(entry.VPath, entry.RPath)) { + if (stop_on_error) + return ec; + } + + // Copy over permissions. + if (auto perms = sys::fs::getPermissions(entry.VPath)) { + if (std::error_code ec = sys::fs::setPermissions(entry.RPath, *perms)) { + if (stop_on_error) + return ec; + } + } + + // Copy over modification time. + sys::fs::file_status stat; + if (std::error_code ec = sys::fs::status(entry.VPath, stat)) { + if (stop_on_error) + return ec; + continue; + } + CopyAccessAndModificationTime(entry.RPath, stat); + } + return {}; +} + +std::error_code FileCollector::WriteMapping(const FileSpec &mapping_file) { + std::lock_guard<std::mutex> lock(m_mutex); + + std::string root = m_overlay_root.GetPath(); + + m_vfs_writer.setOverlayDir(root); + m_vfs_writer.setCaseSensitivity(IsCaseSensitivePath(root)); + m_vfs_writer.setUseExternalNames(false); + + std::error_code ec; + raw_fd_ostream os(mapping_file.GetPath(), ec, sys::fs::F_Text); + if (ec) + return ec; + + m_vfs_writer.write(os); + + return {}; +} diff --git a/source/Utility/FileSpec.cpp b/source/Utility/FileSpec.cpp index 954968b7a8af..35d22404b948 100644 --- a/source/Utility/FileSpec.cpp +++ b/source/Utility/FileSpec.cpp @@ -1,9 +1,8 @@ //===-- FileSpec.cpp --------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -68,9 +67,7 @@ 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); } @@ -78,47 +75,33 @@ FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) { FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &Triple) : FileSpec{path, Triple.isOSWindows() ? Style::windows : Style::posix} {} -//------------------------------------------------------------------ -// Copy constructor -//------------------------------------------------------------------ -FileSpec::FileSpec(const FileSpec &rhs) - : m_directory(rhs.m_directory), m_filename(rhs.m_filename), - m_is_resolved(rhs.m_is_resolved), m_style(rhs.m_style) {} - -//------------------------------------------------------------------ // Copy constructor -//------------------------------------------------------------------ FileSpec::FileSpec(const FileSpec *rhs) : m_directory(), m_filename() { if (rhs) *this = *rhs; } -//------------------------------------------------------------------ // Virtual destructor in case anyone inherits from this class. -//------------------------------------------------------------------ FileSpec::~FileSpec() {} namespace { -//------------------------------------------------------------------ /// Safely get a character at the specified index. /// -/// @param[in] path +/// \param[in] path /// A full, partial, or relative path to a file. /// -/// @param[in] i +/// \param[in] i /// An index into path which may or may not be valid. /// -/// @return +/// \return /// The character at index \a i if the index is valid, or 0 if /// the index is not valid. -//------------------------------------------------------------------ inline char safeCharAtIndex(const llvm::StringRef &path, size_t i) { if (i < path.size()) return path[i]; return 0; } -//------------------------------------------------------------------ /// Check if a path needs to be normalized. /// /// Check if a path needs to be normalized. We currently consider a @@ -131,12 +114,11 @@ inline char safeCharAtIndex(const llvm::StringRef &path, size_t i) { /// need normalization since we aren't trying to resolve the path, /// we are just trying to remove redundant things from the path. /// -/// @param[in] path +/// \param[in] path /// A full, partial, or relative path to a file. /// -/// @return +/// \return /// Returns \b true if the path needs to be normalized. -//------------------------------------------------------------------ bool needsNormalization(const llvm::StringRef &path) { if (path.empty()) return false; @@ -192,9 +174,7 @@ bool needsNormalization(const llvm::StringRef &path) { } -//------------------------------------------------------------------ // Assignment operator. -//------------------------------------------------------------------ const FileSpec &FileSpec::operator=(const FileSpec &rhs) { if (this != &rhs) { m_directory = rhs.m_directory; @@ -207,11 +187,9 @@ const FileSpec &FileSpec::operator=(const FileSpec &rhs) { 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) { m_filename.Clear(); m_directory.Clear(); @@ -254,22 +232,18 @@ void FileSpec::SetFile(llvm::StringRef path, const llvm::Triple &Triple) { return SetFile(path, Triple.isOSWindows() ? Style::windows : Style::posix); } -//---------------------------------------------------------------------- // Convert to pointer operator. This allows code to check any FileSpec objects // to see if they contain anything valid using code such as: // // if (file_spec) // {} -//---------------------------------------------------------------------- FileSpec::operator bool() const { return m_filename || m_directory; } -//---------------------------------------------------------------------- // Logical NOT operator. This allows code to check any FileSpec objects to see // if they are invalid using code such as: // // if (!file_spec) // {} -//---------------------------------------------------------------------- bool FileSpec::operator!() const { return !m_directory && !m_filename; } bool FileSpec::DirectoryEquals(const FileSpec &rhs) const { @@ -282,43 +256,32 @@ bool FileSpec::FileEquals(const FileSpec &rhs) const { return ConstString::Equals(m_filename, rhs.m_filename, case_sensitive); } -//------------------------------------------------------------------ // Equal to operator -//------------------------------------------------------------------ bool FileSpec::operator==(const FileSpec &rhs) const { return FileEquals(rhs) && DirectoryEquals(rhs); } -//------------------------------------------------------------------ // Not equal to operator -//------------------------------------------------------------------ bool FileSpec::operator!=(const FileSpec &rhs) const { return !(*this == rhs); } -//------------------------------------------------------------------ // Less than operator -//------------------------------------------------------------------ bool FileSpec::operator<(const FileSpec &rhs) const { return FileSpec::Compare(*this, rhs, true) < 0; } -//------------------------------------------------------------------ // Dump a FileSpec object to a stream -//------------------------------------------------------------------ Stream &lldb_private::operator<<(Stream &s, const FileSpec &f) { f.Dump(&s); return s; } -//------------------------------------------------------------------ // Clear this object by releasing both the directory and filename string values // and making them both the empty string. -//------------------------------------------------------------------ void FileSpec::Clear() { m_directory.Clear(); m_filename.Clear(); } -//------------------------------------------------------------------ // Compare two FileSpec objects. If "full" is true, then both the directory and // the filename must match. If "full" is false, then the directory names for // "a" and "b" are only compared if they are both non-empty. This allows a @@ -327,7 +290,6 @@ void FileSpec::Clear() { // // Return -1 if the "a" is less than "b", 0 if "a" is equal to "b" and "1" if // "a" is greater than "b". -//------------------------------------------------------------------ int FileSpec::Compare(const FileSpec &a, const FileSpec &b, bool full) { int result = 0; @@ -366,11 +328,20 @@ bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full) { return a == b; } -//------------------------------------------------------------------ +llvm::Optional<FileSpec::Style> FileSpec::GuessPathStyle(llvm::StringRef absolute_path) { + if (absolute_path.startswith("/")) + return Style::posix; + if (absolute_path.startswith(R"(\\)")) + return Style::windows; + if (absolute_path.size() > 3 && llvm::isAlpha(absolute_path[0]) && + absolute_path.substr(1, 2) == R"(:\)") + return Style::windows; + return llvm::None; +} + // Dump the object to the supplied stream. If the object contains a valid // directory name, it will be displayed followed by a directory delimiter, and // the filename. -//------------------------------------------------------------------ void FileSpec::Dump(Stream *s) const { if (s) { std::string path{GetPath(true)}; @@ -383,30 +354,20 @@ void FileSpec::Dump(Stream *s) const { FileSpec::Style FileSpec::GetPathStyle() const { return m_style; } -//------------------------------------------------------------------ // Directory string get accessor. -//------------------------------------------------------------------ ConstString &FileSpec::GetDirectory() { return m_directory; } -//------------------------------------------------------------------ // Directory string const get accessor. -//------------------------------------------------------------------ -const ConstString &FileSpec::GetDirectory() const { return m_directory; } +ConstString FileSpec::GetDirectory() const { return m_directory; } -//------------------------------------------------------------------ // Filename string get accessor. -//------------------------------------------------------------------ ConstString &FileSpec::GetFilename() { return m_filename; } -//------------------------------------------------------------------ // Filename string const get accessor. -//------------------------------------------------------------------ -const ConstString &FileSpec::GetFilename() const { return m_filename; } +ConstString FileSpec::GetFilename() const { return m_filename; } -//------------------------------------------------------------------ // Extract the directory and path into a fixed buffer. This is needed as the // directory and path are stored in separate string values. -//------------------------------------------------------------------ size_t FileSpec::GetPath(char *path, size_t path_max_len, bool denormalize) const { if (!path) @@ -452,10 +413,8 @@ ConstString FileSpec::GetFileNameStrippingExtension() const { return ConstString(llvm::sys::path::stem(m_filename.GetStringRef(), m_style)); } -//------------------------------------------------------------------ // Return the size in bytes that this object takes in memory. This returns the // size in bytes of this object, not any shared string values it may refer to. -//------------------------------------------------------------------ size_t FileSpec::MemorySize() const { return m_filename.MemorySize() + m_directory.MemorySize(); } @@ -516,15 +475,13 @@ bool FileSpec::RemoveLastPathComponent() { } return false; } -//------------------------------------------------------------------ /// Returns true if the filespec represents an implementation source /// file (files with a ".c", ".cpp", ".m", ".mm" (many more) /// extension). /// -/// @return +/// \return /// \b true if the filespec represents an implementation source /// file, \b false otherwise. -//------------------------------------------------------------------ bool FileSpec::IsSourceImplementationFile() const { ConstString extension(GetFileNameExtension()); if (!extension) @@ -557,6 +514,11 @@ bool FileSpec::IsAbsolute() const { return llvm::sys::path::is_absolute(current_path, m_style); } +void FileSpec::MakeAbsolute(const FileSpec &dir) { + if (IsRelative()) + PrependPathComponent(dir); +} + void llvm::format_provider<FileSpec>::format(const FileSpec &F, raw_ostream &Stream, StringRef Style) { diff --git a/source/Utility/IOObject.cpp b/source/Utility/IOObject.cpp index df7929c4f911..5e3ccddb6a30 100644 --- a/source/Utility/IOObject.cpp +++ b/source/Utility/IOObject.cpp @@ -1,9 +1,8 @@ //===-- IOObject.cpp --------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/JSON.cpp b/source/Utility/JSON.cpp index 725ea97955c6..2c3f6229eda1 100644 --- a/source/Utility/JSON.cpp +++ b/source/Utility/JSON.cpp @@ -1,9 +1,8 @@ //===--------------------- JSON.cpp -----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -56,9 +55,9 @@ uint64_t JSONNumber::GetAsUnsigned() const { case DataType::Unsigned: return m_data.m_unsigned; case DataType::Signed: - return (uint64_t)m_data.m_signed; + return static_cast<uint64_t>(m_data.m_signed); case DataType::Double: - return (uint64_t)m_data.m_double; + return static_cast<uint64_t>(m_data.m_double); } llvm_unreachable("Unhandled data type"); } @@ -66,11 +65,11 @@ uint64_t JSONNumber::GetAsUnsigned() const { int64_t JSONNumber::GetAsSigned() const { switch (m_data_type) { case DataType::Unsigned: - return (int64_t)m_data.m_unsigned; + return static_cast<int64_t>(m_data.m_unsigned); case DataType::Signed: return m_data.m_signed; case DataType::Double: - return (int64_t)m_data.m_double; + return static_cast<int64_t>(m_data.m_double); } llvm_unreachable("Unhandled data type"); } @@ -78,9 +77,9 @@ int64_t JSONNumber::GetAsSigned() const { double JSONNumber::GetAsDouble() const { switch (m_data_type) { case DataType::Unsigned: - return (double)m_data.m_unsigned; + return static_cast<double>(m_data.m_unsigned); case DataType::Signed: - return (double)m_data.m_signed; + return static_cast<double>(m_data.m_signed); case DataType::Double: return m_data.m_double; } @@ -239,7 +238,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { break; case '"': { - while (1) { + while (true) { bool was_escaped = false; int escaped_ch = GetEscapedChar(was_escaped); if (escaped_ch == -1) { @@ -254,7 +253,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { const bool is_null = escaped_ch == 0; if (was_escaped || (!is_end_quote && !is_null)) { if (CHAR_MIN <= escaped_ch && escaped_ch <= CHAR_MAX) { - value.append(1, (char)escaped_ch); + value.append(1, static_cast<char>(escaped_ch)); } else { error.Printf("error: wide character support is needed for unicode " "character 0x%4.4x at offset %" PRIu64, @@ -454,7 +453,7 @@ JSONValue::SP JSONParser::ParseJSONObject() { std::string value; std::string key; - while (1) { + while (true) { JSONParser::Token token = GetToken(value); if (token == JSONParser::Token::String) { @@ -485,7 +484,7 @@ JSONValue::SP JSONParser::ParseJSONArray() { std::string value; std::string key; - while (1) { + while (true) { JSONValue::SP value_sp = ParseJSONValue(); if (value_sp) array_up->AppendObject(value_sp); diff --git a/source/Utility/LLDBAssert.cpp b/source/Utility/LLDBAssert.cpp index 3902c89b2c83..75530d806310 100644 --- a/source/Utility/LLDBAssert.cpp +++ b/source/Utility/LLDBAssert.cpp @@ -1,9 +1,8 @@ //===--------------------- LLDBAssert.cpp ------------------------*- C++-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -22,11 +21,16 @@ void lldb_private::lldb_assert(bool expression, const char *expr_text, if (LLVM_LIKELY(expression)) return; + // In a Debug configuration lldb_assert() behaves like assert(0). + llvm_unreachable("lldb_assert failed"); + + // In a Release configuration it will print a warning and encourage the user + // to file a bug report, similar to LLVM’s crash handler, and then return + // execution. errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n", expr_text, func, file, line); errs() << "backtrace leading to the failure:\n"; llvm::sys::PrintStackTrace(errs()); errs() << "please file a bug report against lldb reporting this failure " "log, and as many details as possible\n"; - abort(); } diff --git a/source/Utility/Listener.cpp b/source/Utility/Listener.cpp index a20859e53eeb..50c56406c2ca 100644 --- a/source/Utility/Listener.cpp +++ b/source/Utility/Listener.cpp @@ -1,9 +1,8 @@ //===-- Listener.cpp --------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -28,8 +27,8 @@ namespace { class BroadcasterManagerWPMatcher { public: BroadcasterManagerWPMatcher(BroadcasterManagerSP manager_sp) - : m_manager_sp(manager_sp) {} - bool operator()(const BroadcasterManagerWP input_wp) const { + : m_manager_sp(std::move(manager_sp)) {} + bool operator()(const BroadcasterManagerWP &input_wp) const { BroadcasterManagerSP input_sp = input_wp.lock(); return (input_sp && input_sp == m_manager_sp); } @@ -192,7 +191,7 @@ void Listener::BroadcasterManagerWillDestruct(BroadcasterManagerSP manager_sp) { end_iter = m_broadcaster_managers.end(); BroadcasterManagerWP manager_wp; - BroadcasterManagerWPMatcher matcher(manager_sp); + BroadcasterManagerWPMatcher matcher(std::move(manager_sp)); iter = std::find_if<broadcaster_manager_collection::iterator, BroadcasterManagerWPMatcher>( m_broadcaster_managers.begin(), end_iter, matcher); @@ -239,7 +238,7 @@ public: if (m_broadcaster_names) { bool found_source = false; - const ConstString &event_broadcaster_name = + ConstString event_broadcaster_name = event_sp->GetBroadcaster()->GetBroadcasterName(); for (uint32_t i = 0; i < m_num_broadcaster_names; ++i) { if (m_broadcaster_names[i] == event_broadcaster_name) { @@ -425,7 +424,7 @@ size_t Listener::HandleBroadcastEvent(EventSP &event_sp) { } uint32_t -Listener::StartListeningForEventSpec(BroadcasterManagerSP manager_sp, +Listener::StartListeningForEventSpec(const BroadcasterManagerSP &manager_sp, const BroadcastEventSpec &event_spec) { if (!manager_sp) return 0; @@ -453,7 +452,7 @@ Listener::StartListeningForEventSpec(BroadcasterManagerSP manager_sp, return bits_acquired; } -bool Listener::StopListeningForEventSpec(BroadcasterManagerSP manager_sp, +bool Listener::StopListeningForEventSpec(const BroadcasterManagerSP &manager_sp, const BroadcastEventSpec &event_spec) { if (!manager_sp) return false; diff --git a/source/Utility/Log.cpp b/source/Utility/Log.cpp index 2e8570b762af..217b0d2ba97b 100644 --- a/source/Utility/Log.cpp +++ b/source/Utility/Log.cpp @@ -1,9 +1,8 @@ //===-- Log.cpp -------------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -110,9 +109,7 @@ const Flags Log::GetMask() const { void Log::PutCString(const char *cstr) { Printf("%s", cstr); } void Log::PutString(llvm::StringRef str) { PutCString(str.str().c_str()); } -//---------------------------------------------------------------------- // Simple variable argument logging with flags. -//---------------------------------------------------------------------- void Log::Printf(const char *format, ...) { va_list args; va_start(args, format); @@ -120,11 +117,9 @@ void Log::Printf(const char *format, ...) { va_end(args); } -//---------------------------------------------------------------------- // All logging eventually boils down to this function call. If we have a // callback registered, then we call the logging callback. If we have a valid // file handle, we also log to the file. -//---------------------------------------------------------------------- void Log::VAPrintf(const char *format, va_list args) { llvm::SmallString<64> FinalMessage; llvm::raw_svector_ostream Stream(FinalMessage); @@ -138,9 +133,7 @@ void Log::VAPrintf(const char *format, va_list args) { WriteMessage(FinalMessage.str()); } -//---------------------------------------------------------------------- // Printing of errors that are not fatal. -//---------------------------------------------------------------------- void Log::Error(const char *format, ...) { va_list args; va_start(args, format); @@ -155,9 +148,7 @@ void Log::VAError(const char *format, va_list args) { Printf("error: %s", Content.c_str()); } -//---------------------------------------------------------------------- // Printing of warnings that are not fatal only if verbose mode is enabled. -//---------------------------------------------------------------------- void Log::Verbose(const char *format, ...) { if (!GetVerbose()) return; @@ -168,9 +159,7 @@ void Log::Verbose(const char *format, ...) { va_end(args); } -//---------------------------------------------------------------------- // Printing of warnings that are not fatal. -//---------------------------------------------------------------------- void Log::Warning(const char *format, ...) { llvm::SmallString<64> Content; va_list args; diff --git a/source/Utility/Logging.cpp b/source/Utility/Logging.cpp index b97a88b5edcb..c0856e5d9267 100644 --- a/source/Utility/Logging.cpp +++ b/source/Utility/Logging.cpp @@ -1,9 +1,8 @@ //===-- Logging.cpp ---------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -18,6 +17,7 @@ using namespace lldb_private; static constexpr Log::Category g_categories[] = { {{"api"}, {"log API calls and return values"}, LIBLLDB_LOG_API}, + {{"ast"}, {"log AST"}, LIBLLDB_LOG_AST}, {{"break"}, {"log breakpoints"}, LIBLLDB_LOG_BREAKPOINTS}, {{"commands"}, {"log command argument parsing"}, LIBLLDB_LOG_COMMANDS}, {{"comm"}, {"log communication activities"}, LIBLLDB_LOG_COMMUNICATION}, diff --git a/source/Utility/NameMatches.cpp b/source/Utility/NameMatches.cpp index a76df3f929e8..5c9579ea7332 100644 --- a/source/Utility/NameMatches.cpp +++ b/source/Utility/NameMatches.cpp @@ -1,9 +1,8 @@ //===-- NameMatches.cpp -----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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/NameMatches.h" diff --git a/source/Utility/PPC64LE_DWARF_Registers.h b/source/Utility/PPC64LE_DWARF_Registers.h index 1a7503790e5d..548c1fda8600 100644 --- a/source/Utility/PPC64LE_DWARF_Registers.h +++ b/source/Utility/PPC64LE_DWARF_Registers.h @@ -1,9 +1,8 @@ //===-- PPC64LE_DWARF_Registers.h -------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/PPC64LE_ehframe_Registers.h b/source/Utility/PPC64LE_ehframe_Registers.h index c5763b304711..77cb3e5924e7 100644 --- a/source/Utility/PPC64LE_ehframe_Registers.h +++ b/source/Utility/PPC64LE_ehframe_Registers.h @@ -1,9 +1,8 @@ //===-- PPC64LE_ehframe_Registers.h -----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/PPC64_DWARF_Registers.h b/source/Utility/PPC64_DWARF_Registers.h index 7e3619e0da4d..6ba5b6ac3727 100644 --- a/source/Utility/PPC64_DWARF_Registers.h +++ b/source/Utility/PPC64_DWARF_Registers.h @@ -1,9 +1,8 @@ //===-- PPC64_DWARF_Registers.h ---------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/ProcessInfo.cpp b/source/Utility/ProcessInfo.cpp new file mode 100644 index 000000000000..b67ae8779000 --- /dev/null +++ b/source/Utility/ProcessInfo.cpp @@ -0,0 +1,310 @@ +//===-- ProcessInfo.cpp -----------------------------------------*- 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 "lldb/Utility/ProcessInfo.h" + +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/Stream.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/UserIDResolver.h" +#include "llvm/ADT/SmallString.h" + +#include <climits> + +using namespace lldb; +using namespace lldb_private; + +ProcessInfo::ProcessInfo() + : m_executable(), m_arguments(), m_environment(), m_uid(UINT32_MAX), + m_gid(UINT32_MAX), m_arch(), m_pid(LLDB_INVALID_PROCESS_ID) {} + +ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch, + lldb::pid_t pid) + : m_executable(name), m_arguments(), m_environment(), m_uid(UINT32_MAX), + m_gid(UINT32_MAX), m_arch(arch), m_pid(pid) {} + +void ProcessInfo::Clear() { + m_executable.Clear(); + m_arguments.Clear(); + m_environment.clear(); + m_uid = UINT32_MAX; + m_gid = UINT32_MAX; + m_arch.Clear(); + m_pid = LLDB_INVALID_PROCESS_ID; +} + +const char *ProcessInfo::GetName() const { + return m_executable.GetFilename().GetCString(); +} + +size_t ProcessInfo::GetNameLength() const { + return m_executable.GetFilename().GetLength(); +} + +void ProcessInfo::Dump(Stream &s, Platform *platform) const { + s << "Executable: " << GetName() << "\n"; + s << "Triple: "; + m_arch.DumpTriple(s); + s << "\n"; + + s << "Arguments:\n"; + m_arguments.Dump(s); + + s.Format("Environment:\n{0}", m_environment); +} + +void ProcessInfo::SetExecutableFile(const FileSpec &exe_file, + bool add_exe_file_as_first_arg) { + if (exe_file) { + m_executable = exe_file; + if (add_exe_file_as_first_arg) { + llvm::SmallString<128> filename; + exe_file.GetPath(filename); + if (!filename.empty()) + m_arguments.InsertArgumentAtIndex(0, filename); + } + } else { + m_executable.Clear(); + } +} + +llvm::StringRef ProcessInfo::GetArg0() const { return m_arg0; } + +void ProcessInfo::SetArg0(llvm::StringRef arg) { m_arg0 = arg; } + +void ProcessInfo::SetArguments(char const **argv, + bool first_arg_is_executable) { + m_arguments.SetArguments(argv); + + // Is the first argument the executable? + if (first_arg_is_executable) { + const char *first_arg = m_arguments.GetArgumentAtIndex(0); + if (first_arg) { + // Yes the first argument is an executable, set it as the executable in + // the launch options. Don't resolve the file path as the path could be a + // remote platform path + m_executable.SetFile(first_arg, FileSpec::Style::native); + } + } +} + +void ProcessInfo::SetArguments(const Args &args, bool first_arg_is_executable) { + // Copy all arguments + m_arguments = args; + + // Is the first argument the executable? + if (first_arg_is_executable) { + const char *first_arg = m_arguments.GetArgumentAtIndex(0); + if (first_arg) { + // Yes the first argument is an executable, set it as the executable in + // the launch options. Don't resolve the file path as the path could be a + // remote platform path + m_executable.SetFile(first_arg, FileSpec::Style::native); + } + } +} + +void ProcessInstanceInfo::Dump(Stream &s, UserIDResolver &resolver) const { + if (m_pid != LLDB_INVALID_PROCESS_ID) + s.Printf(" pid = %" PRIu64 "\n", m_pid); + + if (m_parent_pid != LLDB_INVALID_PROCESS_ID) + s.Printf(" parent = %" PRIu64 "\n", m_parent_pid); + + if (m_executable) { + s.Printf(" name = %s\n", m_executable.GetFilename().GetCString()); + s.PutCString(" file = "); + m_executable.Dump(&s); + s.EOL(); + } + const uint32_t argc = m_arguments.GetArgumentCount(); + if (argc > 0) { + for (uint32_t i = 0; i < argc; i++) { + const char *arg = m_arguments.GetArgumentAtIndex(i); + if (i < 10) + s.Printf(" arg[%u] = %s\n", i, arg); + else + s.Printf("arg[%u] = %s\n", i, arg); + } + } + + s.Format("{0}", m_environment); + + if (m_arch.IsValid()) { + s.Printf(" arch = "); + m_arch.DumpTriple(s); + s.EOL(); + } + + if (UserIDIsValid()) { + s.Format(" uid = {0,-5} ({1})\n", GetUserID(), + resolver.GetUserName(GetUserID()).getValueOr("")); + } + if (GroupIDIsValid()) { + s.Format(" gid = {0,-5} ({1})\n", GetGroupID(), + resolver.GetGroupName(GetGroupID()).getValueOr("")); + } + if (EffectiveUserIDIsValid()) { + s.Format(" euid = {0,-5} ({1})\n", GetEffectiveUserID(), + resolver.GetUserName(GetEffectiveUserID()).getValueOr("")); + } + if (EffectiveGroupIDIsValid()) { + s.Format(" egid = {0,-5} ({1})\n", GetEffectiveGroupID(), + resolver.GetGroupName(GetEffectiveGroupID()).getValueOr("")); + } +} + +void ProcessInstanceInfo::DumpTableHeader(Stream &s, bool show_args, + bool verbose) { + const char *label; + if (show_args || verbose) + label = "ARGUMENTS"; + else + label = "NAME"; + + if (verbose) { + s.Printf("PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE " + " %s\n", + label); + s.PutCString("====== ====== ========== ========== ========== ========== " + "======================== ============================\n"); + } else { + s.Printf("PID PARENT USER TRIPLE %s\n", label); + s.PutCString("====== ====== ========== ======================== " + "============================\n"); + } +} + +void ProcessInstanceInfo::DumpAsTableRow(Stream &s, UserIDResolver &resolver, + bool show_args, bool verbose) const { + if (m_pid != LLDB_INVALID_PROCESS_ID) { + s.Printf("%-6" PRIu64 " %-6" PRIu64 " ", m_pid, m_parent_pid); + + StreamString arch_strm; + if (m_arch.IsValid()) + m_arch.DumpTriple(arch_strm); + + auto print = [&](UserIDResolver::id_t id, + llvm::Optional<llvm::StringRef> (UserIDResolver::*get)( + UserIDResolver::id_t id)) { + if (auto name = (resolver.*get)(id)) + s.Format("{0,-10} ", *name); + else + s.Format("{0,-10} ", id); + }; + if (verbose) { + print(m_uid, &UserIDResolver::GetUserName); + print(m_gid, &UserIDResolver::GetGroupName); + print(m_euid, &UserIDResolver::GetUserName); + print(m_egid, &UserIDResolver::GetGroupName); + + s.Printf("%-24s ", arch_strm.GetData()); + } else { + print(m_euid, &UserIDResolver::GetUserName); + s.Printf(" %-24s ", arch_strm.GetData()); + } + + if (verbose || show_args) { + const uint32_t argc = m_arguments.GetArgumentCount(); + if (argc > 0) { + for (uint32_t i = 0; i < argc; i++) { + if (i > 0) + s.PutChar(' '); + s.PutCString(m_arguments.GetArgumentAtIndex(i)); + } + } + } else { + s.PutCString(GetName()); + } + + s.EOL(); + } +} + +bool ProcessInstanceInfoMatch::NameMatches(const char *process_name) const { + if (m_name_match_type == NameMatch::Ignore || process_name == nullptr) + return true; + const char *match_name = m_match_info.GetName(); + if (!match_name) + return true; + + return lldb_private::NameMatches(process_name, m_name_match_type, match_name); +} + +bool ProcessInstanceInfoMatch::Matches( + const ProcessInstanceInfo &proc_info) const { + if (!NameMatches(proc_info.GetName())) + return false; + + if (m_match_info.ProcessIDIsValid() && + m_match_info.GetProcessID() != proc_info.GetProcessID()) + return false; + + if (m_match_info.ParentProcessIDIsValid() && + m_match_info.GetParentProcessID() != proc_info.GetParentProcessID()) + return false; + + if (m_match_info.UserIDIsValid() && + m_match_info.GetUserID() != proc_info.GetUserID()) + return false; + + if (m_match_info.GroupIDIsValid() && + m_match_info.GetGroupID() != proc_info.GetGroupID()) + return false; + + if (m_match_info.EffectiveUserIDIsValid() && + m_match_info.GetEffectiveUserID() != proc_info.GetEffectiveUserID()) + return false; + + if (m_match_info.EffectiveGroupIDIsValid() && + m_match_info.GetEffectiveGroupID() != proc_info.GetEffectiveGroupID()) + return false; + + if (m_match_info.GetArchitecture().IsValid() && + !m_match_info.GetArchitecture().IsCompatibleMatch( + proc_info.GetArchitecture())) + return false; + return true; +} + +bool ProcessInstanceInfoMatch::MatchAllProcesses() const { + if (m_name_match_type != NameMatch::Ignore) + return false; + + if (m_match_info.ProcessIDIsValid()) + return false; + + if (m_match_info.ParentProcessIDIsValid()) + return false; + + if (m_match_info.UserIDIsValid()) + return false; + + if (m_match_info.GroupIDIsValid()) + return false; + + if (m_match_info.EffectiveUserIDIsValid()) + return false; + + if (m_match_info.EffectiveGroupIDIsValid()) + return false; + + if (m_match_info.GetArchitecture().IsValid()) + return false; + + if (m_match_all_users) + return false; + + return true; +} + +void ProcessInstanceInfoMatch::Clear() { + m_match_info.Clear(); + m_name_match_type = NameMatch::Ignore; + m_match_all_users = false; +} diff --git a/source/Utility/RegisterValue.cpp b/source/Utility/RegisterValue.cpp index 27bffde637fb..a01c35a2818e 100644 --- a/source/Utility/RegisterValue.cpp +++ b/source/Utility/RegisterValue.cpp @@ -1,9 +1,8 @@ //===-- RegisterValue.cpp ---------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -147,23 +146,25 @@ bool RegisterValue::GetScalarValue(Scalar &scalar) const { scalar = *(const uint8_t *)buffer.bytes; return true; case 2: - scalar = *(const uint16_t *)buffer.bytes; + scalar = *reinterpret_cast<const uint16_t *>(buffer.bytes); return true; case 4: - scalar = *(const uint32_t *)buffer.bytes; + scalar = *reinterpret_cast<const uint32_t *>(buffer.bytes); return true; case 8: - scalar = *(const uint64_t *)buffer.bytes; + scalar = *reinterpret_cast<const uint64_t *>(buffer.bytes); return true; case 16: case 32: + case 64: if (buffer.length % sizeof(uint64_t) == 0) { const auto length_in_bits = buffer.length * 8; const auto length_in_uint64 = buffer.length / sizeof(uint64_t); scalar = llvm::APInt(length_in_bits, - llvm::ArrayRef<uint64_t>((const uint64_t *)buffer.bytes, - length_in_uint64)); + llvm::ArrayRef<uint64_t>( + reinterpret_cast<const uint64_t *>(buffer.bytes), + length_in_uint64)); return true; } break; @@ -518,7 +519,7 @@ uint16_t RegisterValue::GetAsUInt16(uint16_t fail_value, break; case 1: case 2: - return *(const uint16_t *)buffer.bytes; + return *reinterpret_cast<const uint16_t *>(buffer.bytes); } } break; } @@ -548,7 +549,7 @@ uint32_t RegisterValue::GetAsUInt32(uint32_t fail_value, case 1: case 2: case 4: - return *(const uint32_t *)buffer.bytes; + return *reinterpret_cast<const uint32_t *>(buffer.bytes); } } break; } @@ -579,11 +580,11 @@ uint64_t RegisterValue::GetAsUInt64(uint64_t fail_value, case 1: return *(const uint8_t *)buffer.bytes; case 2: - return *(const uint16_t *)buffer.bytes; + return *reinterpret_cast<const uint16_t *>(buffer.bytes); case 4: - return *(const uint32_t *)buffer.bytes; + return *reinterpret_cast<const uint32_t *>(buffer.bytes); case 8: - return *(const uint64_t *)buffer.bytes; + return *reinterpret_cast<const uint64_t *>(buffer.bytes); } } break; } @@ -618,7 +619,7 @@ llvm::APInt RegisterValue::GetAsUInt128(const llvm::APInt &fail_value, case 8: case 16: return llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, - ((const type128 *)buffer.bytes)->x); + (reinterpret_cast<const type128 *>(buffer.bytes))->x); } } break; } diff --git a/source/Utility/RegularExpression.cpp b/source/Utility/RegularExpression.cpp index 54f773365d99..0192e8b8a01a 100644 --- a/source/Utility/RegularExpression.cpp +++ b/source/Utility/RegularExpression.cpp @@ -1,9 +1,8 @@ //===-- RegularExpression.cpp -----------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -13,10 +12,8 @@ #include <string> -//---------------------------------------------------------------------- // Enable enhanced mode if it is available. This allows for things like \d for // digit, \s for space, and many more, but it isn't available everywhere. -//---------------------------------------------------------------------- #if defined(REG_ENHANCED) #define DEFAULT_COMPILE_FLAGS (REG_ENHANCED | REG_EXTENDED) #else @@ -29,18 +26,15 @@ RegularExpression::RegularExpression() : m_re(), m_comp_err(1), m_preg() { memset(&m_preg, 0, sizeof(m_preg)); } -//---------------------------------------------------------------------- // Constructor that compiles "re" using "flags" and stores the resulting // compiled regular expression into this object. -//---------------------------------------------------------------------- RegularExpression::RegularExpression(llvm::StringRef str) - : m_re(), m_comp_err(1), m_preg() { - memset(&m_preg, 0, sizeof(m_preg)); + : RegularExpression() { Compile(str); } -RegularExpression::RegularExpression(const RegularExpression &rhs) { - memset(&m_preg, 0, sizeof(m_preg)); +RegularExpression::RegularExpression(const RegularExpression &rhs) + : RegularExpression() { Compile(rhs.GetText()); } @@ -51,15 +45,12 @@ operator=(const RegularExpression &rhs) { return *this; } -//---------------------------------------------------------------------- // Destructor // // Any previously compiled regular expression contained in this object will be // freed. -//---------------------------------------------------------------------- RegularExpression::~RegularExpression() { Free(); } -//---------------------------------------------------------------------- // Compile a regular expression using the supplied regular expression text and // flags. The compiled regular expression lives in this object so that it can // be readily used for regular expression matches. Execute() can be called @@ -69,7 +60,6 @@ RegularExpression::~RegularExpression() { Free(); } // RETURNS // True if the regular expression compiles successfully, false // otherwise. -//---------------------------------------------------------------------- bool RegularExpression::Compile(llvm::StringRef str) { Free(); @@ -80,13 +70,11 @@ bool RegularExpression::Compile(llvm::StringRef str) { return m_comp_err == 0; } -//---------------------------------------------------------------------- // Execute a regular expression match using the compiled regular expression // that is already in this object against the match string "s". If any parens // are used for regular expression matches "match_count" should indicate the // number of regmatch_t values that are present in "match_ptr". The regular // expression will be executed using the "execute_flags". -//--------------------------------------------------------------------- bool RegularExpression::Execute(llvm::StringRef str, Match *match) const { int err = 1; if (m_comp_err == 0) { @@ -155,19 +143,13 @@ bool RegularExpression::Match::GetMatchSpanningIndices( return false; } -//---------------------------------------------------------------------- // Returns true if the regular expression compiled and is ready for execution. -//---------------------------------------------------------------------- bool RegularExpression::IsValid() const { return m_comp_err == 0; } -//---------------------------------------------------------------------- // Returns the text that was used to compile the current regular expression. -//---------------------------------------------------------------------- llvm::StringRef RegularExpression::GetText() const { return m_re; } -//---------------------------------------------------------------------- // Free any contained compiled regular expressions. -//---------------------------------------------------------------------- void RegularExpression::Free() { if (m_comp_err == 0) { m_re.clear(); diff --git a/source/Utility/Reproducer.cpp b/source/Utility/Reproducer.cpp index 6e85ba41767a..479ed311d1de 100644 --- a/source/Utility/Reproducer.cpp +++ b/source/Utility/Reproducer.cpp @@ -1,9 +1,8 @@ //===-- Reproducer.cpp ------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -52,6 +51,8 @@ llvm::Error Reproducer::Initialize(ReproducerMode mode, return Error::success(); } +bool Reproducer::Initialized() { return InstanceImpl().operator bool(); } + void Reproducer::Terminate() { lldbassert(InstanceImpl() && "Already terminated."); InstanceImpl().reset(); @@ -178,10 +179,13 @@ void Generator::AddProvidersToIndex() { sys::fs::OpenFlags::F_None); yaml::Output yout(*strm); + std::vector<std::string> files; + files.reserve(m_providers.size()); for (auto &provider : m_providers) { - auto &provider_info = provider.second->GetInfo(); - yout << const_cast<ProviderInfo &>(provider_info); + files.emplace_back(provider.second->GetFile()); } + + yout << files; } Loader::Loader(const FileSpec &root) : m_root(root), m_loaded(false) {} @@ -196,30 +200,86 @@ llvm::Error Loader::LoadIndex() { if (auto err = error_or_file.getError()) return make_error<StringError>("unable to load reproducer index", err); - std::vector<ProviderInfo> provider_info; yaml::Input yin((*error_or_file)->getBuffer()); - yin >> provider_info; - + yin >> m_files; if (auto err = yin.error()) return make_error<StringError>("unable to read reproducer index", err); - for (auto &info : provider_info) - m_provider_info[info.name] = info; + // Sort files to speed up search. + llvm::sort(m_files); + // Remember that we've loaded the index. m_loaded = true; return llvm::Error::success(); } -llvm::Optional<ProviderInfo> Loader::GetProviderInfo(StringRef name) { +bool Loader::HasFile(StringRef file) { assert(m_loaded); + auto it = std::lower_bound(m_files.begin(), m_files.end(), file.str()); + return (it != m_files.end()) && (*it == file); +} + +llvm::Expected<std::unique_ptr<DataRecorder>> +DataRecorder::Create(const FileSpec &filename) { + std::error_code ec; + auto recorder = llvm::make_unique<DataRecorder>(std::move(filename), ec); + if (ec) + return llvm::errorCodeToError(ec); + return std::move(recorder); +} + +DataRecorder *CommandProvider::GetNewDataRecorder() { + std::size_t i = m_data_recorders.size() + 1; + std::string filename = (llvm::Twine(Info::name) + llvm::Twine("-") + + llvm::Twine(i) + llvm::Twine(".txt")) + .str(); + auto recorder_or_error = + DataRecorder::Create(GetRoot().CopyByAppendingPathComponent(filename)); + if (!recorder_or_error) { + llvm::consumeError(recorder_or_error.takeError()); + return nullptr; + } + + m_data_recorders.push_back(std::move(*recorder_or_error)); + return m_data_recorders.back().get(); +} + +void CommandProvider::Keep() { + std::vector<std::string> files; + for (auto &recorder : m_data_recorders) { + recorder->Stop(); + files.push_back(recorder->GetFilename().GetPath()); + } + + FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file); + std::error_code ec; + llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::F_Text); + if (ec) + return; + yaml::Output yout(os); + yout << files; +} - auto it = m_provider_info.find(name); - if (it == m_provider_info.end()) - return llvm::None; +void CommandProvider::Discard() { m_data_recorders.clear(); } - return it->second; +void VersionProvider::Keep() { + FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file); + std::error_code ec; + llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::F_Text); + if (ec) + return; + os << m_version << "\n"; } void ProviderBase::anchor() {} char ProviderBase::ID = 0; +char CommandProvider::ID = 0; +char FileProvider::ID = 0; +char VersionProvider::ID = 0; +const char *CommandProvider::Info::file = "command-interpreter.yaml"; +const char *CommandProvider::Info::name = "command-interpreter"; +const char *FileProvider::Info::file = "files.yaml"; +const char *FileProvider::Info::name = "files"; +const char *VersionProvider::Info::file = "version.txt"; +const char *VersionProvider::Info::name = "version"; diff --git a/source/Utility/ReproducerInstrumentation.cpp b/source/Utility/ReproducerInstrumentation.cpp new file mode 100644 index 000000000000..473786ef4d3e --- /dev/null +++ b/source/Utility/ReproducerInstrumentation.cpp @@ -0,0 +1,122 @@ +//===-- ReproducerInstrumentation.cpp ---------------------------*- 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 "lldb/Utility/ReproducerInstrumentation.h" +#include "lldb/Utility/Reproducer.h" + +using namespace lldb_private; +using namespace lldb_private::repro; + +void *IndexToObject::GetObjectForIndexImpl(unsigned idx) { + return m_mapping.lookup(idx); +} + +void IndexToObject::AddObjectForIndexImpl(unsigned idx, void *object) { + assert(idx != 0 && "Cannot add object for sentinel"); + m_mapping[idx] = object; +} + +template <> char *Deserializer::Deserialize<char *>() { + return const_cast<char *>(Deserialize<const char *>()); +} + +template <> const char *Deserializer::Deserialize<const char *>() { + auto pos = m_buffer.find('\0'); + if (pos == llvm::StringRef::npos) + return nullptr; + const char *str = m_buffer.data(); + m_buffer = m_buffer.drop_front(pos + 1); + return str; +} + +bool Registry::Replay(const FileSpec &file) { + auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath()); + if (auto err = error_or_file.getError()) + return false; + + return Replay((*error_or_file)->getBuffer()); +} + +bool Registry::Replay(llvm::StringRef buffer) { +#ifndef LLDB_REPRO_INSTR_TRACE + Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_API); +#endif + + Deserializer deserializer(buffer); + while (deserializer.HasData(1)) { + unsigned id = deserializer.Deserialize<unsigned>(); + +#ifndef LLDB_REPRO_INSTR_TRACE + LLDB_LOG(log, "Replaying {0}: {1}", id, GetSignature(id)); +#else + llvm::errs() << "Replaying " << id << ": " << GetSignature(id) << "\n"; +#endif + + GetReplayer(id)->operator()(deserializer); + } + + return true; +} + +void Registry::DoRegister(uintptr_t RunID, std::unique_ptr<Replayer> replayer, + SignatureStr signature) { + const unsigned id = m_replayers.size() + 1; + assert(m_replayers.find(RunID) == m_replayers.end()); + m_replayers[RunID] = std::make_pair(std::move(replayer), id); + m_ids[id] = + std::make_pair(m_replayers[RunID].first.get(), std::move(signature)); +} + +unsigned Registry::GetID(uintptr_t addr) { + unsigned id = m_replayers[addr].second; + assert(id != 0 && "Forgot to add function to registry?"); + return id; +} + +std::string Registry::GetSignature(unsigned id) { + assert(m_ids.count(id) != 0 && "ID not in registry"); + return m_ids[id].second.ToString(); +} + +Replayer *Registry::GetReplayer(unsigned id) { + assert(m_ids.count(id) != 0 && "ID not in registry"); + return m_ids[id].first; +} + +std::string Registry::SignatureStr::ToString() const { + return (result + (result.empty() ? "" : " ") + scope + "::" + name + args) + .str(); +} + +unsigned ObjectToIndex::GetIndexForObjectImpl(const void *object) { + unsigned index = m_mapping.size() + 1; + auto it = m_mapping.find(object); + if (it == m_mapping.end()) + m_mapping[object] = index; + return m_mapping[object]; +} + +Recorder::Recorder(llvm::StringRef pretty_func, std::string &&pretty_args) + : m_serializer(nullptr), m_pretty_func(pretty_func), + m_pretty_args(pretty_args), m_local_boundary(false), + m_result_recorded(true) { + if (!g_global_boundary) { + g_global_boundary = true; + m_local_boundary = true; + + LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "{0} ({1})", + m_pretty_func, m_pretty_args); + } +} + +Recorder::~Recorder() { + assert(m_result_recorded && "Did you forget LLDB_RECORD_RESULT?"); + UpdateBoundary(); +} + +bool lldb_private::repro::Recorder::g_global_boundary; diff --git a/source/Utility/Scalar.cpp b/source/Utility/Scalar.cpp index a2bb86ffdb15..23d50b9eaba5 100644 --- a/source/Utility/Scalar.cpp +++ b/source/Utility/Scalar.cpp @@ -1,9 +1,8 @@ //===-- Scalar.cpp ----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -13,6 +12,7 @@ #include "lldb/Utility/Endian.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" +#include "lldb/Utility/StreamString.h" #include "lldb/lldb-types.h" #include "llvm/ADT/SmallString.h" @@ -23,10 +23,8 @@ using namespace lldb; using namespace lldb_private; -//---------------------------------------------------------------------- // Promote to max type currently follows the ANSI C rule for type promotion in // expressions. -//---------------------------------------------------------------------- static Scalar::Type PromoteToMaxType( const Scalar &lhs, // The const left hand side object const Scalar &rhs, // The const right hand side object @@ -71,10 +69,7 @@ static Scalar::Type PromoteToMaxType( return Scalar::e_void; } -Scalar::Scalar() : m_type(e_void), m_float((float)0) {} - -Scalar::Scalar(const Scalar &rhs) - : m_type(rhs.m_type), m_integer(rhs.m_integer), m_float(rhs.m_float) {} +Scalar::Scalar() : m_type(e_void), m_float(static_cast<float>(0)) {} bool Scalar::GetData(DataExtractor &data, size_t limit_byte_size) const { size_t byte_size = GetByteSize(); @@ -107,7 +102,7 @@ const void *Scalar::GetBytes() const { const uint8_t *bytes; static float_t flt_val; static double_t dbl_val; - static uint64_t swapped_words[4]; + static uint64_t swapped_words[8]; switch (m_type) { case e_void: break; @@ -126,12 +121,12 @@ const void *Scalar::GetBytes() const { bytes += 8 - byte_size; } return bytes; + // getRawData always returns a pointer to an array of uint64_t values, + // where the least-significant word always comes first. On big-endian + // systems we need to swap the words. case e_sint128: case e_uint128: apint_words = m_integer.getRawData(); - // getRawData always returns a pointer to an array of two uint64_t values, - // where the least-significant word always comes first. On big-endian - // systems we need to swap the two words. if (endian::InlHostByteOrder() == eByteOrderBig) { swapped_words[0] = apint_words[1]; swapped_words[1] = apint_words[0]; @@ -141,9 +136,6 @@ const void *Scalar::GetBytes() const { case e_sint256: case e_uint256: apint_words = m_integer.getRawData(); - // getRawData always returns a pointer to an array of four uint64_t values, - // where the least-significant word always comes first. On big-endian - // systems we need to swap the four words. if (endian::InlHostByteOrder() == eByteOrderBig) { swapped_words[0] = apint_words[3]; swapped_words[1] = apint_words[2]; @@ -152,6 +144,21 @@ const void *Scalar::GetBytes() const { apint_words = swapped_words; } return reinterpret_cast<const void *>(apint_words); + case e_sint512: + case e_uint512: + apint_words = m_integer.getRawData(); + if (endian::InlHostByteOrder() == eByteOrderBig) { + swapped_words[0] = apint_words[7]; + swapped_words[1] = apint_words[6]; + swapped_words[2] = apint_words[5]; + swapped_words[3] = apint_words[4]; + swapped_words[4] = apint_words[3]; + swapped_words[5] = apint_words[2]; + swapped_words[6] = apint_words[1]; + swapped_words[7] = apint_words[0]; + apint_words = swapped_words; + } + return reinterpret_cast<const void *>(apint_words); case e_float: flt_val = m_float.convertToFloat(); return reinterpret_cast<const void *>(&flt_val); @@ -188,6 +195,8 @@ size_t Scalar::GetByteSize() const { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: return (m_integer.getBitWidth() / 8); case e_float: return sizeof(float_t); @@ -214,6 +223,8 @@ bool Scalar::IsZero() const { case e_uint128: case e_sint256: case e_uint256: + case e_uint512: + case e_sint512: return llvm::APInt::isSameValue(zero_int, m_integer); case e_float: case e_double: @@ -235,6 +246,7 @@ void Scalar::GetValue(Stream *s, bool show_type) const { case e_slonglong: case e_sint128: case e_sint256: + case e_sint512: s->PutCString(m_integer.toString(10, true)); break; case e_uint: @@ -242,6 +254,7 @@ void Scalar::GetValue(Stream *s, bool show_type) const { case e_ulonglong: case e_uint128: case e_uint256: + case e_uint512: s->PutCString(m_integer.toString(10, false)); break; case e_float: @@ -278,6 +291,10 @@ const char *Scalar::GetTypeAsCString() const { return "int256_t"; case e_uint256: return "unsigned int256_t"; + case e_sint512: + return "int512_t"; + case e_uint512: + return "unsigned int512_t"; case e_float: return "float"; case e_double: @@ -348,13 +365,13 @@ Scalar &Scalar::operator=(double v) { Scalar &Scalar::operator=(long double v) { m_type = e_long_double; if (m_ieee_quad) - m_float = llvm::APFloat( - llvm::APFloat::IEEEquad(), - llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x)); + m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), + llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, + (reinterpret_cast<type128 *>(&v))->x)); else - m_float = llvm::APFloat( - llvm::APFloat::x87DoubleExtended(), - llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x)); + m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), + llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, + (reinterpret_cast<type128 *>(&v))->x)); return *this; } @@ -387,6 +404,12 @@ Scalar &Scalar::operator=(llvm::APInt rhs) { else m_type = e_uint256; break; + case 512: + if (m_integer.isSignedIntN(BITWIDTH_INT512)) + m_type = e_sint512; + else + m_type = e_uint512; + break; } return *this; } @@ -443,6 +466,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.sextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, true, @@ -507,6 +536,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.zextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, false, @@ -567,6 +602,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.sextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, true, @@ -623,6 +664,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.zextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, false, @@ -675,6 +722,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.sextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, true, @@ -723,6 +776,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.zextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, false, @@ -771,6 +830,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.sextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, true, @@ -815,6 +880,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.zextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, false, @@ -859,6 +930,12 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; + case e_sint512: + case e_uint512: + m_integer = m_integer.zextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, true, @@ -899,6 +976,13 @@ bool Scalar::Promote(Scalar::Type type) { case e_uint256: success = true; break; + + case e_sint512: + case e_uint512: + m_integer = m_integer.zextOrTrunc(BITWIDTH_INT512); + success = true; + break; + case e_float: m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); m_float.convertFromAPInt(m_integer, false, @@ -923,6 +1007,11 @@ bool Scalar::Promote(Scalar::Type type) { } break; + case e_sint512: + case e_uint512: + lldbassert(false && "unimplemented"); + break; + case e_float: switch (type) { case e_void: @@ -936,12 +1025,14 @@ bool Scalar::Promote(Scalar::Type type) { case e_uint128: case e_sint256: case e_uint256: + case e_uint512: + case e_sint512: break; case e_float: success = true; break; case e_double: - m_float = llvm::APFloat((double_t)m_float.convertToFloat()); + m_float = llvm::APFloat(static_cast<double_t>(m_float.convertToFloat())); success = true; break; @@ -969,6 +1060,8 @@ bool Scalar::Promote(Scalar::Type type) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: case e_float: break; case e_double: @@ -998,6 +1091,8 @@ bool Scalar::Promote(Scalar::Type type) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: case e_float: case e_double: break; @@ -1043,6 +1138,10 @@ const char *Scalar::GetValueTypeAsCString(Scalar::Type type) { return "int256_t"; case e_uint256: return "uint256_t"; + case e_sint512: + return "int512_t"; + case e_uint512: + return "uint512_t"; } return "???"; } @@ -1120,6 +1219,13 @@ bool Scalar::MakeSigned() { m_type = e_sint256; success = true; break; + case e_sint512: + success = true; + break; + case e_uint512: + m_type = e_sint512; + success = true; + break; case e_float: success = true; break; @@ -1175,6 +1281,13 @@ bool Scalar::MakeUnsigned() { case e_uint256: success = true; break; + case e_sint512: + m_type = e_uint512; + success = true; + break; + case e_uint512: + success = true; + break; case e_float: success = true; break; @@ -1203,14 +1316,18 @@ signed char Scalar::SChar(char fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (schar_t)(m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue(); + case e_sint512: + case e_uint512: + return static_cast<schar_t>( + (m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue()); case e_float: - return (schar_t)m_float.convertToFloat(); + return static_cast<schar_t>(m_float.convertToFloat()); case e_double: - return (schar_t)m_float.convertToDouble(); + return static_cast<schar_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (schar_t)(ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue(); + return static_cast<schar_t>( + (ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue()); } return fail_value; } @@ -1229,14 +1346,18 @@ unsigned char Scalar::UChar(unsigned char fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (uchar_t)(m_integer.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue(); + case e_sint512: + case e_uint512: + return static_cast<uchar_t>( + (m_integer.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue()); case e_float: - return (uchar_t)m_float.convertToFloat(); + return static_cast<uchar_t>(m_float.convertToFloat()); case e_double: - return (uchar_t)m_float.convertToDouble(); + return static_cast<uchar_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (uchar_t)(ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue(); + return static_cast<uchar_t>( + (ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue()); } return fail_value; } @@ -1255,16 +1376,18 @@ short Scalar::SShort(short fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (sshort_t)(m_integer.sextOrTrunc(sizeof(sshort_t) * 8)) - .getSExtValue(); + case e_sint512: + case e_uint512: + return static_cast<sshort_t>( + (m_integer.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue()); case e_float: - return (sshort_t)m_float.convertToFloat(); + return static_cast<sshort_t>(m_float.convertToFloat()); case e_double: - return (sshort_t)m_float.convertToDouble(); + return static_cast<sshort_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (sshort_t)(ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8)) - .getSExtValue(); + return static_cast<sshort_t>( + (ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue()); } return fail_value; } @@ -1283,16 +1406,18 @@ unsigned short Scalar::UShort(unsigned short fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (ushort_t)(m_integer.zextOrTrunc(sizeof(ushort_t) * 8)) - .getZExtValue(); + case e_sint512: + case e_uint512: + return static_cast<ushort_t>( + (m_integer.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue()); case e_float: - return (ushort_t)m_float.convertToFloat(); + return static_cast<ushort_t>(m_float.convertToFloat()); case e_double: - return (ushort_t)m_float.convertToDouble(); + return static_cast<ushort_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (ushort_t)(ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8)) - .getZExtValue(); + return static_cast<ushort_t>( + (ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue()); } return fail_value; } @@ -1311,14 +1436,18 @@ int Scalar::SInt(int fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (sint_t)(m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue(); + case e_sint512: + case e_uint512: + return static_cast<sint_t>( + (m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue()); case e_float: - return (sint_t)m_float.convertToFloat(); + return static_cast<sint_t>(m_float.convertToFloat()); case e_double: - return (sint_t)m_float.convertToDouble(); + return static_cast<sint_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (sint_t)(ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue(); + return static_cast<sint_t>( + (ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue()); } return fail_value; } @@ -1337,14 +1466,18 @@ unsigned int Scalar::UInt(unsigned int fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (uint_t)(m_integer.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue(); + case e_sint512: + case e_uint512: + return static_cast<uint_t>( + (m_integer.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue()); case e_float: - return (uint_t)m_float.convertToFloat(); + return static_cast<uint_t>(m_float.convertToFloat()); case e_double: - return (uint_t)m_float.convertToDouble(); + return static_cast<uint_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (uint_t)(ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue(); + return static_cast<uint_t>( + (ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue()); } return fail_value; } @@ -1363,14 +1496,18 @@ long Scalar::SLong(long fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (slong_t)(m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue(); + case e_sint512: + case e_uint512: + return static_cast<slong_t>( + (m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue()); case e_float: - return (slong_t)m_float.convertToFloat(); + return static_cast<slong_t>(m_float.convertToFloat()); case e_double: - return (slong_t)m_float.convertToDouble(); + return static_cast<slong_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (slong_t)(ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue(); + return static_cast<slong_t>( + (ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue()); } return fail_value; } @@ -1389,14 +1526,18 @@ unsigned long Scalar::ULong(unsigned long fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (ulong_t)(m_integer.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue(); + case e_sint512: + case e_uint512: + return static_cast<ulong_t>( + (m_integer.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue()); case e_float: - return (ulong_t)m_float.convertToFloat(); + return static_cast<ulong_t>(m_float.convertToFloat()); case e_double: - return (ulong_t)m_float.convertToDouble(); + return static_cast<ulong_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (ulong_t)(ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue(); + return static_cast<ulong_t>( + (ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue()); } return fail_value; } @@ -1415,16 +1556,18 @@ long long Scalar::SLongLong(long long fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (slonglong_t)(m_integer.sextOrTrunc(sizeof(slonglong_t) * 8)) - .getSExtValue(); + case e_sint512: + case e_uint512: + return static_cast<slonglong_t>( + (m_integer.sextOrTrunc(sizeof(slonglong_t) * 8)).getSExtValue()); case e_float: - return (slonglong_t)m_float.convertToFloat(); + return static_cast<slonglong_t>(m_float.convertToFloat()); case e_double: - return (slonglong_t)m_float.convertToDouble(); + return static_cast<slonglong_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (slonglong_t)(ldbl_val.sextOrTrunc(sizeof(slonglong_t) * 8)) - .getSExtValue(); + return static_cast<slonglong_t>( + (ldbl_val.sextOrTrunc(sizeof(slonglong_t) * 8)).getSExtValue()); } return fail_value; } @@ -1443,21 +1586,23 @@ unsigned long long Scalar::ULongLong(unsigned long long fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (ulonglong_t)(m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8)) - .getZExtValue(); + case e_sint512: + case e_uint512: + return static_cast<ulonglong_t>( + (m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue()); case e_float: - return (ulonglong_t)m_float.convertToFloat(); + return static_cast<ulonglong_t>(m_float.convertToFloat()); case e_double: { double d_val = m_float.convertToDouble(); llvm::APInt rounded_double = llvm::APIntOps::RoundDoubleToAPInt(d_val, sizeof(ulonglong_t) * 8); - return (ulonglong_t)(rounded_double.zextOrTrunc(sizeof(ulonglong_t) * 8)) - .getZExtValue(); + return static_cast<ulonglong_t>( + (rounded_double.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue()); } case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (ulonglong_t)(ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8)) - .getZExtValue(); + return static_cast<ulonglong_t>( + (ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue()); } return fail_value; } @@ -1476,6 +1621,8 @@ llvm::APInt Scalar::SInt128(llvm::APInt &fail_value) const { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: return m_integer; case e_float: case e_double: @@ -1499,52 +1646,8 @@ llvm::APInt Scalar::UInt128(const llvm::APInt &fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return m_integer; - case e_float: - case e_double: - case e_long_double: - return m_float.bitcastToAPInt(); - } - return fail_value; -} - -llvm::APInt Scalar::SInt256(llvm::APInt &fail_value) const { - switch (m_type) { - case e_void: - break; - case e_sint: - case e_uint: - case e_slong: - case e_ulong: - case e_slonglong: - case e_ulonglong: - case e_sint128: - case e_uint128: - case e_sint256: - case e_uint256: - return m_integer; - case e_float: - case e_double: - case e_long_double: - return m_float.bitcastToAPInt(); - } - return fail_value; -} - -llvm::APInt Scalar::UInt256(const llvm::APInt &fail_value) const { - switch (m_type) { - case e_void: - break; - case e_sint: - case e_uint: - case e_slong: - case e_ulong: - case e_slonglong: - case e_ulonglong: - case e_sint128: - case e_uint128: - case e_sint256: - case e_uint256: + case e_sint512: + case e_uint512: return m_integer; case e_float: case e_double: @@ -1568,11 +1671,13 @@ float Scalar::Float(float fail_value) const { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: return llvm::APIntOps::RoundAPIntToFloat(m_integer); case e_float: return m_float.convertToFloat(); case e_double: - return (float_t)m_float.convertToDouble(); + return static_cast<float_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); return ldbl_val.bitsToFloat(); @@ -1594,9 +1699,11 @@ double Scalar::Double(double fail_value) const { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: return llvm::APIntOps::RoundAPIntToDouble(m_integer); case e_float: - return (double_t)m_float.convertToFloat(); + return static_cast<double_t>(m_float.convertToFloat()); case e_double: return m_float.convertToDouble(); case e_long_double: @@ -1620,14 +1727,17 @@ long double Scalar::LongDouble(long double fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (long_double_t)llvm::APIntOps::RoundAPIntToDouble(m_integer); + case e_sint512: + case e_uint512: + return static_cast<long_double_t>( + llvm::APIntOps::RoundAPIntToDouble(m_integer)); case e_float: - return (long_double_t)m_float.convertToFloat(); + return static_cast<long_double_t>(m_float.convertToFloat()); case e_double: - return (long_double_t)m_float.convertToDouble(); + return static_cast<long_double_t>(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return (long_double_t)ldbl_val.bitsToDouble(); + return static_cast<long_double_t>(ldbl_val.bitsToDouble()); } return fail_value; } @@ -1651,6 +1761,8 @@ Scalar &Scalar::operator+=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer = a->m_integer + b->m_integer; break; @@ -1683,6 +1795,8 @@ Scalar &Scalar::operator<<=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: switch (rhs.m_type) { case e_void: case e_float: @@ -1700,6 +1814,8 @@ Scalar &Scalar::operator<<=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer = m_integer << rhs.m_integer; break; } @@ -1727,6 +1843,8 @@ bool Scalar::ShiftRightLogical(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: switch (rhs.m_type) { case e_void: case e_float: @@ -1744,6 +1862,8 @@ bool Scalar::ShiftRightLogical(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer = m_integer.lshr(rhs.m_integer); break; } @@ -1771,6 +1891,8 @@ Scalar &Scalar::operator>>=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: switch (rhs.m_type) { case e_void: case e_float: @@ -1788,6 +1910,8 @@ Scalar &Scalar::operator>>=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer = m_integer.ashr(rhs.m_integer); break; } @@ -1815,6 +1939,8 @@ Scalar &Scalar::operator&=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: switch (rhs.m_type) { case e_void: case e_float: @@ -1832,6 +1958,8 @@ Scalar &Scalar::operator&=(const Scalar &rhs) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer &= rhs.m_integer; break; } @@ -1850,6 +1978,7 @@ bool Scalar::AbsoluteValue() { case e_slonglong: case e_sint128: case e_sint256: + case e_sint512: if (m_integer.isNegative()) m_integer = -m_integer; return true; @@ -1860,6 +1989,7 @@ bool Scalar::AbsoluteValue() { return true; case e_uint128: case e_uint256: + case e_uint512: case e_float: case e_double: case e_long_double: @@ -1883,6 +2013,8 @@ bool Scalar::UnaryNegate() { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer = -m_integer; return true; case e_float: @@ -1906,6 +2038,8 @@ bool Scalar::OnesComplement() { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer = ~m_integer; return true; @@ -1938,6 +2072,8 @@ const Scalar lldb_private::operator+(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: result.m_integer = a->m_integer + b->m_integer; break; case Scalar::e_float: @@ -1970,6 +2106,8 @@ const Scalar lldb_private::operator-(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: result.m_integer = a->m_integer - b->m_integer; break; case Scalar::e_float: @@ -1997,6 +2135,7 @@ const Scalar lldb_private::operator/(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_slonglong: case Scalar::e_sint128: case Scalar::e_sint256: + case Scalar::e_sint512: if (b->m_integer != 0) { result.m_integer = a->m_integer.sdiv(b->m_integer); return result; @@ -2007,6 +2146,7 @@ const Scalar lldb_private::operator/(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_ulonglong: case Scalar::e_uint128: case Scalar::e_uint256: + case Scalar::e_uint512: if (b->m_integer != 0) { result.m_integer = a->m_integer.udiv(b->m_integer); return result; @@ -2048,6 +2188,8 @@ const Scalar lldb_private::operator*(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: result.m_integer = a->m_integer * b->m_integer; break; case Scalar::e_float: @@ -2078,6 +2220,8 @@ const Scalar lldb_private::operator&(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: result.m_integer = a->m_integer & b->m_integer; break; case Scalar::e_void: @@ -2110,6 +2254,8 @@ const Scalar lldb_private::operator|(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: result.m_integer = a->m_integer | b->m_integer; break; @@ -2142,6 +2288,7 @@ const Scalar lldb_private::operator%(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_slonglong: case Scalar::e_sint128: case Scalar::e_sint256: + case Scalar::e_sint512: if (b->m_integer != 0) { result.m_integer = a->m_integer.srem(b->m_integer); return result; @@ -2152,6 +2299,7 @@ const Scalar lldb_private::operator%(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_ulonglong: case Scalar::e_uint128: case Scalar::e_uint256: + case Scalar::e_uint512: if (b->m_integer != 0) { result.m_integer = a->m_integer.urem(b->m_integer); return result; @@ -2181,6 +2329,8 @@ const Scalar lldb_private::operator^(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: result.m_integer = a->m_integer ^ b->m_integer; break; @@ -2227,10 +2377,10 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, error.SetErrorStringWithFormat( "'%s' is not a valid unsigned integer string value", value_str); else if (!UIntValueIsValidForSize(uval64, byte_size)) - error.SetErrorStringWithFormat("value 0x%" PRIx64 - " is too large to fit in a %" PRIu64 - " byte unsigned integer value", - uval64, (uint64_t)byte_size); + error.SetErrorStringWithFormat( + "value 0x%" PRIx64 " is too large to fit in a %" PRIu64 + " byte unsigned integer value", + uval64, static_cast<uint64_t>(byte_size)); else { m_type = Scalar::GetValueTypeForUnsignedIntegerWithByteSize(byte_size); switch (m_type) { @@ -2246,14 +2396,14 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, default: error.SetErrorStringWithFormat( "unsupported unsigned integer byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); break; } } } else { error.SetErrorStringWithFormat( "unsupported unsigned integer byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); return error; } break; @@ -2265,10 +2415,10 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, error.SetErrorStringWithFormat( "'%s' is not a valid signed integer string value", value_str); else if (!SIntValueIsValidForSize(sval64, byte_size)) - error.SetErrorStringWithFormat("value 0x%" PRIx64 - " is too large to fit in a %" PRIu64 - " byte signed integer value", - sval64, (uint64_t)byte_size); + error.SetErrorStringWithFormat( + "value 0x%" PRIx64 " is too large to fit in a %" PRIu64 + " byte signed integer value", + sval64, static_cast<uint64_t>(byte_size)); else { m_type = Scalar::GetValueTypeForSignedIntegerWithByteSize(byte_size); switch (m_type) { @@ -2284,14 +2434,14 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, default: error.SetErrorStringWithFormat( "unsupported signed integer byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); break; } } } else { error.SetErrorStringWithFormat( "unsupported signed integer byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); return error; } break; @@ -2316,17 +2466,17 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, value_str); } else if (byte_size == sizeof(long double)) { if (::sscanf(value_str, "%Lf", &l_val) == 1) { - m_float = - llvm::APFloat(llvm::APFloat::x87DoubleExtended(), - llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, - ((type128 *)&l_val)->x)); + m_float = llvm::APFloat( + llvm::APFloat::x87DoubleExtended(), + llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, + (reinterpret_cast<type128 *>(&l_val))->x)); m_type = e_long_double; } else error.SetErrorStringWithFormat("'%s' is not a valid float string value", value_str); } else { error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); return error; } break; @@ -2359,45 +2509,45 @@ Status Scalar::SetValueFromData(DataExtractor &data, lldb::Encoding encoding, switch (byte_size) { case 1: - operator=((uint8_t)data.GetU8(&offset)); + operator=(data.GetU8(&offset)); break; case 2: - operator=((uint16_t)data.GetU16(&offset)); + operator=(data.GetU16(&offset)); break; case 4: - operator=((uint32_t)data.GetU32(&offset)); + operator=(data.GetU32(&offset)); break; case 8: - operator=((uint64_t)data.GetU64(&offset)); + operator=(data.GetU64(&offset)); break; case 16: if (data.GetByteOrder() == eByteOrderBig) { - int128.x[1] = (uint64_t)data.GetU64(&offset); - int128.x[0] = (uint64_t)data.GetU64(&offset); + int128.x[1] = data.GetU64(&offset); + int128.x[0] = data.GetU64(&offset); } else { - int128.x[0] = (uint64_t)data.GetU64(&offset); - int128.x[1] = (uint64_t)data.GetU64(&offset); + int128.x[0] = data.GetU64(&offset); + int128.x[1] = data.GetU64(&offset); } operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x)); break; case 32: if (data.GetByteOrder() == eByteOrderBig) { - int256.x[3] = (uint64_t)data.GetU64(&offset); - int256.x[2] = (uint64_t)data.GetU64(&offset); - int256.x[1] = (uint64_t)data.GetU64(&offset); - int256.x[0] = (uint64_t)data.GetU64(&offset); + int256.x[3] = data.GetU64(&offset); + int256.x[2] = data.GetU64(&offset); + int256.x[1] = data.GetU64(&offset); + int256.x[0] = data.GetU64(&offset); } else { - int256.x[0] = (uint64_t)data.GetU64(&offset); - int256.x[1] = (uint64_t)data.GetU64(&offset); - int256.x[2] = (uint64_t)data.GetU64(&offset); - int256.x[3] = (uint64_t)data.GetU64(&offset); + int256.x[0] = data.GetU64(&offset); + int256.x[1] = data.GetU64(&offset); + int256.x[2] = data.GetU64(&offset); + int256.x[3] = data.GetU64(&offset); } operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x)); break; default: error.SetErrorStringWithFormat( "unsupported unsigned integer byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); break; } } break; @@ -2406,45 +2556,45 @@ Status Scalar::SetValueFromData(DataExtractor &data, lldb::Encoding encoding, switch (byte_size) { case 1: - operator=((int8_t)data.GetU8(&offset)); + operator=(static_cast<int8_t>(data.GetU8(&offset))); break; case 2: - operator=((int16_t)data.GetU16(&offset)); + operator=(static_cast<int16_t>(data.GetU16(&offset))); break; case 4: - operator=((int32_t)data.GetU32(&offset)); + operator=(static_cast<int32_t>(data.GetU32(&offset))); break; case 8: - operator=((int64_t)data.GetU64(&offset)); + operator=(static_cast<int64_t>(data.GetU64(&offset))); break; case 16: if (data.GetByteOrder() == eByteOrderBig) { - int128.x[1] = (uint64_t)data.GetU64(&offset); - int128.x[0] = (uint64_t)data.GetU64(&offset); + int128.x[1] = data.GetU64(&offset); + int128.x[0] = data.GetU64(&offset); } else { - int128.x[0] = (uint64_t)data.GetU64(&offset); - int128.x[1] = (uint64_t)data.GetU64(&offset); + int128.x[0] = data.GetU64(&offset); + int128.x[1] = data.GetU64(&offset); } operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x)); break; case 32: if (data.GetByteOrder() == eByteOrderBig) { - int256.x[3] = (uint64_t)data.GetU64(&offset); - int256.x[2] = (uint64_t)data.GetU64(&offset); - int256.x[1] = (uint64_t)data.GetU64(&offset); - int256.x[0] = (uint64_t)data.GetU64(&offset); + int256.x[3] = data.GetU64(&offset); + int256.x[2] = data.GetU64(&offset); + int256.x[1] = data.GetU64(&offset); + int256.x[0] = data.GetU64(&offset); } else { - int256.x[0] = (uint64_t)data.GetU64(&offset); - int256.x[1] = (uint64_t)data.GetU64(&offset); - int256.x[2] = (uint64_t)data.GetU64(&offset); - int256.x[3] = (uint64_t)data.GetU64(&offset); + int256.x[0] = data.GetU64(&offset); + int256.x[1] = data.GetU64(&offset); + int256.x[2] = data.GetU64(&offset); + int256.x[3] = data.GetU64(&offset); } operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x)); break; default: error.SetErrorStringWithFormat( "unsupported signed integer byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); break; } } break; @@ -2452,14 +2602,14 @@ Status Scalar::SetValueFromData(DataExtractor &data, lldb::Encoding encoding, lldb::offset_t offset = 0; if (byte_size == sizeof(float)) - operator=((float)data.GetFloat(&offset)); + operator=(data.GetFloat(&offset)); else if (byte_size == sizeof(double)) - operator=((double)data.GetDouble(&offset)); + operator=(data.GetDouble(&offset)); else if (byte_size == sizeof(long double)) - operator=((long double)data.GetLongDouble(&offset)); + operator=(data.GetLongDouble(&offset)); else error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "", - (uint64_t)byte_size); + static_cast<uint64_t>(byte_size)); } break; } @@ -2487,6 +2637,8 @@ bool Scalar::SignExtend(uint32_t sign_bit_pos) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: if (max_bit_pos == sign_bit_pos) return true; else if (sign_bit_pos < (max_bit_pos - 1)) { @@ -2546,6 +2698,7 @@ bool Scalar::ExtractBitfield(uint32_t bit_size, uint32_t bit_offset) { case Scalar::e_slonglong: case Scalar::e_sint128: case Scalar::e_sint256: + case Scalar::e_sint512: m_integer = m_integer.ashr(bit_offset) .sextOrTrunc(bit_size) .sextOrSelf(8 * GetByteSize()); @@ -2556,6 +2709,7 @@ bool Scalar::ExtractBitfield(uint32_t bit_size, uint32_t bit_offset) { case Scalar::e_ulonglong: case Scalar::e_uint128: case Scalar::e_uint256: + case Scalar::e_uint512: m_integer = m_integer.lshr(bit_offset) .zextOrTrunc(bit_size) .zextOrSelf(8 * GetByteSize()); @@ -2586,6 +2740,8 @@ bool lldb_private::operator==(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_uint128: case Scalar::e_sint256: case Scalar::e_uint256: + case Scalar::e_sint512: + case Scalar::e_uint512: return a->m_integer == b->m_integer; case Scalar::e_float: case Scalar::e_double: @@ -2617,6 +2773,8 @@ bool lldb_private::operator<(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_slonglong: case Scalar::e_sint128: case Scalar::e_sint256: + case Scalar::e_sint512: + case Scalar::e_uint512: return a->m_integer.slt(b->m_integer); case Scalar::e_uint: case Scalar::e_ulong: @@ -2660,6 +2818,8 @@ bool Scalar::ClearBit(uint32_t bit) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer.clearBit(bit); return true; case e_float: @@ -2684,6 +2844,8 @@ bool Scalar::SetBit(uint32_t bit) { case e_uint128: case e_sint256: case e_uint256: + case e_sint512: + case e_uint512: m_integer.setBit(bit); return true; case e_float: @@ -2693,3 +2855,9 @@ bool Scalar::SetBit(uint32_t bit) { } return false; } + +llvm::raw_ostream &lldb_private::operator<<(llvm::raw_ostream &os, const Scalar &scalar) { + StreamString s; + scalar.GetValue(&s, /*show_type*/ true); + return os << s.GetString(); +} diff --git a/source/Utility/SelectHelper.cpp b/source/Utility/SelectHelper.cpp index 2979a67dc182..ff21d99e400a 100644 --- a/source/Utility/SelectHelper.cpp +++ b/source/Utility/SelectHelper.cpp @@ -1,9 +1,8 @@ //===-- SelectHelper.cpp ----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -133,9 +132,7 @@ lldb_private::Status SelectHelper::Select() { fd_set *read_fdset_ptr = nullptr; fd_set *write_fdset_ptr = nullptr; fd_set *error_fdset_ptr = nullptr; -//---------------------------------------------------------------------- // Initialize and zero out the fdsets -//---------------------------------------------------------------------- #if defined(__APPLE__) llvm::SmallVector<fd_set, 1> read_fdset; llvm::SmallVector<fd_set, 1> write_fdset; @@ -177,9 +174,7 @@ lldb_private::Status SelectHelper::Select() { error_fdset_ptr = &error_fdset; } #endif - //---------------------------------------------------------------------- // Set the FD bits in the fdsets for read/write/error - //---------------------------------------------------------------------- for (auto &pair : m_fd_map) { const lldb::socket_t fd = pair.first; @@ -193,17 +188,13 @@ lldb_private::Status SelectHelper::Select() { FD_SET(fd, error_fdset_ptr); } - //---------------------------------------------------------------------- // Setup our timeout time value if needed - //---------------------------------------------------------------------- struct timeval *tv_ptr = nullptr; struct timeval tv = {0, 0}; - while (1) { + while (true) { using namespace std::chrono; - //------------------------------------------------------------------ // Setup out relative timeout based on the end time if we have one - //------------------------------------------------------------------ if (m_end_time.hasValue()) { tv_ptr = &tv; const auto remaining_dur = duration_cast<microseconds>( diff --git a/source/Utility/SharingPtr.cpp b/source/Utility/SharingPtr.cpp index bdaedfb9b049..45f2a773758b 100644 --- a/source/Utility/SharingPtr.cpp +++ b/source/Utility/SharingPtr.cpp @@ -1,9 +1,8 @@ //===---------------------SharingPtr.cpp ------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/State.cpp b/source/Utility/State.cpp index 6ff8a4940b0f..51fe92bad77e 100644 --- a/source/Utility/State.cpp +++ b/source/Utility/State.cpp @@ -1,9 +1,8 @@ //===-- State.cpp -----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/Status.cpp b/source/Utility/Status.cpp index 062bd261ea8b..3d64fb810abf 100644 --- a/source/Utility/Status.cpp +++ b/source/Utility/Status.cpp @@ -1,10 +1,9 @@ //===-- Status.cpp -----------------------------------------------*- C++ //-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -48,8 +47,6 @@ Status::Status(std::error_code EC) : m_code(EC.value()), m_type(ErrorType::eErrorTypeGeneric), m_string(EC.message()) {} -Status::Status(const Status &rhs) = default; - Status::Status(const char *format, ...) : m_code(0), m_type(eErrorTypeInvalid), m_string() { va_list args; @@ -96,9 +93,7 @@ llvm::Error Status::ToError() const { llvm::inconvertibleErrorCode()); } -//---------------------------------------------------------------------- // Assignment operator -//---------------------------------------------------------------------- const Status &Status::operator=(const Status &rhs) { if (this != &rhs) { m_code = rhs.m_code; @@ -127,11 +122,9 @@ static std::string RetrieveWin32ErrorString(uint32_t error_code) { } #endif -//---------------------------------------------------------------------- // Get the error value as a NULL C string. The error string will be fetched and // cached on demand. The cached error string value will remain until the error // value is changed or cleared. -//---------------------------------------------------------------------- const char *Status::AsCString(const char *default_error_str) const { if (Success()) return nullptr; @@ -168,35 +161,25 @@ const char *Status::AsCString(const char *default_error_str) const { return m_string.c_str(); } -//---------------------------------------------------------------------- // Clear the error and any cached error string that it might contain. -//---------------------------------------------------------------------- void Status::Clear() { m_code = 0; m_type = eErrorTypeInvalid; m_string.clear(); } -//---------------------------------------------------------------------- // Access the error value. -//---------------------------------------------------------------------- Status::ValueType Status::GetError() const { return m_code; } -//---------------------------------------------------------------------- // Access the error type. -//---------------------------------------------------------------------- ErrorType Status::GetType() const { return m_type; } -//---------------------------------------------------------------------- // Returns true if this object contains a value that describes an error or // 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; @@ -227,40 +210,32 @@ int Status::SetExpressionErrorWithFormat(lldb::ExpressionResults result, return length; } -//---------------------------------------------------------------------- // Set accessor for the error value and type. -//---------------------------------------------------------------------- void Status::SetError(ValueType err, ErrorType type) { m_code = err; m_type = type; m_string.clear(); } -//---------------------------------------------------------------------- // Update the error value to be "errno" and update the type to be "POSIX". -//---------------------------------------------------------------------- void Status::SetErrorToErrno() { m_code = errno; m_type = eErrorTypePOSIX; m_string.clear(); } -//---------------------------------------------------------------------- // Update the error value to be LLDB_GENERIC_ERROR and update the type to be // "Generic". -//---------------------------------------------------------------------- void Status::SetErrorToGenericError() { m_code = LLDB_GENERIC_ERROR; m_type = eErrorTypeGeneric; m_string.clear(); } -//---------------------------------------------------------------------- // Set accessor for the error string value for a specific error. This allows // any string to be supplied as an error explanation. The error string value // will remain until the error value is cleared or a new error value/type is // assigned. -//---------------------------------------------------------------------- void Status::SetErrorString(llvm::StringRef err_str) { if (!err_str.empty()) { // If we have an error string, we should always at least have an error set @@ -271,12 +246,10 @@ void Status::SetErrorString(llvm::StringRef err_str) { m_string = err_str; } -//------------------------------------------------------------------ /// Set the current error string to a formatted error string. /// -/// @param format +/// \param format /// A printf style format string -//------------------------------------------------------------------ int Status::SetErrorStringWithFormat(const char *format, ...) { if (format != nullptr && format[0]) { va_list args; @@ -307,10 +280,8 @@ int Status::SetErrorStringWithVarArg(const char *format, va_list args) { return 0; } -//---------------------------------------------------------------------- // Returns true if the error code in this object is considered a successful // return value. -//---------------------------------------------------------------------- bool Status::Success() const { return m_code == 0; } bool Status::WasInterrupted() const { diff --git a/source/Utility/Stream.cpp b/source/Utility/Stream.cpp index 54691c7066db..c48a12acd906 100644 --- a/source/Utility/Stream.cpp +++ b/source/Utility/Stream.cpp @@ -1,9 +1,8 @@ //===-- Stream.cpp ----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -30,9 +29,7 @@ Stream::Stream() : m_flags(0), m_addr_size(4), m_byte_order(endian::InlHostByteOrder()), m_indent_level(0), m_forwarder(*this) {} -//------------------------------------------------------------------ // Destructor -//------------------------------------------------------------------ Stream::~Stream() {} ByteOrder Stream::SetByteOrder(ByteOrder byte_order) { @@ -41,14 +38,10 @@ ByteOrder Stream::SetByteOrder(ByteOrder byte_order) { return old_byte_order; } -//------------------------------------------------------------------ // Put an offset "uval" out to the stream using the printf format in "format". -//------------------------------------------------------------------ void Stream::Offset(uint32_t uval, const char *format) { Printf(format, uval); } -//------------------------------------------------------------------ // Put an SLEB128 "uval" out to the stream using the printf format in "format". -//------------------------------------------------------------------ size_t Stream::PutSLEB128(int64_t sval) { if (m_flags.Test(eBinary)) return llvm::encodeSLEB128(sval, m_forwarder); @@ -56,9 +49,7 @@ size_t Stream::PutSLEB128(int64_t sval) { return Printf("0x%" PRIi64, sval); } -//------------------------------------------------------------------ // Put an ULEB128 "uval" out to the stream using the printf format in "format". -//------------------------------------------------------------------ size_t Stream::PutULEB128(uint64_t uval) { if (m_flags.Test(eBinary)) return llvm::encodeULEB128(uval, m_forwarder); @@ -66,9 +57,7 @@ size_t Stream::PutULEB128(uint64_t uval) { return Printf("0x%" PRIx64, uval); } -//------------------------------------------------------------------ // Print a raw NULL terminated C string to the stream. -//------------------------------------------------------------------ size_t Stream::PutCString(llvm::StringRef str) { size_t bytes_written = 0; bytes_written = Write(str.data(), str.size()); @@ -79,18 +68,14 @@ size_t Stream::PutCString(llvm::StringRef str) { return bytes_written; } -//------------------------------------------------------------------ // 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) { Printf(format, cstr); } -//------------------------------------------------------------------ // Put an address "addr" out to the stream with optional prefix and suffix // strings. -//------------------------------------------------------------------ void Stream::Address(uint64_t addr, uint32_t addr_size, const char *prefix, const char *suffix) { if (prefix == nullptr) @@ -99,13 +84,11 @@ void Stream::Address(uint64_t addr, uint32_t addr_size, const char *prefix, suffix = ""; // int addr_width = m_addr_size << 1; // Printf ("%s0x%0*" PRIx64 "%s", prefix, addr_width, addr, suffix); - Printf("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, (uint64_t)addr, suffix); + Printf("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, addr, suffix); } -//------------------------------------------------------------------ // Put an address range out to the stream with optional prefix and suffix // strings. -//------------------------------------------------------------------ void Stream::AddressRange(uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size, const char *prefix, const char *suffix) { @@ -119,9 +102,7 @@ void Stream::AddressRange(uint64_t lo_addr, uint64_t hi_addr, size_t Stream::PutChar(char ch) { return Write(&ch, 1); } -//------------------------------------------------------------------ // Print some formatted output to the stream. -//------------------------------------------------------------------ size_t Stream::Printf(const char *format, ...) { va_list args; va_start(args, format); @@ -130,9 +111,7 @@ size_t Stream::Printf(const char *format, ...) { return result; } -//------------------------------------------------------------------ // Print some formatted output to the stream. -//------------------------------------------------------------------ size_t Stream::PrintfVarArg(const char *format, va_list args) { llvm::SmallString<1024> buf; VASprintf(buf, format, args); @@ -144,15 +123,11 @@ size_t Stream::PrintfVarArg(const char *format, va_list args) { return Write(buf.c_str(), length); } -//------------------------------------------------------------------ // Print and End of Line character to the stream -//------------------------------------------------------------------ size_t Stream::EOL() { return PutChar('\n'); } -//------------------------------------------------------------------ // Indent the current line using the current indentation level and print an // optional string following the indentation spaces. -//------------------------------------------------------------------ size_t Stream::Indent(const char *s) { return Printf("%*.*s%s", m_indent_level, m_indent_level, "", s ? s : ""); } @@ -162,17 +137,13 @@ size_t Stream::Indent(llvm::StringRef str) { str.str().c_str()); } -//------------------------------------------------------------------ // Stream a character "ch" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(char ch) { PutChar(ch); return *this; } -//------------------------------------------------------------------ // Stream the NULL terminated C string out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(const char *s) { Printf("%s", s); return *this; @@ -183,96 +154,70 @@ Stream &Stream::operator<<(llvm::StringRef str) { return *this; } -//------------------------------------------------------------------ // Stream the pointer value out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(const void *p) { - Printf("0x%.*tx", (int)sizeof(const void *) * 2, (ptrdiff_t)p); + Printf("0x%.*tx", static_cast<int>(sizeof(const void *)) * 2, (ptrdiff_t)p); return *this; } -//------------------------------------------------------------------ // Stream a uint8_t "uval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(uint8_t uval) { PutHex8(uval); return *this; } -//------------------------------------------------------------------ // Stream a uint16_t "uval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(uint16_t uval) { PutHex16(uval, m_byte_order); return *this; } -//------------------------------------------------------------------ // Stream a uint32_t "uval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(uint32_t uval) { PutHex32(uval, m_byte_order); return *this; } -//------------------------------------------------------------------ // Stream a uint64_t "uval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(uint64_t uval) { PutHex64(uval, m_byte_order); return *this; } -//------------------------------------------------------------------ // Stream a int8_t "sval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(int8_t sval) { - Printf("%i", (int)sval); + Printf("%i", static_cast<int>(sval)); return *this; } -//------------------------------------------------------------------ // Stream a int16_t "sval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(int16_t sval) { - Printf("%i", (int)sval); + Printf("%i", static_cast<int>(sval)); return *this; } -//------------------------------------------------------------------ // Stream a int32_t "sval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(int32_t sval) { - Printf("%i", (int)sval); + Printf("%i", static_cast<int>(sval)); return *this; } -//------------------------------------------------------------------ // Stream a int64_t "sval" out to this stream. -//------------------------------------------------------------------ Stream &Stream::operator<<(int64_t sval) { Printf("%" PRIi64, sval); return *this; } -//------------------------------------------------------------------ // Get the current indentation level -//------------------------------------------------------------------ int Stream::GetIndentLevel() const { return m_indent_level; } -//------------------------------------------------------------------ // Set the current indentation level -//------------------------------------------------------------------ void Stream::SetIndentLevel(int indent_level) { m_indent_level = indent_level; } -//------------------------------------------------------------------ // Increment the current indentation level -//------------------------------------------------------------------ void Stream::IndentMore(int amount) { m_indent_level += amount; } -//------------------------------------------------------------------ // Decrement the current indentation level -//------------------------------------------------------------------ void Stream::IndentLess(int amount) { if (m_indent_level >= amount) m_indent_level -= amount; @@ -280,29 +225,19 @@ void Stream::IndentLess(int amount) { m_indent_level = 0; } -//------------------------------------------------------------------ // Get the address size in bytes -//------------------------------------------------------------------ uint32_t Stream::GetAddressByteSize() const { return m_addr_size; } -//------------------------------------------------------------------ // Set the address size in bytes -//------------------------------------------------------------------ void Stream::SetAddressByteSize(uint32_t addr_size) { m_addr_size = addr_size; } -//------------------------------------------------------------------ // The flags get accessor -//------------------------------------------------------------------ Flags &Stream::GetFlags() { return m_flags; } -//------------------------------------------------------------------ // The flags const get accessor -//------------------------------------------------------------------ const Flags &Stream::GetFlags() const { return m_flags; } -//------------------------------------------------------------------ // The byte order get accessor -//------------------------------------------------------------------ lldb::ByteOrder Stream::GetByteOrder() const { return m_byte_order; } @@ -360,10 +295,10 @@ size_t Stream::PutHex16(uint16_t uvalue, ByteOrder byte_order) { if (byte_order == eByteOrderLittle) { for (size_t byte = 0; byte < sizeof(uvalue); ++byte) - _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false); } else { for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte) - _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false); } return *delta; } @@ -376,10 +311,10 @@ size_t Stream::PutHex32(uint32_t uvalue, ByteOrder byte_order) { if (byte_order == eByteOrderLittle) { for (size_t byte = 0; byte < sizeof(uvalue); ++byte) - _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false); } else { for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte) - _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false); } return *delta; } @@ -392,10 +327,10 @@ size_t Stream::PutHex64(uint64_t uvalue, ByteOrder byte_order) { if (byte_order == eByteOrderLittle) { for (size_t byte = 0; byte < sizeof(uvalue); ++byte) - _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false); } else { for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte) - _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false); } return *delta; } @@ -404,11 +339,11 @@ size_t Stream::PutMaxHex64(uint64_t uvalue, size_t byte_size, lldb::ByteOrder byte_order) { switch (byte_size) { case 1: - return PutHex8((uint8_t)uvalue); + return PutHex8(static_cast<uint8_t>(uvalue)); case 2: - return PutHex16((uint16_t)uvalue, byte_order); + return PutHex16(static_cast<uint16_t>(uvalue), byte_order); case 4: - return PutHex32((uint32_t)uvalue, byte_order); + return PutHex32(static_cast<uint32_t>(uvalue), byte_order); case 8: return PutHex64(uvalue, byte_order); } @@ -451,7 +386,7 @@ size_t Stream::PutRawBytes(const void *s, size_t src_len, if (dst_byte_order == eByteOrderInvalid) dst_byte_order = m_byte_order; - const uint8_t *src = (const uint8_t *)s; + const uint8_t *src = static_cast<const uint8_t *>(s); bool binary_was_set = m_flags.Test(eBinary); if (!binary_was_set) m_flags.Set(eBinary); @@ -478,7 +413,7 @@ size_t Stream::PutBytesAsRawHex8(const void *s, size_t src_len, if (dst_byte_order == eByteOrderInvalid) dst_byte_order = m_byte_order; - const uint8_t *src = (const uint8_t *)s; + const uint8_t *src = static_cast<const uint8_t *>(s); bool binary_is_set = m_flags.Test(eBinary); m_flags.Clear(eBinary); if (src_byte_order == dst_byte_order) { @@ -494,14 +429,12 @@ size_t Stream::PutBytesAsRawHex8(const void *s, size_t src_len, return *delta; } -size_t Stream::PutCStringAsRawHex8(const char *s) { +size_t Stream::PutStringAsRawHex8(llvm::StringRef s) { ByteDelta delta(*this); bool binary_is_set = m_flags.Test(eBinary); m_flags.Clear(eBinary); - while(*s) { - _PutHex8(*s, false); - ++s; - } + for (char c : s) + _PutHex8(c, false); if (binary_is_set) m_flags.Set(eBinary); return *delta; diff --git a/source/Utility/StreamCallback.cpp b/source/Utility/StreamCallback.cpp index 97528439005a..b3d3adea78bc 100644 --- a/source/Utility/StreamCallback.cpp +++ b/source/Utility/StreamCallback.cpp @@ -1,9 +1,8 @@ //===-- StreamCallback.cpp -------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/StreamGDBRemote.cpp b/source/Utility/StreamGDBRemote.cpp index 9304d84f58a0..c710bbe3eecb 100644 --- a/source/Utility/StreamGDBRemote.cpp +++ b/source/Utility/StreamGDBRemote.cpp @@ -1,9 +1,8 @@ //===-- StreamGDBRemote.cpp -------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -27,7 +26,7 @@ StreamGDBRemote::~StreamGDBRemote() {} int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) { int bytes_written = 0; - const uint8_t *src = (const uint8_t *)s; + const uint8_t *src = static_cast<const uint8_t *>(s); bool binary_is_set = m_flags.Test(eBinary); m_flags.Clear(eBinary); while (src_len) { diff --git a/source/Utility/StreamString.cpp b/source/Utility/StreamString.cpp index 152096198858..bf9814d6c305 100644 --- a/source/Utility/StreamString.cpp +++ b/source/Utility/StreamString.cpp @@ -1,9 +1,8 @@ //===-- StreamString.cpp ----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/StringExtractor.cpp b/source/Utility/StringExtractor.cpp index ddf414702d8c..502f468da3cc 100644 --- a/source/Utility/StringExtractor.cpp +++ b/source/Utility/StringExtractor.cpp @@ -1,9 +1,8 @@ //===-- StringExtractor.cpp -------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -25,9 +24,7 @@ static inline int xdigit_to_sint(char ch) { return -1; } -//---------------------------------------------------------------------- // StringExtractor constructor -//---------------------------------------------------------------------- StringExtractor::StringExtractor() : m_packet(), m_index(0) {} StringExtractor::StringExtractor(llvm::StringRef packet_str) @@ -41,26 +38,7 @@ StringExtractor::StringExtractor(const char *packet_cstr) m_packet.assign(packet_cstr); } -//---------------------------------------------------------------------- -// StringExtractor copy constructor -//---------------------------------------------------------------------- -StringExtractor::StringExtractor(const StringExtractor &rhs) - : m_packet(rhs.m_packet), m_index(rhs.m_index) {} - -//---------------------------------------------------------------------- -// StringExtractor assignment operator -//---------------------------------------------------------------------- -const StringExtractor &StringExtractor::operator=(const StringExtractor &rhs) { - if (this != &rhs) { - m_packet = rhs.m_packet; - m_index = rhs.m_index; - } - return *this; -} - -//---------------------------------------------------------------------- // Destructor -//---------------------------------------------------------------------- StringExtractor::~StringExtractor() {} char StringExtractor::GetChar(char fail_value) { @@ -73,13 +51,11 @@ char StringExtractor::GetChar(char fail_value) { return fail_value; } -//---------------------------------------------------------------------- // If a pair of valid hex digits exist at the head of the StringExtractor they // are decoded into an unsigned byte and returned by this function // // If there is not a pair of valid hex digits at the head of the // StringExtractor, it is left unchanged and -1 is returned -//---------------------------------------------------------------------- int StringExtractor::DecodeHexU8() { SkipSpaces(); if (GetBytesLeft() < 2) { @@ -91,13 +67,11 @@ int StringExtractor::DecodeHexU8() { return -1; } m_index += 2; - return (uint8_t)((hi_nibble << 4) + lo_nibble); + return static_cast<uint8_t>((hi_nibble << 4) + lo_nibble); } -//---------------------------------------------------------------------- // Extract an unsigned character from two hex ASCII chars in the packet string, // or return fail_value on failure -//---------------------------------------------------------------------- uint8_t StringExtractor::GetHexU8(uint8_t fail_value, bool set_eof_on_fail) { // On success, fail_value will be overwritten with the next character in the // stream @@ -113,7 +87,7 @@ bool StringExtractor::GetHexU8Ex(uint8_t &ch, bool set_eof_on_fail) { // ch should not be changed in case of failure return false; } - ch = (uint8_t)byte; + ch = static_cast<uint8_t>(byte); return true; } @@ -198,12 +172,12 @@ uint32_t StringExtractor::GetHexMaxU32(bool little_endian, if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { nibble_lo = xdigit_to_sint(m_packet[m_index]); ++m_index; - result |= ((uint32_t)nibble_hi << (shift_amount + 4)); - result |= ((uint32_t)nibble_lo << shift_amount); + result |= (static_cast<uint32_t>(nibble_hi) << (shift_amount + 4)); + result |= (static_cast<uint32_t>(nibble_lo) << shift_amount); nibble_count += 2; shift_amount += 8; } else { - result |= ((uint32_t)nibble_hi << shift_amount); + result |= (static_cast<uint32_t>(nibble_hi) << shift_amount); nibble_count += 1; shift_amount += 4; } @@ -249,12 +223,12 @@ uint64_t StringExtractor::GetHexMaxU64(bool little_endian, if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { nibble_lo = xdigit_to_sint(m_packet[m_index]); ++m_index; - result |= ((uint64_t)nibble_hi << (shift_amount + 4)); - result |= ((uint64_t)nibble_lo << shift_amount); + result |= (static_cast<uint64_t>(nibble_hi) << (shift_amount + 4)); + result |= (static_cast<uint64_t>(nibble_lo) << shift_amount); nibble_count += 2; shift_amount += 8; } else { - result |= ((uint64_t)nibble_hi << shift_amount); + result |= (static_cast<uint64_t>(nibble_hi) << shift_amount); nibble_count += 1; shift_amount += 4; } @@ -305,19 +279,17 @@ size_t StringExtractor::GetHexBytes(llvm::MutableArrayRef<uint8_t> dest, return bytes_extracted; } -//---------------------------------------------------------------------- // Decodes all valid hex encoded bytes at the head of the StringExtractor, // limited by dst_len. // // Returns the number of bytes successfully decoded -//---------------------------------------------------------------------- size_t StringExtractor::GetHexBytesAvail(llvm::MutableArrayRef<uint8_t> dest) { size_t bytes_extracted = 0; while (!dest.empty()) { int decode = DecodeHexU8(); if (decode == -1) break; - dest[0] = (uint8_t)decode; + dest[0] = static_cast<uint8_t>(decode); dest = dest.drop_front(); ++bytes_extracted; } @@ -338,7 +310,7 @@ uint64_t StringExtractor::GetHexWithFixedSize(uint32_t byte_size, uint32_t shift_amount; for (i = 0, shift_amount = 0; i < byte_size && IsGood(); ++i, shift_amount += 8) { - result |= ((uint64_t)GetHexU8() << shift_amount); + result |= (static_cast<uint64_t>(GetHexU8()) << shift_amount); } } else { // Big Endian diff --git a/source/Utility/StringExtractorGDBRemote.cpp b/source/Utility/StringExtractorGDBRemote.cpp index 2a8bd785576b..a011e9246d15 100644 --- a/source/Utility/StringExtractorGDBRemote.cpp +++ b/source/Utility/StringExtractorGDBRemote.cpp @@ -1,9 +1,8 @@ //===-- StringExtractorGDBRemote.cpp ----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -286,8 +285,8 @@ StringExtractorGDBRemote::GetServerPacketType() const { break; case 'X': - if (PACKET_STARTS_WITH("qXfer:auxv:read::")) - return eServerPacketType_qXfer_auxv_read; + if (PACKET_STARTS_WITH("qXfer:")) + return eServerPacketType_qXfer; break; } break; @@ -378,9 +377,7 @@ StringExtractorGDBRemote::GetServerPacketType() const { break; case 'g': - if (packet_size == 1) - return eServerPacketType_g; - break; + return eServerPacketType_g; case 'G': return eServerPacketType_G; diff --git a/source/Utility/StringLexer.cpp b/source/Utility/StringLexer.cpp index d5c7fc628988..958a9580db7a 100644 --- a/source/Utility/StringLexer.cpp +++ b/source/Utility/StringLexer.cpp @@ -1,9 +1,8 @@ //===--------------------- StringLexer.cpp -----------------------*- C++-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -16,9 +15,6 @@ using namespace lldb_utility; StringLexer::StringLexer(std::string s) : m_data(s), m_position(0) {} -StringLexer::StringLexer(const StringLexer &rhs) - : m_data(rhs.m_data), m_position(rhs.m_position) {} - StringLexer::Character StringLexer::Peek() { return m_data[m_position]; } bool StringLexer::NextIf(Character c) { diff --git a/source/Utility/StringList.cpp b/source/Utility/StringList.cpp index 20bde1a39ac1..fb0d9be8797d 100644 --- a/source/Utility/StringList.cpp +++ b/source/Utility/StringList.cpp @@ -1,9 +1,8 @@ //===-- StringList.cpp ------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/StructuredData.cpp b/source/Utility/StructuredData.cpp index 76a141af40b6..0e203f9739d1 100644 --- a/source/Utility/StructuredData.cpp +++ b/source/Utility/StructuredData.cpp @@ -1,9 +1,8 @@ //===---------------------StructuredData.cpp ---------------------*- C++-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -23,9 +22,7 @@ using namespace lldb_private; -//---------------------------------------------------------------------- // Functions that use a JSONParser to parse JSON into StructuredData -//---------------------------------------------------------------------- static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser); static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser); static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser); @@ -54,7 +51,7 @@ static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser) { std::string value; std::string key; - while (1) { + while (true) { JSONParser::Token token = json_parser.GetToken(value); if (token == JSONParser::Token::String) { @@ -85,7 +82,7 @@ static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser) { std::string value; std::string key; - while (1) { + while (true) { StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser); if (value_sp) array_up->AddItem(value_sp); diff --git a/source/Utility/TildeExpressionResolver.cpp b/source/Utility/TildeExpressionResolver.cpp index 4e2be77c49cb..b58f45728ce7 100644 --- a/source/Utility/TildeExpressionResolver.cpp +++ b/source/Utility/TildeExpressionResolver.cpp @@ -1,9 +1,8 @@ //===--------------------- TildeExpressionResolver.cpp ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/Timer.cpp b/source/Utility/Timer.cpp index c56ac2192b33..6b46d8ba7364 100644 --- a/source/Utility/Timer.cpp +++ b/source/Utility/Timer.cpp @@ -1,9 +1,8 @@ //===-- Timer.cpp -----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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/Timer.h" @@ -42,6 +41,8 @@ static TimerStack &GetTimerStackForCurrentThread() { Timer::Category::Category(const char *cat) : m_name(cat) { m_nanos.store(0, std::memory_order_release); + m_nanos_total.store(0, std::memory_order_release); + m_count.store(0, std::memory_order_release); Category *expected = g_categories; do { m_next = expected; @@ -94,6 +95,8 @@ Timer::~Timer() { // Keep total results for each category so we can dump results. m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count(); + m_category.m_nanos_total += std::chrono::nanoseconds(total_dur).count(); + m_category.m_count++; } void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; } @@ -101,25 +104,38 @@ void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; } /* binary function predicate: * - returns whether a person is less than another person */ - -typedef std::pair<const char *, uint64_t> TimerEntry; - -static bool CategoryMapIteratorSortCriterion(const TimerEntry &lhs, - const TimerEntry &rhs) { - return lhs.second > rhs.second; +namespace { +struct Stats { + const char *name; + uint64_t nanos; + uint64_t nanos_total; + uint64_t count; +}; +} // namespace + +static bool CategoryMapIteratorSortCriterion(const Stats &lhs, + const Stats &rhs) { + return lhs.nanos > rhs.nanos; } void Timer::ResetCategoryTimes() { - for (Category *i = g_categories; i; i = i->m_next) + for (Category *i = g_categories; i; i = i->m_next) { i->m_nanos.store(0, std::memory_order_release); + i->m_nanos_total.store(0, std::memory_order_release); + i->m_count.store(0, std::memory_order_release); + } } void Timer::DumpCategoryTimes(Stream *s) { - std::vector<TimerEntry> sorted; + std::vector<Stats> sorted; for (Category *i = g_categories; i; i = i->m_next) { uint64_t nanos = i->m_nanos.load(std::memory_order_acquire); - if (nanos) - sorted.push_back(std::make_pair(i->m_name, nanos)); + if (nanos) { + uint64_t nanos_total = i->m_nanos_total.load(std::memory_order_acquire); + uint64_t count = i->m_count.load(std::memory_order_acquire); + Stats stats{i->m_name, nanos, nanos_total, count}; + sorted.push_back(stats); + } } if (sorted.empty()) return; // Later code will break without any elements. @@ -127,6 +143,10 @@ void Timer::DumpCategoryTimes(Stream *s) { // Sort by time llvm::sort(sorted.begin(), sorted.end(), CategoryMapIteratorSortCriterion); - for (const auto &timer : sorted) - s->Printf("%.9f sec for %s\n", timer.second / 1000000000., timer.first); + for (const auto &stats : sorted) + s->Printf("%.9f sec (total: %.3fs; child: %.3fs; count: %" PRIu64 + ") for %s\n", + stats.nanos / 1000000000., stats.nanos_total / 1000000000., + (stats.nanos_total - stats.nanos) / 1000000000., stats.count, + stats.name); } diff --git a/source/Utility/UUID.cpp b/source/Utility/UUID.cpp index b00878792c7e..2a73f9a482ff 100644 --- a/source/Utility/UUID.cpp +++ b/source/Utility/UUID.cpp @@ -1,9 +1,8 @@ //===-- UUID.cpp ------------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -110,3 +109,15 @@ size_t UUID::SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes) { // Else return zero to indicate we were not able to parse a UUID value return 0; } + +size_t UUID::SetFromOptionalStringRef(llvm::StringRef str, + uint32_t num_uuid_bytes) { + size_t num_chars_consumed = SetFromStringRef(str, num_uuid_bytes); + if (num_chars_consumed) { + if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) + Clear(); + } + + return num_chars_consumed; +} + diff --git a/source/Utility/UriParser.cpp b/source/Utility/UriParser.cpp index a6d81e7a2c8b..b446958f2f47 100644 --- a/source/Utility/UriParser.cpp +++ b/source/Utility/UriParser.cpp @@ -1,9 +1,8 @@ //===-- UriParser.cpp -------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -16,9 +15,7 @@ using namespace lldb_private; -//---------------------------------------------------------------------- // UriParser::Parse -//---------------------------------------------------------------------- bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme, llvm::StringRef &hostname, int &port, llvm::StringRef &path) { diff --git a/source/Utility/UserID.cpp b/source/Utility/UserID.cpp index e65b8fa87d81..b76a1cd84f82 100644 --- a/source/Utility/UserID.cpp +++ b/source/Utility/UserID.cpp @@ -1,9 +1,8 @@ //===-- UserID.cpp ----------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/UserIDResolver.cpp b/source/Utility/UserIDResolver.cpp new file mode 100644 index 000000000000..8aac6f948cd2 --- /dev/null +++ b/source/Utility/UserIDResolver.cpp @@ -0,0 +1,44 @@ +//===-- UserIDResolver.cpp --------------------------------------*- 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 "lldb/Utility/UserIDResolver.h" +#include "llvm/Support/ManagedStatic.h" + +using namespace lldb_private; + +UserIDResolver::~UserIDResolver() = default; + +llvm::Optional<llvm::StringRef> UserIDResolver::Get( + id_t id, Map &cache, + llvm::Optional<std::string> (UserIDResolver::*do_get)(id_t)) { + + std::lock_guard<std::mutex> guard(m_mutex); + auto iter_bool = cache.try_emplace(id, llvm::None); + if (iter_bool.second) + iter_bool.first->second = (this->*do_get)(id); + if (iter_bool.first->second) + return llvm::StringRef(*iter_bool.first->second); + return llvm::None; +} + +namespace { +class NoopResolver : public UserIDResolver { +protected: + llvm::Optional<std::string> DoGetUserName(id_t uid) override { + return llvm::None; + } + + llvm::Optional<std::string> DoGetGroupName(id_t gid) override { + return llvm::None; + } +}; +} // namespace + +static llvm::ManagedStatic<NoopResolver> g_noop_resolver; + +UserIDResolver &UserIDResolver::GetNoopResolver() { return *g_noop_resolver; } diff --git a/source/Utility/UuidCompatibility.h b/source/Utility/UuidCompatibility.h index df26f77ab52d..e992c0c79a1f 100644 --- a/source/Utility/UuidCompatibility.h +++ b/source/Utility/UuidCompatibility.h @@ -1,9 +1,8 @@ //===-- UuidCompatibility.h -------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/VASprintf.cpp b/source/Utility/VASprintf.cpp index 4368a3738307..2ee0f6676fa7 100644 --- a/source/Utility/VASprintf.cpp +++ b/source/Utility/VASprintf.cpp @@ -1,9 +1,8 @@ -//===-- VASPrintf.cpp -------------------------------------------*- C++ -*-===// +//===-- VASprintf.cpp -------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/source/Utility/VMRange.cpp b/source/Utility/VMRange.cpp index 20dc7dbbe757..f3f4ae7efc3c 100644 --- a/source/Utility/VMRange.cpp +++ b/source/Utility/VMRange.cpp @@ -1,9 +1,8 @@ //===-- VMRange.cpp ---------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// |