labath created this revision.
labath requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117490

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/include/lldb/Utility/Log.h
  lldb/include/lldb/Utility/Logging.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
  lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
  lldb/source/Utility/Logging.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp

Index: lldb/tools/lldb-server/lldb-gdbserver.cpp
===================================================================
--- lldb/tools/lldb-server/lldb-gdbserver.cpp
+++ lldb/tools/lldb-server/lldb-gdbserver.cpp
@@ -27,6 +27,7 @@
 #include "lldb/Host/Socket.h"
 #include "lldb/Host/common/NativeProcessProtocol.h"
 #include "lldb/Target/Process.h"
+#include "lldb/Utility/Logging.h"
 #include "lldb/Utility/Status.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Option/ArgList.h"
Index: lldb/source/Utility/Logging.cpp
===================================================================
--- lldb/source/Utility/Logging.cpp
+++ lldb/source/Utility/Logging.cpp
@@ -16,49 +16,98 @@
 using namespace lldb_private;
 
 static constexpr Log::Category g_categories[] = {
-  {{"api"}, {"log API calls and return values"}, LIBLLDB_LOG_API},
-  {{"ast"}, {"log AST"}, LIBLLDB_LOG_AST},
-  {{"break"}, {"log breakpoints"}, LIBLLDB_LOG_BREAKPOINTS},
-  {{"commands"}, {"log command argument parsing"}, LIBLLDB_LOG_COMMANDS},
-  {{"comm"}, {"log communication activities"}, LIBLLDB_LOG_COMMUNICATION},
-  {{"conn"}, {"log connection details"}, LIBLLDB_LOG_CONNECTION},
-  {{"demangle"}, {"log mangled names to catch demangler crashes"}, LIBLLDB_LOG_DEMANGLE},
-  {{"dyld"}, {"log shared library related activities"}, LIBLLDB_LOG_DYNAMIC_LOADER},
-  {{"event"}, {"log broadcaster, listener and event queue activities"}, LIBLLDB_LOG_EVENTS},
-  {{"expr"}, {"log expressions"}, LIBLLDB_LOG_EXPRESSIONS},
-  {{"formatters"}, {"log data formatters related activities"}, LIBLLDB_LOG_DATAFORMATTERS},
-  {{"host"}, {"log host activities"}, LIBLLDB_LOG_HOST},
-  {{"jit"}, {"log JIT events in the target"}, LIBLLDB_LOG_JIT_LOADER},
-  {{"language"}, {"log language runtime events"}, LIBLLDB_LOG_LANGUAGE},
-  {{"mmap"}, {"log mmap related activities"}, LIBLLDB_LOG_MMAP},
-  {{"module"}, {"log module activities such as when modules are created, destroyed, replaced, and more"}, LIBLLDB_LOG_MODULES},
-  {{"object"}, {"log object construction/destruction for important objects"}, LIBLLDB_LOG_OBJECT},
-  {{"os"}, {"log OperatingSystem plugin related activities"}, LIBLLDB_LOG_OS},
-  {{"platform"}, {"log platform events and activities"}, LIBLLDB_LOG_PLATFORM},
-  {{"process"}, {"log process events and activities"}, LIBLLDB_LOG_PROCESS},
-  {{"script"}, {"log events about the script interpreter"}, LIBLLDB_LOG_SCRIPT},
-  {{"state"}, {"log private and public process state changes"}, LIBLLDB_LOG_STATE},
-  {{"step"}, {"log step related activities"}, LIBLLDB_LOG_STEP},
-  {{"symbol"}, {"log symbol related issues and warnings"}, LIBLLDB_LOG_SYMBOLS},
-  {{"system-runtime"}, {"log system runtime events"}, LIBLLDB_LOG_SYSTEM_RUNTIME},
-  {{"target"}, {"log target events and activities"}, LIBLLDB_LOG_TARGET},
-  {{"temp"}, {"log internal temporary debug messages"}, LIBLLDB_LOG_TEMPORARY},
-  {{"thread"}, {"log thread events and activities"}, LIBLLDB_LOG_THREAD},
-  {{"types"}, {"log type system related activities"}, LIBLLDB_LOG_TYPES},
-  {{"unwind"}, {"log stack unwind activities"}, LIBLLDB_LOG_UNWIND},
-  {{"watch"}, {"log watchpoint related activities"}, LIBLLDB_LOG_WATCHPOINTS},
+    {{"api"}, {"log API calls and return values"}, uint32_t(LIBLLDB_LOG_API)},
+    {{"ast"}, {"log AST"}, uint32_t(LIBLLDB_LOG_AST)},
+    {{"break"}, {"log breakpoints"}, uint32_t(LIBLLDB_LOG_BREAKPOINTS)},
+    {{"commands"},
+     {"log command argument parsing"},
+     uint32_t(LIBLLDB_LOG_COMMANDS)},
+    {{"comm"},
+     {"log communication activities"},
+     uint32_t(LIBLLDB_LOG_COMMUNICATION)},
+    {{"conn"}, {"log connection details"}, uint32_t(LIBLLDB_LOG_CONNECTION)},
+    {{"demangle"},
+     {"log mangled names to catch demangler crashes"},
+     uint32_t(LIBLLDB_LOG_DEMANGLE)},
+    {{"dyld"},
+     {"log shared library related activities"},
+     uint32_t(LIBLLDB_LOG_DYNAMIC_LOADER)},
+    {{"event"},
+     {"log broadcaster, listener and event queue activities"},
+     uint32_t(LIBLLDB_LOG_EVENTS)},
+    {{"expr"}, {"log expressions"}, uint32_t(LIBLLDB_LOG_EXPRESSIONS)},
+    {{"formatters"},
+     {"log data formatters related activities"},
+     uint32_t(LIBLLDB_LOG_DATAFORMATTERS)},
+    {{"host"}, {"log host activities"}, uint32_t(LIBLLDB_LOG_HOST)},
+    {{"jit"},
+     {"log JIT events in the target"},
+     uint32_t(LIBLLDB_LOG_JIT_LOADER)},
+    {{"language"},
+     {"log language runtime events"},
+     uint32_t(LIBLLDB_LOG_LANGUAGE)},
+    {{"mmap"}, {"log mmap related activities"}, uint32_t(LIBLLDB_LOG_MMAP)},
+    {{"module"},
+     {"log module activities such as when modules are created, destroyed, "
+      "replaced, and more"},
+     uint32_t(LIBLLDB_LOG_MODULES)},
+    {{"object"},
+     {"log object construction/destruction for important objects"},
+     uint32_t(LIBLLDB_LOG_OBJECT)},
+    {{"os"},
+     {"log OperatingSystem plugin related activities"},
+     uint32_t(LIBLLDB_LOG_OS)},
+    {{"platform"},
+     {"log platform events and activities"},
+     uint32_t(LIBLLDB_LOG_PLATFORM)},
+    {{"process"},
+     {"log process events and activities"},
+     uint32_t(LIBLLDB_LOG_PROCESS)},
+    {{"script"},
+     {"log events about the script interpreter"},
+     uint32_t(LIBLLDB_LOG_SCRIPT)},
+    {{"state"},
+     {"log private and public process state changes"},
+     uint32_t(LIBLLDB_LOG_STATE)},
+    {{"step"}, {"log step related activities"}, uint32_t(LIBLLDB_LOG_STEP)},
+    {{"symbol"},
+     {"log symbol related issues and warnings"},
+     uint32_t(LIBLLDB_LOG_SYMBOLS)},
+    {{"system-runtime"},
+     {"log system runtime events"},
+     uint32_t(LIBLLDB_LOG_SYSTEM_RUNTIME)},
+    {{"target"},
+     {"log target events and activities"},
+     uint32_t(LIBLLDB_LOG_TARGET)},
+    {{"temp"},
+     {"log internal temporary debug messages"},
+     uint32_t(LIBLLDB_LOG_TEMPORARY)},
+    {{"thread"},
+     {"log thread events and activities"},
+     uint32_t(LIBLLDB_LOG_THREAD)},
+    {{"types"},
+     {"log type system related activities"},
+     uint32_t(LIBLLDB_LOG_TYPES)},
+    {{"unwind"}, {"log stack unwind activities"}, uint32_t(LIBLLDB_LOG_UNWIND)},
+    {{"watch"},
+     {"log watchpoint related activities"},
+     uint32_t(LIBLLDB_LOG_WATCHPOINTS)},
 };
 
