Skip to content

[lldb] Adapt lldb to new ASTMangler constructor #9683

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -1490,10 +1490,11 @@ bool SwiftExpressionParser::Complete(CompletionRequest &request, unsigned line,
/// system.
static bool
RedirectCallFromSinkToTrampolineFunction(llvm::Module &module,
SwiftASTManipulator &manipulator) {
SwiftASTManipulator &manipulator,
swift::ASTContext &ast_ctx) {
Log *log = GetLog(LLDBLog::Expressions);

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

if (m_options.GetBindGenericTypes() == lldb::eDontBind &&
!RedirectCallFromSinkToTrampolineFunction(
*m_module.get(), *parsed_expr->code_manipulator.get())) {
diagnostic_manager.Printf(
eSeverityError,
"couldn't setup call to the trampoline function. Please enable the "
"expression log by running \"log enable lldb "
"expr\", then run the failing expression again, and file a "
"bugreport with the log output.");
return ParseResult::unrecoverable_error;
if (ThreadSafeASTContext ast_ctx = m_swift_ast_ctx.GetASTContext()) {
if (m_options.GetBindGenericTypes() == lldb::eDontBind &&
!RedirectCallFromSinkToTrampolineFunction(
*m_module.get(), *parsed_expr->code_manipulator.get(), **ast_ctx)) {
diagnostic_manager.Printf(
eSeverityError,
"couldn't setup call to the trampoline function. Please enable the "
"expression log by running \"log enable lldb "
"expr\", then run the failing expression again, and file a "
"bugreport with the log output.");
return ParseResult::unrecoverable_error;
}
}

if (log) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1501,11 +1501,14 @@ void SwiftLanguageRuntime::RegisterGlobalError(Target &target, ConstString name,

ConstString mangled_name;

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

if (mangled_name.IsEmpty())
return;

lldb::addr_t symbol_addr;

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,12 @@ CompilerType SwiftLanguageRuntimeImpl::BindGenericTypeParametersRemoteAST(
if (target_swift_type->hasArchetype())
target_swift_type = target_swift_type->mapTypeOutOfContext().getPointer();

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

// Replace opaque types with their underlying types when possible.
swift::Mangle::ASTMangler mangler(**ast_ctx, true);
// Rewrite all dynamic self types to their static self types.
target_swift_type =
target_swift_type.transformRec([](swift::TypeBase *type)
Expand Down
6 changes: 5 additions & 1 deletion lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4560,7 +4560,11 @@ ConstString SwiftASTContext::GetMangledTypeName(swift::TypeBase *type_base) {

assert(!swift_type->hasArchetype() &&
"type has not been mapped out of context");
swift::Mangle::ASTMangler mangler(true);
ThreadSafeASTContext ast_ctx = GetASTContext();
if (!ast_ctx)
return {};

swift::Mangle::ASTMangler mangler(**ast_ctx, true);
std::string s = mangler.mangleTypeForDebugger(swift_type, nullptr);
if (s.empty())
return {};
Expand Down