Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp =================================================================== --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -1151,20 +1151,12 @@ } break; } - // This assert should fire for anything that we don't catch above so we know - // to fix any issues we run into. - if (!type_name.empty()) { - std::string type_name_str = type_name.str(); - Host::SystemLog(Host::eSystemLogError, - "error: need to add support for DW_TAG_base_type '%s' " - "encoded with DW_ATE = 0x%x, bit_size = %u\n", - type_name_str.c_str(), dw_ate, bit_size); - } else { - Host::SystemLog(Host::eSystemLogError, "error: need to add support for " - "DW_TAG_base_type encoded with " - "DW_ATE = 0x%x, bit_size = %u\n", - dw_ate, bit_size); - } + + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES); + LLDB_LOG(log, + "error: need to add support for DW_TAG_base_type '{0}' " + "encoded with DW_ATE = {1:x}, bit_size = {2}\n", + type_name, dw_ate, bit_size); return CompilerType(); } Index: lldb/unittests/Symbol/TestTypeSystemClang.cpp =================================================================== --- lldb/unittests/Symbol/TestTypeSystemClang.cpp +++ lldb/unittests/Symbol/TestTypeSystemClang.cpp @@ -13,6 +13,7 @@ #include "lldb/Core/Declaration.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Utility/Log.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" @@ -46,6 +47,39 @@ } }; +TEST_F(TestTypeSystemClang, FailedGetBuiltinTypeForDWARFEncodingAndBitSize) { + // Tests GetBuiltinTypeForDWARFEncodingAndBitSize for unknown types. + const int unknown_dwarf_ate_value = 123456; + const int size = 123; + EXPECT_EQ(m_ast->GetBuiltinTypeForDWARFEncodingAndBitSize( + "random_type", unknown_dwarf_ate_value, size), + CompilerType()); +} + +TEST_F(TestTypeSystemClang, LogFailedGetBuiltinTypeForDWARFEncodingAndBitSize) { + // Tests that invalid calls to GetBuiltinTypeForDWARFEncodingAndBitSize end up + // in the LLDB log. + std::string log_output; + auto log_stream = std::make_shared(log_output); + + std::string error; + llvm::raw_string_ostream error_stream(error); + + Log::Initialize(); + ASSERT_TRUE(Log::EnableLogChannel(log_stream, /*log_options=*/0, "lldb", + "types", error_stream)); + + const int unknown_dwarf_ate_value = 123456; + const int size = 123; + EXPECT_EQ(m_ast->GetBuiltinTypeForDWARFEncodingAndBitSize( + "random_type", unknown_dwarf_ate_value, size), + CompilerType()); + std::string needle = + "error: need to add support for DW_TAG_base_type 'random_type' encoded " + "with DW_ATE = 0x1e240, bit_size = 123\n\n"; + ASSERT_EQ(log_output, needle); +} + TEST_F(TestTypeSystemClang, TestGetBasicTypeFromEnum) { clang::ASTContext &context = m_ast->getASTContext();