Skip to content

[lldb][ClangASTImporter][NFC] Emit a log message when we break MapImported invariant #9454

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
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
36 changes: 26 additions & 10 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,30 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {

void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
clang::Decl *to, clang::Decl *from) {
Log *log = GetLog(LLDBLog::Expressions);

auto getDeclName = [](Decl const *decl) {
std::string name_string;
if (auto const *from_named_decl = dyn_cast<clang::NamedDecl>(decl)) {
llvm::raw_string_ostream name_stream(name_string);
from_named_decl->printName(name_stream);
name_stream.flush();
}

return name_string;
};

if (log) {
if (auto *D = GetAlreadyImportedOrNull(from); D && D != to) {
LLDB_LOG(
log,
"[ClangASTImporter] ERROR: overwriting an already imported decl "
"'{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
"conflict when importing '{1}'.",
D, getDeclName(from), from, to);
}
}

// We might have a forward declaration from a shared library that we
// gave external lexical storage so that Clang asks us about the full
// definition when it needs it. In this case the ASTImporter isn't aware
Expand All @@ -1239,8 +1263,6 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
// tell the ASTImporter that 'to' was imported from 'from'.
MapImported(from, to);

Log *log = GetLog(LLDBLog::Expressions);

if (llvm::Error err = ImportDefinition(from)) {
LLDB_LOG_ERROR(log, std::move(err),
"[ClangASTImporter] Error during importing definition: {0}");
Expand All @@ -1252,19 +1274,13 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
to_tag->setCompleteDefinition(from_tag->isCompleteDefinition());

if (Log *log_ast = GetLog(LLDBLog::AST)) {
std::string name_string;
if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) {
llvm::raw_string_ostream name_stream(name_string);
from_named_decl->printName(name_stream);
name_stream.flush();
}
LLDB_LOG(log_ast,
"==== [ClangASTImporter][TUDecl: {0:x}] Imported "
"({1}Decl*){2:x}, named {3} (from "
"(Decl*){4:x})",
static_cast<void *>(to->getTranslationUnitDecl()),
from->getDeclKindName(), static_cast<void *>(to), name_string,
static_cast<void *>(from));
from->getDeclKindName(), static_cast<void *>(to),
getDeclName(from), static_cast<void *>(from));

// Log the AST of the TU.
std::string ast_string;
Expand Down