Skip to content

Commit a1656d5

Browse files
committed
Improve error logging when ast context is in fatal error state.
1 parent 97281bc commit a1656d5

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,6 @@
132132
#include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
133133
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
134134

135-
#define VALID_OR_RETURN(value) \
136-
do { \
137-
if (HasFatalErrors()) { \
138-
return (value); \
139-
} \
140-
} while (0)
141-
#define VALID_OR_RETURN_VOID() \
142-
do { \
143-
if (HasFatalErrors()) { \
144-
return; \
145-
} \
146-
} while (0);
147-
#define VALID_OR_RETURN_CHECK_TYPE(type, value) \
148-
do { \
149-
if (HasFatalErrors() || !type) { \
150-
return (value); \
151-
} \
152-
} while (0)
153-
154135
namespace {
155136
/// This silly constexpr allows us to filter out the useless __FUNCTION__ name
156137
/// of lambdas in the LOG_PRINTF macro.
@@ -190,6 +171,27 @@ std::recursive_mutex g_log_mutex;
190171
LOG_PRINTF(LIBLLDB_LOG_TYPES, FMT, ##__VA_ARGS__); \
191172
LOG_PRINTF_IMPL(lldb_private::GetSwiftHealthLog(), false, FMT, ##__VA_ARGS__)
192173

174+
#define VALID_OR_RETURN(value) \
175+
do { \
176+
if (HasFatalErrors()) { \
177+
LOG_PRINTF(LIBLLDB_LOG_TYPES, \
178+
"SwiftASTContext is in fatal error state, bailing out."); \
179+
return value; \
180+
} \
181+
} while (0)
182+
#define VALID_OR_RETURN_CHECK_TYPE(type, value) \
183+
do { \
184+
if (HasFatalErrors()) { \
185+
LOG_PRINTF(LIBLLDB_LOG_TYPES, \
186+
"SwiftASTContext is in fatal error state, bailing out."); \
187+
return (value); \
188+
} \
189+
if (!type) { \
190+
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Input type is nullptr, bailing out."); \
191+
return (value); \
192+
} \
193+
} while (0)
194+
193195
using namespace lldb;
194196
using namespace lldb_private;
195197

@@ -3608,7 +3610,7 @@ SwiftASTContext::CreateModule(const SourceModule &module, Status &error,
36083610
}
36093611

36103612
void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
3611-
VALID_OR_RETURN_VOID();
3613+
VALID_OR_RETURN();
36123614

36133615
if (!module)
36143616
return;
@@ -3825,7 +3827,7 @@ GetLibrarySearchPaths(const swift::SearchPathOptions &search_path_opts) {
38253827

38263828
void SwiftASTContext::LoadModule(swift::ModuleDecl *swift_module,
38273829
Process &process, Status &error) {
3828-
VALID_OR_RETURN_VOID();
3830+
VALID_OR_RETURN();
38293831
LLDB_SCOPED_TIMER();
38303832

38313833
Status current_error;
@@ -4127,7 +4129,7 @@ bool SwiftASTContext::LoadLibraryUsingPaths(
41274129
}
41284130

41294131
void SwiftASTContext::LoadExtraDylibs(Process &process, Status &error) {
4130-
VALID_OR_RETURN_VOID();
4132+
VALID_OR_RETURN();
41314133

41324134
error.Clear();
41334135
swift::IRGenOptions &irgen_options = GetIRGenOptions();
@@ -4161,7 +4163,7 @@ static std::string GetBriefModuleName(Module &module) {
41614163

41624164
void SwiftASTContext::RegisterSectionModules(
41634165
Module &module, std::vector<std::string> &module_names) {
4164-
VALID_OR_RETURN_VOID();
4166+
VALID_OR_RETURN();
41654167
LLDB_SCOPED_TIMER();
41664168

41674169
swift::MemoryBufferSerializedModuleLoader *loader =
@@ -4235,7 +4237,7 @@ void SwiftASTContext::RegisterSectionModules(
42354237

42364238
void SwiftASTContext::ValidateSectionModules(
42374239
Module &module, const std::vector<std::string> &module_names) {
4238-
VALID_OR_RETURN_VOID();
4240+
VALID_OR_RETURN();
42394241
LLDB_SCOPED_TIMER();
42404242

42414243
Status error;
@@ -4280,14 +4282,14 @@ ConstString SwiftASTContext::GetMangledTypeName(swift::TypeBase *type_base) {
42804282

42814283
void SwiftASTContext::CacheDemangledType(ConstString name,
42824284
swift::TypeBase *found_type) {
4283-
VALID_OR_RETURN_VOID();
4285+
VALID_OR_RETURN();
42844286

42854287
m_type_to_mangled_name_map.insert({found_type, name.AsCString()});
42864288
m_mangled_name_to_type_map.insert({name.AsCString(), found_type});
42874289
}
42884290

42894291
void SwiftASTContext::CacheDemangledTypeFailure(ConstString name) {
4290-
VALID_OR_RETURN_VOID();
4292+
VALID_OR_RETURN();
42914293

42924294
m_negative_type_cache.Insert(name.AsCString());
42934295
}
@@ -5024,7 +5026,7 @@ void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
50245026
// fatal error field, and then put it to the stream, otherwise just
50255027
// dump the diagnostics to the stream.
50265028

5027-
// N.B. you cannot use VALID_OR_RETURN_VOID here since that exits if
5029+
// N.B. you cannot use VALID_OR_RETURN here since that exits if
50285030
// you have fatal errors, which are what we are trying to print
50295031
// here.
50305032
if (!m_ast_context_ap.get()) {
@@ -5096,7 +5098,10 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
50965098
// We cannot reconfigure ClangImporter after its creation.
50975099
// Instead poison the SwiftASTContext so it gets recreated.
50985100
m_fatal_errors.SetErrorStringWithFormat(
5099-
"New Swift image added: %s",
5101+
"New Swift image added: %s. ClangImporter needs to be reinitialized.",
5102+
module_sp->GetFileSpec().GetPath().c_str());
5103+
HEALTH_LOG_PRINTF(
5104+
"New Swift image added: %s. ClangImporter needs to be reinitialized.",
51005105
module_sp->GetFileSpec().GetPath().c_str());
51015106
}
51025107

0 commit comments

Comments
 (0)