[Lldb-commits] [lldb] c8fbf80 - [lldb] Convert Process KDP Log to the new API

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Sun Jan 30 23:59:56 PST 2022


Author: Pavel Labath
Date: 2022-01-31T08:59:41+01:00
New Revision: c8fbf8037d7ababd686c088461dbb5d52fd33fc7

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

LOG: [lldb] Convert Process KDP Log to the new API

Added: 
    

Modified: 
    lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
    lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
    lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h
    lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
index d397d16876300..ea1893002ddfd 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
@@ -65,7 +65,7 @@ bool CommunicationKDP::SendRequestAndGetReply(
     const CommandType command, const PacketStreamType &request_packet,
     DataExtractor &reply_packet) {
   if (IsRunning()) {
-    Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
+    Log *log = GetLog(KDPLog::Packets);
     if (log) {
       PacketStreamType log_strm;
       DumpPacket(log_strm, request_packet.GetData(), request_packet.GetSize());
@@ -133,7 +133,7 @@ bool CommunicationKDP::SendRequestPacketNoLock(
     const char *packet_data = request_packet.GetData();
     const size_t packet_size = request_packet.GetSize();
 
-    Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
+    Log *log = GetLog(KDPLog::Packets);
     if (log) {
       PacketStreamType log_strm;
       DumpPacket(log_strm, packet_data, packet_size);
@@ -178,7 +178,7 @@ size_t CommunicationKDP::WaitForPacketWithTimeoutMicroSecondsNoLock(
   uint8_t buffer[8192];
   Status error;
 
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
+  Log *log = GetLog(KDPLog::Packets);
 
   // Check for a packet from our cache first without trying any reading...
   if (CheckForPacket(NULL, 0, packet))
@@ -231,7 +231,7 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len,
   // Put the packet data into the buffer in a thread safe fashion
   std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
 
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
+  Log *log = GetLog(KDPLog::Packets);
 
   if (src && src_len > 0) {
     if (log && log->GetVerbose()) {

diff  --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index df046bf1f0755..6752ba3f69c8f 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -381,7 +381,7 @@ ProcessKDP::DoAttachToProcessWithName(const char *process_name,
 void ProcessKDP::DidAttach(ArchSpec &process_arch) {
   Process::DidAttach(process_arch);
 
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
+  Log *log = GetLog(KDPLog::Process);
   LLDB_LOGF(log, "ProcessKDP::DidAttach()");
   if (GetID() != LLDB_INVALID_PROCESS_ID) {
     GetHostArchitecture(process_arch);
@@ -400,7 +400,7 @@ Status ProcessKDP::WillResume() { return Status(); }
 
 Status ProcessKDP::DoResume() {
   Status error;
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
+  Log *log = GetLog(KDPLog::Process);
   // Only start the async thread if we try to do any process control
   if (!m_async_thread.IsJoinable())
     StartAsyncThread();
@@ -492,7 +492,7 @@ lldb::ThreadSP ProcessKDP::GetKernelThread() {
 bool ProcessKDP::DoUpdateThreadList(ThreadList &old_thread_list,
                                     ThreadList &new_thread_list) {
   // locker will keep a mutex locked until it goes out of scope
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD));
+  Log *log = GetLog(KDPLog::Thread);
   LLDB_LOGV(log, "pid = {0}", GetID());
 
   // Even though there is a CPU mask, it doesn't mean we can see each CPU
@@ -530,7 +530,7 @@ Status ProcessKDP::DoHalt(bool &caused_stop) {
 
 Status ProcessKDP::DoDetach(bool keep_stopped) {
   Status error;
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
+  Log *log = GetLog(KDPLog::Process);
   LLDB_LOGF(log, "ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped);
 
   if (m_comm.IsRunning()) {
@@ -715,7 +715,7 @@ void ProcessKDP::DebuggerInitialize(lldb_private::Debugger &debugger) {
 }
 
 bool ProcessKDP::StartAsyncThread() {
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
+  Log *log = GetLog(KDPLog::Process);
 
   LLDB_LOGF(log, "ProcessKDP::StartAsyncThread ()");
 
@@ -725,9 +725,8 @@ bool ProcessKDP::StartAsyncThread() {
   llvm::Expected<HostThread> async_thread = ThreadLauncher::LaunchThread(
       "<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this);
   if (!async_thread) {
-    LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST),
-             "failed to launch host thread: {}",
-             llvm::toString(async_thread.takeError()));
+    LLDB_LOG_ERROR(GetLog(LLDBLog::Host), async_thread.takeError(),
+                   "failed to launch host thread: {}");
     return false;
   }
   m_async_thread = *async_thread;
@@ -735,7 +734,7 @@ bool ProcessKDP::StartAsyncThread() {
 }
 
 void ProcessKDP::StopAsyncThread() {
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
+  Log *log = GetLog(KDPLog::Process);
 
   LLDB_LOGF(log, "ProcessKDP::StopAsyncThread ()");
 
@@ -751,7 +750,7 @@ void *ProcessKDP::AsyncThread(void *arg) {
 
   const lldb::pid_t pid = process->GetID();
 
-  Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
+  Log *log = GetLog(KDPLog::Process);
   LLDB_LOGF(log,
             "ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64
             ") thread starting...",

diff  --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h
index f47a9f5dd0876..78333442ef450 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h
@@ -28,24 +28,10 @@ enum class KDPLog : Log::MaskType {
   Watchpoints = Log::ChannelFlag<10>,
   LLVM_MARK_AS_BITMASK_ENUM(Watchpoints)
 };
-#define KDP_LOG_PROCESS ::lldb_private::KDPLog::Process
-#define KDP_LOG_THREAD ::lldb_private::KDPLog::Thread
-#define KDP_LOG_PACKETS ::lldb_private::KDPLog::Packets
-#define KDP_LOG_MEMORY ::lldb_private::KDPLog::Memory
-#define KDP_LOG_MEMORY_DATA_SHORT ::lldb_private::KDPLog::MemoryDataShort
-#define KDP_LOG_MEMORY_DATA_LONG ::lldb_private::KDPLog::MemoryDataLong
-#define KDP_LOG_BREAKPOINTS ::lldb_private::KDPLog::Breakpoints
-#define KDP_LOG_WATCHPOINTS ::lldb_private::KDPLog::Watchpoints
-#define KDP_LOG_STEP ::lldb_private::KDPLog::Step
-#define KDP_LOG_COMM ::lldb_private::KDPLog::Comm
-#define KDP_LOG_ASYNC ::lldb_private::KDPLog::Async
-#define KDP_LOG_DEFAULT KDP_LOG_PACKETS
 
 class ProcessKDPLog {
 public:
   static void Initialize();
-
-  static Log *GetLogIfAllCategoriesSet(KDPLog mask) { return GetLog(mask); }
 };
 
 template <> Log::Channel &LogChannelFor<KDPLog>();

diff  --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
index a4af5e030ff78..1349de879c69a 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
@@ -39,12 +39,12 @@ using namespace lldb_private;
 ThreadKDP::ThreadKDP(Process &process, lldb::tid_t tid)
     : Thread(process, tid), m_thread_name(), m_dispatch_queue_name(),
       m_thread_dispatch_qaddr(LLDB_INVALID_ADDRESS) {
-  Log *log = ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD);
+  Log *log = GetLog(KDPLog::Thread);
   LLDB_LOG(log, "this = {0}, tid = {1:x}", this, GetID());
 }
 
 ThreadKDP::~ThreadKDP() {
-  Log *log = ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD);
+  Log *log = GetLog(KDPLog::Thread);
   LLDB_LOG(log, "this = {0}, tid = {1:x}", this, GetID());
   DestroyThread();
 }


        


More information about the lldb-commits mailing list