]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp
MFV r308392: file 5.29.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnMIOutOfBandRecord.cpp
1 //===-- MICmnMIOutOfBandRecord.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 // Third Party Headers:
11 #include <assert.h>
12
13 // In-house headers:
14 #include "MICmnMIOutOfBandRecord.h"
15 #include "MICmnResources.h"
16
17 // Instantiations:
18 static const char *
19 MapOutOfBandToText(CMICmnMIOutOfBandRecord::OutOfBand_e veType)
20 {
21     switch (veType)
22     {
23         case CMICmnMIOutOfBandRecord::eOutOfBand_Running:
24             return "running";
25         case CMICmnMIOutOfBandRecord::eOutOfBand_Stopped:
26             return "stopped";
27         case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated:
28             return "breakpoint-created";
29         case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified:
30             return "breakpoint-modified";
31         case CMICmnMIOutOfBandRecord::eOutOfBand_Thread:
32             return ""; // "" Meant to be empty
33         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded:
34             return "thread-group-added";
35         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited:
36             return "thread-group-exited";
37         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved:
38             return "thread-group-removed";
39         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted:
40             return "thread-group-started";
41         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated:
42             return "thread-created";
43         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited:
44             return "thread-exited";
45         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected:
46             return "thread-selected";
47         case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded:
48             return "library-loaded";
49         case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded:
50             return "library-unloaded";
51         case CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput:
52             return "";
53     }
54     assert(false && "unknown CMICmnMIOutofBandRecord::OutOfBand_e");
55     return NULL;
56 }
57
58 static const char *
59 MapOutOfBandToToken(CMICmnMIOutOfBandRecord::OutOfBand_e veType)
60 {
61     switch (veType)
62     {
63         case CMICmnMIOutOfBandRecord::eOutOfBand_Running:
64             return "*";
65         case CMICmnMIOutOfBandRecord::eOutOfBand_Stopped:
66             return "*";
67         case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated:
68             return "=";
69         case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified:
70             return "=";
71         case CMICmnMIOutOfBandRecord::eOutOfBand_Thread:
72             return "@";
73         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded:
74             return "=";
75         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited:
76             return "=";
77         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved:
78             return "=";
79         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted:
80             return "=";
81         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated:
82             return "=";
83         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited:
84             return "=";
85         case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected:
86             return "=";
87         case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded:
88             return "=";
89         case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded:
90             return "=";
91         case CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput:
92             return "@";
93     }
94     assert(false && "unknown CMICmnMIOutofBandRecord::OutOfBand_e");
95     return NULL;
96 }
97
98 //++ ------------------------------------------------------------------------------------
99 // Details: Build the Out-of-band record's mandatory data part. The part up to the first
100 //          (additional) result i.e. async-record ==>  "*" type.
101 // Args:    veType      - (R) A MI Out-of-Band enumeration.
102 // Return:  CMIUtilString - The async record text.
103 // Throws:  None.
104 //--
105 static CMIUtilString
106 BuildAsyncRecord(CMICmnMIOutOfBandRecord::OutOfBand_e veType)
107 {
108     return CMIUtilString::Format("%s%s", MapOutOfBandToToken(veType), MapOutOfBandToText(veType));
109 }
110
111 //++ ------------------------------------------------------------------------------------
112 // Details: CMICmnMIOutOfBandRecord constructor.
113 // Type:    Method.
114 // Args:    None.
115 // Return:  None.
116 // Throws:  None.
117 //--
118 CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord()
119     : m_strAsyncRecord(MIRSRC(IDS_CMD_ERR_EVENT_HANDLED_BUT_NO_ACTION))
120 {
121 }
122
123 //++ ------------------------------------------------------------------------------------
124 // Details: CMICmnMIOutOfBandRecord constructor.
125 // Type:    Method.
126 // Args:    veType      - (R) A MI Out-of-Bound enumeration.
127 // Return:  None.
128 // Throws:  None.
129 //--
130 CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType)
131     : m_strAsyncRecord(BuildAsyncRecord(veType))
132 {
133 }
134
135 //++ ------------------------------------------------------------------------------------
136 // Details: CMICmnMIOutOfBandRecord constructor.
137 // Type:    Method.
138 // Args:    veType      - (R) A MI Out-of-Bound enumeration.
139 //          vConst      - (R) A MI const object.
140 // Return:  None.
141 // Throws:  None.
142 //--
143 CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType, const CMICmnMIValueConst &vConst)
144     : m_strAsyncRecord(BuildAsyncRecord(veType))
145 {
146     m_strAsyncRecord += vConst.GetString();
147 }
148
149 //++ ------------------------------------------------------------------------------------
150 // Details: CMICmnMIOutOfBandRecord constructor.
151 // Type:    Method.
152 // Args:    veType      - (R) A MI Out-of-Bound enumeration.
153 //          vResult     - (R) A MI result object.
154 // Return:  None.
155 // Throws:  None.
156 //--
157 CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType, const CMICmnMIValueResult &vResult)
158     : m_strAsyncRecord(BuildAsyncRecord(veType))
159 {
160     Add(vResult);
161 }
162
163 //++ ------------------------------------------------------------------------------------
164 // Details: CMICmnMIOutOfBandRecord destructor.
165 // Type:    Overrideable.
166 // Args:    None.
167 // Return:  None.
168 // Throws:  None.
169 //--
170 CMICmnMIOutOfBandRecord::~CMICmnMIOutOfBandRecord()
171 {
172 }
173
174 //++ ------------------------------------------------------------------------------------
175 // Details: Return the MI Out-of-band record as a string. The string is a direct result of
176 //          work done on *this Out-of-band record so if not enough data is added then it is
177 //          possible to return a malformed Out-of-band record. If nothing has been set or
178 //          added to *this MI Out-of-band record object then text "<Invalid>" will be returned.
179 // Type:    Method.
180 // Args:    None.
181 // Return:  CMIUtilString & - MI output text.
182 // Throws:  None.
183 //--
184 const CMIUtilString &
185 CMICmnMIOutOfBandRecord::GetString() const
186 {
187     return m_strAsyncRecord;
188 }
189
190 //++ ------------------------------------------------------------------------------------
191 // Details: Add to *this Out-of-band record additional information.
192 // Type:    Method.
193 // Args:    vResult           - (R) A MI result object.
194 // Return:  None.
195 // Throws:  None.
196 //--
197 void
198 CMICmnMIOutOfBandRecord::Add(const CMICmnMIValueResult &vResult)
199 {
200     m_strAsyncRecord += ",";
201     m_strAsyncRecord += vResult.GetString();
202 }