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 {"OCSD_ERR_DCDREG_TOOMANY","Attempted to register too many custom decoders"},
95 /* decoder config */
96 {"OCSD_ERR_DCD_INTERFACE_UNUSED","Attempt to connect or use and interface not supported by this decoder."},
97 /* additional errors */
98 {"OCSD_ERR_INVALID_OPCODE","Illegal Opode found while decoding program memory."},
99 {"OCSD_ERR_I_RANGE_LIMIT_OVERRUN","An optional limit on consecutive instructions in range during decode has been exceeded."},
100 /* end marker*/
101 {"OCSD_ERR_LAST", "No error - error code end marker"}
102 };
103
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code)104 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code) :
105 m_error_code(code),
106 m_sev(sev_type),
107 m_idx(OCSD_BAD_TRC_INDEX),
108 m_chan_ID(OCSD_BAD_CS_SRC_ID)
109 {
110 }
111
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx)112 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx) :
113 m_error_code(code),
114 m_sev(sev_type),
115 m_idx(idx),
116 m_chan_ID(OCSD_BAD_CS_SRC_ID)
117 {
118 }
119
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx,const uint8_t chan_id)120 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) :
121 m_error_code(code),
122 m_sev(sev_type),
123 m_idx(idx),
124 m_chan_ID(chan_id)
125 {
126 }
127
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const std::string & msg)128 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const std::string &msg) :
129 m_error_code(code),
130 m_sev(sev_type),
131 m_idx(OCSD_BAD_TRC_INDEX),
132 m_chan_ID(OCSD_BAD_CS_SRC_ID),
133 m_err_message(msg)
134 {
135 }
136
ocsdError(const ocsd_err_severity_t sev_type,const ocsd_err_t code,const ocsd_trc_index_t idx,const std::string & msg)137 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx, const std::string &msg) :
138 m_error_code(code),
139 m_sev(sev_type),
140 m_idx(idx),
141 m_chan_ID(OCSD_BAD_CS_SRC_ID),
142 m_err_message(msg)
143 {
144 }
145
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)146 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) :
147 m_error_code(code),
148 m_sev(sev_type),
149 m_idx(idx),
150 m_chan_ID(chan_id),
151 m_err_message(msg)
152 {
153 }
154
155
ocsdError(const ocsdError * pError)156 ocsdError::ocsdError(const ocsdError *pError) :
157 m_error_code(pError->getErrorCode()),
158 m_sev(pError->getErrorSeverity()),
159 m_idx(pError->getErrorIndex()),
160 m_chan_ID(pError->getErrorChanID())
161 {
162 setMessage(pError->getMessage());
163 }
164
ocsdError(const ocsdError & Error)165 ocsdError::ocsdError(const ocsdError &Error) :
166 m_error_code(Error.getErrorCode()),
167 m_sev(Error.getErrorSeverity()),
168 m_idx(Error.getErrorIndex()),
169 m_chan_ID(Error.getErrorChanID())
170 {
171 setMessage(Error.getMessage());
172 }
173
ocsdError()174 ocsdError::ocsdError():
175 m_error_code(OCSD_ERR_LAST),
176 m_sev(OCSD_ERR_SEV_NONE),
177 m_idx(OCSD_BAD_TRC_INDEX),
178 m_chan_ID(OCSD_BAD_CS_SRC_ID)
179 {
180 }
181
~ocsdError()182 ocsdError::~ocsdError()
183 {
184 }
185
getErrorString(const ocsdError & error)186 const std::string ocsdError::getErrorString(const ocsdError &error)
187 {
188 std::string szErrStr = "LIBRARY INTERNAL ERROR: Invalid Error Object";
189 const char *sev_type_sz[] = {
190 "NONE ",
191 "ERROR:",
192 "WARN :",
193 "INFO :"
194 };
195
196 switch(error.getErrorSeverity())
197 {
198 default:
199 case OCSD_ERR_SEV_NONE:
200 break;
201
202 case OCSD_ERR_SEV_ERROR:
203 case OCSD_ERR_SEV_WARN:
204 case OCSD_ERR_SEV_INFO:
205 szErrStr = sev_type_sz[(int)error.getErrorSeverity()];
206 appendErrorDetails(szErrStr,error);
207 break;
208 }
209 return szErrStr;
210 }
211
appendErrorDetails(std::string & errStr,const ocsdError & error)212 void ocsdError::appendErrorDetails(std::string &errStr, const ocsdError &error)
213 {
214 int numerrstr = sizeof(s_errorCodeDescs) / sizeof(s_errorCodeDescs[0]);
215 int code = (int)error.getErrorCode();
216 ocsd_trc_index_t idx = error.getErrorIndex();
217 uint8_t chan_ID = error.getErrorChanID();
218 std::ostringstream oss;
219
220 oss << "0x" << std::hex << std::setfill('0') << std::setw(4) << code;
221 if(code < numerrstr)
222 oss << " (" << s_errorCodeDescs[code][0] << ") [" << s_errorCodeDescs[code][1] << "]; ";
223 else
224 oss << " (unknown); ";
225
226 if(idx != OCSD_BAD_TRC_INDEX)
227 oss << "TrcIdx=" << std::dec << idx << "; ";
228
229 if(chan_ID != OCSD_BAD_CS_SRC_ID)
230 oss << "CS ID=" << std::hex << std::setfill('0') << std::setw(2) << (uint16_t)chan_ID << "; ";
231
232 oss << error.getMessage();
233 errStr = oss.str();
234 }
235
236
getStr()237 const char* ocsdDataRespStr::getStr()
238 {
239 static const char* szRespStr[] = {
240 "OCSD_RESP_CONT: Continue processing.",
241 "OCSD_RESP_WARN_CONT: Continue processing -> a component logged a warning.",
242 "OCSD_RESP_ERR_CONT: Continue processing -> a component logged an error.",
243 "OCSD_RESP_WAIT: Pause processing",
244 "OCSD_RESP_WARN_WAIT: Pause processing -> a component logged a warning.",
245 "OCSD_RESP_ERR_WAIT: Pause processing -> a component logged an error.",
246 "OCSD_RESP_FATAL_NOT_INIT: Processing Fatal Error : component unintialised.",
247 "OCSD_RESP_FATAL_INVALID_OP: Processing Fatal Error : invalid data path operation.",
248 "OCSD_RESP_FATAL_INVALID_PARAM: Processing Fatal Error : invalid parameter in datapath call.",
249 "OCSD_RESP_FATAL_INVALID_DATA: Processing Fatal Error : invalid trace data.",
250 "OCSD_RESP_FATAL_SYS_ERR: Processing Fatal Error : internal system error."
251 };
252 if ((m_type < OCSD_RESP_CONT) || (m_type > OCSD_RESP_FATAL_SYS_ERR))
253 return "Unknown OCSD_RESP type.";
254 return szRespStr[m_type];
255 }
256
257 /* End of File ocsd_error.cpp */
258