Add in function to generate config class from config structure via the decoder manager interface.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/ocsd_dcd_mngr.h | 26 ++++++++++++++++++++++++++ decoder/include/common/ocsd_dcd_mngr_i.h | 3 +++ decoder/include/common/ocsd_dcd_tree_elem.h | 7 +++---- decoder/include/common/ocsd_lib_dcd_register.h | 11 ++++++++--- decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 1 + decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 1 + decoder/include/ocsd_if_types.h | 25 +++++++++++++++++++++++-- decoder/include/opencsd.h | 3 ++- decoder/include/ptm/trc_dcd_mngr_ptm.h | 1 + decoder/include/stm/trc_dcd_mngr_stm.h | 1 + decoder/source/ocsd_lib_dcd_register.cpp | 25 +++++++++++++++++++++++++ 11 files changed, 94 insertions(+), 10 deletions(-)
diff --git a/decoder/include/common/ocsd_dcd_mngr.h b/decoder/include/common/ocsd_dcd_mngr.h index 0e6222a..487e1db 100644 --- a/decoder/include/common/ocsd_dcd_mngr.h +++ b/decoder/include/common/ocsd_dcd_mngr.h @@ -70,10 +70,15 @@ public: // data input connection interface virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
+// generate a Config object from opaque config struct pointer. + virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct); + // implemented by decoder handler derived classes virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0; virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; }; + virtual CSConfig *createConfig(const void *pDataStruct) = 0;
+ private: ocsd_trace_protocol_t m_builtInProtocol; //!< Protocol ID if built in type. }; @@ -298,6 +303,15 @@ ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, I return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i); }
+template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct) +{ + CSConfig *pConfig = createConfig(pDataStruct); + if(!pConfig) + return OCSD_ERR_MEM; + *pConfigBase = pConfig; + return OCSD_OK; +}
/****************************************************************************************************/ /* Full decoder / packet process pair, templated base for creating decoder objects */ @@ -306,6 +320,7 @@ ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, I template< class P, // Packet class. class Pt, // Packet enum type ID. class Pc, // Processor config class. + class PcSt, // Processor config struct type class PktProc, // Packet processor class. class PktDcd> // Packet decoder class. class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc> @@ -335,6 +350,11 @@ public: pComp = new (std::nothrow)PktDcd(); return pComp; } + + virtual CSConfig *createConfig(const void *pDataStruct) + { + return new (std::nothrow) Pc((PcSt *)pDataStruct); + } };
/****************************************************************************************************/ @@ -344,6 +364,7 @@ public: template< class P, // Packet class. class Pt, // Packet enum type ID. class Pc, // Processor config class. + class PcSt, // Processor config struct type class PktProc> // Packet processor class. class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc> { @@ -362,6 +383,11 @@ public: pComp = new (std::nothrow) PktProc(); return pComp; } + + virtual CSConfig *createConfig(const void *pDataStruct) + { + return new (std::nothrow) Pc((PcSt *)pDataStruct); + } };
diff --git a/decoder/include/common/ocsd_dcd_mngr_i.h b/decoder/include/common/ocsd_dcd_mngr_i.h index 3e6abe2..f6adb06 100644 --- a/decoder/include/common/ocsd_dcd_mngr_i.h +++ b/decoder/include/common/ocsd_dcd_mngr_i.h @@ -88,6 +88,9 @@ public: //! get raw data input interface from packet processor virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn) = 0;
+// create configuration from data structure + virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct) = 0; + };
#endif // ARM_OCSD_DCD_MNGR_I_H_INCLUDED diff --git a/decoder/include/common/ocsd_dcd_tree_elem.h b/decoder/include/common/ocsd_dcd_tree_elem.h index 6969816..82c2159 100644 --- a/decoder/include/common/ocsd_dcd_tree_elem.h +++ b/decoder/include/common/ocsd_dcd_tree_elem.h @@ -43,9 +43,8 @@ * @addtogroup dcd_tree * * Element describes the protocol supported for this element and - * contains pointers to packet processor and decoder for the protocol. - * - * Union of all recognised decoders, plus an attachment point for an external decoder. + * contains pointers to the decoder manager interface and component handle. + * */ typedef struct _decoder_elements { @@ -92,7 +91,7 @@ inline void DecodeTreeElement::SetDecoderElement(const std::string &name, IDecod dcd_name = name; dcd_mngr = dcdMngr; dcd_handle = pHandle; - protocol = OCSD_PROTOCOL_EXTERN; + protocol = OCSD_PROTOCOL_UNKNOWN; if(dcd_mngr) protocol = dcd_mngr->getProtocolType(); created = bCreated; diff --git a/decoder/include/common/ocsd_lib_dcd_register.h b/decoder/include/common/ocsd_lib_dcd_register.h index dc5fd42..d059214 100644 --- a/decoder/include/common/ocsd_lib_dcd_register.h +++ b/decoder/include/common/ocsd_lib_dcd_register.h @@ -60,17 +60,22 @@ public:
const ocsd_err_t registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact); //!< register a decoder manager interface const ocsd_err_t getDecoderMngrByName(const std::string &name, IDecoderMngr **p_decoder_mngr); + const ocsd_err_t getDecoderMngrByType(const ocsd_trace_protocol_t decoderType, IDecoderMngr **p_decoder_mngr);
const bool isRegisteredDecoder(const std::string &name); const bool getFirstNamedDecoder(std::string &name); const bool getNextNamedDecoder(std::string &name);
+ const bool isRegisteredDecoderType(const ocsd_trace_protocol_t decoderType); + private: void registerBuiltInDecoders(); //!< register the list of build in decoder managers on first access of getDecoderMngrByName.
- std::map<const std::string, IDecoderMngr *> m_decoder_mngrs; //!< map linking names to decoder manager interfaces. - std::map<const std::string, IDecoderMngr *>::const_iterator m_iter; //!< iterator for name search. - + std::map<const std::string, IDecoderMngr *> m_decoder_mngrs; //!< map linking names to decoder manager interfaces. + std::map<const std::string, IDecoderMngr *>::const_iterator m_iter; //!< iterator for name search. + + std::map<const ocsd_trace_protocol_t, IDecoderMngr *> m_typed_decoder_mngrs; //!< map linking decoder managers to protocol type ID + // singleton pattern - need just one of these in the library - ensure all default constructors are private. OcsdLibDcdRegister(); OcsdLibDcdRegister(OcsdLibDcdRegister const &) {}; diff --git a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h index 3ace535..c3a96ff 100644 --- a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h +++ b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h @@ -43,6 +43,7 @@ class DecoderMngrEtmV3 : public DecodeMngrFullDcd< EtmV3TrcPacket, ocsd_etmv3_pkt_type, EtmV3Config, + ocsd_etmv3_cfg, TrcPktProcEtmV3, TrcPktDecodeEtmV3> { diff --git a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h index 7c4802f..a5b2540 100644 --- a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h +++ b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h @@ -17,6 +17,7 @@ class DecoderMngrEtmV4I : public DecodeMngrFullDcd< EtmV4ITrcPacket, ocsd_etmv4_i_pkt_type, EtmV4Config, + ocsd_etmv4_cfg, TrcPktProcEtmV4I, TrcPktDecodeEtmV4I> { diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index d214f76..7e17f04 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -489,16 +489,37 @@ typedef uint32_t (* Fn_MemAcc_CB)(const void *p_context, const ocsd_vaddr_t add /*! Trace Protocol Builtin Types + extern */ typedef enum _ocsd_trace_protocol_t { - OCSD_PROTOCOL_EXTERN, /**< Custom external decoder attached to the decode tree - protocol unknown */ + OCSD_PROTOCOL_UNKNOWN = 0, /**< Protocol unknown */ + +/* Built in library decoders */ OCSD_PROTOCOL_ETMV3, /**< ETMV3 instruction and data trace protocol decoder. */ OCSD_PROTOCOL_ETMV4I, /**< ETMV4 instruction trace protocol decoder. */ OCSD_PROTOCOL_ETMV4D, /**< ETMV4 data trace protocol decoder. */ OCSD_PROTOCOL_PTM, /**< PTM program flow instruction trace protocol decoder. */ OCSD_PROTOCOL_STM, /**< STM system trace protocol decoder. */ - /* others to be added here */ + +/* others to be added here */ + OCSD_PROTOCOL_BUILTIN_END, /**< Invalid protocol - built-in protocol types end marker */ + +/* Custom / external decoders */ + OCSD_PROTOCOL_CUSTOM_0 = 100, + OCSD_PROTOCOL_CUSTOM_1, + OCSD_PROTOCOL_CUSTOM_2, + OCSD_PROTOCOL_CUSTOM_3, + OCSD_PROTOCOL_CUSTOM_4, + OCSD_PROTOCOL_CUSTOM_5, + OCSD_PROTOCOL_CUSTOM_6, + OCSD_PROTOCOL_CUSTOM_7, + OCSD_PROTOCOL_CUSTOM_8, + OCSD_PROTOCOL_CUSTOM_9, + OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ } ocsd_trace_protocol_t;
+#define OCSD_PROTOCOL_IS_BUILTIN(P) ((P > OCSD_PROTOCOL_UNKNOWN) && (P < OCSD_PROTOCOL_BUILTIN_END)) +#define OCSD_PROTOCOL_IS_CUSTOM(P) ((P > OCSD_PROTOCOL_CUSTOM_0) && (P < OCSD_PROTOCOL_END )) + + /** @}*/
/** @}*/ diff --git a/decoder/include/opencsd.h b/decoder/include/opencsd.h index fed2eaf..9ae283b 100644 --- a/decoder/include/opencsd.h +++ b/decoder/include/opencsd.h @@ -73,7 +73,8 @@ #include "i_dec/trc_i_decode.h" #include "mem_acc/trc_mem_acc.h"
-/** The decode tree */ +/** The decode tree and decoder register*/ +#include "common/ocsd_lib_dcd_register.h" #include "common/ocsd_dcd_tree.h"
diff --git a/decoder/include/ptm/trc_dcd_mngr_ptm.h b/decoder/include/ptm/trc_dcd_mngr_ptm.h index 121edfd..0defb0d 100644 --- a/decoder/include/ptm/trc_dcd_mngr_ptm.h +++ b/decoder/include/ptm/trc_dcd_mngr_ptm.h @@ -43,6 +43,7 @@ class DecoderMngrPtm : public DecodeMngrFullDcd< PtmTrcPacket, ocsd_ptm_pkt_type, PtmConfig, + ocsd_ptm_cfg, TrcPktProcPtm, TrcPktDecodePtm> { diff --git a/decoder/include/stm/trc_dcd_mngr_stm.h b/decoder/include/stm/trc_dcd_mngr_stm.h index 7705d3c..740925d 100644 --- a/decoder/include/stm/trc_dcd_mngr_stm.h +++ b/decoder/include/stm/trc_dcd_mngr_stm.h @@ -42,6 +42,7 @@ class DecoderMngrStm : public DecodeMngrPktProc< StmTrcPacket, ocsd_stm_pkt_type, STMConfig, + ocsd_stm_cfg, TrcPktProcStm> { public: diff --git a/decoder/source/ocsd_lib_dcd_register.cpp b/decoder/source/ocsd_lib_dcd_register.cpp index 053f256..ff1cc0f 100644 --- a/decoder/source/ocsd_lib_dcd_register.cpp +++ b/decoder/source/ocsd_lib_dcd_register.cpp @@ -70,6 +70,7 @@ OcsdLibDcdRegister::OcsdLibDcdRegister() OcsdLibDcdRegister::~OcsdLibDcdRegister() { m_decoder_mngrs.clear(); + m_typed_decoder_mngrs.clear(); }
@@ -78,6 +79,7 @@ const ocsd_err_t OcsdLibDcdRegister::registerDecoderTypeByName(const std::string if(isRegisteredDecoder(name)) return OCSD_ERR_DCDREG_NAME_REPEAT; m_decoder_mngrs.emplace(std::pair<const std::string, IDecoderMngr *>(name,p_decoder_fact)); + m_typed_decoder_mngrs.emplace(std::pair<const ocsd_trace_protocol_t, IDecoderMngr *>(p_decoder_fact->getProtocolType(),p_decoder_fact)); return OCSD_OK; }
@@ -121,6 +123,21 @@ const ocsd_err_t OcsdLibDcdRegister::getDecoderMngrByName(const std::string &nam return OCSD_OK; }
+const ocsd_err_t OcsdLibDcdRegister::getDecoderMngrByType(const ocsd_trace_protocol_t decoderType, IDecoderMngr **p_decoder_mngr) +{ + if(!m_b_registeredBuiltins) + { + registerBuiltInDecoders(); + if(!m_b_registeredBuiltins) + return OCSD_ERR_MEM; + } + std::map<const ocsd_trace_protocol_t, IDecoderMngr *>::const_iterator iter = m_typed_decoder_mngrs.find(decoderType); + if(iter != m_typed_decoder_mngrs.end()) + return OCSD_ERR_DCDREG_NAME_UNKNOWN; + *p_decoder_mngr = iter->second; + return OCSD_OK; +} + const bool OcsdLibDcdRegister::isRegisteredDecoder(const std::string &name) { std::map<const std::string, IDecoderMngr *>::const_iterator iter = m_decoder_mngrs.find(name); @@ -129,6 +146,14 @@ const bool OcsdLibDcdRegister::isRegisteredDecoder(const std::string &name) return false; }
+const bool OcsdLibDcdRegister::isRegisteredDecoderType(const ocsd_trace_protocol_t decoderType) +{ + std::map<const ocsd_trace_protocol_t, IDecoderMngr *>::const_iterator iter = m_typed_decoder_mngrs.find(decoderType); + if(iter != m_typed_decoder_mngrs.end()) + return true; + return false; +} + const bool OcsdLibDcdRegister::getFirstNamedDecoder(std::string &name) { m_iter = m_decoder_mngrs.begin();