3 * \brief OpenCSD : Library error class.
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
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.
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.
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.
36 #include "common/ocsd_error.h"
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."},
95 {"OCSD_ERR_DCD_INTERFACE_UNUSED","Attempt to connect or use and interface not supported by this decoder."},
97 {"OCSD_ERR_LAST", "No error - error code end marker"}
100 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code) :
103 m_idx(OCSD_BAD_TRC_INDEX),
104 m_chan_ID(OCSD_BAD_CS_SRC_ID)
108 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx) :
112 m_chan_ID(OCSD_BAD_CS_SRC_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) :
124 ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const std::string &msg) :
127 m_idx(OCSD_BAD_TRC_INDEX),
128 m_chan_ID(OCSD_BAD_CS_SRC_ID),
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) :
137 m_chan_ID(OCSD_BAD_CS_SRC_ID),
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) :
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())
158 setMessage(pError->getMessage());
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())
167 setMessage(Error.getMessage());
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)
178 ocsdError::~ocsdError()
182 const std::string ocsdError::getErrorString(const ocsdError &error)
184 std::string szErrStr = "LIBRARY INTERNAL ERROR: Invalid Error Object";
185 const char *sev_type_sz[] = {
192 switch(error.getErrorSeverity())
195 case OCSD_ERR_SEV_NONE:
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);
208 void ocsdError::appendErrorDetails(std::string &errStr, const ocsdError &error)
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;
216 oss << "0x" << std::hex << std::setfill('0') << std::setw(4) << code;
218 oss << " (" << s_errorCodeDescs[code][0] << ") [" << s_errorCodeDescs[code][1] << "]; ";
220 oss << " (unknown); ";
222 if(idx != OCSD_BAD_TRC_INDEX)
223 oss << "TrcIdx=" << std::dec << idx << "; ";
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 << "; ";
228 oss << error.getMessage();
232 /* End of File ocsd_error.cpp */