diff options
Diffstat (limited to 'source/Plugins/Language/ObjC/Cocoa.cpp')
-rw-r--r-- | source/Plugins/Language/ObjC/Cocoa.cpp | 107 |
1 files changed, 40 insertions, 67 deletions
diff --git a/source/Plugins/Language/ObjC/Cocoa.cpp b/source/Plugins/Language/ObjC/Cocoa.cpp index 48085378939e..ddf3953bb512 100644 --- a/source/Plugins/Language/ObjC/Cocoa.cpp +++ b/source/Plugins/Language/ObjC/Cocoa.cpp @@ -1,9 +1,8 @@ //===-- Cocoa.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,7 +17,6 @@ #include "lldb/Host/Time.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" -#include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" #include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/Target.h" @@ -28,6 +26,7 @@ #include "lldb/Utility/Stream.h" #include "llvm/ADT/APInt.h" +#include "llvm/ADT/bit.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h" @@ -43,9 +42,7 @@ bool lldb_private::formatters::NSBundleSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -93,9 +90,7 @@ bool lldb_private::formatters::NSTimeZoneSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -140,9 +135,7 @@ bool lldb_private::formatters::NSNotificationSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -187,9 +180,7 @@ bool lldb_private::formatters::NSMachPortSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -235,9 +226,7 @@ bool lldb_private::formatters::NSIndexSetSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -426,9 +415,7 @@ bool lldb_private::formatters::NSNumberSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -484,10 +471,9 @@ bool lldb_private::formatters::NSNumberSummaryProvider( return true; } else { Status error; - - AppleObjCRuntime *runtime = - llvm::dyn_cast_or_null<AppleObjCRuntime>( - process_sp->GetObjCLanguageRuntime()); + + AppleObjCRuntime *runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>( + ObjCLanguageRuntime::Get(*process_sp)); const bool new_format = (runtime && runtime->GetFoundationVersion() >= 1400); @@ -679,9 +665,7 @@ bool lldb_private::formatters::NSURLSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -750,24 +734,18 @@ bool lldb_private::formatters::NSURLSummaryProvider( /// distantFuture, except within about 1e-25 second of the reference date. const int TAGGED_DATE_EXPONENT_BIAS = 0x3ef; -typedef union { - struct { - uint64_t fraction:52; // unsigned - uint64_t exponent:11; // signed - uint64_t sign:1; - }; - uint64_t i; - double d; -} DoubleBits; -typedef union { - struct { - uint64_t fraction:52; // unsigned - uint64_t exponent:7; // signed - uint64_t sign:1; - uint64_t unused:4; // placeholder for pointer tag bits - }; - uint64_t i; -} TaggedDoubleBits; +struct DoubleBits { + uint64_t fraction : 52; // unsigned + uint64_t exponent : 11; // signed + uint64_t sign : 1; +}; + +struct TaggedDoubleBits { + uint64_t fraction : 52; // unsigned + uint64_t exponent : 7; // signed + uint64_t sign : 1; + uint64_t unused : 4; // placeholder for pointer tag bits +}; static uint64_t decodeExponent(uint64_t exp) { // Tagged exponent field is 7-bit signed. Sign-extend the value to 64 bits @@ -775,24 +753,24 @@ static uint64_t decodeExponent(uint64_t exp) { return llvm::SignExtend64<7>(exp) + TAGGED_DATE_EXPONENT_BIAS; } -static uint64_t decodeTaggedTimeInterval(uint64_t encodedTimeInterval) { +static double decodeTaggedTimeInterval(uint64_t encodedTimeInterval) { if (encodedTimeInterval == 0) return 0.0; if (encodedTimeInterval == std::numeric_limits<uint64_t>::max()) return (uint64_t)-0.0; - TaggedDoubleBits encodedBits = {}; - encodedBits.i = encodedTimeInterval; - DoubleBits decodedBits; + TaggedDoubleBits encodedBits = + llvm::bit_cast<TaggedDoubleBits>(encodedTimeInterval); + assert(encodedBits.unused == 0); // Sign and fraction are represented exactly. // Exponent is encoded. - assert(encodedBits.unused == 0); + DoubleBits decodedBits; decodedBits.sign = encodedBits.sign; decodedBits.fraction = encodedBits.fraction; decodedBits.exponent = decodeExponent(encodedBits.exponent); - return decodedBits.d; + return llvm::bit_cast<double>(decodedBits); } bool lldb_private::formatters::NSDateSummaryProvider( @@ -801,9 +779,7 @@ bool lldb_private::formatters::NSDateSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -869,7 +845,8 @@ bool lldb_private::formatters::NSDateSummaryProvider( // Accomodate for the __NSTaggedDate format introduced in Foundation 1600. if (class_name == g___NSTaggedDate) { - auto *runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>(process_sp->GetObjCLanguageRuntime()); + auto *runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>( + ObjCLanguageRuntime::Get(*process_sp)); if (runtime && runtime->GetFoundationVersion() >= 1600) date_value = decodeTaggedTimeInterval(value_bits << 4); } @@ -897,9 +874,7 @@ bool lldb_private::formatters::ObjCClassSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -940,7 +915,7 @@ public: bool MightHaveChildren() override { return false; } - size_t GetIndexOfChildWithName(const ConstString &name) override { + size_t GetIndexOfChildWithName(ConstString name) override { return UINT32_MAX; } }; @@ -958,9 +933,7 @@ bool lldb_private::formatters::NSDataSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = - (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime( - lldb::eLanguageTypeObjC); + ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); if (!runtime) return false; @@ -1059,8 +1032,8 @@ bool lldb_private::formatters::ObjCBooleanSummaryProvider( if (!process_sp) return false; - if (AppleObjCRuntime *objc_runtime = - (AppleObjCRuntime *)process_sp->GetObjCLanguageRuntime()) { + if (AppleObjCRuntime *objc_runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>( + ObjCLanguageRuntime::Get(*process_sp))) { lldb::addr_t cf_true = LLDB_INVALID_ADDRESS, cf_false = LLDB_INVALID_ADDRESS; objc_runtime->GetValuesForGlobalCFBooleans(cf_true, cf_false); |