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 // --------------------------------------------------------------------- 47 // Public Static Methods 48 // --------------------------------------------------------------------- 49 static void 50 Initialize(lldb_private::ConstString name); 51 52 static void 53 RegisterPluginName(const char *pluginName) 54 { 55 m_pluginname = pluginName; 56 } 57 58 static void 59 RegisterPluginName(lldb_private::ConstString pluginName) 60 { 61 m_pluginname = pluginName.GetCString(); 62 } 63 64 static lldb_private::Log * 65 GetLogIfAllCategoriesSet(uint32_t mask = 0); 66 67 static void 68 DisableLog (const char **args, lldb_private::Stream *feedback_strm); 69 70 static lldb_private::Log * 71 EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, 72 const char **args, lldb_private::Stream *feedback_strm); 73 74 static void 75 ListLogCategories (lldb_private::Stream *strm); 76 77 static void 78 LogIf (uint32_t mask, const char *format, ...); 79 80 // The following functions can be used to enable the client to limit 81 // logging to only the top level function calls. This is useful for 82 // recursive functions. FIXME: not thread safe! 83 // Example: 84 // void NestingFunc() { 85 // LogSP log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL)); 86 // if (log) 87 // { 88 // ProcessPOSIXLog::IncNestLevel(); 89 // if (ProcessPOSIXLog::AtTopNestLevel()) 90 // log->Print(msg); 91 // } 92 // NestingFunc(); 93 // if (log) 94 // ProcessPOSIXLog::DecNestLevel(); 95 // } 96 97 static bool 98 AtTopNestLevel() 99 { 100 return m_nestinglevel == 1; 101 } 102 103 static void 104 IncNestLevel() 105 { 106 ++m_nestinglevel; 107 } 108 109 static void 110 DecNestLevel() 111 { 112 --m_nestinglevel; 113 assert(m_nestinglevel >= 0); 114 } 115 }; 116 117 #endif // liblldb_ProcessPOSIXLog_h_ 118