Skip to content

Commit dcb4e13

Browse files
committed
[lldb] Adapt lldb to new ASTMangler constructor
ASTMangler needs an ast context due to the new embedded Swift mangling change. This patch simply keeps LLDB building by using the new contructor. (cherry picked from commit 4b4aaea)
1 parent dccb030 commit dcb4e13

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,10 +1492,11 @@ bool SwiftExpressionParser::Complete(CompletionRequest &request, unsigned line,
14921492
/// system.
14931493
static bool
14941494
RedirectCallFromSinkToTrampolineFunction(llvm::Module &module,
1495-
SwiftASTManipulator &manipulator) {
1495+
SwiftASTManipulator &manipulator,
1496+
swift::ASTContext &ast_ctx) {
14961497
Log *log = GetLog(LLDBLog::Expressions);
14971498

1498-
swift::Mangle::ASTMangler mangler;
1499+
swift::Mangle::ASTMangler mangler(ast_ctx);
14991500
auto *entrypoint_decl = manipulator.GetEntrypointDecl();
15001501
if (!entrypoint_decl) {
15011502
LLDB_LOG(log, "[RedirectCallFromSinkToTrampolineFunction] Could not set "
@@ -2072,16 +2073,18 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
20722073
LLDB_LOG(log, "Generated IR module:\n{0}", s);
20732074
}
20742075

2075-
if (m_options.GetBindGenericTypes() == lldb::eDontBind &&
2076-
!RedirectCallFromSinkToTrampolineFunction(
2077-
*m_module.get(), *parsed_expr->code_manipulator.get())) {
2078-
diagnostic_manager.Printf(
2079-
eSeverityError,
2080-
"couldn't setup call to the trampoline function. Please enable the "
2081-
"expression log by running \"log enable lldb "
2082-
"expr\", then run the failing expression again, and file a "
2083-
"bugreport with the log output.");
2084-
return ParseResult::unrecoverable_error;
2076+
if (ThreadSafeASTContext ast_ctx = m_swift_ast_ctx.GetASTContext()) {
2077+
if (m_options.GetBindGenericTypes() == lldb::eDontBind &&
2078+
!RedirectCallFromSinkToTrampolineFunction(
2079+
*m_module.get(), *parsed_expr->code_manipulator.get(), **ast_ctx)) {
2080+
diagnostic_manager.Printf(
2081+
eSeverityError,
2082+
"couldn't setup call to the trampoline function. Please enable the "
2083+
"expression log by running \"log enable lldb "
2084+
"expr\", then run the failing expression again, and file a "
2085+
"bugreport with the log output.");
2086+
return ParseResult::unrecoverable_error;
2087+
}
20852088
}
20862089

20872090
if (log) {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,14 @@ void SwiftLanguageRuntime::RegisterGlobalError(Target &target, ConstString name,
15011501

15021502
ConstString mangled_name;
15031503

1504-
{
1505-
swift::Mangle::ASTMangler mangler(true);
1504+
if (ThreadSafeASTContext ast_ctx = swift_ast_ctx->GetASTContext()) {
1505+
swift::Mangle::ASTMangler mangler(**ast_ctx, true);
15061506
mangled_name = ConstString(mangler.mangleGlobalVariableFull(var_decl));
15071507
}
15081508

1509+
if (mangled_name.IsEmpty())
1510+
return;
1511+
15091512
lldb::addr_t symbol_addr;
15101513

15111514
{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,12 @@ CompilerType SwiftLanguageRuntimeImpl::BindGenericTypeParametersRemoteAST(
297297
if (target_swift_type->hasArchetype())
298298
target_swift_type = target_swift_type->mapTypeOutOfContext().getPointer();
299299

300-
// Replace opaque types with their underlying types when possible.
301-
swift::Mangle::ASTMangler mangler(true);
300+
ThreadSafeASTContext ast_ctx = swift_ast_ctx->GetASTContext();
301+
if (!ast_ctx)
302+
return base_type;
302303

304+
// Replace opaque types with their underlying types when possible.
305+
swift::Mangle::ASTMangler mangler(**ast_ctx, true);
303306
// Rewrite all dynamic self types to their static self types.
304307
target_swift_type =
305308
target_swift_type.transformRec([](swift::TypeBase *type)

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4579,7 +4579,11 @@ ConstString SwiftASTContext::GetMangledTypeName(swift::TypeBase *type_base) {
45794579

45804580
assert(!swift_type->hasArchetype() &&
45814581
"type has not been mapped out of context");
4582-
swift::Mangle::ASTMangler mangler(true);
4582+
ThreadSafeASTContext ast_ctx = GetASTContext();
4583+
if (!ast_ctx)
4584+
return {};
4585+
4586+
swift::Mangle::ASTMangler mangler(**ast_ctx, true);
45834587
std::string s = mangler.mangleTypeForDebugger(swift_type, nullptr);
45844588
if (s.empty())
45854589
return {};

0 commit comments

Comments
 (0)