Skip to content

Commit b6c291f

Browse files
authored
Merge pull request swiftlang#8691 from apple/jdevlieghere/swift-healthcheck-console
2 parents 3580278 + d79dd0d commit b6c291f

30 files changed

+287
-230
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
639639
std::optional<lldb::user_id_t> debugger_id,
640640
uint32_t progress_category_bit = eBroadcastBitProgress);
641641

642-
static void ReportDiagnosticImpl(DiagnosticEventData::Type type,
643-
std::string message,
642+
static void ReportDiagnosticImpl(lldb::Severity severity, std::string message,
644643
std::optional<lldb::user_id_t> debugger_id,
645644
std::once_flag *once);
646645

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,15 @@ class ProgressEventData : public EventData {
7676

7777
class DiagnosticEventData : public EventData {
7878
public:
79-
enum class Type {
80-
Info,
81-
Warning,
82-
Error,
83-
};
84-
DiagnosticEventData(Type type, std::string message, bool debugger_specific)
85-
: m_message(std::move(message)), m_type(type),
79+
DiagnosticEventData(lldb::Severity severity, std::string message,
80+
bool debugger_specific)
81+
: m_message(std::move(message)), m_severity(severity),
8682
m_debugger_specific(debugger_specific) {}
8783
~DiagnosticEventData() override = default;
8884

8985
const std::string &GetMessage() const { return m_message; }
9086
bool IsDebuggerSpecific() const { return m_debugger_specific; }
91-
Type GetType() const { return m_type; }
87+
lldb::Severity GetSeverity() const { return m_severity; }
9288

9389
llvm::StringRef GetPrefix() const;
9490

@@ -105,7 +101,7 @@ class DiagnosticEventData : public EventData {
105101

106102
protected:
107103
std::string m_message;
108-
Type m_type;
104+
lldb::Severity m_severity;
109105
const bool m_debugger_specific;
110106

111107
DiagnosticEventData(const DiagnosticEventData &) = delete;

lldb/include/lldb/Expression/DiagnosticManager.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ enum DiagnosticOrigin {
2828
eDiagnosticOriginLLVM
2929
};
3030

31-
enum DiagnosticSeverity {
32-
eDiagnosticSeverityError,
33-
eDiagnosticSeverityWarning,
34-
eDiagnosticSeverityRemark
35-
};
36-
3731
const uint32_t LLDB_INVALID_COMPILER_ID = UINT32_MAX;
3832

3933
class Diagnostic {
@@ -55,7 +49,7 @@ class Diagnostic {
5549
}
5650
}
5751

58-
Diagnostic(llvm::StringRef message, DiagnosticSeverity severity,
52+
Diagnostic(llvm::StringRef message, lldb::Severity severity,
5953
DiagnosticOrigin origin, uint32_t compiler_id)
6054
: m_message(message), m_severity(severity), m_origin(origin),
6155
m_compiler_id(compiler_id) {}
@@ -68,7 +62,7 @@ class Diagnostic {
6862

6963
virtual bool HasFixIts() const { return false; }
7064

71-
DiagnosticSeverity GetSeverity() const { return m_severity; }
65+
lldb::Severity GetSeverity() const { return m_severity; }
7266

7367
uint32_t GetCompilerID() const { return m_compiler_id; }
7468

@@ -83,7 +77,7 @@ class Diagnostic {
8377

8478
protected:
8579
std::string m_message;
86-
DiagnosticSeverity m_severity;
80+
lldb::Severity m_severity;
8781
DiagnosticOrigin m_origin;
8882
uint32_t m_compiler_id; // Compiler-specific diagnostic ID
8983
};
@@ -106,7 +100,7 @@ class DiagnosticManager {
106100
});
107101
}
108102

109-
void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity,
103+
void AddDiagnostic(llvm::StringRef message, lldb::Severity severity,
110104
DiagnosticOrigin origin,
111105
uint32_t compiler_id = LLDB_INVALID_COMPILER_ID) {
112106
m_diagnostics.emplace_back(
@@ -127,9 +121,9 @@ class DiagnosticManager {
127121
other.Clear();
128122
}
129123

130-
size_t Printf(DiagnosticSeverity severity, const char *format, ...)
124+
size_t Printf(lldb::Severity severity, const char *format, ...)
131125
__attribute__((format(printf, 3, 4)));
132-
void PutString(DiagnosticSeverity severity, llvm::StringRef str);
126+
void PutString(lldb::Severity severity, llvm::StringRef str);
133127

134128
void AppendMessageToDiagnostic(llvm::StringRef str) {
135129
if (!m_diagnostics.empty())

lldb/include/lldb/Host/Host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Host {
8888
lldb::pid_t pid);
8989

9090
/// Emit the given message to the operating system log.
91-
static void SystemLog(llvm::StringRef message);
91+
static void SystemLog(lldb::Severity severity, llvm::StringRef message);
9292

9393
/// Get the process ID for the calling process.
9494
///

lldb/include/lldb/Utility/Log.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ class RotatingLogHandler : public LogHandler {
112112
static char ID;
113113
};
114114

115+
/// A T-style log handler that multiplexes messages to two log handlers.
116+
class TeeLogHandler : public LogHandler {
117+
public:
118+
TeeLogHandler(std::shared_ptr<LogHandler> first_log_handler,
119+
std::shared_ptr<LogHandler> second_log_handler);
120+
121+
void Emit(llvm::StringRef message) override;
122+
123+
bool isA(const void *ClassID) const override { return ClassID == &ID; }
124+
static bool classof(const LogHandler *obj) { return obj->isA(&ID); }
125+
126+
private:
127+
std::shared_ptr<LogHandler> m_first_log_handler;
128+
std::shared_ptr<LogHandler> m_second_log_handler;
129+
static char ID;
130+
};
131+
115132
class Log final {
116133
public:
117134
/// The underlying type of all log channel enums. Declare them as:

lldb/include/lldb/lldb-enumerations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,13 @@ enum DebuggerBroadcastBit {
13711371
eBroadcastBitProgressCategory = (1 << 3),
13721372
};
13731373

1374+
/// Used for expressing severity in logs and diagnostics.
1375+
enum Severity {
1376+
eSeverityError,
1377+
eSeverityWarning,
1378+
eSeverityInfo, // Equivalent to Remark used in clang.
1379+
};
1380+
13741381
} // namespace lldb
13751382

13761383
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Core/Debugger.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,19 +1512,18 @@ void Debugger::ReportProgress(uint64_t progress_id, std::string title,
15121512
}
15131513
}
15141514

1515-
static void PrivateReportDiagnostic(Debugger &debugger,
1516-
DiagnosticEventData::Type type,
1515+
static void PrivateReportDiagnostic(Debugger &debugger, Severity severity,
15171516
std::string message,
15181517
bool debugger_specific) {
15191518
uint32_t event_type = 0;
1520-
switch (type) {
1521-
case DiagnosticEventData::Type::Info:
1522-
assert(false && "DiagnosticEventData::Type::Info should not be broadcast");
1519+
switch (severity) {
1520+
case eSeverityInfo:
1521+
assert(false && "eSeverityInfo should not be broadcast");
15231522
return;
1524-
case DiagnosticEventData::Type::Warning:
1523+
case eSeverityWarning:
15251524
event_type = Debugger::eBroadcastBitWarning;
15261525
break;
1527-
case DiagnosticEventData::Type::Error:
1526+
case eSeverityError:
15281527
event_type = Debugger::eBroadcastBitError;
15291528
break;
15301529
}
@@ -1533,29 +1532,32 @@ static void PrivateReportDiagnostic(Debugger &debugger,
15331532
if (!broadcaster.EventTypeHasListeners(event_type)) {
15341533
// Diagnostics are too important to drop. If nobody is listening, print the
15351534
// diagnostic directly to the debugger's error stream.
1536-
DiagnosticEventData event_data(type, std::move(message), debugger_specific);
1535+
DiagnosticEventData event_data(severity, std::move(message),
1536+
debugger_specific);
15371537
StreamSP stream = debugger.GetAsyncErrorStream();
15381538
event_data.Dump(stream.get());
15391539
return;
15401540
}
15411541
EventSP event_sp = std::make_shared<Event>(
15421542
event_type,
1543-
new DiagnosticEventData(type, std::move(message), debugger_specific));
1543+
new DiagnosticEventData(severity, std::move(message), debugger_specific));
15441544
broadcaster.BroadcastEvent(event_sp);
15451545
}
15461546

1547-
void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
1548-
std::string message,
1547+
void Debugger::ReportDiagnosticImpl(Severity severity, std::string message,
15491548
std::optional<lldb::user_id_t> debugger_id,
15501549
std::once_flag *once) {
15511550
auto ReportDiagnosticLambda = [&]() {
1551+
// Always log diagnostics to the system log.
1552+
Host::SystemLog(severity, message);
1553+
15521554
// The diagnostic subsystem is optional but we still want to broadcast
15531555
// events when it's disabled.
15541556
if (Diagnostics::Enabled())
15551557
Diagnostics::Instance().Report(message);
15561558

15571559
// We don't broadcast info events.
1558-
if (type == DiagnosticEventData::Type::Info)
1560+
if (severity == lldb::eSeverityInfo)
15591561
return;
15601562

15611563
// Check if this diagnostic is for a specific debugger.
@@ -1564,15 +1566,16 @@ void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
15641566
// still exists.
15651567
DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
15661568
if (debugger_sp)
1567-
PrivateReportDiagnostic(*debugger_sp, type, std::move(message), true);
1569+
PrivateReportDiagnostic(*debugger_sp, severity, std::move(message),
1570+
true);
15681571
return;
15691572
}
15701573
// The diagnostic event is not debugger specific, iterate over all debuggers
15711574
// and deliver a diagnostic event to each one.
15721575
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
15731576
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
15741577
for (const auto &debugger : *g_debugger_list_ptr)
1575-
PrivateReportDiagnostic(*debugger, type, message, false);
1578+
PrivateReportDiagnostic(*debugger, severity, message, false);
15761579
}
15771580
};
15781581

@@ -1585,22 +1588,19 @@ void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
15851588
void Debugger::ReportWarning(std::string message,
15861589
std::optional<lldb::user_id_t> debugger_id,
15871590
std::once_flag *once) {
1588-
ReportDiagnosticImpl(DiagnosticEventData::Type::Warning, std::move(message),
1589-
debugger_id, once);
1591+
ReportDiagnosticImpl(eSeverityWarning, std::move(message), debugger_id, once);
15901592
}
15911593

15921594
void Debugger::ReportError(std::string message,
15931595
std::optional<lldb::user_id_t> debugger_id,
15941596
std::once_flag *once) {
1595-
ReportDiagnosticImpl(DiagnosticEventData::Type::Error, std::move(message),
1596-
debugger_id, once);
1597+
ReportDiagnosticImpl(eSeverityError, std::move(message), debugger_id, once);
15971598
}
15981599

15991600
void Debugger::ReportInfo(std::string message,
16001601
std::optional<lldb::user_id_t> debugger_id,
16011602
std::once_flag *once) {
1602-
ReportDiagnosticImpl(DiagnosticEventData::Type::Info, std::move(message),
1603-
debugger_id, once);
1603+
ReportDiagnosticImpl(eSeverityInfo, std::move(message), debugger_id, once);
16041604
}
16051605

16061606
void Debugger::ReportSymbolChange(const ModuleSpec &module_spec) {

lldb/source/Core/DebuggerEvents.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ ProgressEventData::GetAsStructuredData(const Event *event_ptr) {
7373
}
7474

7575
llvm::StringRef DiagnosticEventData::GetPrefix() const {
76-
switch (m_type) {
77-
case Type::Info:
76+
switch (m_severity) {
77+
case Severity::eSeverityInfo:
7878
return "info";
79-
case Type::Warning:
79+
case Severity::eSeverityWarning:
8080
return "warning";
81-
case Type::Error:
81+
case Severity::eSeverityError:
8282
return "error";
8383
}
8484
llvm_unreachable("Fully covered switch above!");
8585
}
8686

8787
void DiagnosticEventData::Dump(Stream *s) const {
88-
llvm::HighlightColor color = m_type == Type::Warning
88+
llvm::HighlightColor color = m_severity == lldb::eSeverityWarning
8989
? llvm::HighlightColor::Warning
9090
: llvm::HighlightColor::Error;
9191
llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)

lldb/source/Expression/DiagnosticManager.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ void DiagnosticManager::Dump(Log *log) {
3131
log->PutCString(str.c_str());
3232
}
3333

34-
static const char *StringForSeverity(DiagnosticSeverity severity) {
34+
static const char *StringForSeverity(lldb::Severity severity) {
3535
switch (severity) {
3636
// this should be exhaustive
37-
case lldb_private::eDiagnosticSeverityError:
37+
case lldb::eSeverityError:
3838
return "error: ";
39-
case lldb_private::eDiagnosticSeverityWarning:
39+
case lldb::eSeverityWarning:
4040
return "warning: ";
41-
case lldb_private::eDiagnosticSeverityRemark:
41+
case lldb::eSeverityInfo:
4242
return "";
4343
}
44-
llvm_unreachable("switch needs another case for DiagnosticSeverity enum");
44+
llvm_unreachable("switch needs another case for lldb::Severity enum");
4545
}
4646

4747
std::string DiagnosticManager::GetString(char separator) {
@@ -65,8 +65,8 @@ std::string DiagnosticManager::GetString(char separator) {
6565
return ret;
6666
}
6767

68-
size_t DiagnosticManager::Printf(DiagnosticSeverity severity,
69-
const char *format, ...) {
68+
size_t DiagnosticManager::Printf(lldb::Severity severity, const char *format,
69+
...) {
7070
StreamString ss;
7171

7272
va_list args;
@@ -79,7 +79,7 @@ size_t DiagnosticManager::Printf(DiagnosticSeverity severity,
7979
return result;
8080
}
8181

82-
void DiagnosticManager::PutString(DiagnosticSeverity severity,
82+
void DiagnosticManager::PutString(lldb::Severity severity,
8383
llvm::StringRef str) {
8484
if (str.empty())
8585
return;

0 commit comments

Comments
 (0)