Skip to content

Commit 3b4db10

Browse files
committed
[lldb] Actually support more than 32 logging categories
In January, Greg put up a patch (D117382) to support, among other things, more than 32 log categories. That led to a bunch of nice cleanups, but categories remained constrained because different parts of the code were still using uint32_t. This patch fixes the remaining issues and makes it possible to add a 32nd log category. Differential revision: https://reviews.llvm.org/D134245
1 parent 181279f commit 3b4db10

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

lldb/include/lldb/Utility/LLDBLog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class LLDBLog : Log::MaskType {
4848
Unwind = Log::ChannelFlag<29>,
4949
Watchpoints = Log::ChannelFlag<30>,
5050
OnDemand = Log::ChannelFlag<31>,
51-
LLVM_MARK_AS_BITMASK_ENUM(Watchpoints),
51+
LLVM_MARK_AS_BITMASK_ENUM(OnDemand),
5252
};
5353

5454
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();

lldb/include/lldb/Utility/Log.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Log final {
166166
// output will be discarded.
167167
Log *GetLog(MaskType mask) {
168168
Log *log = log_ptr.load(std::memory_order_relaxed);
169-
if (log && log->GetMask().AnySet(mask))
169+
if (log && ((log->GetMask() & mask) != 0))
170170
return log;
171171
return nullptr;
172172
}
@@ -243,7 +243,7 @@ class Log final {
243243

244244
const Flags GetOptions() const;
245245

246-
const Flags GetMask() const;
246+
MaskType GetMask() const;
247247

248248
bool GetVerbose() const;
249249

@@ -276,9 +276,9 @@ class Log final {
276276
}
277277

278278
void Enable(const std::shared_ptr<LogHandler> &handler_sp, uint32_t options,
279-
uint32_t flags);
279+
MaskType flags);
280280

281-
void Disable(uint32_t flags);
281+
void Disable(MaskType flags);
282282

283283
bool Dump(llvm::raw_ostream &stream);
284284

@@ -291,8 +291,9 @@ class Log final {
291291

292292
static void ListCategories(llvm::raw_ostream &stream,
293293
const ChannelMap::value_type &entry);
294-
static uint32_t GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &entry,
295-
llvm::ArrayRef<const char *> categories);
294+
static Log::MaskType GetFlags(llvm::raw_ostream &stream,
295+
const ChannelMap::value_type &entry,
296+
llvm::ArrayRef<const char *> categories);
296297

297298
Log(const Log &) = delete;
298299
void operator=(const Log &) = delete;

lldb/source/Utility/Log.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ void Log::ListCategories(llvm::raw_ostream &stream,
6060
});
6161
}
6262

63-
uint32_t Log::GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &entry,
64-
llvm::ArrayRef<const char *> categories) {
63+
Log::MaskType Log::GetFlags(llvm::raw_ostream &stream,
64+
const ChannelMap::value_type &entry,
65+
llvm::ArrayRef<const char *> categories) {
6566
bool list_categories = false;
66-
uint32_t flags = 0;
67+
Log::MaskType flags = 0;
6768
for (const char *category : categories) {
6869
if (llvm::StringRef("all").equals_insensitive(category)) {
69-
flags |= UINT32_MAX;
70+
flags |= std::numeric_limits<Log::MaskType>::max();
7071
continue;
7172
}
7273
if (llvm::StringRef("default").equals_insensitive(category)) {
@@ -91,7 +92,7 @@ uint32_t Log::GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &
9192
}
9293

9394
void Log::Enable(const std::shared_ptr<LogHandler> &handler_sp,
94-
uint32_t options, uint32_t flags) {
95+
uint32_t options, Log::MaskType flags) {
9596
llvm::sys::ScopedWriter lock(m_mutex);
9697

9798
MaskType mask = m_mask.fetch_or(flags, std::memory_order_relaxed);
@@ -102,7 +103,7 @@ void Log::Enable(const std::shared_ptr<LogHandler> &handler_sp,
102103
}
103104
}
104105

105-
void Log::Disable(uint32_t flags) {
106+
void Log::Disable(Log::MaskType flags) {
106107
llvm::sys::ScopedWriter lock(m_mutex);
107108

108109
MaskType mask = m_mask.fetch_and(~flags, std::memory_order_relaxed);
@@ -126,7 +127,7 @@ const Flags Log::GetOptions() const {
126127
return m_options.load(std::memory_order_relaxed);
127128
}
128129

129-
const Flags Log::GetMask() const {
130+
Log::MaskType Log::GetMask() const {
130131
return m_mask.load(std::memory_order_relaxed);
131132
}
132133

@@ -203,7 +204,7 @@ void Log::Register(llvm::StringRef name, Channel &channel) {
203204
void Log::Unregister(llvm::StringRef name) {
204205
auto iter = g_channel_map->find(name);
205206
assert(iter != g_channel_map->end());
206-
iter->second.Disable(UINT32_MAX);
207+
iter->second.Disable(std::numeric_limits<MaskType>::max());
207208
g_channel_map->erase(iter);
208209
}
209210

@@ -216,7 +217,7 @@ bool Log::EnableLogChannel(const std::shared_ptr<LogHandler> &log_handler_sp,
216217
error_stream << llvm::formatv("Invalid log channel '{0}'.\n", channel);
217218
return false;
218219
}
219-
uint32_t flags = categories.empty()
220+
MaskType flags = categories.empty()
220221
? iter->second.m_channel.default_flags
221222
: GetFlags(error_stream, *iter, categories);
222223
iter->second.Enable(log_handler_sp, log_options, flags);
@@ -231,8 +232,8 @@ bool Log::DisableLogChannel(llvm::StringRef channel,
231232
error_stream << llvm::formatv("Invalid log channel '{0}'.\n", channel);
232233
return false;
233234
}
234-
uint32_t flags = categories.empty()
235-
? UINT32_MAX
235+
MaskType flags = categories.empty()
236+
? std::numeric_limits<MaskType>::max()
236237
: GetFlags(error_stream, *iter, categories);
237238
iter->second.Disable(flags);
238239
return true;
@@ -267,7 +268,7 @@ bool Log::ListChannelCategories(llvm::StringRef channel,
267268

268269
void Log::DisableAllLogChannels() {
269270
for (auto &entry : *g_channel_map)
270-
entry.second.Disable(UINT32_MAX);
271+
entry.second.Disable(std::numeric_limits<MaskType>::max());
271272
}
272273

273274
void Log::ForEachChannelCategory(

lldb/unittests/Utility/LogTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ TEST_F(LogChannelEnabledTest, LogGetLogThread) {
363363

364364
// Try fetching the log mask on one thread. Concurrently, try disabling the
365365
// log channel.
366-
uint32_t mask;
367-
std::thread log_thread([this, &mask] { mask = getLog()->GetMask().Get(); });
366+
uint64_t mask;
367+
std::thread log_thread([this, &mask] { mask = getLog()->GetMask(); });
368368
EXPECT_TRUE(DisableChannel("chan", {}, err));
369369
log_thread.join();
370370

0 commit comments

Comments
 (0)