diff options
author | Mike Leach <mike.leach@linaro.org> | 2016-08-19 16:50:59 +0100 |
---|---|---|
committer | Mike Leach <mike.leach@linaro.org> | 2016-09-19 11:28:53 +0100 |
commit | ff1ac8cd7947e9f1eb7f3e2967cfd091e1ba0e05 (patch) | |
tree | 24743fd0dc27456b8deb69989e1cd1c2fe8dd2f1 | |
parent | 6b86cd53451b69c679acc08c36d608989928b491 (diff) |
opencsd: Update to ensure that the C packet structure is used in C API.
The ETMv3 packet C++ object has the C packet stuct encapsulated rather than
as a base class. This resulted in the wrong pointer value being passed out to
the C API. This has been corrected using a base packet class interface to
explicitly get a pointer to the C struct declared for the C API interface.
Signed-off-by: Mike Leach <mike.leach@linaro.org>
-rw-r--r-- | decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj | 1 | ||||
-rw-r--r-- | decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters | 3 | ||||
-rw-r--r-- | decoder/include/common/trc_pkt_elem_base.h | 49 | ||||
-rw-r--r-- | decoder/include/common/trc_printable_elem.h | 4 | ||||
-rw-r--r-- | decoder/include/etmv3/trc_pkt_elem_etmv3.h | 7 | ||||
-rw-r--r-- | decoder/include/etmv4/trc_pkt_elem_etmv4d.h | 4 | ||||
-rw-r--r-- | decoder/include/etmv4/trc_pkt_elem_etmv4i.h | 5 | ||||
-rw-r--r-- | decoder/include/ptm/trc_pkt_elem_ptm.h | 5 | ||||
-rw-r--r-- | decoder/include/stm/trc_pkt_elem_stm.h | 5 | ||||
-rw-r--r-- | decoder/source/c_api/ocsd_c_api.cpp | 25 | ||||
-rw-r--r-- | decoder/source/c_api/ocsd_c_api_obj.h | 14 |
11 files changed, 98 insertions, 24 deletions
diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj index fa1a9127b706..65e066c1dac6 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj @@ -322,6 +322,7 @@ <ClInclude Include="..\..\..\include\common\trc_frame_deformatter.h" /> <ClInclude Include="..\..\..\include\common\trc_gen_elem.h" /> <ClInclude Include="..\..\..\include\common\trc_pkt_decode_base.h" /> + <ClInclude Include="..\..\..\include\common\trc_pkt_elem_base.h" /> <ClInclude Include="..\..\..\include\common\trc_pkt_proc_base.h" /> <ClInclude Include="..\..\..\include\common\trc_printable_elem.h" /> <ClInclude Include="..\..\..\include\etmv3\etmv3_decoder.h" /> diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters index d267c31dee68..e95490f18045 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters @@ -317,6 +317,9 @@ <ClInclude Include="..\..\..\include\stm\trc_dcd_mngr_stm.h"> <Filter>Header Files\stm</Filter> </ClInclude> + <ClInclude Include="..\..\..\include\common\trc_pkt_elem_base.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\trc_component.cpp"> diff --git a/decoder/include/common/trc_pkt_elem_base.h b/decoder/include/common/trc_pkt_elem_base.h new file mode 100644 index 000000000000..07604a664210 --- /dev/null +++ b/decoder/include/common/trc_pkt_elem_base.h @@ -0,0 +1,49 @@ +/* + * \file trc_pkt_elem_base.h + * \brief Reference CoreSight Trace Decoder : + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ +#ifndef ARM_TRC_PKT_ELEM_BASE_H_INCLUDED +#define ARM_TRC_PKT_ELEM_BASE_H_INCLUDED + +/* + * 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. + */ + +class TrcPacketBase +{ +public: + TrcPacketBase() {}; + virtual ~TrcPacketBase() {} + + //! return the underlying C API packet structure + virtual const void *c_pkt() const = 0; +}; + +#endif // ARM_TRC_PKT_ELEM_BASE_H_INCLUDED + +/* End of File trc_pkt_elem_base.h */
\ No newline at end of file diff --git a/decoder/include/common/trc_printable_elem.h b/decoder/include/common/trc_printable_elem.h index 2a9e09d214e2..92a47e882b1a 100644 --- a/decoder/include/common/trc_printable_elem.h +++ b/decoder/include/common/trc_printable_elem.h @@ -77,10 +77,10 @@ inline void trcPrintableElem::toStringFmt(const uint32_t /*fmtFlags*/, std::stri /** static template string function - used in "C" API to provide generic printing */ template<class Pc, class Pt> -void trcPrintElemToString(const Pt *p_pkt, std::string &str) +void trcPrintElemToString(const void *p_pkt, std::string &str) { Pc pktClass; - pktClass = p_pkt; + pktClass = static_cast<const Pt *>(p_pkt); pktClass.toString(str); } diff --git a/decoder/include/etmv3/trc_pkt_elem_etmv3.h b/decoder/include/etmv3/trc_pkt_elem_etmv3.h index 68438f98f2b5..a874ea30c861 100644 --- a/decoder/include/etmv3/trc_pkt_elem_etmv3.h +++ b/decoder/include/etmv3/trc_pkt_elem_etmv3.h @@ -38,6 +38,7 @@ #include "trc_pkt_types_etmv3.h" #include "common/trc_printable_elem.h" +#include "common/trc_pkt_elem_base.h" /** @addtogroup trc_pkts @{*/ @@ -49,7 +50,7 @@ * This class represents a single ETMv3 trace packet, along with intra packet state. * */ -class EtmV3TrcPacket : public trcPrintableElem +class EtmV3TrcPacket : public TrcPacketBase, public trcPrintableElem { public: EtmV3TrcPacket(); @@ -58,10 +59,14 @@ public: // conversions between C-API struct and C++ object types // assign from C-API struct EtmV3TrcPacket &operator =(const ocsd_etmv3_pkt* p_pkt); + // allow const cast to C-API struct to pass C++ object operator const ocsd_etmv3_pkt*() const { return &m_pkt_data; }; operator const ocsd_etmv3_pkt&() const { return m_pkt_data; }; + // override c_pkt to pass out the packet data struct. + virtual const void *c_pkt() const { return &m_pkt_data; }; + // update interface - set packet values void Clear(); //!< clear update data in packet ready for new one. void ResetState(); //!< reset intra packet state data -on full decoder reset. diff --git a/decoder/include/etmv4/trc_pkt_elem_etmv4d.h b/decoder/include/etmv4/trc_pkt_elem_etmv4d.h index 029700fdc6e9..bb6a0029c0c0 100644 --- a/decoder/include/etmv4/trc_pkt_elem_etmv4d.h +++ b/decoder/include/etmv4/trc_pkt_elem_etmv4d.h @@ -37,6 +37,8 @@ #include "trc_pkt_types_etmv4.h" #include "common/trc_printable_elem.h" +#include "common/trc_pkt_elem_base.h" + /** @addtogroup trc_pkts @{*/ /*! @@ -46,7 +48,7 @@ * This class represents a single ETMv4 instruction trace packet, along with intra packet state. * */ -class EtmV4DTrcPacket : public ocsd_etmv4_d_pkt, trcPrintableElem +class EtmV4DTrcPacket : public TrcPacketBase, public ocsd_etmv4_d_pkt, trcPrintableElem { public: EtmV4DTrcPacket(); diff --git a/decoder/include/etmv4/trc_pkt_elem_etmv4i.h b/decoder/include/etmv4/trc_pkt_elem_etmv4i.h index 0d624988c41a..91cc8686f55f 100644 --- a/decoder/include/etmv4/trc_pkt_elem_etmv4i.h +++ b/decoder/include/etmv4/trc_pkt_elem_etmv4i.h @@ -38,6 +38,7 @@ #include "trc_pkt_types_etmv4.h" #include "common/trc_printable_elem.h" +#include "common/trc_pkt_elem_base.h" /** @addtogroup trc_pkts @{*/ @@ -50,7 +51,7 @@ * This class represents a single ETMv4 data trace packet, along with intra packet state. * */ -class EtmV4ITrcPacket : public ocsd_etmv4_i_pkt, public trcPrintableElem +class EtmV4ITrcPacket : public TrcPacketBase, public ocsd_etmv4_i_pkt, public trcPrintableElem { public: EtmV4ITrcPacket(); @@ -58,6 +59,8 @@ public: EtmV4ITrcPacket &operator =(const ocsd_etmv4_i_pkt* p_pkt); + virtual const void *c_pkt() const { return (const ocsd_etmv4_i_pkt *)this; }; + // update interface - set packet values void initStartState(); //!< Set to initial state - no intra packet state valid. Use on start of trace / discontinuities. void initNextPacket(); //!< clear any single packet only flags / state. diff --git a/decoder/include/ptm/trc_pkt_elem_ptm.h b/decoder/include/ptm/trc_pkt_elem_ptm.h index 91e467e6a1a9..266bd2b692a0 100644 --- a/decoder/include/ptm/trc_pkt_elem_ptm.h +++ b/decoder/include/ptm/trc_pkt_elem_ptm.h @@ -39,12 +39,13 @@ #include "trc_pkt_types_ptm.h" #include "common/trc_printable_elem.h" +#include "common/trc_pkt_elem_base.h" /** @addtogroup trc_pkts @{*/ -class PtmTrcPacket : public ocsd_ptm_pkt, trcPrintableElem +class PtmTrcPacket : public TrcPacketBase, public ocsd_ptm_pkt, trcPrintableElem { public: PtmTrcPacket(); @@ -52,6 +53,8 @@ public: PtmTrcPacket &operator =(const ocsd_ptm_pkt* p_pkt); + virtual const void *c_pkt() const { return (const ocsd_ptm_pkt *)this; }; + // update interface - set packet values void Clear(); //!< clear update data in packet ready for new one. diff --git a/decoder/include/stm/trc_pkt_elem_stm.h b/decoder/include/stm/trc_pkt_elem_stm.h index 5b30ebe2560b..79c95957a5b4 100644 --- a/decoder/include/stm/trc_pkt_elem_stm.h +++ b/decoder/include/stm/trc_pkt_elem_stm.h @@ -37,6 +37,7 @@ #include "trc_pkt_types_stm.h" #include "common/trc_printable_elem.h" +#include "common/trc_pkt_elem_base.h" /*! * @class StmTrcPacket @@ -49,7 +50,7 @@ * Based on data structure ocsd_stm_pkt. * */ -class StmTrcPacket : public ocsd_stm_pkt, public trcPrintableElem +class StmTrcPacket : public TrcPacketBase, public ocsd_stm_pkt, public trcPrintableElem { public: StmTrcPacket(); @@ -57,6 +58,8 @@ public: StmTrcPacket &operator =(const ocsd_stm_pkt *p_pkt); + virtual const void *c_pkt() const { return (const ocsd_stm_pkt *)this; }; + void initStartState(); //!< Initialise packet state at start of decoder. void initNextPacket(); //!< Initialise state for next packet. diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index 591e9d4019bb..dbb70494ac81 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -288,20 +288,19 @@ OCSD_C_API ocsd_err_t ocsd_pkt_str(const ocsd_trace_protocol_t pkt_protocol, con switch(pkt_protocol) { case OCSD_PROTOCOL_ETMV4I: - trcPrintElemToString<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(static_cast<const ocsd_etmv4_i_pkt *>(p_pkt), pktStr); - //EtmV4ITrcPacket::toString(static_cast<ocsd_etmv4_i_pkt *>(p_pkt), pktStr); + trcPrintElemToString<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(p_pkt, pktStr); break; case OCSD_PROTOCOL_ETMV3: - trcPrintElemToString<EtmV3TrcPacket,ocsd_etmv3_pkt>(static_cast<const ocsd_etmv3_pkt *>(p_pkt), pktStr); + trcPrintElemToString<EtmV3TrcPacket,ocsd_etmv3_pkt>(p_pkt, pktStr); break; case OCSD_PROTOCOL_STM: - trcPrintElemToString<StmTrcPacket,ocsd_stm_pkt>(static_cast<const ocsd_stm_pkt *>(p_pkt), pktStr); + trcPrintElemToString<StmTrcPacket,ocsd_stm_pkt>(p_pkt, pktStr); break; case OCSD_PROTOCOL_PTM: - trcPrintElemToString<PtmTrcPacket,ocsd_ptm_pkt>(static_cast<const ocsd_ptm_pkt *>(p_pkt), pktStr); + trcPrintElemToString<PtmTrcPacket,ocsd_ptm_pkt>(p_pkt, pktStr); break; default: @@ -409,19 +408,19 @@ static ocsd_err_t ocsd_create_pkt_sink_cb(ocsd_trace_protocol_t protocol, FnDef switch(protocol) { case OCSD_PROTOCOL_ETMV4I: - *ppCBObj = new (std::nothrow) PktCBObj<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktCBObj<EtmV4ITrcPacket>(pPktInFn,p_context); break; case OCSD_PROTOCOL_ETMV3: - *ppCBObj = new (std::nothrow) PktCBObj<EtmV3TrcPacket,ocsd_etmv3_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktCBObj<EtmV3TrcPacket>(pPktInFn,p_context); break; case OCSD_PROTOCOL_PTM: - *ppCBObj = new (std::nothrow) PktCBObj<PtmTrcPacket,ocsd_ptm_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktCBObj<PtmTrcPacket>(pPktInFn,p_context); break; case OCSD_PROTOCOL_STM: - *ppCBObj = new (std::nothrow) PktCBObj<StmTrcPacket,ocsd_stm_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktCBObj<StmTrcPacket>(pPktInFn,p_context); break; default: @@ -443,19 +442,19 @@ static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPk switch(protocol) { case OCSD_PROTOCOL_ETMV4I: - *ppCBObj = new (std::nothrow) PktMonCBObj<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktMonCBObj<EtmV4ITrcPacket>(pPktInFn,p_context); break; case OCSD_PROTOCOL_ETMV3: - *ppCBObj = new (std::nothrow) PktMonCBObj<EtmV3TrcPacket,ocsd_etmv3_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktMonCBObj<EtmV3TrcPacket>(pPktInFn,p_context); break; case OCSD_PROTOCOL_PTM: - *ppCBObj = new (std::nothrow) PktMonCBObj<PtmTrcPacket,ocsd_ptm_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktMonCBObj<PtmTrcPacket>(pPktInFn,p_context); break; case OCSD_PROTOCOL_STM: - *ppCBObj = new (std::nothrow) PktMonCBObj<StmTrcPacket,ocsd_stm_pkt>(pPktInFn,p_context); + *ppCBObj = new (std::nothrow) PktMonCBObj<StmTrcPacket>(pPktInFn,p_context); break; default: diff --git a/decoder/source/c_api/ocsd_c_api_obj.h b/decoder/source/c_api/ocsd_c_api_obj.h index e6f901d45ffb..e3757840a310 100644 --- a/decoder/source/c_api/ocsd_c_api_obj.h +++ b/decoder/source/c_api/ocsd_c_api_obj.h @@ -36,7 +36,7 @@ private: -template<class TrcPkt, class TrcPktStruct> +template<class TrcPkt> class PktCBObj : public IPktDataIn<TrcPkt> { public: @@ -52,7 +52,10 @@ public: const ocsd_trc_index_t index_sop, const TrcPkt *p_packet_in) { - return m_c_api_cb_fn(m_p_context,op,index_sop,(TrcPktStruct *)p_packet_in); + const void *c_pkt_struct = 0; + if(op == OCSD_OP_DATA) + c_pkt_struct = p_packet_in->c_pkt(); // always output the c struct packet + return m_c_api_cb_fn(m_p_context,op,index_sop,c_pkt_struct); }; private: @@ -61,7 +64,7 @@ private: }; -template<class TrcPkt, class TrcPktStruct> +template<class TrcPkt> class PktMonCBObj : public IPktRawDataMon<TrcPkt> { public: @@ -79,7 +82,10 @@ public: const uint32_t size, const uint8_t *p_data) { - m_c_api_cb_fn(m_p_context,op,index_sop,(TrcPktStruct *)p_packet_in,size,p_data); + const void *c_pkt_struct = 0; + if(op == OCSD_OP_DATA) + c_pkt_struct = p_packet_in->c_pkt(); // always output the c struct packet + m_c_api_cb_fn(m_p_context,op,index_sop,c_pkt_struct,size,p_data); }; private: |