Skip to content

Commit 0f8a064

Browse files
Merge pull request #10961 from AnthonyLatsis/stable/20250601
[stable/20250601][Swift] lldb: Fix some build errors
2 parents feacb72 + 61cac61 commit 0f8a064

File tree

11 files changed

+93
-73
lines changed

11 files changed

+93
-73
lines changed

lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,16 @@ class URLComponentsSyntheticChildrenFrontEnd
675675
m_synth_frontend_up->Update();
676676

677677
#define COMPONENT(Name, PrettyName, ID) \
678-
auto index_or_err = m_synth_frontend_up->GetIndexOfChildWithName(g__##Name); \
679-
if (!index_or_err) { \
680-
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), index_or_err.takeError(), \
681-
"{0}"); \
682-
return ChildCacheState::eRefetch; \
678+
{ \
679+
auto index_or_err = \
680+
m_synth_frontend_up->GetIndexOfChildWithName(g__##Name); \
681+
if (!index_or_err) { \
682+
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), \
683+
index_or_err.takeError(), "{0}"); \
684+
return ChildCacheState::eRefetch; \
685+
} \
686+
m_##Name = m_synth_frontend_up->GetChildAtIndex(*index_or_err).get(); \
683687
} \
684-
m_##Name = m_synth_frontend_up->GetChildAtIndex(*index_or_err).get(); \
685688
if (m_##Name) \
686689
m_##Name->SetName(GetNameFor##Name());
687690
#include "URLComponents.def"

lldb/source/Plugins/Language/Swift/SwiftArray.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,12 @@ llvm::Expected<size_t> lldb_private::formatters::swift::ArraySyntheticFrontEnd::
559559
return llvm::createStringError("Type has no child named '%s'",
560560
name.AsCString());
561561
const char *item_name = name.GetCString();
562-
uint32_t idx = ExtractIndexFromString(item_name);
563-
if (idx == UINT32_MAX || idx >= CalculateNumChildrenIgnoringErrors())
562+
auto optional_idx = ExtractIndexFromString(item_name);
563+
if (!optional_idx ||
564+
optional_idx.value() >= CalculateNumChildrenIgnoringErrors())
564565
return llvm::createStringError("Type has no child named '%s'",
565566
name.AsCString());
566-
return idx;
567+
return optional_idx.value();
567568
}
568569

569570
SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,10 @@ HashedSyntheticChildrenFrontEnd::GetIndexOfChildWithName(ConstString name) {
747747
return llvm::createStringError("Type has no child named '%s'",
748748
name.AsCString());
749749
const char *item_name = name.GetCString();
750-
uint32_t idx = ExtractIndexFromString(item_name);
751-
if (idx == UINT32_MAX || idx >= CalculateNumChildrenIgnoringErrors())
750+
auto optional_idx = ExtractIndexFromString(item_name);
751+
if (!optional_idx ||
752+
optional_idx.value() >= CalculateNumChildrenIgnoringErrors())
752753
return llvm::createStringError("Type has no child named '%s'",
753754
name.AsCString());
754-
return idx;
755+
return optional_idx.value();
755756
}

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,54 +1703,54 @@ bool SwiftLanguage::IsUninitializedReference(ValueObject &valobj) {
17031703
}
17041704

