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