|
54 | 54 | #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" |
55 | 55 | #include "Plugins/ExpressionParser/Clang/ClangUtil.h" |
56 | 56 | #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" |
| 57 | +#include "lldb/Core/Debugger.h" |
57 | 58 | #include "lldb/Core/DumpDataExtractor.h" |
58 | 59 | #include "lldb/Core/Module.h" |
59 | 60 | #include "lldb/Core/PluginManager.h" |
@@ -697,10 +698,20 @@ void TypeSystemClang::CreateASTContext() { |
697 | 698 | TargetInfo *target_info = getTargetInfo(); |
698 | 699 | if (target_info) |
699 | 700 | m_ast_up->InitBuiltinTypes(*target_info); |
700 | | - else if (auto *log = GetLog(LLDBLog::Expressions)) |
701 | | - LLDB_LOG(log, |
702 | | - "Failed to initialize builtin ASTContext types for target '{0}'", |
703 | | - m_target_triple); |
| 701 | + else { |
| 702 | + std::string err = |
| 703 | + llvm::formatv( |
| 704 | + "Failed to initialize builtin ASTContext types for target '{0}'. " |
| 705 | + "Printing variables may behave unexpectedly.", |
| 706 | + m_target_triple) |
| 707 | + .str(); |
| 708 | + |
| 709 | + LLDB_LOG(GetLog(LLDBLog::Expressions), err.c_str()); |
| 710 | + |
| 711 | + static std::once_flag s_uninitialized_target_warning; |
| 712 | + Debugger::ReportWarning(std::move(err), /*debugger_id=*/std::nullopt, |
| 713 | + &s_uninitialized_target_warning); |
| 714 | + } |
704 | 715 |
|
705 | 716 | GetASTMap().Insert(m_ast_up.get(), this); |
706 | 717 |
|
@@ -749,6 +760,10 @@ CompilerType |
749 | 760 | TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, |
750 | 761 | size_t bit_size) { |
751 | 762 | ASTContext &ast = getASTContext(); |
| 763 | + |
| 764 | + if (!ast.VoidPtrTy) |
| 765 | + return {}; |
| 766 | + |
752 | 767 | switch (encoding) { |
753 | 768 | case eEncodingInvalid: |
754 | 769 | if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy)) |
@@ -891,6 +906,9 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize( |
891 | 906 | llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) { |
892 | 907 | ASTContext &ast = getASTContext(); |
893 | 908 |
|
| 909 | + if (!ast.VoidPtrTy) |
| 910 | + return {}; |
| 911 | + |
894 | 912 | switch (dw_ate) { |
895 | 913 | default: |
896 | 914 | break; |
@@ -2335,6 +2353,9 @@ CompilerType TypeSystemClang::GetIntTypeFromBitSize(size_t bit_size, |
2335 | 2353 | bool is_signed) { |
2336 | 2354 | clang::ASTContext &ast = getASTContext(); |
2337 | 2355 |
|
| 2356 | + if (!ast.VoidPtrTy) |
| 2357 | + return {}; |
| 2358 | + |
2338 | 2359 | if (is_signed) { |
2339 | 2360 | if (bit_size == ast.getTypeSize(ast.SignedCharTy)) |
2340 | 2361 | return GetType(ast.SignedCharTy); |
@@ -2376,6 +2397,9 @@ CompilerType TypeSystemClang::GetIntTypeFromBitSize(size_t bit_size, |
2376 | 2397 | } |
2377 | 2398 |
|
2378 | 2399 | CompilerType TypeSystemClang::GetPointerSizedIntType(bool is_signed) { |
| 2400 | + if (!getASTContext().VoidPtrTy) |
| 2401 | + return {}; |
| 2402 | + |
2379 | 2403 | return GetIntTypeFromBitSize( |
2380 | 2404 | getASTContext().getTypeSize(getASTContext().VoidPtrTy), is_signed); |
2381 | 2405 | } |
@@ -7453,6 +7477,13 @@ clang::FieldDecl *TypeSystemClang::AddFieldToRecordType( |
7453 | 7477 |
|
7454 | 7478 | clang::Expr *bit_width = nullptr; |
7455 | 7479 | if (bitfield_bit_size != 0) { |
| 7480 | + if (clang_ast.IntTy.isNull()) { |
| 7481 | + LLDB_LOG( |
| 7482 | + GetLog(LLDBLog::Expressions), |
| 7483 | + "{0} failed: builtin ASTContext types have not been initialized"); |
| 7484 | + return nullptr; |
| 7485 | + } |
| 7486 | + |
7456 | 7487 | llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy), |
7457 | 7488 | bitfield_bit_size); |
7458 | 7489 | bit_width = new (clang_ast) |
|
0 commit comments