Skip to content

[next][Swift] lldb: Fix some build errors #11004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,16 @@ class URLComponentsSyntheticChildrenFrontEnd
m_synth_frontend_up->Update();

#define COMPONENT(Name, PrettyName, ID) \
auto index_or_err = m_synth_frontend_up->GetIndexOfChildWithName(g__##Name); \
if (!index_or_err) { \
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), index_or_err.takeError(), \
"{0}"); \
return ChildCacheState::eRefetch; \
{ \
auto index_or_err = \
m_synth_frontend_up->GetIndexOfChildWithName(g__##Name); \
if (!index_or_err) { \
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), \
index_or_err.takeError(), "{0}"); \
return ChildCacheState::eRefetch; \
} \
m_##Name = m_synth_frontend_up->GetChildAtIndex(*index_or_err).get(); \
} \
m_##Name = m_synth_frontend_up->GetChildAtIndex(*index_or_err).get(); \
if (m_##Name) \
m_##Name->SetName(GetNameFor##Name());
#include "URLComponents.def"
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/Language/Swift/SwiftArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,12 @@ llvm::Expected<size_t> lldb_private::formatters::swift::ArraySyntheticFrontEnd::
return llvm::createStringError("Type has no child named '%s'",
name.AsCString());
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
if (idx == UINT32_MAX || idx >= CalculateNumChildrenIgnoringErrors())
auto optional_idx = ExtractIndexFromString(item_name);
if (!optional_idx ||
optional_idx.value() >= CalculateNumChildrenIgnoringErrors())
return llvm::createStringError("Type has no child named '%s'",
name.AsCString());
return idx;
return optional_idx.value();
}

SyntheticChildrenFrontEnd *
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,10 @@ HashedSyntheticChildrenFrontEnd::GetIndexOfChildWithName(ConstString name) {
return llvm::createStringError("Type has no child named '%s'",
name.AsCString());
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
if (idx == UINT32_MAX || idx >= CalculateNumChildrenIgnoringErrors())
auto optional_idx = ExtractIndexFromString(item_name);
if (!optional_idx ||
optional_idx.value() >= CalculateNumChildrenIgnoringErrors())
return llvm::createStringError("Type has no child named '%s'",
name.AsCString());
return idx;
return optional_idx.value();
}
18 changes: 9 additions & 9 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,20 +1717,20 @@ bool SwiftLanguage::IsUninitializedReference(ValueObject &valobj) {
}

bool SwiftLanguage::GetFunctionDisplayName(
const SymbolContext *sc, const ExecutionContext *exe_ctx,
const SymbolContext &sc, const ExecutionContext *exe_ctx,
FunctionNameRepresentation representation, Stream &s) {
switch (representation) {
case Language::FunctionNameRepresentation::eName:
// No need to customize this.
return false;
case Language::FunctionNameRepresentation::eNameWithNoArgs: {
if (!sc->function)
if (!sc.function)
return false;
if (sc->function->GetLanguage() != eLanguageTypeSwift)
if (sc.function->GetLanguage() != eLanguageTypeSwift)
return false;
std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString(
sc->function->GetMangled().GetMangledName().GetStringRef(),
SwiftLanguageRuntime::eSimplified, sc, exe_ctx);
sc.function->GetMangled().GetMangledName().GetStringRef(),
SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
if (display_name.empty())
return false;
s << display_name;
Expand All @@ -1744,20 +1744,20 @@ bool SwiftLanguage::GetFunctionDisplayName(
const InlineFunctionInfo *inline_info = NULL;
VariableListSP variable_list_sp;
bool get_function_vars = true;
if (sc->block) {
Block *inline_block = sc->block->GetContainingInlinedBlock();
if (sc.block) {
Block *inline_block = sc.block->GetContainingInlinedBlock();

if (inline_block) {
get_function_vars = false;
inline_info = sc->block->GetInlinedFunctionInfo();
inline_info = sc.block->GetInlinedFunctionInfo();
if (inline_info)
variable_list_sp = inline_block->GetBlockVariableList(true);
}
}

if (get_function_vars) {
variable_list_sp =
sc->function->GetBlock(true).GetBlockVariableList(true);
sc.function->GetBlock(true).GetBlockVariableList(true);
}

VariableList args;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/Swift/SwiftLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SwiftLanguage : public Language {

bool IsUninitializedReference(ValueObject &valobj) override;

bool GetFunctionDisplayName(const SymbolContext *sc,
bool GetFunctionDisplayName(const SymbolContext &sc,
const ExecutionContext *exe_ctx,
FunctionNameRepresentation representation,
Stream &s) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,7 @@ void SwiftLanguageRuntime::FindFunctionPointersInCall(
if (target_context.symbol)
fn_ptr_address = target_context.symbol->GetAddress();
else if (target_context.function)
fn_ptr_address =
target_context.function->GetAddressRange().GetBaseAddress();
fn_ptr_address = target_context.function->GetAddress();
}
}
}
Expand Down Expand Up @@ -1613,13 +1612,14 @@ class ProjectionSyntheticChildren : public SyntheticChildren {
return nullptr;
}

size_t GetIndexOfChildWithName(ConstString name) override {
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
for (size_t idx = 0; idx < m_projection->field_projections.size();
idx++) {
if (m_projection->field_projections.at(idx).name == name)
return idx;
}
return UINT32_MAX;
return llvm::createStringError("Type has no child named '%s'",
name.AsCString());
}

lldb::ChildCacheState Update() override {
Expand Down Expand Up @@ -2498,7 +2498,7 @@ static llvm::Expected<addr_t> ReadPtrFromAddr(Process &process, addr_t addr,
/// access to those here would be challenging.
static llvm::Expected<addr_t> GetCFA(Process &process, RegisterContext &regctx,
addr_t pc_offset,
UnwindPlan &unwind_plan) {
const UnwindPlan &unwind_plan) {
auto *row = unwind_plan.GetRowForFunctionOffset(pc_offset);
if (!row)
return llvm::createStringError(
Expand Down Expand Up @@ -2528,22 +2528,22 @@ static llvm::Expected<addr_t> GetCFA(Process &process, RegisterContext &regctx,
cfa_loc.GetValueType());
}

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

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

UnwindPlanSP unwind_plan = GetUnwindPlanForAsyncRegister(
auto unwind_plan = GetUnwindPlanForAsyncRegister(
*unwinders, thread.GetProcess()->GetTarget(), thread);
if (!unwind_plan)
return llvm::createStringError(
Expand All @@ -2563,8 +2563,8 @@ GetAsmUnwindPlan(Address pc, SymbolContext &sc, Thread &thread) {
return unwind_plan;
}

static llvm::Expected<uint32_t> GetFpRegisterNumber(UnwindPlan &unwind_plan,
RegisterContext &regctx) {
static llvm::Expected<uint32_t>
GetFpRegisterNumber(const UnwindPlan &unwind_plan, RegisterContext &regctx) {
uint32_t fp_unwind_regdomain;
if (!regctx.ConvertBetweenRegisterKinds(
lldb::eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP,
Expand All @@ -2581,7 +2581,7 @@ static llvm::Expected<uint32_t> GetFpRegisterNumber(UnwindPlan &unwind_plan,
}

struct FrameSetupInfo {
addr_t frame_setup_func_offset;
int64_t frame_setup_func_offset;
int fp_cfa_offset;
};

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

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

// This is an async function with a frame. The prologue roughly follows this
// sequence of instructions:
Expand Down Expand Up @@ -2657,7 +2657,7 @@ GetFrameSetupInfo(UnwindPlan &unwind_plan, RegisterContext &regctx) {
static llvm::Expected<addr_t> ReadAsyncContextRegisterFromUnwind(
SymbolContext &sc, Process &process, Address pc, Address func_start_addr,
RegisterContext &regctx, AsyncUnwindRegisterNumbers regnums) {
llvm::Expected<UnwindPlanSP> unwind_plan =
llvm::Expected<std::shared_ptr<const UnwindPlan>> unwind_plan =
GetAsmUnwindPlan(pc, sc, regctx.GetThread());
if (!unwind_plan)
return unwind_plan.takeError();
Expand All @@ -2669,7 +2669,7 @@ static llvm::Expected<addr_t> ReadAsyncContextRegisterFromUnwind(
// Is PC before the frame formation? If so, use async register directly.
// This handles frameless functions, as frame_setup_func_offset is INT_MAX.
addr_t pc_offset = pc.GetFileAddress() - func_start_addr.GetFileAddress();
if (pc_offset < frame_setup->frame_setup_func_offset)
if ((int64_t)pc_offset < frame_setup->frame_setup_func_offset)
return ReadRegisterAsAddress(regctx, regnums.GetRegisterKind(),
regnums.async_ctx_regnum);

Expand Down Expand Up @@ -2700,9 +2700,11 @@ DoesContinuationPointToSameFunction(addr_t async_reg, SymbolContext &sc,
Address continuation_addr;
continuation_addr.SetLoadAddress(process.FixCodeAddress(*continuation_ptr),
&process.GetTarget());
if (sc.function)
return sc.function->GetAddressRange().ContainsLoadAddress(
continuation_addr, &process.GetTarget());
if (sc.function) {
AddressRange unused_range;
return sc.function->GetRangeContainingLoadAddress(
continuation_addr.GetOffset(), process.GetTarget(), unused_range);
}
assert(sc.symbol);
return sc.symbol->ContainsFileAddress(continuation_addr.GetFileAddress());
}
Expand Down Expand Up @@ -2736,8 +2738,7 @@ static llvm::Expected<bool> IsIndirectContext(Process &process,
uint32_t prologue_size = sc.function ? sc.function->GetPrologueByteSize()
: sc.symbol->GetPrologueByteSize();
Address func_start_addr =
sc.function ? sc.function->GetAddressRange().GetBaseAddress()
: sc.symbol->GetAddress();
sc.function ? sc.function->GetAddress() : sc.symbol->GetAddress();
// Include one instruction after the prologue. This is where breakpoints
// by function name are set, so it's important to get this point right. This
// instruction is exactly at address "base + prologue", so adding 1
Expand Down Expand Up @@ -2788,7 +2789,7 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
Address func_start_addr;
ConstString mangled_name;
if (sc.function) {
func_start_addr = sc.function->GetAddressRange().GetBaseAddress();
func_start_addr = sc.function->GetAddress();
mangled_name = sc.function->GetMangled().GetMangledName();
} else if (sc.symbol) {
func_start_addr = sc.symbol->GetAddress();
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,10 +1886,10 @@ void SwiftASTContext::AddExtraClangCC1Args(

std::string diags;
llvm::raw_string_ostream os(diags);
auto diagOpts = llvm::makeIntrusiveRefCnt<clang::DiagnosticOptions>();
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine clangDiags(
new clang::DiagnosticIDs(), diagOpts,
new clang::TextDiagnosticPrinter(os, diagOpts.get()));
new clang::TextDiagnosticPrinter(os, diagOpts));

if (!clang::CompilerInvocation::CreateFromArgs(invocation, clangArgs,
clangDiags)) {
Expand Down
10 changes: 8 additions & 2 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,19 @@ bool TypeSystemSwift::ShouldTreatScalarValueAsAddress(
.AnySet(eTypeInstanceIsPointer | eTypeIsReference);
}

uint32_t TypeSystemSwift::GetIndexOfChildWithName(
llvm::Expected<uint32_t> TypeSystemSwift::GetIndexOfChildWithName(
opaque_compiler_type_t type, llvm::StringRef name,
ExecutionContext *exe_ctx, bool omit_empty_base_classes) {
std::vector<uint32_t> child_indexes;
size_t num_child_indexes = GetIndexOfChildMemberWithName(
type, name, exe_ctx, omit_empty_base_classes, child_indexes);
return num_child_indexes == 1 ? child_indexes.front() : UINT32_MAX;

if (num_child_indexes == 1) {
return child_indexes.front();
}

return llvm::createStringError("Type has no child named '%s'",
name.str().c_str());
}

lldb::Format TypeSystemSwift::GetFormat(opaque_compiler_type_t type) {
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ class TypeSystemSwift : public TypeSystem {

/// Lookup a child given a name. This function will match base class names
/// and member names in \p type only, not descendants.
uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
llvm::StringRef name,
ExecutionContext *exe_ctx,
bool omit_empty_base_classes) override;
llvm::Expected<uint32_t>
GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
llvm::StringRef name, ExecutionContext *exe_ctx,
bool omit_empty_base_classes) override;

CompilerType
GetLValueReferenceType(lldb::opaque_compiler_type_t type) override {
Expand Down
4 changes: 3 additions & 1 deletion lldb/unittests/Platform/PlatformSiginfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class PlatformSiginfoTest : public ::testing::Test {
for (auto field_name : llvm::split(path, '.')) {
uint64_t bit_offset;
std::string name;
auto index_or_err = field_type.GetIndexOfChildWithName(field_name, false);
lldb_private::ExecutionContext exe_ctx{};
auto index_or_err =
field_type.GetIndexOfChildWithName(field_name, &exe_ctx, false);
ASSERT_FALSE(!index_or_err);
field_type = field_type.GetFieldAtIndex(*index_or_err, name, &bit_offset,
nullptr, nullptr);
Expand Down