[Lldb-commits] [lldb] [lldb][TypeSystem][NFCI] Log creation of new TypeSystem instances to expression log (PR #91985)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Mon May 13 09:22:10 PDT 2024
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/91985
>From 1ccf935f97b21e0bd87955f3313cb47261d11379 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Mon, 13 May 2024 15:34:24 +0100
Subject: [PATCH 1/3] [lldb][TypeSystem][NFCI] Log creation of new TypeSystem
instances to expression log
We emit `ASTContext` and `TypeSystem` pointers into the `expr` log
but there is no easy way (that I know of) to correlate the pointer
value back to an easily readible form. This patch simply logs the name
of the `TypeSystem` and the associated `ASTContext` into the `expr`
channel whenever we create a new `TypeSystemClang`.
---
.../TypeSystem/Clang/TypeSystemClang.cpp | 21 +++++++++++++++----
.../TypeSystem/Clang/TypeSystemClang.h | 4 +++-
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index d0033fcd9cdfc..a7b5c55098de2 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -501,6 +501,8 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
// The caller didn't pass an ASTContext so create a new one for this
// TypeSystemClang.
CreateASTContext();
+
+ LogCreation();
}
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
@@ -510,6 +512,8 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
m_ast_up.reset(&existing_ctxt);
GetASTMap().Insert(&existing_ctxt, this);
+
+ LogCreation();
}
// Destructor
@@ -544,13 +548,16 @@ lldb::TypeSystemSP TypeSystemClang::CreateInstance(lldb::LanguageType language,
}
}
+ lldb::TypeSystemSP instance;
+
if (module) {
std::string ast_name =
"ASTContext for '" + module->GetFileSpec().GetPath() + "'";
- return std::make_shared<TypeSystemClang>(ast_name, triple);
+ instance = std::make_shared<TypeSystemClang>(ast_name, triple);
} else if (target && target->IsValid())
- return std::make_shared<ScratchTypeSystemClang>(*target, triple);
- return lldb::TypeSystemSP();
+ instance = std::make_shared<ScratchTypeSystemClang>(*target, triple);
+
+ return instance;
}
LanguageSet TypeSystemClang::GetSupportedLanguagesForTypes() {
@@ -630,7 +637,7 @@ void TypeSystemClang::SetExternalSource(
ast.setExternalSource(ast_source_up);
}
-ASTContext &TypeSystemClang::getASTContext() {
+ASTContext &TypeSystemClang::getASTContext() const {
assert(m_ast_up);
return *m_ast_up;
}
@@ -9750,3 +9757,9 @@ bool TypeSystemClang::SetDeclIsForcefullyCompleted(const clang::TagDecl *td) {
metadata->SetIsForcefullyCompleted();
return true;
}
+
+void TypeSystemClang::LogCreation() const {
+ if (auto *log = GetLog(LLDBLog::Expressions))
+ LLDB_LOG(log, "Created new TypeSystem for (ASTContext*){0:x} '{1}'",
+ &getASTContext(), getDisplayName());
+}
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 59ca69622d9e8..6ba2c44c36584 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -162,7 +162,7 @@ class TypeSystemClang : public TypeSystem {
llvm::StringRef getDisplayName() const { return m_display_name; }
/// Returns the clang::ASTContext instance managed by this TypeSystemClang.
- clang::ASTContext &getASTContext();
+ clang::ASTContext &getASTContext() const;
clang::MangleContext *getMangleContext();
@@ -1166,6 +1166,8 @@ class TypeSystemClang : public TypeSystem {
bool IsTypeImpl(lldb::opaque_compiler_type_t type,
llvm::function_ref<bool(clang::QualType)> predicate) const;
+ void LogCreation() const;
+
// Classes that inherit from TypeSystemClang can see and modify these
std::string m_target_triple;
std::unique_ptr<clang::ASTContext> m_ast_up;
>From 8cb97736d9ba9bd2f1a0bc10f96c3ad7b9f9f59f Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Mon, 13 May 2024 17:19:21 +0100
Subject: [PATCH 2/3] fixup! revert obsolete changes
---
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index a7b5c55098de2..8b9ef98071e68 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -548,16 +548,14 @@ lldb::TypeSystemSP TypeSystemClang::CreateInstance(lldb::LanguageType language,
}
}
- lldb::TypeSystemSP instance;
-
if (module) {
std::string ast_name =
"ASTContext for '" + module->GetFileSpec().GetPath() + "'";
- instance = std::make_shared<TypeSystemClang>(ast_name, triple);
+ return std::make_shared<TypeSystemClang>(ast_name, triple);
} else if (target && target->IsValid())
- instance = std::make_shared<ScratchTypeSystemClang>(*target, triple);
+ return std::make_shared<ScratchTypeSystemClang>(*target, triple);
- return instance;
+ return lldb::TypeSystemSP();
}
LanguageSet TypeSystemClang::GetSupportedLanguagesForTypes() {
>From f3f982c275e0fa31efd2898de622239ead7bdd26 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Mon, 13 May 2024 17:21:52 +0100
Subject: [PATCH 3/3] fixup! add comment; fix whitespace
---
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 1 -
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 4 ++++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 8b9ef98071e68..17a9c675fbba4 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -554,7 +554,6 @@ lldb::TypeSystemSP TypeSystemClang::CreateInstance(lldb::LanguageType language,
return std::make_shared<TypeSystemClang>(ast_name, triple);
} else if (target && target->IsValid())
return std::make_shared<ScratchTypeSystemClang>(*target, triple);
-
return lldb::TypeSystemSP();
}
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 6ba2c44c36584..042379d40bcb3 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -1166,6 +1166,10 @@ class TypeSystemClang : public TypeSystem {
bool IsTypeImpl(lldb::opaque_compiler_type_t type,
llvm::function_ref<bool(clang::QualType)> predicate) const;
+ /// Emits information about this TypeSystem into the expression log.
+ ///
+ /// Helper method that is used in \ref TypeSystemClang::TypeSystemClang
+ /// on creation of a new instance.
void LogCreation() const;
// Classes that inherit from TypeSystemClang can see and modify these
More information about the lldb-commits
mailing list