On 1 August 2016 at 07:19, Mike Leach mike.leach@linaro.org wrote:
Adds new create by name functions to C API, using the new decoder name register API.
Removes the protocol specific decoder create functions from the main API.
Allow previous protocol specific functions be used as a deprecated API on compile time #define to allow for regression testing.
test program: re-write to simplify and use the new create-by-name functionality. Add -help command to print available command line options.
Signed-off-by: Mike Leach mike.leach@linaro.org
.../win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj | 2 + .../rctdl_c_api_lib.vcxproj.filters | 6 + .../ref_trace_decode_lib/ref_trace_decode_lib.sln | 25 +- decoder/include/c_api/ocsd_c_api_deprc_fn.h | 175 +++++ decoder/include/c_api/ocsd_c_api_types.h | 26 +- decoder/include/c_api/opencsd_c_api.h | 172 ++--- decoder/source/c_api/ocsd_c_api.cpp | 443 ++++------- decoder/source/c_api/ocsd_c_api_deprc_fn.cpp | 200 +++++ decoder/source/c_api/ocsd_c_api_obj.h | 57 ++ .../c_api_pkt_print_test.vcxproj | 325 ++++++++ .../c_api_pkt_print_test.vcxproj.filters | 22 + decoder/tests/source/c_api_pkt_print_test.c | 825 +++++++++++++++++++++ decoder/tests/source/simple_pkt_c_api.c | 1 + 13 files changed, 1839 insertions(+), 440 deletions(-) create mode 100644 decoder/include/c_api/ocsd_c_api_deprc_fn.h create mode 100644 decoder/source/c_api/ocsd_c_api_deprc_fn.cpp create mode 100644 decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj create mode 100644 decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj.filters create mode 100644 decoder/tests/source/c_api_pkt_print_test.c
diff --git a/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj b/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj index ec0f0b7..f1019c1 100644 --- a/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj +++ b/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj @@ -296,6 +296,7 @@ </Link>
</ItemDefinitionGroup> <ItemGroup> + <ClInclude Include="..\..\..\include\c_api\ocsd_c_api_deprc_fn.h" /> <ClInclude Include="..\..\..\include\c_api\ocsd_c_api_types.h" /> <ClInclude Include="..\..\..\include\c_api\opencsd_c_api.h" /> <ClInclude Include="..\..\..\source\c_api\ocsd_c_api_obj.h" /> @@ -307,6 +308,7 @@ </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\c_api\ocsd_c_api.cpp" /> + <ClCompile Include="..\..\..\source\c_api\ocsd_c_api_deprc_fn.cpp" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj.filters b/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj.filters index b75f980..6b0484c 100644 --- a/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj.filters +++ b/decoder/build/win/rctdl_c_api_lib/rctdl_c_api_lib.vcxproj.filters @@ -24,10 +24,16 @@ <ClInclude Include="..\..\..\source\c_api\ocsd_c_api_obj.h"> <Filter>Source Files</Filter> </ClInclude> + <ClInclude Include="..\..\..\include\c_api\ocsd_c_api_deprc_fn.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\c_api\ocsd_c_api.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\c_api\ocsd_c_api_deprc_fn.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.sln b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.sln index 9795338..fbeae9b 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.sln +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.sln @@ -1,9 +1,9 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ref_trace_decode_lib", "ref_trace_decode_lib.vcxproj", "{7F500891-CC76-405F-933F-F682BC39F923}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opencsd_lib", "ref_trace_decode_lib.vcxproj", "{7F500891-CC76-405F-933F-F682BC39F923}"
What is this for? Does it have to be part of the library? Can it be published?
EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rctdl_c_api_lib", "..\rctdl_c_api_lib\rctdl_c_api_lib.vcxproj", "{533F929A-A73B-46B6-9D5F-FFCD62F734E3}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ocsd_c_api_lib", "..\rctdl_c_api_lib\rctdl_c_api_lib.vcxproj", "{533F929A-A73B-46B6-9D5F-FFCD62F734E3}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "snapshot_parser_lib", "......\tests\build\win\snapshot_parser_lib\snapshot_parser_lib.vcxproj", "{DE1F395D-4F53-42FB-8AEF-993A4BF7E411}" EndProject @@ -14,6 +14,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple_pkt_print_c_api", ". {533F929A-A73B-46B6-9D5F-FFCD62F734E3} = {533F929A-A73B-46B6-9D5F-FFCD62F734E3} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c_api_pkt_print_test", "......\tests\build\win\c_api_pkt_print_test\c_api_pkt_print_test.vcxproj", "{3AC169DA-E156-4D16-95DF-73D7302A5606}"
ProjectSection(ProjectDependencies) = postProject
{533F929A-A73B-46B6-9D5F-FFCD62F734E3} = {533F929A-A73B-46B6-9D5F-FFCD62F734E3}
EndProjectSection
+EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -98,6 +103,22 @@ Global {D18112ED-E2D7-4D49-B1F0-15E98967AC0A}.Release-dll|Win32.Build.0 = Release-dll|Win32 {D18112ED-E2D7-4D49-B1F0-15E98967AC0A}.Release-dll|x64.ActiveCfg = Release-dll|x64 {D18112ED-E2D7-4D49-B1F0-15E98967AC0A}.Release-dll|x64.Build.0 = Release-dll|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug|Win32.ActiveCfg = Debug|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug|Win32.Build.0 = Debug|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug|x64.ActiveCfg = Debug|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug|x64.Build.0 = Debug|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug-dll|Win32.ActiveCfg = Debug-dll|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug-dll|Win32.Build.0 = Debug-dll|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug-dll|x64.ActiveCfg = Debug-dll|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Debug-dll|x64.Build.0 = Debug-dll|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release|Win32.ActiveCfg = Release|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release|Win32.Build.0 = Release|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release|x64.ActiveCfg = Release|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release|x64.Build.0 = Release|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release-dll|Win32.ActiveCfg = Release-dll|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release-dll|Win32.Build.0 = Release-dll|Win32
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release-dll|x64.ActiveCfg = Release-dll|x64
{3AC169DA-E156-4D16-95DF-73D7302A5606}.Release-dll|x64.Build.0 = Release-dll|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE
diff --git a/decoder/include/c_api/ocsd_c_api_deprc_fn.h b/decoder/include/c_api/ocsd_c_api_deprc_fn.h new file mode 100644 index 0000000..70986ff --- /dev/null +++ b/decoder/include/c_api/ocsd_c_api_deprc_fn.h @@ -0,0 +1,175 @@ +/*!
- \file ocsd_c_api_deprc_fn.h
- \brief OpenCSD : Deprecated C-API functions
- \copyright Copyright (c) 2016, 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:
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 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.
- 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_OCSD_C_API_DEPRC_FN_H_INCLUDED +#define ARM_OCSD_C_API_DEPRC_FN_H_INCLUDED
+/** @name Deprecated C-API functions +@{*/
+/*---------------------- ETMv4 Trace ----------------------------------------------------------------------------------*/ +/*!
- Create an ETMv4 instruction trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the etmv4 packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *etmv4_cfg : pointer to valid Etmv4 configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function..
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t handle, const void *etmv4_cfg, FnEtmv4IPacketDataIn pPktFn, const void *p_context);
+/*!
- Creates a packet processor + packet decoder pair for the supplied configuration structure.
- Uses the output function set in ocsd_dt_set_gen_elem_outfn() as the output sink.
- @param handle : Handle to decode tree.
- @param *etmv4_cfg : pointer to valid Etmv4 configuration structure.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_decoder(const dcd_tree_handle_t handle, const void *etmv4_cfg);
+/*!
- Attach a callback function to the packet processor monitor point defined by the CoreSight ID.
- @param handle : Handle to decode tree.
- @param trc_chan_id : CoreSight Trace ID for packet processor
- @param pPktFn : Function to attach to monitor point.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv4IPktMonDataIn pPktFn, const void *p_context);
+/*---------------------- ETMv3 trace ----------------------------------------------------------------------------------*/ +/*!
- Create an ETMv3 trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the etmv3 packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *etmv3_cfg : pointer to valid Etmv3 configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t handle, const void *etmv3_cfg, FnEtmv3PacketDataIn pPktFn, const void *p_context);
+/*!
- Creates a packet processor + packet decoder pair for the supplied configuration structure.
- Uses the output function set in ocsd_dt_set_gen_elem_outfn() as the output sink.
- @param handle : Handle to decode tree.
- @param *etmv4_cfg : pointer to valid Etmv4 configuration structure.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_decoder(const dcd_tree_handle_t handle, const void *etmv3_cfg);
+/*!
- Attach a callback function to the packet processor monitor point defined by the CoreSight ID.
- Packet processor must exist for the trace ID and be an ETMv3 processor.
- @param handle : Handle to decode tree.
- @param trc_chan_id : CoreSight Trace ID for packet processor
- @param pPktFn : Function to attach to monitor point.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv3PktMonDataIn pPktFn, const void *p_context);
+/*---------------------- PTM Trace ----------------------------------------------------------------------------------*/ +/*!
- Create an PTM instruction trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the ptm packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *ptm_cfg : pointer to valid Ptm configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function..
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t handle, const void *ptm_cfg, FnPtmPacketDataIn pPktFn, const void *p_context);
+/*!
- Creates a packet processor + packet decoder pair for the supplied configuration structure.
- Uses the output function set in ocsd_dt_set_gen_elem_outfn() as the output sink.
- @param handle : Handle to decode tree.
- @param *ptm_cfg : pointer to valid Ptm configuration structure.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle, const void *ptm_cfg);
+/*!
- Attach a callback function to the packet processor monitor point defined by the CoreSight ID.
- @param handle : Handle to decode tree.
- @param trc_chan_id : CoreSight Trace ID for packet processor
- @param pPktFn : Function to attach to monitor point.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnPtmPktMonDataIn pPktFn, const void *p_context);
+/*---------------------- STM Trace ----------------------------------------------------------------------------------*/ +/*!
- Create an STM trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the stm packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *stm_cfg : pointer to valid Stm configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
+OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t handle, const void *stm_cfg, FnStmPacketDataIn pPktFn, const void *p_context);
+/** @}*/
+#endif // ARM_OCSD_C_API_DEPRC_FN_H_INCLUDED
+/* End of File ocsd_c_api_deprc_fn.h */ diff --git a/decoder/include/c_api/ocsd_c_api_types.h b/decoder/include/c_api/ocsd_c_api_types.h index a58a67e..1e98255 100644 --- a/decoder/include/c_api/ocsd_c_api_types.h +++ b/decoder/include/c_api/ocsd_c_api_types.h @@ -58,7 +58,6 @@ typedef void * dcd_tree_handle_t; /** define invalid handle value for decode tree handle */ #define C_API_INVALID_TREE_HANDLE (dcd_tree_handle_t)0
/** Logger output printer - no output. */ #define C_API_MSGLOGOUT_FLG_NONE 0x0 /** Logger output printer - output to file. */ @@ -71,7 +70,24 @@ typedef void * dcd_tree_handle_t; #define C_API_MSGLOGOUT_MASK 0x7
/** function pointer type for decoder outputs. all protocols, generic data element input */ -typedef ocsd_datapath_resp_t (* FnTraceElemIn)(const void *p_context, const ocsd_trc_index_t index_sop, const uint8_t trc_chan_id, const ocsd_generic_trace_elem *elem); +typedef ocsd_datapath_resp_t (* FnTraceElemIn)( const void *p_context,
const ocsd_trc_index_t index_sop,
const uint8_t trc_chan_id,
const ocsd_generic_trace_elem *elem);
+/** function pointer type for packet processor packet output sink, packet analyser/decoder input - generic declaration */ +typedef ocsd_datapath_resp_t (* FnDefPktDataIn)(const void *p_context,
const ocsd_datapath_op_t op,
const ocsd_trc_index_t index_sop,
const void *p_packet_in);
+/** function pointer type for packet processor packet monitor sink, raw packet monitor / display input - generic declaration */ +typedef void (* FnDefPktDataMon)(const void *p_context,
const ocsd_datapath_op_t op,
const ocsd_trc_index_t index_sop,
const void *p_packet_in,
const uint32_t size,
const uint8_t *p_data);
/** function pointer type for ETMv4 instruction packet processor output, packet analyser/decoder input */ typedef ocsd_datapath_resp_t (* FnEtmv4IPacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_etmv4_i_pkt *p_packet_in); @@ -127,6 +143,12 @@ typedef struct _file_mem_region { size_t region_size; /**< size in bytes of memory region */ } file_mem_region_t;
+typedef enum _ocsd_c_api_cb_types {
- OCSD_C_API_CB_PKT_SINK,
- OCSD_C_API_CB_PKT_MON,
+} ocsd_c_api_cb_types;
/** @}*/
#endif // ARM_OCSD_C_API_TYPES_H_INCLUDED diff --git a/decoder/include/c_api/opencsd_c_api.h b/decoder/include/c_api/opencsd_c_api.h index 5574f19..7c0648a 100644 --- a/decoder/include/c_api/opencsd_c_api.h +++ b/decoder/include/c_api/opencsd_c_api.h @@ -147,144 +147,68 @@ OCSD_C_API ocsd_datapath_resp_t ocsd_dt_process_data(const dcd_tree_handle_t han
- A single function is used for all trace source IDs in the decode tree.
- @param handle : Handle to decode tree.
- @param pFn : Pointer to the callback functions.
- @param pFn : Pointer to the callback function.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
*/
- @return ocsd_err_t : Library error code - OCSD_OK if successful.
OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_outfn(const dcd_tree_handle_t handle, FnTraceElemIn pFn, const void *p_context);
-/*---------------------- ETMv4 Trace ----------------------------------------------------------------------------------*/ +/*---------------------- Trace Decoders ----------------------------------------------------------------------------------*/ /*!
- Create an ETMv4 instruction trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the etmv4 packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *etmv4_cfg : pointer to valid Etmv4 configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function..
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t handle, const void *etmv4_cfg, FnEtmv4IPacketDataIn pPktFn, const void *p_context); +* <Detailed description of the method> +* +* @param handle : Handle to decode tree. +* @param *decoder_name : +* @param create_flags : +* @param *decoder_cfg : +* @param *pCSID : Pointer to location to return the configured CoreSight trace ID for the decoder. +* +* @return ocsd_err_t : +*/ +OCSD_C_API ocsd_err_t ocsd_dt_create_decoder(const dcd_tree_handle_t handle,
const char *decoder_name,
const int create_flags,
const void *decoder_cfg,
unsigned char *pCSID
);
/*!
- Creates a packet processor + packet decoder pair for the supplied configuration structure.
- Uses the output function set in ocsd_dt_set_gen_elem_outfn() as the output sink.
- @param handle : Handle to decode tree.
- @param *etmv4_cfg : pointer to valid Etmv4 configuration structure.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_decoder(const dcd_tree_handle_t handle, const void *etmv4_cfg); +* <Detailed description of the method> +* +* @param handle : Handle to decode tree. +* @param CSID : Configured CoreSight trace ID for the decoder. +* +* @return ocsd_err_t : +*/ +OCSD_C_API ocsd_err_t ocsd_dt_remove_decoder( const dcd_tree_handle_t handle,
const unsigned char CSID);
-/*!
- Attach a callback function to the packet processor monitor point defined by the CoreSight ID.
- @param handle : Handle to decode tree.
- @param trc_chan_id : CoreSight Trace ID for packet processor
- @param pPktFn : Function to attach to monitor point.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv4IPktMonDataIn pPktFn, const void *p_context);
-/*---------------------- ETMv3 trace ----------------------------------------------------------------------------------*/ /*!
- Create an ETMv3 trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the etmv3 packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *etmv3_cfg : pointer to valid Etmv3 configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t handle, const void *etmv3_cfg, FnEtmv3PacketDataIn pPktFn, const void *p_context); +* Attach a callback function to the packet processor. +* +* The callback_type defines the attachment point:- +* +* +* @param handle : Handle to decode tree. +* @param CSID : Configured CoreSight trace ID for the decoder. +* @param callback_type : +* @param p_fn_pkt_data_in : Pointer to the callback function. +* @param p_context : Opaque context pointer value used in callback function. +* +* @return ocsd_err_t : +*/ +OCSD_C_API ocsd_err_t ocsd_dt_attach_packet_callback( const dcd_tree_handle_t handle,
const unsigned char CSID,
const ocsd_c_api_cb_types callback_type,
void *p_fn_callback_data,
const void *p_context);
-/*!
- Creates a packet processor + packet decoder pair for the supplied configuration structure.
- Uses the output function set in ocsd_dt_set_gen_elem_outfn() as the output sink.
- @param handle : Handle to decode tree.
- @param *etmv4_cfg : pointer to valid Etmv4 configuration structure.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_decoder(const dcd_tree_handle_t handle, const void *etmv3_cfg);
-/*!
- Attach a callback function to the packet processor monitor point defined by the CoreSight ID.
- Packet processor must exist for the trace ID and be an ETMv3 processor.
- @param handle : Handle to decode tree.
- @param trc_chan_id : CoreSight Trace ID for packet processor
- @param pPktFn : Function to attach to monitor point.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv3PktMonDataIn pPktFn, const void *p_context);
-/*---------------------- PTM Trace ----------------------------------------------------------------------------------*/ -/*!
- Create an PTM instruction trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the ptm packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *ptm_cfg : pointer to valid Ptm configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function..
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t handle, const void *ptm_cfg, FnPtmPacketDataIn pPktFn, const void *p_context);
-/*!
- Creates a packet processor + packet decoder pair for the supplied configuration structure.
- Uses the output function set in ocsd_dt_set_gen_elem_outfn() as the output sink.
- @param handle : Handle to decode tree.
- @param *ptm_cfg : pointer to valid Ptm configuration structure.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle, const void *ptm_cfg);
-/*!
- Attach a callback function to the packet processor monitor point defined by the CoreSight ID.
- @param handle : Handle to decode tree.
- @param trc_chan_id : CoreSight Trace ID for packet processor
- @param pPktFn : Function to attach to monitor point.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnPtmPktMonDataIn pPktFn, const void *p_context);
-/*---------------------- STM Trace ----------------------------------------------------------------------------------*/ -/*!
- Create an STM trace packet processor only for the supplied configuration.
- Must supply an output callback function which handles the stm packet types, to attach to the packet processor.
- @param handle : handle a decode tree to create the packet processsor.
- @param *stm_cfg : pointer to valid Stm configuration structure.
- @param pPktFn : pointer to a packet handling callback function.
- @param p_context : opaque context pointer value used in callback function.
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
- */
-OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t handle, const void *stm_cfg, FnStmPacketDataIn pPktFn, const void *p_context);
/** TBD : more C API functions to be added here */
/** @}*/ @@ -455,6 +379,10 @@ OCSD_C_API ocsd_err_t ocsd_gen_elem_str(const ocsd_generic_trace_elem *p_pkt, ch
/** @}*/
+#ifdef OPENCSD_INC_DEPRECATED_API +#include "ocsd_c_api_deprc_fn.h" +#endif
#endif // ARM_OPENCSD_C_API_H_INCLUDED
diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index d66cdb0..1e327ae 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -52,7 +52,9 @@ namespace std { const nothrow_t nothrow = nothrow_t(); } /*******************************************************************************/ /* C API internal helper function declarations */ /*******************************************************************************/ -static ocsd_err_t ocsd_dt_attach_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, ocsd_trace_protocol_t protocol, ITrcTypedBase *pPktMonIf, TraceElemCBBase *pCBObj);
+static ocsd_err_t ocsd_create_pkt_sink_cb(ocsd_trace_protocol_t protocol, FnDefPktDataIn pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj ); +static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPktDataMon pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj );
/*******************************************************************************/ /* C library data - additional data on top of the C++ library objects */ @@ -60,7 +62,7 @@ static ocsd_err_t ocsd_dt_attach_pkt_mon(const dcd_tree_handle_t handle, const u
/* keep a list of interface objects for a decode tree for later disposal */ typedef struct _lib_dt_data_list {
- std::vector<TraceElemCBBase *> cb_objs;
- std::vector<ITrcTypedBase *> cb_objs;
} lib_dt_data_list;
/* map lists to handles */ @@ -83,6 +85,8 @@ OCSD_C_API const char * ocsd_get_version_str(void) }
+/*** Decode tree creation etc. */
OCSD_C_API dcd_tree_handle_t ocsd_create_dcd_tree(const ocsd_dcd_tree_src_t src_type, const uint32_t deformatterCfgFlags) { dcd_tree_handle_t handle = C_API_INVALID_TREE_HANDLE; @@ -116,7 +120,7 @@ OCSD_C_API void ocsd_destroy_dcd_tree(const dcd_tree_handle_t handle) it = s_data_map.find(handle); if(it != s_data_map.end()) {
std::vector<TraceElemCBBase *>::iterator itcb;
std::vector<ITrcTypedBase *>::iterator itcb; itcb = it->second->cb_objs.begin(); while(itcb != it->second->cb_objs.end()) {
@@ -131,6 +135,8 @@ OCSD_C_API void ocsd_destroy_dcd_tree(const dcd_tree_handle_t handle) } }
+/*** Decode tree process data */
OCSD_C_API ocsd_datapath_resp_t ocsd_dt_process_data(const dcd_tree_handle_t handle, const ocsd_datapath_op_t op, const ocsd_trc_index_t index, @@ -144,325 +150,85 @@ OCSD_C_API ocsd_datapath_resp_t ocsd_dt_process_data(const dcd_tree_handle_t han return resp; }
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t handle, const void *etmv4_cfg, FnEtmv4IPacketDataIn pPktFn, const void *p_context) -{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
EtmV4Config cfg;
cfg = static_cast<const ocsd_etmv4_cfg *>(etmv4_cfg);
EtmV4ICBObj *p_CBObj = new (std::nothrow) EtmV4ICBObj(pPktFn,p_context);
if(p_CBObj == 0)
err = OCSD_ERR_MEM;
+/*** Decode tree - decoder management */
if(err == OCSD_OK)
{
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV4I,OCSD_CREATE_FLG_PACKET_PROC,&cfg);
if(err == OCSD_OK)
{
DecodeTreeElement *pTElem = ((DecodeTree *)handle)->getDecoderElement(cfg.getTraceID());
if(pTElem)
err = pTElem->getDecoderMngr()->attachPktSink(pTElem->getDecoderHandle(),p_CBObj);
else
err = OCSD_ERR_INVALID_PARAM_VAL;
}
}
if(err == OCSD_OK)
{
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(p_CBObj);
}
else
delete p_CBObj;
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
-}
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_decoder(const dcd_tree_handle_t handle, const void *etmv4_cfg) +OCSD_C_API ocsd_err_t ocsd_dt_create_decoder(const dcd_tree_handle_t handle,
const char *decoder_name,
const int create_flags,
const void *decoder_cfg,
unsigned char *pCSID
)
{ ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
EtmV4Config cfg;
cfg = static_cast<const ocsd_etmv4_cfg *>(etmv4_cfg);
// no need for a spcific CB object here - standard generic elements output used.
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV4I,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
-}
-OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv4IPktMonDataIn pPktFn, const void *p_context) -{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
DecodeTreeElement *pDTElem = pDT->getDecoderElement(trc_chan_id);
if((pDTElem != 0) && (pDTElem->getProtocol() == OCSD_PROTOCOL_ETMV4I))
{
EtmV4IPktMonCBObj *pktMonObj = new (std::nothrow) EtmV4IPktMonCBObj(pPktFn, p_context);
if(pktMonObj != 0)
{
err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
if(err == OCSD_OK)
{
// save object pointer for destruction later.
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(pktMonObj);
}
else
delete pktMonObj;
}
else
err = OCSD_ERR_MEM;
}
else
err = OCSD_ERR_INVALID_PARAM_VAL; // trace ID not found or not match for element protocol type.
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
-}
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t handle, const void *etmv3_cfg, FnEtmv3PacketDataIn pPktFn, const void *p_context) -{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
EtmV3Config cfg;
cfg = static_cast<const ocsd_etmv3_cfg *>(etmv3_cfg);
EtmV3CBObj *p_CBObj = new (std::nothrow) EtmV3CBObj(pPktFn, p_context);
if(p_CBObj == 0)
err = OCSD_ERR_MEM;
- DecodeTree *dt = (DecodeTree *)handle;
- std::string dName = decoder_name;
- IDecoderMngr *pDcdMngr;
- err = OcsdLibDcdRegister::getDecoderRegister()->getDecoderMngrByName(dName,&pDcdMngr);
- if(err != OCSD_OK)
return err;
if(err == OCSD_OK)
{
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV3,OCSD_CREATE_FLG_PACKET_PROC,&cfg);
if(err == OCSD_OK)
{
DecodeTreeElement *pTElem = ((DecodeTree *)handle)->getDecoderElement(cfg.getTraceID());
if(pTElem)
err = pTElem->getDecoderMngr()->attachPktSink(pTElem->getDecoderHandle(),p_CBObj);
else
err = OCSD_ERR_INVALID_PARAM_VAL;
}
}
- CSConfig *pConfig = 0;
- err = pDcdMngr->createConfigFromDataStruct(&pConfig,decoder_cfg);
- if(err != OCSD_OK)
return err;
if(err == OCSD_OK)
{
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(p_CBObj);
}
else
delete p_CBObj;
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- err = dt->createDecoder(dName,create_flags,pConfig);
- if(err == OCSD_OK)
*pCSID = pConfig->getTraceID();
- delete pConfig; return err;
}
-OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_decoder(const dcd_tree_handle_t handle, const void *etmv3_cfg) +OCSD_C_API ocsd_err_t ocsd_dt_remove_decoder( const dcd_tree_handle_t handle,
const unsigned char CSID)
{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
EtmV3Config cfg;
cfg = static_cast<const ocsd_etmv3_cfg *>(etmv3_cfg);
// no need for a spcific CB object here - standard generic elements output used.
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV3,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
- return ((DecodeTree *)handle)->removeDecoder(CSID);
}
-OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv3PktMonDataIn pPktFn, const void *p_context) +OCSD_C_API ocsd_err_t ocsd_dt_attach_packet_callback( const dcd_tree_handle_t handle,
const unsigned char CSID,
const ocsd_c_api_cb_types callback_type,
void *p_fn_callback_data,
const void *p_context)
{ ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
DecodeTreeElement *pDTElem = pDT->getDecoderElement(trc_chan_id);
if((pDTElem != 0) && (pDTElem->getProtocol() == OCSD_PROTOCOL_ETMV3))
{
EtmV3PktMonCBObj *pktMonObj = new (std::nothrow) EtmV3PktMonCBObj(pPktFn, p_context);
if(pktMonObj != 0)
{
err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
if(err == OCSD_OK)
{
// save object pointer for destruction later.
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(pktMonObj);
}
else
delete pktMonObj;
}
else
err = OCSD_ERR_MEM;
}
else
err = OCSD_ERR_INVALID_PARAM_VAL; // trace ID not found or not match for element protocol type.
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
-}
- DecodeTree *pDT = static_cast<DecodeTree *>(handle);
- DecodeTreeElement *pElem = pDT->getDecoderElement(CSID);
- if(pElem == 0)
return OCSD_ERR_INVALID_ID; // cannot find entry for that CSID
-OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t handle, const void *ptm_cfg, FnPtmPacketDataIn pPktFn, const void *p_context) -{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- ITrcTypedBase *pDataInSink = 0; // pointer to a sink callback object
- switch(callback_type) {
PtmConfig cfg;
cfg = static_cast<const ocsd_ptm_cfg *>(ptm_cfg);
PtmCBObj *p_CBObj = new (std::nothrow) PtmCBObj(pPktFn, p_context);
if(p_CBObj == 0)
err = OCSD_ERR_MEM;
if(err == OCSD_OK)
{
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_PTM,OCSD_CREATE_FLG_PACKET_PROC,&cfg);
if(err == OCSD_OK)
{
DecodeTreeElement *pTElem = ((DecodeTree *)handle)->getDecoderElement(cfg.getTraceID());
if(pTElem)
err = pTElem->getDecoderMngr()->attachPktSink(pTElem->getDecoderHandle(),p_CBObj);
else
err = OCSD_ERR_INVALID_PARAM_VAL;
}
}
- case OCSD_C_API_CB_PKT_SINK:
err = ocsd_create_pkt_sink_cb(pElem->getProtocol(),(FnDefPktDataIn)p_fn_callback_data,p_context,&pDataInSink);
break;
if(err == OCSD_OK)
{
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(p_CBObj);
}
else
delete p_CBObj;
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
-}
- case OCSD_C_API_CB_PKT_MON:
err = ocsd_create_pkt_mon_cb(pElem->getProtocol(),(FnDefPktDataMon)p_fn_callback_data,p_context,&pDataInSink);
break;
-OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle, const void *ptm_cfg) -{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
PtmConfig cfg;
cfg = static_cast<const ocsd_ptm_cfg *>(ptm_cfg);
// no need for a spcific CB object here - standard generic elements output used.
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_PTM,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
- }
- else
- default: err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
-}
-OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnPtmPktMonDataIn pPktFn, const void *p_context) -{
- ocsd_err_t err = OCSD_OK;
- PtmPktMonCBObj *pktMonObj = new (std::nothrow) PtmPktMonCBObj(pPktFn, p_context);
- err = ocsd_dt_attach_pkt_mon(handle,trc_chan_id,OCSD_PROTOCOL_PTM,pktMonObj,pktMonObj);
- if(err != OCSD_OK)
delete pktMonObj;
-#if 0
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
DecodeTreeElement *pDTElem = pDT->getDecoderElement(trc_chan_id);
if((pDTElem != 0) && (pDTElem->getProtocol() == OCSD_PROTOCOL_PTM))
{
PtmPktMonCBObj *pktMonObj = new (std::nothrow) PtmPktMonCBObj(pPktFn, p_context);
if(pktMonObj != 0)
{
err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
if(err == OCSD_OK)
{
// save object pointer for destruction later.
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(pktMonObj);
}
else
delete pktMonObj;
}
else
err = OCSD_ERR_MEM;
}
else
}err = OCSD_ERR_INVALID_PARAM_VAL; // trace ID not found or not match for element protocol type.
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
-#endif
- return err;
-}
-OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t handle, const void *stm_cfg, FnStmPacketDataIn pPktFn, const void *p_context) -{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- if(err == OCSD_OK) {
STMConfig cfg;
cfg = static_cast<const ocsd_stm_cfg *>(stm_cfg);
StmCBObj *p_CBObj = new (std::nothrow) StmCBObj(pPktFn, p_context);
if(p_CBObj == 0)
err = OCSD_ERR_MEM;
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_STM,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
err = pElem->getDecoderMngr()->attachPktSink(pElem->getDecoderHandle(),pDataInSink); if(err == OCSD_OK) {
// save object pointer for destruction later. std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it; it = s_data_map.find(handle); if(it != s_data_map.end())
it->second->cb_objs.push_back(p_CBObj);
it->second->cb_objs.push_back(pDataInSink); }
else
}delete p_CBObj;
- else
return err;err = OCSD_ERR_INVALID_PARAM_VAL;
}
+/*** Decode tree set element output */
OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_outfn(const dcd_tree_handle_t handle, FnTraceElemIn pFn, const void *p_context) {
@@ -475,6 +241,9 @@ OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_outfn(const dcd_tree_handle_t handle, return OCSD_ERR_MEM; }
+/*** Default error logging */
OCSD_C_API ocsd_err_t ocsd_def_errlog_init(const ocsd_err_severity_t verbosity, const int create_output_logger) { if(DecodeTree::getDefaultErrorLogger()->initErrorLogger(verbosity,(bool)(create_output_logger != 0))) @@ -504,6 +273,7 @@ OCSD_C_API void ocsd_def_errlog_msgout(const char *msg) pLogger->LogMsg(msg); }
+/*** Convert packet to string */
OCSD_C_API ocsd_err_t ocsd_pkt_str(const ocsd_trace_protocol_t pkt_protocol, const void *p_pkt, char *buffer, const int buffer_size) { @@ -561,6 +331,9 @@ OCSD_C_API ocsd_err_t ocsd_gen_elem_str(const ocsd_generic_trace_elem *p_pkt, ch return err; }
+/*** Decode tree -- memeory accessor control */
OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const char *filepath) { ocsd_err_t err = OCSD_OK; @@ -741,36 +514,75 @@ OCSD_C_API void ocsd_tl_log_mapped_mem_ranges(const dcd_tree_handle_t handle) /*******************************************************************************/ /* C API local fns */ /*******************************************************************************/ -static ocsd_err_t ocsd_dt_attach_pkt_mon( const dcd_tree_handle_t handle,
const uint8_t trc_chan_id,
ocsd_trace_protocol_t protocol,
ITrcTypedBase *pPktMonIf,
TraceElemCBBase *pCBObj)
+static ocsd_err_t ocsd_create_pkt_sink_cb(ocsd_trace_protocol_t protocol, FnDefPktDataIn pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj ) { ocsd_err_t err = OCSD_OK;
- if(handle == C_API_INVALID_TREE_HANDLE)
return OCSD_ERR_INVALID_PARAM_VAL;
- *ppCBObj = 0;
- DecodeTree *pDT = static_cast<DecodeTree *>(handle);
- DecodeTreeElement *pDTElem = pDT->getDecoderElement(trc_chan_id);
- if((pDTElem != 0) && (pDTElem->getProtocol() == protocol))
- switch(protocol) {
err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pPktMonIf);
if(err == OCSD_OK)
{
// save object pointer for destruction later.
std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
it = s_data_map.find(handle);
if(it != s_data_map.end())
it->second->cb_objs.push_back(pCBObj);
}
- case OCSD_PROTOCOL_ETMV4I:
*ppCBObj = new (std::nothrow) PktCBObj<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(pPktInFn,p_context);
break;
- case OCSD_PROTOCOL_ETMV3:
*ppCBObj = new (std::nothrow) PktCBObj<EtmV3TrcPacket,ocsd_etmv3_pkt>(pPktInFn,p_context);
break;
- case OCSD_PROTOCOL_PTM:
*ppCBObj = new (std::nothrow) PktCBObj<PtmTrcPacket,ocsd_ptm_pkt>(pPktInFn,p_context);
break;
- case OCSD_PROTOCOL_STM:
*ppCBObj = new (std::nothrow) PktCBObj<StmTrcPacket,ocsd_stm_pkt>(pPktInFn,p_context);
break;
- default:
err = OCSD_ERR_NO_PROTOCOL;
}break;
- else
err = OCSD_ERR_INVALID_PARAM_VAL; // trace ID not found or not match for element protocol type.
- if((*ppCBObj == 0) && (err == OCSD_OK))
err = OCSD_ERR_MEM;
- return err;
+}
+static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPktDataMon pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj ) +{
- ocsd_err_t err = OCSD_OK;
- *ppCBObj = 0;
- switch(protocol)
- {
- case OCSD_PROTOCOL_ETMV4I:
*ppCBObj = new (std::nothrow) PktMonCBObj<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(pPktInFn,p_context);
break;
- case OCSD_PROTOCOL_ETMV3:
*ppCBObj = new (std::nothrow) PktMonCBObj<EtmV3TrcPacket,ocsd_etmv3_pkt>(pPktInFn,p_context);
break;
- case OCSD_PROTOCOL_PTM:
*ppCBObj = new (std::nothrow) PktMonCBObj<PtmTrcPacket,ocsd_ptm_pkt>(pPktInFn,p_context);
break;
- case OCSD_PROTOCOL_STM:
*ppCBObj = new (std::nothrow) PktMonCBObj<StmTrcPacket,ocsd_stm_pkt>(pPktInFn,p_context);
break;
- default:
err = OCSD_ERR_NO_PROTOCOL;
break;
- }
- if((*ppCBObj == 0) && (err == OCSD_OK))
err = OCSD_ERR_MEM;
- return err;
}
/*******************************************************************************/ /* C API Helper objects */ /*******************************************************************************/ @@ -789,6 +601,9 @@ ocsd_datapath_resp_t GenTraceElemCBObj::TraceElemIn(const ocsd_trc_index_t index return m_c_api_cb_fn(m_p_cb_context, index_sop, trc_chan_id, &elem); }
+#if 0
Same comment as in the previous patch.
/****************** Etmv4 packet processor output callback function ************/ EtmV4ICBObj::EtmV4ICBObj(FnEtmv4IPacketDataIn pCBFn, const void *p_context) : m_c_api_cb_fn(pCBFn), @@ -909,6 +724,6 @@ void StmPktMonCBObj::RawPacketDataMon( const ocsd_datapath_op_t op, { return m_c_api_cb_fn(m_p_cb_context, op, index_sop, p_packet_in, size, p_data); }
+#endif
/* End of File ocsd_c_api.cpp */ diff --git a/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp b/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp new file mode 100644 index 0000000..b5d0ff5 --- /dev/null +++ b/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp @@ -0,0 +1,200 @@ +/*
- \file ocsd_c_api_deprc_fn.cpp
- \brief OpenCSD : Deprecated C-API functions.
- \copyright Copyright (c) 2016, 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:
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 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.
- 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.
- */
+/* pull in the C++ decode library */ +#include "opencsd.h"
+/* C-API and wrapper objects */ +#define OPENCSD_INC_DEPRECATED_API +#include "c_api/opencsd_c_api.h" +#include "ocsd_c_api_obj.h"
+#ifdef OPENCSD_INC_DEPRECATED_API
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t handle, const void *etmv4_cfg, FnEtmv4IPacketDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- uint8_t CSID = 0;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_ETMV4I,OCSD_CREATE_FLG_PACKET_PROC,etmv4_cfg,&CSID);
if(err == OCSD_OK)
{
err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,pPktFn,p_context);
if(err != OCSD_OK)
ocsd_dt_remove_decoder(handle,CSID);
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_decoder(const dcd_tree_handle_t handle, const void *etmv4_cfg) +{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
uint8_t CSID = 0;
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_ETMV4I,OCSD_CREATE_FLG_FULL_DECODER,etmv4_cfg,&CSID);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv4IPktMonDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_attach_packet_callback(handle,trc_chan_id,OCSD_C_API_CB_PKT_MON,pPktFn,p_context);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t handle, const void *etmv3_cfg, FnEtmv3PacketDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- uint8_t CSID = 0;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_ETMV3,OCSD_CREATE_FLG_PACKET_PROC,etmv3_cfg,&CSID);
if(err == OCSD_OK)
{
err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,pPktFn,p_context);
if(err != OCSD_OK)
ocsd_dt_remove_decoder(handle,CSID);
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_decoder(const dcd_tree_handle_t handle, const void *etmv3_cfg) +{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
uint8_t CSID = 0;
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_ETMV3,OCSD_CREATE_FLG_FULL_DECODER,etmv3_cfg,&CSID);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnEtmv3PktMonDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_attach_packet_callback(handle,trc_chan_id,OCSD_C_API_CB_PKT_MON,pPktFn,p_context);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t handle, const void *ptm_cfg, FnPtmPacketDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- uint8_t CSID = 0;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_PTM,OCSD_CREATE_FLG_PACKET_PROC,ptm_cfg,&CSID);
if(err == OCSD_OK)
{
err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,pPktFn,p_context);
if(err != OCSD_OK)
ocsd_dt_remove_decoder(handle,CSID);
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle, const void *ptm_cfg) +{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
uint8_t CSID = 0;
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_PTM,OCSD_CREATE_FLG_FULL_DECODER,ptm_cfg,&CSID);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, const uint8_t trc_chan_id, FnPtmPktMonDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_attach_packet_callback(handle,trc_chan_id,OCSD_C_API_CB_PKT_MON,pPktFn,p_context);
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t handle, const void *stm_cfg, FnStmPacketDataIn pPktFn, const void *p_context) +{
- ocsd_err_t err = OCSD_OK;
- uint8_t CSID = 0;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
err = ocsd_dt_create_decoder(handle,OCSD_BUILTIN_DCD_STM,OCSD_CREATE_FLG_PACKET_PROC,stm_cfg,&CSID);
if(err == OCSD_OK)
{
err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,pPktFn,p_context);
if(err != OCSD_OK)
ocsd_dt_remove_decoder(handle,CSID);
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+}
+#endif
+/* End of File ocsd_c_api_deprc_fn.cpp */ diff --git a/decoder/source/c_api/ocsd_c_api_obj.h b/decoder/source/c_api/ocsd_c_api_obj.h index 6b1f105..dbe6d08 100644 --- a/decoder/source/c_api/ocsd_c_api_obj.h +++ b/decoder/source/c_api/ocsd_c_api_obj.h @@ -34,6 +34,61 @@ private: const void *m_p_cb_context; };
+template<class TrcPkt, class TrcPktStruct> +class PktCBObj : public IPktDataIn<TrcPkt> +{ +public:
- PktCBObj( FnDefPktDataIn pCBFunc, const void *p_context)
- {
m_c_api_cb_fn = pCBFunc;
m_p_context = p_context;
- };
- virtual ~PktCBObj() {};
- virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op,
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);
- };
+private:
- FnDefPktDataIn m_c_api_cb_fn;
- const void *m_p_context;
+};
+template<class TrcPkt, class TrcPktStruct> +class PktMonCBObj : public IPktRawDataMon<TrcPkt> +{ +public:
- PktMonCBObj( FnDefPktDataMon pCBFunc, const void *p_context)
- {
m_c_api_cb_fn = pCBFunc;
m_p_context = p_context;
- };
- virtual ~PktMonCBObj() {};
- virtual void RawPacketDataMon( const ocsd_datapath_op_t op,
const ocsd_trc_index_t index_sop,
const TrcPkt *p_packet_in,
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);
- };
+private:
- FnDefPktDataMon m_c_api_cb_fn;
- const void *m_p_context;
+};
+#if 0
Same comment as in the previous patch.
/************************************************************************/ /*** ETMv4 ***/ /************************************************************************/ @@ -184,6 +239,8 @@ private: const void *m_p_cb_context; };
+#endif
#endif // ARM_OCSD_C_API_OBJ_H_INCLUDED
/* End of File ocsd_c_api_obj.h */ diff --git a/decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj b/decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj new file mode 100644 index 0000000..0c03c76 --- /dev/null +++ b/decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj @@ -0,0 +1,325 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-dll|Win32">
<Configuration>Debug-dll</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-dll|x64">
<Configuration>Debug-dll</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-dll|Win32">
<Configuration>Release-dll</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-dll|x64">
<Configuration>Release-dll</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\c_api_pkt_print_test.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
- <ProjectGuid>{3AC169DA-E156-4D16-95DF-73D7302A5606}</ProjectGuid>
- <Keyword>Win32Proj</Keyword>
- <RootNamespace>c_api_pkt_print_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\build\win\opencsd.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <LinkIncremental>true</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\dbg</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|Win32'">
- <LinkIncremental>true</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\dbg</OutDir>
- <TargetName>$(ProjectName)-dl</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <LinkIncremental>true</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\dbg</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|x64'">
- <LinkIncremental>true</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\dbg</OutDir>
- <TargetName>$(ProjectName)-dl</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\rel</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\rel</OutDir>
- <TargetName>$(ProjectName)-dl</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <LinkIncremental>false</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\rel</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|x64'">
- <LinkIncremental>false</LinkIncremental>
- <OutDir>......\bin\win$(PlatformArchitecture)\rel</OutDir>
- <TargetName>$(ProjectName)-dl</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;OCSD_USE_STATIC_C_API;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\dbg\</AdditionalLibraryDirectories>
<AdditionalDependencies>lib$(LIB_CAPI_NAME).lib;lib$(LIB_BASE_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\dbg\</AdditionalLibraryDirectories>
<AdditionalDependencies>$(LIB_CAPI_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\..\lib\win32\dbg\*.dll ..\..\..\bin\win32\dbg\.</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;OCSD_USE_STATIC_C_API;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>lib$(LIB_CAPI_NAME).lib;lib$(LIB_BASE_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\dbg\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-dll|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\dbg\</AdditionalLibraryDirectories>
<AdditionalDependencies>$(LIB_CAPI_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\..\lib\win64\dbg\*.dll ..\..\..\bin\win64\dbg\.</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;OCSD_USE_STATIC_C_API;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\rel\</AdditionalLibraryDirectories>
<AdditionalDependencies>lib$(LIB_CAPI_NAME).lib;lib$(LIB_BASE_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\rel\</AdditionalLibraryDirectories>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(LIB_CAPI_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\..\lib\win32\rel\*.dll ..\..\..\bin\win32\rel\.</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;OCSD_USE_STATIC_C_API;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\rel\</AdditionalLibraryDirectories>
<AdditionalDependencies>lib$(LIB_CAPI_NAME).lib;lib$(LIB_BASE_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release-dll|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\..\..\lib\win$(PlatformArchitecture)\rel\</AdditionalLibraryDirectories>
<AdditionalDependencies>$(LIB_CAPI_NAME).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\..\lib\win64\rel\*.dll ..\..\..\bin\win64\rel\.</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
+</Project> \ No newline at end of file diff --git a/decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj.filters b/decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj.filters new file mode 100644 index 0000000..e8fc90b --- /dev/null +++ b/decoder/tests/build/win/c_api_pkt_print_test/c_api_pkt_print_test.vcxproj.filters @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\c_api_pkt_print_test.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
+</Project> \ No newline at end of file diff --git a/decoder/tests/source/c_api_pkt_print_test.c b/decoder/tests/source/c_api_pkt_print_test.c new file mode 100644 index 0000000..138df1a --- /dev/null +++ b/decoder/tests/source/c_api_pkt_print_test.c @@ -0,0 +1,825 @@ +/*
- \file c_api_pkt_print_test.c
- \brief OpenCSD : C-API test program
- \copyright Copyright (c) 2016, 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:
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 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.
- 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.
- */
+/*
- Example of using the library with the C-API. Used to validate that the C-API
- functions work.
- Simple test program to print packets from a single trace ID source stream.
- Hard coded configuration based on the Juno r1-1 test snapshot for ETMv4 and
- STM, TC2 test snapshot for ETMv3, PTM.
- The test source can be set from the command line, but will default to the
- ETMv4 trace for trace ID 0x10 on the juno r1-1 test snapshot.
- This example uses the updated C-API functionality from library version 0v004 onwards.
- */
+#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h>
+/* include the C-API library header */ +#include "c_api/opencsd_c_api.h"
+/* path to test snapshots, relative to tests/bin/<plat>/<dbg|rel> build output dir */ +#ifdef _WIN32 +const char *default_path_to_snapshot = "..\..\..\snapshots\juno_r1_1\"; +const char *tc2_snapshot = "..\..\..\snapshots\TC2\"; +#else +const char *default_path_to_snapshot = "../../../snapshots/juno_r1_1/"; +const char *tc2_snapshot = "../../../snapshots/TC2/"; +#endif
+/* trace data and memory file dump names */ +const char *trace_data_filename = "cstrace.bin"; +const char *stmtrace_data_filename = "cstraceitm.bin"; +const char *memory_dump_filename = "kernel_dump.bin"; +ocsd_vaddr_t mem_dump_address=0xFFFFFFC000081000; +const ocsd_vaddr_t mem_dump_address_tc2=0xC0008000;
There is probably value in documenting why those values were chosen.
+/* test variables - set by command line to feature test API */ +static int using_mem_acc_cb = 0; /* test the memory access callback function */ +static int use_region_file = 0; /* test multi region memory files */
+/* buffer to handle a packet string */ +#define PACKET_STR_LEN 1024 +static char packet_str[PACKET_STR_LEN];
+/* decide if we decode & monitor, decode only or packet print */ +typedef enum _test_op {
- TEST_PKT_PRINT, // process trace input into discrete packets and print.
- TEST_PKT_DECODE, // process and decode trace packets, printing discrete packets and generic output.
- TEST_PKT_DECODEONLY // process and decode trace packets, printing generic output packets only.
+} test_op_t;
+// Default test operations +static test_op_t op = TEST_PKT_PRINT; // default operation is to packet print +static ocsd_trace_protocol_t test_protocol = OCSD_PROTOCOL_ETMV4I; // ETMV4 protocl +static uint8_t test_trc_id_override = 0x00; // no trace ID override.
+/* Process command line options - choose the operation to use for the test. */ +static int process_cmd_line(int argc, char *argv[]) +{
- int idx = 1;
- while(idx < argc)
- {
if(strcmp(argv[idx],"-decode_only") == 0)
{
op = TEST_PKT_DECODEONLY;
}
else if(strcmp(argv[idx],"-decode") == 0)
{
op = TEST_PKT_DECODE;
}
else if(strcmp(argv[idx],"-id") == 0)
{
idx++;
if(idx < argc)
{
test_trc_id_override = (uint8_t)(strtoul(argv[idx],0,0));
printf("ID override = 0x%02X\n",test_trc_id_override);
}
}
else if(strcmp(argv[idx],"-etmv3") == 0)
{
test_protocol = OCSD_PROTOCOL_ETMV3;
default_path_to_snapshot = tc2_snapshot;
mem_dump_address = mem_dump_address_tc2;
}
else if(strcmp(argv[idx],"-ptm") == 0)
{
test_protocol = OCSD_PROTOCOL_PTM;
default_path_to_snapshot = tc2_snapshot;
mem_dump_address = mem_dump_address_tc2;
}
else if(strcmp(argv[idx],"-stm") == 0)
{
test_protocol = OCSD_PROTOCOL_STM;
trace_data_filename = stmtrace_data_filename;
}
else if(strcmp(argv[idx],"-test_cb") == 0)
{
using_mem_acc_cb = 1;
use_region_file = 0;
}
else if(strcmp(argv[idx],"-test_region_file") == 0)
{
use_region_file = 1;
using_mem_acc_cb = 0;
}
else if(strcmp(argv[idx],"-help") == 0)
{
return -1;
}
else
printf("Ignored unknown argument %s\n", argv[idx]);
idx++;
- }
- return 0;
+}
+static void print_cmd_line_help() +{
- printf("Usage:\n-etmv3|-stm|-ptm : choose protocol (one only, default etmv4)\n");
- 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("-test_region_file | -test_cb : mem accessor - test multi region file API | test callback API (default single memroy file)\n\n");
+}
+/************************************************************************/ +/* Memory accessor functionality */ +/************************************************************************/
+static FILE *dump_file = NULL; /* pointer to the file providing the opcode memory */ +static ocsd_mem_space_acc_t dump_file_mem_space = OCSD_MEM_SPACE_ANY; /* memory space used by the dump file */ +static long mem_file_size = 0; /* size of the memory file */ +static ocsd_vaddr_t mem_file_en_address = 0; /* end address last inclusive address in file. */
+/* decode memory access using a CallBack function +* tests CB API and add / remove mem acc API. +*/ +static uint32_t mem_acc_cb(const void *p_context, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint32_t reqBytes, uint8_t *byteBuffer) +{
- uint32_t read_bytes = 0;
- size_t file_read_bytes;
- if(dump_file == NULL)
return 0;
- /* bitwise & the incoming mem space and supported mem space to confirm coverage */
- if(((uint8_t)mem_space & (uint8_t)dump_file_mem_space ) == 0)
return 0;
- /* calculate the bytes that can be read */
- if((address >= mem_dump_address) && (address <= mem_file_en_address))
- {
/* some bytes in our range */
read_bytes = reqBytes;
if((address + reqBytes - 1) > mem_file_en_address)
{
/* more than are available - just read the available */
read_bytes = (uint32_t)(mem_file_en_address - (address - 1));
}
- }
- /* read some bytes if more than 0 to read. */
- if(read_bytes != 0)
- {
fseek(dump_file,(long)(address-mem_dump_address),SEEK_SET);
file_read_bytes = fread(byteBuffer,sizeof(uint8_t),read_bytes,dump_file);
if(file_read_bytes < read_bytes)
read_bytes = file_read_bytes;
- }
- return read_bytes;
+}
+/* Create the memory accessor using the callback function and attach to decode tree */ +static ocsd_err_t create_mem_acc_cb(dcd_tree_handle_t dcd_tree_h, const char *mem_file_path) +{
- ocsd_err_t err = OCSD_OK;
- dump_file = fopen(mem_file_path,"rb");
- if(dump_file != NULL)
- {
fseek(dump_file,0,SEEK_END);
mem_file_size = ftell(dump_file);
mem_file_en_address = mem_dump_address + mem_file_size - 1;
err = ocsd_dt_add_callback_mem_acc(dcd_tree_h,
mem_dump_address,mem_file_en_address,dump_file_mem_space,&mem_acc_cb,0);
if(err != OCSD_OK)
{
fclose(dump_file);
dump_file = NULL;
}
- }
- else
err = OCSD_ERR_MEM_ACC_FILE_NOT_FOUND;
- return err;
+}
+/* remove the callback memory accessor from decode tree */ +static void destroy_mem_acc_cb(dcd_tree_handle_t dcd_tree_h) +{
- if(dump_file != NULL)
- {
ocsd_dt_remove_mem_acc(dcd_tree_h,mem_dump_address,dump_file_mem_space);
fclose(dump_file);
dump_file = NULL;
- }
+}
+/* create and attach the memory accessor according to required test parameters */ +static ocsd_err_t create_test_memory_acc(dcd_tree_handle_t handle) +{
- ocsd_err_t ret = OCSD_OK;
- char mem_file_path[512];
- uint32_t i0adjust = 0x100;
- int i = 0;
- /* region list to test multi region memory file API */
- file_mem_region_t region_list[4];
- /* path to the file containing the memory image traced - raw binary data in the snapshot */
- strcpy(mem_file_path,default_path_to_snapshot);
- strcat(mem_file_path,memory_dump_filename);
- /*
- decide how to handle the file - test the normal memory accessor (contiguous binary file),
- a callback accessor or a multi-region file (e.g. similar to using the code region in a .so)
- The same memory dump file is used in each case, we just present it differently
- to test the API functions.
- */
- /* memory access callback */
- if(using_mem_acc_cb)
- {
ret = create_mem_acc_cb(handle,mem_file_path);
- }
- /* multi region file */
- else if(use_region_file)
- {
dump_file = fopen(mem_file_path,"rb");
if(dump_file != NULL)
{
fseek(dump_file,0,SEEK_END);
mem_file_size = ftell(dump_file);
fclose(dump_file);
/* populate the region list - split existing file into four regions */
for(i = 0; i < 4; i++)
{
if(i != 0)
i0adjust = 0;
region_list[i].start_address = mem_dump_address + (i * mem_file_size/4) + i0adjust;
region_list[i].region_size = (mem_file_size/4) - i0adjust;
region_list[i].file_offset = (i * mem_file_size/4) + i0adjust;
}
/* create a memory file accessor - full binary file */
ret = ocsd_dt_add_binfile_region_mem_acc(handle,®ion_list[0],4,OCSD_MEM_SPACE_ANY,mem_file_path);
}
else
ret = OCSD_ERR_MEM_ACC_FILE_NOT_FOUND;
- }
- /* create a memory file accessor - simple contiguous full binary file */
- else
- {
ret = ocsd_dt_add_binfile_mem_acc(handle,mem_dump_address,OCSD_MEM_SPACE_ANY,mem_file_path);
- }
- return ret;
+}
+/************************************************************************/ +/** Packet printers */ +/************************************************************************/
+/* +* Callback function to process the packets in the packet processor output stream - +* simply print them out in this case to the library message/error logger. +*/ +ocsd_datapath_resp_t packet_handler(void *context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const void *p_packet_in) +{
- ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
- int offset = 0;
- switch(op)
- {
- default: break;
I've never seen a case statement with the default at the top. Are you relying on the compiler to do the right thing and re-arrange the code so that missed cases (below) will be caught? I'm not saying it is wrong, it just looks odd to me.
- case OCSD_OP_DATA:
sprintf(packet_str,"Idx:%ld; ", index_sop);
offset = strlen(packet_str);
/*
* got a packet - convert to string and use the libraries' message output to print to file and stdoout
* Since the test always prints a single ID, we know the protocol type.
*/
if(ocsd_pkt_str(test_protocol,p_packet_in,packet_str+offset,PACKET_STR_LEN-offset) == OCSD_OK)
{
/* add in <CR> */
if(strlen(packet_str) == PACKET_STR_LEN - 1) /* maximum length */
packet_str[PACKET_STR_LEN-2] = '\n';
else
strcat(packet_str,"\n");
/* print it using the library output logger. */
ocsd_def_errlog_msgout(packet_str);
}
else
resp = OCSD_RESP_FATAL_INVALID_PARAM; /* mark fatal error */
break;
- case OCSD_OP_EOT:
sprintf(packet_str,"**** END OF TRACE ****\n");
ocsd_def_errlog_msgout(packet_str);
break;
- }
- return resp;
+}
+/* print an array of hex data - used by the packet monitor to print hex data from packet.*/ +static int print_data_array(const uint8_t *p_array, const int array_size, char *p_buffer, int buf_size) +{
- int chars_printed = 0;
- int bytes_processed;
- p_buffer[0] = 0;
- if(buf_size > 9)
- {
/* set up the header */
strcat(p_buffer,"[ ");
chars_printed+=2;
for(bytes_processed = 0; bytes_processed < array_size; bytes_processed++)
{
sprintf(p_buffer+chars_printed,"0x%02X ", p_array[bytes_processed]);
chars_printed += 5;
if((chars_printed + 5) > buf_size)
break;
}
strcat(p_buffer,"];");
chars_printed+=2;
- }
- else if(buf_size >= 4)
- {
sprintf(p_buffer,"[];");
chars_printed+=3;
- }
- return chars_printed;
+}
+/* +* Callback function to process packets and packet data from the monitor output of the +* packet processor. Again print them to the library error logger. +*/ +void packet_monitor(const ocsd_datapath_op_t op,
const ocsd_trc_index_t index_sop,
const void *p_packet_in,
const uint32_t size,
const uint8_t *p_data)
+{
- int offset = 0;
- switch(op)
- {
- default: break;
- case OCSD_OP_DATA:
sprintf(packet_str,"Idx:%ld;", index_sop);
offset = strlen(packet_str);
offset+= print_data_array(p_data,size,packet_str+offset,PACKET_STR_LEN-offset);
/* got a packet - convert to string and use the libraries' message output to print to file and stdoout */
if(ocsd_pkt_str(test_protocol,p_packet_in,packet_str+offset,PACKET_STR_LEN-offset) == OCSD_OK)
{
/* add in <CR> */
if(strlen(packet_str) == PACKET_STR_LEN - 1) /* maximum length */
packet_str[PACKET_STR_LEN-2] = '\n';
else
strcat(packet_str,"\n");
/* print it using the library output logger. */
ocsd_def_errlog_msgout(packet_str);
}
break;
- case OCSD_OP_EOT:
sprintf(packet_str,"**** END OF TRACE ****\n");
ocsd_def_errlog_msgout(packet_str);
break;
- }
+}
+/* +* printer for the generic trace elements when decoder output is being processed +*/ +ocsd_datapath_resp_t gen_trace_elem_print(const void *p_context, const ocsd_trc_index_t index_sop, const uint8_t trc_chan_id, const ocsd_generic_trace_elem *elem) +{
- ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
- int offset = 0;
- sprintf(packet_str,"Idx:%ld; TrcID:0x%02X; ", index_sop, trc_chan_id);
- offset = strlen(packet_str);
- if(ocsd_gen_elem_str(elem, packet_str+offset,PACKET_STR_LEN - offset) == OCSD_OK)
- {
/* add in <CR> */
if(strlen(packet_str) == PACKET_STR_LEN - 1) /* maximum length */
packet_str[PACKET_STR_LEN-2] = '\n';
else
strcat(packet_str,"\n");
- }
- else
- {
strcat(packet_str,"Unable to create element string\n");
- }
- /* print it using the library output logger. */
- ocsd_def_errlog_msgout(packet_str);
- return resp;
+}
+/************************************************************************/ +/** decoder creation **/
+/*** generic ***/ +static ocsd_err_t create_generic_decoder(dcd_tree_handle_t handle, const char *p_name, const void *p_cfg, const void *p_context) +{
- ocsd_err_t ret = OCSD_OK;
- uint8_t CSID = 0;
- if(op == TEST_PKT_PRINT) /* test operation set to packet printing only */
- {
/*
* Create a packet processor on the decode tree for the configuration we have.
* We need to supply the configuration
*/
ret = ocsd_dt_create_decoder(handle,p_name,OCSD_CREATE_FLG_PACKET_PROC,p_cfg,&CSID);
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(ret != OCSD_OK)
ocsd_dt_remove_decoder(handle,CSID); /* if the attach failed then destroy the decoder. */
}
- }
- else
- {
/* Full decode - need decoder, and memory dump */
/* create the packet decoder and packet processor pair from the supplied name */
ret = ocsd_dt_create_decoder(handle,p_name,OCSD_CREATE_FLG_FULL_DECODER,p_cfg,&CSID);
if(ret == OCSD_OK)
{
if((op != TEST_PKT_DECODEONLY) && (ret == OCSD_OK))
{
/*
* 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);
}
/* attach a memory accessor */
if(ret == OCSD_OK)
ret = create_test_memory_acc(handle);
/* if the attach failed then destroy the decoder. */
if(ret != OCSD_OK)
ocsd_dt_remove_decoder(handle,CSID);
}
- }
- return ret;
+}
+/*** ETMV4 specific settings ***/ +static ocsd_err_t create_decoder_etmv4(dcd_tree_handle_t dcd_tree_h) +{
- ocsd_err_t ret = OCSD_OK;
- ocsd_etmv4_cfg trace_config;
- /*
- populate the ETMv4 configuration structure with
- hard coded values from snapshot .ini files.
- */
- trace_config.arch_ver = ARCH_V8;
- trace_config.core_prof = profile_CortexA;
- trace_config.reg_configr = 0x000000C1;
- trace_config.reg_traceidr = 0x00000010; /* this is the trace ID -> 0x10, change this to analyse other streams in snapshot.*/
- if(test_trc_id_override != 0)
- {
trace_config.reg_traceidr = (uint32_t)test_trc_id_override;
- }
- trace_config.reg_idr0 = 0x28000EA1;
- trace_config.reg_idr1 = 0x4100F403;
- trace_config.reg_idr2 = 0x00000488;
- trace_config.reg_idr8 = 0x0;
- trace_config.reg_idr9 = 0x0;
- trace_config.reg_idr10 = 0x0;
- trace_config.reg_idr11 = 0x0;
- trace_config.reg_idr12 = 0x0;
- trace_config.reg_idr13 = 0x0;
I would bzero() trace_config and then set trace_config.reg_idr[0..2].
- /* create an ETMV4 decoder - no context needed as we have a single stream to a single handler. */
- return create_generic_decoder(dcd_tree_h,OCSD_BUILTIN_DCD_ETMV4I,(void *)&trace_config,0);
+}
+/*** ETMV3 specific settings ***/ +static ocsd_err_t create_decoder_etmv3(dcd_tree_handle_t dcd_tree_h) +{
- ocsd_err_t ret = OCSD_OK;
- ocsd_etmv3_cfg trace_config_etmv3;
- /*
- populate the ETMv3 configuration structure with
- hard coded values from snapshot .ini files.
- */
- trace_config_etmv3.arch_ver = ARCH_V7;
- trace_config_etmv3.core_prof = profile_CortexA;
- trace_config_etmv3.reg_ccer = 0x344008F2;
- trace_config_etmv3.reg_ctrl = 0x10001860;
- trace_config_etmv3.reg_idr = 0x410CF250;
- trace_config_etmv3.reg_trc_id = 0x010;
Please document the reason for choosing the above hard coded values.
- if(test_trc_id_override != 0)
- {
trace_config_etmv3.reg_trc_id = (uint32_t)test_trc_id_override;
- }
- /* create an ETMV3 decoder - no context needed as we have a single stream to a single handler. */
- return create_generic_decoder(dcd_tree_h,OCSD_BUILTIN_DCD_ETMV3,(void *)&trace_config_etmv3,0);
+}
+/*** PTM specific settings ***/ +static ocsd_err_t create_decoder_ptm(dcd_tree_handle_t dcd_tree_h) +{
- ocsd_err_t ret = OCSD_OK;
- ocsd_ptm_cfg trace_config_ptm;
- /*
- populate the PTM configuration structure with
- hard coded values from snapshot .ini files.
- */
- trace_config_ptm.arch_ver = ARCH_V7;
- trace_config_ptm.core_prof = profile_CortexA;
- trace_config_ptm.reg_ccer = 0x34C01AC2;
- trace_config_ptm.reg_ctrl = 0x10001000;
- trace_config_ptm.reg_idr = 0x411CF312;
- trace_config_ptm.reg_trc_id = 0x013;
Same here.
- if(test_trc_id_override != 0)
- {
trace_config_ptm.reg_trc_id = (uint32_t)test_trc_id_override;
- }
- /* create an PTM decoder - no context needed as we have a single stream to a single handler. */
- return create_generic_decoder(dcd_tree_h,OCSD_BUILTIN_DCD_PTM,(void *)&trace_config_ptm,0);
+}
+/*** STM specific settings ***/ +static ocsd_err_t create_decoder_stm(dcd_tree_handle_t dcd_tree_h) +{
- ocsd_err_t ret = OCSD_OK;
- ocsd_stm_cfg trace_config_stm;
- /*
- populate the STM configuration structure with
- hard coded values from snapshot .ini files.
- */
- #define STMTCSR_TRC_ID_MASK 0x007F0000
- #define STMTCSR_TRC_ID_SHIFT 16
- trace_config_stm.reg_tcsr = 0x00A00005;
- if(test_trc_id_override != 0)
- {
trace_config_stm.reg_tcsr &= ~STMTCSR_TRC_ID_MASK;
trace_config_stm.reg_tcsr |= ((((uint32_t)test_trc_id_override) << STMTCSR_TRC_ID_SHIFT) & STMTCSR_TRC_ID_MASK);
- }
- trace_config_stm.reg_feat3r = 0x10000; /* channel default */
- trace_config_stm.reg_devid = 0xFF; /* master default */
- /* not using hw event trace decode */
- trace_config_stm.reg_hwev_mast = 0;
- trace_config_stm.reg_feat1r = 0;
- trace_config_stm.hw_event = HwEvent_Unknown_Disabled;
- /* STM only has packet processor at present */
- if(op == TEST_PKT_PRINT) /* packet printing only */
- {
ret = create_generic_decoder(dcd_tree_h,OCSD_BUILTIN_DCD_STM,(void *)&trace_config_stm,0);
- }
- else
- {
/* Full decode */
/* not supported in library at present */
printf("STM Full decode not supported in library at present. Packet print only\n");
ret = OCSD_ERR_RDR_NO_DECODER;
- }
- return ret;
+}
+/************************************************************************/
+/* create a decoder according to options */ +static ocsd_err_t create_decoder(dcd_tree_handle_t dcd_tree_h) +{
- ocsd_err_t err = OCSD_OK;
- switch(test_protocol)
- {
- case OCSD_PROTOCOL_ETMV4I:
err = create_decoder_etmv4(dcd_tree_h);
break;
- case OCSD_PROTOCOL_ETMV3:
err = create_decoder_etmv3(dcd_tree_h);
break;
- case OCSD_PROTOCOL_STM:
err = create_decoder_stm(dcd_tree_h);
break;
- case OCSD_PROTOCOL_PTM:
err = create_decoder_ptm(dcd_tree_h);
break;
- default:
err = OCSD_ERR_NO_PROTOCOL;
break;
- }
- return err;
+}
+#define INPUT_BLOCK_SIZE 1024
+/* process buffer until done or error */ +ocsd_err_t process_data_block(dcd_tree_handle_t dcd_tree_h, int block_index, uint8_t *p_block, const int block_size) +{
- ocsd_err_t ret = OCSD_OK;
- uint32_t bytes_done = 0;
- ocsd_datapath_resp_t dp_ret = OCSD_RESP_CONT;
- uint32_t bytes_this_time = 0;
- while((bytes_done < (uint32_t)block_size) && (ret == OCSD_OK))
- {
if(OCSD_DATA_RESP_IS_CONT(dp_ret))
{
dp_ret = ocsd_dt_process_data(dcd_tree_h,
OCSD_OP_DATA,
block_index+bytes_done,
block_size-bytes_done,
((uint8_t *)p_block)+bytes_done,
&bytes_this_time);
bytes_done += bytes_this_time;
}
else if(OCSD_DATA_RESP_IS_WAIT(dp_ret))
{
dp_ret = ocsd_dt_process_data(dcd_tree_h, OCSD_OP_FLUSH,0,0,NULL,NULL);
}
else
ret = OCSD_ERR_DATA_DECODE_FATAL; /* data path responded with an error - stop processing */
- }
- return ret;
+}
+int process_trace_data(FILE *pf) +{
- ocsd_err_t ret = OCSD_OK;
- dcd_tree_handle_t dcdtree_handle = C_API_INVALID_TREE_HANDLE;
- uint8_t data_buffer[INPUT_BLOCK_SIZE];
- ocsd_trc_index_t index = 0;
- size_t data_read;
- /* Create a decode tree for this source data.
source data is frame formatted, memory aligned from an ETR (no frame syncs) so create tree accordingly
- */
A '*' is missing at the beginning of the second line.
- dcdtree_handle = ocsd_create_dcd_tree(OCSD_TRC_SRC_FRAME_FORMATTED, OCSD_DFRMTR_FRAME_MEM_ALIGN);
- if(dcdtree_handle != C_API_INVALID_TREE_HANDLE)
- {
ret = create_decoder(dcdtree_handle);
ocsd_tl_log_mapped_mem_ranges(dcdtree_handle);
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);
/* now push the trace data through the packet processor */
while(!feof(pf) && (ret == OCSD_OK))
{
/* read from file */
data_read = fread(data_buffer,1,INPUT_BLOCK_SIZE,pf);
if(data_read > 0)
{
/* process a block of data - any packets from the trace stream
we have configured will appear at the callback
*/
ret = process_data_block(dcdtree_handle,
index,
data_buffer,
data_read);
index += data_read;
}
else if(ferror(pf))
ret = OCSD_ERR_FILE_ERROR;
}
/* no errors - let the data path know we are at end of trace */
if(ret == OCSD_OK)
ocsd_dt_process_data(dcdtree_handle, OCSD_OP_EOT, 0,0,NULL,NULL);
Extra space.
/* shut down the mem acc CB if in use. */
if(using_mem_acc_cb)
{
destroy_mem_acc_cb(dcdtree_handle);
}
/* dispose of the decode tree - which will dispose of any packet processors we created
*/
ocsd_destroy_dcd_tree(dcdtree_handle);
- }
- else
- {
printf("Failed to create trace decode tree\n");
ret = OCSD_ERR_NOT_INIT;
- }
- return (int)ret;
+}
+int main(int argc, char *argv[]) +{
- FILE *trace_data;
- char trace_file_path[512];
- int ret = 0;
- char message[512];
- /* command line params */
- if(process_cmd_line(argc,argv) != 0)
- {
print_cmd_line_help();
return -2;
- }
- /* trace data file path */
- strcpy(trace_file_path,default_path_to_snapshot);
- strcat(trace_file_path,trace_data_filename);
- trace_data = fopen(trace_file_path,"rb");
- if(trace_data != NULL)
- {
/* set up the logging in the library - enable the error logger, with an output printer*/
ret = ocsd_def_errlog_init(OCSD_ERR_SEV_INFO,1);
/* set up the output - to file and stdout, set custom logfile name */
if(ret == 0)
ret = ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_FILE | C_API_MSGLOGOUT_FLG_STDOUT, "c_api_test.log");
/* print sign-on message in log */
sprintf(message, "C-API packet print test\nLibrary Version %s\n\n",ocsd_get_version_str());
ocsd_def_errlog_msgout(message);
/* process the trace data */
if(ret == 0)
ret = process_trace_data(trace_data);
/* close the data file */
fclose(trace_data);
- }
- else
- {
printf("Unable to open file %s to process trace data\n", trace_file_path);
ret = -1;
- }
- return ret;
+} +/* End of File simple_pkt_c_api.c */ diff --git a/decoder/tests/source/simple_pkt_c_api.c b/decoder/tests/source/simple_pkt_c_api.c index 6c6e503..32312b8 100644 --- a/decoder/tests/source/simple_pkt_c_api.c +++ b/decoder/tests/source/simple_pkt_c_api.c @@ -46,6 +46,7 @@ #include <stdint.h> #include <stdlib.h>
+#define OPENCSD_INC_DEPRECATED_API /* include the C-API library header */ #include "c_api/opencsd_c_api.h"
-- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight