Skip to content

Commit 528f5ba

Browse files
authored
[lldb] Create a single Severity enum in lldb-enumerations (llvm#90917)
We have 3 different enums all expressing severity (info, warning, error). Remove all uses with a new Severity enum in lldb-enumerations.h.
1 parent 8d946c7 commit 528f5ba

20 files changed

+164
-203
lines changed

lldb/include/lldb/Core/Debugger.h

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

633-
static void ReportDiagnosticImpl(DiagnosticEventData::Type type,
634-
std::string message,
633+
static void ReportDiagnosticImpl(lldb::Severity severity, std::string message,
635634
std::optional<lldb::user_id_t> debugger_id,
636635
std::once_flag *once);
637636

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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,8 @@ class Host {
8787
StartMonitoringChildProcess(const MonitorChildProcessCallback &callback,
8888
lldb::pid_t pid);
8989

90-
/// System log level.
91-
enum SystemLogLevel {
92-
eSystemLogInfo,
93-
eSystemLogWarning,
94-
eSystemLogError,
95-
};
96-
9790
/// Emit the given message to the operating system log.
98-
static void SystemLog(SystemLogLevel log_level, llvm::StringRef message);
91+
static void SystemLog(lldb::Severity severity, llvm::StringRef message);
9992

10093
/// Get the process ID for the calling process.
10194
///

lldb/include/lldb/lldb-enumerations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,13 @@ enum DebuggerBroadcastBit {
13471347
eBroadcastBitProgressCategory = (1 << 3),
13481348
};
13491349

1350+
/// Used for expressing severity in logs and diagnostics.
1351+
enum Severity {
1352+
eSeverityError,
1353+
eSeverityWarning,
1354+
eSeverityInfo, // Equivalent to Remark used in clang.
1355+
};
1356+
13501357
} // namespace lldb
13511358

13521359
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Core/Debugger.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,19 +1476,18 @@ void Debugger::ReportProgress(uint64_t progress_id, std::string title,
14761476
}
14771477
}
14781478

1479-
static void PrivateReportDiagnostic(Debugger &debugger,
1480-
DiagnosticEventData::Type type,
1479+
static void PrivateReportDiagnostic(Debugger &debugger, Severity severity,
14811480
std::string message,
14821481
bool debugger_specific) {
14831482
uint32_t event_type = 0;
1484-
switch (type) {
1485-
case DiagnosticEventData::Type::Info:
1486-
assert(false && "DiagnosticEventData::Type::Info should not be broadcast");
1483+
switch (severity) {
1484+
case eSeverityInfo:
1485+
assert(false && "eSeverityInfo should not be broadcast");
14871486
return;
1488-
case DiagnosticEventData::Type::Warning:
1487+
case eSeverityWarning:
14891488
event_type = Debugger::eBroadcastBitWarning;
14901489
break;
1491-
case DiagnosticEventData::Type::Error:
1490+
case eSeverityError:
14921491
event_type = Debugger::eBroadcastBitError;
14931492
break;
14941493
}
@@ -1497,19 +1496,19 @@ static void PrivateReportDiagnostic(Debugger &debugger,
14971496
if (!broadcaster.EventTypeHasListeners(event_type)) {
14981497
// Diagnostics are too important to drop. If nobody is listening, print the
14991498
// diagnostic directly to the debugger's error stream.
1500-
DiagnosticEventData event_data(type, std::move(message), debugger_specific);
1499+
DiagnosticEventData event_data(severity, std::move(message),
1500+
debugger_specific);
15011501
StreamSP stream = debugger.GetAsyncErrorStream();
15021502
event_data.Dump(stream.get());
15031503
return;
15041504
}
15051505
EventSP event_sp = std::make_shared<Event>(
15061506
event_type,
1507-
new DiagnosticEventData(type, std::move(message), debugger_specific));
1507+
new DiagnosticEventData(severity, std::move(message), debugger_specific));
15081508
broadcaster.BroadcastEvent(event_sp);
15091509
}
15101510

1511-
void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
1512-
std::string message,
1511+
void Debugger::ReportDiagnosticImpl(Severity severity, std::string message,
15131512
std::optional<lldb::user_id_t> debugger_id,
15141513
std::once_flag *once) {
15151514
auto ReportDiagnosticLambda = [&]() {
@@ -1519,7 +1518,7 @@ void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
15191518
Diagnostics::Instance().Report(message);
15201519

15211520
// We don't broadcast info events.
1522-
if (type == DiagnosticEventData::Type::Info)
1521+
if (severity == lldb::eSeverityInfo)
15231522
return;
15241523

15251524
// Check if this diagnostic is for a specific debugger.
@@ -1528,15 +1527,16 @@ void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
15281527
// still exists.
15291528
DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
15301529
if (debugger_sp)
1531-
PrivateReportDiagnostic(*debugger_sp, type, std::move(message), true);
1530+
PrivateReportDiagnostic(*debugger_sp, severity, std::move(message),
1531+
true);
15321532
return;
15331533
}
15341534
// The diagnostic event is not debugger specific, iterate over all debuggers
15351535
// and deliver a diagnostic event to each one.
15361536
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
15371537
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
15381538
for (const auto &debugger : *g_debugger_list_ptr)
1539-
PrivateReportDiagnostic(*debugger, type, message, false);
1539+
PrivateReportDiagnostic(*debugger, severity, message, false);
15401540
}
15411541
};
15421542

@@ -1549,22 +1549,19 @@ void Debugger::ReportDiagnosticImpl(DiagnosticEventData::Type type,
15491549
void Debugger::ReportWarning(std::string message,
15501550
std::optional<lldb::user_id_t> debugger_id,
15511551
std::once_flag *once) {
1552-
ReportDiagnosticImpl(DiagnosticEventData::Type::Warning, std::move(message),
1553-
debugger_id, once);
1552+
ReportDiagnosticImpl(eSeverityWarning, std::move(message), debugger_id, once);
15541553
}
15551554

15561555
void Debugger::ReportError(std::string message,
15571556
std::optional<lldb::user_id_t> debugger_id,
15581557
std::once_flag *once) {
1559-
ReportDiagnosticImpl(DiagnosticEventData::Type::Error, std::move(message),
1560-
debugger_id, once);
1558+
ReportDiagnosticImpl(eSeverityError, std::move(message), debugger_id, once);
15611559
}
15621560

15631561
void Debugger::ReportInfo(std::string message,
15641562
std::optional<lldb::user_id_t> debugger_id,
15651563
std::once_flag *once) {
1566-
ReportDiagnosticImpl(DiagnosticEventData::Type::Info, std::move(message),
1567-
debugger_id, once);
1564+
ReportDiagnosticImpl(eSeverityInfo, std::move(message), debugger_id, once);
15681565
}
15691566

15701567
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;

lldb/source/Expression/FunctionCaller.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,25 @@ bool FunctionCaller::WriteFunctionWrapper(
6767
Process *process = exe_ctx.GetProcessPtr();
6868

6969
if (!process) {
70-
diagnostic_manager.Printf(eDiagnosticSeverityError, "no process.");
70+
diagnostic_manager.Printf(lldb::eSeverityError, "no process.");
7171
return false;
7272
}
7373

7474
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
7575

7676
if (process != jit_process_sp.get()) {
77-
diagnostic_manager.Printf(eDiagnosticSeverityError,
78-
"process does not match the stored process.");
77+
diagnostic_manager.Printf(lldb::eSeverityError,
78+
"process does not match the stored process.");
7979
return false;
8080
}
8181

8282
if (process->GetState() != lldb::eStateStopped) {
83-
diagnostic_manager.Printf(eDiagnosticSeverityError,
84-
"process is not stopped");
83+
diagnostic_manager.Printf(lldb::eSeverityError, "process is not stopped");
8584
return false;
8685
}
8786

8887
if (!m_compiled) {
89-
diagnostic_manager.Printf(eDiagnosticSeverityError,
90-
"function not compiled");
88+
diagnostic_manager.Printf(lldb::eSeverityError, "function not compiled");
9189
return false;
9290
}
9391

@@ -101,7 +99,7 @@ bool FunctionCaller::WriteFunctionWrapper(
10199
can_interpret, eExecutionPolicyAlways));
102100

103101
if (!jit_error.Success()) {
104-
diagnostic_manager.Printf(eDiagnosticSeverityError,
102+
diagnostic_manager.Printf(lldb::eSeverityError,
105103
"Error in PrepareForExecution: %s.",
106104
jit_error.AsCString());
107105
return false;
@@ -144,7 +142,7 @@ bool FunctionCaller::WriteFunctionArguments(
144142
// All the information to reconstruct the struct is provided by the
145143
// StructExtractor.
146144
if (!m_struct_valid) {
147-
diagnostic_manager.PutString(eDiagnosticSeverityError,
145+
diagnostic_manager.PutString(lldb::eSeverityError,
148146
"Argument information was not correctly "
149147
"parsed, so the function cannot be called.");
150148
return false;
@@ -192,7 +190,7 @@ bool FunctionCaller::WriteFunctionArguments(
192190
size_t num_args = arg_values.GetSize();
193191
if (num_args != m_arg_values.GetSize()) {
194192
diagnostic_manager.Printf(
195-
eDiagnosticSeverityError,
193+
lldb::eSeverityError,
196194
"Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "",
197195
(uint64_t)num_args, (uint64_t)m_arg_values.GetSize());
198196
return false;
@@ -231,11 +229,11 @@ bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx,
231229
// the caller, we need to be stopped.
232230
Process *process = exe_ctx.GetProcessPtr();
233231
if (!process) {
234-
diagnostic_manager.PutString(eDiagnosticSeverityError, "no process");
232+
diagnostic_manager.PutString(lldb::eSeverityError, "no process");
235233
return false;
236234
}
237235
if (process->GetState() != lldb::eStateStopped) {
238-
diagnostic_manager.PutString(eDiagnosticSeverityError, "process running");
236+
diagnostic_manager.PutString(lldb::eSeverityError, "process running");
239237
return false;
240238
}
241239
if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
@@ -267,8 +265,7 @@ lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction(
267265
Thread *thread = exe_ctx.GetThreadPtr();
268266
if (thread == nullptr) {
269267
diagnostic_manager.PutString(
270-
eDiagnosticSeverityError,
271-
"Can't call a function without a valid thread.");
268+
lldb::eSeverityError, "Can't call a function without a valid thread.");
272269
return nullptr;
273270
}
274271

0 commit comments

Comments
 (0)