Skip to content

Commit 4930d5a

Browse files
authored
Merge pull request #9683 from augusto2112/adapt-ast-mangler
[lldb] Adapt lldb to new ASTMangler constructor
2 parents 7362728 + 4b4aaea commit 4930d5a

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
@@ -1490,10 +1490,11 @@ bool SwiftExpressionParser::Complete(CompletionRequest &request, unsigned line,
14901490
/// system.
14911491
static bool
14921492
RedirectCallFromSinkToTrampolineFunction(llvm::Module &module,
1493-
SwiftASTManipulator &manipulator) {
1493+
SwiftASTManipulator &manipulator,
1494+
swift::ASTContext &ast_ctx) {
14941495
Log *log = GetLog(LLDBLog::Expressions);
14951496

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

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

20862089
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
@@ -4560,7 +4560,11 @@ ConstString SwiftASTContext::GetMangledTypeName(swift::TypeBase *type_base) {
45604560

45614561
assert(!swift_type->hasArchetype() &&
45624562
"type has not been mapped out of context");
4563-
swift::Mangle::ASTMangler mangler(true);
4563+
ThreadSafeASTContext ast_ctx = GetASTContext();
4564+
if (!ast_ctx)
4565+
return {};
4566+
4567+
swift::Mangle::ASTMangler mangler(**ast_ctx, true);
45644568
std::string s = mangler.mangleTypeForDebugger(swift_type, nullptr);
45654569
if (s.empty())
45664570
return {};

0 commit comments

Comments
 (0)