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