aboutsummaryrefslogtreecommitdiff
path: root/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp
blob: 029f76e65a856e1ea1720946e12df2c663aa7369 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//===-- MICmnMIOutOfBandRecord.cpp ------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// Third Party Headers:
#include <assert.h>

// In-house headers:
#include "MICmnMIOutOfBandRecord.h"
#include "MICmnResources.h"

// Instantiations:
static const char *
MapOutOfBandToText(CMICmnMIOutOfBandRecord::OutOfBand_e veType) {
  switch (veType) {
  case CMICmnMIOutOfBandRecord::eOutOfBand_Running:
    return "running";
  case CMICmnMIOutOfBandRecord::eOutOfBand_Stopped:
    return "stopped";
  case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated:
    return "breakpoint-created";
  case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified:
    return "breakpoint-modified";
  case CMICmnMIOutOfBandRecord::eOutOfBand_Thread:
    return ""; // "" Meant to be empty
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded:
    return "thread-group-added";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited:
    return "thread-group-exited";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved:
    return "thread-group-removed";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted:
    return "thread-group-started";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated:
    return "thread-created";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited:
    return "thread-exited";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected:
    return "thread-selected";
  case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded:
    return "library-loaded";
  case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded:
    return "library-unloaded";
  case CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput:
    return "";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ConsoleStreamOutput:
    return "";
  case CMICmnMIOutOfBandRecord::eOutOfBand_LogStreamOutput:
    return "";
  }
  assert(false && "unknown CMICmnMIOutofBandRecord::OutOfBand_e");
  return NULL;
}

static const char *
MapOutOfBandToToken(CMICmnMIOutOfBandRecord::OutOfBand_e veType) {
  switch (veType) {
  case CMICmnMIOutOfBandRecord::eOutOfBand_Running:
    return "*";
  case CMICmnMIOutOfBandRecord::eOutOfBand_Stopped:
    return "*";
  case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_Thread:
    return "@";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded:
    return "=";
  case CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput:
    return "@";
  case CMICmnMIOutOfBandRecord::eOutOfBand_ConsoleStreamOutput:
    return "~";
  case CMICmnMIOutOfBandRecord::eOutOfBand_LogStreamOutput:
    return "&";
  }
  assert(false && "unknown CMICmnMIOutofBandRecord::OutOfBand_e");
  return NULL;
}

//++
//------------------------------------------------------------------------------------
// Details: Build the Out-of-band record's mandatory data part. The part up to
// the first
//          (additional) result i.e. async-record ==>  "*" type.
// Args:    veType      - (R) A MI Out-of-Band enumeration.
// Return:  CMIUtilString - The async record text.
// Throws:  None.
//--
static CMIUtilString
BuildAsyncRecord(CMICmnMIOutOfBandRecord::OutOfBand_e veType) {
  return CMIUtilString::Format("%s%s", MapOutOfBandToToken(veType),
                               MapOutOfBandToText(veType));
}

//++
//------------------------------------------------------------------------------------
// Details: CMICmnMIOutOfBandRecord constructor.
// Type:    Method.
// Args:    None.
// Return:  None.
// Throws:  None.
//--
CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord()
    : m_strAsyncRecord(MIRSRC(IDS_CMD_ERR_EVENT_HANDLED_BUT_NO_ACTION)) {}

//++
//------------------------------------------------------------------------------------
// Details: CMICmnMIOutOfBandRecord constructor.
// Type:    Method.
// Args:    veType      - (R) A MI Out-of-Bound enumeration.
// Return:  None.
// Throws:  None.
//--
CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType)
    : m_strAsyncRecord(BuildAsyncRecord(veType)) {}

//++
//------------------------------------------------------------------------------------
// Details: CMICmnMIOutOfBandRecord constructor.
// Type:    Method.
// Args:    veType      - (R) A MI Out-of-Bound enumeration.
//          vConst      - (R) A MI const object.
// Return:  None.
// Throws:  None.
//--
CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(
    OutOfBand_e veType, const CMICmnMIValueConst &vConst)
    : m_strAsyncRecord(BuildAsyncRecord(veType)) {
  m_strAsyncRecord += vConst.GetString();
}

//++
//------------------------------------------------------------------------------------
// Details: CMICmnMIOutOfBandRecord constructor.
// Type:    Method.
// Args:    veType      - (R) A MI Out-of-Bound enumeration.
//          vResult     - (R) A MI result object.
// Return:  None.
// Throws:  None.
//--
CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(
    OutOfBand_e veType, const CMICmnMIValueResult &vResult)
    : m_strAsyncRecord(BuildAsyncRecord(veType)) {
  Add(vResult);
}

//++
//------------------------------------------------------------------------------------
// Details: CMICmnMIOutOfBandRecord destructor.
// Type:    Overrideable.
// Args:    None.
// Return:  None.
// Throws:  None.
//--
CMICmnMIOutOfBandRecord::~CMICmnMIOutOfBandRecord() {}

//++
//------------------------------------------------------------------------------------
// Details: Return the MI Out-of-band record as a string. The string is a direct
// result of
//          work done on *this Out-of-band record so if not enough data is added
//          then it is
//          possible to return a malformed Out-of-band record. If nothing has
//          been set or
//          added to *this MI Out-of-band record object then text "<Invalid>"
//          will be returned.
// Type:    Method.
// Args:    None.
// Return:  CMIUtilString & - MI output text.
// Throws:  None.
//--
const CMIUtilString &CMICmnMIOutOfBandRecord::GetString() const {
  return m_strAsyncRecord;
}

//++
//------------------------------------------------------------------------------------
// Details: Add to *this Out-of-band record additional information.
// Type:    Method.
// Args:    vResult           - (R) A MI result object.
// Return:  None.
// Throws:  None.
//--
void CMICmnMIOutOfBandRecord::Add(const CMICmnMIValueResult &vResult) {
  m_strAsyncRecord += ",";
  m_strAsyncRecord += vResult.GetString();
}