blob: 7edd839152e67580356027d3c51d706fa8993030 [file] [log] [blame]
Ed Maste69b76d52013-06-24 14:51:39 +00001//===-- ProcessPOSIXLog.h -----------------------------------------*- C++ -*-===//
Johnny Chen9ed5b492012-01-05 21:48:15 +00002//
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
Ed Maste69b76d52013-06-24 14:51:39 +000010#ifndef liblldb_ProcessPOSIXLog_h_
11#define liblldb_ProcessPOSIXLog_h_
Johnny Chen9ed5b492012-01-05 21:48:15 +000012
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
40class ProcessPOSIXLog
41{
42 static int m_nestinglevel;
43 static const char *m_pluginname;
44
45public:
Robert Flack5f4b6c72015-03-11 21:14:22 +000046 // ---------------------------------------------------------------------
47 // Public Static Methods
48 // ---------------------------------------------------------------------
49 static void
50 Initialize(lldb_private::ConstString name);
51
Johnny Chen9ed5b492012-01-05 21:48:15 +000052 static void
53 RegisterPluginName(const char *pluginName)
54 {
55 m_pluginname = pluginName;
56 }
57
Sylvestre Ledruf8cec0e2013-05-13 09:43:11 +000058 static void
59 RegisterPluginName(lldb_private::ConstString pluginName)
60 {
61 m_pluginname = pluginName.GetCString();
62 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000063
Ashok Thirumurthi01186352013-03-28 16:02:31 +000064 static lldb_private::Log *
Johnny Chen9ed5b492012-01-05 21:48:15 +000065 GetLogIfAllCategoriesSet(uint32_t mask = 0);
66
67 static void
Greg Clayton0c90ef42012-02-21 18:40:07 +000068 DisableLog (const char **args, lldb_private::Stream *feedback_strm);
Johnny Chen9ed5b492012-01-05 21:48:15 +000069
Ashok Thirumurthi01186352013-03-28 16:02:31 +000070 static lldb_private::Log *
Johnny Chen9ed5b492012-01-05 21:48:15 +000071 EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options,
Greg Clayton0c90ef42012-02-21 18:40:07 +000072 const char **args, lldb_private::Stream *feedback_strm);
Johnny Chen9ed5b492012-01-05 21:48:15 +000073
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() {
Ed Maste69b76d52013-06-24 14:51:39 +000085 // LogSP log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL));
Johnny Chen9ed5b492012-01-05 21:48:15 +000086 // if (log)
87 // {
Ed Maste69b76d52013-06-24 14:51:39 +000088 // ProcessPOSIXLog::IncNestLevel();
89 // if (ProcessPOSIXLog::AtTopNestLevel())
Johnny Chen9ed5b492012-01-05 21:48:15 +000090 // log->Print(msg);
91 // }
92 // NestingFunc();
93 // if (log)
Ed Maste69b76d52013-06-24 14:51:39 +000094 // ProcessPOSIXLog::DecNestLevel();
Johnny Chen9ed5b492012-01-05 21:48:15 +000095 // }
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
Ed Maste69b76d52013-06-24 14:51:39 +0000117#endif // liblldb_ProcessPOSIXLog_h_