2 * \file trc_gen_elem.cpp
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "common/trc_gen_elem.h"
41 static const char *s_elem_descs[][2] =
43 {"OCSD_GEN_TRC_ELEM_UNKNOWN","Unknown trace element - default value or indicate error in stream to client."},
44 {"OCSD_GEN_TRC_ELEM_NO_SYNC","Waiting for sync - either at start of decode, or after overflow / bad packet"},
45 {"OCSD_GEN_TRC_ELEM_TRACE_ON","Start of trace - beginning of elements or restart after discontinuity (overflow, trace filtering)."},
46 {"OCSD_GEN_TRC_ELEM_EO_TRACE","End of the available trace in the buffer."},
47 {"OCSD_GEN_TRC_ELEM_PE_CONTEXT","PE status update / change (arch, ctxtid, vmid etc)."},
48 {"OCSD_GEN_TRC_ELEM_INSTR_RANGE","Traced N consecutive instructions from addr (no intervening events or data elements), may have data assoc key"},
49 {"OCSD_GEN_TRC_ELEM_ADDR_NACC","Tracing in inaccessible memory area."},
50 {"OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN","Tracing unknown address area."},
51 {"OCSD_GEN_TRC_ELEM_EXCEPTION","Exception"},
52 {"OCSD_GEN_TRC_ELEM_EXCEPTION_RET","Expection return"},
53 {"OCSD_GEN_TRC_ELEM_TIMESTAMP","Timestamp - preceding elements happeded before this time."},
54 {"OCSD_GEN_TRC_ELEM_CYCLE_COUNT","Cycle count - cycles since last cycle count value - associated with a preceding instruction range."},
55 {"OCSD_GEN_TRC_ELEM_EVENT","Event - numbered event or trigger"},
56 {"OCSD_GEN_TRC_ELEM_SWTRACE","Software trace packet - may contain data payload."},
57 {"OCSD_GEN_TRC_ELEM_CUSTOM","Fully custom packet type."}
60 static const char *instr_type[] = {
68 #define T_SIZE (sizeof(instr_type) / sizeof(const char *))
70 static const char *instr_sub_type[] = {
77 #define ST_SIZE (sizeof(instr_sub_type) / sizeof(const char *))
79 static const char *s_trace_on_reason[] = {
86 static const char *s_isa_str[] = {
87 "A32", /**< V7 ARM 32, V8 AArch32 */
88 "T32", /**< Thumb2 -> 16/32 bit instructions */
89 "A64", /**< V8 AArch64 */
90 "TEE", /**< Thumb EE - unsupported */
91 "Jaz", /**< Jazelle - unsupported in trace */
92 "Cst", /**< ISA custom */
93 "Unk" /**< ISA not yet known */
96 void OcsdTraceElement::toString(std::string &str) const
98 std::ostringstream oss;
99 int num_str = ((sizeof(s_elem_descs) / sizeof(const char *)) / 2);
100 int typeIdx = (int)this->elem_type;
101 if(typeIdx < num_str)
103 oss << s_elem_descs[typeIdx][0] << "(";
106 case OCSD_GEN_TRC_ELEM_INSTR_RANGE:
107 oss << "exec range=0x" << std::hex << st_addr << ":[0x" << en_addr << "] ";
108 oss << "(ISA=" << s_isa_str[(int)isa] << ") ";
109 oss << ((last_instr_exec == 1) ? "E " : "N ");
110 if((int)last_i_type < T_SIZE)
111 oss << instr_type[last_i_type];
112 if((last_i_subtype != OCSD_S_INSTR_NONE) && ((int)last_i_subtype < ST_SIZE))
113 oss << instr_sub_type[last_i_subtype];
116 case OCSD_GEN_TRC_ELEM_ADDR_NACC:
117 oss << " 0x" << std::hex << st_addr << " ";
120 case OCSD_GEN_TRC_ELEM_EXCEPTION:
121 if(excep_ret_addr == 1)
123 oss << "pref ret addr:0x" << std::hex << en_addr << "; ";
125 oss << "excep num (0x" << std::setfill('0') << std::setw(2) << std::hex << exception_number << ") ";
128 case OCSD_GEN_TRC_ELEM_PE_CONTEXT:
129 oss << "(ISA=" << s_isa_str[(int)isa] << ") ";
130 if((context.exception_level > ocsd_EL_unknown) && (context.el_valid))
132 oss << "EL" << std::dec << (int)(context.exception_level);
134 oss << (context.security_level == ocsd_sec_secure ? "S; " : "N; ") << (context.bits64 ? "64-bit; " : "32-bit; ");
135 if(context.vmid_valid)
136 oss << "VMID=0x" << std::hex << context.vmid << "; ";
137 if(context.ctxt_id_valid)
138 oss << "CTXTID=0x" << std::hex << context.context_id << "; ";
141 case OCSD_GEN_TRC_ELEM_TRACE_ON:
142 oss << " [" << s_trace_on_reason[trace_on_reason] << "]";
145 case OCSD_GEN_TRC_ELEM_TIMESTAMP:
146 oss << " [ TS=0x" << std::setfill('0') << std::setw(12) << std::hex << timestamp << "]; ";
149 case OCSD_GEN_TRC_ELEM_SWTRACE:
156 oss << std::dec << " [CC=" << cycle_count << "]; ";
161 oss << "OCSD_GEN_TRC_ELEM??: index out of range.";
166 OcsdTraceElement &OcsdTraceElement::operator =(const ocsd_generic_trace_elem* p_elem)
168 *dynamic_cast<ocsd_generic_trace_elem*>(this) = *p_elem;
173 void OcsdTraceElement::printSWInfoPkt(std::ostringstream & oss) const
175 if (!sw_trace_info.swt_global_err)
177 if (sw_trace_info.swt_id_valid)
179 oss << " (Ma:0x" << std::setfill('0') << std::setw(2) << std::hex << sw_trace_info.swt_master_id << "; ";
180 oss << "Ch:0x" << std::setfill('0') << std::setw(2) << std::hex << sw_trace_info.swt_channel_id << ") ";
183 oss << "(Ma:0x??; Ch:0x??" << ") ";
185 if (sw_trace_info.swt_payload_pkt_bitsize > 0)
187 oss << "0x" << std::setfill('0') << std::hex;
188 if (sw_trace_info.swt_payload_pkt_bitsize == 4)
191 oss << (uint16_t)(((uint8_t *)ptr_extended_data)[0] & 0xF);
195 switch (sw_trace_info.swt_payload_pkt_bitsize)
198 // force uint8 to uint16 so oss 'sees' them as something to be stringised, rather than absolute char values
199 oss << std::setw(2) << (uint16_t)((uint8_t *)ptr_extended_data)[0];
202 oss << std::setw(4) << ((uint16_t *)ptr_extended_data)[0];
205 oss << std::setw(8) << ((uint32_t *)ptr_extended_data)[0];
208 oss << std::setw(16) << ((uint64_t *)ptr_extended_data)[0];
211 oss << "{Data Error : unsupported bit width.}";
217 if (sw_trace_info.swt_marker_packet)
219 if (sw_trace_info.swt_trigger_event)
221 if (sw_trace_info.swt_has_timestamp)
222 oss << " [ TS=0x" << std::setfill('0') << std::setw(12) << std::hex << timestamp << "]; ";
223 if (sw_trace_info.swt_frequency)
225 if (sw_trace_info.swt_master_err)
226 oss << "{Master Error.}";
230 oss << "{Global Error.}";
235 void OcsdTraceElement::toString(const ocsd_generic_trace_elem *p_elem, std::string &str)
237 OcsdTraceElement elem;
242 /* End of File trc_gen_elem.cpp */