Move packet printing code from the test environment into the main library. Allows for later additions to let external clients use built in print objects to create strings and logs when using the library, avoiding the need for specific callbacks. Applies to raw trace frames, generic output packets and built-in packet protocols.
Creates packet printer factory to generate printer objects. Test programs adjusted to verify new API.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/build/linux/ref_trace_decode_lib/makefile | 10 +- .../ref_trace_decode_lib.vcxproj | 8 + .../ref_trace_decode_lib.vcxproj.filters | 30 ++++ decoder/include/opencsd.h | 4 + decoder/include/pkt_printers/gen_elem_printer.h | 95 +++++++++++ decoder/include/pkt_printers/item_printer.h | 94 ++++++++++ decoder/include/pkt_printers/pkt_printer_t.h | 189 +++++++++++++++++++++ decoder/include/pkt_printers/raw_frame_printer.h | 69 ++++++++ decoder/include/pkt_printers/trc_pkt_printers.h | 43 +++++ decoder/include/pkt_printers/trc_print_fact.h | 62 +++++++ decoder/source/pkt_printers/raw_frame_printer.cpp | 104 ++++++++++++ decoder/source/pkt_printers/trc_print_fact.cpp | 111 ++++++++++++ decoder/source/trc_frame_deformatter.cpp | 21 ++- decoder/tests/build/linux/trc_pkt_lister/makefile | 3 +- .../trc_pkt_lister/trc_pkt_lister.vcxproj | 6 +- .../trc_pkt_lister/trc_pkt_lister.vcxproj.filters | 14 +- decoder/tests/source/gen_elem_printer.h | 96 ----------- decoder/tests/source/item_printer.h | 94 ---------- decoder/tests/source/pkt_printer_t.h | 188 -------------------- decoder/tests/source/raw_frame_printer.cpp | 96 ----------- decoder/tests/source/raw_frame_printer.h | 71 -------- decoder/tests/source/trc_pkt_lister.cpp | 91 +++++----- 22 files changed, 881 insertions(+), 618 deletions(-) create mode 100644 decoder/include/pkt_printers/gen_elem_printer.h create mode 100644 decoder/include/pkt_printers/item_printer.h create mode 100644 decoder/include/pkt_printers/pkt_printer_t.h create mode 100644 decoder/include/pkt_printers/raw_frame_printer.h create mode 100644 decoder/include/pkt_printers/trc_pkt_printers.h create mode 100644 decoder/include/pkt_printers/trc_print_fact.h create mode 100644 decoder/source/pkt_printers/raw_frame_printer.cpp create mode 100644 decoder/source/pkt_printers/trc_print_fact.cpp delete mode 100644 decoder/tests/source/gen_elem_printer.h delete mode 100644 decoder/tests/source/item_printer.h delete mode 100644 decoder/tests/source/pkt_printer_t.h delete mode 100644 decoder/tests/source/raw_frame_printer.cpp delete mode 100644 decoder/tests/source/raw_frame_printer.h
diff --git a/decoder/build/linux/ref_trace_decode_lib/makefile b/decoder/build/linux/ref_trace_decode_lib/makefile index 5d89999..748bab1 100644 --- a/decoder/build/linux/ref_trace_decode_lib/makefile +++ b/decoder/build/linux/ref_trace_decode_lib/makefile @@ -48,7 +48,8 @@ VPATH= $(OCSD_SOURCE) \ $(OCSD_SOURCE)/ptm \ $(OCSD_SOURCE)/i_dec \ $(OCSD_SOURCE)/mem_acc \ - $(OCSD_SOURCE)/stm + $(OCSD_SOURCE)/stm \ + $(OCSD_SOURCE)/pkt_printers
CPP_INCLUDES= \ @@ -86,6 +87,10 @@ STMOBJ= $(BUILD_DIR)/trc_pkt_elem_stm.o \ $(BUILD_DIR)/trc_pkt_proc_stm.o \ $(BUILD_DIR)/trc_pkt_decode_stm.o
+PKTPRNTOBJ= $(BUILD_DIR)/raw_frame_printer.o \ + $(BUILD_DIR)/trc_print_fact.o + + OBJECTS=$(BUILD_DIR)/ocsd_code_follower.o \ $(BUILD_DIR)/ocsd_dcd_tree.o \ $(BUILD_DIR)/ocsd_error.o \ @@ -104,7 +109,8 @@ OBJECTS=$(BUILD_DIR)/ocsd_code_follower.o \ $(IDECOBJ) \ $(MEMACCOBJ) \ $(STMOBJ) \ - $(PTMOBJ) + $(PTMOBJ) \ + $(PKTPRNTOBJ)
all: build_dir $(OBJECTS) mkdir -p $(LIB_TARGET_DIR) diff --git a/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj b/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj index 05e5857..709f031 100644 --- a/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj +++ b/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj @@ -372,6 +372,12 @@ <ClInclude Include="..\..\..\include\ocsd_if_types.h" /> <ClInclude Include="..\..\..\include\ocsd_if_version.h" /> <ClInclude Include="..\..\..\include\opencsd.h" /> + <ClInclude Include="..\..\..\include\pkt_printers\gen_elem_printer.h" /> + <ClInclude Include="..\..\..\include\pkt_printers\item_printer.h" /> + <ClInclude Include="..\..\..\include\pkt_printers\pkt_printer_t.h" /> + <ClInclude Include="..\..\..\include\pkt_printers\raw_frame_printer.h" /> + <ClInclude Include="..\..\..\include\pkt_printers\trc_pkt_printers.h" /> + <ClInclude Include="..\..\..\include\pkt_printers\trc_print_fact.h" /> <ClInclude Include="..\..\..\include\ptm\ptm_decoder.h" /> <ClInclude Include="..\..\..\include\ptm\trc_cmp_cfg_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_dcd_mngr_ptm.h" /> @@ -421,6 +427,8 @@ <ClCompile Include="..\..\..\source\ocsd_lib_dcd_register.cpp" /> <ClCompile Include="..\..\..\source\ocsd_msg_logger.cpp" /> <ClCompile Include="..\..\..\source\ocsd_version.cpp" /> + <ClCompile Include="..\..\..\source\pkt_printers\raw_frame_printer.cpp" /> + <ClCompile Include="..\..\..\source\pkt_printers\trc_print_fact.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_cmp_cfg_ptm.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_pkt_decode_ptm.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_pkt_elem_ptm.cpp" /> diff --git a/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters b/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters index 87aa847..2ee0f50 100644 --- a/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters +++ b/decoder/build/win-vs2015/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters @@ -58,6 +58,12 @@ <Filter Include="Header Files\common"> <UniqueIdentifier>{58d2398e-efdd-45d9-b7be-fc6096f3bec2}</UniqueIdentifier> </Filter> + <Filter Include="Header Files\pkt_printers"> + <UniqueIdentifier>{0e6e1f5d-465e-4f91-88a3-479952bbd316}</UniqueIdentifier> + </Filter> + <Filter Include="Source Files\pkt_printers"> + <UniqueIdentifier>{baf047d0-0ff7-4502-b42b-4f1fda94d54b}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <None Include="..\..\..\..\LICENSE"> @@ -329,6 +335,24 @@ <ClInclude Include="..\..\..\include\ocsd_if_version.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\..\..\include\pkt_printers\gen_elem_printer.h"> + <Filter>Header Files\pkt_printers</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\pkt_printers\item_printer.h"> + <Filter>Header Files\pkt_printers</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\pkt_printers\pkt_printer_t.h"> + <Filter>Header Files\pkt_printers</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\pkt_printers\raw_frame_printer.h"> + <Filter>Header Files\pkt_printers</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\pkt_printers\trc_pkt_printers.h"> + <Filter>Header Files\pkt_printers</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\pkt_printers\trc_print_fact.h"> + <Filter>Header Files\pkt_printers</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\trc_component.cpp"> @@ -445,5 +469,11 @@ <ClCompile Include="..\..\..\source\stm\trc_pkt_decode_stm.cpp"> <Filter>Source Files\stm</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\pkt_printers\raw_frame_printer.cpp"> + <Filter>Source Files\pkt_printers</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\pkt_printers\trc_print_fact.cpp"> + <Filter>Source Files\pkt_printers</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/decoder/include/opencsd.h b/decoder/include/opencsd.h index ad6e2d2..fa8a45a 100644 --- a/decoder/include/opencsd.h +++ b/decoder/include/opencsd.h @@ -70,6 +70,10 @@ #include "i_dec/trc_i_decode.h" #include "mem_acc/trc_mem_acc.h"
+/* printers for builtin packet elements */ +#include "pkt_printers/trc_pkt_printers.h" +#include "pkt_printers/trc_print_fact.h" + /** The decode tree and decoder register*/ #include "common/ocsd_lib_dcd_register.h" #include "common/ocsd_dcd_tree.h" diff --git a/decoder/include/pkt_printers/gen_elem_printer.h b/decoder/include/pkt_printers/gen_elem_printer.h new file mode 100644 index 0000000..ba3138a --- /dev/null +++ b/decoder/include/pkt_printers/gen_elem_printer.h @@ -0,0 +1,95 @@ +/* + * \file gen_elem_printer.h + * \brief OpenCSD : Generic element printer 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. + */ +#ifndef ARM_GEN_ELEM_PRINTER_H_INCLUDED +#define ARM_GEN_ELEM_PRINTER_H_INCLUDED + +#include "opencsd.h" + +class TrcGenericElementPrinter : public ItemPrinter, public ITrcGenElemIn +{ +public: + TrcGenericElementPrinter(); + virtual ~TrcGenericElementPrinter() {}; + + virtual ocsd_datapath_resp_t TraceElemIn(const ocsd_trc_index_t index_sop, + const uint8_t trc_chan_id, + const OcsdTraceElement &elem); + + // funtionality to test wait / flush mechanism + void ackWait() { m_needWaitAck = false; }; + const bool needAckWait() const { return m_needWaitAck; }; + +protected: + bool m_needWaitAck; +}; + + +inline TrcGenericElementPrinter::TrcGenericElementPrinter() : + m_needWaitAck(false) +{ +} + +inline ocsd_datapath_resp_t TrcGenericElementPrinter::TraceElemIn(const ocsd_trc_index_t index_sop, + const uint8_t trc_chan_id, + const OcsdTraceElement &elem) +{ + ocsd_datapath_resp_t resp = OCSD_RESP_CONT; + std::string elemStr; + std::ostringstream oss; + oss << "Idx:" << index_sop << "; ID:"<< std::hex << (uint32_t)trc_chan_id << "; "; + elem.toString(elemStr); + oss << elemStr << std::endl; + itemPrintLine(oss.str()); + + // funtionality to test wait / flush mechanism + if(m_needWaitAck) + { + oss.str(""); + oss << "WARNING: Generic Element Printer; New element without previous _WAIT acknowledged\n"; + itemPrintLine(oss.str()); + m_needWaitAck = false; + } + + if(getTestWaits()) + { + resp = OCSD_RESP_WAIT; // return _WAIT for the 1st N packets. + decTestWaits(); + m_needWaitAck = true; + } + return resp; +} + +#endif // ARM_GEN_ELEM_PRINTER_H_INCLUDED + +/* End of File gen_elem_printer.h */ diff --git a/decoder/include/pkt_printers/item_printer.h b/decoder/include/pkt_printers/item_printer.h new file mode 100644 index 0000000..cc3ec37 --- /dev/null +++ b/decoder/include/pkt_printers/item_printer.h @@ -0,0 +1,94 @@ +/* + * \file item_printer.h + * \brief OpenCSD : + * + * \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. + */ + +#ifndef ARM_ITEM_PRINTER_H_INCLUDED +#define ARM_ITEM_PRINTER_H_INCLUDED + +#include "opencsd.h" +#include <string> + +class ItemPrinter +{ +public: + ItemPrinter(); + virtual ~ItemPrinter(); + + void setMessageLogger(ocsdMsgLogger *pMsgLogger) { m_pMsgLogger = pMsgLogger; }; + void itemPrintLine(const std::string &msg); + + // return wait for the first N packets - test the wait mechanism. + void setTestWaits(const int num_waits); + const int getTestWaits() const; + void decTestWaits(); + +protected: + ocsdMsgLogger *m_pMsgLogger; + int m_test_waits; +}; + +inline ItemPrinter::ItemPrinter() : + m_pMsgLogger(0), + m_test_waits(0) +{ +} + +inline ItemPrinter::~ItemPrinter() +{ + m_pMsgLogger = 0; +} + +inline void ItemPrinter::itemPrintLine(const std::string &msg) +{ + if(m_pMsgLogger) + m_pMsgLogger->LogMsg(msg); +} + +inline void ItemPrinter::setTestWaits(const int num_waits) +{ + m_test_waits = num_waits; +} + +inline const int ItemPrinter::getTestWaits() const +{ + return m_test_waits; +} + +inline void ItemPrinter::decTestWaits() +{ + m_test_waits--; +} + +#endif // ARM_ITEM_PRINTER_H_INCLUDED + +/* End of File item_printer.h */ diff --git a/decoder/include/pkt_printers/pkt_printer_t.h b/decoder/include/pkt_printers/pkt_printer_t.h new file mode 100644 index 0000000..fc3ad2a --- /dev/null +++ b/decoder/include/pkt_printers/pkt_printer_t.h @@ -0,0 +1,189 @@ +/* + * \file pkt_printer_t.h + * \brief OpenCSD : Test packet printer. + * + * \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. + */ + +#ifndef ARM_PKT_PRINTER_T_H_INCLUDED +#define ARM_PKT_PRINTER_T_H_INCLUDED + +#include "opencsd.h" + +#include <string> +#include <sstream> +#include <iostream> +#include <iomanip> + +template<class P> +class PacketPrinter : public IPktDataIn<P>, public IPktRawDataMon<P>, public ItemPrinter +{ +public: + PacketPrinter(const uint8_t trcID); + PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger); + virtual ~PacketPrinter(); + + + virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const P *p_packet_in); + + virtual void RawPacketDataMon( const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const P *pkt, + const uint32_t size, + const uint8_t *p_data); + + +private: + void printIdx_ID(const ocsd_trc_index_t index_sop); + + uint8_t m_trcID; + bool m_bRawPrint; + std::ostringstream m_oss; + ocsd_datapath_resp_t m_last_resp; + +}; + +template<class P> PacketPrinter<P>::PacketPrinter(uint8_t trcID) : + m_trcID(trcID), + m_bRawPrint(false), + m_last_resp(OCSD_RESP_CONT) +{ +} + +template<class P> PacketPrinter<P>::PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger) : + m_trcID(trcID), + m_bRawPrint(false), + m_last_resp(OCSD_RESP_CONT) +{ + setMessageLogger(pMsgLogger); +} + +template<class P> PacketPrinter<P>::~PacketPrinter() +{ +} + +template<class P> ocsd_datapath_resp_t PacketPrinter<P>::PacketDataIn( const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const P *p_packet_in) +{ + std::string pktstr; + ocsd_datapath_resp_t resp = OCSD_RESP_CONT; + + // wait / flush test verification + if(!m_bRawPrint && (m_last_resp == OCSD_RESP_WAIT)) + { + // expect a flush or a complete reset after a wait. + if((op != OCSD_OP_FLUSH) || (op != OCSD_OP_RESET)) + { + m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tERROR: FLUSH operation expected after wait on trace decode path\n"; + itemPrintLine(m_oss.str()); + m_oss.str(""); + return OCSD_RESP_FATAL_INVALID_OP; + } + } + + switch(op) + { + case OCSD_OP_DATA: + p_packet_in->toString(pktstr); + if(!m_bRawPrint) + printIdx_ID(index_sop); + m_oss << ";\t" << pktstr << std::endl; + + // test the wait/flush response mechnism + if(getTestWaits() && !m_bRawPrint) + { + decTestWaits(); + resp = OCSD_RESP_WAIT; + } + break; + + case OCSD_OP_EOT: + m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tEND OF TRACE DATA\n"; + break; + + case OCSD_OP_FLUSH: + m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tFLUSH operation on trace decode path\n"; + break; + + case OCSD_OP_RESET: + m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tRESET operation on trace decode path\n"; + break; + } + + m_last_resp = resp; + itemPrintLine(m_oss.str()); + m_oss.str(""); + return resp; +} + +template<class P> void PacketPrinter<P>::RawPacketDataMon( const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const P *pkt, + const uint32_t size, + const uint8_t *p_data) +{ + switch(op) + { + case OCSD_OP_DATA: + printIdx_ID(index_sop); + m_oss << "; ["; + if((size > 0) && (p_data != 0)) + { + uint32_t data = 0; + for(uint32_t i = 0; i < size; i++) + { + data = (uint32_t)(p_data[i] & 0xFF); + m_oss << "0x" << std::hex << std::setw(2) << std::setfill('0') << data << " "; + } + } + m_oss << "]"; + m_bRawPrint = true; + PacketDataIn(op,index_sop,pkt); + m_bRawPrint = false; + break; + + default: + PacketDataIn(op,index_sop,pkt); + break; + } + +} + +template<class P> void PacketPrinter<P>::printIdx_ID(const ocsd_trc_index_t index_sop) +{ + m_oss << "Idx:" << std::dec << index_sop << "; ID:"<< std::hex << (uint32_t)m_trcID; +} + +#endif // ARM_PKT_PRINTER_T_H_INCLUDED + +/* End of File pkt_printer_t.h */ diff --git a/decoder/include/pkt_printers/raw_frame_printer.h b/decoder/include/pkt_printers/raw_frame_printer.h new file mode 100644 index 0000000..50caeb8 --- /dev/null +++ b/decoder/include/pkt_printers/raw_frame_printer.h @@ -0,0 +1,69 @@ +/* + * \file raw_frame_printer.h + * \brief OpenCSD : + * + * \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. + */ + +#ifndef ARM_RAW_FRAME_PRINTER_H_INCLUDED +#define ARM_RAW_FRAME_PRINTER_H_INCLUDED + +#include "opencsd.h" + +#include <string> +#include <sstream> + +class RawFramePrinter : public ITrcRawFrameIn, public ItemPrinter +{ +public: + RawFramePrinter() {}; + RawFramePrinter(ocsdMsgLogger *pMsgLogger); + virtual ~RawFramePrinter() {}; + + virtual ocsd_err_t TraceRawFrameIn( const ocsd_datapath_op_t op, + const ocsd_trc_index_t index, + const ocsd_rawframe_elem_t frame_element, + const int dataBlockSize, + const uint8_t *pDataBlock, + const uint8_t traceID); + +private: + void createDataString(const int dataSize, const uint8_t *pData, int bytesPerLine, std::string &dataStr); + +}; + +inline RawFramePrinter::RawFramePrinter(ocsdMsgLogger *pMsgLogger) +{ + setMessageLogger(pMsgLogger); +} + +#endif // ARM_RAW_FRAME_PRINTER_H_INCLUDED + +/* End of File raw_frame_printer.h */ diff --git a/decoder/include/pkt_printers/trc_pkt_printers.h b/decoder/include/pkt_printers/trc_pkt_printers.h new file mode 100644 index 0000000..439701a --- /dev/null +++ b/decoder/include/pkt_printers/trc_pkt_printers.h @@ -0,0 +1,43 @@ +/* +* \file trc_pkt_printers.h +* \brief OpenCSD : Known protocol packet printers. +* +* \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. +*/ + +#ifndef ARM_TRC_PKT_PRINTERS_H_INCLUDED +#define ARM_TRC_PKT_PRINTERS_H_INCLUDED + +#include "pkt_printers/item_printer.h" +#include "pkt_printers/pkt_printer_t.h" +#include "pkt_printers/gen_elem_printer.h" +#include "pkt_printers/raw_frame_printer.h" + +#endif // ARM_TRC_PKT_PRINTERS_H_INCLUDED diff --git a/decoder/include/pkt_printers/trc_print_fact.h b/decoder/include/pkt_printers/trc_print_fact.h new file mode 100644 index 0000000..002d74c --- /dev/null +++ b/decoder/include/pkt_printers/trc_print_fact.h @@ -0,0 +1,62 @@ +/* +* \file trc_print_fact.h +* \brief OpenCSD : Factory for protocol packet printers. +* +* \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. +*/ + +#ifndef ARM_TRC_PRINT_FACT_H_INCLUDED +#define ARM_TRC_PRINT_FACT_H_INCLUDED + +#include "opencsd.h" + +class PktPrinterFact +{ +public: + static ItemPrinter *createProtocolPrinter(ocsd_trace_protocol_t protocol, uint8_t elemID, ocsdMsgLogger *pMsgLogger = 0); + static RawFramePrinter *createRawFramePrinter(ocsdMsgLogger *pMsgLogger = 0); + static TrcGenericElementPrinter *createGenElemPrinter(ocsdMsgLogger *pMsgLogger = 0); + + static void destroyAllPrinters(); + static const int numPrinters(); + static std::vector<ItemPrinter *> &getPrinterList(); + +private: + static void SavePrinter(ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger); + + PktPrinterFact() {}; + ~PktPrinterFact() {}; + + static std::vector<ItemPrinter *> sm_printers; /* list of printers created. */ +}; + +#endif // ARM_TRC_PRINT_FACT_H_INCLUDED + +/* end of file trc_print_fact.h */ diff --git a/decoder/source/pkt_printers/raw_frame_printer.cpp b/decoder/source/pkt_printers/raw_frame_printer.cpp new file mode 100644 index 0000000..7ac2ddf --- /dev/null +++ b/decoder/source/pkt_printers/raw_frame_printer.cpp @@ -0,0 +1,104 @@ +/* + * \file raw_frame_printer.cpp + * \brief OpenCSD : + * + * \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 <string> +#include <sstream> +#include <iomanip> + +#include "opencsd.h" + + +ocsd_err_t RawFramePrinter::TraceRawFrameIn( const ocsd_datapath_op_t op, + const ocsd_trc_index_t index, + const ocsd_rawframe_elem_t frame_element, + const int dataBlockSize, + const uint8_t *pDataBlock, + const uint8_t traceID) +{ + + if(op == OCSD_OP_DATA) // only interested in actual frame data. + { + std::string strData; + std::ostringstream oss; + int printDataSize = dataBlockSize; + + oss << "Frame Data; Index" << std::setw(7) << index << "; "; + + switch(frame_element) + { + case OCSD_FRM_PACKED: oss << std::setw(15) << "RAW_PACKED; "; break; + case OCSD_FRM_HSYNC: oss << std::setw(15) << "HSYNC; "; break; + case OCSD_FRM_FSYNC: oss << std::setw(15) << "FSYNC; "; break; + case OCSD_FRM_ID_DATA: + oss << std::setw(10) << "ID_DATA["; + if (traceID == OCSD_BAD_CS_SRC_ID) + oss << "????"; + else + oss << "0x" << std::hex << std::setw(2) << std::setfill('0') << (uint16_t)traceID; + oss << "]; "; + break; + default: oss << std::setw(15) << "UNKNOWN; "; break; + } + + if(printDataSize) + { + createDataString(printDataSize,pDataBlock,16,strData); + oss << strData; + } + oss << std::endl; + itemPrintLine(oss.str()); + } + return OCSD_OK; +} + +void RawFramePrinter::createDataString(const int dataSize, const uint8_t *pData, int bytesPerLine, std::string &dataStr) +{ + int lineBytes = 0; + std::ostringstream oss; + + for(int i = 0; i < dataSize; i++) + { + if(lineBytes == bytesPerLine) + { + oss << std::endl; + lineBytes = 0; + } + oss << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)pData[i] << " "; + lineBytes ++; + } + dataStr = oss.str(); +} + + +/* End of File raw_frame_printer.cpp */ diff --git a/decoder/source/pkt_printers/trc_print_fact.cpp b/decoder/source/pkt_printers/trc_print_fact.cpp new file mode 100644 index 0000000..39d770d --- /dev/null +++ b/decoder/source/pkt_printers/trc_print_fact.cpp @@ -0,0 +1,111 @@ +/* +* \file trc_print_fact.cpp +* \brief OpenCSD : Trace Packet printer factory. +* +* \copyright Copyright (c) 2017, 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 "pkt_printers/trc_print_fact.h" + +std::vector<ItemPrinter *> PktPrinterFact::sm_printers; + +RawFramePrinter * PktPrinterFact::createRawFramePrinter(ocsdMsgLogger *pMsgLogger /*= 0*/) +{ + RawFramePrinter *pPrinter = 0; + pPrinter = new (std::nothrow)RawFramePrinter(); + SavePrinter(pPrinter, pMsgLogger); + return pPrinter; +} + +TrcGenericElementPrinter *PktPrinterFact::createGenElemPrinter(ocsdMsgLogger *pMsgLogger /*= 0*/) +{ + TrcGenericElementPrinter *pPrinter = 0; + pPrinter = new (std::nothrow)TrcGenericElementPrinter(); + SavePrinter(pPrinter, pMsgLogger); + return pPrinter; +} + +ItemPrinter *PktPrinterFact::createProtocolPrinter(ocsd_trace_protocol_t protocol, uint8_t CSID, ocsdMsgLogger *pMsgLogger /*= 0*/) +{ + ItemPrinter *pPrinter = 0; + switch (protocol) + { + case OCSD_PROTOCOL_ETMV4I: + pPrinter = new (std::nothrow) PacketPrinter<EtmV4ITrcPacket>(CSID); + break; + case OCSD_PROTOCOL_ETMV3: + pPrinter = new (std::nothrow) PacketPrinter<EtmV3TrcPacket>(CSID); + break; + case OCSD_PROTOCOL_PTM: + pPrinter = new (std::nothrow) PacketPrinter<PtmTrcPacket>(CSID); + break; + case OCSD_PROTOCOL_STM: + pPrinter = new (std::nothrow) PacketPrinter<StmTrcPacket>(CSID); + break; + default: + break; + } + SavePrinter(pPrinter, pMsgLogger); + return pPrinter; +} + +const int PktPrinterFact::numPrinters() +{ + return sm_printers.size(); +} + +std::vector<ItemPrinter *> &PktPrinterFact::getPrinterList() +{ + return sm_printers; +} + +void PktPrinterFact::SavePrinter(ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger) +{ + if (pPrinter) + { + pPrinter->setMessageLogger(pMsgLogger); + sm_printers.push_back((ItemPrinter *)pPrinter); + } +} + +void PktPrinterFact::destroyAllPrinters() +{ + std::vector<ItemPrinter *>::iterator it; + it = sm_printers.begin(); + while (it != sm_printers.end()) + { + delete *it; + it++; + } + sm_printers.clear(); +} + +/* end of file trc_print_fact.cpp */ diff --git a/decoder/source/trc_frame_deformatter.cpp b/decoder/source/trc_frame_deformatter.cpp index 769c38c..dad84e5 100644 --- a/decoder/source/trc_frame_deformatter.cpp +++ b/decoder/source/trc_frame_deformatter.cpp @@ -460,8 +460,21 @@ bool TraceFmtDcdImpl::extractFrame() { // some linux drivers (e.g. for perf) will insert FSYNCS to pad or differentiate // between blocks of aligned data, always in frame aligned complete 16 byte frames. - if( m_cfgFlags & OCSD_DFRMTR_RESET_ON_4X_FSYNC) - f_sync_bytes = checkForResetFSyncPatterns(); + if (m_cfgFlags & OCSD_DFRMTR_RESET_ON_4X_FSYNC) + { + f_sync_bytes = checkForResetFSyncPatterns(); + + /* in this case the FSYNC pattern is output on both packed and unpacked cases */ + if (f_sync_bytes && (m_b_output_packed_raw || m_b_output_unpacked_raw)) + { + outputRawMonBytes(OCSD_OP_DATA, + m_trc_curr_idx, + OCSD_FRM_FSYNC, + f_sync_bytes, + m_in_block_base + m_in_block_processed, + 0); + } + }
if((m_in_block_processed+f_sync_bytes) == m_in_block_size) { @@ -719,8 +732,8 @@ bool TraceFmtDcdImpl::outputFrame() } else { - // optional raw output for debugging / monitor tools - if(m_b_output_unpacked_raw && rawChanEnabled( m_out_data[m_out_processed].id)) + // optional raw output for debugging / monitor tools of unknown src ID data + if(m_b_output_unpacked_raw) { outputRawMonBytes( OCSD_OP_DATA, m_out_data[m_out_processed].index, diff --git a/decoder/tests/build/linux/trc_pkt_lister/makefile b/decoder/tests/build/linux/trc_pkt_lister/makefile index d2975f8..f160b9c 100644 --- a/decoder/tests/build/linux/trc_pkt_lister/makefile +++ b/decoder/tests/build/linux/trc_pkt_lister/makefile @@ -48,8 +48,7 @@ CPP_INCLUDES = \ -I$(OCSD_INCLUDE) \ -I$(OCSD_TESTS)/snapshot_parser_lib/include
-OBJECTS = $(BUILD_DIR)/trc_pkt_lister.o \ - $(BUILD_DIR)/raw_frame_printer.o +OBJECTS = $(BUILD_DIR)/trc_pkt_lister.o
LIBS = -L$(LIB_TEST_TARGET_DIR) -lsnapshot_parser \ -L$(LIB_TARGET_DIR) -l$(LIB_BASE_NAME) diff --git a/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj b/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj index a739864..3f90191 100644 --- a/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj +++ b/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj @@ -300,7 +300,6 @@ </Link> </ItemDefinitionGroup> <ItemGroup> - <ClCompile Include="..\..\..\source\raw_frame_printer.cpp" /> <ClCompile Include="..\..\..\source\trc_pkt_lister.cpp" /> </ItemGroup> <ItemGroup> @@ -309,10 +308,7 @@ </ProjectReference> </ItemGroup> <ItemGroup> - <ClInclude Include="..\..\..\source\gen_elem_printer.h" /> - <ClInclude Include="..\..\..\source\item_printer.h" /> - <ClInclude Include="..\..\..\source\pkt_printer_t.h" /> - <ClInclude Include="..\..\..\source\raw_frame_printer.h" /> + <ClInclude Include="..\..\..\..\include\pkt_printers\trc_pkt_printers.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj.filters b/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj.filters index daab04a..9f44406 100644 --- a/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj.filters +++ b/decoder/tests/build/win-vs2015/trc_pkt_lister/trc_pkt_lister.vcxproj.filters @@ -18,21 +18,9 @@ <ClCompile Include="..\..\..\source\trc_pkt_lister.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\raw_frame_printer.cpp"> - <Filter>Source Files</Filter> - </ClCompile> </ItemGroup> <ItemGroup> - <ClInclude Include="..\..\..\source\pkt_printer_t.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\item_printer.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\raw_frame_printer.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\gen_elem_printer.h"> + <ClInclude Include="..\..\..\..\include\pkt_printers\trc_pkt_printers.h"> <Filter>Header Files</Filter> </ClInclude> </ItemGroup> diff --git a/decoder/tests/source/gen_elem_printer.h b/decoder/tests/source/gen_elem_printer.h deleted file mode 100644 index f3e9717..0000000 --- a/decoder/tests/source/gen_elem_printer.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * \file gen_elem_printer.h - * \brief OpenCSD : Generic element printer 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. - */ -#ifndef ARM_GEN_ELEM_PRINTER_H_INCLUDED -#define ARM_GEN_ELEM_PRINTER_H_INCLUDED - -#include "opencsd.h" -#include "item_printer.h" - -class TrcGenericElementPrinter : public ItemPrinter, public ITrcGenElemIn -{ -public: - TrcGenericElementPrinter(); - virtual ~TrcGenericElementPrinter() {}; - - virtual ocsd_datapath_resp_t TraceElemIn(const ocsd_trc_index_t index_sop, - const uint8_t trc_chan_id, - const OcsdTraceElement &elem); - - // funtionality to test wait / flush mechanism - void ackWait() { m_needWaitAck = false; }; - const bool needAckWait() const { return m_needWaitAck; }; - -protected: - bool m_needWaitAck; -}; - - -inline TrcGenericElementPrinter::TrcGenericElementPrinter() : - m_needWaitAck(false) -{ -} - -inline ocsd_datapath_resp_t TrcGenericElementPrinter::TraceElemIn(const ocsd_trc_index_t index_sop, - const uint8_t trc_chan_id, - const OcsdTraceElement &elem) -{ - ocsd_datapath_resp_t resp = OCSD_RESP_CONT; - std::string elemStr; - std::ostringstream oss; - oss << "Idx:" << index_sop << "; ID:"<< std::hex << (uint32_t)trc_chan_id << "; "; - elem.toString(elemStr); - oss << elemStr << std::endl; - itemPrintLine(oss.str()); - - // funtionality to test wait / flush mechanism - if(m_needWaitAck) - { - oss.str(""); - oss << "WARNING: Generic Element Printer; New element without previous _WAIT acknowledged\n"; - itemPrintLine(oss.str()); - m_needWaitAck = false; - } - - if(getTestWaits()) - { - resp = OCSD_RESP_WAIT; // return _WAIT for the 1st N packets. - decTestWaits(); - m_needWaitAck = true; - } - return resp; -} - -#endif // ARM_GEN_ELEM_PRINTER_H_INCLUDED - -/* End of File gen_elem_printer.h */ diff --git a/decoder/tests/source/item_printer.h b/decoder/tests/source/item_printer.h deleted file mode 100644 index cc3ec37..0000000 --- a/decoder/tests/source/item_printer.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * \file item_printer.h - * \brief OpenCSD : - * - * \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. - */ - -#ifndef ARM_ITEM_PRINTER_H_INCLUDED -#define ARM_ITEM_PRINTER_H_INCLUDED - -#include "opencsd.h" -#include <string> - -class ItemPrinter -{ -public: - ItemPrinter(); - virtual ~ItemPrinter(); - - void setMessageLogger(ocsdMsgLogger *pMsgLogger) { m_pMsgLogger = pMsgLogger; }; - void itemPrintLine(const std::string &msg); - - // return wait for the first N packets - test the wait mechanism. - void setTestWaits(const int num_waits); - const int getTestWaits() const; - void decTestWaits(); - -protected: - ocsdMsgLogger *m_pMsgLogger; - int m_test_waits; -}; - -inline ItemPrinter::ItemPrinter() : - m_pMsgLogger(0), - m_test_waits(0) -{ -} - -inline ItemPrinter::~ItemPrinter() -{ - m_pMsgLogger = 0; -} - -inline void ItemPrinter::itemPrintLine(const std::string &msg) -{ - if(m_pMsgLogger) - m_pMsgLogger->LogMsg(msg); -} - -inline void ItemPrinter::setTestWaits(const int num_waits) -{ - m_test_waits = num_waits; -} - -inline const int ItemPrinter::getTestWaits() const -{ - return m_test_waits; -} - -inline void ItemPrinter::decTestWaits() -{ - m_test_waits--; -} - -#endif // ARM_ITEM_PRINTER_H_INCLUDED - -/* End of File item_printer.h */ diff --git a/decoder/tests/source/pkt_printer_t.h b/decoder/tests/source/pkt_printer_t.h deleted file mode 100644 index 8876ac6..0000000 --- a/decoder/tests/source/pkt_printer_t.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * \file pkt_printer_t.h - * \brief OpenCSD : Test packet printer. - * - * \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. - */ - -#ifndef ARM_PKT_PRINTER_T_H_INCLUDED -#define ARM_PKT_PRINTER_T_H_INCLUDED - -#include "opencsd.h" -#include "item_printer.h" - -#include <string> -#include <sstream> - -template<class P> -class PacketPrinter : public IPktDataIn<P>, public IPktRawDataMon<P>, public ItemPrinter -{ -public: - PacketPrinter(const uint8_t trcID); - PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger); - virtual ~PacketPrinter(); - - - virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const P *p_packet_in); - - virtual void RawPacketDataMon( const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const P *pkt, - const uint32_t size, - const uint8_t *p_data); - - -private: - void printIdx_ID(const ocsd_trc_index_t index_sop); - - uint8_t m_trcID; - bool m_bRawPrint; - std::ostringstream m_oss; - ocsd_datapath_resp_t m_last_resp; - -}; - -template<class P> PacketPrinter<P>::PacketPrinter(uint8_t trcID) : - m_trcID(trcID), - m_bRawPrint(false), - m_last_resp(OCSD_RESP_CONT) -{ -} - -template<class P> PacketPrinter<P>::PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger) : - m_trcID(trcID), - m_bRawPrint(false), - m_last_resp(OCSD_RESP_CONT) -{ - setMessageLogger(pMsgLogger); -} - -template<class P> PacketPrinter<P>::~PacketPrinter() -{ -} - -template<class P> ocsd_datapath_resp_t PacketPrinter<P>::PacketDataIn( const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const P *p_packet_in) -{ - std::string pktstr; - ocsd_datapath_resp_t resp = OCSD_RESP_CONT; - - // wait / flush test verification - if(!m_bRawPrint && (m_last_resp == OCSD_RESP_WAIT)) - { - // expect a flush or a complete reset after a wait. - if((op != OCSD_OP_FLUSH) || (op != OCSD_OP_RESET)) - { - m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tERROR: FLUSH operation expected after wait on trace decode path\n"; - itemPrintLine(m_oss.str()); - m_oss.str(""); - return OCSD_RESP_FATAL_INVALID_OP; - } - } - - switch(op) - { - case OCSD_OP_DATA: - p_packet_in->toString(pktstr); - if(!m_bRawPrint) - printIdx_ID(index_sop); - m_oss << ";\t" << pktstr << std::endl; - - // test the wait/flush response mechnism - if(getTestWaits() && !m_bRawPrint) - { - decTestWaits(); - resp = OCSD_RESP_WAIT; - } - break; - - case OCSD_OP_EOT: - m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tEND OF TRACE DATA\n"; - break; - - case OCSD_OP_FLUSH: - m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tFLUSH operation on trace decode path\n"; - break; - - case OCSD_OP_RESET: - m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tRESET operation on trace decode path\n"; - break; - } - - m_last_resp = resp; - itemPrintLine(m_oss.str()); - m_oss.str(""); - return resp; -} - -template<class P> void PacketPrinter<P>::RawPacketDataMon( const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const P *pkt, - const uint32_t size, - const uint8_t *p_data) -{ - switch(op) - { - case OCSD_OP_DATA: - printIdx_ID(index_sop); - m_oss << "; ["; - if((size > 0) && (p_data != 0)) - { - uint32_t data = 0; - for(uint32_t i = 0; i < size; i++) - { - data = (uint32_t)(p_data[i] & 0xFF); - m_oss << "0x" << std::hex << std::setw(2) << std::setfill('0') << data << " "; - } - } - m_oss << "]"; - m_bRawPrint = true; - PacketDataIn(op,index_sop,pkt); - m_bRawPrint = false; - break; - - default: - PacketDataIn(op,index_sop,pkt); - break; - } - -} - -template<class P> void PacketPrinter<P>::printIdx_ID(const ocsd_trc_index_t index_sop) -{ - m_oss << "Idx:" << std::dec << index_sop << "; ID:"<< std::hex << (uint32_t)m_trcID; -} - -#endif // ARM_PKT_PRINTER_T_H_INCLUDED - -/* End of File pkt_printer_t.h */ diff --git a/decoder/tests/source/raw_frame_printer.cpp b/decoder/tests/source/raw_frame_printer.cpp deleted file mode 100644 index f16c906..0000000 --- a/decoder/tests/source/raw_frame_printer.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * \file raw_frame_printer.cpp - * \brief OpenCSD : - * - * \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 <string> -#include <sstream> -#include <iomanip> - -#include "raw_frame_printer.h" - - -ocsd_err_t RawFramePrinter::TraceRawFrameIn( const ocsd_datapath_op_t op, - const ocsd_trc_index_t index, - const ocsd_rawframe_elem_t frame_element, - const int dataBlockSize, - const uint8_t *pDataBlock, - const uint8_t traceID) -{ - - if(op == OCSD_OP_DATA) // only interested in actual frame data. - { - std::string strData; - std::ostringstream oss; - int printDataSize = dataBlockSize; - - oss << "Frame Data; Index" << std::setw(7) << index << "; "; - switch(frame_element) - { - case OCSD_FRM_PACKED: oss << std::setw(15) << "RAW_PACKED; "; break; - case OCSD_FRM_HSYNC: oss << std::setw(15) << "HSYNC; "; break; - case OCSD_FRM_FSYNC: oss << std::setw(15) << "FSYNC; "; break; - case OCSD_FRM_ID_DATA: oss << std::setw(10) << "ID_DATA[0x" << std::hex << std::setw(2) << std::setfill('0') << (uint16_t)traceID << "]; "; break; - default: oss << std::setw(15) << "UNKNOWN; "; break; - } - - if(printDataSize) - { - createDataString(printDataSize,pDataBlock,16,strData); - oss << strData; - } - oss << std::endl; - itemPrintLine(oss.str()); - } - return OCSD_OK; -} - -void RawFramePrinter::createDataString(const int dataSize, const uint8_t *pData, int bytesPerLine, std::string &dataStr) -{ - int lineBytes = 0; - std::ostringstream oss; - - for(int i = 0; i < dataSize; i++) - { - if(lineBytes == bytesPerLine) - { - oss << std::endl; - lineBytes = 0; - } - oss << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)pData[i] << " "; - lineBytes ++; - } - dataStr = oss.str(); -} - - -/* End of File raw_frame_printer.cpp */ diff --git a/decoder/tests/source/raw_frame_printer.h b/decoder/tests/source/raw_frame_printer.h deleted file mode 100644 index 8fb41c2..0000000 --- a/decoder/tests/source/raw_frame_printer.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * \file raw_frame_printer.h - * \brief OpenCSD : - * - * \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. - */ - -#ifndef ARM_RAW_FRAME_PRINTER_H_INCLUDED -#define ARM_RAW_FRAME_PRINTER_H_INCLUDED - -#include "opencsd.h" -#include "item_printer.h" - -#include <string> -#include <sstream> - -class RawFramePrinter : public ITrcRawFrameIn, public ItemPrinter -{ -public: - RawFramePrinter() {}; - RawFramePrinter(ocsdMsgLogger *pMsgLogger); - virtual ~RawFramePrinter() {}; - - virtual ocsd_err_t TraceRawFrameIn( const ocsd_datapath_op_t op, - const ocsd_trc_index_t index, - const ocsd_rawframe_elem_t frame_element, - const int dataBlockSize, - const uint8_t *pDataBlock, - const uint8_t traceID); - -private: - void createDataString(const int dataSize, const uint8_t *pData, int bytesPerLine, std::string &dataStr); - -}; - -inline RawFramePrinter::RawFramePrinter(ocsdMsgLogger *pMsgLogger) -{ - setMessageLogger(pMsgLogger); -} - - -#endif // ARM_RAW_FRAME_PRINTER_H_INCLUDED - -/* End of File raw_frame_printer.h */ diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index 1839bc2..47a887e 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -44,11 +44,6 @@ #include "opencsd.h" // the library #include "trace_snapshots.h" // the snapshot reading test library
-// include some printers for packet elements -#include "pkt_printer_t.h" -#include "raw_frame_printer.h" -#include "gen_elem_printer.h" - static bool process_cmd_line_opts( int argc, char* argv[]); static void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader, const std::string &trace_buffer_name); static bool process_cmd_line_logger_opts(int argc, char* argv[]); @@ -170,7 +165,7 @@ int main(int argc, char* argv[]) else { std::ostringstream oss; - oss << "Trace Packet Lister : Snapshot path" << ss_path << "not found\n"; + oss << "Trace Packet Lister : Snapshot path" << ss_path << " not found\n"; logger.LogMsg(oss.str()); }
@@ -425,9 +420,10 @@ bool process_cmd_line_opts(int argc, char* argv[]) // if packet processing only, then waits will be coming from there until the count is extinguished // wait testing with packet processor only really works correctly if we are doing a single source as there is no way at this // point to know which source has sent the _WAIT. with multi packet processor waiting may get false warnings once the _WAITs run out. -bool ExpectingPPrintWaitResp(std::vector<ItemPrinter *> &printers, TrcGenericElementPrinter &genElemPrinter) +bool ExpectingPPrintWaitResp(TrcGenericElementPrinter &genElemPrinter) { bool ExpectingWaits = false; + std::vector<ItemPrinter *> &printers = PktPrinterFact::getPrinterList(); if(test_waits > 0) { // see if last response was from the Gen elem printer expecting a wait @@ -452,21 +448,26 @@ bool ExpectingPPrintWaitResp(std::vector<ItemPrinter *> &printers, TrcGenericEle return ExpectingWaits; }
-void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &printers) +void AttachPacketPrinters( DecodeTree *dcd_tree) { uint8_t elemID; + ocsd_trace_protocol_t protocol; + std::ostringstream oss; + // attach packet printers to each trace source in the tree DecodeTreeElement *pElement = dcd_tree->getFirstElement(elemID); while(pElement && !no_undecoded_packets) { if(!element_filtered(elemID)) { - switch(pElement->getProtocol()) + oss.str(""); + protocol = pElement->getProtocol(); + switch(protocol) { case OCSD_PROTOCOL_ETMV4I: { - std::ostringstream oss; - PacketPrinter<EtmV4ITrcPacket> *pPrinter = new (std::nothrow) PacketPrinter<EtmV4ITrcPacket>(elemID,&logger); + + PacketPrinter<EtmV4ITrcPacket> *pPrinter = dynamic_cast<PacketPrinter<EtmV4ITrcPacket> *>(PktPrinterFact::createProtocolPrinter(protocol,elemID,&logger)); if(pPrinter) { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. @@ -478,18 +479,17 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri if(test_waits) pPrinter->setTestWaits(test_waits); } - printers.push_back(pPrinter); // save printer to destroy it later + oss << "Trace Packet Lister : ETMv4 Instuction trace Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; } - - oss << "Trace Packet Lister : ETMv4 Instuction trace Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; + else + oss << "Trace Packet Lister : Failed to set printer for ETMv4 Instuction trace Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; logger.LogMsg(oss.str()); } break;
case OCSD_PROTOCOL_ETMV3: { - std::ostringstream oss; - PacketPrinter<EtmV3TrcPacket> *pPrinter = new (std::nothrow) PacketPrinter<EtmV3TrcPacket>(elemID,&logger); + PacketPrinter<EtmV3TrcPacket> *pPrinter = dynamic_cast<PacketPrinter<EtmV3TrcPacket> *>(PktPrinterFact::createProtocolPrinter(protocol, elemID, &logger)); if(pPrinter) { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. @@ -501,16 +501,16 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri if(test_waits) pPrinter->setTestWaits(test_waits); } - printers.push_back(pPrinter); // save printer to destroy it later - } - oss << "Trace Packet Lister : ETMv3 Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; + oss << "Trace Packet Lister : ETMv3 Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; + } + else + oss << "Trace Packet Lister : Failed to set printer for ETMv3 Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; logger.LogMsg(oss.str()); } break;
case OCSD_PROTOCOL_PTM: { - std::ostringstream oss; PacketPrinter<PtmTrcPacket> *pPrinter = new (std::nothrow) PacketPrinter<PtmTrcPacket>(elemID,&logger); if(pPrinter) { @@ -523,7 +523,6 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri if(test_waits) pPrinter->setTestWaits(test_waits); } - printers.push_back(pPrinter); // save printer to destroy it later } oss << "Trace Packet Lister : PTM Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; logger.LogMsg(oss.str()); @@ -533,7 +532,6 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri
case OCSD_PROTOCOL_STM: { - std::ostringstream oss; PacketPrinter<StmTrcPacket> *pPrinter = new (std::nothrow) PacketPrinter<StmTrcPacket>(elemID,&logger); if(pPrinter) { @@ -547,7 +545,6 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri pPrinter->setTestWaits(test_waits); }
- printers.push_back(pPrinter); // save printer to destroy it later } oss << "Trace Packet Lister : STM Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; logger.LogMsg(oss.str()); @@ -556,7 +553,6 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri
default: { - std::ostringstream oss; oss << "Trace Packet Lister : Unsupported Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; logger.LogMsg(oss.str()); } @@ -593,39 +589,46 @@ void ConfigureFrameDeMux(DecodeTree *dcd_tree, RawFramePrinter &framePrinter) void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader, const std::string &trace_buffer_name) { CreateDcdTreeFromSnapShot tree_creator; - RawFramePrinter framePrinter; - TrcGenericElementPrinter genElemPrinter; + RawFramePrinter *framePrinter = 0; + TrcGenericElementPrinter *genElemPrinter = 0; + + framePrinter = PktPrinterFact::createRawFramePrinter(&logger); + if (decode) + genElemPrinter = PktPrinterFact::createGenElemPrinter(&logger); + + if ((framePrinter == 0) || (decode && (genElemPrinter == 0))) + { + std::ostringstream oss; + oss << "Trace Packet Lister : failed to create printer objects\n"; + logger.LogMsg(oss.str()); + return; + }
- framePrinter.setMessageLogger(&logger); - tree_creator.initialise(&reader,&err_logger); - if(decode) - genElemPrinter.setMessageLogger(&logger); + tree_creator.initialise(&reader, &err_logger);
if(tree_creator.createDecodeTree(trace_buffer_name, (decode == false))) { - std::vector<ItemPrinter *> printers; DecodeTree *dcd_tree = tree_creator.getDecodeTree();
- AttachPacketPrinters(dcd_tree, printers); + AttachPacketPrinters(dcd_tree);
- ConfigureFrameDeMux(dcd_tree, framePrinter); + ConfigureFrameDeMux(dcd_tree, *framePrinter);
// if decoding set the generic element printer to the output interface on the tree. if(decode) { std::ostringstream oss; - dcd_tree->setGenTraceElemOutI(&genElemPrinter); + dcd_tree->setGenTraceElemOutI(genElemPrinter); oss << "Trace Packet Lister : Set trace element decode printer\n"; logger.LogMsg(oss.str()); - genElemPrinter.setTestWaits(test_waits); + genElemPrinter->setTestWaits(test_waits); }
- if(decode) dcd_tree->logMappedRanges(); // print out the mapped ranges
// check if we have attached at least one printer - if(decode || (printers.size() > 0)) + if(decode || (PktPrinterFact::numPrinters() > 0)) { // set up the filtering at the tree level (avoid pushing to processors with no attached printers) if(!all_source_ids) @@ -668,7 +671,7 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader trace_index += nUsedThisTime;
// test printers can inject _WAIT responses - see if we are expecting one... - if(ExpectingPPrintWaitResp(printers,genElemPrinter)) + if(ExpectingPPrintWaitResp(*genElemPrinter)) { if(OCSD_DATA_RESP_IS_CONT(dataPathResp)) { @@ -682,8 +685,8 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader else // last response was _WAIT { // may need to acknowledge a wait from the gen elem printer - if(genElemPrinter.needAckWait()) - genElemPrinter.ackWait(); + if(genElemPrinter->needAckWait()) + genElemPrinter->ackWait();
// dataPathResp not continue or fatal so must be wait... dataPathResp = dcd_tree->TraceDataIn(OCSD_OP_FLUSH,0,0,0,0); @@ -737,13 +740,7 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader tree_creator.destroyDecodeTree();
// get rid of all the printers. - std::vector<ItemPrinter *>::iterator it; - it = printers.begin(); - while(it != printers.end()) - { - delete *it; - it++; - } + PktPrinterFact::destroyAllPrinters(); } }