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