JDevlieghere created this revision.
JDevlieghere added reviewers: labath, clayborg.
Herald added a project: All.
JDevlieghere requested review of this revision.
In January, Greg put up a patch (D117382 <https://reviews.llvm.org/D117382>) to
support more than 32 log categories, among other things. That led to a bunch of
nice cleanups, but categories are still limited to 32 because different places
still using `uint32_t`. This patch fixes the remaining issues and enables
adding a 32nd log category.
https://reviews.llvm.org/D134245
Files:
lldb/include/lldb/Utility/LLDBLog.h
lldb/include/lldb/Utility/Log.h
lldb/source/Utility/Log.cpp
Index: lldb/source/Utility/Log.cpp
===================================================================
--- lldb/source/Utility/Log.cpp
+++ lldb/source/Utility/Log.cpp
@@ -60,13 +60,14 @@
});
}
-uint32_t Log::GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &entry,
- llvm::ArrayRef<const char *> categories) {
+Log::MaskType Log::GetFlags(llvm::raw_ostream &stream,
+ const ChannelMap::value_type &entry,
+ llvm::ArrayRef<const char *> categories) {
bool list_categories = false;
- uint32_t flags = 0;
+ Log::MaskType flags = 0;
for (const char *category : categories) {
if (llvm::StringRef("all").equals_insensitive(category)) {
- flags |= UINT32_MAX;
+ flags |= std::numeric_limits<Log::MaskType>::max();
continue;
}
if (llvm::StringRef("default").equals_insensitive(category)) {
@@ -91,7 +92,7 @@
}
void Log::Enable(const std::shared_ptr<LogHandler> &handler_sp,
- uint32_t options, uint32_t flags) {
+ uint32_t options, Log::MaskType flags) {
llvm::sys::ScopedWriter lock(m_mutex);
MaskType mask = m_mask.fetch_or(flags, std::memory_order_relaxed);
@@ -102,7 +103,7 @@
}
}
-void Log::Disable(uint32_t flags) {
+void Log::Disable(Log::MaskType flags) {
llvm::sys::ScopedWriter lock(m_mutex);
MaskType mask = m_mask.fetch_and(~flags, std::memory_order_relaxed);
@@ -126,7 +127,7 @@
return m_options.load(std::memory_order_relaxed);
}
-const Flags Log::GetMask() const {
+Log::MaskType Log::GetMask() const {
return m_mask.load(std::memory_order_relaxed);
}
@@ -203,7 +204,7 @@
void Log::Unregister(llvm::StringRef name) {
auto iter = g_channel_map->find(name);
assert(iter != g_channel_map->end());
- iter->second.Disable(UINT32_MAX);
+ iter->second.Disable(std::numeric_limits<MaskType>::max());
g_channel_map->erase(iter);
}
@@ -216,7 +217,7 @@
error_stream << llvm::formatv("Invalid log channel '{0}'.\n", channel);
return false;
}
- uint32_t flags = categories.empty()
+ MaskType flags = categories.empty()
? iter->second.m_channel.default_flags
: GetFlags(error_stream, *iter, categories);
iter->second.Enable(log_handler_sp, log_options, flags);
@@ -231,8 +232,8 @@
error_stream << llvm::formatv("Invalid log channel '{0}'.\n", channel);
return false;
}
- uint32_t flags = categories.empty()
- ? UINT32_MAX
+ MaskType flags = categories.empty()
+ ? std::numeric_limits<MaskType>::max()
: GetFlags(error_stream, *iter, categories);
iter->second.Disable(flags);
return true;
@@ -267,7 +268,7 @@
void Log::DisableAllLogChannels() {
for (auto &entry : *g_channel_map)
- entry.second.Disable(UINT32_MAX);
+ entry.second.Disable(std::numeric_limits<MaskType>::max());
}
void Log::ForEachChannelCategory(
Index: lldb/include/lldb/Utility/Log.h
===================================================================
--- lldb/include/lldb/Utility/Log.h
+++ lldb/include/lldb/Utility/Log.h
@@ -166,7 +166,7 @@
// output will be discarded.
Log *GetLog(MaskType mask) {
Log *log = log_ptr.load(std::memory_order_relaxed);
- if (log && log->GetMask().AnySet(mask))
+ if (log && ((log->GetMask() & mask) != 0))
return log;
return nullptr;
}
@@ -243,7 +243,7 @@
const Flags GetOptions() const;
- const Flags GetMask() const;
+ MaskType GetMask() const;
bool GetVerbose() const;
@@ -276,9 +276,9 @@
}
void Enable(const std::shared_ptr<LogHandler> &handler_sp, uint32_t options,
- uint32_t flags);
+ MaskType flags);
- void Disable(uint32_t flags);
+ void Disable(MaskType flags);
bool Dump(llvm::raw_ostream &stream);
@@ -291,8 +291,9 @@
static void ListCategories(llvm::raw_ostream &stream,
const ChannelMap::value_type &entry);
- static uint32_t GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &entry,
- llvm::ArrayRef<const char *> categories);
+ static Log::MaskType GetFlags(llvm::raw_ostream &stream,
+ const ChannelMap::value_type &entry,
+ llvm::ArrayRef<const char *> categories);
Log(const Log &) = delete;
void operator=(const Log &) = delete;
Index: lldb/include/lldb/Utility/LLDBLog.h
===================================================================
--- lldb/include/lldb/Utility/LLDBLog.h
+++ lldb/include/lldb/Utility/LLDBLog.h
@@ -48,7 +48,7 @@
Unwind = Log::ChannelFlag<29>,
Watchpoints = Log::ChannelFlag<30>,
OnDemand = Log::ChannelFlag<31>,
- LLVM_MARK_AS_BITMASK_ENUM(Watchpoints),
+ LLVM_MARK_AS_BITMASK_ENUM(OnDemand),
};
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits