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","Exception 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[] = {
78 #define ST_SIZE (sizeof(instr_sub_type) / sizeof(const char *))
80 static const char *s_trace_on_reason[] = {
87 static const char *s_isa_str[] = {
88 "A32", /**< V7 ARM 32, V8 AArch32 */
89 "T32", /**< Thumb2 -> 16/32 bit instructions */
90 "A64", /**< V8 AArch64 */
91 "TEE", /**< Thumb EE - unsupported */
92 "Jaz", /**< Jazelle - unsupported in trace */
93 "Cst", /**< ISA custom */
94 "Unk" /**< ISA not yet known */
97 void OcsdTraceElement::toString(std::string &str) const
99 std::ostringstream oss;
100 int num_str = ((sizeof(s_elem_descs) / sizeof(const char *)) / 2);
101 int typeIdx = (int)this->elem_type;
102 if(typeIdx < num_str)
104 oss << s_elem_descs[typeIdx][0] << "(";
107 case OCSD_GEN_TRC_ELEM_INSTR_RANGE:
108 oss << "exec range=0x" << std::hex << st_addr << ":[0x" << en_addr << "] ";
109 oss << "num_i(" << std::dec << num_instr_range << ") ";
110 oss << "last_sz(" << last_instr_sz << ") ";
111 oss << "(ISA=" << s_isa_str[(int)isa] << ") ";
112 oss << ((last_instr_exec == 1) ? "E " : "N ");
113 if((int)last_i_type < T_SIZE)
114 oss << instr_type[last_i_type];
115 if((last_i_subtype != OCSD_S_INSTR_NONE) && ((int)last_i_subtype < ST_SIZE))
116 oss << instr_sub_type[last_i_subtype];
121 case OCSD_GEN_TRC_ELEM_ADDR_NACC:
122 oss << " 0x" << std::hex << st_addr << " ";
125 case OCSD_GEN_TRC_ELEM_EXCEPTION:
126 if (excep_ret_addr == 1)
128 oss << "pref ret addr:0x" << std::hex << en_addr;
129 if (excep_ret_addr_br_tgt)
131 oss << " [addr also prev br tgt]";
135 oss << "excep num (0x" << std::setfill('0') << std::setw(2) << std::hex << exception_number << ") ";
138 case OCSD_GEN_TRC_ELEM_PE_CONTEXT:
139 oss << "(ISA=" << s_isa_str[(int)isa] << ") ";
140 if((context.exception_level > ocsd_EL_unknown) && (context.el_valid))
142 oss << "EL" << std::dec << (int)(context.exception_level);
144 oss << (context.security_level == ocsd_sec_secure ? "S; " : "N; ") << (context.bits64 ? "64-bit; " : "32-bit; ");
145 if(context.vmid_valid)
146 oss << "VMID=0x" << std::hex << context.vmid << "; ";
147 if(context.ctxt_id_valid)
148 oss << "CTXTID=0x" << std::hex << context.context_id << "; ";
151 case OCSD_GEN_TRC_ELEM_TRACE_ON:
152 oss << " [" << s_trace_on_reason[trace_on_reason] << "]";
155 case OCSD_GEN_TRC_ELEM_TIMESTAMP:
156 oss << " [ TS=0x" << std::setfill('0') << std::setw(12) << std::hex << timestamp << "]; ";
159 case OCSD_GEN_TRC_ELEM_SWTRACE:
163 case OCSD_GEN_TRC_ELEM_EVENT:
164 if(trace_event.ev_type == EVENT_TRIGGER)
166 else if(trace_event.ev_type == EVENT_NUMBERED)
167 oss << " Numbered:" << std::dec << trace_event.ev_number << "; ";
173 oss << std::dec << " [CC=" << cycle_count << "]; ";
178 oss << "OCSD_GEN_TRC_ELEM??: index out of range.";
183 OcsdTraceElement &OcsdTraceElement::operator =(const ocsd_generic_trace_elem* p_elem)
185 *dynamic_cast<ocsd_generic_trace_elem*>(this) = *p_elem;
190 void OcsdTraceElement::printSWInfoPkt(std::ostringstream & oss) const
192 if (!sw_trace_info.swt_global_err)
194 if (sw_trace_info.swt_id_valid)
196 oss << " (Ma:0x" << std::setfill('0') << std::setw(2) << std::hex << sw_trace_info.swt_master_id << "; ";
197 oss << "Ch:0x" << std::setfill('0') << std::setw(2) << std::hex << sw_trace_info.swt_channel_id << ") ";
200 oss << "(Ma:0x??; Ch:0x??" << ") ";
202 if (sw_trace_info.swt_payload_pkt_bitsize > 0)
204 oss << "0x" << std::setfill('0') << std::hex;
205 if (sw_trace_info.swt_payload_pkt_bitsize == 4)
208 oss << (uint16_t)(((uint8_t *)ptr_extended_data)[0] & 0xF);
212 switch (sw_trace_info.swt_payload_pkt_bitsize)
215 // force uint8 to uint16 so oss 'sees' them as something to be stringised, rather than absolute char values
216 oss << std::setw(2) << (uint16_t)((uint8_t *)ptr_extended_data)[0];
219 oss << std::setw(4) << ((uint16_t *)ptr_extended_data)[0];
222 oss << std::setw(8) << ((uint32_t *)ptr_extended_data)[0];
225 oss << std::setw(16) << ((uint64_t *)ptr_extended_data)[0];
228 oss << "{Data Error : unsupported bit width.}";
234 if (sw_trace_info.swt_marker_packet)
236 if (sw_trace_info.swt_trigger_event)
238 if (sw_trace_info.swt_has_timestamp)
239 oss << " [ TS=0x" << std::setfill('0') << std::setw(12) << std::hex << timestamp << "]; ";
240 if (sw_trace_info.swt_frequency)
242 if (sw_trace_info.swt_master_err)
243 oss << "{Master Error.}";
247 oss << "{Global Error.}";
252 void OcsdTraceElement::toString(const ocsd_generic_trace_elem *p_elem, std::string &str)
254 OcsdTraceElement elem;
259 /* End of File trc_gen_elem.cpp */