]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnBase.cpp
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[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
65 CMICmnBase::HaveErrorDescription(void) const
66 {
67     return m_strMILastErrorDescription.empty();
68 }
69
70 //++ ------------------------------------------------------------------------------------
71 // Details: Retrieve MI's last error condition.
72 // Type:    Method.
73 // Args:    None.
74 // Return:  CMIUtilString & - Text description.
75 // Throws:  None.
76 //--
77 const CMIUtilString &
78 CMICmnBase::GetErrorDescription(void) const
79 {
80     return m_strMILastErrorDescription;
81 }
82
83 //++ ------------------------------------------------------------------------------------
84 // Details: Set MI's error condition description. This may be accessed by clients and
85 //          seen by users.  Message is available to the client using the server and sent
86 //          to the Logger.
87 // Type:    Method.
88 // Args:    vrTxt   - (R) Text description.
89 // Return:  None.
90 // Throws:  None.
91 //--
92 void
93 CMICmnBase::SetErrorDescription(const CMIUtilString &vrTxt) const
94 {
95     m_strMILastErrorDescription = vrTxt;
96     if (!vrTxt.empty())
97     {
98         const CMIUtilString txt(CMIUtilString::Format("Error: %s", vrTxt.c_str()));
99         CMICmnStreamStderr::Instance().Write(txt);
100     }
101 }
102
103 //++ ------------------------------------------------------------------------------------
104 // Details: Set MI's error condition description. This may be accessed by clients and
105 //          seen by users.  Message is available to the client using the server and sent
106 //          to the Logger.
107 // Type:    Method.
108 // Args:    vrTxt   - (R) Text description.
109 // Return:  None.
110 // Throws:  None.
111 //--
112 void
113 CMICmnBase::SetErrorDescriptionNoLog(const CMIUtilString &vrTxt) const
114 {
115     m_strMILastErrorDescription = vrTxt;
116 }
117
118 //++ ------------------------------------------------------------------------------------
119 // Details: Clear MI's error condition description.
120 // Type:    Method.
121 // Args:    None.
122 // Return:  None.
123 // Throws:  None.
124 //--
125 void
126 CMICmnBase::ClrErrorDescription(void) const
127 {
128     m_strMILastErrorDescription.clear();
129 }
130
131 //++ ------------------------------------------------------------------------------------
132 // Details: Set MI's error condition description. This may be accessed by clients and
133 //          seen by users. Message is available to the client using the server and sent
134 //          to the Logger.
135 // Type:    Method.
136 // Args:    vFormat - (R) Format string.
137 //          ...     - (R) Variable number of CMIUtilString type objects.
138 // Return:  None.
139 // Throws:  None.
140 //--
141 void
142 CMICmnBase::SetErrorDescriptionn(const CMIUtilString vFormat, ...) const
143 {
144     va_list args;
145     va_start(args, vFormat);
146     CMIUtilString strResult = CMIUtilString::FormatValist(vFormat, args);
147     va_end(args);
148
149     SetErrorDescription(strResult);
150 }