Adds packet printer create / attch interface to decode tree. Adds C-API functions to access new packet printer API. Updates tests to use new API.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/c_api/opencsd_c_api.h | 37 +++++- decoder/include/common/ocsd_dcd_tree.h | 18 ++- decoder/include/pkt_printers/trc_print_fact.h | 16 ++- decoder/source/c_api/ocsd_c_api.cpp | 32 ++--- decoder/source/ocsd_dcd_tree.cpp | 111 +++++++++++++++++- decoder/source/pkt_printers/trc_print_fact.cpp | 54 +++++---- decoder/tests/source/c_api_pkt_print_test.c | 29 ++++- decoder/tests/source/trc_pkt_lister.cpp | 156 +++++-------------------- 8 files changed, 273 insertions(+), 180 deletions(-)
diff --git a/decoder/include/c_api/opencsd_c_api.h b/decoder/include/c_api/opencsd_c_api.h index 4fc8379..f9f4ed4 100644 --- a/decoder/include/c_api/opencsd_c_api.h +++ b/decoder/include/c_api/opencsd_c_api.h @@ -397,14 +397,45 @@ OCSD_C_API void ocsd_gen_elem_init(ocsd_generic_trace_elem *p_pkt, const ocsd_ge /** @}*/
/** @name Library packet and data printer control API - @brief Allows client to use libraries packet and data printers to log packets etc rather than attach callbacks. + @brief Allows client to use libraries packet and data printers to log packets etc rather than attach callbacks + to packet output and use packet to string calls. @{*/
/*! * Set a raw frame printer on the trace frame demuxer. Allows inspection of raw trace data frames for debug. - * Prints via the default error logging mechanisms. + * Prints via the library default error logging mechanisms. + * + * The flags input determines the data printed. OR combination of one or both of: + * OCSD_DFRMTR_PACKED_RAW_OUT : Output the undemuxed raw data frames. + * OCSD_DFRMTR_UNPACKED_RAW_OUT : Output the raw data by trace ID after unpacking the frame. + * + * @param handle : Handle to decode tree. + * @param flags : indicates type of raw frames to print. + * + * @return ocsd_err_t : Library error code - RCDTL_OK if successful. + */ +OCSD_C_API ocsd_err_t ocsd_dt_set_raw_frame_printer(const dcd_tree_handle_t handle, int flags); + +/*! + * Set a library printer on the generic element output of a full decoder. + * + * @param handle : Handle to decode tree. + * + * @return ocsd_err_t : Library error code - RCDTL_OK if successful. + */ +OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_printer(const dcd_tree_handle_t handle); + +/*! + * Attach a library printer to the packet processor. May be attached to the main packet output, or the monitor + * output if the main packet output is to be attached to a packet decoder in the datapath. + * + * @param handle : Handle to decode tree. + * @param cs_id : Coresight trace ID for stream to print. + * @param monitor: 0 to attach printer directly to datapath packet output, 1 to attach to packet monitor output + * + * @return ocsd_err_t : Library error code - RCDTL_OK if successful. */ -OCSD_C_API ocsd_err_t ocsd_set_raw_frame_printer(const dcd_tree_handle_t handle, int flags); +OCSD_C_API ocsd_err_t ocsd_dt_set_pkt_protocol_printer(const dcd_tree_handle_t handle, uint8_t cs_id, int monitor);
/** @}*/
diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 1ab5fbc..496f8e5 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -83,7 +83,7 @@ public: /** @}*/
-/** @name Error Logging +/** @name Error and element Logging @{*/ /** @brief The library default error logger */ static ocsdDefaultErrorLogger* getDefaultErrorLogger() { return &s_error_logger; }; @@ -94,6 +94,20 @@ public: /** set an alternate error logging interface. */ static void setAlternateErrorLogger(ITraceErrorLog *p_error_logger);
+ /** get the list of packet printers for this decode tree */ + std::vector<ItemPrinter *> &getPrinterList() { return m_printer_list; }; + + /** add a protocol packet printer */ + ocsd_err_t addPacketPrinter(uint8_t CSID, bool bMonitor, ItemPrinter **ppPrinter); + + /** add a raw frame printer */ + ocsd_err_t addRawFramePrinter(RawFramePrinter **ppPrinter, uint32_t flags); + + /** add a generic element output printer */ + ocsd_err_t addGenElemPrinter(TrcGenericElementPrinter **ppPrinter); + + + /** @}*/
@@ -372,6 +386,8 @@ private: TrcMemAccMapper *m_default_mapper; //!< the mem acc mapper to use bool m_created_mapper; //!< true if created by decode tree object
+ std::vector<ItemPrinter *> m_printer_list; //!< list of packet printers. + /* global error logger - all sources */ static ITraceErrorLog *s_i_error_logger; static std::list<DecodeTree *> s_trace_dcd_trees; diff --git a/decoder/include/pkt_printers/trc_print_fact.h b/decoder/include/pkt_printers/trc_print_fact.h index 002d74c..73dd9dc 100644 --- a/decoder/include/pkt_printers/trc_print_fact.h +++ b/decoder/include/pkt_printers/trc_print_fact.h @@ -40,21 +40,19 @@ 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 ItemPrinter *createProtocolPrinter(std::vector<ItemPrinter *> &printer_list, ocsd_trace_protocol_t protocol, uint8_t elemID, ocsdMsgLogger *pMsgLogger = 0); + static RawFramePrinter *createRawFramePrinter(std::vector<ItemPrinter *> &printer_list, ocsdMsgLogger *pMsgLogger = 0); + static TrcGenericElementPrinter *createGenElemPrinter(std::vector<ItemPrinter *> &printer_list, ocsdMsgLogger *pMsgLogger = 0);
- static void destroyAllPrinters(); - static const int numPrinters(); - static std::vector<ItemPrinter *> &getPrinterList(); + static void destroyPrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter); + static void destroyAllPrinters(std::vector<ItemPrinter *> &printer_list); + static const int numPrinters(std::vector<ItemPrinter *> &printer_list);
private: - static void SavePrinter(ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger); + static void SavePrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger);
PktPrinterFact() {}; ~PktPrinterFact() {}; - - static std::vector<ItemPrinter *> sm_printers; /* list of printers created. */ };
#endif // ARM_TRC_PRINT_FACT_H_INCLUDED diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index 9794ffc..b866db8 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -434,23 +434,29 @@ OCSD_C_API void ocsd_gen_elem_init(ocsd_generic_trace_elem *p_pkt, const ocsd_ge p_pkt->ptr_extended_data = 0; }
-OCSD_C_API ocsd_err_t ocsd_set_raw_frame_printer(const dcd_tree_handle_t handle, int flags) +OCSD_C_API ocsd_err_t ocsd_dt_set_raw_frame_printer(const dcd_tree_handle_t handle, int flags) { if (handle != C_API_INVALID_TREE_HANDLE) + return ((DecodeTree *)handle)->addRawFramePrinter(0, (uint32_t)flags); + return OCSD_ERR_NOT_INIT; +} + +OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_printer(const dcd_tree_handle_t handle) +{ + if (handle != C_API_INVALID_TREE_HANDLE) + return ((DecodeTree *)handle)->addGenElemPrinter(0); + return OCSD_ERR_NOT_INIT; +} + +OCSD_C_API ocsd_err_t ocsd_dt_set_pkt_protocol_printer(const dcd_tree_handle_t handle, uint8_t cs_id, int monitor) +{ + ocsd_err_t err = OCSD_ERR_NOT_INIT; + if (handle != C_API_INVALID_TREE_HANDLE) { - RawFramePrinter *pPrinter = PktPrinterFact::createRawFramePrinter(); - if (pPrinter) - { - pPrinter->setMessageLogger((DecodeTree::getDefaultErrorLogger()->getOutputLogger())); - TraceFormatterFrameDecoder *pFrameDecoder = ((DecodeTree *)handle)->getFrameDeformatter(); - int cfgFlags = pFrameDecoder->getConfigFlags(); - cfgFlags |= ((uint32_t)flags & (OCSD_DFRMTR_PACKED_RAW_OUT | OCSD_DFRMTR_UNPACKED_RAW_OUT)); - pFrameDecoder->Configure(cfgFlags); - return pFrameDecoder->getTrcRawFrameAttachPt()->attach(pPrinter); - } - return OCSD_ERR_MEM; + DecodeTree *p_tree = (DecodeTree *)handle; + err = p_tree->addPacketPrinter(cs_id, (bool)(monitor != 0), 0); } - return OCSD_ERR_NOT_INIT; + return err; }
/*******************************************************************************/ diff --git a/decoder/source/ocsd_dcd_tree.cpp b/decoder/source/ocsd_dcd_tree.cpp index b6451d0..0cce134 100644 --- a/decoder/source/ocsd_dcd_tree.cpp +++ b/decoder/source/ocsd_dcd_tree.cpp @@ -109,7 +109,7 @@ DecodeTree::~DecodeTree() { destroyDecodeElement(i); } - + PktPrinterFact::destroyAllPrinters(m_printer_list); }
@@ -559,4 +559,113 @@ ocsd_err_t DecodeTree::clearIDFilter() return err; }
+/** add a protocol packet printer */ +ocsd_err_t DecodeTree::addPacketPrinter(uint8_t CSID, bool bMonitor, ItemPrinter **ppPrinter) +{ + ocsd_err_t err = OCSD_ERR_INVALID_PARAM_VAL; + DecodeTreeElement *pElement = getDecoderElement(CSID); + if (pElement) + { + ocsd_trace_protocol_t protocol = pElement->getProtocol(); + ItemPrinter *pPrinter; + + pPrinter = PktPrinterFact::createProtocolPrinter(getPrinterList(), protocol, CSID); + if (pPrinter) + { + pPrinter->setMessageLogger(getCurrentErrorLogI()->getOutputLogger()); + switch (protocol) + { + case OCSD_PROTOCOL_ETMV4I: + { + PacketPrinter<EtmV4ITrcPacket> *pTPrinter = dynamic_cast<PacketPrinter<EtmV4ITrcPacket> *>(pPrinter); + if (bMonitor) + err = pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(), (IPktRawDataMon<EtmV4ITrcPacket> *)pTPrinter); + else + err = pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(), (IPktDataIn<EtmV4ITrcPacket> *)pTPrinter); + } + break; + + case OCSD_PROTOCOL_ETMV3: + { + PacketPrinter<EtmV3TrcPacket> *pTPrinter = dynamic_cast<PacketPrinter<EtmV3TrcPacket> *>(pPrinter); + if (bMonitor) + err = pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(), (IPktRawDataMon<EtmV3TrcPacket> *)pTPrinter); + else + err = pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(), (IPktDataIn<EtmV3TrcPacket> *)pTPrinter); + } + break; + + case OCSD_PROTOCOL_PTM: + { + PacketPrinter<PtmTrcPacket> *pTPrinter = dynamic_cast<PacketPrinter<PtmTrcPacket> *>(pPrinter); + if (bMonitor) + err = pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(), (IPktRawDataMon<PtmTrcPacket> *)pTPrinter); + else + err = pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(), (IPktDataIn<PtmTrcPacket> *)pTPrinter); + } + break; + + case OCSD_PROTOCOL_STM: + { + PacketPrinter<StmTrcPacket> *pTPrinter = dynamic_cast<PacketPrinter<StmTrcPacket> *>(pPrinter); + if (bMonitor) + err = pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(), (IPktRawDataMon<StmTrcPacket> *)pTPrinter); + else + err = pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(), (IPktDataIn<StmTrcPacket> *)pTPrinter); + } + break; + + default: + err = OCSD_ERR_NO_PROTOCOL; + break; + } + + if (err == OCSD_OK) + { + if (ppPrinter) + *ppPrinter = pPrinter; + } + else + PktPrinterFact::destroyPrinter(getPrinterList(), pPrinter); + } + } + return err; +} + +/** add a raw frame printer */ +ocsd_err_t DecodeTree::addRawFramePrinter(RawFramePrinter **ppPrinter, uint32_t flags) +{ + ocsd_err_t err = OCSD_ERR_MEM; + RawFramePrinter *pPrinter = PktPrinterFact::createRawFramePrinter(getPrinterList()); + if (pPrinter) + { + pPrinter->setMessageLogger((DecodeTree::getCurrentErrorLogI()->getOutputLogger())); + TraceFormatterFrameDecoder *pFrameDecoder = getFrameDeformatter(); + uint32_t cfgFlags = pFrameDecoder->getConfigFlags(); + cfgFlags |= ((uint32_t)flags & (OCSD_DFRMTR_PACKED_RAW_OUT | OCSD_DFRMTR_UNPACKED_RAW_OUT)); + pFrameDecoder->Configure(cfgFlags); + err = pFrameDecoder->getTrcRawFrameAttachPt()->attach(pPrinter); + if (ppPrinter && (err==OCSD_OK)) + *ppPrinter = pPrinter; + } + return err; +} + +/** add a generic element output printer */ +ocsd_err_t DecodeTree::addGenElemPrinter(TrcGenericElementPrinter **ppPrinter) +{ + ocsd_err_t err = OCSD_ERR_MEM; + TrcGenericElementPrinter *pPrinter = PktPrinterFact::createGenElemPrinter(getPrinterList()); + if (pPrinter) + { + pPrinter->setMessageLogger((DecodeTree::getCurrentErrorLogI()->getOutputLogger())); + setGenTraceElemOutI(pPrinter); + err = OCSD_OK; + if (ppPrinter) + *ppPrinter = pPrinter; + } + return err; + +} + /* End of File ocsd_dcd_tree.cpp */ diff --git a/decoder/source/pkt_printers/trc_print_fact.cpp b/decoder/source/pkt_printers/trc_print_fact.cpp index 39d770d..52dcb6b 100644 --- a/decoder/source/pkt_printers/trc_print_fact.cpp +++ b/decoder/source/pkt_printers/trc_print_fact.cpp @@ -35,25 +35,23 @@
#include "pkt_printers/trc_print_fact.h"
-std::vector<ItemPrinter *> PktPrinterFact::sm_printers; - -RawFramePrinter * PktPrinterFact::createRawFramePrinter(ocsdMsgLogger *pMsgLogger /*= 0*/) +RawFramePrinter * PktPrinterFact::createRawFramePrinter(std::vector<ItemPrinter *> &printer_list, ocsdMsgLogger *pMsgLogger /*= 0*/) { RawFramePrinter *pPrinter = 0; pPrinter = new (std::nothrow)RawFramePrinter(); - SavePrinter(pPrinter, pMsgLogger); + SavePrinter(printer_list, pPrinter, pMsgLogger); return pPrinter; }
-TrcGenericElementPrinter *PktPrinterFact::createGenElemPrinter(ocsdMsgLogger *pMsgLogger /*= 0*/) +TrcGenericElementPrinter *PktPrinterFact::createGenElemPrinter(std::vector<ItemPrinter *> &printer_list, ocsdMsgLogger *pMsgLogger /*= 0*/) { TrcGenericElementPrinter *pPrinter = 0; pPrinter = new (std::nothrow)TrcGenericElementPrinter(); - SavePrinter(pPrinter, pMsgLogger); + SavePrinter(printer_list, pPrinter, pMsgLogger); return pPrinter; }
-ItemPrinter *PktPrinterFact::createProtocolPrinter(ocsd_trace_protocol_t protocol, uint8_t CSID, ocsdMsgLogger *pMsgLogger /*= 0*/) +ItemPrinter *PktPrinterFact::createProtocolPrinter(std::vector<ItemPrinter *> &printer_list, ocsd_trace_protocol_t protocol, uint8_t CSID, ocsdMsgLogger *pMsgLogger /*= 0*/) { ItemPrinter *pPrinter = 0; switch (protocol) @@ -73,39 +71,53 @@ ItemPrinter *PktPrinterFact::createProtocolPrinter(ocsd_trace_protocol_t protoco default: break; } - SavePrinter(pPrinter, pMsgLogger); + SavePrinter(printer_list, pPrinter, pMsgLogger); return pPrinter; }
-const int PktPrinterFact::numPrinters() -{ - return sm_printers.size(); -} - -std::vector<ItemPrinter *> &PktPrinterFact::getPrinterList() +const int PktPrinterFact::numPrinters(std::vector<ItemPrinter *> &printer_list) { - return sm_printers; + return printer_list.size(); }
-void PktPrinterFact::SavePrinter(ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger) +void PktPrinterFact::SavePrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger) { if (pPrinter) { pPrinter->setMessageLogger(pMsgLogger); - sm_printers.push_back((ItemPrinter *)pPrinter); + printer_list.push_back((ItemPrinter *)pPrinter); } }
-void PktPrinterFact::destroyAllPrinters() +void PktPrinterFact::destroyAllPrinters(std::vector<ItemPrinter *> &printer_list) { std::vector<ItemPrinter *>::iterator it; - it = sm_printers.begin(); - while (it != sm_printers.end()) + it = printer_list.begin(); + while (it != printer_list.end()) { delete *it; it++; } - sm_printers.clear(); + printer_list.clear(); }
+void PktPrinterFact::destroyPrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter) +{ + std::vector<ItemPrinter *>::iterator it; + it = printer_list.begin(); + while (it != printer_list.end()) + { + if (*it == pPrinter) + { + printer_list.erase(it); + delete pPrinter; + return; + } + else + it++; + } +} + + + /* end of file trc_print_fact.cpp */ diff --git a/decoder/tests/source/c_api_pkt_print_test.c b/decoder/tests/source/c_api_pkt_print_test.c index 7ae09f6..1390b62 100644 --- a/decoder/tests/source/c_api_pkt_print_test.c +++ b/decoder/tests/source/c_api_pkt_print_test.c @@ -107,6 +107,9 @@ static int frame_raw_unpacked = 0; static int frame_raw_packed = 0; static int test_printstr = 0;
+/* test the library printer API */ +static int test_lib_printers = 0; + /* Process command line options - choose the operation to use for the test. */ static int process_cmd_line(int argc, char *argv[]) { @@ -174,6 +177,10 @@ static int process_cmd_line(int argc, char *argv[]) { test_printstr = 1; } + else if (strcmp(argv[idx], "-test_libprint") == 0) + { + test_lib_printers = 1; + } else if(strcmp(argv[idx],"-help") == 0) { return -1; @@ -191,6 +198,7 @@ static void print_cmd_line_help() printf("-id <ID> : decode source for id <ID> (default 0x10)\n"); printf("-decode | -decode_only : full decode + trace packets / full decode packets only (default trace packets only)\n"); printf("-raw / -raw_packed: print raw unpacked / packed data;\n"); + printf("-test_printstr | -test_libprint : ttest lib printstr callback | test lib based packet printers\n"); printf("-test_region_file | -test_cb : mem accessor - test multi region file API | test callback API (default single memory file)\n\n"); }
@@ -514,7 +522,10 @@ static ocsd_err_t create_generic_decoder(dcd_tree_handle_t handle, const char *p if(ret == OCSD_OK) { /* Attach the packet handler to the output of the packet processor - referenced by CSID */ - ret = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,&packet_handler,p_context); + if (test_lib_printers) + ret = ocsd_dt_set_pkt_protocol_printer(handle, CSID, 0); + else + ret = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,&packet_handler,p_context); if(ret != OCSD_OK) ocsd_dt_remove_decoder(handle,CSID); /* if the attach failed then destroy the decoder. */ } @@ -533,7 +544,10 @@ static ocsd_err_t create_generic_decoder(dcd_tree_handle_t handle, const char *p * print the packets as well as the decode - use the packet processors monitor * output this time, as the main output is attached to the packet decoder. */ - ret = ocsd_dt_attach_packet_callback(handle,CSID,OCSD_C_API_CB_PKT_MON,packet_monitor,p_context); + if (test_lib_printers) + ret = ocsd_dt_set_pkt_protocol_printer(handle, CSID, 1); + else + ret = ocsd_dt_attach_packet_callback(handle,CSID,OCSD_C_API_CB_PKT_MON,packet_monitor,p_context); }
/* attach a memory accessor */ @@ -690,7 +704,7 @@ static ocsd_err_t attach_raw_printers(dcd_tree_handle_t dcd_tree_h) flags |= OCSD_DFRMTR_PACKED_RAW_OUT; if (flags) { - err = ocsd_set_raw_frame_printer(dcd_tree_h, flags); + err = ocsd_dt_set_raw_frame_printer(dcd_tree_h, flags); } return err; } @@ -822,9 +836,14 @@ int process_trace_data(FILE *pf) ret = create_decoder(dcdtree_handle); ocsd_tl_log_mapped_mem_ranges(dcdtree_handle);
- if(ret == OCSD_OK) + if (ret == OCSD_OK) + { /* attach the generic trace element output callback */ - ret = ocsd_dt_set_gen_elem_outfn(dcdtree_handle,gen_trace_elem_print,0); + if (test_lib_printers) + ret = ocsd_dt_set_gen_elem_printer(dcdtree_handle); + else + ret = ocsd_dt_set_gen_elem_outfn(dcdtree_handle, gen_trace_elem_print, 0); + }
/* raw print and str print cb options tested in their init functions */ diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index 47a887e..854f158 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -420,10 +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(TrcGenericElementPrinter &genElemPrinter) +bool ExpectingPPrintWaitResp(DecodeTree *dcd_tree, TrcGenericElementPrinter &genElemPrinter) { bool ExpectingWaits = false; - std::vector<ItemPrinter *> &printers = PktPrinterFact::getPrinterList(); + std::vector<ItemPrinter *> &printers = dcd_tree->getPrinterList(); if(test_waits > 0) { // see if last response was from the Gen elem printer expecting a wait @@ -451,7 +451,6 @@ bool ExpectingPPrintWaitResp(TrcGenericElementPrinter &genElemPrinter) 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 @@ -461,112 +460,28 @@ void AttachPacketPrinters( DecodeTree *dcd_tree) if(!element_filtered(elemID)) { oss.str(""); - protocol = pElement->getProtocol(); - switch(protocol) - { - case OCSD_PROTOCOL_ETMV4I: - { - - 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. - if(decode || pkt_mon) - pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<EtmV4ITrcPacket> *)pPrinter); - else - { - pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<EtmV4ITrcPacket> *)pPrinter); - if(test_waits) - pPrinter->setTestWaits(test_waits); - } - 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: - { - 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. - if(decode || pkt_mon) - pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<EtmV3TrcPacket> *)pPrinter); - else - { - pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<EtmV3TrcPacket> *)pPrinter); - if(test_waits) - pPrinter->setTestWaits(test_waits); - } - 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: - { - PacketPrinter<PtmTrcPacket> *pPrinter = new (std::nothrow) PacketPrinter<PtmTrcPacket>(elemID,&logger); - if(pPrinter) - { - // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. - if(decode || pkt_mon) - pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<PtmTrcPacket> *)pPrinter); - else - { - pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<PtmTrcPacket> *)pPrinter); - if(test_waits) - pPrinter->setTestWaits(test_waits); - } - } - oss << "Trace Packet Lister : PTM Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; - logger.LogMsg(oss.str()); - } - break;
+ ItemPrinter *pPrinter; + ocsd_err_t err = dcd_tree->addPacketPrinter(elemID, (bool)(decode || pkt_mon),&pPrinter); + if (err == OCSD_OK) + { + // if not decoding or monitor only + if((!(decode || pkt_mon)) && test_waits) + pPrinter->setTestWaits(test_waits);
- case OCSD_PROTOCOL_STM: - { - PacketPrinter<StmTrcPacket> *pPrinter = new (std::nothrow) PacketPrinter<StmTrcPacket>(elemID,&logger); - if(pPrinter) - { - // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. - if(decode || pkt_mon) - pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<StmTrcPacket> *)pPrinter); - else - { - pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<StmTrcPacket> *)pPrinter); - if(test_waits) - pPrinter->setTestWaits(test_waits); - } - - } - oss << "Trace Packet Lister : STM Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; - logger.LogMsg(oss.str()); - } - break; - - default: - { - oss << "Trace Packet Lister : Unsupported Protocol on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; - logger.LogMsg(oss.str()); - } - break; + oss << "Trace Packet Lister : Protocol printer " << pElement->getDecoderTypeName() << " on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; + } + else + oss << "Trace Packet Lister : Failed to Protocol printer " << pElement->getDecoderTypeName() << " on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; + logger.LogMsg(oss.str());
- // TBD : handle other protocol types. - } } pElement = dcd_tree->getNextElement(elemID); }
}
-void ConfigureFrameDeMux(DecodeTree *dcd_tree, RawFramePrinter &framePrinter) +void ConfigureFrameDeMux(DecodeTree *dcd_tree, RawFramePrinter **framePrinter) { // configure the frame deformatter, and attach a frame printer to the frame deformatter if needed TraceFormatterFrameDecoder *pDeformatter = dcd_tree->getFrameDeformatter(); @@ -575,50 +490,40 @@ void ConfigureFrameDeMux(DecodeTree *dcd_tree, RawFramePrinter &framePrinter) // configuration - memory alinged buffer uint32_t configFlags = OCSD_DFRMTR_FRAME_MEM_ALIGN;
- // if we want the raw frames output - if(outRawPacked || outRawUnpacked) + pDeformatter->Configure(configFlags); + if (outRawPacked || outRawUnpacked) { - pDeformatter->getTrcRawFrameAttachPt()->attach(&framePrinter); - if(outRawPacked) configFlags |= OCSD_DFRMTR_PACKED_RAW_OUT; - if(outRawUnpacked) configFlags |= OCSD_DFRMTR_UNPACKED_RAW_OUT; + if (outRawPacked) configFlags |= OCSD_DFRMTR_PACKED_RAW_OUT; + if (outRawUnpacked) configFlags |= OCSD_DFRMTR_UNPACKED_RAW_OUT; + dcd_tree->addRawFramePrinter(framePrinter, configFlags); } - pDeformatter->Configure(configFlags); } }
void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader, const std::string &trace_buffer_name) { CreateDcdTreeFromSnapShot tree_creator; - 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; - }
tree_creator.initialise(&reader, &err_logger);
if(tree_creator.createDecodeTree(trace_buffer_name, (decode == false))) { DecodeTree *dcd_tree = tree_creator.getDecodeTree(); + dcd_tree->setAlternateErrorLogger(&err_logger); + + RawFramePrinter *framePrinter = 0; + TrcGenericElementPrinter *genElemPrinter = 0;
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); + dcd_tree->addGenElemPrinter(&genElemPrinter); oss << "Trace Packet Lister : Set trace element decode printer\n"; logger.LogMsg(oss.str()); genElemPrinter->setTestWaits(test_waits); @@ -628,7 +533,7 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader dcd_tree->logMappedRanges(); // print out the mapped ranges
// check if we have attached at least one printer - if(decode || (PktPrinterFact::numPrinters() > 0)) + if(decode || (PktPrinterFact::numPrinters(dcd_tree->getPrinterList()) > 0)) { // set up the filtering at the tree level (avoid pushing to processors with no attached printers) if(!all_source_ids) @@ -671,7 +576,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(*genElemPrinter)) + if(ExpectingPPrintWaitResp(dcd_tree, *genElemPrinter)) { if(OCSD_DATA_RESP_IS_CONT(dataPathResp)) { @@ -738,9 +643,6 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader
// get rid of the decode tree. tree_creator.destroyDecodeTree(); - - // get rid of all the printers. - PktPrinterFact::destroyAllPrinters(); } }