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