-static Log::Channel g_log_channel(g_categories, LIBLLDB_LOG_DEFAULT);
+static Log::Channel g_log_channel(g_categories, uint32_t(LIBLLDB_LOG_DEFAULT));
+
+template <> Log::Channel &lldb_private::LogChannelFor<LLDBLog>() {
+  return g_log_channel;
+}
 
 void lldb_private::InitializeLldbChannel() {
   Log::Register("lldb", g_log_channel);
 }
 
-Log *lldb_private::GetLogIfAllCategoriesSet(uint32_t mask) {
-  return g_log_channel.GetLogIfAll(mask);
+Log *lldb_private::GetLogIfAllCategoriesSet(LLDBLog mask) {
+  return GetLogIfAny(mask);
 }
 
-Log *lldb_private::GetLogIfAnyCategoriesSet(uint32_t mask) {
-  return g_log_channel.GetLogIfAny(mask);
+Log *lldb_private::GetLogIfAnyCategoriesSet(LLDBLog mask) {
+  return GetLogIfAny(mask);
 }
Index: lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -39,7 +39,7 @@
       m_dispatch_queue_t(LLDB_INVALID_ADDRESS), m_queue_kind(eQueueKindUnknown),
       m_queue_serial_number(LLDB_INVALID_QUEUE_ID),
       m_associated_with_libdispatch_queue(eLazyBoolCalculate) {
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+  Log *log(GetLogIfAny(GDBR_LOG_THREAD));
   LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this, process.GetID(),
            GetID());
   // At this point we can clone reg_info for architectures supporting
@@ -54,7 +54,7 @@
 
 ThreadGDBRemote::~ThreadGDBRemote() {
   ProcessSP process_sp(GetProcess());
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+  Log *log(GetLogIfAny(GDBR_LOG_THREAD));
   LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this,
            process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, GetID());
   DestroyThread();
@@ -222,7 +222,7 @@
 StructuredData::ObjectSP ThreadGDBRemote::FetchThreadExtendedInfo() {
   StructuredData::ObjectSP object_sp;
   const lldb::user_id_t tid = GetProtocolID();
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+  Log *log(GetLogIfAny(GDBR_LOG_THREAD));
   LLDB_LOGF(log, "Fetching extended information for thread %4.4" PRIx64, tid);
   ProcessSP process_sp(GetProcess());
   if (process_sp) {
@@ -236,7 +236,7 @@
 void ThreadGDBRemote::WillResume(StateType resume_state) {
   int signo = GetResumeSignal();
   const lldb::user_id_t tid = GetProtocolID();
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+  Log *log(GetLogIfAny(GDBR_LOG_THREAD));
   LLDB_LOGF(log, "Resuming thread: %4.4" PRIx64 " with state: %s.", tid,
             StateAsCString(resume_state));
 
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
@@ -11,35 +11,52 @@
 
 #include "lldb/Utility/Log.h"
 
-#define GDBR_LOG_PROCESS (1u << 1)
-#define GDBR_LOG_THREAD (1u << 2)
-#define GDBR_LOG_PACKETS (1u << 3)
-#define GDBR_LOG_MEMORY (1u << 4) // Log memory reads/writes calls
-#define GDBR_LOG_MEMORY_DATA_SHORT                                             \
-  (1u << 5) // Log short memory reads/writes bytes
-#define GDBR_LOG_MEMORY_DATA_LONG (1u << 6) // Log all memory reads/writes bytes
-#define GDBR_LOG_BREAKPOINTS (1u << 7)
-#define GDBR_LOG_WATCHPOINTS (1u << 8)
-#define GDBR_LOG_STEP (1u << 9)
-#define GDBR_LOG_COMM (1u << 10)
-#define GDBR_LOG_ASYNC (1u << 11)
-#define GDBR_LOG_ALL (UINT32_MAX)
-#define GDBR_LOG_DEFAULT GDBR_LOG_PACKETS
-
 namespace lldb_private {
 namespace process_gdb_remote {
 
-class ProcessGDBRemoteLog {
-  static Log::Channel g_channel;
+enum class GDBRLog : uint32_t {
+  Process = 1u << 1,
+  LLVM_MARK_AS_BITMASK_ENUM(UINT32_MAX)
+};
 
+#define GDBR_LOG_PROCESS ::lldb_private::process_gdb_remote::GDBRLog::Process
+#define GDBR_LOG_THREAD ::lldb_private::process_gdb_remote::GDBRLog(1u << 2)
+#define GDBR_LOG_PACKETS ::lldb_private::process_gdb_remote::GDBRLog(1u << 3)
+#define GDBR_LOG_MEMORY                                                        \
+  ::lldb_private::process_gdb_remote::GDBRLog(                                 \
+      1u << 4) // Log memory reads/writes calls
+#define GDBR_LOG_MEMORY_DATA_SHORT                                             \
+  ::lldb_private::process_gdb_remote::GDBRLog(                                 \
+      1u << 5) // Log short memory reads/writes bytes
+#define GDBR_LOG_MEMORY_DATA_LONG                                              \
+  ::lldb_private::process_gdb_remote::GDBRLog(                                 \
+      1u << 6) // Log all memory reads/writes bytes
+#define GDBR_LOG_BREAKPOINTS                                                   \
+  ::lldb_private::process_gdb_remote::GDBRLog(1u << 7)
+#define GDBR_LOG_WATCHPOINTS                                                   \
+  ::lldb_private::process_gdb_remote::GDBRLog(1u << 8)
+#define GDBR_LOG_STEP ::lldb_private::process_gdb_remote::GDBRLog(1u << 9)
+#define GDBR_LOG_COMM ::lldb_private::process_gdb_remote::GDBRLog(1u << 10)
+#define GDBR_LOG_ASYNC ::lldb_private::process_gdb_remote::GDBRLog(1u << 11)
+#define GDBR_LOG_ALL ::lldb_private::process_gdb_remote::GDBRLog(UINT32_MAX)
+#define GDBR_LOG_DEFAULT GDBR_LOG_PACKETS
+
+class ProcessGDBRemoteLog {
 public:
   static void Initialize();
 
-  static Log *GetLogIfAllCategoriesSet(uint32_t mask) { return g_channel.GetLogIfAll(mask); }
-  static Log *GetLogIfAnyCategoryIsSet(uint32_t mask) { return g_channel.GetLogIfAny(mask); }
+  static Log *GetLogIfAllCategoriesSet(GDBRLog mask) {
+    return GetLogIfAll(mask);
+  }
+  static Log *GetLogIfAnyCategoryIsSet(GDBRLog mask) {
+    return GetLogIfAny(mask);
+  }
 };
 
 } // namespace process_gdb_remote
+
+template <> Log::Channel &LogChannelFor<process_gdb_remote::GDBRLog>();
+
 } // namespace lldb_private
 
 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_PROCESSGDBREMOTELOG_H
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
@@ -15,25 +15,35 @@
 using namespace lldb_private::process_gdb_remote;
 
 static constexpr Log::Category g_categories[] = {
-    {{"async"}, {"log asynchronous activity"}, GDBR_LOG_ASYNC},
-    {{"break"}, {"log breakpoints"}, GDBR_LOG_BREAKPOINTS},
-    {{"comm"}, {"log communication activity"}, GDBR_LOG_COMM},
-    {{"packets"}, {"log gdb remote packets"}, GDBR_LOG_PACKETS},
-    {{"memory"}, {"log memory reads and writes"}, GDBR_LOG_MEMORY},
+    {{"async"}, {"log asynchronous activity"}, uint32_t(GDBR_LOG_ASYNC)},
+    {{"break"}, {"log breakpoints"}, uint32_t(GDBR_LOG_BREAKPOINTS)},
+    {{"comm"}, {"log communication activity"}, uint32_t(GDBR_LOG_COMM)},
+    {{"packets"}, {"log gdb remote packets"}, uint32_t(GDBR_LOG_PACKETS)},
+    {{"memory"}, {"log memory reads and writes"}, uint32_t(GDBR_LOG_MEMORY)},
     {{"data-short"},
      {"log memory bytes for memory reads and writes for short transactions "
       "only"},
-     GDBR_LOG_MEMORY_DATA_SHORT},
+     uint32_t(GDBR_LOG_MEMORY_DATA_SHORT)},
     {{"data-long"},
      {"log memory bytes for memory reads and writes for all transactions"},
-     GDBR_LOG_MEMORY_DATA_LONG},
-    {{"process"}, {"log process events and activities"}, GDBR_LOG_PROCESS},
-    {{"step"}, {"log step related activities"}, GDBR_LOG_STEP},
-    {{"thread"}, {"log thread events and activities"}, GDBR_LOG_THREAD},
-    {{"watch"}, {"log watchpoint related activities"}, GDBR_LOG_WATCHPOINTS},
+     uint32_t(GDBR_LOG_MEMORY_DATA_LONG)},
+    {{"process"},
+     {"log process events and activities"},
+     uint32_t(GDBR_LOG_PROCESS)},
+    {{"step"}, {"log step related activities"}, uint32_t(GDBR_LOG_STEP)},
+    {{"thread"},
+     {"log thread events and activities"},
+     uint32_t(GDBR_LOG_THREAD)},
+    {{"watch"},
+     {"log watchpoint related activities"},
+     uint32_t(GDBR_LOG_WATCHPOINTS)},
 };
 
-Log::Channel ProcessGDBRemoteLog::g_channel(g_categories, GDBR_LOG_DEFAULT);
+static Log::Channel g_channel(g_categories, uint32_t(GDBR_LOG_DEFAULT));
+
+template <> Log::Channel &lldb_private::LogChannelFor<GDBRLog>() {
+  return g_channel;
+}
 
 void ProcessGDBRemoteLog::Initialize() {
   static llvm::once_flag g_once_flag;
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -524,7 +524,7 @@
 }
 
 Status ProcessGDBRemote::DoConnectRemote(llvm::StringRef remote_url) {
-  Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  Log *log(GetLogIfAny(GDBR_LOG_PROCESS));
 
   Status error(WillLaunchOrAttach());
   if (error.Fail())
@@ -601,8 +601,7 @@
                 ReadModuleFromMemory(FileSpec(namebuf), standalone_value);
           }
 
-          Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(
-              LIBLLDB_LOG_DYNAMIC_LOADER));
+          Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
           if (module_sp.get()) {
             target.GetImages().AppendIfNeeded(module_sp, false);
 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -1086,7 +1086,7 @@
 }
 
 void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() {
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_COMM));
+  Log *log(GetLogIfAny(GDBR_LOG_COMM));
 
   bool interrupt = false;
   bool done = false;
Index: lldb/include/lldb/Utility/Logging.h
===================================================================
--- lldb/include/lldb/Utility/Logging.h
+++ lldb/include/lldb/Utility/Logging.h
@@ -9,57 +9,65 @@
 #ifndef LLDB_UTILITY_LOGGING_H
 #define LLDB_UTILITY_LOGGING_H
 
+#include "lldb/Utility/Log.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include <cstdint>
 
+namespace lldb_private {
+
+enum class LLDBLog : uint32_t {
+  Process = 1u << 1,
+  LLVM_MARK_AS_BITMASK_ENUM(UINT32_MAX)
+};
+
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+
 // Log Bits specific to logging in lldb
-#define LIBLLDB_LOG_PROCESS (1u << 1)
-#define LIBLLDB_LOG_THREAD (1u << 2)
-#define LIBLLDB_LOG_DYNAMIC_LOADER (1u << 3)
-#define LIBLLDB_LOG_EVENTS (1u << 4)
-#define LIBLLDB_LOG_BREAKPOINTS (1u << 5)
-#define LIBLLDB_LOG_WATCHPOINTS (1u << 6)
-#define LIBLLDB_LOG_STEP (1u << 7)
-#define LIBLLDB_LOG_EXPRESSIONS (1u << 8)
-#define LIBLLDB_LOG_TEMPORARY (1u << 9)
-#define LIBLLDB_LOG_STATE (1u << 10)
-#define LIBLLDB_LOG_OBJECT (1u << 11)
-#define LIBLLDB_LOG_COMMUNICATION (1u << 12)
-#define LIBLLDB_LOG_CONNECTION (1u << 13)
-#define LIBLLDB_LOG_HOST (1u << 14)
-#define LIBLLDB_LOG_UNWIND (1u << 15)
-#define LIBLLDB_LOG_API (1u << 16)
-#define LIBLLDB_LOG_SCRIPT (1u << 17)
-#define LIBLLDB_LOG_COMMANDS (1U << 18)
-#define LIBLLDB_LOG_TYPES (1u << 19)
-#define LIBLLDB_LOG_SYMBOLS (1u << 20)
-#define LIBLLDB_LOG_MODULES (1u << 21)
-#define LIBLLDB_LOG_TARGET (1u << 22)
-#define LIBLLDB_LOG_MMAP (1u << 23)
-#define LIBLLDB_LOG_OS (1u << 24)
-#define LIBLLDB_LOG_PLATFORM (1u << 25)
-#define LIBLLDB_LOG_SYSTEM_RUNTIME (1u << 26)
-#define LIBLLDB_LOG_JIT_LOADER (1u << 27)
-#define LIBLLDB_LOG_LANGUAGE (1u << 28)
-#define LIBLLDB_LOG_DATAFORMATTERS (1u << 29)
-#define LIBLLDB_LOG_DEMANGLE (1u << 30)
-#define LIBLLDB_LOG_AST (1u << 31)
-#define LIBLLDB_LOG_ALL (UINT32_MAX)
+#define LIBLLDB_LOG_PROCESS ::lldb_private::LLDBLog::Process
+#define LIBLLDB_LOG_THREAD ::lldb_private::LLDBLog(1u << 2)
+#define LIBLLDB_LOG_DYNAMIC_LOADER ::lldb_private::LLDBLog(1u << 3)
+#define LIBLLDB_LOG_EVENTS ::lldb_private::LLDBLog(1u << 4)
+#define LIBLLDB_LOG_BREAKPOINTS ::lldb_private::LLDBLog(1u << 5)
+#define LIBLLDB_LOG_WATCHPOINTS ::lldb_private::LLDBLog(1u << 6)
+#define LIBLLDB_LOG_STEP ::lldb_private::LLDBLog(1u << 7)
+#define LIBLLDB_LOG_EXPRESSIONS ::lldb_private::LLDBLog(1u << 8)
+#define LIBLLDB_LOG_TEMPORARY ::lldb_private::LLDBLog(1u << 9)
+#define LIBLLDB_LOG_STATE ::lldb_private::LLDBLog(1u << 10)
+#define LIBLLDB_LOG_OBJECT ::lldb_private::LLDBLog(1u << 11)
+#define LIBLLDB_LOG_COMMUNICATION ::lldb_private::LLDBLog(1u << 12)
+#define LIBLLDB_LOG_CONNECTION ::lldb_private::LLDBLog(1u << 13)
+#define LIBLLDB_LOG_HOST ::lldb_private::LLDBLog(1u << 14)
+#define LIBLLDB_LOG_UNWIND ::lldb_private::LLDBLog(1u << 15)
+#define LIBLLDB_LOG_API ::lldb_private::LLDBLog(1u << 16)
+#define LIBLLDB_LOG_SCRIPT ::lldb_private::LLDBLog(1u << 17)
+#define LIBLLDB_LOG_COMMANDS ::lldb_private::LLDBLog(1U << 18)
+#define LIBLLDB_LOG_TYPES ::lldb_private::LLDBLog(1u << 19)
+#define LIBLLDB_LOG_SYMBOLS ::lldb_private::LLDBLog(1u << 20)
+#define LIBLLDB_LOG_MODULES ::lldb_private::LLDBLog(1u << 21)
+#define LIBLLDB_LOG_TARGET ::lldb_private::LLDBLog(1u << 22)
+#define LIBLLDB_LOG_MMAP ::lldb_private::LLDBLog(1u << 23)
+#define LIBLLDB_LOG_OS ::lldb_private::LLDBLog(1u << 24)
+#define LIBLLDB_LOG_PLATFORM ::lldb_private::LLDBLog(1u << 25)
+#define LIBLLDB_LOG_SYSTEM_RUNTIME ::lldb_private::LLDBLog(1u << 26)
+#define LIBLLDB_LOG_JIT_LOADER ::lldb_private::LLDBLog(1u << 27)
+#define LIBLLDB_LOG_LANGUAGE ::lldb_private::LLDBLog(1u << 28)
+#define LIBLLDB_LOG_DATAFORMATTERS ::lldb_private::LLDBLog(1u << 29)
+#define LIBLLDB_LOG_DEMANGLE ::lldb_private::LLDBLog(1u << 30)
+#define LIBLLDB_LOG_AST ::lldb_private::LLDBLog(1u << 31)
+#define LIBLLDB_LOG_ALL ::lldb_private::LLDBLog(UINT32_MAX)
 #define LIBLLDB_LOG_DEFAULT                                                    \
   (LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD | LIBLLDB_LOG_DYNAMIC_LOADER |     \
    LIBLLDB_LOG_BREAKPOINTS | LIBLLDB_LOG_WATCHPOINTS | LIBLLDB_LOG_STEP |      \
    LIBLLDB_LOG_STATE | LIBLLDB_LOG_SYMBOLS | LIBLLDB_LOG_TARGET |              \
    LIBLLDB_LOG_COMMANDS)
 
-namespace lldb_private {
-
-class Log;
-
-Log *GetLogIfAllCategoriesSet(uint32_t mask);
+Log *GetLogIfAllCategoriesSet(LLDBLog mask);
 
-Log *GetLogIfAnyCategoriesSet(uint32_t mask);
+Log *GetLogIfAnyCategoriesSet(LLDBLog mask);
 
 void InitializeLldbChannel();
 
+template <> Log::Channel &LogChannelFor<LLDBLog>();
 } // namespace lldb_private
 
 #endif // LLDB_UTILITY_LOGGING_H
Index: lldb/include/lldb/Utility/Log.h
===================================================================
--- lldb/include/lldb/Utility/Log.h
+++ lldb/include/lldb/Utility/Log.h
@@ -10,7 +10,6 @@
 #define LLDB_UTILITY_LOG_H
 
 #include "lldb/Utility/Flags.h"
-#include "lldb/Utility/Logging.h"
 #include "lldb/lldb-defines.h"
 
 #include "llvm/ADT/ArrayRef.h"
@@ -215,6 +214,14 @@
   void operator=(const Log &) = delete;
 };
 
+template <typename Cat> Log::Channel &LogChannelFor() = delete;
+template <typename Cat> Log *GetLogIfAny(Cat mask) {
+  return LogChannelFor<Cat>().GetLogIfAny(uint32_t(mask));
+}
+template <typename Cat> Log *GetLogIfAll(Cat mask) {
+  return LogChannelFor<Cat>().GetLogIfAll(uint32_t(mask));
+}
+
 } // namespace lldb_private
 
 /// The LLDB_LOG* macros defined below are the way to emit log messages.
@@ -272,3 +279,7 @@
   } while (0)
 
 #endif // LLDB_UTILITY_LOG_H
+
+
+// TODO: Remove this and fix includes everywhere.
+#include "lldb/Utility/Logging.h"
Index: lldb/include/lldb/Interpreter/ScriptedInterface.h
===================================================================
--- lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -32,7 +32,7 @@
   template <typename Ret>
   Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
                        Status &error,
-                       uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
+                       LLDBLog log_caterogy = LIBLLDB_LOG_PROCESS) {
     LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
               caller_name.data(), error_msg.data());
     error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to