]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnLog.h
Update lldb to upstream trunk r242221.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnLog.h
1 //===-- MICmnLog.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 #pragma once
11
12 // Third party headers:
13 #include <map>
14
15 // In-house headers:
16 #include "MIUtilString.h"
17 #include "MICmnBase.h"
18 #include "MIUtilSingletonBase.h"
19
20 //++ ============================================================================
21 // Details: MI common code implementation class. Handle application trace
22 //          activity logging. Medium objects derived from the Medium abstract
23 ///          class are registered with this logger. The function Write is called
24 //          by a client callee to log information. That information is given to
25 //          registered relevant mediums. The medium file is registered during
26 //          *this logs initialization so it will always have a file log for the
27 //          application.
28 //          Singleton class.
29 // Gotchas: None.
30 // Authors: Illya Rudkin 01/02/2012.
31 // Changes: None.
32 //--
33 class CMICmnLog : public MI::ISingleton<CMICmnLog>
34 {
35     friend MI::ISingleton<CMICmnLog>;
36
37     // Enumeration:
38   public:
39     //++
40     // Description: Data given to the Logger can be of several types. The Logger can be
41     //              set at levels of verbosity. Can determine how data is sent to one or
42     //              mediums.
43     //--
44     enum ELogVerbosity
45     {                                         // Descriptions of what 'may' occur, depends ultimately on the medium itself. See the medium.
46         eLogVerbosity_FnTrace = 0x00000004,   // Debug function stack call tracing
47         eLogVerbosity_DbgOp = 0x00000008,     // Send a string to the debugger for display (not implemented)
48         eLogVerbosity_ClientMsg = 0x00000010, // A client using MI can insert messages into the log (not implemented)
49         eLogVerbosity_Log = 0x00000020        // Send to only the Log file.
50     };
51
52     // Class:
53   public:
54     //++
55     // Description: Register a medium derived from this interface which will be
56     //              called writing log trace data i.e. a file or a console.
57     //              Medium objects registered are not owned by *this logger.
58     //--
59     class IMedium
60     {
61       public:
62         virtual bool Initialize(void) = 0;
63         virtual const CMIUtilString &GetName(void) const = 0;
64         virtual bool Write(const CMIUtilString &vData, const ELogVerbosity veType) = 0;
65         virtual const CMIUtilString &GetError(void) const = 0;
66         virtual bool Shutdown(void) = 0;
67
68         // Not part of the interface, ignore
69         // AD:  This virtual destructor seems to hit a bug in the stdlib
70         //      where vector delete is incorrectly called.  Workaround is
71         //      to comment this out while I investigate.
72         /* dtor */ virtual ~IMedium(void) {}
73     };
74
75     // Statics:
76   public:
77     static bool WriteLog(const CMIUtilString &vData);
78
79     // Methods:
80   public:
81     bool RegisterMedium(const IMedium &vrMedium);
82     bool UnregisterMedium(const IMedium &vrMedium);
83     bool Write(const CMIUtilString &vData, const ELogVerbosity veType);
84     bool SetEnabled(const bool vbYes);
85     bool GetEnabled(void) const;
86
87     // MI common object handling - duplicate of CMICmnBase functions, necessary for LINUX build
88     // Done to stop locking on object construction init circular dependency.
89     const CMIUtilString &GetErrorDescription(void) const;
90     void SetErrorDescription(const CMIUtilString &vrTxt) const;
91     void ClrErrorDescription(void) const;
92
93     // Overridden:
94   public:
95     // From MI::ISingleton
96     bool Initialize(void) override;
97     bool Shutdown(void) override;
98
99     // Methods:
100   private:
101     /* ctor */ CMICmnLog(void);
102     /* ctor */ CMICmnLog(const CMICmnLog &);
103     void operator=(const CMICmnLog &);
104
105     // Overridden:
106   private:
107     // From CMICmnBase
108     /* dtor */ ~CMICmnLog(void) override;
109
110     // Typedef:
111   private:
112     typedef std::map<IMedium *, CMIUtilString> MapMediumToName_t;
113     typedef std::pair<IMedium *, CMIUtilString> MapPairMediumToName_t;
114
115     // Methods:
116   private:
117     bool HaveMediumAlready(const IMedium &vrMedium) const;
118     bool UnregisterMediumAll(void);
119
120     // Attributes:
121   private:
122     bool m_bRecursiveDive; // True = yes recursive, false = no
123     MapMediumToName_t m_mapMediumToName;
124     bool m_bEnabled;         // True = Logger enabled for writing to mediums, false = medium not written to
125     bool m_bInitializingATM; // True = Yes in process of initing *this logger, false = not initing
126     //
127     // MI common object handling - duplicate of CMICmnBase functions, necessary for LINUX build
128     bool m_bInitialized; // True = yes successfully initialized, false = no yet or failed
129     mutable CMIUtilString m_strMILastErrorDescription;
130     MIint m_clientUsageRefCnt; // Count of client using *this object so not shutdown() object to early
131 };