17051705
bool SwiftLanguage::GetFunctionDisplayName(
1706-
const SymbolContext *sc, const ExecutionContext *exe_ctx,
1706+
const SymbolContext &sc, const ExecutionContext *exe_ctx,
17071707
FunctionNameRepresentation representation, Stream &s) {
17081708
switch (representation) {
17091709
case Language::FunctionNameRepresentation::eName:
17101710
// No need to customize this.
17111711
return false;
17121712
case Language::FunctionNameRepresentation::eNameWithNoArgs: {
1713-
if (!sc->function)
1713+
if (!sc.function)
17141714
return false;
1715-
if (sc->function->GetLanguage() != eLanguageTypeSwift)
1715+
if (sc.function->GetLanguage() != eLanguageTypeSwift)
17161716
return false;
17171717
std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString(
1718-
sc->function->GetMangled().GetMangledName().GetStringRef(),
1719-
SwiftLanguageRuntime::eSimplified, sc, exe_ctx);
1718+
sc.function->GetMangled().GetMangledName().GetStringRef(),
1719+
SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
17201720
if (display_name.empty())
17211721
return false;
17221722
s << display_name;
17231723
return true;
17241724
}
17251725
case Language::FunctionNameRepresentation::eNameWithArgs: {
1726-
if (!sc->function)
1726+
if (!sc.function)
17271727
return false;
1728-
if (sc->function->GetLanguage() != eLanguageTypeSwift)
1728+
if (sc.function->GetLanguage() != eLanguageTypeSwift)
17291729
return false;
17301730
std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString(
1731-
sc->function->GetMangled().GetMangledName().GetStringRef(),
1732-
SwiftLanguageRuntime::eSimplified, sc, exe_ctx);
1731+
sc.function->GetMangled().GetMangledName().GetStringRef(),
1732+
SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
17331733
if (display_name.empty())
17341734
return false;
17351735
ExecutionContextScope *exe_scope =
17361736
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
17371737
const InlineFunctionInfo *inline_info = NULL;
17381738
VariableListSP variable_list_sp;
17391739
bool get_function_vars = true;
1740-
if (sc->block) {
1741-
Block *inline_block = sc->block->GetContainingInlinedBlock();
1740+
if (sc.block) {
1741+
Block *inline_block = sc.block->GetContainingInlinedBlock();
17421742

17431743
if (inline_block) {
17441744
get_function_vars = false;
1745-
inline_info = sc->block->GetInlinedFunctionInfo();
1745+
inline_info = sc.block->GetInlinedFunctionInfo();
17461746
if (inline_info)
17471747
variable_list_sp = inline_block->GetBlockVariableList(true);
17481748
}
17491749
}
17501750

17511751
if (get_function_vars) {
17521752
variable_list_sp =
1753-
sc->function->GetBlock(true).GetBlockVariableList(true);
1753+
sc.function->GetBlock(true).GetBlockVariableList(true);
17541754
}
17551755

17561756
if (inline_info) {

lldb/source/Plugins/Language/Swift/SwiftLanguage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class SwiftLanguage : public Language {
6464

6565
bool IsUninitializedReference(ValueObject &valobj) override;
6666

67-
bool GetFunctionDisplayName(const SymbolContext *sc,
67+
bool GetFunctionDisplayName(const SymbolContext &sc,
6868
const ExecutionContext *exe_ctx,
6969
FunctionNameRepresentation representation,
7070
Stream &s) override;

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
214214
// aware of local symbols, so avoid returning those.
215215
using namespace swift::Demangle;
216216
if (isSwiftSymbol(mangledName) && !isOldFunctionTypeMangling(mangledName))
217-
return {{mangledName, 0}};
217+
return swift::remote::RemoteAbsolutePointer{mangledName, 0, address};
218218
}
219219

220220
return {};
@@ -228,15 +228,16 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
228228
// We may have gotten a pointer to a process address, try to map it back
229229
// to a tagged address so further memory reads originating from it benefit
230230
// from the file-cache optimization.
231-
swift::remote::RemoteAbsolutePointer process_pointer("", readValue);
231+
swift::remote::RemoteAbsolutePointer process_pointer{
232+
swift::remote::RemoteAddress{readValue}};
232233

233234
if (!readMetadataFromFileCacheEnabled())
234235
return process_pointer;
235236

236237
// Try to strip the pointer before checking if we have it mapped.
237238
auto strippedPointer = signedPointerStripper(process_pointer);
238-
if (strippedPointer.isResolved())
239-
readValue = strippedPointer.getOffset();
239+
if (auto resolved = strippedPointer.getResolvedAddress())
240+
readValue = resolved.getAddressData();
240241

241242
auto &target = m_process.GetTarget();
242243
Address addr;
@@ -294,9 +295,12 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
294295
return process_pointer;
295296
}
296297

297-
swift::remote::RemoteAbsolutePointer tagged_pointer("", tagged_address);
298-
if (tagged_address !=
299-
(uint64_t)signedPointerStripper(tagged_pointer).getOffset()) {
298+
swift::remote::RemoteAbsolutePointer tagged_pointer{
299+
swift::remote::RemoteAddress{tagged_address}};
300+
301+
if (tagged_address != (uint64_t)signedPointerStripper(tagged_pointer)
302+
.getResolvedAddress()
303+
.getAddressData()) {
300304
lldbassert(false &&
301305
"Tagged pointer runs into pointer authentication mask!");
302306
return process_pointer;
@@ -528,9 +532,11 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
528532
auto module_end_address = module_start_address + size;
529533

530534
if (module_end_address !=
531-
(uint64_t)signedPointerStripper(
532-
swift::remote::RemoteAbsolutePointer("", module_end_address))
533-
.getOffset()) {
535+
signedPointerStripper(
536+
swift::remote::RemoteAbsolutePointer{
537+
swift::remote::RemoteAddress{module_end_address}})
538+
.getResolvedAddress()
539+
.getAddressData()) {
534540
LLDB_LOG(GetLog(LLDBLog::Types),
535541
"[MemoryReader] module to address map ran into pointer "
536542
"authentication mask!");

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,7 @@ void SwiftLanguageRuntime::FindFunctionPointersInCall(
11761176
if (target_context.symbol)
11771177
fn_ptr_address = target_context.symbol->GetAddress();
11781178
else if (target_context.function)
1179-
fn_ptr_address =
1180-
target_context.function->GetAddressRange().GetBaseAddress();
1179+
fn_ptr_address = target_context.function->GetAddress();
11811180
}
11821181
}
11831182
}
@@ -1602,13 +1601,14 @@ class ProjectionSyntheticChildren : public SyntheticChildren {
16021601
return nullptr;
16031602
}
16041603

1605-
size_t GetIndexOfChildWithName(ConstString name) override {
1604+
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
16061605
for (size_t idx = 0; idx < m_projection->field_projections.size();
16071606
idx++) {
16081607
if (m_projection->field_projections.at(idx).name == name)
16091608
return idx;
16101609
}
1611-
return UINT32_MAX;
1610+
return llvm::createStringError("Type has no child named '%s'",
1611+
name.AsCString());
16121612
}
16131613

16141614
lldb::ChildCacheState Update() override {
@@ -2486,7 +2486,7 @@ static llvm::Expected<addr_t> ReadPtrFromAddr(Process &process, addr_t addr,
24862486
/// access to those here would be challenging.
24872487
static llvm::Expected<addr_t> GetCFA(Process &process, RegisterContext &regctx,
24882488
addr_t pc_offset,
2489-
UnwindPlan &unwind_plan) {
2489+
const UnwindPlan &unwind_plan) {
24902490
auto *row = unwind_plan.GetRowForFunctionOffset(pc_offset);
24912491
if (!row)
24922492
return llvm::createStringError(
@@ -2516,22 +2516,22 @@ static llvm::Expected<addr_t> GetCFA(Process &process, RegisterContext &regctx,
25162516
cfa_loc.GetValueType());
25172517
}
25182518

2519-
static UnwindPlanSP GetUnwindPlanForAsyncRegister(FuncUnwinders &unwinders,
2520-
Target &target,
2521-
Thread &thread) {
2519+
static std::shared_ptr<const UnwindPlan>
2520+
GetUnwindPlanForAsyncRegister(FuncUnwinders &unwinders, Target &target,
2521+
Thread &thread) {
25222522
// We cannot trust compiler emitted unwind plans, as they respect the
25232523
// swifttail calling convention, which assumes the async register is _not_
25242524
// restored and therefore it is not tracked by compiler plans. If LLDB uses
25252525
// those plans, it may take "no info" to mean "register not clobbered". For
25262526
// those reasons, always favour the assembly plan first, it will try to track
25272527
// the async register by assuming the usual arm calling conventions.
2528-
if (UnwindPlanSP asm_plan = unwinders.GetAssemblyUnwindPlan(target, thread))
2528+
if (auto asm_plan = unwinders.GetAssemblyUnwindPlan(target, thread))
25292529
return asm_plan;
25302530
// In the unlikely case the assembly plan is not available, try all others.
25312531
return unwinders.GetUnwindPlanAtNonCallSite(target, thread);
25322532
}
25332533

2534-
static llvm::Expected<UnwindPlanSP>
2534+
static llvm::Expected<std::shared_ptr<const UnwindPlan>>
25352535
GetAsmUnwindPlan(Address pc, SymbolContext &sc, Thread &thread) {
25362536
FuncUnwindersSP unwinders =
25372537
pc.GetModule()->GetUnwindTable().GetFuncUnwindersContainingAddress(pc,
@@ -2541,7 +2541,7 @@ GetAsmUnwindPlan(Address pc, SymbolContext &sc, Thread &thread) {
25412541
"function unwinder at address 0x%8.8" PRIx64,
25422542
pc.GetFileAddress());
25432543

2544-
UnwindPlanSP unwind_plan = GetUnwindPlanForAsyncRegister(
2544+
auto unwind_plan = GetUnwindPlanForAsyncRegister(
25452545
*unwinders, thread.GetProcess()->GetTarget(), thread);
25462546
if (!unwind_plan)
25472547
return llvm::createStringError(
@@ -2551,8 +2551,8 @@ GetAsmUnwindPlan(Address pc, SymbolContext &sc, Thread &thread) {
25512551
return unwind_plan;
25522552
}
25532553

2554-
static llvm::Expected<uint32_t> GetFpRegisterNumber(UnwindPlan &unwind_plan,
2555-
RegisterContext &regctx) {
2554+
static llvm::Expected<uint32_t>
2555+
GetFpRegisterNumber(const UnwindPlan &unwind_plan, RegisterContext &regctx) {
25562556
uint32_t fp_unwind_regdomain;
25572557
if (!regctx.ConvertBetweenRegisterKinds(
25582558
lldb::eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP,
@@ -2569,7 +2569,7 @@ static llvm::Expected<uint32_t> GetFpRegisterNumber(UnwindPlan &unwind_plan,
25692569
}
25702570

25712571
struct FrameSetupInfo {
2572-
addr_t frame_setup_func_offset;
2572+
int64_t frame_setup_func_offset;
25732573
int fp_cfa_offset;
25742574
};
25752575

@@ -2580,7 +2580,7 @@ struct FrameSetupInfo {
25802580
/// compared against it.
25812581
/// 2. The CFA offset at which FP is stored, meaningless in the frameless case.
25822582
static llvm::Expected<FrameSetupInfo>
2583-
GetFrameSetupInfo(UnwindPlan &unwind_plan, RegisterContext &regctx) {
2583+
GetFrameSetupInfo(const UnwindPlan &unwind_plan, RegisterContext &regctx) {
25842584
using AbstractRegisterLocation = UnwindPlan::Row::AbstractRegisterLocation;
25852585

25862586
llvm::Expected<uint32_t> fp_unwind_regdomain =
@@ -2610,7 +2610,7 @@ GetFrameSetupInfo(UnwindPlan &unwind_plan, RegisterContext &regctx) {
26102610
// This is a frameless function, use large positive offset so that a PC can
26112611
// still be compared against it.
26122612
if (it == fp_locs.end())
2613-
return FrameSetupInfo{std::numeric_limits<addr_t>::max(), 0};
2613+
return FrameSetupInfo{std::numeric_limits<int64_t>::max(), 0};
26142614

26152615
// This is an async function with a frame. The prologue roughly follows this
26162616
// sequence of instructions:
@@ -2645,7 +2645,7 @@ GetFrameSetupInfo(UnwindPlan &unwind_plan, RegisterContext &regctx) {
26452645
static llvm::Expected<addr_t> ReadAsyncContextRegisterFromUnwind(
26462646
SymbolContext &sc, Process &process, Address pc, Address func_start_addr,
26472647
RegisterContext &regctx, AsyncUnwindRegisterNumbers regnums) {
2648-
llvm::Expected<UnwindPlanSP> unwind_plan =
2648+
llvm::Expected<std::shared_ptr<const UnwindPlan>> unwind_plan =
26492649
GetAsmUnwindPlan(pc, sc, regctx.GetThread());
26502650
if (!unwind_plan)
26512651
return unwind_plan.takeError();
@@ -2657,7 +2657,7 @@ static llvm::Expected<addr_t> ReadAsyncContextRegisterFromUnwind(
26572657
// Is PC before the frame formation? If so, use async register directly.
26582658
// This handles frameless functions, as frame_setup_func_offset is INT_MAX.
26592659
addr_t pc_offset = pc.GetFileAddress() - func_start_addr.GetFileAddress();
2660-
if (pc_offset < frame_setup->frame_setup_func_offset)
2660+
if ((int64_t)pc_offset < frame_setup->frame_setup_func_offset)
26612661
return ReadRegisterAsAddress(regctx, regnums.GetRegisterKind(),
26622662
regnums.async_ctx_regnum);
26632663

@@ -2688,9 +2688,11 @@ DoesContinuationPointToSameFunction(addr_t async_reg, SymbolContext &sc,
26882688
Address continuation_addr;
26892689
continuation_addr.SetLoadAddress(process.FixCodeAddress(*continuation_ptr),
26902690
&process.GetTarget());
2691-
if (sc.function)
2692-
return sc.function->GetAddressRange().ContainsLoadAddress(
2693-
continuation_addr, &process.GetTarget());
2691+
if (sc.function) {
2692+
AddressRange unused_range;
2693+
return sc.function->GetRangeContainingLoadAddress(
2694+
continuation_addr.GetOffset(), process.GetTarget(), unused_range);
2695+
}
26942696
assert(sc.symbol);
26952697
return sc.symbol->ContainsFileAddress(continuation_addr.GetFileAddress());
26962698
}
@@ -2724,8 +2726,7 @@ static llvm::Expected<bool> IsIndirectContext(Process &process,
27242726
uint32_t prologue_size = sc.function ? sc.function->GetPrologueByteSize()
27252727
: sc.symbol->GetPrologueByteSize();
27262728
Address func_start_addr =
2727-
sc.function ? sc.function->GetAddressRange().GetBaseAddress()
2728-
: sc.symbol->GetAddress();
2729+
sc.function ? sc.function->GetAddress() : sc.symbol->GetAddress();
27292730
// Include one instruction after the prologue. This is where breakpoints
27302731
// by function name are set, so it's important to get this point right. This
27312732
// instruction is exactly at address "base + prologue", so adding 1
@@ -2776,7 +2777,7 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
27762777
Address func_start_addr;
27772778
ConstString mangled_name;
27782779
if (sc.function) {
2779-
func_start_addr = sc.function->GetAddressRange().GetBaseAddress();
2780+
func_start_addr = sc.function->GetAddress();
27802781
mangled_name = sc.function->GetMangled().GetMangledName();
27812782
} else if (sc.symbol) {
27822783
func_start_addr = sc.symbol->GetAddress();

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,10 +2077,11 @@ CompilerType SwiftLanguageRuntime::GetDynamicTypeAndAddress_EmbeddedClass(
20772077
if (!pointer)
20782078
return {};
20792079
llvm::StringRef symbol_name;
2080-
if (pointer->isResolved()) {
2080+
if (pointer->getSymbol().empty() || pointer->getOffset()) {
20812081
// Find the symbol name at this address.
20822082
Address address;
2083-
address.SetLoadAddress(pointer->getOffset(), &GetProcess().GetTarget());
2083+
address.SetLoadAddress(pointer->getResolvedAddress().getAddressData(),
2084+
&GetProcess().GetTarget());
20842085
Symbol *symbol = address.CalculateSymbolContextSymbol();
20852086
if (!symbol)
20862087
return {};
@@ -2377,8 +2378,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
23772378
return false;
23782379

23792380
uint64_t address = 0;
2380-
if (maybe_addr_or_symbol->isResolved()) {
2381-
address = maybe_addr_or_symbol->getOffset();
2381+
if (maybe_addr_or_symbol->getSymbol().empty() &&
2382+
maybe_addr_or_symbol->getOffset() == 0) {
2383+
address = maybe_addr_or_symbol->getResolvedAddress().getAddressData();
23822384
} else {
23832385
SymbolContextList sc_list;
23842386
auto &module_list = GetProcess().GetTarget().GetImages();
@@ -2397,7 +2399,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
23972399
GetDynamicTypeAndAddress_EmbeddedClass(address, existential_type);
23982400
if (!dynamic_type)
23992401
return false;
2400-
dynamic_address = maybe_addr_or_symbol->getOffset();
2402+
dynamic_address = maybe_addr_or_symbol->getResolvedAddress().getAddressData();
24012403
}
24022404
if (use_local_buffer)
24032405
PopLocalBuffer();

0 commit comments

Comments
 (0)