Skip to content

[lldb][TypeSystem][NFCI] Log creation of new TypeSystem instances to expression log #91985

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 4 commits into from
May 13, 2024

Conversation

Michael137
Copy link
Member

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.

The following is an example of the new log entries:

$ grep Created /tmp/lldb.log 
 Created new TypeSystem for (ASTContext*)0x0000000101a2e200 'ASTContext for '/Users/michaelbuch/a.out''
 Created new TypeSystem for (ASTContext*)0x0000000102512a00 'scratch ASTContext'
 Created new TypeSystem for (ASTContext*)0x0000000102116a00 'ClangModulesDeclVendor ASTContext'
 Created new TypeSystem for (ASTContext*)0x00000001022e8c00 'Expression ASTContext for '<user expression 0>''
 Created new TypeSystem for (ASTContext*)0x00000001103e7200 'AppleObjCTypeEncodingParser ASTContext'
 Created new TypeSystem for (ASTContext*)0x00000001103f7000 'AppleObjCDeclVendor AST'
 Created new TypeSystem for (ASTContext*)0x00000001104bfe00 'Expression ASTContext for '<clang expression>''
 Created new TypeSystem for (ASTContext*)0x0000000101f01000 'Expression ASTContext for '<clang expression>''
 Created new TypeSystem for (ASTContext*)0x00000001025d3c00 'Expression ASTContext for '<clang expression>''
 Created new TypeSystem for (ASTContext*)0x0000000110422400 'Expression ASTContext for '<clang expression>''
 Created new TypeSystem for (ASTContext*)0x000000011602c200 'Expression ASTContext for '<user expression 1>''
 Created new TypeSystem for (ASTContext*)0x0000000110641600 'Expression ASTContext for '<clang expression>''
 Created new TypeSystem for (ASTContext*)0x0000000110617400 'Expression ASTContext for '<clang expression>''

…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`.
@Michael137 Michael137 requested a review from JDevlieghere as a code owner May 13, 2024 16:02
@llvmbot llvmbot added the lldb label May 13, 2024
@llvmbot
Copy link
Member

llvmbot commented May 13, 2024

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

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.

The following is an example of the new log entries:

$ grep Created /tmp/lldb.log 
 Created new TypeSystem for (ASTContext*)0x0000000101a2e200 'ASTContext for '/Users/michaelbuch/a.out''
 Created new TypeSystem for (ASTContext*)0x0000000102512a00 'scratch ASTContext'
 Created new TypeSystem for (ASTContext*)0x0000000102116a00 'ClangModulesDeclVendor ASTContext'
 Created new TypeSystem for (ASTContext*)0x00000001022e8c00 'Expression ASTContext for '&lt;user expression 0&gt;''
 Created new TypeSystem for (ASTContext*)0x00000001103e7200 'AppleObjCTypeEncodingParser ASTContext'
 Created new TypeSystem for (ASTContext*)0x00000001103f7000 'AppleObjCDeclVendor AST'
 Created new TypeSystem for (ASTContext*)0x00000001104bfe00 'Expression ASTContext for '&lt;clang expression&gt;''
 Created new TypeSystem for (ASTContext*)0x0000000101f01000 'Expression ASTContext for '&lt;clang expression&gt;''
 Created new TypeSystem for (ASTContext*)0x00000001025d3c00 'Expression ASTContext for '&lt;clang expression&gt;''
 Created new TypeSystem for (ASTContext*)0x0000000110422400 'Expression ASTContext for '&lt;clang expression&gt;''
 Created new TypeSystem for (ASTContext*)0x000000011602c200 'Expression ASTContext for '&lt;user expression 1&gt;''
 Created new TypeSystem for (ASTContext*)0x0000000110641600 'Expression ASTContext for '&lt;clang expression&gt;''
 Created new TypeSystem for (ASTContext*)0x0000000110617400 'Expression ASTContext for '&lt;clang expression&gt;''

Full diff: https://github.com/llvm/llvm-project/pull/91985.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+17-4)
  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h (+3-1)
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;

@Michael137 Michael137 requested a review from adrian-prantl May 13, 2024 16:17
Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Michael137 Michael137 merged commit dc7ce3b into llvm:main May 13, 2024
4 checks passed
@Michael137 Michael137 deleted the tc/log-typesystem-creation branch May 13, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants