Skip to content

Commit ea59be8

Browse files
authored
Merge pull request #7680 from apple/jdevlieghere/LanguageRuntimeSwift
[lldb] Fix issues in LanguageRuntime/Swift (NFC)
2 parents 4802294 + 2063882 commit ea59be8

10 files changed

+106
-52
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
//===-- LLDBMemoryReader.cpp ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
113
#include "LLDBMemoryReader.h"
214
#include "lldb/Core/Address.h"
315
#include "lldb/Core/Section.h"
@@ -475,8 +487,8 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
475487
auto last_section =
476488
section_list->GetSectionAtIndex(section_list->GetSize() - 1);
477489

478-
// The total size is the last section's file address plus size, subtracting the
479-
// first section's file address.
490+
// The total size is the last section's file address plus size, subtracting
491+
// the first section's file address.
480492
auto start_file_address = first_section->GetFileAddress();
481493
uint64_t end_file_address =
482494
last_section->GetFileAddress() + last_section->GetByteSize();
@@ -551,7 +563,7 @@ LLDBMemoryReader::getFileAddressAndModuleForTaggedAddress(
551563
// when constructing the range to module map.
552564
file_address = tagged_address - std::prev(pair_iterator)->first;
553565

554-
// We also need to add the module's file address, since we subtract it when
566+
// We also need to add the module's file address, since we subtract it when
555567
// building the range to module map.
556568
file_address += section_list->GetSectionAtIndex(0)->GetFileAddress();
557569
return {{file_address, module}};

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
//===-- LLDBMemoryReader.h --------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
112

213
#ifndef liblldb_LLDBMemoryReader_h_
314
#define liblldb_LLDBMemoryReader_h_
415

5-
616
#include "SwiftLanguageRuntime.h"
717

818
// We need to include ReflectionContext.h before TypeLowering.h to avoid
@@ -13,7 +23,6 @@
1323
#include "llvm/ADT/SmallSet.h"
1424
#include "llvm/Support/Memory.h"
1525

16-
1726
namespace lldb_private {
1827
class LLDBMemoryReader : public swift::remote::MemoryReader {
1928
public:
@@ -67,19 +76,19 @@ class LLDBMemoryReader : public swift::remote::MemoryReader {
6776
llvm::Optional<std::pair<uint64_t, lldb::ModuleSP>>
6877
getFileAddressAndModuleForTaggedAddress(uint64_t tagged_address) const;
6978

70-
/// Resolves the address by either mapping a tagged address back to an LLDB
71-
/// Address with section + offset, or, in case the address is not tagged,
79+
/// Resolves the address by either mapping a tagged address back to an LLDB
80+
/// Address with section + offset, or, in case the address is not tagged,
7281
/// constructing an LLDB address with just the offset.
73-
/// \return an Address with Section + offset if we succesfully converted a tagged
74-
/// address back, an Address with just an offset if the address was not tagged,
75-
/// and None if the address was tagged but we couldn't convert it back to an
76-
/// Address.
82+
/// \return an Address with Section + offset if we succesfully converted a
83+
/// tagged address back, an Address with just an offset if the address was not
84+
/// tagged, and None if the address was tagged but we couldn't convert it back
85+
/// to an Address.
7786
llvm::Optional<Address> resolveRemoteAddress(uint64_t address) const;
7887

79-
/// Reads memory from the symbol rich binary from the address into dest.
80-
/// \return true if it was able to successfully read memory.
81-
llvm::Optional<Address> resolveRemoteAddressFromSymbolObjectFile(uint64_t address) const;
82-
88+
/// Reads memory from the symbol rich binary from the address into dest.
89+
/// \return true if it was able to successfully read memory.
90+
llvm::Optional<Address>
91+
resolveRemoteAddressFromSymbolObjectFile(uint64_t address) const;
8392

8493
private:
8594
Process &m_process;
@@ -104,17 +113,15 @@ llvm::Optional<Address> resolveRemoteAddressFromSymbolObjectFile(uint64_t addres
104113

105114
/// The set of modules where we should read memory from the symbol file's
106115
/// object file instead of the main object file.
107-
llvm::SmallSet<lldb::ModuleSP, 8>
108-
m_modules_with_metadata_in_symbol_obj_file;
116+
llvm::SmallSet<lldb::ModuleSP, 8> m_modules_with_metadata_in_symbol_obj_file;
109117

110118
/// The bit used to tag LLDB's virtual addresses as such. See \c
111119
/// m_range_module_map.
112120
const static uint64_t LLDB_FILE_ADDRESS_BIT = 0x2000000000000000;
113121
static_assert(LLDB_FILE_ADDRESS_BIT & SWIFT_ABI_X86_64_SWIFT_SPARE_BITS_MASK,
114-
"LLDB file address bit not in spare bits mask!");
122+
"LLDB file address bit not in spare bits mask!");
115123
static_assert(LLDB_FILE_ADDRESS_BIT & SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK,
116-
"LLDB file address bit not in spare bits mask!");
117-
124+
"LLDB file address bit not in spare bits mask!");
118125
};
119126
} // namespace lldb_private
120127
#endif

lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
//===-- ReflectionContextInterface.h ----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
113
#ifndef liblldb_SwiftReflectionContextInterface_h_
214
#define liblldb_SwiftReflectionContextInterface_h_
315

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ static bool HasReflectionInfo(ObjectFile *obj_file) {
452452
return hasReflectionSection;
453453
}
454454

455-
ThreadSafeReflectionContext
455+
ThreadSafeReflectionContext
456456
SwiftLanguageRuntimeImpl::GetReflectionContext() {
457457
m_reflection_ctx_mutex.lock();
458458
SetupReflection();
@@ -503,7 +503,7 @@ void SwiftLanguageRuntimeImpl::SetupReflection() {
503503
std::lock_guard<std::recursive_mutex> lock(m_reflection_ctx_mutex);
504504
if (m_initialized_reflection_ctx)
505505
return;
506-
506+
507507
// The global ABI bit is read by the Swift runtime library.
508508
SetupABIBit();
509509

@@ -930,7 +930,7 @@ void SwiftLanguageRuntimeImpl::ModulesDidLoad(const ModuleList &module_list) {
930930
m_modules_to_add.AppendIfNeeded(module_list);
931931
}
932932

933-
std::string
933+
std::string
934934
SwiftLanguageRuntimeImpl::GetObjectDescriptionExpr_Result(ValueObject &object) {
935935
Log *log(GetLog(LLDBLog::DataFormatters | LLDBLog::Expressions));
936936
std::string expr_string
@@ -942,12 +942,12 @@ SwiftLanguageRuntimeImpl::GetObjectDescriptionExpr_Result(ValueObject &object) {
942942
return expr_string;
943943
}
944944

945-
std::string
945+
std::string
946946
SwiftLanguageRuntimeImpl::GetObjectDescriptionExpr_Ref(ValueObject &object) {
947947
Log *log(GetLog(LLDBLog::DataFormatters | LLDBLog::Expressions));
948948

949949
StreamString expr_string;
950-
std::string expr_str
950+
std::string expr_str
951951
= llvm::formatv("Swift._DebuggerSupport.stringForPrintObject(Swift."
952952
"unsafeBitCast({0:x}, to: AnyObject.self))",
953953
object.GetValueAsUnsigned(0)).str();
@@ -964,7 +964,7 @@ static const ExecutionContextRef *GetSwiftExeCtx(ValueObject &valobj) {
964964
: nullptr;
965965
}
966966

967-
std::string
967+
std::string
968968
SwiftLanguageRuntimeImpl::GetObjectDescriptionExpr_Copy(ValueObject &object,
969969
lldb::addr_t &copy_location)
970970
{
@@ -982,7 +982,7 @@ SwiftLanguageRuntimeImpl::GetObjectDescriptionExpr_Copy(ValueObject &object,
982982
// printing, as IRGen requires a fully realized type to work on.
983983
StackFrameSP frame_sp = object.GetFrameSP();
984984
if (!frame_sp)
985-
frame_sp
985+
frame_sp
986986
= m_process.GetThreadList().GetSelectedThread()
987987
->GetSelectedFrame(DoNoSelectMostRelevantFrame);
988988

@@ -1021,20 +1021,20 @@ SwiftLanguageRuntimeImpl::GetObjectDescriptionExpr_Copy(ValueObject &object,
10211021
return {};
10221022
}
10231023

1024-
std::string expr_string
1024+
std::string expr_string
10251025
= llvm::formatv("Swift._DebuggerSupport.stringForPrintObject(Swift."
10261026
"UnsafePointer<{0}>(bitPattern: {1:x})!.pointee)",
10271027
static_type.GetTypeName().GetCString(), copy_location).str();
10281028
if (log)
10291029
log->Printf("[GetObjectDescriptionExpr_Copy] expression: %s",
10301030
expr_string.c_str());
1031-
1031+
10321032
return expr_string;
10331033
}
10341034

1035-
bool
1036-
SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(ValueObject &object,
1037-
std::string &expr_string,
1035+
bool
1036+
SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(ValueObject &object,
1037+
std::string &expr_string,
10381038
Stream &result)
10391039
{
10401040
Log *log(GetLog(LLDBLog::DataFormatters | LLDBLog::Expressions));
@@ -1044,10 +1044,10 @@ SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(ValueObject &object,
10441044
eval_options.SetSuppressPersistentResult(true);
10451045
eval_options.SetGenerateDebugInfo(true);
10461046
eval_options.SetTimeout(m_process.GetUtilityExpressionTimeout());
1047-
1047+
10481048
StackFrameSP frame_sp = object.GetFrameSP();
10491049
if (!frame_sp)
1050-
frame_sp
1050+
frame_sp
10511051
= m_process.GetThreadList().GetSelectedThread()
10521052
->GetSelectedFrame(DoNoSelectMostRelevantFrame);
10531053
if (!frame_sp) {
@@ -1060,7 +1060,7 @@ SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(ValueObject &object,
10601060
result_sp, eval_options);
10611061

10621062
if (log) {
1063-
const char *eval_result_str
1063+
const char *eval_result_str
10641064
= m_process.ExecutionResultAsCString(eval_result);
10651065
log->Printf("[RunObjectDescriptionExpr] %s", eval_result_str);
10661066
}
@@ -1903,7 +1903,7 @@ void SwiftLanguageRuntimeImpl::WillStartExecutingUserExpression(
19031903
if (!ts) {
19041904
LLDB_LOG(log, "type system no longer live");
19051905
return;
1906-
}
1906+
}
19071907
ConstString BoolName("bool");
19081908
llvm::Optional<uint64_t> bool_size =
19091909
ts->GetBuiltinTypeByName(BoolName).GetByteSize(nullptr);
@@ -1978,7 +1978,7 @@ void SwiftLanguageRuntimeImpl::DidFinishExecutingUserExpression(
19781978
if (!ts) {
19791979
LLDB_LOG(log, "type system no longer live");
19801980
return;
1981-
}
1981+
}
19821982
ConstString BoolName("bool");
19831983
llvm::Optional<uint64_t> bool_size =
19841984
ts->GetBuiltinTypeByName(BoolName).GetByteSize(nullptr);
@@ -2582,7 +2582,7 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
25822582
RegisterContext *regctx,
25832583
bool &behaves_like_zeroth_frame) {
25842584
LLDB_SCOPED_TIMER();
2585-
2585+
25862586
Target &target(process_sp->GetTarget());
25872587
auto arch = target.GetArchitecture();
25882588
llvm::Optional<AsyncUnwindRegisterNumbers> regnums =
@@ -2758,7 +2758,7 @@ static UnwindPlanSP
27582758
GetFollowAsyncContextUnwindPlan(RegisterContext *regctx, ArchSpec &arch,
27592759
bool &behaves_like_zeroth_frame) {
27602760
LLDB_SCOPED_TIMER();
2761-
2761+
27622762
UnwindPlan::RowSP row(new UnwindPlan::Row);
27632763
const int32_t ptr_size = 8;
27642764
row->SetOffset(0);

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class SwiftLanguageRuntime : public LanguageRuntime {
132132
/// Return true if name is a Swift async function, await resume partial
133133
/// function, or suspend resume partial function symbol.
134134
static bool IsAnySwiftAsyncFunctionSymbol(llvm::StringRef name);
135-
135+
136136
/// Return the async context address using the target's specific register.
137137
static lldb::addr_t GetAsyncContext(RegisterContext *regctx);
138138

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ class LLDBTypeInfoProvider : public swift::remote::TypeInfoProvider {
313313
mangledName.str().c_str());
314314
return nullptr;
315315
}
316-
316+
317317
return GetOrCreateTypeInfo(clang_type);
318318
}
319-
319+
320320
const swift::reflection::TypeInfo *
321321
GetOrCreateTypeInfo(CompilerType clang_type) {
322322
if (auto ti = m_runtime.lookupClangTypeInfo(clang_type))
@@ -1240,7 +1240,7 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack(
12401240
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
12411241
if (!reflection_ctx)
12421242
return false;
1243-
1243+
12441244
// Return a tuple type, with one element per pack element and its
12451245
// type has all DependentGenericParamType that appear in type packs
12461246
// substituted.
@@ -1270,7 +1270,7 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack(
12701270

12711271
Target &target = m_process.GetTarget();
12721272
size_t ptr_size = m_process.GetAddressByteSize();
1273-
1273+
12741274
swift::Demangle::Demangler dem;
12751275

12761276
auto expand_pack_type = [&](ConstString mangled_pack_type,
@@ -1536,7 +1536,7 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
15361536
if (auto *tr = sc.get_typeref()) {
15371537
swift::Demangle::Demangler dem;
15381538
swift::Demangle::NodePointer node = tr->getDemangling(dem);
1539-
// Skip private Foundation types since it's unlikely that would be
1539+
// Skip private Foundation types since it's unlikely that would be
15401540
// useful to users.
15411541
if (IsPrivateNSClass(node))
15421542
return false;
@@ -2068,7 +2068,7 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase(
20682068
lldb::addr_t box_location = m_process.ReadPointerFromMemory(box_addr, error);
20692069
if (box_location == LLDB_INVALID_ADDRESS)
20702070
return false;
2071-
2071+
20722072
box_location = MaskMaybeBridgedPointer(m_process, box_location);
20732073
lldb::addr_t box_value = box_addr + in_value.GetByteOffset();
20742074
Flags type_info(child_type.GetTypeInfo());
@@ -2540,7 +2540,7 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
25402540
{"$s14CoreFoundation7CGFloatVD", "$s12CoreGraphics7CGFloatVD"}};
25412541

25422542
auto it = known_types_with_redefined_modules.find(mangled_name);
2543-
if (it != known_types_with_redefined_modules.end())
2543+
if (it != known_types_with_redefined_modules.end())
25442544
mangled_name = it->second;
25452545

25462546
swift::Demangle::NodePointer node =

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ class SwiftLanguageRuntimeImpl {
316316
// types of swift objects.
317317
std::string GetObjectDescriptionExpr_Result(ValueObject &object);
318318
std::string GetObjectDescriptionExpr_Ref(ValueObject &object);
319-
std::string GetObjectDescriptionExpr_Copy(ValueObject &object,
319+
std::string GetObjectDescriptionExpr_Copy(ValueObject &object,
320320
lldb::addr_t &copy_location);
321-
bool RunObjectDescriptionExpr(ValueObject &object, std::string &expr_string,
321+
bool RunObjectDescriptionExpr(ValueObject &object, std::string &expr_string,
322322
Stream &result);
323323
/// We have to load swift dependent libraries by hand, but if they
324324
/// are missing, we shouldn't keep trying.

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ std::string SwiftLanguageRuntime::DemangleSymbolAsString(
716716
options.DisplayLocalNameContexts = false;
717717
options.DisplayDebuggerGeneratedModule = false;
718718
options.ShowFunctionArgumentTypes = true;
719-
break;
719+
break;
720720
}
721721

722722
if (sc) {
@@ -1315,7 +1315,7 @@ SwiftLanguageRuntime::GetGenericSignature(StringRef function_name,
13151315

13161316
if (error)
13171317
return {};
1318-
1318+
13191319
// Build the maps associating value and type packs with their count
13201320
// arguments.
13211321
unsigned next_count = 0;

lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
//===-- SwiftMetadataCache.cpp --------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
113
#include "SwiftMetadataCache.h"
214

315
#include "lldb/Utility/DataEncoder.h"

0 commit comments

Comments
 (0)