|
56 | 56 | #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" |
57 | 57 | #include "Plugins/ExpressionParser/Clang/ClangUtil.h" |
58 | 58 | #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" |
| 59 | +#include "lldb/Core/Debugger.h" |
59 | 60 | #include "lldb/Core/DumpDataExtractor.h" |
60 | 61 | #include "lldb/Core/Module.h" |
61 | 62 | #include "lldb/Core/PluginManager.h" |
@@ -748,10 +749,20 @@ void TypeSystemClang::CreateASTContext() { |
748 | 749 | TargetInfo *target_info = getTargetInfo(); |
749 | 750 | if (target_info) |
750 | 751 | m_ast_up->InitBuiltinTypes(*target_info); |
751 | | - else if (auto *log = GetLog(LLDBLog::Expressions)) |
752 | | - LLDB_LOG(log, |
753 | | - "Failed to initialize builtin ASTContext types for target '{0}'", |
754 | | - m_target_triple); |
| 752 | + else { |
| 753 | + std::string err = |
| 754 | + llvm::formatv( |
| 755 | + "Failed to initialize builtin ASTContext types for target '{0}'. " |
| 756 | + "Printing variables may behave unexpectedly.", |
| 757 | + m_target_triple) |
| 758 | + .str(); |
| 759 | + |
| 760 | + LLDB_LOG(GetLog(LLDBLog::Expressions), err.c_str()); |
| 761 | + |
| 762 | + static std::once_flag s_uninitialized_target_warning; |
| 763 | + Debugger::ReportWarning(std::move(err), /*debugger_id=*/std::nullopt, |
| 764 | + &s_uninitialized_target_warning); |
| 765 | + } |
755 | 766 |
|
756 | 767 | GetASTMap().Insert(m_ast_up.get(), this); |
757 | 768 |
|
@@ -801,6 +812,10 @@ CompilerType |
801 | 812 | TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, |
802 | 813 | size_t bit_size) { |
803 | 814 | ASTContext &ast = getASTContext(); |
| 815 | + |
| 816 | + if (!ast.VoidPtrTy) |
| 817 | + return {}; |
| 818 | + |
804 | 819 | switch (encoding) { |
805 | 820 | case eEncodingInvalid: |
806 | 821 | if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy)) |
@@ -943,6 +958,9 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize( |
943 | 958 | llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) { |
944 | 959 | ASTContext &ast = getASTContext(); |
945 | 960 |
|
| 961 | + if (!ast.VoidPtrTy) |
| 962 | + return {}; |
| 963 | + |
946 | 964 | switch (dw_ate) { |
947 | 965 | default: |
948 | 966 | break; |
@@ -2421,6 +2439,9 @@ CompilerType TypeSystemClang::GetIntTypeFromBitSize(size_t bit_size, |
2421 | 2439 | bool is_signed) { |
2422 | 2440 | clang::ASTContext &ast = getASTContext(); |
2423 | 2441 |
|
| 2442 | + if (!ast.VoidPtrTy) |
| 2443 | + return {}; |
| 2444 | + |
2424 | 2445 | if (is_signed) { |
2425 | 2446 | if (bit_size == ast.getTypeSize(ast.SignedCharTy)) |
2426 | 2447 | return GetType(ast.SignedCharTy); |
@@ -2462,6 +2483,9 @@ CompilerType TypeSystemClang::GetIntTypeFromBitSize(size_t bit_size, |
2462 | 2483 | } |
2463 | 2484 |
|
2464 | 2485 | CompilerType TypeSystemClang::GetPointerSizedIntType(bool is_signed) { |
| 2486 | + if (!getASTContext().VoidPtrTy) |
| 2487 | + return {}; |
| 2488 | + |
2465 | 2489 | return GetIntTypeFromBitSize( |
2466 | 2490 | getASTContext().getTypeSize(getASTContext().VoidPtrTy), is_signed); |
2467 | 2491 | } |
@@ -7575,6 +7599,13 @@ clang::FieldDecl *TypeSystemClang::AddFieldToRecordType( |
7575 | 7599 |
|
7576 | 7600 | clang::Expr *bit_width = nullptr; |
7577 | 7601 | if (bitfield_bit_size != 0) { |
| 7602 | + if (clang_ast.IntTy.isNull()) { |
| 7603 | + LLDB_LOG( |
| 7604 | + GetLog(LLDBLog::Expressions), |
| 7605 | + "{0} failed: builtin ASTContext types have not been initialized"); |
| 7606 | + return nullptr; |
| 7607 | + } |
| 7608 | + |
7578 | 7609 | llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy), |
7579 | 7610 | bitfield_bit_size); |
7580 | 7611 | bit_width = new (clang_ast) |
|
0 commit comments