1 //===-- ProcessLinuxLog.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_ProcessLinuxLog_h_ 11 #define liblldb_ProcessLinuxLog_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 53 static lldb::LogSP 54 GetLogIfAllCategoriesSet(uint32_t mask = 0); 55 56 static void 57 DisableLog (const char **args, lldb_private::Stream *feedback_strm); 58 59 static lldb::LogSP 60 EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, 61 const char **args, lldb_private::Stream *feedback_strm); 62 63 static void 64 ListLogCategories (lldb_private::Stream *strm); 65 66 static void 67 LogIf (uint32_t mask, const char *format, ...); 68 69 // The following functions can be used to enable the client to limit 70 // logging to only the top level function calls. This is useful for 71 // recursive functions. FIXME: not thread safe! 72 // Example: 73 // void NestingFunc() { 74 // LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL)); 75 // if (log) 76 // { 77 // ProcessLinuxLog::IncNestLevel(); 78 // if (ProcessLinuxLog::AtTopNestLevel()) 79 // log->Print(msg); 80 // } 81 // NestingFunc(); 82 // if (log) 83 // ProcessLinuxLog::DecNestLevel(); 84 // } 85 86 static bool 87 AtTopNestLevel() 88 { 89 return m_nestinglevel == 1; 90 } 91 92 static void 93 IncNestLevel() 94 { 95 ++m_nestinglevel; 96 } 97 98 static void 99 DecNestLevel() 100 { 101 --m_nestinglevel; 102 assert(m_nestinglevel >= 0); 103 } 104 }; 105 106 #endif // liblldb_ProcessLinuxLog_h_ 107