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