Skip to content

Commit dc7ce3b

Browse files
authored
[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>'' ```
1 parent 66466ff commit dc7ce3b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
501501
// The caller didn't pass an ASTContext so create a new one for this
502502
// TypeSystemClang.
503503
CreateASTContext();
504+
505+
LogCreation();
504506
}
505507

506508
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
@@ -510,6 +512,8 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
510512

511513
m_ast_up.reset(&existing_ctxt);
512514
GetASTMap().Insert(&existing_ctxt, this);
515+
516+
LogCreation();
513517
}
514518

515519
// Destructor
@@ -630,7 +634,7 @@ void TypeSystemClang::SetExternalSource(
630634
ast.setExternalSource(ast_source_up);
631635
}
632636

633-
ASTContext &TypeSystemClang::getASTContext() {
637+
ASTContext &TypeSystemClang::getASTContext() const {
634638
assert(m_ast_up);
635639
return *m_ast_up;
636640
}
@@ -9750,3 +9754,9 @@ bool TypeSystemClang::SetDeclIsForcefullyCompleted(const clang::TagDecl *td) {
97509754
metadata->SetIsForcefullyCompleted();
97519755
return true;
97529756
}
9757+
9758+
void TypeSystemClang::LogCreation() const {
9759+
if (auto *log = GetLog(LLDBLog::Expressions))
9760+
LLDB_LOG(log, "Created new TypeSystem for (ASTContext*){0:x} '{1}'",
9761+
&getASTContext(), getDisplayName());
9762+
}

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class TypeSystemClang : public TypeSystem {
162162
llvm::StringRef getDisplayName() const { return m_display_name; }
163163

164164
/// Returns the clang::ASTContext instance managed by this TypeSystemClang.
165-
clang::ASTContext &getASTContext();
165+
clang::ASTContext &getASTContext() const;
166166

167167
clang::MangleContext *getMangleContext();
168168

@@ -1166,6 +1166,12 @@ class TypeSystemClang : public TypeSystem {
11661166
bool IsTypeImpl(lldb::opaque_compiler_type_t type,
11671167
llvm::function_ref<bool(clang::QualType)> predicate) const;
11681168

1169+
/// Emits information about this TypeSystem into the expression log.
1170+
///
1171+
/// Helper method that is used in \ref TypeSystemClang::TypeSystemClang
1172+
/// on creation of a new instance.
1173+
void LogCreation() const;
1174+
11691175
// Classes that inherit from TypeSystemClang can see and modify these
11701176
std::string m_target_triple;
11711177
std::unique_ptr<clang::ASTContext> m_ast_up;

0 commit comments

Comments
 (0)