[Lldb-commits] [lldb] dc7ce3b - [lldb][TypeSystem][NFCI] Log creation of new TypeSystem instances to expression log (#91985)

via lldb-commits lldb-commits at lists.llvm.org
Mon May 13 11:12:54 PDT 2024


Author: Michael Buch
Date: 2024-05-13T19:12:49+01:00
New Revision: dc7ce3b41c936c4cc189b4bbf6a2e3b5475d9fc5

URL: https://github.com/llvm/llvm-project/commit/dc7ce3b41c936c4cc189b4bbf6a2e3b5475d9fc5
DIFF: https://github.com/llvm/llvm-project/commit/dc7ce3b41c936c4cc189b4bbf6a2e3b5475d9fc5.diff

LOG: [lldb][TypeSystem][NFCI] Log creation of new TypeSystem instances to expression log (#91985)

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>''
```

Added: 
    

Modified: 
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index d0033fcd9cdfc..17a9c675fbba4 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
@@ -630,7 +634,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 +9754,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..042379d40bcb3 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,12 @@ 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
   std::string m_target_triple;
   std::unique_ptr<clang::ASTContext> m_ast_up;


        


More information about the lldb-commits mailing list