1 /*
2 * \file ocsd_error.cpp
3 * \brief OpenCSD : Library error class.
4 *
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
6 */
7
8
9 /*
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the copyright holder nor the names of its contributors
21 * may be used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include "common/ocsd_error.h"
37 #include <sstream>
38 #include <iomanip>
39
40 static const char *s_errorCodeDescs[][2] = {
41 /* general return errors */
42 {"OCSD_OK", "No Error."},
43 {"OCSD_ERR_FAIL","General failure."},
44 {"OCSD_ERR_MEM","Internal memory allocation error."},
45 {"OCSD_ERR_NOT_INIT","Component not initialised."},
46 {"OCSD_ERR_INVALID_ID","Invalid CoreSight Trace Source ID."},
47 {"OCSD_ERR_BAD_HANDLE","Invalid handle passed to component."},
48 {"OCSD_ERR_INVALID_PARAM_VAL","Invalid value parameter passed to component."},
49 {"OCSD_ERR_INVALID_PARAM_TYPE","Type mismatch on abstract interface."},
50 {"OCSD_ERR_FILE_ERROR","File access error"},
51 {"OCSD_ERR_NO_PROTOCOL","Trace protocol unsupported"},
52 /* attachment point errors */
53 {"OCSD_ERR_ATTACH_TOO_MANY","Cannot attach - attach device limit reached."},
54 {"OCSD_ERR_ATTACH_INVALID_PARAM"," Cannot attach - invalid parameter."},
55 {"OCSD_ERR_ATTACH_COMP_NOT_FOUND","Cannot detach - component not found."},
56 /* source reader errors */
57 {"OCSD_ERR_RDR_FILE_NOT_FOUND","source reader - file not found."},
58 {"OCSD_ERR_RDR_INVALID_INIT", "source reader - invalid initialisation parameter."},
59 {"OCSD_ERR_RDR_NO_DECODER", "source reader - not trace decoder set."},
60 /* data path errors */
61 {"OCSD_ERR_DATA_DECODE_FATAL", "A decoder in the data path has returned a fatal error."},
62 /* frame deformatter errors */
63 {"OCSD_ERR_DFMTR_NOTCONTTRACE", "Trace input to deformatter none-continuous"},
64 {"OCSD_ERR_DFMTR_BAD_FHSYNC", "Bad frame or half frame sync in trace deformatter"},
65 /* packet processor errors - protocol issues etc */
66 {"OCSD_ERR_BAD_PACKET_SEQ","Bad packet sequence"},
67 {"OCSD_ERR_INVALID_PCKT_HDR","Invalid packet header"},
68 {"OCSD_ERR_PKT_INTERP_FAIL","Interpreter failed - cannot recover - bad data or sequence"},
69 /* packet decoder errors */
70 {"OCSD_ERR_UNSUPPORTED_ISA","ISA not supported in decoder"},
71 {"OCSD_ERR_HW_CFG_UNSUPP","Programmed trace configuration not supported by decodUer."},
72 {"OCSD_ERR_UNSUPP_DECODE_PKT","Packet not supported in decoder"},
73 {"OCSD_ERR_BAD_DECODE_PKT","Reserved or unknown packet in decoder."},
74 {"OCSD_ERR_COMMIT_PKT_OVERRUN","Overrun in commit packet stack - tried to commit more than available"},
75 {"OCSD_ERR_MEM_NACC","Unable to access required memory address."},
76 {"OCSD_ERR_RET_STACK_OVERFLOW","Internal return stack overflow checks failed - popped more than we pushed."},
77 /* decode tree errors */
78 {"OCSD_ERR_DCDT_NO_FORMATTER","No formatter in use - operation not valid."},
79 /* target memory access errors */
80 {"OCSD_ERR_MEM_ACC_OVERLAP","Attempted to set an overlapping range in memory access map."},
81 {"OCSD_ERR_MEM_ACC_FILE_NOT_FOUND","Memory access file could not be opened."},
82 {"OCSD_ERR_MEM_ACC_FILE_DIFF_RANGE","Attempt to re-use the same memory access file for a different address range."},
83 {"OCSD_ERR_MEM_ACC_BAD_LEN","Memory accessor returned a bad read length value (larger than requested."},
84 {"OCSD_ERR_MEM_ACC_RANGE_INVALID","Address range in accessor set to invalid values."},
85 /* test errors - errors generated only by the test code, not the library */
86 {"OCSD_ERR_TEST_SNAPSHOT_PARSE", "Test snapshot file parse error"},
87 {"OCSD_ERR_TEST_SNAPSHOT_PARSE_INFO", "Test snapshot file parse information"},
88 {"OCSD_ERR_TEST_SNAPSHOT_READ","test snapshot reader error"},
89 {"OCSD_ERR_TEST_SS_TO_DECODER","test snapshot to decode tree conversion error"},
90 /* decoder registration */
91 {"OCSD_ERR_DCDREG_NAME_REPEAT","Attempted to register a decoder with the same name as another one."},
92 {"OCSD_ERR_DCDREG_NAME_UNKNOWN","Attempted to find a decoder with a name that is not known in the library."},
93 {"OCSD_ERR_DCDREG_TYPE_UNKNOWN","Attempted to find a decoder with a type that is not known in the library."},
94 /* decoder config */
95 {"OCSD_ERR_DCD_INTERFACE_UNUSED","Attempt to connect or use and interface not supported by this decoder."},
96 /* end marker*/
97 {"OCSD_ERR_LAST", "No error - error code end marker"}
98 };
99
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code)100 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code) :
101 m_error_code(code),
102 m_sev(sev_type),
103 m_idx(OCSD_BAD_TRC_INDEX),
104 m_chan_ID(OCSD_BAD_CS_SRC_ID)
105 {
106 }
107
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx)108 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx) :
109 m_error_code(code),
110 m_sev(sev_type),
111 m_idx(idx),
112 m_chan_ID(OCSD_BAD_CS_SRC_ID)
113 {
114 }
115
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx,const uint8_t chan_id)116 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx, const uint8_t chan_id) :
117 m_error_code(code),
118 m_sev(sev_type),
119 m_idx(idx),
120 m_chan_ID(chan_id)
121 {
122 }
123
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const std::string & msg)124 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const std::string &msg) :
125 m_error_code(code),
126 m_sev(sev_type),
127 m_idx(OCSD_BAD_TRC_INDEX),
128 m_chan_ID(OCSD_BAD_CS_SRC_ID),
129 m_err_message(msg)
130 {
131 }
132
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx,const std::string & msg)133 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx, const std::string &msg) :
134 m_error_code(code),
135 m_sev(sev_type),
136 m_idx(idx),
137 m_chan_ID(OCSD_BAD_CS_SRC_ID),
138 m_err_message(msg)
139 {
140 }
141
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx,const uint8_t chan_id,const std::string & msg)142 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx, const uint8_t chan_id, const std::string &msg) :
143 m_error_code(code),
144 m_sev(sev_type),
145 m_idx(idx),
146 m_chan_ID(chan_id),
147 m_err_message(msg)
148 {
149 }
150
151
ocsdError(const ocsdError * pError)152 ocsdError::ocsdError(const ocsdError *pError) :
153 m_error_code(pError->getErrorCode()),
154 m_sev(pError->getErrorSeverity()),
155 m_idx(pError->getErrorIndex()),
156 m_chan_ID(pError->getErrorChanID())
157 {
158 setMessage(pError->getMessage());
159 }
160
ocsdError(const ocsdError & Error)161 ocsdError::ocsdError(const ocsdError &Error) :
162 m_error_code(Error.getErrorCode()),
163 m_sev(Error.getErrorSeverity()),
164 m_idx(Error.getErrorIndex()),
165 m_chan_ID(Error.getErrorChanID())
166 {
167 setMessage(Error.getMessage());
168 }
169
ocsdError()170 ocsdError::ocsdError():
171 m_error_code(OCSD_ERR_LAST),
172 m_sev(OCSD_ERR_SEV_NONE),
173 m_idx(OCSD_BAD_TRC_INDEX),
174 m_chan_ID(OCSD_BAD_CS_SRC_ID)
175 {
176 }
177
~ocsdError()178 ocsdError::~ocsdError()
179 {
180 }
181
getErrorString(const ocsdError & error)182 const std::string ocsdError::getErrorString(const ocsdError &error)
183 {
184 std::string szErrStr = "LIBRARY INTERNAL ERROR: Invalid Error Object";
185 const char *sev_type_sz[] = {
186 "NONE ",
187 "ERROR:",
188 "WARN :",
189 "INFO :"
190 };
191
192 switch(error.getErrorSeverity())
193 {
194 default:
195 case OCSD_ERR_SEV_NONE:
196 break;
197
198 case OCSD_ERR_SEV_ERROR:
199 case OCSD_ERR_SEV_WARN:
200 case OCSD_ERR_SEV_INFO:
201 szErrStr = sev_type_sz[(int)error.getErrorSeverity()];
202 appendErrorDetails(szErrStr,error);
203 break;
204 }
205 return szErrStr;
206 }
207
appendErrorDetails(std::string & errStr,const ocsdError & error)208 void ocsdError::appendErrorDetails(std::string &errStr, const ocsdError &error)
209 {
210 int numerrstr = sizeof(s_errorCodeDescs) / sizeof(s_errorCodeDescs[0]);
211 int code = (int)error.getErrorCode();
212 ocsd_trc_index_t idx = error.getErrorIndex();
213 uint8_t chan_ID = error.getErrorChanID();
214 std::ostringstream oss;
215
216 oss << "0x" << std::hex << std::setfill('0') << std::setw(4) << code;
217 if(code < numerrstr)
218 oss << " (" << s_errorCodeDescs[code][0] << ") [" << s_errorCodeDescs[code][1] << "]; ";
219 else
220 oss << " (unknown); ";
221
222 if(idx != OCSD_BAD_TRC_INDEX)
223 oss << "TrcIdx=" << std::dec << idx << "; ";
224
225 if(chan_ID != OCSD_BAD_CS_SRC_ID)
226 oss << "CS ID=" << std::hex << std::setfill('0') << std::setw(2) << (uint16_t)chan_ID << "; ";
227
228 oss << error.getMessage();
229 errStr = oss.str();
230 }
231
232
getStr()233 const char* ocsdDataRespStr::getStr()
234 {
235 static const char* szRespStr[] = {
236 "OCSD_RESP_CONT: Continue processing.",
237 "OCSD_RESP_WARN_CONT: Continue processing -> a component logged a warning.",
238 "OCSD_RESP_ERR_CONT: Continue processing -> a component logged an error.",
239 "OCSD_RESP_WAIT: Pause processing",
240 "OCSD_RESP_WARN_WAIT: Pause processing -> a component logged a warning.",
241 "OCSD_RESP_ERR_WAIT: Pause processing -> a component logged an error.",
242 "OCSD_RESP_FATAL_NOT_INIT: Processing Fatal Error : component unintialised.",
243 "OCSD_RESP_FATAL_INVALID_OP: Processing Fatal Error : invalid data path operation.",
244 "OCSD_RESP_FATAL_INVALID_PARAM: Processing Fatal Error : invalid parameter in datapath call.",
245 "OCSD_RESP_FATAL_INVALID_DATA: Processing Fatal Error : invalid trace data.",
246 "OCSD_RESP_FATAL_SYS_ERR: Processing Fatal Error : internal system error."
247 };
248 if ((m_type < OCSD_RESP_CONT) || (m_type > OCSD_RESP_FATAL_SYS_ERR))
249 return "Unknown OCSD_RESP type.";
250 return szRespStr[m_type];
251 }
252
253 /* End of File ocsd_error.cpp */
254