https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/110481
>From 0669f9fbeddaf81edfca7e81f4883a1b95a780f6 Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Mon, 30 Sep 2024 10:53:47 +0100 Subject: [PATCH 1/3] [lldb][TypeSystemClang] Add warning and defensive checks when ASTContext is not fully initialized --- .../TypeSystem/Clang/TypeSystemClang.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index b0f49ebf2d2cbb..2f423269fecd2d 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -54,6 +54,7 @@ #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" #include "Plugins/ExpressionParser/Clang/ClangUtil.h" #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" +#include "lldb/Core/Debugger.h" #include "lldb/Core/DumpDataExtractor.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -697,10 +698,19 @@ void TypeSystemClang::CreateASTContext() { TargetInfo *target_info = getTargetInfo(); if (target_info) m_ast_up->InitBuiltinTypes(*target_info); - else if (auto *log = GetLog(LLDBLog::Expressions)) - LLDB_LOG(log, - "Failed to initialize builtin ASTContext types for target '{0}'", - m_target_triple); + else { + std::string err = + llvm::formatv( + "Failed to initialize builtin ASTContext types for target '{0}'. " + "Printing variables may behave unexpectedly.", + m_target_triple) + .str(); + + LLDB_LOG(GetLog(LLDBLog::Expressions), err.c_str()); + + static std::once_flag s_uninitialized_target_warning; + Debugger::ReportWarning(std::move(err), /*debugger_id=*/std::nullopt, &s_uninitialized_target_warning); + } GetASTMap().Insert(m_ast_up.get(), this); @@ -749,6 +759,11 @@ CompilerType TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, size_t bit_size) { ASTContext &ast = getASTContext(); + if (!ast.VoidPtrTy) { + LLDB_LOG(GetLog(LLDBLog::Expressions), "{0} failed: builtin types on ASTContext were not initialized properly.", __func__); + return {}; + } + switch (encoding) { case eEncodingInvalid: if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy)) @@ -891,6 +906,11 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize( llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) { ASTContext &ast = getASTContext(); + if (!ast.VoidPtrTy) { + LLDB_LOG(GetLog(LLDBLog::Expressions), "{0} failed: builtin types on ASTContext were not initialized properly.", __func__); + return {}; + } + switch (dw_ate) { default: break; >From 46c4015cd76709bae4b9e38eff312ad58225b62a Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Mon, 30 Sep 2024 11:16:06 +0100 Subject: [PATCH 2/3] fixup! format --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 2f423269fecd2d..9ba5d0a79445e8 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -759,6 +759,7 @@ CompilerType TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, size_t bit_size) { ASTContext &ast = getASTContext(); + if (!ast.VoidPtrTy) { LLDB_LOG(GetLog(LLDBLog::Expressions), "{0} failed: builtin types on ASTContext were not initialized properly.", __func__); return {}; >From caed9b07141176ab202d8c95bf0ffa4f59dce1d3 Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Mon, 30 Sep 2024 11:16:31 +0100 Subject: [PATCH 3/3] fixup! clang-format --- .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 9ba5d0a79445e8..02d6675ddc811e 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -709,7 +709,8 @@ void TypeSystemClang::CreateASTContext() { LLDB_LOG(GetLog(LLDBLog::Expressions), err.c_str()); static std::once_flag s_uninitialized_target_warning; - Debugger::ReportWarning(std::move(err), /*debugger_id=*/std::nullopt, &s_uninitialized_target_warning); + Debugger::ReportWarning(std::move(err), /*debugger_id=*/std::nullopt, + &s_uninitialized_target_warning); } GetASTMap().Insert(m_ast_up.get(), this); @@ -761,7 +762,10 @@ TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, ASTContext &ast = getASTContext(); if (!ast.VoidPtrTy) { - LLDB_LOG(GetLog(LLDBLog::Expressions), "{0} failed: builtin types on ASTContext were not initialized properly.", __func__); + LLDB_LOG(GetLog(LLDBLog::Expressions), + "{0} failed: builtin types on ASTContext were not initialized " + "properly.", + __func__); return {}; } @@ -908,7 +912,10 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize( ASTContext &ast = getASTContext(); if (!ast.VoidPtrTy) { - LLDB_LOG(GetLog(LLDBLog::Expressions), "{0} failed: builtin types on ASTContext were not initialized properly.", __func__); + LLDB_LOG(GetLog(LLDBLog::Expressions), + "{0} failed: builtin types on ASTContext were not initialized " + "properly.", + __func__); return {}; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits