aboutsummaryrefslogtreecommitdiffstats
path: root/decoder/source/ocsd_error.cpp
blob: 251964b7a4b0eafa49e3ca3db7725e00e64f6d9d (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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 * \file       ocsd_error.cpp
 * \brief      OpenCSD : Library error class.
 * 
 * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
 */


/* 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 * this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution. 
 * 
 * 3. Neither the name of the copyright holder nor the names of its contributors 
 * may be used to endorse or promote products derived from this software without 
 * specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */ 

#include "common/ocsd_error.h"
#include <sstream>
#include <iomanip>

static const char *s_errorCodeDescs[][2] = {
    /* general return errors */
    {"OCSD_OK", "No Error."},
    {"OCSD_ERR_FAIL","General failure."},
    {"OCSD_ERR_MEM","Internal memory allocation error."},
    {"OCSD_ERR_NOT_INIT","Component not initialised."},
    {"OCSD_ERR_INVALID_ID","Invalid CoreSight Trace Source ID."},
    {"OCSD_ERR_BAD_HANDLE","Invalid handle passed to component."},
    {"OCSD_ERR_INVALID_PARAM_VAL","Invalid value parameter passed to component."},
    {"OCSD_ERR_INVALID_PARAM_TYPE","Type mismatch on abstract interface."},
    {"OCSD_ERR_FILE_ERROR","File access error"},
    {"OCSD_ERR_NO_PROTOCOL","Trace protocol unsupported"},
    /* attachment point errors */
    {"OCSD_ERR_ATTACH_TOO_MANY","Cannot attach - attach device limit reached."},
    {"OCSD_ERR_ATTACH_INVALID_PARAM"," Cannot attach - invalid parameter."},
    {"OCSD_ERR_ATTACH_COMP_NOT_FOUND","Cannot detach - component not found."},
    /* source reader errors */
    {"OCSD_ERR_RDR_FILE_NOT_FOUND","source reader - file not found."},
    {"OCSD_ERR_RDR_INVALID_INIT",  "source reader - invalid initialisation parameter."},
    {"OCSD_ERR_RDR_NO_DECODER", "source reader - not trace decoder set."},
    /* data path errors */
    {"OCSD_ERR_DATA_DECODE_FATAL", "A decoder in the data path has returned a fatal error."},
    /* frame deformatter errors */
    {"OCSD_ERR_DFMTR_NOTCONTTRACE", "Trace input to deformatter none-continuous"},
    {"OCSD_ERR_DFMTR_BAD_FHSYNC", "Bad frame or half frame sync in trace deformatter"},
    /* packet processor errors - protocol issues etc */
    {"OCSD_ERR_BAD_PACKET_SEQ","Bad packet sequence"},
    {"OCSD_ERR_INVALID_PCKT_HDR","Invalid packet header"},
    {"OCSD_ERR_PKT_INTERP_FAIL","Interpreter failed - cannot recover - bad data or sequence"},
    /* packet decoder errors */
    {"OCSD_ERR_UNSUPPORTED_ISA","ISA not supported in decoder"},
    {"OCSD_ERR_HW_CFG_UNSUPP","Programmed trace configuration not supported by decodUer."},
    {"OCSD_ERR_UNSUPP_DECODE_PKT","Packet not supported in decoder"},
    {"OCSD_ERR_BAD_DECODE_PKT","Reserved or unknown packet in decoder."}, 
    {"OCSD_ERR_COMMIT_PKT_OVERRUN","Overrun in commit packet stack - tried to commit more than available"},
    {"OCSD_ERR_MEM_NACC","Unable to access required memory address."},
    {"OCSD_ERR_RET_STACK_OVERFLOW","Internal return stack overflow checks failed - popped more than we pushed."},
    /* decode tree errors */
    {"OCSD_ERR_DCDT_NO_FORMATTER","No formatter in use - operation not valid."},
    /* target memory access errors */
    {"OCSD_ERR_MEM_ACC_OVERLAP","Attempted to set an overlapping range in memory access map."},
    {"OCSD_ERR_MEM_ACC_FILE_NOT_FOUND","Memory access file could not be opened."},
    {"OCSD_ERR_MEM_ACC_FILE_DIFF_RANGE","Attempt to re-use the same memory access file for a different address range."},
    {"OCSD_ERR_MEM_ACC_BAD_LEN","Memory accessor returned a bad read length value (larger than requested."},
    {"OCSD_ERR_MEM_ACC_RANGE_INVALID","Address range in accessor set to invalid values."},
    /* test errors - errors generated only by the test code, not the library */
    {"OCSD_ERR_TEST_SNAPSHOT_PARSE", "Test snapshot file parse error"},
    {"OCSD_ERR_TEST_SNAPSHOT_PARSE_INFO", "Test snapshot file parse information"},
    {"OCSD_ERR_TEST_SNAPSHOT_READ","test snapshot reader error"},
    {"OCSD_ERR_TEST_SS_TO_DECODER","test snapshot to decode tree conversion error"},
    /* decoder registration */
    {"OCSD_ERR_DCDREG_NAME_REPEAT","Attempted to register a decoder with the same name as another one."},
    {"OCSD_ERR_DCDREG_NAME_UNKNOWN","Attempted to find a decoder with a name that is not known in the library."},
    {"OCSD_ERR_DCDREG_TYPE_UNKNOWN","Attempted to find a decoder with a type that is not known in the library."},
    /* decoder config */
    {"OCSD_ERR_DCD_INTERFACE_UNUSED","Attempt to connect or use and interface not supported by this decoder."},
    /* end marker*/
    {"OCSD_ERR_LAST", "No error - error code end marker"}
};

ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code) :
    m_error_code(code),
    m_sev(sev_type),
    m_idx(OCSD_BAD_TRC_INDEX),
    m_chan_ID(OCSD_BAD_CS_SRC_ID)
{
}

ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx) :
    m_error_code(code),
    m_sev(sev_type),
    m_idx(idx),
    m_chan_ID(OCSD_BAD_CS_SRC_ID)
{
}

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) :
    m_error_code(code),
    m_sev(sev_type),
    m_idx(idx),
    m_chan_ID(chan_id)
{
}

ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const std::string &msg) :
    m_error_code(code),
    m_sev(sev_type),
    m_idx(OCSD_BAD_TRC_INDEX),
    m_chan_ID(OCSD_BAD_CS_SRC_ID),
    m_err_message(msg)
{
}

ocsdError::ocsdError(const ocsd_err_severity_t sev_type, const ocsd_err_t code, const ocsd_trc_index_t idx, const std::string &msg) :
    m_error_code(code),
    m_sev(sev_type),
    m_idx(idx),
    m_chan_ID(OCSD_BAD_CS_SRC_ID),
    m_err_message(msg)
{
}

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) :
    m_error_code(code),
    m_sev(sev_type),
    m_idx(idx),
    m_chan_ID(chan_id),
    m_err_message(msg)
{
}


ocsdError::ocsdError(const ocsdError *pError) :
    m_error_code(pError->getErrorCode()),
    m_sev(pError->getErrorSeverity()),
    m_idx(pError->getErrorIndex()),
    m_chan_ID(pError->getErrorChanID())
{
    setMessage(pError->getMessage());
}

ocsdError::ocsdError(const ocsdError &Error) :
    m_error_code(Error.getErrorCode()),
    m_sev(Error.getErrorSeverity()),
    m_idx(Error.getErrorIndex()),
    m_chan_ID(Error.getErrorChanID())
{
    setMessage(Error.getMessage());
}

ocsdError::ocsdError():
    m_error_code(OCSD_ERR_LAST),
    m_sev(OCSD_ERR_SEV_NONE),
    m_idx(OCSD_BAD_TRC_INDEX),
    m_chan_ID(OCSD_BAD_CS_SRC_ID)
{
}

ocsdError::~ocsdError()
{
}

const std::string ocsdError::getErrorString(const ocsdError &error)
{
    std::string szErrStr = "LIBRARY INTERNAL ERROR: Invalid Error Object";
    const char *sev_type_sz[] = {
        "NONE ",
        "ERROR:",
        "WARN :", 
        "INFO :"
    };

    switch(error.getErrorSeverity())
    {
    default:
    case OCSD_ERR_SEV_NONE:
        break;

    case OCSD_ERR_SEV_ERROR:
    case OCSD_ERR_SEV_WARN:
    case OCSD_ERR_SEV_INFO:
        szErrStr = sev_type_sz[(int)error.getErrorSeverity()];
        appendErrorDetails(szErrStr,error);
        break;
    }
    return szErrStr;
}

void ocsdError::appendErrorDetails(std::string &errStr, const ocsdError &error)
{
    int numerrstr = ((sizeof(s_errorCodeDescs) / sizeof(const char *)) / 2);
    int code = (int)error.getErrorCode();
    ocsd_trc_index_t idx = error.getErrorIndex();
    uint8_t chan_ID = error.getErrorChanID();
    std::ostringstream oss;

    oss << "0x" << std::hex << std::setfill('0') << std::setw(4) << code;
    if(code < numerrstr)
        oss << " (" << s_errorCodeDescs[code][0] << ") [" << s_errorCodeDescs[code][1] << "]; ";
    else
        oss << " (unknown); ";

    if(idx != OCSD_BAD_TRC_INDEX)
        oss << "TrcIdx=" << std::dec << idx << "; ";

    if(chan_ID != OCSD_BAD_CS_SRC_ID)
        oss << "CS ID=" << std::hex << std::setfill('0') << std::setw(2) << (uint16_t)chan_ID << "; ";

    oss << error.getMessage();
    errStr = oss.str();
}

/* End of File ocsd_error.cpp */