]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnBase.cpp
Merge ^/head r274961 through r276418.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnBase.cpp
1 //===-- MICmnBase.cpp -------------------------------------------*- 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 //++
11 // File:                MICmnBase.cpp
12 //
13 // Overview:    CMICmnBase implementation.
14 //
15 // Environment: Compilers:      Visual C++ 12.
16 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //                              Libraries:      See MIReadmetxt. 
18 //
19 // Copyright:   None.
20 //--
21
22 // Third party headers
23 #include <stdarg.h>             // va_list, va_start, var_end
24
25 // In-house headers:
26 #include "MICmnBase.h"
27 #include "MICmnLog.h"
28 #include "MICmnStreamStderr.h"
29
30 //++ ------------------------------------------------------------------------------------
31 // Details:     CMICmnBase constructor.
32 // Type:        Method.
33 // Args:        None.
34 // Return:      None.
35 // Throws:      None.
36 //--
37 CMICmnBase::CMICmnBase( void )
38 :       m_strMILastErrorDescription( CMIUtilString() )
39 ,       m_bInitialized( false )
40 ,       m_pLog( &CMICmnLog::Instance() )
41 ,       m_clientUsageRefCnt( 0 )
42 {
43 }
44
45 //++ ------------------------------------------------------------------------------------
46 // Details:     CMICmnBase destructor.
47 // Type:        Overrideable.
48 // Args:        None.
49 // Return:      None.
50 // Throws:      None.
51 //--
52 CMICmnBase::~CMICmnBase( void )
53 {
54         m_pLog = NULL;
55 }
56
57 //++ ------------------------------------------------------------------------------------
58 // Details:     Retrieve whether *this object has an error description set.
59 // Type:        Method.
60 // Args:        None.
61 // Return:      bool    - True = Yes already defined, false = empty discription.
62 // Throws:      None.
63 //--
64 bool CMICmnBase::HaveErrorDescription( void ) const
65 {
66         return m_strMILastErrorDescription.empty();
67 }
68         
69 //++ ------------------------------------------------------------------------------------
70 // Details:     Retrieve MI's last error condition.
71 // Type:        Method.
72 // Args:        None.
73 // Return:      CMIUtilString & - Text description.
74 // Throws:      None.
75 //--
76 const CMIUtilString & CMICmnBase::GetErrorDescription( void ) const
77 {
78         return m_strMILastErrorDescription;
79 }
80         
81 //++ ------------------------------------------------------------------------------------
82 // Details:     Set MI's error condition description. This may be accessed by clients and
83 //                      seen by users.  Message is available to the client using the server and sent
84 //                      to the Logger.
85 // Type:        Method.
86 // Args:        vrTxt   - (R) Text description.
87 // Return:      None.
88 // Throws:      None.
89 //--
90 void CMICmnBase::SetErrorDescription( const CMIUtilString & vrTxt ) const
91 {
92         m_strMILastErrorDescription = vrTxt;
93         if( !vrTxt.empty() )
94         {
95                 const CMIUtilString txt( CMIUtilString::Format( "Error: %s", vrTxt.c_str() ) );
96                 CMICmnStreamStderr::Instance().Write( txt );
97         }
98 }
99
100 //++ ------------------------------------------------------------------------------------
101 // Details:     Set MI's error condition description. This may be accessed by clients and
102 //                      seen by users.  Message is available to the client using the server and sent
103 //                      to the Logger.
104 // Type:        Method.
105 // Args:        vrTxt   - (R) Text description.
106 // Return:      None.
107 // Throws:      None.
108 //--
109 void CMICmnBase::SetErrorDescriptionNoLog( const CMIUtilString & vrTxt ) const
110 {
111         m_strMILastErrorDescription = vrTxt;
112 }
113         
114 //++ ------------------------------------------------------------------------------------
115 // Details:     Clear MI's error condition description.
116 // Type:        Method.
117 // Args:        None.
118 // Return:      None.
119 // Throws:      None.
120 //--
121 void CMICmnBase::ClrErrorDescription( void ) const
122 {
123         m_strMILastErrorDescription.clear();
124 }
125
126 //++ ------------------------------------------------------------------------------------
127 // Details:     Set MI's error condition description. This may be accessed by clients and
128 //                      seen by users. Message is available to the client using the server and sent
129 //                      to the Logger.
130 // Type:        Method.
131 // Args:        vrFormat        - (R) Format string.
132 //                      ...                     - (R) Variable number of CMIUtilString type objects.
133 // Return:      None.
134 // Throws:      None.
135 //--
136 void CMICmnBase::SetErrorDescriptionn( const CMIUtilString & vrFormat, ... ) const
137 {
138         va_list args;
139         va_start( args, vrFormat );
140         CMIUtilString strResult = CMIUtilString::FormatValist( vrFormat, args );
141         va_end( args );
142
143         SetErrorDescription( strResult );
144 }