Home | History | Annotate | Download | only in POSIX
      1 //===-- ProcessPOSIXLog.h -----------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef liblldb_ProcessPOSIXLog_h_
     11 #define liblldb_ProcessPOSIXLog_h_
     12 
     13 // C Includes
     14 // C++ Includes
     15 // Other libraries and framework includes
     16 
     17 // Project includes
     18 #include "lldb/Core/Log.h"
     19 
     20 #define POSIX_LOG_VERBOSE                  (1u << 0)
     21 #define POSIX_LOG_PROCESS                  (1u << 1)
     22 #define POSIX_LOG_THREAD                   (1u << 2)
     23 #define POSIX_LOG_PACKETS                  (1u << 3)
     24 #define POSIX_LOG_MEMORY                   (1u << 4)    // Log memory reads/writes calls
     25 #define POSIX_LOG_MEMORY_DATA_SHORT        (1u << 5)    // Log short memory reads/writes bytes
     26 #define POSIX_LOG_MEMORY_DATA_LONG         (1u << 6)    // Log all memory reads/writes bytes
     27 #define POSIX_LOG_BREAKPOINTS              (1u << 7)
     28 #define POSIX_LOG_WATCHPOINTS              (1u << 8)
     29 #define POSIX_LOG_STEP                     (1u << 9)
     30 #define POSIX_LOG_COMM                     (1u << 10)
     31 #define POSIX_LOG_ASYNC                    (1u << 11)
     32 #define POSIX_LOG_PTRACE                   (1u << 12)
     33 #define POSIX_LOG_REGISTERS                (1u << 13)
     34 #define POSIX_LOG_ALL                      (UINT32_MAX)
     35 #define POSIX_LOG_DEFAULT                  POSIX_LOG_PACKETS
     36 
     37 // The size which determines "short memory reads/writes".
     38 #define POSIX_LOG_MEMORY_SHORT_BYTES       (4 * sizeof(ptrdiff_t))
     39 
     40 class ProcessPOSIXLog
     41 {
     42     static int m_nestinglevel;
     43     static const char *m_pluginname;
     44 
     45 public:
     46     static void
     47     RegisterPluginName(const char *pluginName)
     48     {
     49         m_pluginname = pluginName;
     50     }
     51 
     52     static void
     53     RegisterPluginName(lldb_private::ConstString pluginName)
     54         {
     55             m_pluginname = pluginName.GetCString();
     56         }
     57 
     58     static lldb_private::Log *
     59     GetLogIfAllCategoriesSet(uint32_t mask = 0);
     60 
     61     static void
     62     DisableLog (const char **args, lldb_private::Stream *feedback_strm);
     63 
     64     static lldb_private::Log *
     65     EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options,
     66                const char **args, lldb_private::Stream *feedback_strm);
     67 
     68     static void
     69     ListLogCategories (lldb_private::Stream *strm);
     70 
     71     static void
     72     LogIf (uint32_t mask, const char *format, ...);
     73 
     74     // The following functions can be used to enable the client to limit
     75     // logging to only the top level function calls.  This is useful for
     76     // recursive functions.  FIXME: not thread safe!
     77     //     Example:
     78     //     void NestingFunc() {
     79     //         LogSP log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL));
     80     //         if (log)
     81     //         {
     82     //             ProcessPOSIXLog::IncNestLevel();
     83     //             if (ProcessPOSIXLog::AtTopNestLevel())
     84     //                 log->Print(msg);
     85     //         }
     86     //         NestingFunc();
     87     //         if (log)
     88     //             ProcessPOSIXLog::DecNestLevel();
     89     //     }
     90 
     91     static bool
     92     AtTopNestLevel()
     93     {
     94         return m_nestinglevel == 1;
     95     }
     96 
     97     static void
     98     IncNestLevel()
     99     {
    100         ++m_nestinglevel;
    101     }
    102 
    103     static void
    104     DecNestLevel()
    105     {
    106         --m_nestinglevel;
    107         assert(m_nestinglevel >= 0);
    108     }
    109 };
    110 
    111 #endif  // liblldb_ProcessPOSIXLog_h_
    112