[Lldb-commits] [lldb] 3b4db10 - [lldb] Actually support more than 32 logging categories

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 19 22:31:29 PDT 2022


Author: Jonas Devlieghere
Date: 2022-09-19T22:31:20-07:00
New Revision: 3b4db10f3492dfbab705ca4b2dd19d32fee075b9

URL: https://github.com/llvm/llvm-project/commit/3b4db10f3492dfbab705ca4b2dd19d32fee075b9
DIFF: https://github.com/llvm/llvm-project/commit/3b4db10f3492dfbab705ca4b2dd19d32fee075b9.diff

LOG: [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

Added: 
    

Modified: 
    lldb/include/lldb/Utility/LLDBLog.h
    lldb/include/lldb/Utility/Log.h
    lldb/source/Utility/Log.cpp
    lldb/unittests/Utility/LogTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/LLDBLog.h b/lldb/include/lldb/Utility/LLDBLog.h
index 63dbb63f6f56..a440a72df9ea 100644
--- a/lldb/include/lldb/Utility/LLDBLog.h
+++ b/lldb/include/lldb/Utility/LLDBLog.h
@@ -48,7 +48,7 @@ enum class LLDBLog : Log::MaskType {
   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();

diff  --git a/lldb/include/lldb/Utility/Log.h b/lldb/include/lldb/Utility/Log.h
index 304dc7a0368f..596bec21b6f1 100644
--- a/lldb/include/lldb/Utility/Log.h
+++ b/lldb/include/lldb/Utility/Log.h
@@ -166,7 +166,7 @@ class Log final {
     // 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 @@ class Log final {
 
   const Flags GetOptions() const;
 
-  const Flags GetMask() const;
+  MaskType GetMask() const;
 
   bool GetVerbose() const;
 
@@ -276,9 +276,9 @@ class Log final {
   }
 
   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 @@ class Log final {
 
   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;

diff  --git a/lldb/source/Utility/Log.cpp b/lldb/source/Utility/Log.cpp
index 67edb15ba684..045e0f2cb68a 100644
--- a/lldb/source/Utility/Log.cpp
+++ b/lldb/source/Utility/Log.cpp
@@ -60,13 +60,14 @@ void Log::ListCategories(llvm::raw_ostream &stream,
                   });
 }
 
-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 @@ uint32_t Log::GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &
 }
 
 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::Enable(const std::shared_ptr<LogHandler> &handler_sp,
   }
 }
 
-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 @@ const Flags Log::GetOptions() const {
   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::Register(llvm::StringRef name, Channel &channel) {
 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 @@ bool Log::EnableLogChannel(const std::shared_ptr<LogHandler> &log_handler_sp,
     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 @@ bool Log::DisableLogChannel(llvm::StringRef channel,
     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 @@ bool Log::ListChannelCategories(llvm::StringRef channel,
 
 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(

diff  --git a/lldb/unittests/Utility/LogTest.cpp b/lldb/unittests/Utility/LogTest.cpp
index 87928a695689..275bd0dda334 100644
--- a/lldb/unittests/Utility/LogTest.cpp
+++ b/lldb/unittests/Utility/LogTest.cpp
@@ -363,8 +363,8 @@ TEST_F(LogChannelEnabledTest, LogGetLogThread) {
 
   // Try fetching the log mask on one thread. Concurrently, try disabling the
   // log channel.
-  uint32_t mask;
-  std::thread log_thread([this, &mask] { mask = getLog()->GetMask().Get(); });
+  uint64_t mask;
+  std::thread log_thread([this, &mask] { mask = getLog()->GetMask(); });
   EXPECT_TRUE(DisableChannel("chan", {}, err));
   log_thread.join();
 


        


More information about the lldb-commits mailing list