Patchset for the OpenCSD 0v004 release.
Updates to allow decoder registration and decoder selection by name. Adds generic handling of decoders in the APIs. First stage in providing custom external decoder interface.
C API and decode tree API updates to use the new functionality.
Updated test programs. C-API test program re-written to use new API and re-names.
Deprecated functionality still available on conditional compile for regression testing.
Signed-off-by: Mike Leach mike.leach@linaro.org
Mike Leach (19): opencsd: Updated version numbers to 0v004. opencsd: Updated docs and help opencsd: Add .bash scripts - library testing in perf opencsd: bugfix - ETMv4, PTM - output packet error. opencsd: Add new base class for trace component config. opencsd: Adds abstract base class interface opencsd: adds classes to handle decoder registration and management opencsd: updates to code to utilize decoder registration. opencsd: Add protocol type ID to decoder manager opencsd: DecodeTree modifications - using new API fns. opencsd: bugfix - etmv4 trace info packet opencsd: Updates to decoder registration code opencsd: Update C API functions to reflect new create decoder API. opencsd: Rework memory accessor API on decode tree. opencsd: Udpated linux makefiles for recent code updates. opencsd: Bugfix - initialisation of associated component pointer opencsd: remove C API deprecated types. opencsd: Doxygen comment updates. opencsd: bugfix - extraction of multibyte payload values from packets.
HOWTO.md | 134 +++- README.md | 10 +- decoder/build/linux/makefile | 2 + decoder/build/linux/rctdl_c_api_lib/makefile | 3 +- decoder/build/linux/ref_trace_decode_lib/makefile | 1 + .../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 +- .../ref_trace_decode_lib.vcxproj | 10 + .../ref_trace_decode_lib.vcxproj.filters | 30 + decoder/docs/doxygen_config.dox | 5 +- decoder/include/c_api/ocsd_c_api_deprc_fn.h | 233 ++++++ decoder/include/c_api/ocsd_c_api_types.h | 81 +- decoder/include/c_api/opencsd_c_api.h | 190 ++--- decoder/include/common/comp_attach_pt_t.h | 15 + decoder/include/common/ocsd_dcd_mngr.h | 397 ++++++++++ decoder/include/common/ocsd_dcd_mngr_i.h | 98 +++ decoder/include/common/ocsd_dcd_tree.h | 286 +++++-- decoder/include/common/ocsd_dcd_tree_elem.h | 169 ++--- decoder/include/common/ocsd_lib_dcd_register.h | 122 +++ decoder/include/common/trc_component.h | 22 +- decoder/include/common/trc_cs_config.h | 62 ++ decoder/include/common/trc_gen_elem.h | 6 + decoder/include/common/trc_pkt_decode_base.h | 36 +- decoder/include/common/trc_pkt_proc_base.h | 53 +- decoder/include/etmv3/trc_cmp_cfg_etmv3.h | 6 +- decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 57 ++ decoder/include/etmv4/trc_cmp_cfg_etmv4.h | 102 +-- decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 31 + decoder/include/interfaces/trc_abs_typed_base_i.h | 58 ++ decoder/include/interfaces/trc_indexer_pkt_i.h | 4 +- decoder/include/interfaces/trc_pkt_in_i.h | 4 +- decoder/include/interfaces/trc_pkt_raw_in_i.h | 4 +- decoder/include/ocsd_if_types.h | 88 ++- decoder/include/opencsd.h | 6 +- decoder/include/ptm/trc_cmp_cfg_ptm.h | 55 +- decoder/include/ptm/trc_dcd_mngr_ptm.h | 57 ++ decoder/include/stm/trc_cmp_cfg_stm.h | 55 +- decoder/include/stm/trc_dcd_mngr_stm.h | 55 ++ decoder/include/trc_gen_elem_types.h | 4 +- decoder/source/c_api/ocsd_c_api.cpp | 546 +++++--------- decoder/source/c_api/ocsd_c_api_deprc_fn.cpp | 200 +++++ decoder/source/c_api/ocsd_c_api_obj.h | 57 ++ decoder/source/etmv3/trc_pkt_proc_etmv3.cpp | 2 +- decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp | 40 +- decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp | 14 +- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp | 76 +- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h | 22 +- decoder/source/ocsd_dcd_tree.cpp | 518 ++++--------- decoder/source/ocsd_error.cpp | 6 + decoder/source/ocsd_lib_dcd_register.cpp | 172 +++++ decoder/source/ptm/trc_cmp_cfg_ptm.cpp | 17 +- decoder/source/ptm/trc_pkt_decode_ptm.cpp | 11 +- decoder/source/trc_component.cpp | 1 + .../build/linux/c_api_pkt_print_test/makefile | 82 ++ .../c_api_pkt_print_test.vcxproj | 325 ++++++++ .../c_api_pkt_print_test.vcxproj.filters | 22 + .../tests/perf-test-scripts/perf-setup-env.bash | 42 ++ .../tests/perf-test-scripts/perf-test-report.bash | 14 + .../tests/perf-test-scripts/perf-test-script.bash | 11 + .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 65 +- decoder/tests/source/c_api_pkt_print_test.c | 825 +++++++++++++++++++++ decoder/tests/source/gen_elem_printer.h | 2 +- decoder/tests/source/simple_pkt_c_api.c | 1 + decoder/tests/source/trc_pkt_lister.cpp | 30 +- 65 files changed, 4294 insertions(+), 1391 deletions(-) create mode 100644 decoder/include/c_api/ocsd_c_api_deprc_fn.h create mode 100644 decoder/include/common/ocsd_dcd_mngr.h create mode 100644 decoder/include/common/ocsd_dcd_mngr_i.h create mode 100644 decoder/include/common/ocsd_lib_dcd_register.h create mode 100644 decoder/include/common/trc_cs_config.h create mode 100644 decoder/include/etmv3/trc_dcd_mngr_etmv3.h create mode 100644 decoder/include/etmv4/trc_dcd_mngr_etmv4i.h create mode 100644 decoder/include/interfaces/trc_abs_typed_base_i.h create mode 100644 decoder/include/ptm/trc_dcd_mngr_ptm.h create mode 100644 decoder/include/stm/trc_dcd_mngr_stm.h create mode 100644 decoder/source/c_api/ocsd_c_api_deprc_fn.cpp create mode 100644 decoder/source/ocsd_lib_dcd_register.cpp create mode 100644 decoder/tests/build/linux/c_api_pkt_print_test/makefile 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 100755 decoder/tests/perf-test-scripts/perf-setup-env.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-report.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-script.bash create mode 100644 decoder/tests/source/c_api_pkt_print_test.c
Version 0v004 in development.
Ensure that any tests done during D&T of new feature do not have same version as the stable library.
Signed-off-by: Mike Leach mike.leach@linaro.org --- README.md | 3 ++- decoder/docs/doxygen_config.dox | 2 +- decoder/include/ocsd_if_types.h | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md index 9d07e94..b1e6c73 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The library is implemented in C++ with an optional "C" API. CoreSight Trace Component Support. ----------------------------------
-_Current Version 0.003_ +_Current Version 0.004_
### Current support:
@@ -78,6 +78,7 @@ Version and Modification Information - _Version 0.001_: Library development - tested with `perf` tools integration - BKK16, 8th March 2016 - _Version 0.002_: Library development - added in PTM decoder support. Restructure header dir, replaced ARM rctdl prefix with opencsd/ocsd. - _Version 0.003_: Library development - added in ETMv3 instruction decoder support. +- _Version 0.004_: In development - decode tree api updates.
Licence Information =================== diff --git a/decoder/docs/doxygen_config.dox b/decoder/docs/doxygen_config.dox index ed9f327..bdb24f0 100644 --- a/decoder/docs/doxygen_config.dox +++ b/decoder/docs/doxygen_config.dox @@ -38,7 +38,7 @@ PROJECT_NAME = "OpenCSD - CoreSight Trace Decode Library" # could be handy for archiving the generated documentation or if some version # control system is used.
-PROJECT_NUMBER = 0.003 +PROJECT_NUMBER = 0.004
# Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index 00f8604..4fb428d 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -48,8 +48,8 @@ /** @name Library Versioning @{*/ #define OCSD_VER_MAJOR 0x0 /**< Library Major Version */ -#define OCSD_VER_MINOR 0x3 /**< Library Minor Version */ -#define OCSD_VER_STRING "0.003" /**< Library Version string */ +#define OCSD_VER_MINOR 0x4 /**< Library Minor Version */ +#define OCSD_VER_STRING "0.004" /**< Library Version string */ #define OCSD_LIB_NAME "OpenCSD Library" /**< Library name string */ #define OCSD_LIB_SHORT_NAME "OCSD" /**< Library Short name string */ /** @}*/
On 01.08.16 14:19 +0100, Mike Leach wrote:
Version 0v004 in development.
Ensure that any tests done during D&T of new feature do not have same version as the stable library.
Signed-off-by: Mike Leach mike.leach@linaro.org
README.md | 3 ++- decoder/docs/doxygen_config.dox | 2 +- decoder/include/ocsd_if_types.h | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md index 9d07e94..b1e6c73 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The library is implemented in C++ with an optional "C" API. CoreSight Trace Component Support.
-_Current Version 0.003_ +_Current Version 0.004_ ### Current support: @@ -78,6 +78,7 @@ Version and Modification Information
- _Version 0.001_: Library development - tested with `perf` tools integration - BKK16, 8th March 2016
- _Version 0.002_: Library development - added in PTM decoder support. Restructure header dir, replaced ARM rctdl prefix with opencsd/ocsd.
- _Version 0.003_: Library development - added in ETMv3 instruction decoder support.
+- _Version 0.004_: In development - decode tree api updates. Licence Information =================== diff --git a/decoder/docs/doxygen_config.dox b/decoder/docs/doxygen_config.dox index ed9f327..bdb24f0 100644 --- a/decoder/docs/doxygen_config.dox +++ b/decoder/docs/doxygen_config.dox @@ -38,7 +38,7 @@ PROJECT_NAME = "OpenCSD - CoreSight Trace Decode Library" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.003 +PROJECT_NUMBER = 0.004 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index 00f8604..4fb428d 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -48,8 +48,8 @@ /** @name Library Versioning @{*/ #define OCSD_VER_MAJOR 0x0 /**< Library Major Version */ -#define OCSD_VER_MINOR 0x3 /**< Library Minor Version */
Mike, have we considered using semantic versioning schema? http://semver.org/
-#define OCSD_VER_STRING "0.003" /**< Library Version string */ +#define OCSD_VER_MINOR 0x4 /**< Library Minor Version */ +#define OCSD_VER_STRING "0.004" /**< Library Version string */ #define OCSD_LIB_NAME "OpenCSD Library" /**< Library name string */ #define OCSD_LIB_SHORT_NAME "OCSD" /**< Library Short name string */ /** @}*/ -- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight
I hadn't, but I have no objection to using this as a versioning mechanism
Mike
On 8 August 2016 at 06:40, Serge Broslavsky serge.broslavsky@linaro.org wrote:
On 01.08.16 14:19 +0100, Mike Leach wrote:
Version 0v004 in development.
Ensure that any tests done during D&T of new feature do not have same
version as the stable library.
Signed-off-by: Mike Leach mike.leach@linaro.org
README.md | 3 ++- decoder/docs/doxygen_config.dox | 2 +- decoder/include/ocsd_if_types.h | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md index 9d07e94..b1e6c73 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The library is implemented in C++ with an optional "C"
API.
CoreSight Trace Component Support.
-_Current Version 0.003_ +_Current Version 0.004_
### Current support:
@@ -78,6 +78,7 @@ Version and Modification Information
- _Version 0.001_: Library development - tested with `perf` tools
integration - BKK16, 8th March 2016
- _Version 0.002_: Library development - added in PTM decoder support.
Restructure header dir, replaced ARM rctdl prefix with opencsd/ocsd.
- _Version 0.003_: Library development - added in ETMv3 instruction
decoder support.
+- _Version 0.004_: In development - decode tree api updates.
Licence Information
diff --git a/decoder/docs/doxygen_config.dox
b/decoder/docs/doxygen_config.dox
index ed9f327..bdb24f0 100644 --- a/decoder/docs/doxygen_config.dox +++ b/decoder/docs/doxygen_config.dox @@ -38,7 +38,7 @@ PROJECT_NAME = "OpenCSD - CoreSight Trace
Decode Library"
# could be handy for archiving the generated documentation or if some
version
# control system is used.
-PROJECT_NUMBER = 0.003 +PROJECT_NUMBER = 0.004
# Using the PROJECT_BRIEF tag one can provide an optional one line
description
# for a project that appears at the top of each page and should give
viewer a
diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_
types.h
index 00f8604..4fb428d 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -48,8 +48,8 @@ /** @name Library Versioning @{*/ #define OCSD_VER_MAJOR 0x0 /**< Library Major Version */ -#define OCSD_VER_MINOR 0x3 /**< Library Minor Version */
Mike, have we considered using semantic versioning schema? http://semver.org/
-#define OCSD_VER_STRING "0.003" /**< Library Version string */ +#define OCSD_VER_MINOR 0x4 /**< Library Minor Version */ +#define OCSD_VER_STRING "0.004" /**< Library Version string */ #define OCSD_LIB_NAME "OpenCSD Library" /**< Library name string */ #define OCSD_LIB_SHORT_NAME "OCSD" /**< Library Short name string */ /** @}*/ -- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight
-- Best Regards, Serge Broslavsky serge.broslavsky@linaro.org
Core Development Project Manager, Linaro M: +37129426328 IRC: ototo Skype: serge.broslavsky http://linaro.org | Open source software for ARM SoCs
README: change to work done / work TBD for STM
Help program: Updated output of help message to include the -log*** commands. Allowed help with input of any of -help --help -h.
HOWTO: Updated the HOWTO document to reflect operation with the latest perf-opencsd branch, perf-opencsd-4.7-rc4, and the opencsd-0v003 library branch.
Added addtional example using the --dump option in perf report to see trace packet data. Signed-off-by: Mike Leach mike.leach@linaro.org --- HOWTO.md | 90 +++++++++++++++++++++++++-------- README.md | 7 ++- decoder/tests/source/trc_pkt_lister.cpp | 14 +++-- 3 files changed, 85 insertions(+), 26 deletions(-)
diff --git a/HOWTO.md b/HOWTO.md index 93d6a9d..ad19e9e 100644 --- a/HOWTO.md +++ b/HOWTO.md @@ -7,9 +7,9 @@ This HOWTO explains how to use the perf cmd line tools and the openCSD library to collect and extract program flow traces generated by the CoreSight IP blocks on a Linux system. The examples have been generated using an aarch64 Juno-r0 platform. All information is considered accurate and tested -using library branch `opencsd-0v003` (decode library only) and the latest perf -branch `perf-opencsd-4.7-rc1` (decode library + perf tools) on the -[OpenCSD github repository][1]. +using library branches `opencsd-0v002` and `opencsd-0v003` (decode library only) +and the latest perf branch `perf-opencsd-4.7-rc4` (decode library + perf tools) +on the [OpenCSD github repository][1].
On Target Trace Acquisition - Perf Record @@ -17,8 +17,8 @@ On Target Trace Acquisition - Perf Record
All the enhancement to the Perf tools that support the new `cs_etm` pmu have not been upstreamed yet. To get the required functionality branch -`perf-opencsd-4.7-rc1` needs to be downloaded to the target system where -traces are to be collected. This branch is an upstream v4.7-rc1 kernel +`perf-opencsd-4.7-rc4` needs to be downloaded to the target system where +traces are to be collected. This branch is an upstream v4.7-rc4 kernel supplemented with modifications to the CoreSight framework and drivers to be usable by the Perf core. The remaining out of tree patches are being upstreamed incrementally. @@ -135,42 +135,42 @@ Off Target OpenCSD Compilation As of this writing the openCSD library is not part of the perf tools source. It is available on [github][1] and needs to be compiled before perf.
- linaro@t430:~/linaro/coresight$ git clone -b opencsd-0v002 https://github.com/Linaro/OpenCSD.git opencsd-0v002 + linaro@t430:~/linaro/coresight$ git clone -b opencsd-0v003 https://github.com/Linaro/OpenCSD.git opencsd-0v003 Cloning into 'OpenCSD'... remote: Counting objects: 2063, done. remote: Total 2063 (delta 0), reused 0 (delta 0), pack-reused 2063 Receiving objects: 100% (2063/2063), 2.51 MiB | 1.24 MiB/s, done. Resolving deltas: 100% (1399/1399), done. Checking connectivity... done. - linaro@t430:~/linaro/coresight$ ls opencsd-0v002 + linaro@t430:~/linaro/coresight$ ls opencsd-0v003 decoder LICENSE README.md
Once the source code has been acquired compilation of the openCSD library can take place. For Linux two options are available, LINUX and LINUX64, based on the host's (which has nothing to do with the target) architecture:
- linaro@t430:~/linaro/coresight/$ cd opencsd-0v002/decoder/build/linux/ - linaro@t430:~/linaro/coresight/opencsd-0v002/decoder/build/linux$ ls + linaro@t430:~/linaro/coresight/$ cd opencsd-0v003/decoder/build/linux/ + linaro@t430:~/linaro/coresight/opencsd-0v003/decoder/build/linux$ ls makefile rctdl_c_api_lib ref_trace_decode_lib
- linaro@t430:~/linaro/coresight/opencsd-0v002/decoder/build/linux$ make LINUX64=1 DEBUG=1 + linaro@t430:~/linaro/coresight/opencsd-0v003/decoder/build/linux$ make LINUX64=1 DEBUG=1 ... ...
- linaro@t430:~/linaro/coresight/opencsd-0v002/decoder/build/linux$ ls ../../lib/linux64/dbg/ + linaro@t430:~/linaro/coresight/opencsd-0v003/decoder/build/linux$ ls ../../lib/linux64/dbg/ libcstraced.a libcstraced_c_api.a libcstraced_c_api.so libcstraced.so
Off Target Perf Tools Compilation --------------------------------- As stated above not all the pieces of the solution have been upstreamed. To -get all the components branch `perf-opencsd-4.7-rc1` needs to be +get all the components branch `perf-opencsd-4.7-rc4` needs to be obtained:
- linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7-rc1 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7-rc1 + linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7-rc4 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7-rc4 ... ...
- linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7-rc1/ + linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7-rc4/ arch certs CREDITS Documentation firmware include ipc Kconfig lib Makefile net REPORTING-BUGS scripts sound usr block COPYING crypto drivers fs init Kbuild kernel MAINTAINERS mm README samples security tools virt
@@ -179,12 +179,12 @@ variable telling the build scripts where to find the library is needed. If the `CSTRACE_PATH` variable is not defined the compilation will still be successful, but handling of CoreSight trace data won't be supported.
- linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7-rc1 - linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc1$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v002/decoder - linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc1$ make -C tools/perf + linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7-rc4 + linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v003/decoder + linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ make -C tools/perf ... ... - linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc1$ ls -l tools/perf/perf + linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ ls -l tools/perf/perf -rwxrwxr-x 1 linaro linaro 6276360 Mar 3 10:05 tools/perf/perf
@@ -223,8 +223,8 @@ to be sure everything is clean.
linaro@t430:~/linaro/coresight/feb24$ rm -rf ~/.debug linaro@t430:~/linaro/coresight/feb24$ cp -dpR .debug ~/ - linaro@t430:~/linaro/coresight/feb24$ export LD_LIBRARY_PATH=~/linaro/coresight/opencsd-0v002/decoder/lib/linux64/dbg/ - linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc1/tools/perf/perf report --stdio + linaro@t430:~/linaro/coresight/feb24$ export LD_LIBRARY_PATH=~/linaro/coresight/opencsd-0v003/decoder/lib/linux64/dbg/ + linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf report --stdio
# To display the perf.data header info, please use --header/--header-only options. # @@ -266,15 +266,61 @@ to be sure everything is clean. 1.24% 1.24% uname libc-2.21.so [.] 0x00000000000fcab8 ...
+Additional data can be obtained, which contains a dump of the trace packets received using the command + + mjl@ubuntu-vbox:./perf-opencsd-4.7-rc4/coresight/tools/perf/perf report --stdio --dump + +resulting a large amount of data, trace looking like:- + + 0x618 [0x30]: PERF_RECORD_AUXTRACE size: 0x11ef0 offset: 0 ref: 0x4d881c1f13216016 idx: 0 tid: 15244 cpu: -1 + + . ... CoreSight ETM Trace data: size 73456 bytes + + 0: I_ASYNC : Alignment Synchronisation. + 12: I_TRACE_INFO : Trace Info. + 17: I_TRACE_ON : Trace On. + 18: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F24D80; Ctxt: AArch64,EL0, NS; + 28: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE + 29: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE + 30: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE + 32: I_ATOM_F6 : Atom format 6.; EEEEN + 33: I_ATOM_F1 : Atom format 1.; E + 34: I_EXCEPT : Exception.; Data Fault; Ret Addr Follows; + 36: I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000007F89F2832C; + 45: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0xFFFFFFC000083400; Ctxt: AArch64,EL1, NS; + 56: I_TRACE_ON : Trace On. + 57: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F2832C; Ctxt: AArch64,EL0, NS; + 68: I_ATOM_F3 : Atom format 3.; NEE + 69: I_ATOM_F3 : Atom format 3.; NEN + 70: I_ATOM_F3 : Atom format 3.; NNE + 71: I_ATOM_F5 : Atom format 5.; ENENE + 72: I_ATOM_F5 : Atom format 5.; NENEN + 73: I_ATOM_F5 : Atom format 5.; ENENE + 74: I_ATOM_F5 : Atom format 5.; NENEN + 75: I_ATOM_F5 : Atom format 5.; ENENE + 76: I_ATOM_F3 : Atom format 3.; NNE + 77: I_ATOM_F3 : Atom format 3.; NNE + 78: I_ATOM_F3 : Atom format 3.; NNE + 80: I_ATOM_F3 : Atom format 3.; NNE + 81: I_ATOM_F3 : Atom format 3.; ENN + 82: I_EXCEPT : Exception.; Data Fault; Ret Addr Follows; + 84: I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000007F89F283F0; + 93: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0xFFFFFFC000083400; Ctxt: AArch64,EL1, NS; + 104: I_TRACE_ON : Trace On. + 105: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F283F0; Ctxt: AArch64,EL0, NS; + 116: I_ATOM_F5 : Atom format 5.; NNNNN + 117: I_ATOM_F5 : Atom format 5.; NNNNN + + Trace Decoding with Perf Script ------------------------------- Working with perf scripts needs more command line options but yields interesting results.
- linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7-rc1/tools/perf/ + linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7-rc4/tools/perf/ linaro@t430:~/linaro/coresight/feb24$ export SCRIPT_PATH=$EXEC_PATH/scripts/python/ linaro@t430:~/linaro/coresight/feb24$ export XTOOL_PATH=/your/aarch64/toolchain/path/bin/ - linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc1/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump + linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump
7f89f24d80: 910003e0 mov x0, sp 7f89f24d84: 94000d53 bl 7f89f282d0 <free@plt+0x3790> diff --git a/README.md b/README.md index b1e6c73..d422b4a 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,15 @@ _Current Version 0.004_
### Support to be added:
-- ITM software trace - packet processing. +- STM software trace - packet decode. +- ITM software trace - packet processing and decode. - ETMv3 data trace - packet decode. - ETMv4 data trace - packet processing and decode.
+Note: for ITM and STM, packet decode is combining Master+Channel+Marker+Payload packets into a single generic +output packet. + + Note on the Git Repository. ---------------------------
diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index c96d09b..893bc36 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -181,10 +181,10 @@ void print_help() { std::ostringstream oss; oss << "Trace Packet Lister - commands\n\n"; - oss << "Snapshot:\n"; + oss << "Snapshot:\n\n"; oss << "-ss_dir <dir> Set the directory path to a trace snapshot\n"; oss << "-ss_verbose Verbose output when reading the snapshot\n"; - oss << "Decode:\n"; + oss << "\nDecode:\n\n"; oss << "-id <n> Set an ID to list (may be used mutiple times) - default if no id set is for all IDs to be printed\n"; oss << "-src_name <name> List packets from a given snapshot source name (defaults to first source found)\n"; oss << "-decode Full decode of the packets from the trace snapshot (default is to list undecoded packets only\n"; @@ -192,6 +192,14 @@ void print_help() oss << "-o_raw_packed Output raw packed trace frames\n"; oss << "-o_raw_unpacked Output raw unpacked trace data per ID\n"; oss << "-test_waits <N> Force wait from packet printer for N packets - test the wait/flush mechanisms for the decoder\n"; + oss << "\nOutput:\n"; + oss << " Setting any of these options cancels the default output to file & stdout,\n using _only_ the options supplied.\n\n"; + oss << "-logstdout Output to stdout -> console.\n"; + oss << "-logstderr Output to stderr.\n"; + oss << "-logfile Output to default file - " << logfileName << "\n"; + oss << "-logfilename <name> Output to file <name> \n"; + + logger.LogMsg(oss.str()); }
@@ -381,7 +389,7 @@ bool process_cmd_line_opts(int argc, char* argv[]) no_undecoded_packets = true; decode = true; } - else if(strcmp(argv[optIdx], "-help") == 0) + else if((strcmp(argv[optIdx], "-help") == 0) || (strcmp(argv[optIdx], "--help") == 0) || (strcmp(argv[optIdx], "-h") == 0)) { print_help(); bOptsOK = false;
On 1 August 2016 at 07:19, Mike Leach mike.leach@linaro.org wrote:
README: change to work done / work TBD for STM
Help program: Updated output of help message to include the -log*** commands. Allowed help with input of any of -help --help -h.
HOWTO: Updated the HOWTO document to reflect operation with the latest perf-opencsd branch, perf-opencsd-4.7-rc4, and the opencsd-0v003 library branch.
Branch perf-opencsd-4.7-rc4 no longer exist - I've replaced it with the official perf-opencsd-4.7. Other than being based on an official kernel release, the functionality is the same.
And shoudn't it be opencsd-0v004 rather than opencsd-0v003?
Added addtional example using the --dump option in perf report to see trace packet data.
Signed-off-by: Mike Leach mike.leach@linaro.org
HOWTO.md | 90 +++++++++++++++++++++++++-------- README.md | 7 ++- decoder/tests/source/trc_pkt_lister.cpp | 14 +++-- 3 files changed, 85 insertions(+), 26 deletions(-)
diff --git a/HOWTO.md b/HOWTO.md index 93d6a9d..ad19e9e 100644 --- a/HOWTO.md +++ b/HOWTO.md @@ -7,9 +7,9 @@ This HOWTO explains how to use the perf cmd line tools and the openCSD library to collect and extract program flow traces generated by the CoreSight IP blocks on a Linux system. The examples have been generated using an aarch64 Juno-r0 platform. All information is considered accurate and tested -using library branch `opencsd-0v003` (decode library only) and the latest perf -branch `perf-opencsd-4.7-rc1` (decode library + perf tools) on the -[OpenCSD github repository][1]. +using library branches `opencsd-0v002` and `opencsd-0v003` (decode library only) +and the latest perf branch `perf-opencsd-4.7-rc4` (decode library + perf tools) +on the [OpenCSD github repository][1].
On Target Trace Acquisition - Perf Record @@ -17,8 +17,8 @@ On Target Trace Acquisition - Perf Record
All the enhancement to the Perf tools that support the new `cs_etm` pmu have not been upstreamed yet. To get the required functionality branch -`perf-opencsd-4.7-rc1` needs to be downloaded to the target system where -traces are to be collected. This branch is an upstream v4.7-rc1 kernel +`perf-opencsd-4.7-rc4` needs to be downloaded to the target system where +traces are to be collected. This branch is an upstream v4.7-rc4 kernel supplemented with modifications to the CoreSight framework and drivers to be usable by the Perf core. The remaining out of tree patches are being upstreamed incrementally. @@ -135,42 +135,42 @@ Off Target OpenCSD Compilation As of this writing the openCSD library is not part of the perf tools source. It is available on [github][1] and needs to be compiled before perf.
- linaro@t430:~/linaro/coresight$ git clone -b opencsd-0v002 https://github.com/Linaro/OpenCSD.git opencsd-0v002
- linaro@t430:~/linaro/coresight$ git clone -b opencsd-0v003 https://github.com/Linaro/OpenCSD.git opencsd-0v003 Cloning into 'OpenCSD'... remote: Counting objects: 2063, done. remote: Total 2063 (delta 0), reused 0 (delta 0), pack-reused 2063 Receiving objects: 100% (2063/2063), 2.51 MiB | 1.24 MiB/s, done. Resolving deltas: 100% (1399/1399), done. Checking connectivity... done.
- linaro@t430:~/linaro/coresight$ ls opencsd-0v002
- linaro@t430:~/linaro/coresight$ ls opencsd-0v003 decoder LICENSE README.md
Once the source code has been acquired compilation of the openCSD library can take place. For Linux two options are available, LINUX and LINUX64, based on the host's (which has nothing to do with the target) architecture:
- linaro@t430:~/linaro/coresight/$ cd opencsd-0v002/decoder/build/linux/
- linaro@t430:~/linaro/coresight/opencsd-0v002/decoder/build/linux$ ls
- linaro@t430:~/linaro/coresight/$ cd opencsd-0v003/decoder/build/linux/
- linaro@t430:~/linaro/coresight/opencsd-0v003/decoder/build/linux$ ls makefile rctdl_c_api_lib ref_trace_decode_lib
- linaro@t430:~/linaro/coresight/opencsd-0v002/decoder/build/linux$ make LINUX64=1 DEBUG=1
- linaro@t430:~/linaro/coresight/opencsd-0v003/decoder/build/linux$ make LINUX64=1 DEBUG=1 ... ...
- linaro@t430:~/linaro/coresight/opencsd-0v002/decoder/build/linux$ ls ../../lib/linux64/dbg/
- linaro@t430:~/linaro/coresight/opencsd-0v003/decoder/build/linux$ ls ../../lib/linux64/dbg/ libcstraced.a libcstraced_c_api.a libcstraced_c_api.so libcstraced.so
Off Target Perf Tools Compilation
As stated above not all the pieces of the solution have been upstreamed. To -get all the components branch `perf-opencsd-4.7-rc1` needs to be +get all the components branch `perf-opencsd-4.7-rc4` needs to be obtained:
- linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7-rc1 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7-rc1
- linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7-rc4 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7-rc4 ... ...
- linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7-rc1/
- linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7-rc4/ arch certs CREDITS Documentation firmware include ipc Kconfig lib Makefile net REPORTING-BUGS scripts sound usr block COPYING crypto drivers fs init Kbuild kernel MAINTAINERS mm README samples security tools virt
@@ -179,12 +179,12 @@ variable telling the build scripts where to find the library is needed. If the `CSTRACE_PATH` variable is not defined the compilation will still be successful, but handling of CoreSight trace data won't be supported.
- linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7-rc1
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc1$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v002/decoder
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc1$ make -C tools/perf
- linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7-rc4
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v003/decoder
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ make -C tools/perf ... ...
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc1$ ls -l tools/perf/perf
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ ls -l tools/perf/perf -rwxrwxr-x 1 linaro linaro 6276360 Mar 3 10:05 tools/perf/perf
@@ -223,8 +223,8 @@ to be sure everything is clean.
linaro@t430:~/linaro/coresight/feb24$ rm -rf ~/.debug linaro@t430:~/linaro/coresight/feb24$ cp -dpR .debug ~/
- linaro@t430:~/linaro/coresight/feb24$ export LD_LIBRARY_PATH=~/linaro/coresight/opencsd-0v002/decoder/lib/linux64/dbg/
- linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc1/tools/perf/perf report --stdio
linaro@t430:~/linaro/coresight/feb24$ export LD_LIBRARY_PATH=~/linaro/coresight/opencsd-0v003/decoder/lib/linux64/dbg/
linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf report --stdio
# To display the perf.data header info, please use --header/--header-only options. #
@@ -266,15 +266,61 @@ to be sure everything is clean. 1.24% 1.24% uname libc-2.21.so [.] 0x00000000000fcab8 ...
+Additional data can be obtained, which contains a dump of the trace packets received using the command
- mjl@ubuntu-vbox:./perf-opencsd-4.7-rc4/coresight/tools/perf/perf report --stdio --dump
+resulting a large amount of data, trace looking like:-
- 0x618 [0x30]: PERF_RECORD_AUXTRACE size: 0x11ef0 offset: 0 ref: 0x4d881c1f13216016 idx: 0 tid: 15244 cpu: -1
- . ... CoreSight ETM Trace data: size 73456 bytes
0: I_ASYNC : Alignment Synchronisation.
12: I_TRACE_INFO : Trace Info.
17: I_TRACE_ON : Trace On.
18: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F24D80; Ctxt: AArch64,EL0, NS;
28: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE
29: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE
30: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE
32: I_ATOM_F6 : Atom format 6.; EEEEN
33: I_ATOM_F1 : Atom format 1.; E
34: I_EXCEPT : Exception.; Data Fault; Ret Addr Follows;
36: I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000007F89F2832C;
45: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0xFFFFFFC000083400; Ctxt: AArch64,EL1, NS;
56: I_TRACE_ON : Trace On.
57: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F2832C; Ctxt: AArch64,EL0, NS;
68: I_ATOM_F3 : Atom format 3.; NEE
69: I_ATOM_F3 : Atom format 3.; NEN
70: I_ATOM_F3 : Atom format 3.; NNE
71: I_ATOM_F5 : Atom format 5.; ENENE
72: I_ATOM_F5 : Atom format 5.; NENEN
73: I_ATOM_F5 : Atom format 5.; ENENE
74: I_ATOM_F5 : Atom format 5.; NENEN
75: I_ATOM_F5 : Atom format 5.; ENENE
76: I_ATOM_F3 : Atom format 3.; NNE
77: I_ATOM_F3 : Atom format 3.; NNE
78: I_ATOM_F3 : Atom format 3.; NNE
80: I_ATOM_F3 : Atom format 3.; NNE
81: I_ATOM_F3 : Atom format 3.; ENN
82: I_EXCEPT : Exception.; Data Fault; Ret Addr Follows;
84: I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000007F89F283F0;
93: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0xFFFFFFC000083400; Ctxt: AArch64,EL1, NS;
104: I_TRACE_ON : Trace On.
105: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F283F0; Ctxt: AArch64,EL0, NS;
116: I_ATOM_F5 : Atom format 5.; NNNNN
117: I_ATOM_F5 : Atom format 5.; NNNNN
Trace Decoding with Perf Script
Working with perf scripts needs more command line options but yields interesting results.
- linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7-rc1/tools/perf/
- linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7-rc4/tools/perf/ linaro@t430:~/linaro/coresight/feb24$ export SCRIPT_PATH=$EXEC_PATH/scripts/python/ linaro@t430:~/linaro/coresight/feb24$ export XTOOL_PATH=/your/aarch64/toolchain/path/bin/
- linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc1/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump
linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump
7f89f24d80: 910003e0 mov x0, sp 7f89f24d84: 94000d53 bl 7f89f282d0 <free@plt+0x3790>
diff --git a/README.md b/README.md index b1e6c73..d422b4a 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,15 @@ _Current Version 0.004_
### Support to be added:
-- ITM software trace - packet processing. +- STM software trace - packet decode. +- ITM software trace - packet processing and decode.
- ETMv3 data trace - packet decode.
- ETMv4 data trace - packet processing and decode.
+Note: for ITM and STM, packet decode is combining Master+Channel+Marker+Payload packets into a single generic +output packet.
Note on the Git Repository.
diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index c96d09b..893bc36 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -181,10 +181,10 @@ void print_help() { std::ostringstream oss; oss << "Trace Packet Lister - commands\n\n";
- oss << "Snapshot:\n";
- oss << "Snapshot:\n\n"; oss << "-ss_dir <dir> Set the directory path to a trace snapshot\n"; oss << "-ss_verbose Verbose output when reading the snapshot\n";
- oss << "Decode:\n";
- oss << "\nDecode:\n\n"; oss << "-id <n> Set an ID to list (may be used mutiple times) - default if no id set is for all IDs to be printed\n"; oss << "-src_name <name> List packets from a given snapshot source name (defaults to first source found)\n"; oss << "-decode Full decode of the packets from the trace snapshot (default is to list undecoded packets only\n";
@@ -192,6 +192,14 @@ void print_help() oss << "-o_raw_packed Output raw packed trace frames\n"; oss << "-o_raw_unpacked Output raw unpacked trace data per ID\n"; oss << "-test_waits <N> Force wait from packet printer for N packets - test the wait/flush mechanisms for the decoder\n";
- oss << "\nOutput:\n";
- oss << " Setting any of these options cancels the default output to file & stdout,\n using _only_ the options supplied.\n\n";
- oss << "-logstdout Output to stdout -> console.\n";
- oss << "-logstderr Output to stderr.\n";
- oss << "-logfile Output to default file - " << logfileName << "\n";
- oss << "-logfilename <name> Output to file <name> \n";
- logger.LogMsg(oss.str());
}
@@ -381,7 +389,7 @@ bool process_cmd_line_opts(int argc, char* argv[]) no_undecoded_packets = true; decode = true; }
else if(strcmp(argv[optIdx], "-help") == 0)
else if((strcmp(argv[optIdx], "-help") == 0) || (strcmp(argv[optIdx], "--help") == 0) || (strcmp(argv[optIdx], "-h") == 0)) { print_help(); bOptsOK = false;
-- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight
Added bash scripts to setup build and test environment variables required when testing the library with perf report and perf script.
Updated HOWTO.md to describe the use of these scripts. Adjust for latest opencsd-perf branch.
Signed-off-by: Mike Leach mike.leach@linaro.org --- HOWTO.md | 70 ++++++++++++++++++---- .../tests/perf-test-scripts/perf-setup-env.bash | 42 +++++++++++++ .../tests/perf-test-scripts/perf-test-report.bash | 14 +++++ .../tests/perf-test-scripts/perf-test-script.bash | 11 ++++ 4 files changed, 124 insertions(+), 13 deletions(-) create mode 100755 decoder/tests/perf-test-scripts/perf-setup-env.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-report.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-script.bash
diff --git a/HOWTO.md b/HOWTO.md index ad19e9e..6d3cde3 100644 --- a/HOWTO.md +++ b/HOWTO.md @@ -8,7 +8,7 @@ library to collect and extract program flow traces generated by the CoreSight IP blocks on a Linux system. The examples have been generated using an aarch64 Juno-r0 platform. All information is considered accurate and tested using library branches `opencsd-0v002` and `opencsd-0v003` (decode library only) -and the latest perf branch `perf-opencsd-4.7-rc4` (decode library + perf tools) +and the latest perf branch `perf-opencsd-4.7` (decode library + perf tools) on the [OpenCSD github repository][1].
@@ -17,7 +17,7 @@ On Target Trace Acquisition - Perf Record
All the enhancement to the Perf tools that support the new `cs_etm` pmu have not been upstreamed yet. To get the required functionality branch -`perf-opencsd-4.7-rc4` needs to be downloaded to the target system where +`perf-opencsd-4.7` needs to be downloaded to the target system where traces are to be collected. This branch is an upstream v4.7-rc4 kernel supplemented with modifications to the CoreSight framework and drivers to be usable by the Perf core. The remaining out of tree patches are being @@ -163,14 +163,14 @@ the host's (which has nothing to do with the target) architecture: Off Target Perf Tools Compilation --------------------------------- As stated above not all the pieces of the solution have been upstreamed. To -get all the components branch `perf-opencsd-4.7-rc4` needs to be +get all the components branch `perf-opencsd-4.7` needs to be obtained:
- linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7-rc4 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7-rc4 + linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7 ... ...
- linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7-rc4/ + linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7/ arch certs CREDITS Documentation firmware include ipc Kconfig lib Makefile net REPORTING-BUGS scripts sound usr block COPYING crypto drivers fs init Kbuild kernel MAINTAINERS mm README samples security tools virt
@@ -179,12 +179,14 @@ variable telling the build scripts where to find the library is needed. If the `CSTRACE_PATH` variable is not defined the compilation will still be successful, but handling of CoreSight trace data won't be supported.
- linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7-rc4 - linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v003/decoder - linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ make -C tools/perf +**See perf-test-scripts below for assistance in creating a build and test enviroment.** + + linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7 + linaro@t430:~/linaro/coresight/perf-opencsd-4.7$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v003/decoder + linaro@t430:~/linaro/coresight/perf-opencsd-4.7$ make -C tools/perf ... ... - linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ ls -l tools/perf/perf + linaro@t430:~/linaro/coresight/perf-opencsd-4.7$ ls -l tools/perf/perf -rwxrwxr-x 1 linaro linaro 6276360 Mar 3 10:05 tools/perf/perf
@@ -224,7 +226,7 @@ to be sure everything is clean. linaro@t430:~/linaro/coresight/feb24$ rm -rf ~/.debug linaro@t430:~/linaro/coresight/feb24$ cp -dpR .debug ~/ linaro@t430:~/linaro/coresight/feb24$ export LD_LIBRARY_PATH=~/linaro/coresight/opencsd-0v003/decoder/lib/linux64/dbg/ - linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf report --stdio + linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7/tools/perf/perf report --stdio
# To display the perf.data header info, please use --header/--header-only options. # @@ -268,7 +270,7 @@ to be sure everything is clean.
Additional data can be obtained, which contains a dump of the trace packets received using the command
- mjl@ubuntu-vbox:./perf-opencsd-4.7-rc4/coresight/tools/perf/perf report --stdio --dump + mjl@ubuntu-vbox:./perf-opencsd-4.7/coresight/tools/perf/perf report --stdio --dump
resulting a large amount of data, trace looking like:-
@@ -317,10 +319,10 @@ Trace Decoding with Perf Script Working with perf scripts needs more command line options but yields interesting results.
- linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7-rc4/tools/perf/ + linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7/tools/perf/ linaro@t430:~/linaro/coresight/feb24$ export SCRIPT_PATH=$EXEC_PATH/scripts/python/ linaro@t430:~/linaro/coresight/feb24$ export XTOOL_PATH=/your/aarch64/toolchain/path/bin/ - linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump + linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump
7f89f24d80: 910003e0 mov x0, sp 7f89f24d84: 94000d53 bl 7f89f282d0 <free@plt+0x3790> @@ -346,6 +348,48 @@ interesting results. 7f89f28304: eb01001f cmp x0, x1 7f89f28308: 54ffffc1 b.ne 7f89f28300 <free@plt+0x37c0>
+Perf Test Environment Scripts +----------------------------- + +The decoder library comes with a number of `bash` scripts that ease the setting up of the +offline build and test environment for perf, and executing tests. + +These scripts can be found in + + decoder/tests/perf-test-scripts + +There are three scripts provided: + +- `perf-setup-env.bash` : this sets up all the environment variables mentioned above. +- `perf-test-report.bash` : this runs `perf report` - using the environment setup by `perf-setup-env.bash` +- `perf-test-script.bash` : this runs `perf script` - using the environment setup by `perf-setup-env.bash` + +Use as follows:- + +1. Prior to building perf, edit `perf-setup-env.bash` to conform to your environment. There are four lines at the top of the file that will require editing. + +2. Execute the script using the command + + source perf-setup-env.bash + + This will set up all the environment variables mentioned in the sections on building and running + perf above, and these are used by the `perf-test...` scripts to run the tests. + +3. Build perf as described above. +4. Follow the instructions for downloading the test capture, or create a capture from your target. +5. Copy the `perf-test...` scripts into the capture data directory -> the one that contains `perf.data`. + +6. The scripts can now be run. No options are required for the default operation, but any command line options will be added to the perf report / perf script command line. + +e.g. + + ./perf-test-report.bash --dump + +will add the --dump option to the end of the command line and run + + ${PERF_EXEC_PATH}/perf report --stdio --dump + + The Linaro CoreSight Team ------------------------- - Mike Leach diff --git a/decoder/tests/perf-test-scripts/perf-setup-env.bash b/decoder/tests/perf-test-scripts/perf-setup-env.bash new file mode 100755 index 0000000..09431a7 --- /dev/null +++ b/decoder/tests/perf-test-scripts/perf-setup-env.bash @@ -0,0 +1,42 @@ +#!/bin/bash +# Script to set up the environment for testing perf with OpenCSD +# +# See HOWTO.md for details on how these environment variables should be set and used. +# +# to use this script:- +# +# source perf-setup-env.bash +# + +#------ User Edits Start ------- +# Edit as required for user system. + +# Root of the opencsd library project as cloned from github +export OPENCSD_ROOT=~/OpenCSD/opencsd-github/opencsd + +# the opencsd build library directory to use. +export OCSD_LIB_DIR=lib/linux64/rel + +# the root of the perf branch / perf dev-tree as checked out +export PERF_ROOT=~/work2/perf-opencsd/mp-4.7-rc4/coresight + +# the arm x-compiler toolchain path +export XTOOLS_PATH=~/work2/toolchain-aarch64/gcc-linaro-4.9-2015.05-1-rc1-x86_64_aarch64-linux-gnu/bin/ + +#------ User Edits End ------- + +# path to source/include root dir - used by perf build to +# include Opencsd decoder. +export CSTRACE_PATH=${OPENCSD_ROOT}/decoder + +# add library to lib path +if [ "${LD_LIBRARY_PATH}" == "" ]; then + export LD_LIBRARY_PATH=${CSTRACE_PATH}/${OCSD_LIB_DIR} +else + export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${CSTRACE_PATH}/${OCSD_LIB_DIR} +fi + +# perf script defines +export PERF_EXEC_PATH=${PERF_ROOT}/tools/perf +export PERF_SCRIPT_PATH=${PERF_EXEC_PATH}/scripts/python + diff --git a/decoder/tests/perf-test-scripts/perf-test-report.bash b/decoder/tests/perf-test-scripts/perf-test-report.bash new file mode 100755 index 0000000..f8d4e7e --- /dev/null +++ b/decoder/tests/perf-test-scripts/perf-test-report.bash @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Script to run perf report +# +# Uses environment set up by perf-setup-env.bash. +# See HOWTO.md for further details. +# +# run from directory containing perf.data file. +# +# + +${PERF_EXEC_PATH}/perf report --stdio $* + + diff --git a/decoder/tests/perf-test-scripts/perf-test-script.bash b/decoder/tests/perf-test-scripts/perf-test-script.bash new file mode 100755 index 0000000..745e8b7 --- /dev/null +++ b/decoder/tests/perf-test-scripts/perf-test-script.bash @@ -0,0 +1,11 @@ +#!/bin/bash +# +# Script to run perf report +# +# Uses environment set up by perf-setup-env.bash. +# See HOWTO.md for further details. +# +# run from directory containing perf.data file. +# + +${PERF_EXEC_PATH}/perf --exec-path=${PERF_EXEC_PATH} script --script=python:${PERF_SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOLS_PATH}/aarch64-linux-gnu-objdump $*
On 1 August 2016 at 07:19, Mike Leach mike.leach@linaro.org wrote:
Added bash scripts to setup build and test environment variables required when testing the library with perf report and perf script.
Updated HOWTO.md to describe the use of these scripts. Adjust for latest opencsd-perf branch.
Very interesting - I'll have to try that. I still see references to opencsd-0v003 below.
Signed-off-by: Mike Leach mike.leach@linaro.org
HOWTO.md | 70 ++++++++++++++++++---- .../tests/perf-test-scripts/perf-setup-env.bash | 42 +++++++++++++ .../tests/perf-test-scripts/perf-test-report.bash | 14 +++++ .../tests/perf-test-scripts/perf-test-script.bash | 11 ++++ 4 files changed, 124 insertions(+), 13 deletions(-) create mode 100755 decoder/tests/perf-test-scripts/perf-setup-env.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-report.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-script.bash
diff --git a/HOWTO.md b/HOWTO.md index ad19e9e..6d3cde3 100644 --- a/HOWTO.md +++ b/HOWTO.md @@ -8,7 +8,7 @@ library to collect and extract program flow traces generated by the CoreSight IP blocks on a Linux system. The examples have been generated using an aarch64 Juno-r0 platform. All information is considered accurate and tested using library branches `opencsd-0v002` and `opencsd-0v003` (decode library only) -and the latest perf branch `perf-opencsd-4.7-rc4` (decode library + perf tools) +and the latest perf branch `perf-opencsd-4.7` (decode library + perf tools) on the [OpenCSD github repository][1].
@@ -17,7 +17,7 @@ On Target Trace Acquisition - Perf Record
All the enhancement to the Perf tools that support the new `cs_etm` pmu have not been upstreamed yet. To get the required functionality branch -`perf-opencsd-4.7-rc4` needs to be downloaded to the target system where +`perf-opencsd-4.7` needs to be downloaded to the target system where traces are to be collected. This branch is an upstream v4.7-rc4 kernel supplemented with modifications to the CoreSight framework and drivers to be usable by the Perf core. The remaining out of tree patches are being @@ -163,14 +163,14 @@ the host's (which has nothing to do with the target) architecture: Off Target Perf Tools Compilation
As stated above not all the pieces of the solution have been upstreamed. To -get all the components branch `perf-opencsd-4.7-rc4` needs to be +get all the components branch `perf-opencsd-4.7` needs to be obtained:
- linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7-rc4 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7-rc4
- linaro@t430:~/linaro/coresight$ git clone -b perf-opencsd-4.7 https://github.com/Linaro/OpenCSD.git perf-opencsd-4.7 ... ...
- linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7-rc4/
- linaro@t430:~/linaro/coresight$ ls perf-opencsd-4.7/ arch certs CREDITS Documentation firmware include ipc Kconfig lib Makefile net REPORTING-BUGS scripts sound usr block COPYING crypto drivers fs init Kbuild kernel MAINTAINERS mm README samples security tools virt
@@ -179,12 +179,14 @@ variable telling the build scripts where to find the library is needed. If the `CSTRACE_PATH` variable is not defined the compilation will still be successful, but handling of CoreSight trace data won't be supported.
- linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7-rc4
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v003/decoder
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ make -C tools/perf
+**See perf-test-scripts below for assistance in creating a build and test enviroment.**
- linaro@t430:~/linaro/coresight$ cd perf-opencsd-4.7
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7$ export CSTRACE_PATH=~/linaro/coresight/opencsd-0v003/decoder
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7$ make -C tools/perf ... ...
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7-rc4$ ls -l tools/perf/perf
- linaro@t430:~/linaro/coresight/perf-opencsd-4.7$ ls -l tools/perf/perf -rwxrwxr-x 1 linaro linaro 6276360 Mar 3 10:05 tools/perf/perf
@@ -224,7 +226,7 @@ to be sure everything is clean. linaro@t430:~/linaro/coresight/feb24$ rm -rf ~/.debug linaro@t430:~/linaro/coresight/feb24$ cp -dpR .debug ~/ linaro@t430:~/linaro/coresight/feb24$ export LD_LIBRARY_PATH=~/linaro/coresight/opencsd-0v003/decoder/lib/linux64/dbg/
- linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf report --stdio
linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7/tools/perf/perf report --stdio
# To display the perf.data header info, please use --header/--header-only options. #
@@ -268,7 +270,7 @@ to be sure everything is clean.
Additional data can be obtained, which contains a dump of the trace packets received using the command
- mjl@ubuntu-vbox:./perf-opencsd-4.7-rc4/coresight/tools/perf/perf report --stdio --dump
- mjl@ubuntu-vbox:./perf-opencsd-4.7/coresight/tools/perf/perf report --stdio --dump
resulting a large amount of data, trace looking like:-
@@ -317,10 +319,10 @@ Trace Decoding with Perf Script Working with perf scripts needs more command line options but yields interesting results.
- linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7-rc4/tools/perf/
- linaro@t430:~/linaro/coresight/feb24$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-4.7/tools/perf/ linaro@t430:~/linaro/coresight/feb24$ export SCRIPT_PATH=$EXEC_PATH/scripts/python/ linaro@t430:~/linaro/coresight/feb24$ export XTOOL_PATH=/your/aarch64/toolchain/path/bin/
- linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7-rc4/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump
linaro@t430:~/linaro/coresight/feb24$ ../perf-opencsd-4.7/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump
7f89f24d80: 910003e0 mov x0, sp 7f89f24d84: 94000d53 bl 7f89f282d0 <free@plt+0x3790>
@@ -346,6 +348,48 @@ interesting results. 7f89f28304: eb01001f cmp x0, x1 7f89f28308: 54ffffc1 b.ne 7f89f28300 <free@plt+0x37c0>
+Perf Test Environment Scripts +-----------------------------
+The decoder library comes with a number of `bash` scripts that ease the setting up of the +offline build and test environment for perf, and executing tests.
+These scripts can be found in
- decoder/tests/perf-test-scripts
+There are three scripts provided:
+- `perf-setup-env.bash` : this sets up all the environment variables mentioned above. +- `perf-test-report.bash` : this runs `perf report` - using the environment setup by `perf-setup-env.bash` +- `perf-test-script.bash` : this runs `perf script` - using the environment setup by `perf-setup-env.bash`
+Use as follows:-
+1. Prior to building perf, edit `perf-setup-env.bash` to conform to your environment. There are four lines at the top of the file that will require editing.
+2. Execute the script using the command
source perf-setup-env.bash
- This will set up all the environment variables mentioned in the sections on building and running
- perf above, and these are used by the `perf-test...` scripts to run the tests.
+3. Build perf as described above. +4. Follow the instructions for downloading the test capture, or create a capture from your target. +5. Copy the `perf-test...` scripts into the capture data directory -> the one that contains `perf.data`.
+6. The scripts can now be run. No options are required for the default operation, but any command line options will be added to the perf report / perf script command line.
+e.g.
./perf-test-report.bash --dump
+will add the --dump option to the end of the command line and run
${PERF_EXEC_PATH}/perf report --stdio --dump
The Linaro CoreSight Team
- Mike Leach
diff --git a/decoder/tests/perf-test-scripts/perf-setup-env.bash b/decoder/tests/perf-test-scripts/perf-setup-env.bash new file mode 100755 index 0000000..09431a7 --- /dev/null +++ b/decoder/tests/perf-test-scripts/perf-setup-env.bash @@ -0,0 +1,42 @@ +#!/bin/bash +# Script to set up the environment for testing perf with OpenCSD +# +# See HOWTO.md for details on how these environment variables should be set and used. +# +# to use this script:- +# +# source perf-setup-env.bash +#
+#------ User Edits Start ------- +# Edit as required for user system.
+# Root of the opencsd library project as cloned from github +export OPENCSD_ROOT=~/OpenCSD/opencsd-github/opencsd
+# the opencsd build library directory to use. +export OCSD_LIB_DIR=lib/linux64/rel
+# the root of the perf branch / perf dev-tree as checked out +export PERF_ROOT=~/work2/perf-opencsd/mp-4.7-rc4/coresight
+# the arm x-compiler toolchain path +export XTOOLS_PATH=~/work2/toolchain-aarch64/gcc-linaro-4.9-2015.05-1-rc1-x86_64_aarch64-linux-gnu/bin/
+#------ User Edits End -------
+# path to source/include root dir - used by perf build to +# include Opencsd decoder. +export CSTRACE_PATH=${OPENCSD_ROOT}/decoder
+# add library to lib path +if [ "${LD_LIBRARY_PATH}" == "" ]; then
- export LD_LIBRARY_PATH=${CSTRACE_PATH}/${OCSD_LIB_DIR}
+else
- export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${CSTRACE_PATH}/${OCSD_LIB_DIR}
+fi
+# perf script defines +export PERF_EXEC_PATH=${PERF_ROOT}/tools/perf +export PERF_SCRIPT_PATH=${PERF_EXEC_PATH}/scripts/python
diff --git a/decoder/tests/perf-test-scripts/perf-test-report.bash b/decoder/tests/perf-test-scripts/perf-test-report.bash new file mode 100755 index 0000000..f8d4e7e --- /dev/null +++ b/decoder/tests/perf-test-scripts/perf-test-report.bash @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Script to run perf report +# +# Uses environment set up by perf-setup-env.bash. +# See HOWTO.md for further details. +# +# run from directory containing perf.data file. +# +#
+${PERF_EXEC_PATH}/perf report --stdio $*
diff --git a/decoder/tests/perf-test-scripts/perf-test-script.bash b/decoder/tests/perf-test-scripts/perf-test-script.bash new file mode 100755 index 0000000..745e8b7 --- /dev/null +++ b/decoder/tests/perf-test-scripts/perf-test-script.bash @@ -0,0 +1,11 @@ +#!/bin/bash +# +# Script to run perf report +# +# Uses environment set up by perf-setup-env.bash. +# See HOWTO.md for further details. +# +# run from directory containing perf.data file. +#
+${PERF_EXEC_PATH}/perf --exec-path=${PERF_EXEC_PATH} script --script=python:${PERF_SCRIPT_PATH}/cs-trace-disasm.py -- -d ${XTOOLS_PATH}/aarch64-linux-gnu-objdump $*
2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight
Initilisation issue was causing a crash in the debug build tests in windows. Generic elements not initialising some parts of the structure - enhanced printing in 0v003 saw out of range in array. Assume linux passed due to zero initialisation of these elements.
Further invesigation showed that the .isa element on the generic output packet not always set in PTM and ETMv4
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/trc_gen_elem.h | 6 ++++++ decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp | 14 ++++++++------ decoder/source/ptm/trc_pkt_decode_ptm.cpp | 7 ++++--- 3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/decoder/include/common/trc_gen_elem.h b/decoder/include/common/trc_gen_elem.h index 4f99c37..300b91b 100644 --- a/decoder/include/common/trc_gen_elem.h +++ b/decoder/include/common/trc_gen_elem.h @@ -148,6 +148,12 @@ inline void OcsdTraceElement::updateType(const ocsd_gen_trc_elem_t type)
inline void OcsdTraceElement::init() { + st_addr = en_addr = (ocsd_vaddr_t)-1; + isa = ocsd_isa_unknown; + + cycle_count = 0; + timestamp = 0; + context.ctxt_id_valid = 0; context.vmid_valid = 0; context.el_valid = 0; diff --git a/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp b/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp index 092f709..78ac7e6 100644 --- a/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp +++ b/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp @@ -883,9 +883,8 @@ ocsd_datapath_resp_t TrcPktDecodeEtmV4I::processAtom(const ocsd_atm_val atom, bo break; } m_output_elem.setType(OCSD_GEN_TRC_ELEM_INSTR_RANGE); - m_output_elem.last_instr_exec = (atom == ATOM_E) ? 1 : 0; - m_output_elem.last_i_type = m_instr_info.type; - m_output_elem.last_i_subtype = m_instr_info.sub_type; + m_output_elem.setLastInstrInfo((atom == ATOM_E),m_instr_info.type, m_instr_info.sub_type); + m_output_elem.setISA(m_instr_info.isa); resp = outputTraceElementIdx(pElem->getRootIndex(),m_output_elem);
} @@ -898,6 +897,8 @@ ocsd_datapath_resp_t TrcPktDecodeEtmV4I::processAtom(const ocsd_atm_val atom, bo { // some trace before we were out of memory access range m_output_elem.setType(OCSD_GEN_TRC_ELEM_INSTR_RANGE); + m_output_elem.setLastInstrInfo(true,m_instr_info.type, m_instr_info.sub_type); + m_output_elem.setISA(m_instr_info.isa); resp = outputTraceElementIdx(pElem->getRootIndex(),m_output_elem); }
@@ -1040,9 +1041,8 @@ ocsd_datapath_resp_t TrcPktDecodeEtmV4I::processException() } } m_output_elem.setType(OCSD_GEN_TRC_ELEM_INSTR_RANGE); - m_output_elem.last_instr_exec = 1; - m_output_elem.last_i_type = m_instr_info.type; - m_output_elem.last_i_subtype = m_instr_info.sub_type; + m_output_elem.setLastInstrInfo(true,m_instr_info.type, m_instr_info.sub_type); + m_output_elem.setISA(m_instr_info.isa); resp = outputTraceElementIdx(m_excep_index, m_output_elem); m_excep_proc = EXCEP_EXCEP; } @@ -1055,6 +1055,8 @@ ocsd_datapath_resp_t TrcPktDecodeEtmV4I::processException() { // some trace before we were out of memory access range m_output_elem.setType(OCSD_GEN_TRC_ELEM_INSTR_RANGE); + m_output_elem.setLastInstrInfo(true,m_instr_info.type, m_instr_info.sub_type); + m_output_elem.setISA(m_instr_info.isa); resp = outputTraceElementIdx(m_excep_index,m_output_elem); }
diff --git a/decoder/source/ptm/trc_pkt_decode_ptm.cpp b/decoder/source/ptm/trc_pkt_decode_ptm.cpp index 2699637..9c5b16d 100644 --- a/decoder/source/ptm/trc_pkt_decode_ptm.cpp +++ b/decoder/source/ptm/trc_pkt_decode_ptm.cpp @@ -531,9 +531,8 @@ ocsd_datapath_resp_t TrcPktDecodePtm::processAtomRange(const ocsd_atm_val A, con }
m_output_elem.setType(OCSD_GEN_TRC_ELEM_INSTR_RANGE); - m_output_elem.last_instr_exec = (A == ATOM_E) ? 1 : 0; - m_output_elem.last_i_type = m_instr_info.type; - m_output_elem.last_i_subtype = m_instr_info.sub_type; + m_output_elem.setLastInstrInfo((A == ATOM_E),m_instr_info.type, m_instr_info.sub_type); + m_output_elem.setISA(m_curr_pe_state.isa); if(m_curr_packet_in->hasCC()) m_output_elem.setCycleCount(m_curr_packet_in->getCCVal()); resp = outputTraceElementIdx(m_index_curr_pkt,m_output_elem); @@ -550,6 +549,8 @@ ocsd_datapath_resp_t TrcPktDecodePtm::processAtomRange(const ocsd_atm_val A, con { // some trace before we were out of memory access range m_output_elem.setType(OCSD_GEN_TRC_ELEM_INSTR_RANGE); + m_output_elem.setLastInstrInfo(true,m_instr_info.type, m_instr_info.sub_type); + m_output_elem.setISA(m_curr_pe_state.isa); resp = outputTraceElementIdx(m_index_curr_pkt,m_output_elem); } }
Common base class added for all the trace component configuration classes. Allows for baseline features plus generic manipulation of configuration register objects.
Separate commit to prevent git errors in thinking this is a rename
ETMv3, PTM, STM and ETMv4 configuration register classes now use common base class.
C-API struct now a member, rather than a base of the classes to improve encapsulation / allow for common base.
Minor mods to decoder code where access functions were needed in place of previous direct struct manipulation.
Update handling of STM, ETMv4 and PTM config objects in test program to reflect the changes to this set of classes - config struct no longer a base.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/trc_cs_config.h | 56 +++++++++++ decoder/include/etmv3/trc_cmp_cfg_etmv3.h | 6 +- decoder/include/etmv4/trc_cmp_cfg_etmv4.h | 102 +++++++++++---------- decoder/include/ptm/trc_cmp_cfg_ptm.h | 51 +++++++---- decoder/include/stm/trc_cmp_cfg_stm.h | 55 +++++++---- decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp | 34 +++---- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp | 2 +- decoder/source/ptm/trc_cmp_cfg_ptm.cpp | 17 ++-- decoder/source/ptm/trc_pkt_decode_ptm.cpp | 4 +- .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 24 +++-- 10 files changed, 232 insertions(+), 119 deletions(-) create mode 100644 decoder/include/common/trc_cs_config.h
diff --git a/decoder/include/common/trc_cs_config.h b/decoder/include/common/trc_cs_config.h new file mode 100644 index 0000000..58398f7 --- /dev/null +++ b/decoder/include/common/trc_cs_config.h @@ -0,0 +1,56 @@ +/* + * \file trc_cs_config.h + * \brief OpenCSD : Trace component config base class. + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ +#ifndef ARM_TRC_CS_CONFIG_H_INCLUDED +#define ARM_TRC_CS_CONFIG_H_INCLUDED + + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/*! + * @class CSConfig : Base class for configuration data on CoreSight trace component. + * + * Defines common access functionality, common to all components. + * (e.g. trace ID). + * + */ +class CSConfig +{ +public: + CSConfig() {}; + virtual ~CSConfig() {}; + + virtual const uint8_t getTraceID() const = 0; //!< CoreSight Trace ID for this device. +}; + +#endif // ARM_TRC_CS_CONFIG_H_INCLUDED + +/* End of File trc_cs_config.h */ \ No newline at end of file diff --git a/decoder/include/etmv3/trc_cmp_cfg_etmv3.h b/decoder/include/etmv3/trc_cmp_cfg_etmv3.h index f2da178..509de20 100644 --- a/decoder/include/etmv3/trc_cmp_cfg_etmv3.h +++ b/decoder/include/etmv3/trc_cmp_cfg_etmv3.h @@ -37,6 +37,8 @@ #define ARM_TRC_CMP_CFG_ETMV3_H_INCLUDED
#include "trc_pkt_types_etmv3.h" +#include "common/trc_cs_config.h" +
/** @addtogroup ocsd_protocol_cfg @{*/ @@ -53,7 +55,7 @@ * Primarily inlined for efficient code. * */ -class EtmV3Config //: public ocsd_etmv3_cfg +class EtmV3Config : public CSConfig { public: EtmV3Config(); /**< Default constructor */ @@ -117,7 +119,7 @@ public: const bool isTSEnabled() const; //!< Timestamp trace is enabled. const bool TSPkt64() const; //!< timestamp packet is 64 bits in size.
- const uint8_t getTraceID() const; //!< CoreSight Trace ID for this device. + virtual const uint8_t getTraceID() const; //!< CoreSight Trace ID for this device.
const ocsd_arch_version_t getArchVersion() const; //!< architecture version const ocsd_core_profile_t getCoreProfile() const; //!< core profile. diff --git a/decoder/include/etmv4/trc_cmp_cfg_etmv4.h b/decoder/include/etmv4/trc_cmp_cfg_etmv4.h index 48bb1af..a3f8835 100644 --- a/decoder/include/etmv4/trc_cmp_cfg_etmv4.h +++ b/decoder/include/etmv4/trc_cmp_cfg_etmv4.h @@ -37,7 +37,7 @@ #define ARM_TRC_CMP_CFG_ETMV4_H_INCLUDED
#include "trc_pkt_types_etmv4.h" - +#include "common/trc_cs_config.h"
/** @addtogroup ocsd_protocol_cfg @@ -53,17 +53,25 @@ * Provides quick value interpretation methods for the ETMv4 config register values. * Primarily inlined for efficient code. */ -class EtmV4Config : public ocsd_etmv4_cfg +class EtmV4Config : public CSConfig // public ocsd_etmv4_cfg { public: EtmV4Config(); /**< Default constructor */ + EtmV4Config(const ocsd_etmv4_cfg *cfg_regs); ~EtmV4Config() {}; /**< Default destructor */
+// operations to convert to and from C-API structure + //! copy assignment operator for base structure into class. EtmV4Config & operator=(const ocsd_etmv4_cfg *p_cfg);
- const ocsd_core_profile_t &coreProfile() const { return core_prof; }; - const ocsd_arch_version_t &archVersion() const { return arch_ver; }; + //! cast operator returning struct const reference + operator const ocsd_etmv4_cfg &() const { return m_cfg; }; + //! cast operator returning struct const pointer + operator const ocsd_etmv4_cfg *() const { return &m_cfg; }; + + const ocsd_core_profile_t &coreProfile() const { return m_cfg.core_prof; }; + const ocsd_arch_version_t &archVersion() const { return m_cfg.arch_ver; };
/* idr 0 */ const bool LSasInstP0() const; @@ -120,7 +128,7 @@ public: const uint32_t CondKeyMaxIncr() const;
/* trace idr */ - const uint8_t getTraceID() const; + virtual const uint8_t getTraceID() const; //!< CoreSight Trace ID for this device.
/* config R */ const bool enabledDVTrace() const; @@ -171,47 +179,49 @@ private:
bool m_condTraceCalc; CondITrace_t m_CondTrace; + + ocsd_etmv4_cfg m_cfg; };
/* idr 0 */ inline const bool EtmV4Config::LSasInstP0() const { - return (bool)((reg_idr0 & 0x6) == 0x6); + return (bool)((m_cfg.reg_idr0 & 0x6) == 0x6); }
inline const bool EtmV4Config::hasDataTrace() const { - return (bool)((reg_idr0 & 0x18) == 0x18); + return (bool)((m_cfg.reg_idr0 & 0x18) == 0x18); }
inline const bool EtmV4Config::hasBranchBroadcast() const { - return (bool)((reg_idr0 & 0x20) == 0x20); + return (bool)((m_cfg.reg_idr0 & 0x20) == 0x20); }
inline const bool EtmV4Config::hasCondTrace() const { - return (bool)((reg_idr0 & 0x40) == 0x40); + return (bool)((m_cfg.reg_idr0 & 0x40) == 0x40); }
inline const bool EtmV4Config::hasCycleCountI() const { - return (bool)((reg_idr0 & 0x80) == 0x80); + return (bool)((m_cfg.reg_idr0 & 0x80) == 0x80); }
inline const bool EtmV4Config::hasRetStack() const { - return (bool)((reg_idr0 & 0x200) == 0x200); + return (bool)((m_cfg.reg_idr0 & 0x200) == 0x200); }
inline const uint8_t EtmV4Config::numEvents() const { - return ((reg_idr0 >> 10) & 0x3) + 1; + return ((m_cfg.reg_idr0 >> 10) & 0x3) + 1; }
inline const EtmV4Config::condType EtmV4Config::hasCondType() const { - return ((reg_idr0 & 0x3000) == 0x1000) ? EtmV4Config::COND_HAS_ASPR : EtmV4Config::COND_PASS_FAIL; + return ((m_cfg.reg_idr0 & 0x3000) == 0x1000) ? EtmV4Config::COND_HAS_ASPR : EtmV4Config::COND_PASS_FAIL; }
inline const EtmV4Config::QSuppType EtmV4Config::getQSuppType() @@ -234,12 +244,12 @@ inline const bool EtmV4Config::hasQFilter()
inline const bool EtmV4Config::hasTrcExcpData() const { - return (bool)((reg_idr0 & 0x20000) == 0x20000); + return (bool)((m_cfg.reg_idr0 & 0x20000) == 0x20000); }
inline const uint32_t EtmV4Config::TimeStampSize() const { - uint32_t tsSizeF = (reg_idr0 >> 24) & 0x1F; + uint32_t tsSizeF = (m_cfg.reg_idr0 >> 24) & 0x1F; if(tsSizeF == 0x6) return 48; if(tsSizeF == 0x8) @@ -249,30 +259,30 @@ inline const uint32_t EtmV4Config::TimeStampSize() const
inline const bool EtmV4Config::commitOpt1() const { - return (bool)((reg_idr0 & 0x20000000) == 0x20000000) && hasCycleCountI(); + return (bool)((m_cfg.reg_idr0 & 0x20000000) == 0x20000000) && hasCycleCountI(); }
/* idr 1 */ inline const uint8_t EtmV4Config::MajVersion() const { - return (uint8_t)((reg_idr1 >> 8) & 0xF); + return (uint8_t)((m_cfg.reg_idr1 >> 8) & 0xF); }
inline const uint8_t EtmV4Config::MinVersion() const { - return (uint8_t)((reg_idr1 >> 4) & 0xF); + return (uint8_t)((m_cfg.reg_idr1 >> 4) & 0xF); }
/* idr 2 */ inline const uint32_t EtmV4Config::iaSizeMax() const { - return ((reg_idr2 & 0x1F) == 0x8) ? 64 : 32; + return ((m_cfg.reg_idr2 & 0x1F) == 0x8) ? 64 : 32; }
inline const uint32_t EtmV4Config::cidSize() const { - return (((reg_idr2 >> 5) & 0x1F) == 0x4) ? 32 : 0; + return (((m_cfg.reg_idr2 >> 5) & 0x1F) == 0x4) ? 32 : 0; }
inline const uint32_t EtmV4Config::vmidSize() @@ -286,81 +296,81 @@ inline const uint32_t EtmV4Config::vmidSize()
inline const uint32_t EtmV4Config::daSize() const { - uint32_t daSizeF = ((reg_idr2 >> 15) & 0x1F); + uint32_t daSizeF = ((m_cfg.reg_idr2 >> 15) & 0x1F); if(daSizeF) - return (((reg_idr2 >> 15) & 0x1F) == 0x8) ? 64 : 32; + return (((m_cfg.reg_idr2 >> 15) & 0x1F) == 0x8) ? 64 : 32; return 0; }
inline const uint32_t EtmV4Config::dvSize() const { - uint32_t dvSizeF = ((reg_idr2 >> 20) & 0x1F); + uint32_t dvSizeF = ((m_cfg.reg_idr2 >> 20) & 0x1F); if(dvSizeF) - return (((reg_idr2 >> 20) & 0x1F) == 0x8) ? 64 : 32; + return (((m_cfg.reg_idr2 >> 20) & 0x1F) == 0x8) ? 64 : 32; return 0; }
inline const uint32_t EtmV4Config::ccSize() const { - return ((reg_idr2 >> 25) & 0xF) + 12; + return ((m_cfg.reg_idr2 >> 25) & 0xF) + 12; }
inline const bool EtmV4Config::vmidOpt() const { - return (bool)((reg_idr2 & 0x20000000) == 0x20000000) && (MinVersion() > 0); + return (bool)((m_cfg.reg_idr2 & 0x20000000) == 0x20000000) && (MinVersion() > 0); }
/* id regs 8-13*/
inline const uint32_t EtmV4Config::MaxSpecDepth() const { - return reg_idr8; + return m_cfg.reg_idr8; }
inline const uint32_t EtmV4Config::P0_Key_Max() const { - return (reg_idr9 == 0) ? 1 : reg_idr9; + return (m_cfg.reg_idr9 == 0) ? 1 : m_cfg.reg_idr9; }
inline const uint32_t EtmV4Config::P1_Key_Max() const { - return reg_idr10; + return m_cfg.reg_idr10; }
inline const uint32_t EtmV4Config::P1_Spcl_Key_Max() const { - return reg_idr11; + return m_cfg.reg_idr11; }
inline const uint32_t EtmV4Config::CondKeyMax() const { - return reg_idr12; + return m_cfg.reg_idr12; }
inline const uint32_t EtmV4Config::CondSpecKeyMax() const { - return reg_idr13; + return m_cfg.reg_idr13; }
inline const uint32_t EtmV4Config::CondKeyMaxIncr() const { - return reg_idr12 - reg_idr13; + return m_cfg.reg_idr12 - m_cfg.reg_idr13; }
inline const uint8_t EtmV4Config::getTraceID() const { - return (uint8_t)(reg_traceidr & 0x7F); + return (uint8_t)(m_cfg.reg_traceidr & 0x7F); }
/* config R */ inline const bool EtmV4Config::enabledDVTrace() const { - return hasDataTrace() && enabledLSP0Trace() && ((reg_configr & (0x1 << 17)) != 0); + return hasDataTrace() && enabledLSP0Trace() && ((m_cfg.reg_configr & (0x1 << 17)) != 0); }
inline const bool EtmV4Config::enabledDATrace() const { - return hasDataTrace() && enabledLSP0Trace() && ((reg_configr & (0x1 << 16)) != 0); + return hasDataTrace() && enabledLSP0Trace() && ((m_cfg.reg_configr & (0x1 << 16)) != 0); }
inline const bool EtmV4Config::enabledDataTrace() const @@ -370,39 +380,39 @@ inline const bool EtmV4Config::enabledDataTrace() const
inline const bool EtmV4Config::enabledLSP0Trace() const { - return ((reg_configr & 0x6) != 0); + return ((m_cfg.reg_configr & 0x6) != 0); }
inline const EtmV4Config::LSP0_t EtmV4Config::LSP0Type() const { - return (LSP0_t)((reg_configr & 0x6) >> 1); + return (LSP0_t)((m_cfg.reg_configr & 0x6) >> 1); }
inline const bool EtmV4Config::enabledBrBroad() const { - return ((reg_configr & (0x1 << 3)) != 0); + return ((m_cfg.reg_configr & (0x1 << 3)) != 0); }
inline const bool EtmV4Config::enabledCCI() const { - return ((reg_configr & (0x1 << 4)) != 0); + return ((m_cfg.reg_configr & (0x1 << 4)) != 0); }
inline const bool EtmV4Config::enabledCID() const { - return ((reg_configr & (0x1 << 6)) != 0); + return ((m_cfg.reg_configr & (0x1 << 6)) != 0); }
inline const bool EtmV4Config::enabledVMID() const { - return ((reg_configr & (0x1 << 7)) != 0); + return ((m_cfg.reg_configr & (0x1 << 7)) != 0); }
inline const EtmV4Config::CondITrace_t EtmV4Config::enabledCondITrace() { if(!m_condTraceCalc) { - switch((reg_configr >> 8) & 0x7) + switch((m_cfg.reg_configr >> 8) & 0x7) { default: case 0: m_CondTrace = COND_TR_DIS; break; @@ -418,17 +428,17 @@ inline const EtmV4Config::CondITrace_t EtmV4Config::enabledCondITrace()
inline const bool EtmV4Config::enabledTS() const { - return ((reg_configr & (0x1 << 11)) != 0); + return ((m_cfg.reg_configr & (0x1 << 11)) != 0); }
inline const bool EtmV4Config::enabledRetStack() const { - return ((reg_configr & (0x1 << 12)) != 0); + return ((m_cfg.reg_configr & (0x1 << 12)) != 0); }
inline const bool EtmV4Config::enabledQE() const { - return ((reg_configr & (0x3 << 13)) != 0); + return ((m_cfg.reg_configr & (0x3 << 13)) != 0); }
/** @}*/ diff --git a/decoder/include/ptm/trc_cmp_cfg_ptm.h b/decoder/include/ptm/trc_cmp_cfg_ptm.h index e77f6aa..5a4dae2 100644 --- a/decoder/include/ptm/trc_cmp_cfg_ptm.h +++ b/decoder/include/ptm/trc_cmp_cfg_ptm.h @@ -37,6 +37,7 @@ #define ARM_TRC_CMP_CFG_PTM_H_INCLUDED
#include "trc_pkt_types_ptm.h" +#include "common/trc_cs_config.h"
/** @defgroup ocsd_protocol_cfg OpenCSD Library : Protcol Generator Configuration.
@@ -58,10 +59,11 @@ * Provides quick value interpretation methods for the PTM config register values. * Primarily inlined for efficient code. */ -class PtmConfig : public ocsd_ptm_cfg +class PtmConfig : public CSConfig // public ocsd_ptm_cfg { public: PtmConfig(); /**< Default constructor */ + PtmConfig(const ocsd_ptm_cfg *cfg_regs); ~PtmConfig() {}; /**< Default destructor */
/* register bit constants. */ @@ -79,9 +81,18 @@ public: static const uint32_t CCER_TS_ENC_NAT = (0x1 << 28); static const uint32_t CCER_TS_64BIT = (0x1 << 29);
+// operations to convert to and from C-API structure + //! copy assignment operator for base structure into class. PtmConfig & operator=(const ocsd_ptm_cfg *p_cfg);
+ //! cast operator returning struct const reference + operator const ocsd_ptm_cfg &() const { return m_cfg; }; + //! cast operator returning struct const pointer + operator const ocsd_ptm_cfg *() const { return &m_cfg; }; + +// access functions + const bool enaBranchBCast() const; //!< Branch broadcast enabled. const bool enaCycleAcc() const; //!< cycle accurate tracing enabled.
@@ -102,7 +113,13 @@ public: const bool dmsbGenTS() const; //!< TS generated for DMB and DSB const bool dmsbWayPt() const; //!< DMB and DSB are waypoint instructions.
- const uint8_t getTraceID() const; //!< CoreSight Trace ID for this device. + virtual const uint8_t getTraceID() const; //!< CoreSight Trace ID for this device. + + const ocsd_core_profile_t &coreProfile() const { return m_cfg.core_prof; }; + const ocsd_arch_version_t &archVersion() const { return m_cfg.arch_ver; }; + +private: + ocsd_ptm_cfg m_cfg; };
/* inlines */ @@ -110,80 +127,80 @@ public: inline PtmConfig & PtmConfig::operator=(const ocsd_ptm_cfg *p_cfg) { // object of base class ocsd_ptm_cfg - *dynamic_cast<ocsd_ptm_cfg *>(this) = *p_cfg; + m_cfg = *p_cfg; return *this; }
inline const bool PtmConfig::enaBranchBCast() const { - return (bool)((reg_ctrl & CTRL_BRANCH_BCAST) != 0); + return (bool)((m_cfg.reg_ctrl & CTRL_BRANCH_BCAST) != 0); }
inline const bool PtmConfig::enaCycleAcc() const { - return (bool)((reg_ctrl & CTRL_CYCLEACC) != 0); + return (bool)((m_cfg.reg_ctrl & CTRL_CYCLEACC) != 0); }
inline const bool PtmConfig::enaRetStack() const { - return (bool)((reg_ctrl & CTRL_RETSTACK_ENA) != 0); + return (bool)((m_cfg.reg_ctrl & CTRL_RETSTACK_ENA) != 0); }
inline const bool PtmConfig::hasRetStack() const { - return (bool)((reg_ccer & CCER_RESTACK_IMPL) != 0); + return (bool)((m_cfg.reg_ccer & CCER_RESTACK_IMPL) != 0); }
inline const int PtmConfig::MinorRev() const { - return ((int)reg_idr & 0xF0) >> 4; + return ((int)m_cfg.reg_idr & 0xF0) >> 4; }
inline const bool PtmConfig::hasTS() const { - return (bool)((reg_ccer & CCER_TS_IMPL) != 0); + return (bool)((m_cfg.reg_ccer & CCER_TS_IMPL) != 0); }
inline const bool PtmConfig::enaTS() const { - return (bool)((reg_ctrl & CTRL_TS_ENA) != 0); + return (bool)((m_cfg.reg_ctrl & CTRL_TS_ENA) != 0); }
inline const bool PtmConfig::TSPkt64() const { if(MinorRev() == 0) return false; - return (bool)((reg_ccer & CCER_TS_64BIT) != 0); + return (bool)((m_cfg.reg_ccer & CCER_TS_64BIT) != 0); }
inline const bool PtmConfig::TSBinEnc() const { if(MinorRev() == 0) return false; - return (bool)((reg_ccer & CCER_TS_ENC_NAT) != 0); + return (bool)((m_cfg.reg_ccer & CCER_TS_ENC_NAT) != 0); }
inline const bool PtmConfig::hasVirtExt() const { - return (bool)((reg_ccer & CCER_VIRTEXT) != 0); + return (bool)((m_cfg.reg_ccer & CCER_VIRTEXT) != 0); }
inline const bool PtmConfig::enaVMID() const { - return (bool)((reg_ctrl & CTRL_VMID_ENA) != 0); + return (bool)((m_cfg.reg_ctrl & CTRL_VMID_ENA) != 0); }
inline const bool PtmConfig::dmsbGenTS() const { - return (bool)((reg_ccer & CCER_TS_DMSB) != 0); + return (bool)((m_cfg.reg_ccer & CCER_TS_DMSB) != 0); }
inline const bool PtmConfig::dmsbWayPt() const { - return (bool)((reg_ccer & CCER_DMSB_WPT) != 0); + return (bool)((m_cfg.reg_ccer & CCER_DMSB_WPT) != 0); }
inline const uint8_t PtmConfig::getTraceID() const { - return (uint8_t)(reg_trc_id & 0x7F); + return (uint8_t)(m_cfg.reg_trc_id & 0x7F); }
/** @}*/ diff --git a/decoder/include/stm/trc_cmp_cfg_stm.h b/decoder/include/stm/trc_cmp_cfg_stm.h index dbef0eb..41003ec 100644 --- a/decoder/include/stm/trc_cmp_cfg_stm.h +++ b/decoder/include/stm/trc_cmp_cfg_stm.h @@ -36,6 +36,7 @@ #define ARM_TRC_CMP_CFG_STM_H_INCLUDED
#include "trc_pkt_types_stm.h" +#include "common/trc_cs_config.h"
/** @addtogroup ocsd_protocol_cfg @{*/ @@ -56,17 +57,26 @@ * * Can also be initialised with a fully populated ocsd_stm_cfg structure. */ -class STMConfig : public ocsd_stm_cfg +class STMConfig : public CSConfig // public ocsd_stm_cfg { public: STMConfig(); //!< Constructor - creates a default configuration + STMConfig(const ocsd_stm_cfg *cfg_regs); ~STMConfig() {};
+// operations to convert to and from C-API structure + STMConfig & operator=(const ocsd_stm_cfg *p_cfg); //!< set from full configuration structure. + //! cast operator returning struct const reference + operator const ocsd_stm_cfg &() const { return m_cfg; }; + //! cast operator returning struct const pointer + operator const ocsd_stm_cfg *() const { return &m_cfg; }; + +// access functions void setTraceID(const uint8_t traceID); //!< Set the CoreSight trace ID. void setHWTraceFeat(const hw_event_feat_t hw_feat); //!< set usage of STM HW event trace.
- const uint8_t getTraceID() const; //!< Get the CoreSight trace ID. + virtual const uint8_t getTraceID() const; //!< Get the CoreSight trace ID. const uint8_t getMaxMasterIdx() const; //!< Get the maximum master index const uint16_t getMaxChannelIdx() const; //!< Get the maximum channel index. const uint16_t getHWTraceMasterIdx() const; //!< Get the master used for HW event trace. @@ -74,22 +84,29 @@ public:
private: bool m_bHWTraceEn; + ocsd_stm_cfg m_cfg; };
inline STMConfig::STMConfig() { - reg_tcsr = 0; - reg_devid = 0xFF; // default to 256 masters. - reg_feat3r = 0x10000; // default to 65536 channels. - reg_feat1r = 0x0; - reg_hwev_mast = 0; // default hwtrace master = 0; - hw_event = HwEvent_Unknown_Disabled; // default to not present / disabled. + m_cfg.reg_tcsr = 0; + m_cfg.reg_devid = 0xFF; // default to 256 masters. + m_cfg.reg_feat3r = 0x10000; // default to 65536 channels. + m_cfg.reg_feat1r = 0x0; + m_cfg.reg_hwev_mast = 0; // default hwtrace master = 0; + m_cfg.hw_event = HwEvent_Unknown_Disabled; // default to not present / disabled. m_bHWTraceEn = false; }
+inline STMConfig::STMConfig(const ocsd_stm_cfg *cfg_regs) +{ + m_cfg = *cfg_regs; + setHWTraceFeat(m_cfg.hw_event); +} + inline STMConfig & STMConfig::operator=(const ocsd_stm_cfg *p_cfg) { - *dynamic_cast<ocsd_stm_cfg *>(this) = *p_cfg; + m_cfg = *p_cfg; setHWTraceFeat(p_cfg->hw_event); return *this; } @@ -97,36 +114,36 @@ inline STMConfig & STMConfig::operator=(const ocsd_stm_cfg *p_cfg) inline void STMConfig::setTraceID(const uint8_t traceID) { uint32_t IDmask = 0x007F0000; - reg_tcsr &= ~IDmask; - reg_tcsr |= (((uint32_t)traceID) << 16) & IDmask; + m_cfg.reg_tcsr &= ~IDmask; + m_cfg.reg_tcsr |= (((uint32_t)traceID) << 16) & IDmask; }
inline void STMConfig::setHWTraceFeat(const hw_event_feat_t hw_feat) { - hw_event = hw_feat; - m_bHWTraceEn = (hw_event == HwEvent_Enabled); - if(hw_event == HwEvent_UseRegisters) - m_bHWTraceEn = (((reg_feat1r & 0xC0000) == 0x80000) && ((reg_tcsr & 0x8) == 0x8)); + m_cfg.hw_event = hw_feat; + m_bHWTraceEn = (m_cfg.hw_event == HwEvent_Enabled); + if(m_cfg.hw_event == HwEvent_UseRegisters) + m_bHWTraceEn = (((m_cfg.reg_feat1r & 0xC0000) == 0x80000) && ((m_cfg.reg_tcsr & 0x8) == 0x8)); }
inline const uint8_t STMConfig::getTraceID() const { - return (uint8_t)((reg_tcsr >> 16) & 0x7F); + return (uint8_t)((m_cfg.reg_tcsr >> 16) & 0x7F); }
inline const uint8_t STMConfig::getMaxMasterIdx() const { - return (uint8_t)(reg_devid & 0xFF); + return (uint8_t)(m_cfg.reg_devid & 0xFF); }
inline const uint16_t STMConfig::getMaxChannelIdx() const { - return (uint16_t)(reg_feat3r - 1); + return (uint16_t)(m_cfg.reg_feat3r - 1); }
inline const uint16_t STMConfig::getHWTraceMasterIdx() const { - return (uint16_t)(reg_hwev_mast & 0xFFFF); + return (uint16_t)(m_cfg.reg_hwev_mast & 0xFFFF); }
inline bool STMConfig::getHWTraceEn() const diff --git a/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp b/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp index 214d149..5703406 100644 --- a/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp +++ b/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp @@ -36,26 +36,26 @@
EtmV4Config::EtmV4Config() { - reg_idr0 = 0x28000EA1; - reg_idr1 = 0x4100F403; - reg_idr2 = 0x00000488; - reg_idr8 = 0; - reg_idr9 = 0; - reg_idr10 = 0; - reg_idr11 = 0; - reg_idr12 = 0; - reg_idr13 = 0; - reg_configr = 0xC1; - reg_traceidr = 0; - arch_ver = ARCH_V7; - core_prof = profile_CortexA; + m_cfg.reg_idr0 = 0x28000EA1; + m_cfg.reg_idr1 = 0x4100F403; + m_cfg.reg_idr2 = 0x00000488; + m_cfg.reg_idr8 = 0; + m_cfg.reg_idr9 = 0; + m_cfg.reg_idr10 = 0; + m_cfg.reg_idr11 = 0; + m_cfg.reg_idr12 = 0; + m_cfg.reg_idr13 = 0; + m_cfg.reg_configr = 0xC1; + m_cfg.reg_traceidr = 0; + m_cfg.arch_ver = ARCH_V7; + m_cfg.core_prof = profile_CortexA;
PrivateInit(); }
EtmV4Config & EtmV4Config::operator=(const ocsd_etmv4_cfg *p_cfg) { - *dynamic_cast<ocsd_etmv4_cfg *>(this) = *p_cfg; + m_cfg = *p_cfg; PrivateInit(); return *this; } @@ -79,15 +79,15 @@ void EtmV4Config::CalcQSupp() Q_NO_ICOUNT_ONLY, Q_FULL }; - uint8_t Qsupp = (reg_idr0 >> 15) & 0x3; + uint8_t Qsupp = (m_cfg.reg_idr0 >> 15) & 0x3; m_QSuppType = qtypes[Qsupp]; - m_QSuppFilter = (bool)((reg_idr0 & 0x4000) == 0x4000) && (m_QSuppType != Q_NONE); + m_QSuppFilter = (bool)((m_cfg.reg_idr0 & 0x4000) == 0x4000) && (m_QSuppType != Q_NONE); m_QSuppCalc = true; }
void EtmV4Config::CalcVMIDSize() { - uint32_t vmidszF = (reg_idr2 >> 10) & 0x1F; + uint32_t vmidszF = (m_cfg.reg_idr2 >> 10) & 0x1F; if(vmidszF == 1) m_VMIDSize = 8; else if(MinVersion() > 0) diff --git a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp index 0bc2e59..8966504 100644 --- a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp +++ b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp @@ -515,7 +515,7 @@ void EtmV4IPktProcImpl::iPktException() uint16_t excep_type = (m_currPacketData[1] >> 1) & 0x1F; uint8_t addr_interp = (m_currPacketData[1] & 0x40) >> 5 | (m_currPacketData[1] & 0x1); uint8_t m_fault_pending = 0; - uint8_t m_type = (m_config.core_prof == profile_CortexM) ? 1 : 0; + uint8_t m_type = (m_config.coreProfile() == profile_CortexM) ? 1 : 0;
// extended exception packet (probably M class); if(m_currPacketData[1] & 0x80) diff --git a/decoder/source/ptm/trc_cmp_cfg_ptm.cpp b/decoder/source/ptm/trc_cmp_cfg_ptm.cpp index 8f51c2f..8028683 100644 --- a/decoder/source/ptm/trc_cmp_cfg_ptm.cpp +++ b/decoder/source/ptm/trc_cmp_cfg_ptm.cpp @@ -37,17 +37,22 @@ PtmConfig::PtmConfig() { // defaults set ETMv1.1, V7A - arch_ver = ARCH_V7; - core_prof = profile_CortexA; - reg_ccer = 0; - reg_idr = 0x4100F310; - reg_ctrl = 0; + m_cfg.arch_ver = ARCH_V7; + m_cfg.core_prof = profile_CortexA; + m_cfg.reg_ccer = 0; + m_cfg.reg_idr = 0x4100F310; + m_cfg.reg_ctrl = 0; +} + +PtmConfig::PtmConfig(const ocsd_ptm_cfg *cfg_regs) +{ + m_cfg = *cfg_regs; }
const int PtmConfig::CtxtIDBytes() const { int ctxtIdsizes[] = { 0, 1, 2, 4 }; - return ctxtIdsizes[(reg_ctrl >> 14) & 0x3]; + return ctxtIdsizes[(m_cfg.reg_ctrl >> 14) & 0x3]; }
diff --git a/decoder/source/ptm/trc_pkt_decode_ptm.cpp b/decoder/source/ptm/trc_pkt_decode_ptm.cpp index 9c5b16d..5381086 100644 --- a/decoder/source/ptm/trc_pkt_decode_ptm.cpp +++ b/decoder/source/ptm/trc_pkt_decode_ptm.cpp @@ -165,8 +165,8 @@ ocsd_err_t TrcPktDecodePtm::onProtocolConfig() m_CSID = m_config->getTraceID();
// config options affecting decode - m_instr_info.pe_type.profile = m_config->core_prof; - m_instr_info.pe_type.arch = m_config->arch_ver; + m_instr_info.pe_type.profile = m_config->coreProfile(); + m_instr_info.pe_type.arch = m_config->archVersion(); m_instr_info.dsb_dmb_waypoints = m_config->dmsbWayPt() ? 1 : 0; return err; } diff --git a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp index 271b83b..0a31edd 100644 --- a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp +++ b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp @@ -243,7 +243,7 @@ bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, bool configOK = true;
// generate the config data from the device data. - EtmV4Config config; + ocsd_etmv4_cfg config;
regs_to_access_t regs_to_access[] = { { ETMv4RegCfg, true, &config.reg_configr, 0 }, @@ -270,16 +270,18 @@ bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, if(configOK) { ocsd_err_t err = OCSD_OK; + EtmV4Config configObj(&config); + if(m_bPacketProcOnly) { if(bDataChannel) - err = m_pDecodeTree->createETMv4DPktProcessor(&config); + err = m_pDecodeTree->createETMv4DPktProcessor(&configObj); else - err = m_pDecodeTree->createETMv4IPktProcessor(&config); + err = m_pDecodeTree->createETMv4IPktProcessor(&configObj); } else { - err = m_pDecodeTree->createETMv4Decoder(&config,bDataChannel); + err = m_pDecodeTree->createETMv4Decoder(&configObj,bDataChannel); } if(err == OCSD_OK) createdDecoder = true; @@ -337,7 +339,8 @@ bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Pa bool configOK = true;
// generate the config data from the device data. - PtmConfig config; + + ocsd_ptm_cfg config;
regs_to_access_t regs_to_access[] = { { ETMv3PTMRegIDR, true, &config.reg_idr, 0 }, @@ -356,11 +359,12 @@ bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Pa // good config - generate the decoder on the tree. if(configOK) { + PtmConfig configObj(&config); ocsd_err_t err = OCSD_OK; if(m_bPacketProcOnly) - err = m_pDecodeTree->createPTMPktProcessor(&config); + err = m_pDecodeTree->createPTMPktProcessor(&configObj); else - err = m_pDecodeTree->createPTMDecoder(&config); + err = m_pDecodeTree->createPTMDecoder(&configObj);
if(err == OCSD_OK) createdDecoder = true; @@ -395,7 +399,8 @@ bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc) bool configOK = true;
// generate the config data from the device data. - STMConfig config; + + ocsd_stm_cfg config;
regs_to_access_t regs_to_access[] = { { STMRegTCSR, true, &config.reg_tcsr, 0 } @@ -405,8 +410,9 @@ bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc) if(configOK) { ocsd_err_t err = OCSD_OK; + STMConfig configObj(&config); if(m_bPacketProcOnly) - err = m_pDecodeTree->createSTMPktProcessor(&config); + err = m_pDecodeTree->createSTMPktProcessor(&configObj); else err = OCSD_ERR_TEST_SS_TO_DECODER;
Enables templated interface classes to be handled generically
Updates to classes to prepare for generic handling of decoder registration and connection.
Attachment point function added to simply replace current attached component with supplied replacement. Supply 0 to detach.
Trace component common base class adjusted to be virtual + added method to associate trace components.
Trace packet decoded added information on usage of memory access and instruction decoder interfaces (STM decoder will not need these)
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/comp_attach_pt_t.h | 15 ++++++ decoder/include/common/trc_component.h | 22 ++++++++- decoder/include/common/trc_pkt_decode_base.h | 36 +++++++++----- decoder/include/interfaces/trc_abs_typed_base_i.h | 57 +++++++++++++++++++++++ decoder/include/interfaces/trc_indexer_pkt_i.h | 4 +- decoder/include/interfaces/trc_pkt_in_i.h | 4 +- decoder/include/interfaces/trc_pkt_raw_in_i.h | 4 +- 7 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 decoder/include/interfaces/trc_abs_typed_base_i.h
diff --git a/decoder/include/common/comp_attach_pt_t.h b/decoder/include/common/comp_attach_pt_t.h index ee9a06f..1d56240 100644 --- a/decoder/include/common/comp_attach_pt_t.h +++ b/decoder/include/common/comp_attach_pt_t.h @@ -81,6 +81,10 @@ public: */ virtual ocsd_err_t detach(T* component);
+ + // detach current first if anything attached, connect supplied pointer, remain unattached if pointer 0 + virtual ocsd_err_t replace_first(T* component); + /*! * Detach all components. */ @@ -170,6 +174,17 @@ template<class T> ocsd_err_t componentAttachPt<T>::attach(T* component) return OCSD_OK; }
+template<class T> ocsd_err_t componentAttachPt<T>::replace_first(T* component) +{ + if(m_hasAttached) + detach(m_comp); + + if(component == 0) + return OCSD_OK; + + return attach(component); +} + template<class T> ocsd_err_t componentAttachPt<T>::detach(T* component) { if(m_comp != component) diff --git a/decoder/include/common/trc_component.h b/decoder/include/common/trc_component.h index 3ccbac6..49ad265 100644 --- a/decoder/include/common/trc_component.h +++ b/decoder/include/common/trc_component.h @@ -58,7 +58,7 @@ class TraceComponent public: TraceComponent(const std::string &name); TraceComponent(const std::string &name, int instIDNum); - ~TraceComponent(); /**< Default Destructor */ + virtual ~TraceComponent(); /**< Default Destructor */
const std::string &getComponentName() const { return m_name; }; void setComponentName(const std::string &name) { m_name = name; }; @@ -94,6 +94,22 @@ public: */ const uint32_t getSupportedOpModes() const { return m_supported_op_flags; };
+ /*! + * Set associated trace component - used by generic code to track + * packet processor / packet decoder pairs. + * + * @param *assocComp : pointer to the associated component + */ + void setAssocComponent(TraceComponent *assocComp) { m_assocComp = assocComp; }; + + + /*! + * get associated trace component pointer + * + * @return TraceComponent *: associated component. + */ + TraceComponent *getAssocComponent() { return m_assocComp; }; + protected: friend class errLogAttachMonitor;
@@ -114,7 +130,9 @@ private: ocsd_err_severity_t m_errVerbosity; errLogAttachMonitor *m_pErrAttachMon;
- std::string m_name; + std::string m_name; + + TraceComponent *m_assocComp; //!< associated component -> if this is a pkt decoder, associated pkt processor. }; /** @}*/ #endif // ARM_TRC_COMPONENT_H_INCLUDED diff --git a/decoder/include/common/trc_pkt_decode_base.h b/decoder/include/common/trc_pkt_decode_base.h index 38b4ebd..2bbf5e5 100644 --- a/decoder/include/common/trc_pkt_decode_base.h +++ b/decoder/include/common/trc_pkt_decode_base.h @@ -43,7 +43,6 @@ #include "interfaces/trc_tgt_mem_access_i.h" #include "interfaces/trc_instr_decode_i.h"
- /** @defgroup ocsd_pkt_decode OpenCSD Library : Packet Decoders.
@brief Classes providing Protocol Packet Decoding capability. @@ -64,11 +63,17 @@ class TrcPktDecodeI : public TraceComponent public: TrcPktDecodeI(const char *component_name); TrcPktDecodeI(const char *component_name, int instIDNum); + virtual ~TrcPktDecodeI() {};
componentAttachPt<ITrcGenElemIn> *getTraceElemOutAttachPt() { return &m_trace_elem_out; }; componentAttachPt<ITargetMemAccess> *getMemoryAccessAttachPt() { return &m_mem_access; }; componentAttachPt<IInstrDecode> *getInstrDecodeAttachPt() { return &m_instr_decode; };
+ void setUsesMemAccess(bool bUsesMemaccess) { m_uses_memaccess = bUsesMemaccess; }; + const bool getUsesMemAccess() const { return m_uses_memaccess; }; + + void setUsesIDecode(bool bUsesIDecode) { m_uses_idecode = bUsesIDecode; }; + const bool getUsesIDecode() const { return m_uses_idecode; };
protected:
@@ -103,13 +108,18 @@ protected:
std::string init_err_msg; //!< error message for init error
+ bool m_uses_memaccess; + bool m_uses_idecode; + };
inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name) : TraceComponent(component_name), m_index_curr_pkt(0), m_decode_init_ok(false), - m_config_init_ok(false) + m_config_init_ok(false), + m_uses_memaccess(true), + m_uses_idecode(true) { }
@@ -117,7 +127,9 @@ inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name, int instIDNum) : TraceComponent(component_name, instIDNum), m_index_curr_pkt(0), m_decode_init_ok(false), - m_config_init_ok(false) + m_config_init_ok(false), + m_uses_memaccess(true), + m_uses_idecode(true) { }
@@ -129,9 +141,9 @@ inline const bool TrcPktDecodeI::checkInit() init_err_msg = "No decoder configuration information"; else if(!m_trace_elem_out.hasAttachedAndEnabled()) init_err_msg = "No element output interface attached and enabled"; - else if(!m_mem_access.hasAttachedAndEnabled()) + else if(m_uses_memaccess && !m_mem_access.hasAttachedAndEnabled()) init_err_msg = "No memory access interface attached and enabled"; - else if(!m_instr_decode.hasAttachedAndEnabled()) + else if(m_uses_idecode && !m_instr_decode.hasAttachedAndEnabled()) init_err_msg = "No instruction decoder interface attached and enabled"; else m_decode_init_ok = true; @@ -151,17 +163,19 @@ inline ocsd_datapath_resp_t TrcPktDecodeI::outputTraceElementIdx(ocsd_trc_index_
inline ocsd_err_t TrcPktDecodeI::instrDecode(ocsd_instr_info *instr_info) { - return m_instr_decode.first()->DecodeInstruction(instr_info); + if(m_uses_idecode) + return m_instr_decode.first()->DecodeInstruction(instr_info); + return OCSD_ERR_DCD_INTERFACE_UNUSED; }
inline ocsd_err_t TrcPktDecodeI::accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer) { - return m_mem_access.first()->ReadTargetMemory(address,getCoreSightTraceID(),mem_space, num_bytes,p_buffer); + if(m_uses_memaccess) + return m_mem_access.first()->ReadTargetMemory(address,getCoreSightTraceID(),mem_space, num_bytes,p_buffer); + return OCSD_ERR_DCD_INTERFACE_UNUSED; }
- /**********************************************************************/ - template <class P, class Pc> class TrcPktDecodeBase : public TrcPktDecodeI, public IPktDataIn<P> { @@ -176,7 +190,7 @@ public:
/* protocol configuration */ - ocsd_err_t setProtocolConfig(Pc *config); + ocsd_err_t setProtocolConfig(const Pc *config); const Pc * getProtocolConfig() const { return m_config; };
protected: @@ -255,7 +269,7 @@ template <class P, class Pc> ocsd_datapath_resp_t TrcPktDecodeBase<P, Pc>::Packe }
/* protocol configuration */ -template <class P, class Pc> ocsd_err_t TrcPktDecodeBase<P, Pc>::setProtocolConfig(Pc *config) +template <class P, class Pc> ocsd_err_t TrcPktDecodeBase<P, Pc>::setProtocolConfig(const Pc *config) { ocsd_err_t err = OCSD_ERR_INVALID_PARAM_VAL; if(config != 0) diff --git a/decoder/include/interfaces/trc_abs_typed_base_i.h b/decoder/include/interfaces/trc_abs_typed_base_i.h new file mode 100644 index 0000000..034ecd3 --- /dev/null +++ b/decoder/include/interfaces/trc_abs_typed_base_i.h @@ -0,0 +1,57 @@ +/* + * \file trc_abs_typed_base_i.h + * \brief OpenCSD : + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_TRC_ABS_TYPED_BASE_I_H_INCLUDED +#define ARM_TRC_ABS_TYPED_BASE_I_H_INCLUDED + +/*! + * @class ITrcTypedBase : Abstract base class to for interfaces templated types. + * + * This class is used as an abstract base for any interfaces that are specialised using + * template<> types. + * + * Designed to allow interface objects to be passed through generic interfaces into type + * specific templated implmentation handlers. + */ +class ITrcTypedBase +{ +public: + ITrcTypedBase() {}; + virtual ~ITrcTypedBase() {}; +}; + +#endif // ARM_TRC_ABS_TYPED_BASE_I_H_INCLUDED + +/* End of File trc_abs_typed_base_i.h */ diff --git a/decoder/include/interfaces/trc_indexer_pkt_i.h b/decoder/include/interfaces/trc_indexer_pkt_i.h index 138a0a6..02aecda 100644 --- a/decoder/include/interfaces/trc_indexer_pkt_i.h +++ b/decoder/include/interfaces/trc_indexer_pkt_i.h @@ -36,6 +36,8 @@ #ifndef ARM_TRC_INDEXER_PKT_I_H_INCLUDED #define ARM_TRC_INDEXER_PKT_I_H_INCLUDED
+#include "trc_abs_typed_base_i.h" + /*! * @class ITrcPktIndexer
@@ -55,7 +57,7 @@ * */ template <class Pt> -class ITrcPktIndexer +class ITrcPktIndexer : public ITrcTypedBase { public: ITrcPktIndexer() {}; /**< Default constructor. */ diff --git a/decoder/include/interfaces/trc_pkt_in_i.h b/decoder/include/interfaces/trc_pkt_in_i.h index 0d3135d..8f6c5ef 100644 --- a/decoder/include/interfaces/trc_pkt_in_i.h +++ b/decoder/include/interfaces/trc_pkt_in_i.h @@ -36,6 +36,8 @@ #ifndef ARM_TRC_PKT_IN_I_H_INCLUDED #define ARM_TRC_PKT_IN_I_H_INCLUDED
+#include "trc_abs_typed_base_i.h" + /*! * @class IPktDataIn * @ingroup ocsd_interfaces @@ -49,7 +51,7 @@ * */ template<class P> -class IPktDataIn +class IPktDataIn : public ITrcTypedBase { public: IPktDataIn() {}; /**< Default constructor. */ diff --git a/decoder/include/interfaces/trc_pkt_raw_in_i.h b/decoder/include/interfaces/trc_pkt_raw_in_i.h index 3cb711d..6f7b213 100644 --- a/decoder/include/interfaces/trc_pkt_raw_in_i.h +++ b/decoder/include/interfaces/trc_pkt_raw_in_i.h @@ -36,6 +36,8 @@ #ifndef ARM_TRC_PKT_RAW_IN_I_H_INCLUDED #define ARM_TRC_PKT_RAW_IN_I_H_INCLUDED
+#include "trc_abs_typed_base_i.h" + /*! * @class IPktRawDataMon * @@ -52,7 +54,7 @@ * */ template<class P> -class IPktRawDataMon +class IPktRawDataMon : public ITrcTypedBase { public: IPktRawDataMon() {}; /**< Default constructor. */
OcsdLibDcdRegister: class to manage the registration and access of named decoders in the library. Creates list of decoder managers
IDecoderMngr: Abstract interface to allow creation, interconnection and clean-up of protocol / type specific macros.
DecoderMngrBase: templated base class to implement generic version of the IDecoderMngr functionality. Type specific decoder managers specialise this with only default constructors/desctructors required making adding new decoder into the mechanism very easy
Signed-off-by: Mike Leach mike.leach@linaro.org --- .../ref_trace_decode_lib.vcxproj | 10 + .../ref_trace_decode_lib.vcxproj.filters | 30 ++ decoder/include/common/ocsd_dcd_mngr.h | 362 +++++++++++++++++++++ decoder/include/common/ocsd_dcd_mngr_i.h | 92 ++++++ decoder/include/common/ocsd_lib_dcd_register.h | 117 +++++++ decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 56 ++++ decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 30 ++ decoder/include/ocsd_if_types.h | 52 ++- decoder/include/ptm/trc_dcd_mngr_ptm.h | 56 ++++ decoder/include/stm/trc_dcd_mngr_stm.h | 54 +++ decoder/source/ocsd_lib_dcd_register.cpp | 147 +++++++++ 11 files changed, 993 insertions(+), 13 deletions(-) create mode 100644 decoder/include/common/ocsd_dcd_mngr.h create mode 100644 decoder/include/common/ocsd_dcd_mngr_i.h create mode 100644 decoder/include/common/ocsd_lib_dcd_register.h create mode 100644 decoder/include/etmv3/trc_dcd_mngr_etmv3.h create mode 100644 decoder/include/etmv4/trc_dcd_mngr_etmv4i.h create mode 100644 decoder/include/ptm/trc_dcd_mngr_ptm.h create mode 100644 decoder/include/stm/trc_dcd_mngr_stm.h create mode 100644 decoder/source/ocsd_lib_dcd_register.cpp
diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj index 929df5a..fa1a912 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj @@ -305,16 +305,20 @@ <ClInclude Include="..\..\..\include\common\comp_attach_notifier_i.h" /> <ClInclude Include="..\..\..\include\common\comp_attach_pt_t.h" /> <ClInclude Include="..\..\..\include\common\ocsd_code_follower.h" /> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr.h" /> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr_i.h" /> <ClInclude Include="..\..\..\include\common\ocsd_dcd_tree.h" /> <ClInclude Include="..\..\..\include\common\ocsd_dcd_tree_elem.h" /> <ClInclude Include="..\..\..\include\common\ocsd_error.h" /> <ClInclude Include="..\..\..\include\common\ocsd_error_logger.h" /> <ClInclude Include="..\..\..\include\common\ocsd_gen_elem_list.h" /> + <ClInclude Include="..\..\..\include\common\ocsd_lib_dcd_register.h" /> <ClInclude Include="..\..\..\include\common\ocsd_msg_logger.h" /> <ClInclude Include="..\..\..\include\common\ocsd_pe_context.h" /> <ClInclude Include="..\..\..\include\common\ocsd_version.h" /> <ClInclude Include="..\..\..\include\common\trc_component.h" /> <ClInclude Include="..\..\..\include\common\trc_core_arch_map.h" /> + <ClInclude Include="..\..\..\include\common\trc_cs_config.h" /> <ClInclude Include="..\..\..\include\common\trc_frame_deformatter.h" /> <ClInclude Include="..\..\..\include\common\trc_gen_elem.h" /> <ClInclude Include="..\..\..\include\common\trc_pkt_decode_base.h" /> @@ -322,17 +326,20 @@ <ClInclude Include="..\..\..\include\common\trc_printable_elem.h" /> <ClInclude Include="..\..\..\include\etmv3\etmv3_decoder.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_cmp_cfg_etmv3.h" /> + <ClInclude Include="..\..\..\include\etmv3\trc_dcd_mngr_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_decode_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_elem_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_proc_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_types_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv4\etmv4_decoder.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_cmp_cfg_etmv4.h" /> + <ClInclude Include="..\..\..\include\etmv4\trc_dcd_mngr_etmv4i.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_decode_etmv4i.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_elem_etmv4d.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_elem_etmv4i.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_proc_etmv4.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_types_etmv4.h" /> + <ClInclude Include="..\..\..\include\interfaces\trc_abs_typed_base_i.h" /> <ClInclude Include="..\..\..\include\interfaces\trc_data_rawframe_in_i.h" /> <ClInclude Include="..\..\..\include\interfaces\trc_data_raw_in_i.h" /> <ClInclude Include="..\..\..\include\interfaces\trc_error_log_i.h" /> @@ -356,12 +363,14 @@ <ClInclude Include="..\..\..\include\opencsd.h" /> <ClInclude Include="..\..\..\include\ptm\ptm_decoder.h" /> <ClInclude Include="..\..\..\include\ptm\trc_cmp_cfg_ptm.h" /> + <ClInclude Include="..\..\..\include\ptm\trc_dcd_mngr_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_decode_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_elem_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_proc_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_types_ptm.h" /> <ClInclude Include="..\..\..\include\stm\stm_decoder.h" /> <ClInclude Include="..\..\..\include\stm\trc_cmp_cfg_stm.h" /> + <ClInclude Include="..\..\..\include\stm\trc_dcd_mngr_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_elem_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_proc_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_types_stm.h" /> @@ -397,6 +406,7 @@ <ClCompile Include="..\..\..\source\ocsd_error.cpp" /> <ClCompile Include="..\..\..\source\ocsd_error_logger.cpp" /> <ClCompile Include="..\..\..\source\ocsd_gen_elem_list.cpp" /> + <ClCompile Include="..\..\..\source\ocsd_lib_dcd_register.cpp" /> <ClCompile Include="..\..\..\source\ocsd_msg_logger.cpp" /> <ClCompile Include="..\..\..\source\ocsd_version.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_cmp_cfg_ptm.cpp" /> diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters index efb3183..d267c31 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters @@ -290,6 +290,33 @@ <ClInclude Include="..\..\..\include\common\ocsd_gen_elem_list.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="..\..\..\include\common\trc_cs_config.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr_i.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\common\ocsd_lib_dcd_register.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\interfaces\trc_abs_typed_base_i.h"> + <Filter>interfaces</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\etmv4\trc_dcd_mngr_etmv4i.h"> + <Filter>Header Files\etmv4</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\etmv3\trc_dcd_mngr_etmv3.h"> + <Filter>Source Files\etmv3</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\ptm\trc_dcd_mngr_ptm.h"> + <Filter>Header Files\ptm</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\stm\trc_dcd_mngr_stm.h"> + <Filter>Header Files\stm</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\trc_component.cpp"> @@ -400,5 +427,8 @@ <ClCompile Include="..\..\..\source\ocsd_gen_elem_list.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\ocsd_lib_dcd_register.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/decoder/include/common/ocsd_dcd_mngr.h b/decoder/include/common/ocsd_dcd_mngr.h new file mode 100644 index 0000000..3b58e60 --- /dev/null +++ b/decoder/include/common/ocsd_dcd_mngr.h @@ -0,0 +1,362 @@ +/* + * \file ocsd_dcd_mngr.h + * \brief OpenCSD : Decoder manager base class. + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_OCSD_DCD_MNGR_H_INCLUDED +#define ARM_OCSD_DCD_MNGR_H_INCLUDED + +#include "ocsd_if_types.h" +#include "common/ocsd_dcd_mngr_i.h" +#include "common/ocsd_lib_dcd_register.h" +#include "common/trc_pkt_decode_base.h" + + +template <class P, class Pt, class Pc> +class DecoderMngrBase : public IDecoderMngr +{ +public: + DecoderMngrBase(const std::string &decoderTypeName); + virtual ~DecoderMngrBase() {}; + + // create decoder interface. + virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component); + virtual ocsd_err_t destroyDecoder(TraceComponent *p_component); + +// common + virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog); + +// pkt decoder + virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec); + virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor); + virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink); + +// pkt processor + virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon); + virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer); + virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink); + +// data input connection interface + virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn); + +// implemented by decoder handler derived classes + virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0; + virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; }; +}; + +template <class P, class Pt, class Pc> +DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName) +{ + OcsdLibDcdRegister *pDcdReg = OcsdLibDcdRegister::getDecoderRegister(); + if(pDcdReg) + pDcdReg->registerDecoderTypeByName(decoderTypeName,this); +} + + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createDecoder(const int create_flags, const int instID, const CSConfig *pConfig, TraceComponent **ppTrcComp) +{ + ocsd_err_t err = OCSD_OK; + TraceComponent *pkt_proc = 0; + TraceComponent *pkt_dcd = 0; + bool bUseInstID = (create_flags & OCSD_CREATE_FLG_INST_ID) != 0; + bool bDecoder = (create_flags & OCSD_CREATE_FLG_FULL_DECODER) != 0; + bool bUnConfigured = (pConfig == 0); + + const Pc *pConf = dynamic_cast< const Pc * >(pConfig); + + // check inputs valid... + if((pConf == 0) && !bUnConfigured) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if((create_flags & (OCSD_CREATE_FLG_PACKET_PROC | OCSD_CREATE_FLG_FULL_DECODER)) == 0) + return OCSD_ERR_INVALID_PARAM_VAL; + + // always need a packet processor + pkt_proc = createPktProc(bUseInstID, instID); + if(!pkt_proc) + return OCSD_ERR_MEM; + + // set the configuration + TrcPktProcBase<P,Pt,Pc> *pProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> *>(pkt_proc); + if(pProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(!bUnConfigured) + pProcBase->setProtocolConfig(pConf); + + *ppTrcComp = pkt_proc; + + // may need a packet decoder + if(bDecoder) + { + // create the decoder + pkt_dcd = createPktDecode(bUseInstID, instID); + if(!pkt_dcd) + return OCSD_ERR_MEM; + + // get the decoder base + TrcPktDecodeBase<P,Pc> *pBase = dynamic_cast< TrcPktDecodeBase<P,Pc> *>(pkt_dcd); + if(pBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(!bUnConfigured) + pBase->setProtocolConfig(pConf); + + // associate decoder with packet processor + // -> this means a TraceComponent with an associated component is a packet decoder. + // the associated component is the connected packet processor. + pkt_dcd->setAssocComponent(pkt_proc); + + // connect packet processor and decoder + pProcBase->getPacketOutAttachPt()->attach(pBase); + + *ppTrcComp = pkt_dcd; + } + return OCSD_OK; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::destroyDecoder(TraceComponent *pComponent) +{ + if(pComponent->getAssocComponent() != 0) + delete pComponent->getAssocComponent(); + delete pComponent; + return OCSD_OK; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog) +{ + return pComponent->getErrorLogAttachPt()->replace_first(pIErrorLog); +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec) +{ + ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED; + + if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor + return OCSD_ERR_INVALID_PARAM_TYPE; + + TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent); + if(pDcdI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(pDcdI->getUsesIDecode()) + err = pDcdI->getInstrDecodeAttachPt()->replace_first(pIInstrDec); + + return err; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor) +{ + ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED; + + if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor + return OCSD_ERR_INVALID_PARAM_TYPE; + + TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent); + if(pDcdI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(pDcdI->getUsesMemAccess()) + err = pDcdI->getMemoryAccessAttachPt()->replace_first(pMemAccessor); + + return err; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink) +{ + ocsd_err_t err = OCSD_ERR_INVALID_PARAM_TYPE; + + if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor + return err; + + TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent); + if(pDcdI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + err = pDcdI->getTraceElemOutAttachPt()->replace_first(pOutSink); + + return err; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn) +{ + // find the packet processor + TraceComponent *pPktProc = pComponent; + if(pComponent->getAssocComponent() != 0) + pPktProc = pComponent->getAssocComponent(); + + TrcPktProcI *pPPI = dynamic_cast< TrcPktProcI * >(pPktProc); + if(pPPI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + *ppDataIn = pPPI; + + return OCSD_OK; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon) +{ + // find the packet processor + TraceComponent *pPktProc = pComponent; + if(pComponent->getAssocComponent() != 0) + pPktProc = pComponent->getAssocComponent(); + + // get the packet processor + TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc); + if(pPktProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // get the interface + IPktRawDataMon<P> *p_If = dynamic_cast< IPktRawDataMon<P> * >(pPktRawDataMon); + if(p_If == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + return pPktProcBase->getRawPacketMonAttachPt()->replace_first(p_If); +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer) +{ + // find the packet processor + TraceComponent *pPktProc = pComponent; + if(pComponent->getAssocComponent() != 0) + pPktProc = pComponent->getAssocComponent(); + + // get the packet processor + TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc); + if(pPktProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // get the interface + ITrcPktIndexer<Pt> *p_If = dynamic_cast< ITrcPktIndexer<Pt> * >(pPktIndexer); + if(p_If == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + return pPktProcBase->getTraceIDIndexerAttachPt()->replace_first(p_If); +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink) +{ + // must be solo packet processor + if(pComponent->getAssocComponent() != 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // interface must be the correct one. + IPktDataIn<P> *pkt_in_i = dynamic_cast< IPktDataIn<P> * >(pPktDataInSink); + if(pkt_in_i == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // get the packet processor + TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pComponent); + if(pPktProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // attach + return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i); +} + + +/****************************************************************************************************/ +/* Full decoder / packet process pair, templated base for creating decoder objects */ +/****************************************************************************************************/ + +template< class P, // Packet class. + class Pt, // Packet enum type ID. + class Pc, // Processor config class. + class PktProc, // Packet processor class. + class PktDcd> // Packet decoder class. +class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc> +{ +public: + DecodeMngrFullDcd (const std::string &name) : DecoderMngrBase(name) {}; + virtual ~DecodeMngrFullDcd() {}; + + virtual TraceComponent *createPktProc(const bool useInstID, const int instID) + { + TraceComponent *pComp; + if(useInstID) + pComp = new (std::nothrow) PktProc(instID); + else + pComp = new (std::nothrow) PktProc(); + return pComp; + } + + virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) + { + TraceComponent *pComp; + if(useInstID) + pComp = new (std::nothrow)PktDcd(instID); + else + pComp = new (std::nothrow)PktDcd(); + return pComp; + } +}; + +/****************************************************************************************************/ +/* Packet processor only, templated base for creating decoder objects */ +/****************************************************************************************************/ + +template< class P, // Packet class. + class Pt, // Packet enum type ID. + class Pc, // Processor config class. + class PktProc> // Packet processor class. +class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc> +{ +public: + DecodeMngrPktProc (const std::string &name) : DecoderMngrBase(name) {}; + virtual ~DecodeMngrPktProc() {}; + + virtual TraceComponent *createPktProc(const bool useInstID, const int instID) + { + TraceComponent *pComp; + if(useInstID) + pComp = new (std::nothrow) PktProc(instID); + else + pComp = new (std::nothrow) PktProc(); + return pComp; + } +}; + + + +#endif // ARM_OCSD_DCD_MNGR_H_INCLUDED + +/* End of File ocsd_dcd_mngr.h */ diff --git a/decoder/include/common/ocsd_dcd_mngr_i.h b/decoder/include/common/ocsd_dcd_mngr_i.h new file mode 100644 index 0000000..f7a6720 --- /dev/null +++ b/decoder/include/common/ocsd_dcd_mngr_i.h @@ -0,0 +1,92 @@ +/* + * \file ocsd_dcd_mngr_i.h + * \brief OpenCSD : Decoder manager interface. + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_OCSD_DCD_MNGR_I_H_INCLUDED +#define ARM_OCSD_DCD_MNGR_I_H_INCLUDED + +#include "ocsd_if_types.h" +#include "common/trc_cs_config.h" +#include "common/trc_component.h" + +#include "interfaces/trc_error_log_i.h" +#include "interfaces/trc_data_raw_in_i.h" +#include "interfaces/trc_instr_decode_i.h" +#include "interfaces/trc_tgt_mem_access_i.h" +#include "interfaces/trc_gen_elem_in_i.h" +#include "interfaces/trc_abs_typed_base_i.h" + +class IDecoderMngr +{ +public: + IDecoderMngr() {}; + virtual ~IDecoderMngr() {}; + +// create and destroy decoders + virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **ppComponent) = 0; + virtual ocsd_err_t destroyDecoder(TraceComponent *pComponent) = 0; + +// connect decoders to other components - (replace current / 0 pointer value to detach ); +// compatible with all decoders + //!attach error logger to ptk-processor, or both of pkt processor and pkt decoder pair + virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog) = 0; + +// pkt decoder only + //! attach instruction decoder to pkt decoder + virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec) = 0; + + //! attach memory accessor to pkt decoder + virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor) = 0; + + //! attach generic output interface to pkt decoder + virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink) = 0; + +// pkt processor only + //! attach a raw packet monitor to pkt processor (solo pkt processor, or pkt processor part of pair) + virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon) = 0; + + //! attach a packet indexer to pkt processor (solo pkt processor, or pkt processor part of pair) + virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer) = 0; + + //! attach a packet data sink to pkt processor output (solo pkt processor only - instead of decoder when pkt processor only created.) + virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink) = 0; + +// data input connection interface + //! get raw data input interface from packet processor + virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn) = 0; + +}; + +#endif // ARM_OCSD_DCD_MNGR_I_H_INCLUDED + +/* End of File ocsd_dcd_mngr.h */ \ No newline at end of file diff --git a/decoder/include/common/ocsd_lib_dcd_register.h b/decoder/include/common/ocsd_lib_dcd_register.h new file mode 100644 index 0000000..dc5fd42 --- /dev/null +++ b/decoder/include/common/ocsd_lib_dcd_register.h @@ -0,0 +1,117 @@ +/* + * \file ocsd_lib_dcd_register.h + * \brief OpenCSD : Library decoder registration and management. + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ + +#ifndef ARM_OCSD_LIB_DCD_REGISTER_H_INCLUDED +#define ARM_OCSD_LIB_DCD_REGISTER_H_INCLUDED + + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <map> + +#include "ocsd_if_types.h" +#include "common/ocsd_dcd_mngr_i.h" + +/*! + * @class OcsdLibDcdRegister : Registers decoders with the library + * + * library decoder register class allows decoders to be registered by name, and the register allows clients to access + * the list of names of registerd decoders. + * + * The decoders in the library are accessed through the decoder manager interface. This provides a set of functions to allow + * the creation, manipulation and destruction of registered decoders + * + */ +class OcsdLibDcdRegister +{ +public: + static OcsdLibDcdRegister *getDecoderRegister(); + + static void deregisterAllDecoders(); //!< library cleanup - deregisters decoder managers and destroys the register object. + + const ocsd_err_t registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact); //!< register a decoder manager interface + const ocsd_err_t getDecoderMngrByName(const std::string &name, IDecoderMngr **p_decoder_mngr); + + const bool isRegisteredDecoder(const std::string &name); + const bool getFirstNamedDecoder(std::string &name); + const bool getNextNamedDecoder(std::string &name); + +private: + void registerBuiltInDecoders(); //!< register the list of build in decoder managers on first access of getDecoderMngrByName. + + std::map<const std::string, IDecoderMngr *> m_decoder_mngrs; //!< map linking names to decoder manager interfaces. + std::map<const std::string, IDecoderMngr *>::const_iterator m_iter; //!< iterator for name search. + + // singleton pattern - need just one of these in the library - ensure all default constructors are private. + OcsdLibDcdRegister(); + OcsdLibDcdRegister(OcsdLibDcdRegister const &) {}; + OcsdLibDcdRegister& operator=(OcsdLibDcdRegister const &){}; + ~OcsdLibDcdRegister(); + + static OcsdLibDcdRegister *m_p_libMngr; + static bool m_b_registeredBuiltins; +}; + +/*! + * Typedef of function signature to create a decoder manager. + * + * @param *name : Registered name of the decoder. + */ +typedef IDecoderMngr *(*CreateMngr)(const std::string &name); + +/*! + * Template function to create a specific decoder manager class object. + * + * @param &name : Registered name of the decoder. + * + * @return IDecoderMngr * : pointer to the decoder manager base class interface. + */ +template <typename T> IDecoderMngr *createManagerInst(const std::string &name) +{ + return new (std::nothrow)T(name); +} + +/*! Structure to contain the information needed to create and register a builtin decoder + * manager with the library + */ +typedef struct built_in_decoder_info { + IDecoderMngr *pMngr; //!< pointer to created decoder manager + CreateMngr PFn; //!< function to create the decoder manager. + const char *name; //!< registered name of the decoder. +} built_in_decoder_info_t; + +//! Define to use to fill in an array of built_in_decoder_info_t structures. +#define CREATE_BUILTIN_ENTRY(C,N) { 0, createManagerInst<C>, N } + +#endif // ARM_OCSD_LIB_DCD_REGISTER_H_INCLUDED + +/* End of File ocsd_lib_dcd_register.h */ diff --git a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h new file mode 100644 index 0000000..cbd1182 --- /dev/null +++ b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h @@ -0,0 +1,56 @@ +/* + * \file trc_dcd_mngr_etmv3.h + * \brief OpenCSD : ETMv3 decoder manager / handler specialisation + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef ARM_TRC_DCD_MNGR_ETMV3_H_INCLUDED +#define ARM_TRC_DCD_MNGR_ETMV3_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_etmv3.h" +#include "trc_pkt_proc_etmv3.h" +#include "trc_cmp_cfg_etmv3.h" +#include "trc_pkt_types_etmv3.h" + +class DecoderMngrEtmV3 : public DecodeMngrFullDcd< EtmV3TrcPacket, + ocsd_etmv3_pkt_type, + EtmV3Config, + TrcPktProcEtmV3, + TrcPktDecodeEtmV3> +{ +public: + DecoderMngrEtmV3(const std::string &name) : DecodeMngrFullDcd(name) {}; + virtual ~DecoderMngrEtmV3() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_ETMV3_H_INCLUDED + +/* End of File trc_dcd_mngr_etmv3.h */ diff --git a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h new file mode 100644 index 0000000..3aef842 --- /dev/null +++ b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h @@ -0,0 +1,30 @@ +/* + * \file trc_dcd_mngr_etmv4i.h + * \brief Reference CoreSight Trace Decoder : + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ + +#ifndef ARM_TRC_DCD_MNGR_ETMV4I_H_INCLUDED +#define ARM_TRC_DCD_MNGR_ETMV4I_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_etmv4i.h" +#include "trc_pkt_proc_etmv4.h" +#include "trc_cmp_cfg_etmv4.h" +#include "trc_pkt_types_etmv4.h" + +class DecoderMngrEtmV4I : public DecodeMngrFullDcd< EtmV4ITrcPacket, + ocsd_etmv4_i_pkt_type, + EtmV4Config, + TrcPktProcEtmV4I, + TrcPktDecodeEtmV4I> +{ +public: + DecoderMngrEtmV4I(const std::string &name) : DecodeMngrFullDcd(name) {}; + virtual ~DecoderMngrEtmV4I() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_ETMV4I_H_INCLUDED + +/* End of File trc_dcd_mngr_etmv4i.h */ diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index 4fb428d..d214f76 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -86,6 +86,7 @@ typedef enum _ocsd_err_t { OCSD_ERR_INVALID_ID, /**< Invalid CoreSight Trace Source ID. */ OCSD_ERR_BAD_HANDLE, /**< Invalid handle passed to component. */ OCSD_ERR_INVALID_PARAM_VAL, /**< Invalid value parameter passed to component. */ + OCSD_ERR_INVALID_PARAM_TYPE, /**< Type mismatch on abstract interface */ OCSD_ERR_FILE_ERROR, /**< File access error */ OCSD_ERR_NO_PROTOCOL, /**< Trace protocol unsupported */ /* attachment point errors */ @@ -123,6 +124,11 @@ typedef enum _ocsd_err_t { OCSD_ERR_TEST_SNAPSHOT_PARSE_INFO, /**< test snapshot file parse information */ OCSD_ERR_TEST_SNAPSHOT_READ, /**< test snapshot reader error */ OCSD_ERR_TEST_SS_TO_DECODER, /**< test snapshot to decode tree conversion error */ + /* decoder registration */ + OCSD_ERR_DCDREG_NAME_REPEAT, /**< attempted to register a decoder with the same name as another one */ + OCSD_ERR_DCDREG_NAME_UNKNOWN, /**< attempted to find a decoder with a name that is not known in the library */ + /* decoder config */ + OCSD_ERR_DCD_INTERFACE_UNUSED, /**< Attempt to connect or use and inteface not supported by this decoder. */ /* end marker*/ OCSD_ERR_LAST } ocsd_err_t; @@ -202,19 +208,6 @@ typedef enum _ocsd_datapath_resp_t { /** @name Trace Decode component types @{*/
-/*! Trace Protocol Types - used to create appropriate decoder. - */ -typedef enum _ocsd_trace_protocol_t { - OCSD_PROTOCOL_EXTERN, /**< Custom external decoder attached to the decode tree - protocol unknown */ - OCSD_PROTOCOL_ETMV3, /**< ETMV3 instruction and data trace protocol decoder. */ - OCSD_PROTOCOL_ETMV4I, /**< ETMV4 instruction trace protocol decoder. */ - OCSD_PROTOCOL_ETMV4D, /**< ETMV4 data trace protocol decoder. */ - OCSD_PROTOCOL_PTM, /**< PTM program flow instruction trace protocol decoder. */ - OCSD_PROTOCOL_STM, /**< STM system trace protocol decoder. */ - /* others to be added here */ - OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ -} ocsd_trace_protocol_t; -
/** Raw frame element data types Data blocks types output from ITrcRawFrameIn. @@ -474,6 +467,39 @@ typedef uint32_t (* Fn_MemAcc_CB)(const void *p_context, const ocsd_vaddr_t add
/** @}*/
+/** @name Decoder creation information + + Flags to use when creating decoders by name + + Builtin decoder names. + + Protocol type enum +@{*/ + +#define OCSD_CREATE_FLG_PACKET_PROC 0x01 /**< Create packet processor only. */ +#define OCSD_CREATE_FLG_FULL_DECODER 0x02 /**< Create packet processor + decoder pair */ +#define OCSD_CREATE_FLG_INST_ID 0x04 /**< Use instance ID in decoder instance name */ + +#define OCSD_BUILTIN_DCD_STM "STM" /**< STM decoder */ +#define OCSD_BUILTIN_DCD_ETMV3 "ETMV3" /**< ETMv3 decoder */ +#define OCSD_BUILTIN_DCD_ETMV4I "ETMV4I" /**< ETMv4 instruction decoder */ +#define OCSD_BUILTIN_DCD_ETMV4D "ETMV4D" /**< ETMv4 data decoder */ +#define OCSD_BUILTIN_DCD_PTM "PTM" /**< PTM decoder */ + +/*! Trace Protocol Builtin Types + extern + */ +typedef enum _ocsd_trace_protocol_t { + OCSD_PROTOCOL_EXTERN, /**< Custom external decoder attached to the decode tree - protocol unknown */ + OCSD_PROTOCOL_ETMV3, /**< ETMV3 instruction and data trace protocol decoder. */ + OCSD_PROTOCOL_ETMV4I, /**< ETMV4 instruction trace protocol decoder. */ + OCSD_PROTOCOL_ETMV4D, /**< ETMV4 data trace protocol decoder. */ + OCSD_PROTOCOL_PTM, /**< PTM program flow instruction trace protocol decoder. */ + OCSD_PROTOCOL_STM, /**< STM system trace protocol decoder. */ + /* others to be added here */ + OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ +} ocsd_trace_protocol_t; + +/** @}*/
/** @}*/ #endif // ARM_OCSD_IF_TYPES_H_INCLUDED diff --git a/decoder/include/ptm/trc_dcd_mngr_ptm.h b/decoder/include/ptm/trc_dcd_mngr_ptm.h new file mode 100644 index 0000000..27fb270 --- /dev/null +++ b/decoder/include/ptm/trc_dcd_mngr_ptm.h @@ -0,0 +1,56 @@ +/* + * \file trc_dcd_mngr_ptm.h + * \brief OpenCSD : PTM decoder manager / handler specialisation + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef ARM_TRC_DCD_MNGR_PTM_H_INCLUDED +#define ARM_TRC_DCD_MNGR_PTM_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_ptm.h" +#include "trc_pkt_proc_ptm.h" +#include "trc_cmp_cfg_ptm.h" +#include "trc_pkt_types_ptm.h" + +class DecoderMngrPtm : public DecodeMngrFullDcd< PtmTrcPacket, + ocsd_ptm_pkt_type, + PtmConfig, + TrcPktProcPtm, + TrcPktDecodePtm> +{ +public: + DecoderMngrPtm(const std::string &name) : DecodeMngrFullDcd(name) {}; + virtual ~DecoderMngrPtm() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_PTM_H_INCLUDED + +/* End of File trc_dcd_mngr_ptm.h */ diff --git a/decoder/include/stm/trc_dcd_mngr_stm.h b/decoder/include/stm/trc_dcd_mngr_stm.h new file mode 100644 index 0000000..356ed72 --- /dev/null +++ b/decoder/include/stm/trc_dcd_mngr_stm.h @@ -0,0 +1,54 @@ +/* + * \file trc_dcd_mngr_stm.h + * \brief OpenCSD : STM decoder manager / handler specialisation + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef ARM_TRC_DCD_MNGR_STM_H_INCLUDED +#define ARM_TRC_DCD_MNGR_STM_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_proc_stm.h" +#include "trc_cmp_cfg_stm.h" +#include "trc_pkt_types_stm.h" + +class DecoderMngrStm : public DecodeMngrPktProc< StmTrcPacket, + ocsd_stm_pkt_type, + STMConfig, + TrcPktProcStm> +{ +public: + DecoderMngrStm(const std::string &name) : DecodeMngrPktProc(name) {}; + virtual ~DecoderMngrStm() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_STM_H_INCLUDED + +/* End of File trc_dcd_mngr_stm.h */ diff --git a/decoder/source/ocsd_lib_dcd_register.cpp b/decoder/source/ocsd_lib_dcd_register.cpp new file mode 100644 index 0000000..053f256 --- /dev/null +++ b/decoder/source/ocsd_lib_dcd_register.cpp @@ -0,0 +1,147 @@ +/* + * \file ocsd_lib_dcd_register.cpp + * \brief OpenCSD : Library decoder register object + * + * \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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "common/ocsd_lib_dcd_register.h" + +// include built-in decode manager headers +#include "etmv4/trc_dcd_mngr_etmv4i.h" +#include "etmv3/trc_dcd_mngr_etmv3.h" +#include "ptm/trc_dcd_mngr_ptm.h" +#include "stm/trc_dcd_mngr_stm.h" + +// create array of built-in decoders to register with library +static built_in_decoder_info_t sBuiltInArray[] = { + CREATE_BUILTIN_ENTRY(DecoderMngrEtmV4I,OCSD_BUILTIN_DCD_ETMV4I), + CREATE_BUILTIN_ENTRY(DecoderMngrEtmV3, OCSD_BUILTIN_DCD_ETMV3), + CREATE_BUILTIN_ENTRY(DecoderMngrPtm, OCSD_BUILTIN_DCD_PTM), + CREATE_BUILTIN_ENTRY(DecoderMngrStm, OCSD_BUILTIN_DCD_STM) + //{ 0, 0, 0} +}; + +#define NUM_BUILTINS sizeof(sBuiltInArray) / sizeof(built_in_decoder_info_t) + + +OcsdLibDcdRegister *OcsdLibDcdRegister::m_p_libMngr = 0; +bool OcsdLibDcdRegister::m_b_registeredBuiltins = false; + +OcsdLibDcdRegister *OcsdLibDcdRegister::getDecoderRegister() +{ + if(m_p_libMngr == 0) + m_p_libMngr = new (std::nothrow) OcsdLibDcdRegister(); + return m_p_libMngr; +} + +OcsdLibDcdRegister::OcsdLibDcdRegister() +{ + m_iter = m_decoder_mngrs.begin(); +} + +OcsdLibDcdRegister::~OcsdLibDcdRegister() +{ + m_decoder_mngrs.clear(); +} + + +const ocsd_err_t OcsdLibDcdRegister::registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact) +{ + if(isRegisteredDecoder(name)) + return OCSD_ERR_DCDREG_NAME_REPEAT; + m_decoder_mngrs.emplace(std::pair<const std::string, IDecoderMngr *>(name,p_decoder_fact)); + return OCSD_OK; +} + +void OcsdLibDcdRegister::registerBuiltInDecoders() +{ + bool memFail = false; + for(int i = 0; i < NUM_BUILTINS; i++) + { + if(sBuiltInArray[i].PFn) + { + sBuiltInArray[i].pMngr = sBuiltInArray[i].PFn( sBuiltInArray[i].name); + if(!sBuiltInArray[i].pMngr) + memFail=true; + } + } + m_b_registeredBuiltins = !memFail; +} + +void OcsdLibDcdRegister::deregisterAllDecoders() +{ + for(int i = 0; i < NUM_BUILTINS; i++) + delete sBuiltInArray[i].pMngr; + m_b_registeredBuiltins = false; + delete m_p_libMngr; + m_p_libMngr = 0; +} + +const ocsd_err_t OcsdLibDcdRegister::getDecoderMngrByName(const std::string &name, IDecoderMngr **p_decoder_mngr) +{ + if(!m_b_registeredBuiltins) + { + registerBuiltInDecoders(); + if(!m_b_registeredBuiltins) + return OCSD_ERR_MEM; + } + + std::map<const std::string, IDecoderMngr *>::const_iterator iter = m_decoder_mngrs.find(name); + if(iter == m_decoder_mngrs.end()) + return OCSD_ERR_DCDREG_NAME_UNKNOWN; + *p_decoder_mngr = iter->second; + return OCSD_OK; +} + +const bool OcsdLibDcdRegister::isRegisteredDecoder(const std::string &name) +{ + std::map<const std::string, IDecoderMngr *>::const_iterator iter = m_decoder_mngrs.find(name); + if(iter != m_decoder_mngrs.end()) + return true; + return false; +} + +const bool OcsdLibDcdRegister::getFirstNamedDecoder(std::string &name) +{ + m_iter = m_decoder_mngrs.begin(); + return getNextNamedDecoder(name); +} + +const bool OcsdLibDcdRegister::getNextNamedDecoder(std::string &name) +{ + if(m_iter == m_decoder_mngrs.end()) + return false; + name = m_iter->first; + m_iter++; + return true; +} + +/* End of File ocsd_lib_dcd_register.cpp */
Added create by name API to decode tree class. Update error printer to handle added error codes.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/ocsd_dcd_tree.h | 3 + decoder/source/etmv3/trc_pkt_proc_etmv3.cpp | 2 +- decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp | 6 ++ decoder/source/ocsd_dcd_tree.cpp | 80 ++++++++++++++++++++++ decoder/source/ocsd_error.cpp | 6 ++ .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 10 ++- 6 files changed, 105 insertions(+), 2 deletions(-)
diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 843a7b5..77b69bf 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -116,6 +116,9 @@ public: ocsd_err_t createETMv4Decoder(EtmV4Config *p_config, bool bDataChannel = false); ocsd_err_t createPTMDecoder(PtmConfig *p_config);
+ /*! Create a decoder by registered name */ + ocsd_err_t createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig); + /* remove a decoder / packet processor attached to an ID - allows another decoder to be substituted. */ ocsd_err_t removeDecoder(const uint8_t CSID);
diff --git a/decoder/source/etmv3/trc_pkt_proc_etmv3.cpp b/decoder/source/etmv3/trc_pkt_proc_etmv3.cpp index 9f79c60..e7465b3 100644 --- a/decoder/source/etmv3/trc_pkt_proc_etmv3.cpp +++ b/decoder/source/etmv3/trc_pkt_proc_etmv3.cpp @@ -41,7 +41,7 @@ // G++ doesn't like the ## pasting #define ETMV3_PKTS_NAME "PKTP_ETMV3" #else -#define ETMV3_PKTS_NAME OCSD_CMPNAME_PREFIX_PKTPROC##"_ETMV3" +#define ETMV3_PKTS_NAME OCSD_CMPNAME_PREFIX_PKTPROC##"_"##OCSD_BUILTIN_DCD_ETMV3 #endif
static const uint32_t ETMV3_SUPPORTED_OP_FLAGS = OCSD_OPFLG_PKTPROC_COMMON | diff --git a/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp b/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp index 5703406..1b90b17 100644 --- a/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp +++ b/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp @@ -53,6 +53,12 @@ EtmV4Config::EtmV4Config() PrivateInit(); }
+EtmV4Config::EtmV4Config(const ocsd_etmv4_cfg *cfg_regs) +{ + m_cfg = *cfg_regs; + PrivateInit(); +} + EtmV4Config & EtmV4Config::operator=(const ocsd_etmv4_cfg *p_cfg) { m_cfg = *p_cfg; diff --git a/decoder/source/ocsd_dcd_tree.cpp b/decoder/source/ocsd_dcd_tree.cpp index 8f14af1..c6c0a04 100644 --- a/decoder/source/ocsd_dcd_tree.cpp +++ b/decoder/source/ocsd_dcd_tree.cpp @@ -34,6 +34,7 @@ */
#include "common/ocsd_dcd_tree.h" +#include "common/ocsd_lib_dcd_register.h" #include "mem_acc/trc_mem_acc_mapper.h"
@@ -632,6 +633,85 @@ ocsd_err_t DecodeTree::createPTMDecoder(PtmConfig *p_config) return err; }
+ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig) +{ + ocsd_err_t err = OCSD_OK; + IDecoderMngr *pDecoderMngr = 0; + TraceComponent *pTraceComp = 0; + int crtFlags = createFlags; + + uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID + if(usingFormatter()) + { + CSID = pConfig->getTraceID(); + crtFlags |= OCSD_CREATE_FLG_INST_ID; + } + + // create the decode element to attach to the channel. + if((err = createDecodeElement(CSID)) != OCSD_OK) + return err; + + // get the libary decoder register. + OcsdLibDcdRegister * lib_reg = OcsdLibDcdRegister::getDecoderRegister(); + if(lib_reg == 0) + return OCSD_ERR_NOT_INIT; + + // find the named decoder + if((err = lib_reg->getDecoderMngrByName(decoderName,&pDecoderMngr)) != OCSD_OK) + return err; + + // got the decoder... + err = pDecoderMngr->createDecoder(crtFlags,(int)CSID,pConfig,&pTraceComp); + + // TBD: set decode element + // when elements accept new pointer types -> component handle and decoder manager. + // m_decode_elements[CSID]->SetDecoderElement(pTraceComp, pDecoderMngr); + + // always attach an error logger + if(err == OCSD_OK) + err = pDecoderMngr->attachErrorLogger(pTraceComp,DecodeTree::s_i_error_logger); + + // if we created a packet decoder it may need additional components. + if(crtFlags & OCSD_CREATE_FLG_FULL_DECODER) + { + if(m_i_instr_decode && (err == OCSD_OK)) + err = pDecoderMngr->attachInstrDecoder(pTraceComp,m_i_instr_decode); + + if(err == OCSD_ERR_DCD_INTERFACE_UNUSED) // ignore if instruction decoder refused + err = OCSD_OK; + + if(m_i_mem_access && (err == OCSD_OK)) + err = pDecoderMngr->attachMemAccessor(pTraceComp,m_i_mem_access); + + if(err == OCSD_ERR_DCD_INTERFACE_UNUSED) // ignore if mem accessor refused + err = OCSD_OK; + + if( m_i_gen_elem_out && (err == OCSD_OK)) + err = pDecoderMngr->attachOutputSink(pTraceComp,m_i_gen_elem_out); + } + + // finally attach the packet processor input to the demux output channel + if(err == OCSD_OK) + { + ITrcDataIn *pDataIn = 0; + if((err = pDecoderMngr->getDataInputI(pTraceComp,&pDataIn)) == OCSD_OK) + { + // got the interface -> attach to demux, or direct to input of decode tree + if(usingFormatter()) + err = m_frame_deformatter_root->getIDStreamAttachPt(CSID)->attach(pDataIn); + else + m_i_decoder_root = pDataIn; + } + } + + if(err != OCSD_OK) + { + // TBD: destroyDecodeElement(CSID); // will destroy decoder as well. + } + return err; +} + +
ocsd_err_t DecodeTree::removeDecoder(const uint8_t CSID) { diff --git a/decoder/source/ocsd_error.cpp b/decoder/source/ocsd_error.cpp index a94b7b2..ca55c20 100644 --- a/decoder/source/ocsd_error.cpp +++ b/decoder/source/ocsd_error.cpp @@ -46,6 +46,7 @@ static const char *s_errorCodeDescs[][2] = { {"OCSD_ERR_INVALID_ID","Invalid CoreSight Trace Source ID."}, {"OCSD_ERR_BAD_HANDLE","Invalid handle passed to component."}, {"OCSD_ERR_INVALID_PARAM_VAL","Invalid value parameter passed to component."}, + {"OCSD_ERR_INVALID_PARAM_TYPE","Type mismatch on abstract interface."}, {"OCSD_ERR_FILE_ERROR","File access error"}, {"OCSD_ERR_NO_PROTOCOL","Trace protocol unsupported"}, /* attachment point errors */ @@ -83,6 +84,11 @@ static const char *s_errorCodeDescs[][2] = { {"OCSD_ERR_TEST_SNAPSHOT_PARSE_INFO", "Test snapshot file parse information"}, {"OCSD_ERR_TEST_SNAPSHOT_READ","test snapshot reader error"}, {"OCSD_ERR_TEST_SS_TO_DECODER","test snapshot to decode tree conversion error"}, + /* decoder registration */ + {"OCSD_ERR_DCDREG_NAME_REPEAT","Attempted to register a decoder with the same name as another one."}, + {"OCSD_ERR_DCDREG_NAME_UNKNOWN","Attempted to find a decoder with a name that is not known in the library."}, + /* decoder config */ + {"OCSD_ERR_DCD_INTERFACE_UNUSED","Attempt to connect or use and inteface not supported by this decoder."}, /* end marker*/ {"OCSD_ERR_LAST", "No error - error code end marker"} }; diff --git a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp index 0a31edd..349f095 100644 --- a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp +++ b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp @@ -272,6 +272,13 @@ bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, ocsd_err_t err = OCSD_OK; EtmV4Config configObj(&config);
+ + // test new infrastructure + // + err = m_pDecodeTree->createDecoder("ETMV4I", m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj); + + + if(m_bPacketProcOnly) { if(bDataChannel) @@ -283,6 +290,8 @@ bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, { err = m_pDecodeTree->createETMv4Decoder(&configObj,bDataChannel); } + + if(err == OCSD_OK) createdDecoder = true; else @@ -372,7 +381,6 @@ bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Pa LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree.")); } return createdDecoder; - }
bool CreateDcdTreeFromSnapShot::createSTDecoder(Parser::Parsed *devSrc)
Add in the enum type describing the trace protocol to decoder managers and interface. Covers ARM built in decoders, with external / none ARM covered by external tag.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/ocsd_dcd_mngr.h | 21 +++++++++++++++------ decoder/include/common/ocsd_dcd_mngr_i.h | 3 +++ decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 2 +- decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 2 +- decoder/include/ptm/trc_dcd_mngr_ptm.h | 2 +- decoder/include/stm/trc_dcd_mngr_stm.h | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/decoder/include/common/ocsd_dcd_mngr.h b/decoder/include/common/ocsd_dcd_mngr.h index 3b58e60..0e6222a 100644 --- a/decoder/include/common/ocsd_dcd_mngr.h +++ b/decoder/include/common/ocsd_dcd_mngr.h @@ -45,16 +45,18 @@ template <class P, class Pt, class Pc> class DecoderMngrBase : public IDecoderMngr { public: - DecoderMngrBase(const std::string &decoderTypeName); + DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol); virtual ~DecoderMngrBase() {};
// create decoder interface. virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component); virtual ocsd_err_t destroyDecoder(TraceComponent *p_component);
+ virtual const ocsd_trace_protocol_t getProtocolType() const { return m_builtInProtocol; } + // common virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog); - + // pkt decoder virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec); virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor); @@ -71,17 +73,20 @@ public: // implemented by decoder handler derived classes virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0; virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; }; + +private: + ocsd_trace_protocol_t m_builtInProtocol; //!< Protocol ID if built in type. };
template <class P, class Pt, class Pc> -DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName) +DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol) { OcsdLibDcdRegister *pDcdReg = OcsdLibDcdRegister::getDecoderRegister(); if(pDcdReg) pDcdReg->registerDecoderTypeByName(decoderTypeName,this); + m_builtInProtocol = builtInProtocol; }
- template <class P, class Pt, class Pc> ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createDecoder(const int create_flags, const int instID, const CSConfig *pConfig, TraceComponent **ppTrcComp) { @@ -306,7 +311,9 @@ template< class P, // Packet class. class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc> { public: - DecodeMngrFullDcd (const std::string &name) : DecoderMngrBase(name) {}; + DecodeMngrFullDcd (const std::string &name, ocsd_trace_protocol_t builtInProtocol) + : DecoderMngrBase(name,builtInProtocol) {}; + virtual ~DecodeMngrFullDcd() {};
virtual TraceComponent *createPktProc(const bool useInstID, const int instID) @@ -341,7 +348,9 @@ template< class P, // Packet class. class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc> { public: - DecodeMngrPktProc (const std::string &name) : DecoderMngrBase(name) {}; + DecodeMngrPktProc (const std::string &name, ocsd_trace_protocol_t builtInProtocol) + : DecoderMngrBase(name,builtInProtocol) {}; + virtual ~DecodeMngrPktProc() {};
virtual TraceComponent *createPktProc(const bool useInstID, const int instID) diff --git a/decoder/include/common/ocsd_dcd_mngr_i.h b/decoder/include/common/ocsd_dcd_mngr_i.h index f7a6720..3e6abe2 100644 --- a/decoder/include/common/ocsd_dcd_mngr_i.h +++ b/decoder/include/common/ocsd_dcd_mngr_i.h @@ -56,6 +56,9 @@ public: virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **ppComponent) = 0; virtual ocsd_err_t destroyDecoder(TraceComponent *pComponent) = 0;
+ //! Get the built in protocol type ID managed by this instance - extern for custom decoders + virtual const ocsd_trace_protocol_t getProtocolType() const = 0; + // connect decoders to other components - (replace current / 0 pointer value to detach ); // compatible with all decoders //!attach error logger to ptk-processor, or both of pkt processor and pkt decoder pair diff --git a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h index cbd1182..3ace535 100644 --- a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h +++ b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h @@ -47,7 +47,7 @@ class DecoderMngrEtmV3 : public DecodeMngrFullDcd< EtmV3TrcPacket, TrcPktDecodeEtmV3> { public: - DecoderMngrEtmV3(const std::string &name) : DecodeMngrFullDcd(name) {}; + DecoderMngrEtmV3(const std::string &name) : DecodeMngrFullDcd(name,OCSD_PROTOCOL_ETMV3) {}; virtual ~DecoderMngrEtmV3() {}; };
diff --git a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h index 3aef842..7c4802f 100644 --- a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h +++ b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h @@ -21,7 +21,7 @@ class DecoderMngrEtmV4I : public DecodeMngrFullDcd< EtmV4ITrcPacket, TrcPktDecodeEtmV4I> { public: - DecoderMngrEtmV4I(const std::string &name) : DecodeMngrFullDcd(name) {}; + DecoderMngrEtmV4I(const std::string &name) : DecodeMngrFullDcd(name,OCSD_PROTOCOL_ETMV4I) {}; virtual ~DecoderMngrEtmV4I() {}; };
diff --git a/decoder/include/ptm/trc_dcd_mngr_ptm.h b/decoder/include/ptm/trc_dcd_mngr_ptm.h index 27fb270..121edfd 100644 --- a/decoder/include/ptm/trc_dcd_mngr_ptm.h +++ b/decoder/include/ptm/trc_dcd_mngr_ptm.h @@ -47,7 +47,7 @@ class DecoderMngrPtm : public DecodeMngrFullDcd< PtmTrcPacket, TrcPktDecodePtm> { public: - DecoderMngrPtm(const std::string &name) : DecodeMngrFullDcd(name) {}; + DecoderMngrPtm(const std::string &name) : DecodeMngrFullDcd(name,OCSD_PROTOCOL_PTM) {}; virtual ~DecoderMngrPtm() {}; };
diff --git a/decoder/include/stm/trc_dcd_mngr_stm.h b/decoder/include/stm/trc_dcd_mngr_stm.h index 356ed72..7705d3c 100644 --- a/decoder/include/stm/trc_dcd_mngr_stm.h +++ b/decoder/include/stm/trc_dcd_mngr_stm.h @@ -45,7 +45,7 @@ class DecoderMngrStm : public DecodeMngrPktProc< StmTrcPacket, TrcPktProcStm> { public: - DecoderMngrStm(const std::string &name) : DecodeMngrPktProc(name) {}; + DecoderMngrStm(const std::string &name) : DecodeMngrPktProc(name,OCSD_PROTOCOL_STM) {}; virtual ~DecoderMngrStm() {}; };
Deprecated type specific API - createDecoderX fns in favour of createDecoder(name) fn.
Updated C-API handler code and packet lister test program to work with this change.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/ocsd_dcd_tree.h | 22 -- decoder/include/common/ocsd_dcd_tree_elem.h | 148 ++------ decoder/source/c_api/ocsd_c_api.cpp | 146 ++++++-- decoder/source/ocsd_dcd_tree.cpp | 417 +-------------------- .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 48 +-- decoder/tests/source/trc_pkt_lister.cpp | 16 +- 6 files changed, 177 insertions(+), 620 deletions(-)
diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 77b69bf..7073a5d 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -98,34 +98,12 @@ public: const uint8_t *pDataBlock, uint32_t *numBytesProcessed);
- - - /* create packet processing element only - attach to CSID in config - optionally attach the output interface - */ - ocsd_err_t createETMv3PktProcessor(EtmV3Config *p_config, IPktDataIn<EtmV3TrcPacket> *p_Iout = 0); - ocsd_err_t createETMv4IPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4ITrcPacket> *p_Iout = 0); - ocsd_err_t createETMv4DPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4DTrcPacket> *p_Iout = 0); - ocsd_err_t createPTMPktProcessor(PtmConfig *p_config, IPktDataIn<PtmTrcPacket> *p_Iout = 0); - ocsd_err_t createSTMPktProcessor(STMConfig *p_config, IPktDataIn<StmTrcPacket> *p_Iout = 0); - - /* create full decoder - packet processor + packet decoder - attach to CSID in config - All use the standard generic elements output interface. - */ - ocsd_err_t createETMv3Decoder(EtmV3Config *p_config); - ocsd_err_t createETMv4Decoder(EtmV4Config *p_config, bool bDataChannel = false); - ocsd_err_t createPTMDecoder(PtmConfig *p_config); - /*! Create a decoder by registered name */ ocsd_err_t createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig);
/* remove a decoder / packet processor attached to an ID - allows another decoder to be substituted. */ ocsd_err_t removeDecoder(const uint8_t CSID);
- /* attach custom / external decoders */ - ocsd_err_t attachExternPktProcessor(const uint8_t CSID, ITrcDataIn* ext_data_in, void *p_pkt_proc_obj); - ocsd_err_t attachExternDecoder(const uint8_t CSID, ITrcDataIn* ext_data_in, void *p_pkt_proc_obj, void *p_decoder_obj); - /* set key interfaces - attach / replace on any existing tree components? */ void setInstrDecoder(IInstrDecode *i_instr_decode); void setMemAccessI(ITargetMemAccess *i_mem_access); diff --git a/decoder/include/common/ocsd_dcd_tree_elem.h b/decoder/include/common/ocsd_dcd_tree_elem.h index 31fe011..6969816 100644 --- a/decoder/include/common/ocsd_dcd_tree_elem.h +++ b/decoder/include/common/ocsd_dcd_tree_elem.h @@ -35,6 +35,9 @@ #ifndef ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED #define ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
+#include "common/ocsd_dcd_mngr_i.h" +#include "common/trc_component.h" + /** @class decoder_elements * @brief Decode tree element base structure. * @addtogroup dcd_tree @@ -46,32 +49,9 @@ */ typedef struct _decoder_elements { - union { - struct { - TrcPktProcEtmV3 *proc; - TrcPktDecodeEtmV3 *dcd; - } etmv3; /**< ETMv3 decoders */ - struct { - TrcPktProcEtmV4I *proc; - TrcPktDecodeEtmV4I *dcd; - } etmv4i; /**< ETMv4 Decoders */ - struct { - TrcPktProcEtmV4D *proc; - void * /*TrcPktDecodeEtmV4 **/ dcd; //** TBD - } etmv4d; - struct { - TrcPktProcPtm *proc; - TrcPktDecodePtm *dcd; - } ptm; - struct { - TrcPktProcStm *proc; - void * /*TrcPktDecodeStm **/ dcd; //** TBD - } stm; - struct { - void * proc; - void * dcd; - } extern_custom; - } decoder; + std::string dcd_name; + TraceComponent *dcd_handle; + IDecoderMngr *dcd_mngr; ocsd_trace_protocol_t protocol; bool created; /**< decode tree created this element (destroy it on tree destruction) */ } decoder_element; @@ -83,113 +63,47 @@ typedef struct _decoder_elements * * */ -class DecodeTreeElement : public decoder_element +class DecodeTreeElement : protected decoder_element { public: DecodeTreeElement(); ~DecodeTreeElement() {};
- void SetProcElement(const ocsd_trace_protocol_t elem_type, void *pkt_proc, const bool created); - void SetDecoderElement(void *pkt_decode); + void SetDecoderElement(const std::string &name, IDecoderMngr *dcdMngr, TraceComponent *pHandle, bool bCreated); void DestroyElem();
- TrcPktProcEtmV3 * getEtmV3PktProc() const - { - if(protocol == OCSD_PROTOCOL_ETMV3) - return decoder.etmv3.proc; - return 0; - } - - TrcPktProcEtmV4I * getEtmV4IPktProc() const - { - if(protocol == OCSD_PROTOCOL_ETMV4I) - return decoder.etmv4i.proc; - return 0; - } - - TrcPktDecodeEtmV4I * getEtmV4IPktDecoder() const - { - if(protocol == OCSD_PROTOCOL_ETMV4I) - return decoder.etmv4i.dcd; - return 0; - } - - TrcPktProcEtmV4D * getEtmV4DPktProc() const - { - if(protocol == OCSD_PROTOCOL_ETMV4D) - return decoder.etmv4d.proc; - return 0; - } - - TrcPktProcPtm * getPtmPktProc() const - { - if(protocol == OCSD_PROTOCOL_PTM) - return decoder.ptm.proc; - return 0; - } - - TrcPktDecodePtm * getPtmPktDecoder() const - { - if(protocol == OCSD_PROTOCOL_PTM) - return decoder.ptm.dcd; - return 0; - } - - TrcPktProcStm * getStmPktProc() const - { - if(protocol == OCSD_PROTOCOL_STM) - return decoder.stm.proc; - return 0; - } - - void * getExternPktProc() const - { - if(protocol == OCSD_PROTOCOL_EXTERN) - return decoder.extern_custom.proc; - return 0; - } - - TrcPktDecodeI * getDecoderBaseI() const - { - TrcPktDecodeI *pDecoder = 0; - switch(protocol) - { - case OCSD_PROTOCOL_ETMV3: - pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.etmv3.dcd); - break; - case OCSD_PROTOCOL_ETMV4I: - pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.etmv4i.dcd); - break; - case OCSD_PROTOCOL_ETMV4D: - //pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.etmv4d.dcd); - break; - case OCSD_PROTOCOL_PTM: - pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.ptm.dcd); - break; - case OCSD_PROTOCOL_STM: - //pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.stm.dcd); - break; - case OCSD_PROTOCOL_EXTERN: - pDecoder = static_cast<TrcPktDecodeI *>(decoder.extern_custom.dcd); - break; - } - return pDecoder; - } - - + const std::string &getDecoderTypeName() { return dcd_name; }; + IDecoderMngr *getDecoderMngr() { return dcd_mngr; }; ocsd_trace_protocol_t getProtocol() const { return protocol; }; - + TraceComponent *getDecoderHandle() { return dcd_handle; }; };
inline DecodeTreeElement::DecodeTreeElement() { - // set one element in union to zero all. - decoder.extern_custom.dcd = 0; - decoder.extern_custom.proc = 0; + dcd_name = "unknown"; + dcd_mngr = 0; + dcd_handle = 0; protocol = OCSD_PROTOCOL_END; created = false; }
+inline void DecodeTreeElement::SetDecoderElement(const std::string &name, IDecoderMngr *dcdMngr, TraceComponent *pHandle, bool bCreated) +{ + dcd_name = name; + dcd_mngr = dcdMngr; + dcd_handle = pHandle; + protocol = OCSD_PROTOCOL_EXTERN; + if(dcd_mngr) + protocol = dcd_mngr->getProtocolType(); + created = bCreated; +} + +inline void DecodeTreeElement::DestroyElem() +{ + if(created && (dcd_mngr != 0) && (dcd_handle != 0)) + dcd_mngr->destroyDecoder(dcd_handle); +} + #endif // ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
/* End of File ocsd_dcd_tree_elem.h */ diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index c1d8215..d66cdb0 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -49,6 +49,10 @@ namespace std { const nothrow_t nothrow = nothrow_t(); } #endif #endif
+/*******************************************************************************/ +/* 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);
/*******************************************************************************/ /* C library data - additional data on top of the C++ library objects */ @@ -153,8 +157,17 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t han err = OCSD_ERR_MEM;
if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createETMv4IPktProcessor(&cfg,p_CBObj); - + { + 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; @@ -181,7 +194,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_decoder(const dcd_tree_handle_t hand
// no need for a spcific CB object here - standard generic elements output used. if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createETMv4Decoder(&cfg); + err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV4I,OCSD_CREATE_FLG_FULL_DECODER,&cfg); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -200,13 +213,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t hand EtmV4IPktMonCBObj *pktMonObj = new (std::nothrow) EtmV4IPktMonCBObj(pPktFn, p_context); if(pktMonObj != 0) { - pDTElem->getEtmV4IPktProc()->getRawPacketMonAttachPt()->attach(pktMonObj); + err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
- // 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); + 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; @@ -232,7 +250,17 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t hand err = OCSD_ERR_MEM;
if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createETMv3PktProcessor(&cfg,p_CBObj); + { + 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; + } + }
if(err == OCSD_OK) { @@ -259,7 +287,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_decoder(const dcd_tree_handle_t handl
// no need for a spcific CB object here - standard generic elements output used. if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createETMv3Decoder(&cfg); + err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV3,OCSD_CREATE_FLG_FULL_DECODER,&cfg); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -278,13 +306,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handl EtmV3PktMonCBObj *pktMonObj = new (std::nothrow) EtmV3PktMonCBObj(pPktFn, p_context); if(pktMonObj != 0) { - pDTElem->getEtmV3PktProc()->getRawPacketMonAttachPt()->attach(pktMonObj); + err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
- // 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); + 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; @@ -311,7 +344,17 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t handle err = OCSD_ERR_MEM;
if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createPTMPktProcessor(&cfg,p_CBObj); + { + 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; + } + }
if(err == OCSD_OK) { @@ -338,7 +381,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle,
// no need for a spcific CB object here - standard generic elements output used. if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createPTMDecoder(&cfg); + err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_PTM,OCSD_CREATE_FLG_FULL_DECODER,&cfg); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -347,7 +390,14 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle,
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); @@ -357,13 +407,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, PtmPktMonCBObj *pktMonObj = new (std::nothrow) PtmPktMonCBObj(pPktFn, p_context); if(pktMonObj != 0) { - pDTElem->getPtmPktProc()->getRawPacketMonAttachPt()->attach(pktMonObj); - - // 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); + 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; @@ -373,11 +428,11 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, } else err = OCSD_ERR_INVALID_PARAM_VAL; - return err; +#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; @@ -391,7 +446,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t handle err = OCSD_ERR_MEM;
if(err == OCSD_OK) - err = ((DecodeTree *)handle)->createSTMPktProcessor(&cfg,p_CBObj); + err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_STM,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
if(err == OCSD_OK) { @@ -684,6 +739,39 @@ 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) +{ + ocsd_err_t err = OCSD_OK; + if(handle == C_API_INVALID_TREE_HANDLE) + return OCSD_ERR_INVALID_PARAM_VAL; + + DecodeTree *pDT = static_cast<DecodeTree *>(handle); + DecodeTreeElement *pDTElem = pDT->getDecoderElement(trc_chan_id); + if((pDTElem != 0) && (pDTElem->getProtocol() == 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); + } + } + else + err = OCSD_ERR_INVALID_PARAM_VAL; // trace ID not found or not match for element protocol type. + return err; +} + +/*******************************************************************************/ /* C API Helper objects */ /*******************************************************************************/
diff --git a/decoder/source/ocsd_dcd_tree.cpp b/decoder/source/ocsd_dcd_tree.cpp index c6c0a04..cd0995b 100644 --- a/decoder/source/ocsd_dcd_tree.cpp +++ b/decoder/source/ocsd_dcd_tree.cpp @@ -37,67 +37,6 @@ #include "common/ocsd_lib_dcd_register.h" #include "mem_acc/trc_mem_acc_mapper.h"
- -void DecodeTreeElement::SetProcElement(const ocsd_trace_protocol_t protocol_type, void *pkt_proc, const bool decoder_created) -{ - created = decoder_created; - protocol = protocol_type; - - // as pointers are in a union, assume types OK and just set the extern void types. - decoder.extern_custom.proc = pkt_proc; - -} - -void DecodeTreeElement::SetDecoderElement(void *pkt_decode) -{ - decoder.extern_custom.dcd = pkt_decode; -} -// destroy the elements using correctly typed pointers to ensure destructors are called. -void DecodeTreeElement::DestroyElem() -{ - if(created) - { - switch(protocol) - { - case OCSD_PROTOCOL_ETMV3: - delete decoder.etmv3.proc; - decoder.etmv3.proc = 0; - delete decoder.etmv3.dcd; - decoder.etmv3.dcd = 0; - break; - - case OCSD_PROTOCOL_ETMV4I: - delete decoder.etmv4i.proc; - decoder.etmv4i.proc = 0; - delete decoder.etmv4i.dcd; - decoder.etmv4i.dcd = 0; - break; - - case OCSD_PROTOCOL_ETMV4D: - delete decoder.etmv4d.proc; - decoder.etmv4d.proc = 0; - //TBD: delete decoder.etmv4d.dcd; - decoder.etmv4d.dcd = 0; - break; - - case OCSD_PROTOCOL_PTM: - delete decoder.ptm.proc; - decoder.ptm.proc = 0; - delete decoder.ptm.dcd; - decoder.ptm.dcd = 0; - break; - - case OCSD_PROTOCOL_STM: - delete decoder.stm.proc; - decoder.stm.proc = 0; - // TBD: delete decoder.stm.dcd; - decoder.stm.dcd = 0; - break; - } - } -} - - /***************************************************************/ ITraceErrorLog *DecodeTree::s_i_error_logger = &DecodeTree::s_error_logger; std::list<DecodeTree *> DecodeTree::s_trace_dcd_trees; /**< list of pointers to decode tree objects */ @@ -192,16 +131,11 @@ void DecodeTree::setInstrDecoder(IInstrDecode *i_instr_decode) { uint8_t elemID; DecodeTreeElement *pElem = 0; - TrcPktDecodeI *pDecoder;
pElem = getFirstElement(elemID); while(pElem != 0) { - pDecoder = pElem->getDecoderBaseI(); - if(pDecoder) - { - pDecoder->getInstrDecodeAttachPt()->attach(i_instr_decode); - } + pElem->getDecoderMngr()->attachInstrDecoder(pElem->getDecoderHandle(),i_instr_decode); pElem = getNextElement(elemID); } } @@ -210,16 +144,11 @@ void DecodeTree::setMemAccessI(ITargetMemAccess *i_mem_access) { uint8_t elemID; DecodeTreeElement *pElem = 0; - TrcPktDecodeI *pDecoder; - + pElem = getFirstElement(elemID); while(pElem != 0) { - pDecoder = pElem->getDecoderBaseI(); - if(pDecoder) - { - pDecoder->getMemoryAccessAttachPt()->attach(i_mem_access); - } + pElem->getDecoderMngr()->attachMemAccessor(pElem->getDecoderHandle(),i_mem_access); pElem = getNextElement(elemID); } m_i_mem_access = i_mem_access; @@ -229,16 +158,11 @@ void DecodeTree::setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem) { uint8_t elemID; DecodeTreeElement *pElem = 0; - TrcPktDecodeI *pDecoder;
pElem = getFirstElement(elemID); while(pElem != 0) { - pDecoder = pElem->getDecoderBaseI(); - if(pDecoder) - { - pDecoder->getTraceElemOutAttachPt()->attach(i_gen_trace_elem); - } + pElem->getDecoderMngr()->attachOutputSink(pElem->getDecoderHandle(),i_gen_trace_elem); pElem = getNextElement(elemID); } } @@ -311,328 +235,6 @@ void DecodeTree::logMappedRanges() m_default_mapper->logMappedRanges(); }
-/* create packet processing element only - attach to CSID in config */ -ocsd_err_t DecodeTree::createETMv3PktProcessor(EtmV3Config *p_config, IPktDataIn<EtmV3TrcPacket> *p_Iout /*= 0*/) -{ - ocsd_err_t err = OCSD_OK; - - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - // see if we can attach to the desire CSID point - if((err = createDecodeElement(CSID)) == OCSD_OK) - { - - TrcPktProcEtmV3 *pProc = new (std::nothrow) TrcPktProcEtmV3(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - // set the configuration - err = pProc->setProtocolConfig(p_config); - - // attach the decoder if passed in. - if((err == OCSD_OK) && p_Iout) - err = pProc->getPacketOutAttachPt()->attach(p_Iout); - - // attach the error logger - if(err == OCSD_OK) - pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - // attach to the frame demuxer. - if(usingFormatter() && (err == OCSD_OK)) - err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc); - - if(err != OCSD_OK) - { - // unable to attach as in use - delete the processor and return. - delete pProc; - destroyDecodeElement(CSID); - } - else - { - if(!usingFormatter()) - setSingleRoot(pProc); - m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_ETMV3,pProc,true); - } - } - return err; -} - -ocsd_err_t DecodeTree::createETMv4IPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4ITrcPacket> *p_Iout/* = 0*/) -{ - ocsd_err_t err = OCSD_ERR_NOT_INIT; - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - // see if we can attach to the desired CSID point - if((err = createDecodeElement(CSID)) == OCSD_OK) - { - TrcPktProcEtmV4I *pProc = 0; - pProc = new (std::nothrow) TrcPktProcEtmV4I(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - err = pProc->setProtocolConfig(p_config); - - if((err == OCSD_OK) && p_Iout) - err = pProc->getPacketOutAttachPt()->attach(p_Iout); - - if(err == OCSD_OK) - err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - if(usingFormatter() && (err == OCSD_OK)) - err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc); - - if(err != OCSD_OK) - { - // error - delete the processor and return - delete pProc; - destroyDecodeElement(CSID); - } - else - { - // register with decode element list - if(!usingFormatter()) - setSingleRoot(pProc); - m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_ETMV4I,pProc,true); - } - } - return err; -} - -ocsd_err_t DecodeTree::createETMv4DPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4DTrcPacket> *p_Iout/* = 0*/) -{ - ocsd_err_t err = OCSD_ERR_NOT_INIT; - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - // see if we can attach to the desired CSID point - if((err = createDecodeElement(CSID)) == OCSD_OK) - { - TrcPktProcEtmV4D *pProc = 0; - err = pProc->setProtocolConfig(p_config); - - if((err == OCSD_OK) && p_Iout) - err = pProc->getPacketOutAttachPt()->attach(p_Iout); - - if(err == OCSD_OK) - err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - if(usingFormatter() && (err == OCSD_OK)) - err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc); - - if(err != OCSD_OK) - { - // error - delete the processor and return - delete pProc; - destroyDecodeElement(CSID); - } - else - { - // register with decode element list - if(!usingFormatter()) - setSingleRoot(pProc); - m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_ETMV4D,pProc,true); - } - } - return err; -} - -ocsd_err_t DecodeTree::createPTMPktProcessor(PtmConfig *p_config, IPktDataIn<PtmTrcPacket> *p_Iout /*= 0*/) -{ - ocsd_err_t err = OCSD_OK; - - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - // see if we can attach to the desire CSID point - if((err = createDecodeElement(CSID)) == OCSD_OK) - { - TrcPktProcPtm *pProc = new (std::nothrow) TrcPktProcPtm(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - // set the configuration - err = pProc->setProtocolConfig(p_config); - - // attach the decoder if passed in. - if((err == OCSD_OK) && p_Iout) - err = pProc->getPacketOutAttachPt()->attach(p_Iout); - - // attach the error logger - if(err == OCSD_OK) - pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - // attach to the frame demuxer. - if(usingFormatter() && (err == OCSD_OK)) - err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc); - - if(err != OCSD_OK) - { - // unable to attach as in use - delete the processor and return. - delete pProc; - destroyDecodeElement(CSID); - } - else - { - if(!usingFormatter()) - setSingleRoot(pProc); - m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_PTM,pProc,true); - } - } - return err; -} - -ocsd_err_t DecodeTree::createSTMPktProcessor(STMConfig *p_config, IPktDataIn<StmTrcPacket> *p_Iout/* = 0*/) -{ - ocsd_err_t err = OCSD_ERR_NOT_INIT; - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - // see if we can attach to the desired CSID point - if((err = createDecodeElement(CSID)) == OCSD_OK) - { - TrcPktProcStm *pProc = 0; - pProc = new (std::nothrow) TrcPktProcStm(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - err = pProc->setProtocolConfig(p_config); - - if((err == OCSD_OK) && p_Iout) - err = pProc->getPacketOutAttachPt()->attach(p_Iout); - - if(err == OCSD_OK) - err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - if(usingFormatter() && (err == OCSD_OK)) - err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc); - - if(err != OCSD_OK) - { - // error - delete the processor and return - delete pProc; - destroyDecodeElement(CSID); - } - else - { - // register with decode element list - if(!usingFormatter()) - setSingleRoot(pProc); - m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_STM,pProc,true); - } - } - return err; -} - -/* create full decoder - packet processor + packet decoder - attach to CSID in config */ -ocsd_err_t DecodeTree::createETMv3Decoder(EtmV3Config *p_config) -{ - ocsd_err_t err = OCSD_ERR_NOT_INIT; - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - TrcPktDecodeEtmV3 *pProc = 0; - pProc = new (std::nothrow) TrcPktDecodeEtmV3(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - err = createETMv3PktProcessor(p_config,pProc); - if(err == OCSD_OK) - { - m_decode_elements[CSID]->SetDecoderElement(pProc); - err = pProc->setProtocolConfig(p_config); - if(m_i_instr_decode && (err == OCSD_OK)) - err = pProc->getInstrDecodeAttachPt()->attach(m_i_instr_decode); - if(m_i_mem_access && (err == OCSD_OK)) - err = pProc->getMemoryAccessAttachPt()->attach(m_i_mem_access); - if( m_i_gen_elem_out && (err == OCSD_OK)) - err = pProc->getTraceElemOutAttachPt()->attach(m_i_gen_elem_out); - if(err == OCSD_OK) - err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - if(err != OCSD_OK) - destroyDecodeElement(CSID); - } - - return err; -} - -ocsd_err_t DecodeTree::createETMv4Decoder(EtmV4Config *p_config, bool bDataChannel /*= false*/) -{ - ocsd_err_t err = OCSD_ERR_NOT_INIT; - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - - if(!bDataChannel) - { - TrcPktDecodeEtmV4I *pProc = 0; - pProc = new (std::nothrow) TrcPktDecodeEtmV4I(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - err = createETMv4IPktProcessor(p_config,pProc); - if(err == OCSD_OK) - { - m_decode_elements[CSID]->SetDecoderElement(pProc); - err = pProc->setProtocolConfig(p_config); - if(m_i_instr_decode && (err == OCSD_OK)) - err = pProc->getInstrDecodeAttachPt()->attach(m_i_instr_decode); - if(m_i_mem_access && (err == OCSD_OK)) - err = pProc->getMemoryAccessAttachPt()->attach(m_i_mem_access); - if( m_i_gen_elem_out && (err == OCSD_OK)) - err = pProc->getTraceElemOutAttachPt()->attach(m_i_gen_elem_out); - if(err == OCSD_OK) - err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - if(err != OCSD_OK) - destroyDecodeElement(CSID); - } - - } - return err; -} - -ocsd_err_t DecodeTree::createPTMDecoder(PtmConfig *p_config) -{ - ocsd_err_t err = OCSD_ERR_NOT_INIT; - uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID - if(usingFormatter()) - CSID = p_config->getTraceID(); - - TrcPktDecodePtm *pProc = 0; - pProc = new (std::nothrow) TrcPktDecodePtm(CSID); - if(!pProc) - return OCSD_ERR_MEM; - - err = createPTMPktProcessor(p_config,pProc); - if(err == OCSD_OK) - { - m_decode_elements[CSID]->SetDecoderElement(pProc); - err = pProc->setProtocolConfig(p_config); - if(m_i_instr_decode && (err == OCSD_OK)) - err = pProc->getInstrDecodeAttachPt()->attach(m_i_instr_decode); - if(m_i_mem_access && (err == OCSD_OK)) - err = pProc->getMemoryAccessAttachPt()->attach(m_i_mem_access); - if( m_i_gen_elem_out && (err == OCSD_OK)) - err = pProc->getTraceElemOutAttachPt()->attach(m_i_gen_elem_out); - if(err == OCSD_OK) - err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger); - - if(err != OCSD_OK) - destroyDecodeElement(CSID); - } - return err; -} - ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig) { ocsd_err_t err = OCSD_OK; @@ -661,11 +263,10 @@ ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int c return err;
// got the decoder... - err = pDecoderMngr->createDecoder(crtFlags,(int)CSID,pConfig,&pTraceComp); + if((err = pDecoderMngr->createDecoder(crtFlags,(int)CSID,pConfig,&pTraceComp)) != OCSD_OK) + return err;
- // TBD: set decode element - // when elements accept new pointer types -> component handle and decoder manager. - // m_decode_elements[CSID]->SetDecoderElement(pTraceComp, pDecoderMngr); + m_decode_elements[CSID]->SetDecoderElement(decoderName, pDecoderMngr, pTraceComp, true);
// always attach an error logger if(err == OCSD_OK) @@ -706,13 +307,11 @@ ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int c
if(err != OCSD_OK) { - // TBD: destroyDecodeElement(CSID); // will destroy decoder as well. + destroyDecodeElement(CSID); // will destroy decoder as well. } return err; }
- - ocsd_err_t DecodeTree::removeDecoder(const uint8_t CSID) { ocsd_err_t err = OCSD_OK; diff --git a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp index 349f095..9c6c55b 100644 --- a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp +++ b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp @@ -271,31 +271,17 @@ bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, { ocsd_err_t err = OCSD_OK; EtmV4Config configObj(&config); + const char *decoderName = bDataChannel ? OCSD_BUILTIN_DCD_ETMV4D : OCSD_BUILTIN_DCD_ETMV4I;
- - // test new infrastructure - // - err = m_pDecodeTree->createDecoder("ETMV4I", m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj); - - - - if(m_bPacketProcOnly) - { - if(bDataChannel) - err = m_pDecodeTree->createETMv4DPktProcessor(&configObj); - else - err = m_pDecodeTree->createETMv4IPktProcessor(&configObj); - } - else - { - err = m_pDecodeTree->createETMv4Decoder(&configObj,bDataChannel); - } - + err = m_pDecodeTree->createDecoder(decoderName, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);
if(err == OCSD_OK) createdDecoder = true; else - LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree.")); + { + std::string msg = "Snapshot processor : failed to create " + (std::string)decoderName + " decoder on decode tree."; + LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,msg)); + } }
return createdDecoder; @@ -329,15 +315,12 @@ bool CreateDcdTreeFromSnapShot::createETMv3Decoder(const std::string &coreName, { EtmV3Config config(&cfg_regs); ocsd_err_t err = OCSD_OK; - if(m_bPacketProcOnly) - err = m_pDecodeTree->createETMv3PktProcessor(&config); - else - err = m_pDecodeTree->createETMv3Decoder(&config); + err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_ETMV3, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&config);
if(err == OCSD_OK) createdDecoder = true; else - LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree.")); + LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create ETMV3 decoder on decode tree.")); } return createdDecoder; } @@ -370,15 +353,12 @@ bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Pa { PtmConfig configObj(&config); ocsd_err_t err = OCSD_OK; - if(m_bPacketProcOnly) - err = m_pDecodeTree->createPTMPktProcessor(&configObj); - else - err = m_pDecodeTree->createPTMDecoder(&configObj); + err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_PTM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);
if(err == OCSD_OK) createdDecoder = true; else - LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree.")); + LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create PTM decoder on decode tree.")); } return createdDecoder; } @@ -408,7 +388,7 @@ bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc)
// generate the config data from the device data.
- ocsd_stm_cfg config; + ocsd_stm_cfg config;
regs_to_access_t regs_to_access[] = { { STMRegTCSR, true, &config.reg_tcsr, 0 } @@ -419,10 +399,8 @@ bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc) { ocsd_err_t err = OCSD_OK; STMConfig configObj(&config); - if(m_bPacketProcOnly) - err = m_pDecodeTree->createSTMPktProcessor(&configObj); - else - err = OCSD_ERR_TEST_SS_TO_DECODER; + + err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_STM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);
if(err == OCSD_OK) createdDecoder = true; diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index 893bc36..d5ef8be 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -471,10 +471,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon) - pElement->getEtmV4IPktProc()->getRawPacketMonAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<EtmV4ITrcPacket> *)pPrinter); else { - pElement->getEtmV4IPktProc()->getPacketOutAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<EtmV4ITrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); } @@ -494,10 +494,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon) - pElement->getEtmV3PktProc()->getRawPacketMonAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<EtmV3TrcPacket> *)pPrinter); else { - pElement->getEtmV3PktProc()->getPacketOutAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<EtmV3TrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); } @@ -516,10 +516,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon) - pElement->getPtmPktProc()->getRawPacketMonAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<PtmTrcPacket> *)pPrinter); else { - pElement->getPtmPktProc()->getPacketOutAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<PtmTrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); } @@ -539,10 +539,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon) - pElement->getStmPktProc()->getRawPacketMonAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<StmTrcPacket> *)pPrinter); else { - pElement->getStmPktProc()->getPacketOutAttachPt()->attach(pPrinter); + pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<StmTrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); }
On 1 August 2016 at 07:19, Mike Leach mike.leach@linaro.org wrote:
Deprecated type specific API - createDecoderX fns in favour of createDecoder(name) fn.
Updated C-API handler code and packet lister test program to work with this change.
Signed-off-by: Mike Leach mike.leach@linaro.org
decoder/include/common/ocsd_dcd_tree.h | 22 -- decoder/include/common/ocsd_dcd_tree_elem.h | 148 ++------ decoder/source/c_api/ocsd_c_api.cpp | 146 ++++++-- decoder/source/ocsd_dcd_tree.cpp | 417 +-------------------- .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 48 +-- decoder/tests/source/trc_pkt_lister.cpp | 16 +- 6 files changed, 177 insertions(+), 620 deletions(-)
diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 77b69bf..7073a5d 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -98,34 +98,12 @@ public: const uint8_t *pDataBlock, uint32_t *numBytesProcessed);
/* create packet processing element only - attach to CSID in config
optionally attach the output interface
*/
ocsd_err_t createETMv3PktProcessor(EtmV3Config *p_config, IPktDataIn<EtmV3TrcPacket> *p_Iout = 0);
ocsd_err_t createETMv4IPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4ITrcPacket> *p_Iout = 0);
ocsd_err_t createETMv4DPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4DTrcPacket> *p_Iout = 0);
ocsd_err_t createPTMPktProcessor(PtmConfig *p_config, IPktDataIn<PtmTrcPacket> *p_Iout = 0);
ocsd_err_t createSTMPktProcessor(STMConfig *p_config, IPktDataIn<StmTrcPacket> *p_Iout = 0);
/* create full decoder - packet processor + packet decoder - attach to CSID in config
All use the standard generic elements output interface.
*/
ocsd_err_t createETMv3Decoder(EtmV3Config *p_config);
ocsd_err_t createETMv4Decoder(EtmV4Config *p_config, bool bDataChannel = false);
ocsd_err_t createPTMDecoder(PtmConfig *p_config);
/*! Create a decoder by registered name */ ocsd_err_t createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig);
/* remove a decoder / packet processor attached to an ID - allows another decoder to be substituted. */ ocsd_err_t removeDecoder(const uint8_t CSID);
/* attach custom / external decoders */
ocsd_err_t attachExternPktProcessor(const uint8_t CSID, ITrcDataIn* ext_data_in, void *p_pkt_proc_obj);
ocsd_err_t attachExternDecoder(const uint8_t CSID, ITrcDataIn* ext_data_in, void *p_pkt_proc_obj, void *p_decoder_obj);
/* set key interfaces - attach / replace on any existing tree components? */ void setInstrDecoder(IInstrDecode *i_instr_decode); void setMemAccessI(ITargetMemAccess *i_mem_access);
diff --git a/decoder/include/common/ocsd_dcd_tree_elem.h b/decoder/include/common/ocsd_dcd_tree_elem.h index 31fe011..6969816 100644 --- a/decoder/include/common/ocsd_dcd_tree_elem.h +++ b/decoder/include/common/ocsd_dcd_tree_elem.h @@ -35,6 +35,9 @@ #ifndef ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED #define ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
+#include "common/ocsd_dcd_mngr_i.h" +#include "common/trc_component.h"
/** @class decoder_elements
- @brief Decode tree element base structure.
- @addtogroup dcd_tree
@@ -46,32 +49,9 @@ */ typedef struct _decoder_elements {
- union {
struct {
TrcPktProcEtmV3 *proc;
TrcPktDecodeEtmV3 *dcd;
} etmv3; /**< ETMv3 decoders */
struct {
TrcPktProcEtmV4I *proc;
TrcPktDecodeEtmV4I *dcd;
} etmv4i; /**< ETMv4 Decoders */
struct {
TrcPktProcEtmV4D *proc;
void * /*TrcPktDecodeEtmV4 **/ dcd; //** TBD
} etmv4d;
struct {
TrcPktProcPtm *proc;
TrcPktDecodePtm *dcd;
} ptm;
struct {
TrcPktProcStm *proc;
void * /*TrcPktDecodeStm **/ dcd; //** TBD
} stm;
struct {
void * proc;
void * dcd;
} extern_custom;
- } decoder;
- std::string dcd_name;
- TraceComponent *dcd_handle;
- IDecoderMngr *dcd_mngr; ocsd_trace_protocol_t protocol; bool created; /**< decode tree created this element (destroy it on tree destruction) */
} decoder_element; @@ -83,113 +63,47 @@ typedef struct _decoder_elements
*/ -class DecodeTreeElement : public decoder_element +class DecodeTreeElement : protected decoder_element { public: DecodeTreeElement(); ~DecodeTreeElement() {};
- void SetProcElement(const ocsd_trace_protocol_t elem_type, void *pkt_proc, const bool created);
- void SetDecoderElement(void *pkt_decode);
- void SetDecoderElement(const std::string &name, IDecoderMngr *dcdMngr, TraceComponent *pHandle, bool bCreated); void DestroyElem();
- TrcPktProcEtmV3 * getEtmV3PktProc() const
- {
if(protocol == OCSD_PROTOCOL_ETMV3)
return decoder.etmv3.proc;
return 0;
- }
- TrcPktProcEtmV4I * getEtmV4IPktProc() const
- {
if(protocol == OCSD_PROTOCOL_ETMV4I)
return decoder.etmv4i.proc;
return 0;
- }
- TrcPktDecodeEtmV4I * getEtmV4IPktDecoder() const
- {
if(protocol == OCSD_PROTOCOL_ETMV4I)
return decoder.etmv4i.dcd;
return 0;
- }
- TrcPktProcEtmV4D * getEtmV4DPktProc() const
- {
if(protocol == OCSD_PROTOCOL_ETMV4D)
return decoder.etmv4d.proc;
return 0;
- }
- TrcPktProcPtm * getPtmPktProc() const
- {
if(protocol == OCSD_PROTOCOL_PTM)
return decoder.ptm.proc;
return 0;
- }
- TrcPktDecodePtm * getPtmPktDecoder() const
- {
if(protocol == OCSD_PROTOCOL_PTM)
return decoder.ptm.dcd;
return 0;
- }
- TrcPktProcStm * getStmPktProc() const
- {
if(protocol == OCSD_PROTOCOL_STM)
return decoder.stm.proc;
return 0;
- }
- void * getExternPktProc() const
- {
if(protocol == OCSD_PROTOCOL_EXTERN)
return decoder.extern_custom.proc;
return 0;
- }
- TrcPktDecodeI * getDecoderBaseI() const
- {
TrcPktDecodeI *pDecoder = 0;
switch(protocol)
{
case OCSD_PROTOCOL_ETMV3:
pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.etmv3.dcd);
break;
case OCSD_PROTOCOL_ETMV4I:
pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.etmv4i.dcd);
break;
case OCSD_PROTOCOL_ETMV4D:
//pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.etmv4d.dcd);
break;
case OCSD_PROTOCOL_PTM:
pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.ptm.dcd);
break;
case OCSD_PROTOCOL_STM:
//pDecoder = dynamic_cast<TrcPktDecodeI *>(decoder.stm.dcd);
break;
case OCSD_PROTOCOL_EXTERN:
pDecoder = static_cast<TrcPktDecodeI *>(decoder.extern_custom.dcd);
break;
}
return pDecoder;
- }
- const std::string &getDecoderTypeName() { return dcd_name; };
- IDecoderMngr *getDecoderMngr() { return dcd_mngr; }; ocsd_trace_protocol_t getProtocol() const { return protocol; };
- TraceComponent *getDecoderHandle() { return dcd_handle; };
};
inline DecodeTreeElement::DecodeTreeElement() {
- // set one element in union to zero all.
- decoder.extern_custom.dcd = 0;
- decoder.extern_custom.proc = 0;
- dcd_name = "unknown";
- dcd_mngr = 0;
- dcd_handle = 0; protocol = OCSD_PROTOCOL_END; created = false;
}
+inline void DecodeTreeElement::SetDecoderElement(const std::string &name, IDecoderMngr *dcdMngr, TraceComponent *pHandle, bool bCreated) +{
- dcd_name = name;
- dcd_mngr = dcdMngr;
- dcd_handle = pHandle;
- protocol = OCSD_PROTOCOL_EXTERN;
- if(dcd_mngr)
protocol = dcd_mngr->getProtocolType();
- created = bCreated;
+}
+inline void DecodeTreeElement::DestroyElem() +{
- if(created && (dcd_mngr != 0) && (dcd_handle != 0))
dcd_mngr->destroyDecoder(dcd_handle);
+}
#endif // ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
/* End of File ocsd_dcd_tree_elem.h */ diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index c1d8215..d66cdb0 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -49,6 +49,10 @@ namespace std { const nothrow_t nothrow = nothrow_t(); } #endif #endif
+/*******************************************************************************/ +/* 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);
/*******************************************************************************/ /* C library data - additional data on top of the C++ library objects */ @@ -153,8 +157,17 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t han err = OCSD_ERR_MEM;
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createETMv4IPktProcessor(&cfg,p_CBObj);
{
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;
@@ -181,7 +194,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_decoder(const dcd_tree_handle_t hand
// no need for a spcific CB object here - standard generic elements output used. if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createETMv4Decoder(&cfg);
} else err = OCSD_ERR_INVALID_PARAM_VAL;err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV4I,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
@@ -200,13 +213,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t hand EtmV4IPktMonCBObj *pktMonObj = new (std::nothrow) EtmV4IPktMonCBObj(pPktFn, p_context); if(pktMonObj != 0) {
pDTElem->getEtmV4IPktProc()->getRawPacketMonAttachPt()->attach(pktMonObj);
err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
// 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);
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;
@@ -232,7 +250,17 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t hand err = OCSD_ERR_MEM;
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createETMv3PktProcessor(&cfg,p_CBObj);
{
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;
}
} if(err == OCSD_OK) {
@@ -259,7 +287,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_decoder(const dcd_tree_handle_t handl
// no need for a spcific CB object here - standard generic elements output used. if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createETMv3Decoder(&cfg);
} else err = OCSD_ERR_INVALID_PARAM_VAL;err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_ETMV3,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
@@ -278,13 +306,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handl EtmV3PktMonCBObj *pktMonObj = new (std::nothrow) EtmV3PktMonCBObj(pPktFn, p_context); if(pktMonObj != 0) {
pDTElem->getEtmV3PktProc()->getRawPacketMonAttachPt()->attach(pktMonObj);
err = pDTElem->getDecoderMngr()->attachPktMonitor(pDTElem->getDecoderHandle(),pktMonObj);
// 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);
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;
@@ -311,7 +344,17 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t handle err = OCSD_ERR_MEM;
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createPTMPktProcessor(&cfg,p_CBObj);
{
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;
}
} if(err == OCSD_OK) {
@@ -338,7 +381,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle,
// no need for a spcific CB object here - standard generic elements output used. if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createPTMDecoder(&cfg);
} else err = OCSD_ERR_INVALID_PARAM_VAL;err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_PTM,OCSD_CREATE_FLG_FULL_DECODER,&cfg);
@@ -347,7 +390,14 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_decoder(const dcd_tree_handle_t handle,
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
What is this for? Perhaps debug code you want to keep? If so I suggest adding a #define DEGUB [0,1] at the top of the file.
if(handle != C_API_INVALID_TREE_HANDLE) { DecodeTree *pDT = static_cast<DecodeTree *>(handle);
@@ -357,13 +407,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, PtmPktMonCBObj *pktMonObj = new (std::nothrow) PtmPktMonCBObj(pPktFn, p_context); if(pktMonObj != 0) {
pDTElem->getPtmPktProc()->getRawPacketMonAttachPt()->attach(pktMonObj);
// 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);
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;
@@ -373,11 +428,11 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, } else err = OCSD_ERR_INVALID_PARAM_VAL;
- return err;
+#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; @@ -391,7 +446,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t handle err = OCSD_ERR_MEM;
if(err == OCSD_OK)
err = ((DecodeTree *)handle)->createSTMPktProcessor(&cfg,p_CBObj);
err = ((DecodeTree *)handle)->createDecoder(OCSD_BUILTIN_DCD_STM,OCSD_CREATE_FLG_FULL_DECODER,&cfg); if(err == OCSD_OK) {
@@ -684,6 +739,39 @@ 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)
+{
- ocsd_err_t err = OCSD_OK;
- if(handle == C_API_INVALID_TREE_HANDLE)
return OCSD_ERR_INVALID_PARAM_VAL;
- DecodeTree *pDT = static_cast<DecodeTree *>(handle);
- DecodeTreeElement *pDTElem = pDT->getDecoderElement(trc_chan_id);
- if((pDTElem != 0) && (pDTElem->getProtocol() == 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);
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL; // trace ID not found or not match for element protocol type.
- return err;
+}
+/*******************************************************************************/ /* C API Helper objects */ /*******************************************************************************/
diff --git a/decoder/source/ocsd_dcd_tree.cpp b/decoder/source/ocsd_dcd_tree.cpp index c6c0a04..cd0995b 100644 --- a/decoder/source/ocsd_dcd_tree.cpp +++ b/decoder/source/ocsd_dcd_tree.cpp @@ -37,67 +37,6 @@ #include "common/ocsd_lib_dcd_register.h" #include "mem_acc/trc_mem_acc_mapper.h"
-void DecodeTreeElement::SetProcElement(const ocsd_trace_protocol_t protocol_type, void *pkt_proc, const bool decoder_created) -{
created = decoder_created;
protocol = protocol_type;
// as pointers are in a union, assume types OK and just set the extern void types.
decoder.extern_custom.proc = pkt_proc;
-}
-void DecodeTreeElement::SetDecoderElement(void *pkt_decode) -{
- decoder.extern_custom.dcd = pkt_decode;
-} -// destroy the elements using correctly typed pointers to ensure destructors are called. -void DecodeTreeElement::DestroyElem() -{
- if(created)
- {
switch(protocol)
{
case OCSD_PROTOCOL_ETMV3:
delete decoder.etmv3.proc;
decoder.etmv3.proc = 0;
delete decoder.etmv3.dcd;
decoder.etmv3.dcd = 0;
break;
case OCSD_PROTOCOL_ETMV4I:
delete decoder.etmv4i.proc;
decoder.etmv4i.proc = 0;
delete decoder.etmv4i.dcd;
decoder.etmv4i.dcd = 0;
break;
case OCSD_PROTOCOL_ETMV4D:
delete decoder.etmv4d.proc;
decoder.etmv4d.proc = 0;
//TBD: delete decoder.etmv4d.dcd;
decoder.etmv4d.dcd = 0;
break;
case OCSD_PROTOCOL_PTM:
delete decoder.ptm.proc;
decoder.ptm.proc = 0;
delete decoder.ptm.dcd;
decoder.ptm.dcd = 0;
break;
case OCSD_PROTOCOL_STM:
delete decoder.stm.proc;
decoder.stm.proc = 0;
// TBD: delete decoder.stm.dcd;
decoder.stm.dcd = 0;
break;
}
- }
-}
/***************************************************************/ ITraceErrorLog *DecodeTree::s_i_error_logger = &DecodeTree::s_error_logger; std::list<DecodeTree *> DecodeTree::s_trace_dcd_trees; /**< list of pointers to decode tree objects */ @@ -192,16 +131,11 @@ void DecodeTree::setInstrDecoder(IInstrDecode *i_instr_decode) { uint8_t elemID; DecodeTreeElement *pElem = 0;
TrcPktDecodeI *pDecoder;
pElem = getFirstElement(elemID); while(pElem != 0) {
pDecoder = pElem->getDecoderBaseI();
if(pDecoder)
{
pDecoder->getInstrDecodeAttachPt()->attach(i_instr_decode);
}
}pElem->getDecoderMngr()->attachInstrDecoder(pElem->getDecoderHandle(),i_instr_decode); pElem = getNextElement(elemID);
} @@ -210,16 +144,11 @@ void DecodeTree::setMemAccessI(ITargetMemAccess *i_mem_access) { uint8_t elemID; DecodeTreeElement *pElem = 0;
- TrcPktDecodeI *pDecoder;
- pElem = getFirstElement(elemID); while(pElem != 0) {
pDecoder = pElem->getDecoderBaseI();
if(pDecoder)
{
pDecoder->getMemoryAccessAttachPt()->attach(i_mem_access);
}
} m_i_mem_access = i_mem_access;pElem->getDecoderMngr()->attachMemAccessor(pElem->getDecoderHandle(),i_mem_access); pElem = getNextElement(elemID);
@@ -229,16 +158,11 @@ void DecodeTree::setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem) { uint8_t elemID; DecodeTreeElement *pElem = 0;
TrcPktDecodeI *pDecoder;
pElem = getFirstElement(elemID); while(pElem != 0) {
pDecoder = pElem->getDecoderBaseI();
if(pDecoder)
{
pDecoder->getTraceElemOutAttachPt()->attach(i_gen_trace_elem);
}
}pElem->getDecoderMngr()->attachOutputSink(pElem->getDecoderHandle(),i_gen_trace_elem); pElem = getNextElement(elemID);
} @@ -311,328 +235,6 @@ void DecodeTree::logMappedRanges() m_default_mapper->logMappedRanges(); }
-/* create packet processing element only - attach to CSID in config */ -ocsd_err_t DecodeTree::createETMv3PktProcessor(EtmV3Config *p_config, IPktDataIn<EtmV3TrcPacket> *p_Iout /*= 0*/) -{
- ocsd_err_t err = OCSD_OK;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- // see if we can attach to the desire CSID point
- if((err = createDecodeElement(CSID)) == OCSD_OK)
- {
TrcPktProcEtmV3 *pProc = new (std::nothrow) TrcPktProcEtmV3(CSID);
if(!pProc)
return OCSD_ERR_MEM;
// set the configuration
err = pProc->setProtocolConfig(p_config);
// attach the decoder if passed in.
if((err == OCSD_OK) && p_Iout)
err = pProc->getPacketOutAttachPt()->attach(p_Iout);
// attach the error logger
if(err == OCSD_OK)
pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
// attach to the frame demuxer.
if(usingFormatter() && (err == OCSD_OK))
err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc);
if(err != OCSD_OK)
{
// unable to attach as in use - delete the processor and return.
delete pProc;
destroyDecodeElement(CSID);
}
else
{
if(!usingFormatter())
setSingleRoot(pProc);
m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_ETMV3,pProc,true);
}
- }
- return err;
-}
-ocsd_err_t DecodeTree::createETMv4IPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4ITrcPacket> *p_Iout/* = 0*/) -{
- ocsd_err_t err = OCSD_ERR_NOT_INIT;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- // see if we can attach to the desired CSID point
- if((err = createDecodeElement(CSID)) == OCSD_OK)
- {
TrcPktProcEtmV4I *pProc = 0;
pProc = new (std::nothrow) TrcPktProcEtmV4I(CSID);
if(!pProc)
return OCSD_ERR_MEM;
err = pProc->setProtocolConfig(p_config);
if((err == OCSD_OK) && p_Iout)
err = pProc->getPacketOutAttachPt()->attach(p_Iout);
if(err == OCSD_OK)
err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
if(usingFormatter() && (err == OCSD_OK))
err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc);
if(err != OCSD_OK)
{
// error - delete the processor and return
delete pProc;
destroyDecodeElement(CSID);
}
else
{
// register with decode element list
if(!usingFormatter())
setSingleRoot(pProc);
m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_ETMV4I,pProc,true);
}
- }
- return err;
-}
-ocsd_err_t DecodeTree::createETMv4DPktProcessor(EtmV4Config *p_config, IPktDataIn<EtmV4DTrcPacket> *p_Iout/* = 0*/) -{
- ocsd_err_t err = OCSD_ERR_NOT_INIT;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- // see if we can attach to the desired CSID point
- if((err = createDecodeElement(CSID)) == OCSD_OK)
- {
TrcPktProcEtmV4D *pProc = 0;
err = pProc->setProtocolConfig(p_config);
if((err == OCSD_OK) && p_Iout)
err = pProc->getPacketOutAttachPt()->attach(p_Iout);
if(err == OCSD_OK)
err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
if(usingFormatter() && (err == OCSD_OK))
err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc);
if(err != OCSD_OK)
{
// error - delete the processor and return
delete pProc;
destroyDecodeElement(CSID);
}
else
{
// register with decode element list
if(!usingFormatter())
setSingleRoot(pProc);
m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_ETMV4D,pProc,true);
}
- }
- return err;
-}
-ocsd_err_t DecodeTree::createPTMPktProcessor(PtmConfig *p_config, IPktDataIn<PtmTrcPacket> *p_Iout /*= 0*/) -{
- ocsd_err_t err = OCSD_OK;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- // see if we can attach to the desire CSID point
- if((err = createDecodeElement(CSID)) == OCSD_OK)
- {
TrcPktProcPtm *pProc = new (std::nothrow) TrcPktProcPtm(CSID);
if(!pProc)
return OCSD_ERR_MEM;
// set the configuration
err = pProc->setProtocolConfig(p_config);
// attach the decoder if passed in.
if((err == OCSD_OK) && p_Iout)
err = pProc->getPacketOutAttachPt()->attach(p_Iout);
// attach the error logger
if(err == OCSD_OK)
pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
// attach to the frame demuxer.
if(usingFormatter() && (err == OCSD_OK))
err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc);
if(err != OCSD_OK)
{
// unable to attach as in use - delete the processor and return.
delete pProc;
destroyDecodeElement(CSID);
}
else
{
if(!usingFormatter())
setSingleRoot(pProc);
m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_PTM,pProc,true);
}
- }
- return err;
-}
-ocsd_err_t DecodeTree::createSTMPktProcessor(STMConfig *p_config, IPktDataIn<StmTrcPacket> *p_Iout/* = 0*/) -{
- ocsd_err_t err = OCSD_ERR_NOT_INIT;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- // see if we can attach to the desired CSID point
- if((err = createDecodeElement(CSID)) == OCSD_OK)
- {
TrcPktProcStm *pProc = 0;
pProc = new (std::nothrow) TrcPktProcStm(CSID);
if(!pProc)
return OCSD_ERR_MEM;
err = pProc->setProtocolConfig(p_config);
if((err == OCSD_OK) && p_Iout)
err = pProc->getPacketOutAttachPt()->attach(p_Iout);
if(err == OCSD_OK)
err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
if(usingFormatter() && (err == OCSD_OK))
err = m_frame_deformatter_root->getIDStreamAttachPt(p_config->getTraceID())->attach(pProc);
if(err != OCSD_OK)
{
// error - delete the processor and return
delete pProc;
destroyDecodeElement(CSID);
}
else
{
// register with decode element list
if(!usingFormatter())
setSingleRoot(pProc);
m_decode_elements[CSID]->SetProcElement(OCSD_PROTOCOL_STM,pProc,true);
}
- }
- return err;
-}
-/* create full decoder - packet processor + packet decoder - attach to CSID in config */ -ocsd_err_t DecodeTree::createETMv3Decoder(EtmV3Config *p_config) -{
- ocsd_err_t err = OCSD_ERR_NOT_INIT;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- TrcPktDecodeEtmV3 *pProc = 0;
- pProc = new (std::nothrow) TrcPktDecodeEtmV3(CSID);
- if(!pProc)
return OCSD_ERR_MEM;
- err = createETMv3PktProcessor(p_config,pProc);
- if(err == OCSD_OK)
- {
m_decode_elements[CSID]->SetDecoderElement(pProc);
err = pProc->setProtocolConfig(p_config);
if(m_i_instr_decode && (err == OCSD_OK))
err = pProc->getInstrDecodeAttachPt()->attach(m_i_instr_decode);
if(m_i_mem_access && (err == OCSD_OK))
err = pProc->getMemoryAccessAttachPt()->attach(m_i_mem_access);
if( m_i_gen_elem_out && (err == OCSD_OK))
err = pProc->getTraceElemOutAttachPt()->attach(m_i_gen_elem_out);
if(err == OCSD_OK)
err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
if(err != OCSD_OK)
destroyDecodeElement(CSID);
- }
- return err;
-}
-ocsd_err_t DecodeTree::createETMv4Decoder(EtmV4Config *p_config, bool bDataChannel /*= false*/) -{
- ocsd_err_t err = OCSD_ERR_NOT_INIT;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- if(!bDataChannel)
- {
TrcPktDecodeEtmV4I *pProc = 0;
pProc = new (std::nothrow) TrcPktDecodeEtmV4I(CSID);
if(!pProc)
return OCSD_ERR_MEM;
err = createETMv4IPktProcessor(p_config,pProc);
if(err == OCSD_OK)
{
m_decode_elements[CSID]->SetDecoderElement(pProc);
err = pProc->setProtocolConfig(p_config);
if(m_i_instr_decode && (err == OCSD_OK))
err = pProc->getInstrDecodeAttachPt()->attach(m_i_instr_decode);
if(m_i_mem_access && (err == OCSD_OK))
err = pProc->getMemoryAccessAttachPt()->attach(m_i_mem_access);
if( m_i_gen_elem_out && (err == OCSD_OK))
err = pProc->getTraceElemOutAttachPt()->attach(m_i_gen_elem_out);
if(err == OCSD_OK)
err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
if(err != OCSD_OK)
destroyDecodeElement(CSID);
}
- }
- return err;
-}
-ocsd_err_t DecodeTree::createPTMDecoder(PtmConfig *p_config) -{
- ocsd_err_t err = OCSD_ERR_NOT_INIT;
- uint8_t CSID = 0; // default for single stream decoder (no deformatter) - we ignore the ID
- if(usingFormatter())
CSID = p_config->getTraceID();
- TrcPktDecodePtm *pProc = 0;
- pProc = new (std::nothrow) TrcPktDecodePtm(CSID);
- if(!pProc)
return OCSD_ERR_MEM;
- err = createPTMPktProcessor(p_config,pProc);
- if(err == OCSD_OK)
- {
m_decode_elements[CSID]->SetDecoderElement(pProc);
err = pProc->setProtocolConfig(p_config);
if(m_i_instr_decode && (err == OCSD_OK))
err = pProc->getInstrDecodeAttachPt()->attach(m_i_instr_decode);
if(m_i_mem_access && (err == OCSD_OK))
err = pProc->getMemoryAccessAttachPt()->attach(m_i_mem_access);
if( m_i_gen_elem_out && (err == OCSD_OK))
err = pProc->getTraceElemOutAttachPt()->attach(m_i_gen_elem_out);
if(err == OCSD_OK)
err = pProc->getErrorLogAttachPt()->attach(DecodeTree::s_i_error_logger);
if(err != OCSD_OK)
destroyDecodeElement(CSID);
- }
- return err;
-}
ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig) { ocsd_err_t err = OCSD_OK; @@ -661,11 +263,10 @@ ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int c return err;
// got the decoder...
- err = pDecoderMngr->createDecoder(crtFlags,(int)CSID,pConfig,&pTraceComp);
- if((err = pDecoderMngr->createDecoder(crtFlags,(int)CSID,pConfig,&pTraceComp)) != OCSD_OK)
return err;
- // TBD: set decode element
- // when elements accept new pointer types -> component handle and decoder manager.
- // m_decode_elements[CSID]->SetDecoderElement(pTraceComp, pDecoderMngr);
m_decode_elements[CSID]->SetDecoderElement(decoderName, pDecoderMngr, pTraceComp, true);
// always attach an error logger if(err == OCSD_OK)
@@ -706,13 +307,11 @@ ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int c
if(err != OCSD_OK) {
// TBD: destroyDecodeElement(CSID); // will destroy decoder as well.
} return err;destroyDecodeElement(CSID); // will destroy decoder as well.
}
ocsd_err_t DecodeTree::removeDecoder(const uint8_t CSID) { ocsd_err_t err = OCSD_OK; diff --git a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp index 349f095..9c6c55b 100644 --- a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp +++ b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp @@ -271,31 +271,17 @@ bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, { ocsd_err_t err = OCSD_OK; EtmV4Config configObj(&config);
const char *decoderName = bDataChannel ? OCSD_BUILTIN_DCD_ETMV4D : OCSD_BUILTIN_DCD_ETMV4I;
// test new infrastructure
//
err = m_pDecodeTree->createDecoder("ETMV4I", m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);
if(m_bPacketProcOnly)
{
if(bDataChannel)
err = m_pDecodeTree->createETMv4DPktProcessor(&configObj);
else
err = m_pDecodeTree->createETMv4IPktProcessor(&configObj);
}
else
{
err = m_pDecodeTree->createETMv4Decoder(&configObj,bDataChannel);
}
err = m_pDecodeTree->createDecoder(decoderName, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj); if(err == OCSD_OK) createdDecoder = true; else
LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree."));
{
std::string msg = "Snapshot processor : failed to create " + (std::string)decoderName + " decoder on decode tree.";
LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,msg));
}
}
return createdDecoder;
@@ -329,15 +315,12 @@ bool CreateDcdTreeFromSnapShot::createETMv3Decoder(const std::string &coreName, { EtmV3Config config(&cfg_regs); ocsd_err_t err = OCSD_OK;
if(m_bPacketProcOnly)
err = m_pDecodeTree->createETMv3PktProcessor(&config);
else
err = m_pDecodeTree->createETMv3Decoder(&config);
err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_ETMV3, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&config); if(err == OCSD_OK) createdDecoder = true; else
LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree."));
} return createdDecoder;LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create ETMV3 decoder on decode tree."));
} @@ -370,15 +353,12 @@ bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Pa { PtmConfig configObj(&config); ocsd_err_t err = OCSD_OK;
if(m_bPacketProcOnly)
err = m_pDecodeTree->createPTMPktProcessor(&configObj);
else
err = m_pDecodeTree->createPTMDecoder(&configObj);
err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_PTM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj); if(err == OCSD_OK) createdDecoder = true; else
LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create decoder on decode tree."));
} return createdDecoder;LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create PTM decoder on decode tree."));
} @@ -408,7 +388,7 @@ bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc)
// generate the config data from the device data.
ocsd_stm_cfg config;
ocsd_stm_cfg config;
regs_to_access_t regs_to_access[] = { { STMRegTCSR, true, &config.reg_tcsr, 0 }
@@ -419,10 +399,8 @@ bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc) { ocsd_err_t err = OCSD_OK; STMConfig configObj(&config);
if(m_bPacketProcOnly)
err = m_pDecodeTree->createSTMPktProcessor(&configObj);
else
err = OCSD_ERR_TEST_SS_TO_DECODER;
err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_STM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj); if(err == OCSD_OK) createdDecoder = true;
diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index 893bc36..d5ef8be 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -471,10 +471,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon)
pElement->getEtmV4IPktProc()->getRawPacketMonAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<EtmV4ITrcPacket> *)pPrinter); else {
pElement->getEtmV4IPktProc()->getPacketOutAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<EtmV4ITrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); }
@@ -494,10 +494,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon)
pElement->getEtmV3PktProc()->getRawPacketMonAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<EtmV3TrcPacket> *)pPrinter); else {
pElement->getEtmV3PktProc()->getPacketOutAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<EtmV3TrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); }
@@ -516,10 +516,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon)
pElement->getPtmPktProc()->getRawPacketMonAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<PtmTrcPacket> *)pPrinter); else {
pElement->getPtmPktProc()->getPacketOutAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<PtmTrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); }
@@ -539,10 +539,10 @@ void AttachPacketPrinters( DecodeTree *dcd_tree, std::vector<ItemPrinter *> &pri { // if we are decoding then the decoder is attached to the packet output - attach the printer to the monitor point. if(decode || pkt_mon)
pElement->getStmPktProc()->getRawPacketMonAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktMonitor(pElement->getDecoderHandle(),(IPktRawDataMon<StmTrcPacket> *)pPrinter); else {
pElement->getStmPktProc()->getPacketOutAttachPt()->attach(pPrinter);
pElement->getDecoderMngr()->attachPktSink(pElement->getDecoderHandle(),(IPktDataIn<StmTrcPacket> *)pPrinter); if(test_waits) pPrinter->setTestWaits(test_waits); }
-- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight
ETMv4 Instruction packet processor had potential indexing issue if the payload control packet had continuation bytes.
Spec allows for these but no known implementation uses them.
Fix ensures that indexing into the packet for payload sections is correct. Some additional code simplification.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp | 68 +++++++++++------------ decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h | 22 +++++--- 2 files changed, 49 insertions(+), 41 deletions(-)
diff --git a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp index 8966504..0125788 100644 --- a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp +++ b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp @@ -375,67 +375,66 @@ void EtmV4IPktProcImpl::iPktASync() void EtmV4IPktProcImpl::iPktTraceInfo() { uint8_t lastByte = m_currPacketData.back(); - if(m_currPacketData.size() == 1) + if(m_currPacketData.size() == 1) // header { //clear flags - m_ctrlSect = m_infoSect = m_keySect = m_specSect = m_cyctSect = false; + m_tinfo_sections.sectFlags = 0; // mark all sections as incomplete. + m_tinfo_sections.ctrlBytes = 1; // assume only a single control section byte for now + } - else if(m_currPacketData.size() == 2) + else if(m_currPacketData.size() == 2) // first payload control byte { - // figure out which sections are absent and set to true; - m_infoSect = (bool)((lastByte & 0x1) == 0x0); - m_keySect = (bool)((lastByte & 0x2) == 0x0); - m_specSect = (bool)((lastByte & 0x4) == 0x0); - m_cyctSect = (bool)((lastByte & 0x8) == 0x0); + // figure out which sections are absent and set to true - opposite of bitfeild in byte; + m_tinfo_sections.sectFlags = (~lastByte) & TINFO_ALL_SECT;
// see if there is an extended control section, otherwise this byte is it. - m_ctrlSect = (bool)((lastByte & 0x80) == 0x0); + if((lastByte & 0x80) == 0x0) + m_tinfo_sections.sectFlags |= TINFO_CTRL; + } else { - if(!m_ctrlSect) - m_ctrlSect = (bool)((lastByte & 0x80) == 0x0); - else if(!m_infoSect) - m_infoSect = (bool)((lastByte & 0x80) == 0x0); - else if(!m_keySect) - m_keySect = (bool)((lastByte & 0x80) == 0x0); - else if(!m_specSect) - m_specSect = (bool)((lastByte & 0x80) == 0x0); - else if(!m_cyctSect) - m_cyctSect = (bool)((lastByte & 0x80) == 0x0); + if(!(m_tinfo_sections.sectFlags & TINFO_CTRL)) + { + m_tinfo_sections.sectFlags |= (lastByte & 0x80) ? 0 : TINFO_CTRL; + m_tinfo_sections.ctrlBytes++; + } + else if(!(m_tinfo_sections.sectFlags & TINFO_INFO_SECT)) + m_tinfo_sections.sectFlags |= (lastByte & 0x80) ? 0 : TINFO_INFO_SECT; + else if(!(m_tinfo_sections.sectFlags & TINFO_KEY_SECT)) + m_tinfo_sections.sectFlags |= (lastByte & 0x80) ? 0 : TINFO_KEY_SECT; + else if(!(m_tinfo_sections.sectFlags & TINFO_SPEC_SECT)) + m_tinfo_sections.sectFlags |= (lastByte & 0x80) ? 0 : TINFO_SPEC_SECT; + else if(!(m_tinfo_sections.sectFlags & TINFO_CYCT_SECT)) + m_tinfo_sections.sectFlags |= (lastByte & 0x80) ? 0 : TINFO_CYCT_SECT; }
// all sections accounted for? - if(m_ctrlSect && m_infoSect && m_keySect && m_specSect && m_cyctSect) + if(m_tinfo_sections.sectFlags == TINFO_ALL) { - unsigned idx = 2; + // index of first section is number of payload control bytes + 1 for header byte + unsigned idx = m_tinfo_sections.ctrlBytes + 1; uint32_t fieldVal = 0; - - // now need to know which sections to look for, so re-examine the flags byte... - lastByte = m_currPacketData[1]; - m_infoSect = (bool)((lastByte & 0x1) == 0x1); - m_keySect = (bool)((lastByte & 0x2) == 0x2); - m_specSect = (bool)((lastByte & 0x4) == 0x4); - m_cyctSect = (bool)((lastByte & 0x8) == 0x8); + uint8_t presSect = m_currPacketData[1] & TINFO_ALL_SECT; // first payload control byte
m_curr_packet.clearTraceInfo();
- if(m_infoSect && (idx < m_currPacketData.size())) + if((presSect & TINFO_INFO_SECT) && (idx < m_currPacketData.size())) { - m_curr_packet.setTraceInfo((uint32_t)m_currPacketData[idx]); - idx++; + idx += extractContField(m_currPacketData,idx,fieldVal); + m_curr_packet.setTraceInfo(fieldVal); } - if(m_keySect && (idx < m_currPacketData.size())) + if((presSect & TINFO_KEY_SECT) && (idx < m_currPacketData.size())) { idx += extractContField(m_currPacketData,idx,fieldVal); m_curr_packet.setTraceInfoKey(fieldVal); } - if(m_specSect && (idx < m_currPacketData.size())) + if((presSect & TINFO_SPEC_SECT) && (idx < m_currPacketData.size())) { idx += extractContField(m_currPacketData,idx,fieldVal); m_curr_packet.setTraceInfoSpec(fieldVal); } - if(m_cyctSect && (idx < m_currPacketData.size())) + if((presSect & TINFO_CYCT_SECT) && (idx < m_currPacketData.size())) { idx += extractContField(m_currPacketData,idx,fieldVal); m_curr_packet.setTraceInfoCyct(fieldVal); @@ -443,6 +442,7 @@ void EtmV4IPktProcImpl::iPktTraceInfo() m_process_state = SEND_PKT; m_first_trace_info = true; } + }
void EtmV4IPktProcImpl::iPktTimestamp() diff --git a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h index 0a0d1ca..7ccaa43 100644 --- a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h +++ b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h @@ -1,6 +1,6 @@ /* * \file trc_pkt_proc_etmv4i_impl.h - * \brief OpenCSD : + * \brief OpenCSD : Implementation of ETMv4 packet processing * * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. */ @@ -100,12 +100,20 @@ private: // current processing state data - counts and flags to determine if a packet is complete.
// TraceInfo Packet - // flags to indicate processing for these sections is complete. - bool m_ctrlSect; - bool m_infoSect; - bool m_keySect; - bool m_specSect; - bool m_cyctSect; + // flags to indicate processing progress for these sections is complete. + struct _t_info_pkt_prog { + uint8_t sectFlags; + uint8_t ctrlBytes; + } m_tinfo_sections; + + #define TINFO_INFO_SECT 0x01 + #define TINFO_KEY_SECT 0x02 + #define TINFO_SPEC_SECT 0x04 + #define TINFO_CYCT_SECT 0x08 + #define TINFO_CTRL 0x10 + #define TINFO_ALL_SECT 0x0F + #define TINFO_ALL 0x1F +
// address and context packets int m_addrBytes;
Add in function to generate config class from config structure via the decoder manager interface.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/ocsd_dcd_mngr.h | 26 ++++++++++++++++++++++++++ decoder/include/common/ocsd_dcd_mngr_i.h | 3 +++ decoder/include/common/ocsd_dcd_tree_elem.h | 7 +++---- decoder/include/common/ocsd_lib_dcd_register.h | 11 ++++++++--- decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 1 + decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 1 + decoder/include/ocsd_if_types.h | 25 +++++++++++++++++++++++-- decoder/include/opencsd.h | 3 ++- decoder/include/ptm/trc_dcd_mngr_ptm.h | 1 + decoder/include/stm/trc_dcd_mngr_stm.h | 1 + decoder/source/ocsd_lib_dcd_register.cpp | 25 +++++++++++++++++++++++++ 11 files changed, 94 insertions(+), 10 deletions(-)
diff --git a/decoder/include/common/ocsd_dcd_mngr.h b/decoder/include/common/ocsd_dcd_mngr.h index 0e6222a..487e1db 100644 --- a/decoder/include/common/ocsd_dcd_mngr.h +++ b/decoder/include/common/ocsd_dcd_mngr.h @@ -70,10 +70,15 @@ public: // data input connection interface virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
+// generate a Config object from opaque config struct pointer. + virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct); + // implemented by decoder handler derived classes virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0; virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; }; + virtual CSConfig *createConfig(const void *pDataStruct) = 0;
+ private: ocsd_trace_protocol_t m_builtInProtocol; //!< Protocol ID if built in type. }; @@ -298,6 +303,15 @@ ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, I return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i); }
+template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct) +{ + CSConfig *pConfig = createConfig(pDataStruct); + if(!pConfig) + return OCSD_ERR_MEM; + *pConfigBase = pConfig; + return OCSD_OK; +}
/****************************************************************************************************/ /* Full decoder / packet process pair, templated base for creating decoder objects */ @@ -306,6 +320,7 @@ ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, I template< class P, // Packet class. class Pt, // Packet enum type ID. class Pc, // Processor config class. + class PcSt, // Processor config struct type class PktProc, // Packet processor class. class PktDcd> // Packet decoder class. class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc> @@ -335,6 +350,11 @@ public: pComp = new (std::nothrow)PktDcd(); return pComp; } + + virtual CSConfig *createConfig(const void *pDataStruct) + { + return new (std::nothrow) Pc((PcSt *)pDataStruct); + } };
/****************************************************************************************************/ @@ -344,6 +364,7 @@ public: template< class P, // Packet class. class Pt, // Packet enum type ID. class Pc, // Processor config class. + class PcSt, // Processor config struct type class PktProc> // Packet processor class. class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc> { @@ -362,6 +383,11 @@ public: pComp = new (std::nothrow) PktProc(); return pComp; } + + virtual CSConfig *createConfig(const void *pDataStruct) + { + return new (std::nothrow) Pc((PcSt *)pDataStruct); + } };
diff --git a/decoder/include/common/ocsd_dcd_mngr_i.h b/decoder/include/common/ocsd_dcd_mngr_i.h index 3e6abe2..f6adb06 100644 --- a/decoder/include/common/ocsd_dcd_mngr_i.h +++ b/decoder/include/common/ocsd_dcd_mngr_i.h @@ -88,6 +88,9 @@ public: //! get raw data input interface from packet processor virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn) = 0;
+// create configuration from data structure + virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct) = 0; + };
#endif // ARM_OCSD_DCD_MNGR_I_H_INCLUDED diff --git a/decoder/include/common/ocsd_dcd_tree_elem.h b/decoder/include/common/ocsd_dcd_tree_elem.h index 6969816..82c2159 100644 --- a/decoder/include/common/ocsd_dcd_tree_elem.h +++ b/decoder/include/common/ocsd_dcd_tree_elem.h @@ -43,9 +43,8 @@ * @addtogroup dcd_tree * * Element describes the protocol supported for this element and - * contains pointers to packet processor and decoder for the protocol. - * - * Union of all recognised decoders, plus an attachment point for an external decoder. + * contains pointers to the decoder manager interface and component handle. + * */ typedef struct _decoder_elements { @@ -92,7 +91,7 @@ inline void DecodeTreeElement::SetDecoderElement(const std::string &name, IDecod dcd_name = name; dcd_mngr = dcdMngr; dcd_handle = pHandle; - protocol = OCSD_PROTOCOL_EXTERN; + protocol = OCSD_PROTOCOL_UNKNOWN; if(dcd_mngr) protocol = dcd_mngr->getProtocolType(); created = bCreated; diff --git a/decoder/include/common/ocsd_lib_dcd_register.h b/decoder/include/common/ocsd_lib_dcd_register.h index dc5fd42..d059214 100644 --- a/decoder/include/common/ocsd_lib_dcd_register.h +++ b/decoder/include/common/ocsd_lib_dcd_register.h @@ -60,17 +60,22 @@ public:
const ocsd_err_t registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact); //!< register a decoder manager interface const ocsd_err_t getDecoderMngrByName(const std::string &name, IDecoderMngr **p_decoder_mngr); + const ocsd_err_t getDecoderMngrByType(const ocsd_trace_protocol_t decoderType, IDecoderMngr **p_decoder_mngr);
const bool isRegisteredDecoder(const std::string &name); const bool getFirstNamedDecoder(std::string &name); const bool getNextNamedDecoder(std::string &name);
+ const bool isRegisteredDecoderType(const ocsd_trace_protocol_t decoderType); + private: void registerBuiltInDecoders(); //!< register the list of build in decoder managers on first access of getDecoderMngrByName.
- std::map<const std::string, IDecoderMngr *> m_decoder_mngrs; //!< map linking names to decoder manager interfaces. - std::map<const std::string, IDecoderMngr *>::const_iterator m_iter; //!< iterator for name search. - + std::map<const std::string, IDecoderMngr *> m_decoder_mngrs; //!< map linking names to decoder manager interfaces. + std::map<const std::string, IDecoderMngr *>::const_iterator m_iter; //!< iterator for name search. + + std::map<const ocsd_trace_protocol_t, IDecoderMngr *> m_typed_decoder_mngrs; //!< map linking decoder managers to protocol type ID + // singleton pattern - need just one of these in the library - ensure all default constructors are private. OcsdLibDcdRegister(); OcsdLibDcdRegister(OcsdLibDcdRegister const &) {}; diff --git a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h index 3ace535..c3a96ff 100644 --- a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h +++ b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h @@ -43,6 +43,7 @@ class DecoderMngrEtmV3 : public DecodeMngrFullDcd< EtmV3TrcPacket, ocsd_etmv3_pkt_type, EtmV3Config, + ocsd_etmv3_cfg, TrcPktProcEtmV3, TrcPktDecodeEtmV3> { diff --git a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h index 7c4802f..a5b2540 100644 --- a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h +++ b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h @@ -17,6 +17,7 @@ class DecoderMngrEtmV4I : public DecodeMngrFullDcd< EtmV4ITrcPacket, ocsd_etmv4_i_pkt_type, EtmV4Config, + ocsd_etmv4_cfg, TrcPktProcEtmV4I, TrcPktDecodeEtmV4I> { diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index d214f76..7e17f04 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -489,16 +489,37 @@ typedef uint32_t (* Fn_MemAcc_CB)(const void *p_context, const ocsd_vaddr_t add /*! Trace Protocol Builtin Types + extern */ typedef enum _ocsd_trace_protocol_t { - OCSD_PROTOCOL_EXTERN, /**< Custom external decoder attached to the decode tree - protocol unknown */ + OCSD_PROTOCOL_UNKNOWN = 0, /**< Protocol unknown */ + +/* Built in library decoders */ OCSD_PROTOCOL_ETMV3, /**< ETMV3 instruction and data trace protocol decoder. */ OCSD_PROTOCOL_ETMV4I, /**< ETMV4 instruction trace protocol decoder. */ OCSD_PROTOCOL_ETMV4D, /**< ETMV4 data trace protocol decoder. */ OCSD_PROTOCOL_PTM, /**< PTM program flow instruction trace protocol decoder. */ OCSD_PROTOCOL_STM, /**< STM system trace protocol decoder. */ - /* others to be added here */ + +/* others to be added here */ + OCSD_PROTOCOL_BUILTIN_END, /**< Invalid protocol - built-in protocol types end marker */ + +/* Custom / external decoders */ + OCSD_PROTOCOL_CUSTOM_0 = 100, + OCSD_PROTOCOL_CUSTOM_1, + OCSD_PROTOCOL_CUSTOM_2, + OCSD_PROTOCOL_CUSTOM_3, + OCSD_PROTOCOL_CUSTOM_4, + OCSD_PROTOCOL_CUSTOM_5, + OCSD_PROTOCOL_CUSTOM_6, + OCSD_PROTOCOL_CUSTOM_7, + OCSD_PROTOCOL_CUSTOM_8, + OCSD_PROTOCOL_CUSTOM_9, + OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ } ocsd_trace_protocol_t;
+#define OCSD_PROTOCOL_IS_BUILTIN(P) ((P > OCSD_PROTOCOL_UNKNOWN) && (P < OCSD_PROTOCOL_BUILTIN_END)) +#define OCSD_PROTOCOL_IS_CUSTOM(P) ((P > OCSD_PROTOCOL_CUSTOM_0) && (P < OCSD_PROTOCOL_END )) + + /** @}*/
/** @}*/ diff --git a/decoder/include/opencsd.h b/decoder/include/opencsd.h index fed2eaf..9ae283b 100644 --- a/decoder/include/opencsd.h +++ b/decoder/include/opencsd.h @@ -73,7 +73,8 @@ #include "i_dec/trc_i_decode.h" #include "mem_acc/trc_mem_acc.h"
-/** The decode tree */ +/** The decode tree and decoder register*/ +#include "common/ocsd_lib_dcd_register.h" #include "common/ocsd_dcd_tree.h"
diff --git a/decoder/include/ptm/trc_dcd_mngr_ptm.h b/decoder/include/ptm/trc_dcd_mngr_ptm.h index 121edfd..0defb0d 100644 --- a/decoder/include/ptm/trc_dcd_mngr_ptm.h +++ b/decoder/include/ptm/trc_dcd_mngr_ptm.h @@ -43,6 +43,7 @@ class DecoderMngrPtm : public DecodeMngrFullDcd< PtmTrcPacket, ocsd_ptm_pkt_type, PtmConfig, + ocsd_ptm_cfg, TrcPktProcPtm, TrcPktDecodePtm> { diff --git a/decoder/include/stm/trc_dcd_mngr_stm.h b/decoder/include/stm/trc_dcd_mngr_stm.h index 7705d3c..740925d 100644 --- a/decoder/include/stm/trc_dcd_mngr_stm.h +++ b/decoder/include/stm/trc_dcd_mngr_stm.h @@ -42,6 +42,7 @@ class DecoderMngrStm : public DecodeMngrPktProc< StmTrcPacket, ocsd_stm_pkt_type, STMConfig, + ocsd_stm_cfg, TrcPktProcStm> { public: diff --git a/decoder/source/ocsd_lib_dcd_register.cpp b/decoder/source/ocsd_lib_dcd_register.cpp index 053f256..ff1cc0f 100644 --- a/decoder/source/ocsd_lib_dcd_register.cpp +++ b/decoder/source/ocsd_lib_dcd_register.cpp @@ -70,6 +70,7 @@ OcsdLibDcdRegister::OcsdLibDcdRegister() OcsdLibDcdRegister::~OcsdLibDcdRegister() { m_decoder_mngrs.clear(); + m_typed_decoder_mngrs.clear(); }
@@ -78,6 +79,7 @@ const ocsd_err_t OcsdLibDcdRegister::registerDecoderTypeByName(const std::string if(isRegisteredDecoder(name)) return OCSD_ERR_DCDREG_NAME_REPEAT; m_decoder_mngrs.emplace(std::pair<const std::string, IDecoderMngr *>(name,p_decoder_fact)); + m_typed_decoder_mngrs.emplace(std::pair<const ocsd_trace_protocol_t, IDecoderMngr *>(p_decoder_fact->getProtocolType(),p_decoder_fact)); return OCSD_OK; }
@@ -121,6 +123,21 @@ const ocsd_err_t OcsdLibDcdRegister::getDecoderMngrByName(const std::string &nam return OCSD_OK; }
+const ocsd_err_t OcsdLibDcdRegister::getDecoderMngrByType(const ocsd_trace_protocol_t decoderType, IDecoderMngr **p_decoder_mngr) +{ + if(!m_b_registeredBuiltins) + { + registerBuiltInDecoders(); + if(!m_b_registeredBuiltins) + return OCSD_ERR_MEM; + } + std::map<const ocsd_trace_protocol_t, IDecoderMngr *>::const_iterator iter = m_typed_decoder_mngrs.find(decoderType); + if(iter != m_typed_decoder_mngrs.end()) + return OCSD_ERR_DCDREG_NAME_UNKNOWN; + *p_decoder_mngr = iter->second; + return OCSD_OK; +} + const bool OcsdLibDcdRegister::isRegisteredDecoder(const std::string &name) { std::map<const std::string, IDecoderMngr *>::const_iterator iter = m_decoder_mngrs.find(name); @@ -129,6 +146,14 @@ const bool OcsdLibDcdRegister::isRegisteredDecoder(const std::string &name) return false; }
+const bool OcsdLibDcdRegister::isRegisteredDecoderType(const ocsd_trace_protocol_t decoderType) +{ + std::map<const ocsd_trace_protocol_t, IDecoderMngr *>::const_iterator iter = m_typed_decoder_mngrs.find(decoderType); + if(iter != m_typed_decoder_mngrs.end()) + return true; + return false; +} + const bool OcsdLibDcdRegister::getFirstNamedDecoder(std::string &name) { m_iter = m_decoder_mngrs.begin();
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}" 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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_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 - err = OCSD_ERR_INVALID_PARAM_VAL; return err; }
+/*** 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 + /****************** 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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* 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 + /************************************************************************/ /*** 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: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * 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; + +/* 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; + 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; + + /* 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; + 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; + 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 + */ + 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); + + + /* 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"
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
Memory accessor API on decode tree was different to simpler API on C API. Decode tree API re-worked to make the two more consistent.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/c_api/ocsd_c_api_deprc_fn.h | 4 + decoder/include/c_api/ocsd_c_api_types.h | 10 +- decoder/include/c_api/opencsd_c_api.h | 2 +- decoder/include/common/ocsd_dcd_tree.h | 16 +- decoder/include/ocsd_if_types.h | 8 + decoder/source/c_api/ocsd_c_api.cpp | 163 ++++----------------- decoder/source/ocsd_dcd_tree.cpp | 151 ++++++++++++++++--- .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 13 +- decoder/tests/source/c_api_pkt_print_test.c | 2 +- 9 files changed, 191 insertions(+), 178 deletions(-)
diff --git a/decoder/include/c_api/ocsd_c_api_deprc_fn.h b/decoder/include/c_api/ocsd_c_api_deprc_fn.h index 70986ff..7c74987 100644 --- a/decoder/include/c_api/ocsd_c_api_deprc_fn.h +++ b/decoder/include/c_api/ocsd_c_api_deprc_fn.h @@ -168,6 +168,10 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, */ 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);
+ + +/** deprecated memory region type for adding multi-region binary files to memory access interface */ +typedef ocsd_file_mem_region_t file_mem_region_t; /** @}*/
#endif // ARM_OCSD_C_API_DEPRC_FN_H_INCLUDED diff --git a/decoder/include/c_api/ocsd_c_api_types.h b/decoder/include/c_api/ocsd_c_api_types.h index 1e98255..aa11391 100644 --- a/decoder/include/c_api/ocsd_c_api_types.h +++ b/decoder/include/c_api/ocsd_c_api_types.h @@ -135,20 +135,12 @@ typedef void (* FnStmPktMonDataIn)( const void *p_context, const uint32_t size, const uint8_t *p_data);
- -/** memory region type for adding multi-region binary files to memory access interface */ -typedef struct _file_mem_region { - size_t file_offset; /**< Offset from start of file for memory region */ - ocsd_vaddr_t start_address; /**< Start address of memory region */ - size_t region_size; /**< size in bytes of memory region */ -} file_mem_region_t; - +/** Callback interface type when attaching monitor/sink to packet processor */ 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 7c0648a..061bfe4 100644 --- a/decoder/include/c_api/opencsd_c_api.h +++ b/decoder/include/c_api/opencsd_c_api.h @@ -252,7 +252,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_mem_acc(const dcd_tree_handle_t handle * * @return ocsd_err_t : Library error code - RCDTL_OK if successful. */ -OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath); +OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath);
/*! * Add a memory buffer based memory range accessor to the decode tree. diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 7073a5d..0461eef 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -109,14 +109,19 @@ public: void setMemAccessI(ITargetMemAccess *i_mem_access); void setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem);
- /* create mapper within the decode tree. */ + /* create mapper within the decode tree - also allows direct manipulation of the mapper object to set up custom arrangements of accessors. */ ocsd_err_t createMemAccMapper(memacc_mapper_t type = MEMACC_MAP_GLOBAL); - ocsd_err_t addMemAccessorToMap(TrcMemAccessorBase *p_accessor, const uint8_t cs_trace_id); - ocsd_err_t removeMemAccessor(TrcMemAccessorBase *p_accessor); - ocsd_err_t removeMemAccessorByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id); + TrcMemAccMapper *getMemAccMapper() const { return m_default_mapper; }; + void setExternMemAccMapper(TrcMemAccMapper * pMapper); const bool hasMemAccMapper() const { return (bool)(m_default_mapper != 0); }; void logMappedRanges();
+ /* create and destroy accessor types - all using global CSID value - on default accessor */ + ocsd_err_t addBufferMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length); + ocsd_err_t addBinFileMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const std::string &filepath); + ocsd_err_t addBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath); + ocsd_err_t addCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context); + ocsd_err_t removeMemAccByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space);
/* get decoder elements currently in use */ DecodeTreeElement *getDecoderElement(const uint8_t CSID) const; @@ -153,7 +158,8 @@ private:
uint8_t m_decode_elem_iter;
- TrcMemAccMapper *m_default_mapper; + TrcMemAccMapper *m_default_mapper; //!< the mem acc mapper to use + bool m_created_mapper; //!< true if created by decode tree object
/* global error logger - all sources */ static ITraceErrorLog *s_i_error_logger; diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index 7e17f04..f5d1fde 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -435,6 +435,14 @@ typedef enum _ocsd_mem_space_acc_t { */ typedef uint32_t (* Fn_MemAcc_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);
+ +/** memory region type for adding multi-region binary files to memory access interface */ +typedef struct _ocsd_file_mem_region { + size_t file_offset; /**< Offset from start of file for memory region */ + ocsd_vaddr_t start_address; /**< Start address of memory region */ + size_t region_size; /**< size in bytes of memory region */ +} ocsd_file_mem_region_t; + /** @}*/
/** @name Packet Processor Operation Control Flags diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index 1e327ae..335bbe5 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -55,6 +55,7 @@ namespace std { const nothrow_t nothrow = nothrow_t(); }
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 ); +static ocsd_err_t ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle, DecodeTree **ppDT);
/*******************************************************************************/ /* C library data - additional data on top of the C++ library objects */ @@ -332,156 +333,45 @@ OCSD_C_API ocsd_err_t ocsd_gen_elem_str(const ocsd_generic_trace_elem *p_pkt, ch }
-/*** Decode tree -- memeory accessor control */ +/*** Decode tree -- memory 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; - - if(handle != C_API_INVALID_TREE_HANDLE) - { - DecodeTree *pDT = static_cast<DecodeTree *>(handle); - if(!pDT->hasMemAccMapper()) - err = pDT->createMemAccMapper(); - - if(err == OCSD_OK) - { - TrcMemAccessorBase *p_accessor; - std::string pathToFile = filepath; - err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,pathToFile,address); - if(err == OCSD_OK) - { - TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor); - if(pAcc) - { - pAcc->setMemSpace(mem_space); - err = pDT->addMemAccessorToMap(pAcc,0); - } - else - err = OCSD_ERR_MEM; // wrong type of object - treat as mem error - - if(err != OCSD_OK) - TrcMemAccFactory::DestroyAccessor(p_accessor); - } - } - } - else - err = OCSD_ERR_INVALID_PARAM_VAL; + DecodeTree *pDT; + err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT); + if(err == OCSD_OK) + err = pDT->addBinFileMemAcc(address,mem_space,filepath); return err; }
-OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath) +OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath) { ocsd_err_t err = OCSD_OK; - - if((handle != C_API_INVALID_TREE_HANDLE) && (region_array != 0) && (num_regions != 0)) - { - DecodeTree *pDT = static_cast<DecodeTree *>(handle); - if(!pDT->hasMemAccMapper()) - err = pDT->createMemAccMapper(); - - if(err == OCSD_OK) - { - TrcMemAccessorBase *p_accessor; - std::string pathToFile = filepath; - int curr_region_idx = 0; - err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,pathToFile,region_array[curr_region_idx].start_address,region_array[curr_region_idx].file_offset, region_array[curr_region_idx].region_size); - if(err == OCSD_OK) - { - TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor); - if(pAcc) - { - curr_region_idx++; - while(curr_region_idx < num_regions) - { - pAcc->AddOffsetRange(region_array[curr_region_idx].start_address, - region_array[curr_region_idx].region_size, - region_array[curr_region_idx].file_offset); - curr_region_idx++; - } - pAcc->setMemSpace(mem_space); - err = pDT->addMemAccessorToMap(pAcc,0); - } - else - err = OCSD_ERR_MEM; // wrong type of object - treat as mem error - - if(err != OCSD_OK) - TrcMemAccFactory::DestroyAccessor(p_accessor); - } - } - } - else - err = OCSD_ERR_INVALID_PARAM_VAL; + DecodeTree *pDT; + err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT); + if(err == OCSD_OK) + err = pDT->addBinFileRegionMemAcc(region_array,num_regions,mem_space,filepath); return err; }
OCSD_C_API ocsd_err_t ocsd_dt_add_buffer_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length) { ocsd_err_t err = OCSD_OK; - - if(handle != C_API_INVALID_TREE_HANDLE) - { - DecodeTree *pDT = static_cast<DecodeTree *>(handle); - if(!pDT->hasMemAccMapper()) - err = pDT->createMemAccMapper(); - - if(err == OCSD_OK) - { - TrcMemAccessorBase *p_accessor; - err = TrcMemAccFactory::CreateBufferAccessor(&p_accessor, address, p_mem_buffer, mem_length); - if(err == OCSD_OK) - { - TrcMemAccBufPtr *pMBuffAcc = dynamic_cast<TrcMemAccBufPtr *>(p_accessor); - if(pMBuffAcc) - { - pMBuffAcc->setMemSpace(mem_space); - err = pDT->addMemAccessorToMap(p_accessor,0); - } - else - err = OCSD_ERR_MEM; // wrong type of object - treat as mem error - - if(err != OCSD_OK) - TrcMemAccFactory::DestroyAccessor(p_accessor); - } - } - } - else - err = OCSD_ERR_INVALID_PARAM_VAL; + DecodeTree *pDT; + err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT); + if(err == OCSD_OK) + err = pDT->addBufferMemAcc(address,mem_space,p_mem_buffer,mem_length); return err; }
OCSD_C_API ocsd_err_t ocsd_dt_add_callback_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context) { ocsd_err_t err = OCSD_OK; - - if(handle != C_API_INVALID_TREE_HANDLE) - { - DecodeTree *pDT = static_cast<DecodeTree *>(handle); - if(!pDT->hasMemAccMapper()) - err = pDT->createMemAccMapper(); - - if(err == OCSD_OK) - { - TrcMemAccessorBase *p_accessor; - err = TrcMemAccFactory::CreateCBAccessor(&p_accessor, st_address, en_address, mem_space); - if(err == OCSD_OK) - { - TrcMemAccCB *pCBAcc = dynamic_cast<TrcMemAccCB *>(p_accessor); - if(pCBAcc) - { - pCBAcc->setCBIfFn(p_cb_func, p_context); - err = pDT->addMemAccessorToMap(p_accessor,0); - } - else - err = OCSD_ERR_MEM; // wrong type of object - treat as mem error - - if(err != OCSD_OK) - TrcMemAccFactory::DestroyAccessor(p_accessor); - } - } - } - else - err = OCSD_ERR_INVALID_PARAM_VAL; + DecodeTree *pDT; + err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT); + if(err == OCSD_OK) + err = pDT->addCallbackMemAcc(st_address,en_address,mem_space,p_cb_func,p_context); return err; }
@@ -492,10 +382,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_remove_mem_acc(const dcd_tree_handle_t handle, con if(handle != C_API_INVALID_TREE_HANDLE) { DecodeTree *pDT = static_cast<DecodeTree *>(handle); - if(!pDT->hasMemAccMapper()) - err = OCSD_ERR_INVALID_PARAM_VAL; /* no mapper, no remove*/ - else - err = pDT->removeMemAccessorByAddress(st_address,mem_space,0); + err = pDT->removeMemAccByAddress(st_address,mem_space); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -582,6 +469,16 @@ static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPk return err; }
+static ocsd_err_t ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle, DecodeTree **ppDT) +{ + *ppDT = 0; + if(handle == C_API_INVALID_TREE_HANDLE) + return OCSD_ERR_INVALID_PARAM_VAL; + *ppDT = static_cast<DecodeTree *>(handle); + if(!(*ppDT)->hasMemAccMapper()) + return (*ppDT)->createMemAccMapper(); + return OCSD_OK; +}
/*******************************************************************************/ /* C API Helper objects */ diff --git a/decoder/source/ocsd_dcd_tree.cpp b/decoder/source/ocsd_dcd_tree.cpp index cd0995b..b6451d0 100644 --- a/decoder/source/ocsd_dcd_tree.cpp +++ b/decoder/source/ocsd_dcd_tree.cpp @@ -96,8 +96,8 @@ DecodeTree::DecodeTree() : m_i_decoder_root(0), m_frame_deformatter_root(0), m_decode_elem_iter(0), - m_default_mapper(0) - + m_default_mapper(0), + m_created_mapper(false) { for(int i = 0; i < 0x80; i++) m_decode_elements[i] = 0; @@ -167,7 +167,7 @@ void DecodeTree::setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem) } }
-ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type) +ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type /* = MEMACC_MAP_GLOBAL*/ ) { // clean up any old one destroyMemAccMapper(); @@ -184,6 +184,7 @@ ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type) // set the access interface if(m_default_mapper) { + m_created_mapper = true; setMemAccessI(m_default_mapper); m_default_mapper->setErrorLog(s_i_error_logger); } @@ -191,48 +192,160 @@ ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type) return (m_default_mapper != 0) ? OCSD_OK : OCSD_ERR_MEM; }
-ocsd_err_t DecodeTree::addMemAccessorToMap(TrcMemAccessorBase *p_accessor, const uint8_t cs_trace_id) +void DecodeTree::setExternMemAccMapper(TrcMemAccMapper* pMapper) { - ocsd_err_t err= OCSD_ERR_NOT_INIT; - if(m_default_mapper) - err = m_default_mapper->AddAccessor(p_accessor,cs_trace_id); - return err; + destroyMemAccMapper(); // destroy any existing mapper - if decode tree created it. + m_default_mapper = pMapper; }
void DecodeTree::destroyMemAccMapper() { - if(m_default_mapper) + if(m_default_mapper && m_created_mapper) { m_default_mapper->RemoveAllAccessors(); delete m_default_mapper; m_default_mapper = 0; + m_created_mapper = false; } }
-ocsd_err_t DecodeTree::removeMemAccessor(TrcMemAccessorBase *p_accessor) +void DecodeTree::logMappedRanges() { - ocsd_err_t err= OCSD_ERR_NOT_INIT; if(m_default_mapper) + m_default_mapper->logMappedRanges(); +} + +/* Memory accessor creation - all on default mem accessor using the 0 CSID for global core space. */ +ocsd_err_t DecodeTree::addBufferMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length) +{ + if(!hasMemAccMapper()) + return OCSD_ERR_NOT_INIT; + + // need a valid memory buffer, and a least enough bytes for one opcode. + if((p_mem_buffer == 0) || (mem_length < 4)) + return OCSD_ERR_INVALID_PARAM_VAL; + + TrcMemAccessorBase *p_accessor; + ocsd_err_t err = TrcMemAccFactory::CreateBufferAccessor(&p_accessor, address, p_mem_buffer, mem_length); + if(err == OCSD_OK) { - err = m_default_mapper->RemoveAccessor(p_accessor); + TrcMemAccBufPtr *pMBuffAcc = dynamic_cast<TrcMemAccBufPtr *>(p_accessor); + if(pMBuffAcc) + { + pMBuffAcc->setMemSpace(mem_space); + err = m_default_mapper->AddAccessor(p_accessor,0); + } + else + err = OCSD_ERR_MEM; // wrong type of object - treat as mem error + + if(err != OCSD_OK) + TrcMemAccFactory::DestroyAccessor(p_accessor); } return err; }
-ocsd_err_t DecodeTree::removeMemAccessorByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id) +ocsd_err_t DecodeTree::addBinFileMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const std::string &filepath) { - ocsd_err_t err= OCSD_ERR_NOT_INIT; - if(m_default_mapper) + if(!hasMemAccMapper()) + return OCSD_ERR_NOT_INIT; + + if(filepath.length() == 0) + return OCSD_ERR_INVALID_PARAM_VAL; + + TrcMemAccessorBase *p_accessor; + ocsd_err_t err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,filepath,address); + + if(err == OCSD_OK) { - err = m_default_mapper->RemoveAccessorByAddress(address,mem_space,cs_trace_id); + TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor); + if(pAcc) + { + pAcc->setMemSpace(mem_space); + err = m_default_mapper->AddAccessor(pAcc,0); + } + else + err = OCSD_ERR_MEM; // wrong type of object - treat as mem error + + if(err != OCSD_OK) + TrcMemAccFactory::DestroyAccessor(p_accessor); } return err; + }
-void DecodeTree::logMappedRanges() +ocsd_err_t DecodeTree::addBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath) { - if(m_default_mapper) - m_default_mapper->logMappedRanges(); + if(!hasMemAccMapper()) + return OCSD_ERR_NOT_INIT; + + if((region_array == 0) || (num_regions == 0) || (filepath.length() == 0)) + return OCSD_ERR_INVALID_PARAM_VAL; + + TrcMemAccessorBase *p_accessor; + int curr_region_idx = 0; + + // add first region during the creation of the file accessor. + ocsd_err_t err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,filepath,region_array[curr_region_idx].start_address,region_array[curr_region_idx].file_offset, region_array[curr_region_idx].region_size); + if(err == OCSD_OK) + { + TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor); + if(pAcc) + { + // add additional regions to the file accessor. + curr_region_idx++; + while(curr_region_idx < num_regions) + { + pAcc->AddOffsetRange(region_array[curr_region_idx].start_address, + region_array[curr_region_idx].region_size, + region_array[curr_region_idx].file_offset); + curr_region_idx++; + } + pAcc->setMemSpace(mem_space); + + // add the accessor to the map. + err = m_default_mapper->AddAccessor(pAcc,0); + } + else + err = OCSD_ERR_MEM; // wrong type of object - treat as mem error + + if(err != OCSD_OK) + TrcMemAccFactory::DestroyAccessor(p_accessor); + } + return err; +} + +ocsd_err_t DecodeTree::addCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context) +{ + if(!hasMemAccMapper()) + return OCSD_ERR_NOT_INIT; + + if(p_cb_func == 0) + return OCSD_ERR_INVALID_PARAM_VAL; + + TrcMemAccessorBase *p_accessor; + ocsd_err_t err = TrcMemAccFactory::CreateCBAccessor(&p_accessor, st_address, en_address, mem_space); + if(err == OCSD_OK) + { + TrcMemAccCB *pCBAcc = dynamic_cast<TrcMemAccCB *>(p_accessor); + if(pCBAcc) + { + pCBAcc->setCBIfFn(p_cb_func, p_context); + err = m_default_mapper->AddAccessor(p_accessor,0); + } + else + err = OCSD_ERR_MEM; // wrong type of object - treat as mem error + + if(err != OCSD_OK) + TrcMemAccFactory::DestroyAccessor(p_accessor); + } + return err; +} + +ocsd_err_t DecodeTree::removeMemAccByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space) +{ + if(!hasMemAccMapper()) + return OCSD_ERR_NOT_INIT; + return m_default_mapper->RemoveAccessorByAddress(address,mem_space,0); }
ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig) diff --git a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp index 9c6c55b..00e1173 100644 --- a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp +++ b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp @@ -509,16 +509,9 @@ void CreateDcdTreeFromSnapShot::processDumpfiles(std::vectorParser::DumpDef &d dumpFilePathName = m_pReader->getSnapShotDir() + it->path; if(!TrcMemAccessorFile::isExistingFileAccessor(dumpFilePathName)) { - TrcMemAccessorBase *p_acc; - // not already a file accessor on this tree (n.b. assume only one tree in use) - ocsd_err_t err = TrcMemAccFactory::CreateFileAccessor(&p_acc, dumpFilePathName,it->address); - - if(err == OCSD_OK) - { - err = m_pDecodeTree->addMemAccessorToMap(p_acc,0); - } - else - { + ocsd_err_t err = m_pDecodeTree->addBinFileMemAcc(it->address,OCSD_MEM_SPACE_ANY,dumpFilePathName); + if(err != OCSD_OK) + { std::ostringstream oss; oss << "Failed to create memory accessor for file " << dumpFilePathName << "."; LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,oss.str())); diff --git a/decoder/tests/source/c_api_pkt_print_test.c b/decoder/tests/source/c_api_pkt_print_test.c index 138df1a..5448331 100644 --- a/decoder/tests/source/c_api_pkt_print_test.c +++ b/decoder/tests/source/c_api_pkt_print_test.c @@ -255,7 +255,7 @@ static ocsd_err_t create_test_memory_acc(dcd_tree_handle_t handle) int i = 0;
/* region list to test multi region memory file API */ - file_mem_region_t region_list[4]; + ocsd_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);
On 1 August 2016 at 07:19, Mike Leach mike.leach@linaro.org wrote:
Memory accessor API on decode tree was different to simpler API on C API.
I can't figure out what this sentence is - please revisit.
Decode tree API re-worked to make the two more consistent.
Signed-off-by: Mike Leach mike.leach@linaro.org
decoder/include/c_api/ocsd_c_api_deprc_fn.h | 4 + decoder/include/c_api/ocsd_c_api_types.h | 10 +- decoder/include/c_api/opencsd_c_api.h | 2 +- decoder/include/common/ocsd_dcd_tree.h | 16 +- decoder/include/ocsd_if_types.h | 8 + decoder/source/c_api/ocsd_c_api.cpp | 163 ++++----------------- decoder/source/ocsd_dcd_tree.cpp | 151 ++++++++++++++++--- .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 13 +- decoder/tests/source/c_api_pkt_print_test.c | 2 +- 9 files changed, 191 insertions(+), 178 deletions(-)
diff --git a/decoder/include/c_api/ocsd_c_api_deprc_fn.h b/decoder/include/c_api/ocsd_c_api_deprc_fn.h index 70986ff..7c74987 100644 --- a/decoder/include/c_api/ocsd_c_api_deprc_fn.h +++ b/decoder/include/c_api/ocsd_c_api_deprc_fn.h @@ -168,6 +168,10 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, */ 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);
+/** deprecated memory region type for adding multi-region binary files to memory access interface */ +typedef ocsd_file_mem_region_t file_mem_region_t; /** @}*/
#endif // ARM_OCSD_C_API_DEPRC_FN_H_INCLUDED diff --git a/decoder/include/c_api/ocsd_c_api_types.h b/decoder/include/c_api/ocsd_c_api_types.h index 1e98255..aa11391 100644 --- a/decoder/include/c_api/ocsd_c_api_types.h +++ b/decoder/include/c_api/ocsd_c_api_types.h @@ -135,20 +135,12 @@ typedef void (* FnStmPktMonDataIn)( const void *p_context, const uint32_t size, const uint8_t *p_data);
-/** memory region type for adding multi-region binary files to memory access interface */ -typedef struct _file_mem_region {
- size_t file_offset; /**< Offset from start of file for memory region */
- ocsd_vaddr_t start_address; /**< Start address of memory region */
- size_t region_size; /**< size in bytes of memory region */
-} file_mem_region_t;
+/** Callback interface type when attaching monitor/sink to packet processor */ 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 7c0648a..061bfe4 100644 --- a/decoder/include/c_api/opencsd_c_api.h +++ b/decoder/include/c_api/opencsd_c_api.h @@ -252,7 +252,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_mem_acc(const dcd_tree_handle_t handle
- @return ocsd_err_t : Library error code - RCDTL_OK if successful.
*/ -OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath); +OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath);
/*!
- Add a memory buffer based memory range accessor to the decode tree.
diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 7073a5d..0461eef 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -109,14 +109,19 @@ public: void setMemAccessI(ITargetMemAccess *i_mem_access); void setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem);
- /* create mapper within the decode tree. */
- /* create mapper within the decode tree - also allows direct manipulation of the mapper object to set up custom arrangements of accessors. */ ocsd_err_t createMemAccMapper(memacc_mapper_t type = MEMACC_MAP_GLOBAL);
- ocsd_err_t addMemAccessorToMap(TrcMemAccessorBase *p_accessor, const uint8_t cs_trace_id);
- ocsd_err_t removeMemAccessor(TrcMemAccessorBase *p_accessor);
- ocsd_err_t removeMemAccessorByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id);
TrcMemAccMapper *getMemAccMapper() const { return m_default_mapper; };
void setExternMemAccMapper(TrcMemAccMapper * pMapper); const bool hasMemAccMapper() const { return (bool)(m_default_mapper != 0); }; void logMappedRanges();
/* create and destroy accessor types - all using global CSID value - on default accessor */
ocsd_err_t addBufferMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length);
ocsd_err_t addBinFileMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const std::string &filepath);
ocsd_err_t addBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath);
ocsd_err_t addCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context);
ocsd_err_t removeMemAccByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space);
/* get decoder elements currently in use */ DecodeTreeElement *getDecoderElement(const uint8_t CSID) const;
@@ -153,7 +158,8 @@ private:
uint8_t m_decode_elem_iter;
- TrcMemAccMapper *m_default_mapper;
TrcMemAccMapper *m_default_mapper; //!< the mem acc mapper to use
bool m_created_mapper; //!< true if created by decode tree object
/* global error logger - all sources */ static ITraceErrorLog *s_i_error_logger;
diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index 7e17f04..f5d1fde 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -435,6 +435,14 @@ typedef enum _ocsd_mem_space_acc_t { */ typedef uint32_t (* Fn_MemAcc_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);
+/** memory region type for adding multi-region binary files to memory access interface */ +typedef struct _ocsd_file_mem_region {
- size_t file_offset; /**< Offset from start of file for memory region */
- ocsd_vaddr_t start_address; /**< Start address of memory region */
- size_t region_size; /**< size in bytes of memory region */
+} ocsd_file_mem_region_t;
/** @}*/
/** @name Packet Processor Operation Control Flags diff --git a/decoder/source/c_api/ocsd_c_api.cpp b/decoder/source/c_api/ocsd_c_api.cpp index 1e327ae..335bbe5 100644 --- a/decoder/source/c_api/ocsd_c_api.cpp +++ b/decoder/source/c_api/ocsd_c_api.cpp @@ -55,6 +55,7 @@ namespace std { const nothrow_t nothrow = nothrow_t(); }
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 ); +static ocsd_err_t ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle, DecodeTree **ppDT);
/*******************************************************************************/ /* C library data - additional data on top of the C++ library objects */ @@ -332,156 +333,45 @@ OCSD_C_API ocsd_err_t ocsd_gen_elem_str(const ocsd_generic_trace_elem *p_pkt, ch }
-/*** Decode tree -- memeory accessor control */ +/*** Decode tree -- memory 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;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
if(!pDT->hasMemAccMapper())
err = pDT->createMemAccMapper();
if(err == OCSD_OK)
{
TrcMemAccessorBase *p_accessor;
std::string pathToFile = filepath;
err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,pathToFile,address);
if(err == OCSD_OK)
{
TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor);
if(pAcc)
{
pAcc->setMemSpace(mem_space);
err = pDT->addMemAccessorToMap(pAcc,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
TrcMemAccFactory::DestroyAccessor(p_accessor);
}
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- DecodeTree *pDT;
- err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
- if(err == OCSD_OK)
return err;err = pDT->addBinFileMemAcc(address,mem_space,filepath);
}
-OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath) +OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath) { ocsd_err_t err = OCSD_OK;
- if((handle != C_API_INVALID_TREE_HANDLE) && (region_array != 0) && (num_regions != 0))
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
if(!pDT->hasMemAccMapper())
err = pDT->createMemAccMapper();
if(err == OCSD_OK)
{
TrcMemAccessorBase *p_accessor;
std::string pathToFile = filepath;
int curr_region_idx = 0;
err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,pathToFile,region_array[curr_region_idx].start_address,region_array[curr_region_idx].file_offset, region_array[curr_region_idx].region_size);
if(err == OCSD_OK)
{
TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor);
if(pAcc)
{
curr_region_idx++;
while(curr_region_idx < num_regions)
{
pAcc->AddOffsetRange(region_array[curr_region_idx].start_address,
region_array[curr_region_idx].region_size,
region_array[curr_region_idx].file_offset);
curr_region_idx++;
}
pAcc->setMemSpace(mem_space);
err = pDT->addMemAccessorToMap(pAcc,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
TrcMemAccFactory::DestroyAccessor(p_accessor);
}
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- DecodeTree *pDT;
- err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
- if(err == OCSD_OK)
return err;err = pDT->addBinFileRegionMemAcc(region_array,num_regions,mem_space,filepath);
}
OCSD_C_API ocsd_err_t ocsd_dt_add_buffer_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length) { ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
if(!pDT->hasMemAccMapper())
err = pDT->createMemAccMapper();
if(err == OCSD_OK)
{
TrcMemAccessorBase *p_accessor;
err = TrcMemAccFactory::CreateBufferAccessor(&p_accessor, address, p_mem_buffer, mem_length);
if(err == OCSD_OK)
{
TrcMemAccBufPtr *pMBuffAcc = dynamic_cast<TrcMemAccBufPtr *>(p_accessor);
if(pMBuffAcc)
{
pMBuffAcc->setMemSpace(mem_space);
err = pDT->addMemAccessorToMap(p_accessor,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
TrcMemAccFactory::DestroyAccessor(p_accessor);
}
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- DecodeTree *pDT;
- err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
- if(err == OCSD_OK)
return err;err = pDT->addBufferMemAcc(address,mem_space,p_mem_buffer,mem_length);
}
OCSD_C_API ocsd_err_t ocsd_dt_add_callback_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context) { ocsd_err_t err = OCSD_OK;
- if(handle != C_API_INVALID_TREE_HANDLE)
- {
DecodeTree *pDT = static_cast<DecodeTree *>(handle);
if(!pDT->hasMemAccMapper())
err = pDT->createMemAccMapper();
if(err == OCSD_OK)
{
TrcMemAccessorBase *p_accessor;
err = TrcMemAccFactory::CreateCBAccessor(&p_accessor, st_address, en_address, mem_space);
if(err == OCSD_OK)
{
TrcMemAccCB *pCBAcc = dynamic_cast<TrcMemAccCB *>(p_accessor);
if(pCBAcc)
{
pCBAcc->setCBIfFn(p_cb_func, p_context);
err = pDT->addMemAccessorToMap(p_accessor,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
TrcMemAccFactory::DestroyAccessor(p_accessor);
}
}
- }
- else
err = OCSD_ERR_INVALID_PARAM_VAL;
- DecodeTree *pDT;
- err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
- if(err == OCSD_OK)
return err;err = pDT->addCallbackMemAcc(st_address,en_address,mem_space,p_cb_func,p_context);
}
@@ -492,10 +382,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_remove_mem_acc(const dcd_tree_handle_t handle, con if(handle != C_API_INVALID_TREE_HANDLE) { DecodeTree *pDT = static_cast<DecodeTree *>(handle);
if(!pDT->hasMemAccMapper())
err = OCSD_ERR_INVALID_PARAM_VAL; /* no mapper, no remove*/
else
err = pDT->removeMemAccessorByAddress(st_address,mem_space,0);
} else err = OCSD_ERR_INVALID_PARAM_VAL;err = pDT->removeMemAccByAddress(st_address,mem_space);
@@ -582,6 +469,16 @@ static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPk return err; }
+static ocsd_err_t ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle, DecodeTree **ppDT) +{
- *ppDT = 0;
- if(handle == C_API_INVALID_TREE_HANDLE)
return OCSD_ERR_INVALID_PARAM_VAL;
- *ppDT = static_cast<DecodeTree *>(handle);
- if(!(*ppDT)->hasMemAccMapper())
return (*ppDT)->createMemAccMapper();
- return OCSD_OK;
+}
/*******************************************************************************/ /* C API Helper objects */ diff --git a/decoder/source/ocsd_dcd_tree.cpp b/decoder/source/ocsd_dcd_tree.cpp index cd0995b..b6451d0 100644 --- a/decoder/source/ocsd_dcd_tree.cpp +++ b/decoder/source/ocsd_dcd_tree.cpp @@ -96,8 +96,8 @@ DecodeTree::DecodeTree() : m_i_decoder_root(0), m_frame_deformatter_root(0), m_decode_elem_iter(0),
- m_default_mapper(0)
- m_default_mapper(0),
- m_created_mapper(false)
{ for(int i = 0; i < 0x80; i++) m_decode_elements[i] = 0; @@ -167,7 +167,7 @@ void DecodeTree::setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem) } }
-ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type) +ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type /* = MEMACC_MAP_GLOBAL*/ ) { // clean up any old one destroyMemAccMapper(); @@ -184,6 +184,7 @@ ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type) // set the access interface if(m_default_mapper) {
}m_created_mapper = true; setMemAccessI(m_default_mapper); m_default_mapper->setErrorLog(s_i_error_logger);
@@ -191,48 +192,160 @@ ocsd_err_t DecodeTree::createMemAccMapper(memacc_mapper_t type) return (m_default_mapper != 0) ? OCSD_OK : OCSD_ERR_MEM; }
-ocsd_err_t DecodeTree::addMemAccessorToMap(TrcMemAccessorBase *p_accessor, const uint8_t cs_trace_id) +void DecodeTree::setExternMemAccMapper(TrcMemAccMapper* pMapper) {
- ocsd_err_t err= OCSD_ERR_NOT_INIT;
- if(m_default_mapper)
err = m_default_mapper->AddAccessor(p_accessor,cs_trace_id);
- return err;
- destroyMemAccMapper(); // destroy any existing mapper - if decode tree created it.
- m_default_mapper = pMapper;
}
void DecodeTree::destroyMemAccMapper() {
- if(m_default_mapper)
- if(m_default_mapper && m_created_mapper) { m_default_mapper->RemoveAllAccessors(); delete m_default_mapper; m_default_mapper = 0;
}m_created_mapper = false;
}
-ocsd_err_t DecodeTree::removeMemAccessor(TrcMemAccessorBase *p_accessor) +void DecodeTree::logMappedRanges() {
- ocsd_err_t err= OCSD_ERR_NOT_INIT; if(m_default_mapper)
m_default_mapper->logMappedRanges();
+}
+/* Memory accessor creation - all on default mem accessor using the 0 CSID for global core space. */ +ocsd_err_t DecodeTree::addBufferMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length) +{
- if(!hasMemAccMapper())
return OCSD_ERR_NOT_INIT;
- // need a valid memory buffer, and a least enough bytes for one opcode.
- if((p_mem_buffer == 0) || (mem_length < 4))
return OCSD_ERR_INVALID_PARAM_VAL;
- TrcMemAccessorBase *p_accessor;
- ocsd_err_t err = TrcMemAccFactory::CreateBufferAccessor(&p_accessor, address, p_mem_buffer, mem_length);
- if(err == OCSD_OK) {
err = m_default_mapper->RemoveAccessor(p_accessor);
TrcMemAccBufPtr *pMBuffAcc = dynamic_cast<TrcMemAccBufPtr *>(p_accessor);
if(pMBuffAcc)
{
pMBuffAcc->setMemSpace(mem_space);
err = m_default_mapper->AddAccessor(p_accessor,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
} return err;TrcMemAccFactory::DestroyAccessor(p_accessor);
}
-ocsd_err_t DecodeTree::removeMemAccessorByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id) +ocsd_err_t DecodeTree::addBinFileMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const std::string &filepath) {
- ocsd_err_t err= OCSD_ERR_NOT_INIT;
- if(m_default_mapper)
- if(!hasMemAccMapper())
return OCSD_ERR_NOT_INIT;
- if(filepath.length() == 0)
return OCSD_ERR_INVALID_PARAM_VAL;
- TrcMemAccessorBase *p_accessor;
- ocsd_err_t err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,filepath,address);
- if(err == OCSD_OK) {
err = m_default_mapper->RemoveAccessorByAddress(address,mem_space,cs_trace_id);
TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor);
if(pAcc)
{
pAcc->setMemSpace(mem_space);
err = m_default_mapper->AddAccessor(pAcc,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
} return err;TrcMemAccFactory::DestroyAccessor(p_accessor);
}
-void DecodeTree::logMappedRanges() +ocsd_err_t DecodeTree::addBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath) {
- if(m_default_mapper)
m_default_mapper->logMappedRanges();
- if(!hasMemAccMapper())
return OCSD_ERR_NOT_INIT;
- if((region_array == 0) || (num_regions == 0) || (filepath.length() == 0))
return OCSD_ERR_INVALID_PARAM_VAL;
- TrcMemAccessorBase *p_accessor;
- int curr_region_idx = 0;
- // add first region during the creation of the file accessor.
- ocsd_err_t err = TrcMemAccFactory::CreateFileAccessor(&p_accessor,filepath,region_array[curr_region_idx].start_address,region_array[curr_region_idx].file_offset, region_array[curr_region_idx].region_size);
- if(err == OCSD_OK)
- {
TrcMemAccessorFile *pAcc = dynamic_cast<TrcMemAccessorFile *>(p_accessor);
if(pAcc)
{
// add additional regions to the file accessor.
curr_region_idx++;
while(curr_region_idx < num_regions)
{
pAcc->AddOffsetRange(region_array[curr_region_idx].start_address,
region_array[curr_region_idx].region_size,
region_array[curr_region_idx].file_offset);
curr_region_idx++;
}
pAcc->setMemSpace(mem_space);
// add the accessor to the map.
err = m_default_mapper->AddAccessor(pAcc,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
TrcMemAccFactory::DestroyAccessor(p_accessor);
- }
- return err;
+}
+ocsd_err_t DecodeTree::addCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context) +{
- if(!hasMemAccMapper())
return OCSD_ERR_NOT_INIT;
- if(p_cb_func == 0)
return OCSD_ERR_INVALID_PARAM_VAL;
- TrcMemAccessorBase *p_accessor;
- ocsd_err_t err = TrcMemAccFactory::CreateCBAccessor(&p_accessor, st_address, en_address, mem_space);
- if(err == OCSD_OK)
- {
TrcMemAccCB *pCBAcc = dynamic_cast<TrcMemAccCB *>(p_accessor);
if(pCBAcc)
{
pCBAcc->setCBIfFn(p_cb_func, p_context);
err = m_default_mapper->AddAccessor(p_accessor,0);
}
else
err = OCSD_ERR_MEM; // wrong type of object - treat as mem error
if(err != OCSD_OK)
TrcMemAccFactory::DestroyAccessor(p_accessor);
- }
- return err;
+}
+ocsd_err_t DecodeTree::removeMemAccByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space) +{
- if(!hasMemAccMapper())
return OCSD_ERR_NOT_INIT;
- return m_default_mapper->RemoveAccessorByAddress(address,mem_space,0);
}
ocsd_err_t DecodeTree::createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig) diff --git a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp index 9c6c55b..00e1173 100644 --- a/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp +++ b/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp @@ -509,16 +509,9 @@ void CreateDcdTreeFromSnapShot::processDumpfiles(std::vectorParser::DumpDef &d dumpFilePathName = m_pReader->getSnapShotDir() + it->path; if(!TrcMemAccessorFile::isExistingFileAccessor(dumpFilePathName)) {
TrcMemAccessorBase *p_acc;
// not already a file accessor on this tree (n.b. assume only one tree in use)
ocsd_err_t err = TrcMemAccFactory::CreateFileAccessor(&p_acc, dumpFilePathName,it->address);
if(err == OCSD_OK)
{
err = m_pDecodeTree->addMemAccessorToMap(p_acc,0);
}
else
{
ocsd_err_t err = m_pDecodeTree->addBinFileMemAcc(it->address,OCSD_MEM_SPACE_ANY,dumpFilePathName);
if(err != OCSD_OK)
{ std::ostringstream oss; oss << "Failed to create memory accessor for file " << dumpFilePathName << "."; LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,oss.str()));
diff --git a/decoder/tests/source/c_api_pkt_print_test.c b/decoder/tests/source/c_api_pkt_print_test.c index 138df1a..5448331 100644 --- a/decoder/tests/source/c_api_pkt_print_test.c +++ b/decoder/tests/source/c_api_pkt_print_test.c @@ -255,7 +255,7 @@ static ocsd_err_t create_test_memory_acc(dcd_tree_handle_t handle) int i = 0;
/* region list to test multi region memory file API */
- file_mem_region_t region_list[4];
ocsd_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);
-- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight
Makefiles updated to reflect new decoder registration code. Makefiles updated for changed C API
Some source changes to reflect differing requirements in MSVC and G++ compilation.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/build/linux/makefile | 2 + decoder/build/linux/rctdl_c_api_lib/makefile | 3 +- decoder/build/linux/ref_trace_decode_lib/makefile | 1 + decoder/include/common/ocsd_dcd_mngr.h | 6 +- decoder/include/common/ocsd_lib_dcd_register.h | 2 +- decoder/include/ocsd_if_types.h | 1 + decoder/source/c_api/ocsd_c_api_deprc_fn.cpp | 14 ++-- .../build/linux/c_api_pkt_print_test/makefile | 82 ++++++++++++++++++++++ 8 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 decoder/tests/build/linux/c_api_pkt_print_test/makefile
diff --git a/decoder/build/linux/makefile b/decoder/build/linux/makefile index 4befae3..b86fafe 100644 --- a/decoder/build/linux/makefile +++ b/decoder/build/linux/makefile @@ -158,6 +158,7 @@ tests: libs cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && make cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && make cd $(OCSD_ROOT)/tests/build/linux/simple_pkt_print_c_api && make + cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && make
############################################################# # clean targets @@ -174,3 +175,4 @@ clean_tests: cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && make clean cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && make clean cd $(OCSD_ROOT)/tests/build/linux/simple_pkt_print_c_api && make clean + cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && make clean diff --git a/decoder/build/linux/rctdl_c_api_lib/makefile b/decoder/build/linux/rctdl_c_api_lib/makefile index 9338bfa..dfebe09 100644 --- a/decoder/build/linux/rctdl_c_api_lib/makefile +++ b/decoder/build/linux/rctdl_c_api_lib/makefile @@ -49,7 +49,8 @@ CPP_INCLUDES= \ -I$(OCSD_INCLUDE) \ -I$(OCSD_SOURCE)/c_api
-OBJECTS=$(BUILD_DIR)/ocsd_c_api.o +OBJECTS=$(BUILD_DIR)/ocsd_c_api.o \ + $(BUILD_DIR)/ocsd_c_api_deprc_fn.o
all: build_dir $(OBJECTS) diff --git a/decoder/build/linux/ref_trace_decode_lib/makefile b/decoder/build/linux/ref_trace_decode_lib/makefile index 56982bd..b650331 100644 --- a/decoder/build/linux/ref_trace_decode_lib/makefile +++ b/decoder/build/linux/ref_trace_decode_lib/makefile @@ -90,6 +90,7 @@ OBJECTS=$(BUILD_DIR)/ocsd_code_follower.o \ $(BUILD_DIR)/ocsd_error.o \ $(BUILD_DIR)/ocsd_error_logger.o \ $(BUILD_DIR)/ocsd_gen_elem_list.o \ + $(BUILD_DIR)/ocsd_lib_dcd_register.o \ $(BUILD_DIR)/ocsd_msg_logger.o \ $(BUILD_DIR)/ocsd_version.o \ $(BUILD_DIR)/trc_component.o \ diff --git a/decoder/include/common/ocsd_dcd_mngr.h b/decoder/include/common/ocsd_dcd_mngr.h index 487e1db..b70a4cc 100644 --- a/decoder/include/common/ocsd_dcd_mngr.h +++ b/decoder/include/common/ocsd_dcd_mngr.h @@ -39,7 +39,7 @@ #include "common/ocsd_dcd_mngr_i.h" #include "common/ocsd_lib_dcd_register.h" #include "common/trc_pkt_decode_base.h" - +#include "common/trc_pkt_proc_base.h"
template <class P, class Pt, class Pc> class DecoderMngrBase : public IDecoderMngr @@ -327,7 +327,7 @@ class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc> { public: DecodeMngrFullDcd (const std::string &name, ocsd_trace_protocol_t builtInProtocol) - : DecoderMngrBase(name,builtInProtocol) {}; + : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
virtual ~DecodeMngrFullDcd() {};
@@ -370,7 +370,7 @@ class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc> { public: DecodeMngrPktProc (const std::string &name, ocsd_trace_protocol_t builtInProtocol) - : DecoderMngrBase(name,builtInProtocol) {}; + : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
virtual ~DecodeMngrPktProc() {};
diff --git a/decoder/include/common/ocsd_lib_dcd_register.h b/decoder/include/common/ocsd_lib_dcd_register.h index d059214..3e6611e 100644 --- a/decoder/include/common/ocsd_lib_dcd_register.h +++ b/decoder/include/common/ocsd_lib_dcd_register.h @@ -79,7 +79,7 @@ private: // singleton pattern - need just one of these in the library - ensure all default constructors are private. OcsdLibDcdRegister(); OcsdLibDcdRegister(OcsdLibDcdRegister const &) {}; - OcsdLibDcdRegister& operator=(OcsdLibDcdRegister const &){}; + OcsdLibDcdRegister& operator=(OcsdLibDcdRegister const &){ }; ~OcsdLibDcdRegister();
static OcsdLibDcdRegister *m_p_libMngr; diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index f5d1fde..f026d4e 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -36,6 +36,7 @@ #define ARM_OCSD_IF_TYPES_H_INCLUDED
#include <stdint.h> +#include <stddef.h>
/** @defgroup ocsd_interfaces OpenCSD Library : Interfaces @brief Set of types, structures and virtual interface classes making up the primary API diff --git a/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp b/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp index b5d0ff5..959ef0b 100644 --- a/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp +++ b/decoder/source/c_api/ocsd_c_api_deprc_fn.cpp @@ -51,7 +51,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv4i_pkt_proc(const dcd_tree_handle_t han 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); + err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,(void *)pPktFn,p_context); if(err != OCSD_OK) ocsd_dt_remove_decoder(handle,CSID); } @@ -79,7 +79,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv4i_pkt_mon(const dcd_tree_handle_t hand 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); + err = ocsd_dt_attach_packet_callback(handle,trc_chan_id,OCSD_C_API_CB_PKT_MON,(void *)pPktFn,p_context); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -95,7 +95,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t hand 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); + err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,(void *)pPktFn,p_context); if(err != OCSD_OK) ocsd_dt_remove_decoder(handle,CSID); } @@ -123,7 +123,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_etmv3_pkt_mon(const dcd_tree_handle_t handl 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); + err = ocsd_dt_attach_packet_callback(handle,trc_chan_id,OCSD_C_API_CB_PKT_MON,(void *)pPktFn,p_context); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -140,7 +140,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_ptm_pkt_proc(const dcd_tree_handle_t 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); + err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,(void *)pPktFn,p_context); if(err != OCSD_OK) ocsd_dt_remove_decoder(handle,CSID); } @@ -169,7 +169,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_ptm_pkt_mon(const dcd_tree_handle_t handle, 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); + err = ocsd_dt_attach_packet_callback(handle,trc_chan_id,OCSD_C_API_CB_PKT_MON,(void *)pPktFn,p_context); } else err = OCSD_ERR_INVALID_PARAM_VAL; @@ -185,7 +185,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_stm_pkt_proc(const dcd_tree_handle_t 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); + err = ocsd_dt_attach_packet_callback(handle,CSID, OCSD_C_API_CB_PKT_SINK,(void *)pPktFn,p_context); if(err != OCSD_OK) ocsd_dt_remove_decoder(handle,CSID); } diff --git a/decoder/tests/build/linux/c_api_pkt_print_test/makefile b/decoder/tests/build/linux/c_api_pkt_print_test/makefile new file mode 100644 index 0000000..01d4660 --- /dev/null +++ b/decoder/tests/build/linux/c_api_pkt_print_test/makefile @@ -0,0 +1,82 @@ +######################################################## +# Copyright 2015 ARM Limited. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +################################################################################# + +######## +# RCTDL - test makefile for simple c api packet list test. +# + +CC := $(MASTER_CC) +CC_FLAGS := $(MASTER_CC_FLAGS) -Wno-switch +LINKER := $(MASTER_LINKER) +LINKER_FLAGS := $(MASTER_LINKER_FLAGS) + +PROG = c_api_pkt_print_test + +BUILD_DIR=./$(PLAT_DIR) + +VPATH = $(OCSD_TESTS)/source + +CC_INCLUDES = \ + -I$(OCSD_TESTS)/source \ + -I$(OCSD_INCLUDE) + +OBJECTS = $(BUILD_DIR)/c_api_pkt_print_test.o + +LIBS = -L$(LIB_TARGET_DIR) -l$(LIB_BASE_NAME) -l$(LIB_CAPI_NAME) + +all: build_dir test_app copy_libs + +test_app: $(OBJECTS) $(BIN_TEST_TARGET_DIR)/$(PROG) + + + $(BIN_TEST_TARGET_DIR)/$(PROG): + mkdir -p $(BIN_TEST_TARGET_DIR) + $(LINKER) $(LINKER_FLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group -o $(BIN_TEST_TARGET_DIR)/$(PROG) + cp $(LIB_TARGET_DIR)/*.so . + +build_dir: + mkdir -p $(BUILD_DIR) + +.PHONY: copy_libs + +copy_libs: + cp $(LIB_TARGET_DIR)/*.so $(BIN_TEST_TARGET_DIR)/. + + +#### build rules +$(BUILD_DIR)/%.o : %.c + $(CC) $(CC_FLAGS) $(CC_INCLUDES) $< -o $@ + +#### clean +.PHONY: clean +clean : + rm -f $(BIN_TEST_TARGET_DIR)/$(PROG) $(OBJECTS) + +# end of file makefile
Update to TraceComponent base class to correctly initialise m_assocComp.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/source/trc_component.cpp | 1 + 1 file changed, 1 insertion(+)
diff --git a/decoder/source/trc_component.cpp b/decoder/source/trc_component.cpp index 3cc4c31..3c201f8 100644 --- a/decoder/source/trc_component.cpp +++ b/decoder/source/trc_component.cpp @@ -83,6 +83,7 @@ void TraceComponent::Init(const std::string &name)
m_supported_op_flags = 0; m_op_flags = 0; + m_assocComp = 0;
m_pErrAttachMon = new (std::nothrow) errLogAttachMonitor(); if(m_pErrAttachMon)
Move deprecated types out of the main C API header into the deprecated header for eventual permanent removal.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/c_api/ocsd_c_api_types.h | 49 ++------------------------------ decoder/include/c_api/opencsd_c_api.h | 30 ++++++++++--------- 2 files changed, 18 insertions(+), 61 deletions(-)
diff --git a/decoder/include/c_api/ocsd_c_api_types.h b/decoder/include/c_api/ocsd_c_api_types.h index aa11391..be7316f 100644 --- a/decoder/include/c_api/ocsd_c_api_types.h +++ b/decoder/include/c_api/ocsd_c_api_types.h @@ -89,56 +89,11 @@ typedef void (* FnDefPktDataMon)(const void *p_context, 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); - -/** function pointer type for ETMv4 instruction packet processor monitor output, raw packet monitor / display input */ -typedef void (* FnEtmv4IPktMonDataIn)( 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, - const uint32_t size, - const uint8_t *p_data); - -/** function pointer type for ETMv3 packet processor output, packet analyser/decoder input */ -typedef ocsd_datapath_resp_t (* FnEtmv3PacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_etmv3_pkt *p_packet_in); - -/** function pointer type for ETMv3 packet processor monitor output, raw packet monitor / display input */ -typedef void (* FnEtmv3PktMonDataIn)( const void *p_context, - const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const ocsd_etmv3_pkt *p_packet_in, - const uint32_t size, - const uint8_t *p_data); - - -/** function pointer type for PTM packet processor output, packet analyser/decoder input */ -typedef ocsd_datapath_resp_t (* FnPtmPacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_ptm_pkt *p_packet_in); - -/** function pointer type for PTM packet processor monitor output, raw packet monitor / display input */ -typedef void (* FnPtmPktMonDataIn)( const void *p_context, - const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const ocsd_ptm_pkt *p_packet_in, - const uint32_t size, - const uint8_t *p_data); - - -/** function pointer type for STM packet processor output, packet analyser/decoder input */ -typedef ocsd_datapath_resp_t (* FnStmPacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_stm_pkt *p_packet_in); - -/** function pointer type for STM packet processor monitor output, raw packet monitor / display input */ -typedef void (* FnStmPktMonDataIn)( const void *p_context, - const ocsd_datapath_op_t op, - const ocsd_trc_index_t index_sop, - const ocsd_stm_pkt *p_packet_in, - const uint32_t size, - const uint8_t *p_data);
/** Callback interface type when attaching monitor/sink to packet processor */ typedef enum _ocsd_c_api_cb_types { - OCSD_C_API_CB_PKT_SINK, - OCSD_C_API_CB_PKT_MON, + OCSD_C_API_CB_PKT_SINK, /** Attach to the packet processor primary packet output (CB fn is FnDefPktDataIn) */ + OCSD_C_API_CB_PKT_MON, /** Attach to the packet processor packet monitor output (CB fn is FnDefPktDataMon) */ } ocsd_c_api_cb_types;
/** @}*/ diff --git a/decoder/include/c_api/opencsd_c_api.h b/decoder/include/c_api/opencsd_c_api.h index 061bfe4..c40c20f 100644 --- a/decoder/include/c_api/opencsd_c_api.h +++ b/decoder/include/c_api/opencsd_c_api.h @@ -126,7 +126,7 @@ OCSD_C_API void ocsd_destroy_dcd_tree(const dcd_tree_handle_t handle); * @param *pDataBlock : Pointer to data block. * @param *numBytesProcessed : Number of bytes actually processed by the decoder. * - * @return ocsd_datapath_resp_t : Datapath response code + * @return ocsd_datapath_resp_t : Datapath response code (CONT/WAIT/FATAL) */ OCSD_C_API ocsd_datapath_resp_t ocsd_dt_process_data(const dcd_tree_handle_t handle, const ocsd_datapath_op_t op, @@ -156,15 +156,18 @@ OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_outfn(const dcd_tree_handle_t handle,
/*---------------------- Trace Decoders ----------------------------------------------------------------------------------*/ /*! -* <Detailed description of the method> +* Creates a decoder that is registered with the library under the supplied name. +* Flags determine if a full packet processor / packet decoder pair or +* packet processor only is created. +* Uses the supplied configuration structure. * * @param handle : Handle to decode tree. -* @param *decoder_name : -* @param create_flags : -* @param *decoder_cfg : +* @param *decoder_name : Registered name of the decoder to create. +* @param create_flags : Decoder creation options. +* @param *decoder_cfg : Pointer to a valid configuration structure for the named decoder. * @param *pCSID : Pointer to location to return the configured CoreSight trace ID for the decoder. * -* @return ocsd_err_t : +* @return ocsd_err_t : Library error code - OCSD_OK if successful. */ OCSD_C_API ocsd_err_t ocsd_dt_create_decoder(const dcd_tree_handle_t handle, const char *decoder_name, @@ -174,12 +177,12 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_decoder(const dcd_tree_handle_t handle, );
/*! -* <Detailed description of the method> +* Remove a decoder from the tree and destroy it. * * @param handle : Handle to decode tree. * @param CSID : Configured CoreSight trace ID for the decoder. * -* @return ocsd_err_t : +* @return ocsd_err_t : Library error code - OCSD_OK if successful. */ OCSD_C_API ocsd_err_t ocsd_dt_remove_decoder( const dcd_tree_handle_t handle, const unsigned char CSID); @@ -188,16 +191,16 @@ OCSD_C_API ocsd_err_t ocsd_dt_remove_decoder( const dcd_tree_handle_t handle, /*! * Attach a callback function to the packet processor. * -* The callback_type defines the attachment point:- +* The callback_type defines the attachment point, either the main packet output +* (only if no decoder attached), or the packet monitor. * -* * @param handle : Handle to decode tree. * @param CSID : Configured CoreSight trace ID for the decoder. -* @param callback_type : +* @param callback_type : Attachment point * @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 : +* @return ocsd_err_t : Library error code - OCSD_OK if successful. */ OCSD_C_API ocsd_err_t ocsd_dt_attach_packet_callback( const dcd_tree_handle_t handle, const unsigned char CSID, @@ -208,8 +211,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_attach_packet_callback( const dcd_tree_handle_t h
- -/** TBD : more C API functions to be added here */ +
/** @}*/ /*---------------------- Memory Access for traced opcodes ----------------------------------------------------------------------------------*/
Improved documentation.
Added the include/common directory to the files scanned by doxygen.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/docs/doxygen_config.dox | 3 +- decoder/include/c_api/ocsd_c_api_deprc_fn.h | 58 ++++- decoder/include/common/ocsd_dcd_tree.h | 261 +++++++++++++++++++--- decoder/include/common/ocsd_dcd_tree_elem.h | 24 +- decoder/include/common/trc_cs_config.h | 8 +- decoder/include/common/trc_pkt_proc_base.h | 53 +++-- decoder/include/interfaces/trc_abs_typed_base_i.h | 5 +- decoder/include/ocsd_if_types.h | 8 +- decoder/include/opencsd.h | 3 - decoder/include/ptm/trc_cmp_cfg_ptm.h | 4 +- decoder/include/trc_gen_elem_types.h | 4 +- decoder/tests/source/gen_elem_printer.h | 2 +- 12 files changed, 366 insertions(+), 67 deletions(-)
diff --git a/decoder/docs/doxygen_config.dox b/decoder/docs/doxygen_config.dox index bdb24f0..d6b1666 100644 --- a/decoder/docs/doxygen_config.dox +++ b/decoder/docs/doxygen_config.dox @@ -773,7 +773,8 @@ INPUT = ../include \ ../include/mem_acc \ ../../README.md \ . \ - ../../HOWTO.md + ../../HOWTO.md \ + ../include/common
# This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/decoder/include/c_api/ocsd_c_api_deprc_fn.h b/decoder/include/c_api/ocsd_c_api_deprc_fn.h index 7c74987..463f4af 100644 --- a/decoder/include/c_api/ocsd_c_api_deprc_fn.h +++ b/decoder/include/c_api/ocsd_c_api_deprc_fn.h @@ -35,9 +35,63 @@ #ifndef ARM_OCSD_C_API_DEPRC_FN_H_INCLUDED #define ARM_OCSD_C_API_DEPRC_FN_H_INCLUDED
-/** @name Deprecated C-API functions +/** @defgroup depr_lib_c_api OpenCSD Library : Deprecated "C" API functions and types + + @brief "C" API functions and types that have been deprecated after API changes. + + Retained for regression testing for a few library versions + Will be removed completely in a later library version + + To use these functions define the macro OPENCSD_INC_DEPRECATED_API @{*/
+/** 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); + +/** function pointer type for ETMv4 instruction packet processor monitor output, raw packet monitor / display input */ +typedef void (* FnEtmv4IPktMonDataIn)( 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, + const uint32_t size, + const uint8_t *p_data); + +/** function pointer type for ETMv3 packet processor output, packet analyser/decoder input */ +typedef ocsd_datapath_resp_t (* FnEtmv3PacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_etmv3_pkt *p_packet_in); + +/** function pointer type for ETMv3 packet processor monitor output, raw packet monitor / display input */ +typedef void (* FnEtmv3PktMonDataIn)( const void *p_context, + const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const ocsd_etmv3_pkt *p_packet_in, + const uint32_t size, + const uint8_t *p_data); + + +/** function pointer type for PTM packet processor output, packet analyser/decoder input */ +typedef ocsd_datapath_resp_t (* FnPtmPacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_ptm_pkt *p_packet_in); + +/** function pointer type for PTM packet processor monitor output, raw packet monitor / display input */ +typedef void (* FnPtmPktMonDataIn)( const void *p_context, + const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const ocsd_ptm_pkt *p_packet_in, + const uint32_t size, + const uint8_t *p_data); + + +/** function pointer type for STM packet processor output, packet analyser/decoder input */ +typedef ocsd_datapath_resp_t (* FnStmPacketDataIn)(const void *p_context, const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const ocsd_stm_pkt *p_packet_in); + +/** function pointer type for STM packet processor monitor output, raw packet monitor / display input */ +typedef void (* FnStmPktMonDataIn)( const void *p_context, + const ocsd_datapath_op_t op, + const ocsd_trc_index_t index_sop, + const ocsd_stm_pkt *p_packet_in, + const uint32_t size, + const uint8_t *p_data); + + /*---------------------- ETMv4 Trace ----------------------------------------------------------------------------------*/ /*! * Create an ETMv4 instruction trace packet processor only for the supplied configuration. @@ -95,7 +149,7 @@ OCSD_C_API ocsd_err_t ocsd_dt_create_etmv3_pkt_proc(const dcd_tree_handle_t hand * 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. + * @param *etmv3_cfg : pointer to valid Etmv4 configuration structure. * * @return ocsd_err_t : Library error code - RCDTL_OK if successful. */ diff --git a/decoder/include/common/ocsd_dcd_tree.h b/decoder/include/common/ocsd_dcd_tree.h index 0461eef..1ab5fbc 100644 --- a/decoder/include/common/ocsd_dcd_tree.h +++ b/decoder/include/common/ocsd_dcd_tree.h @@ -40,7 +40,7 @@ #include <list>
#include "opencsd.h" - +#include "ocsd_dcd_tree_elem.h"
/** @defgroup dcd_tree OpenCSD Library : Trace Decode Tree. @brief Create a multi source decode tree for a single trace capture buffer. @@ -50,8 +50,6 @@
@{*/
-#include "ocsd_dcd_tree_elem.h" - /*! * @class DecodeTree * @brief Class to manage the decoding of data from a single trace sink . @@ -63,11 +61,13 @@ class DecodeTree : public ITrcDataIn { public: - DecodeTree(); - ~DecodeTree(); +/** @name Creation and Destruction +@{*/ + DecodeTree(); //!< default constructor + ~DecodeTree(); //!< default destructor
/*! - * Create a decode tree. + * @brief Create a decode tree. * Automatically creates a trace frame deformatter if required and a default error log component. * * @param src_type : Data stream source type, can be CoreSight frame formatted trace, or single demuxed trace data stream, @@ -77,10 +77,15 @@ public: */ static DecodeTree *CreateDecodeTree(const ocsd_dcd_tree_src_t src_type, const uint32_t formatterCfgFlags);
- /** Destroy a decode tree */ + /** @brief Destroy a decode tree */ static void DestroyDecodeTree(DecodeTree *p_dcd_tree);
- /** The library default error logger */ +/** @}*/ + + +/** @name Error Logging +@{*/ + /** @brief The library default error logger */ static ocsdDefaultErrorLogger* getDefaultErrorLogger() { return &s_error_logger; };
/** the current error logging interface in use */ @@ -89,8 +94,15 @@ public: /** set an alternate error logging interface. */ static void setAlternateErrorLogger(ITraceErrorLog *p_error_logger);
- /** decode tree implements the data in interface : ITrcDataIn . - Captured trace data is passed to the deformatter and decoders via this method. +/** @}*/ + + +/** @name Trace Data Path +@{*/ + /** @brief Trace Data input interface (ITrcDataIn) + + Decode tree implements the data in interface : ITrcDataIn . + Captured raw trace data is passed into the deformatter and decoders via this method. */ virtual ocsd_datapath_resp_t TraceDataIn( const ocsd_datapath_op_t op, const ocsd_trc_index_t index, @@ -98,43 +110,242 @@ public: const uint8_t *pDataBlock, uint32_t *numBytesProcessed);
- /*! Create a decoder by registered name */ + /*! + * @brief Decoded Trace output. + * + * Client trace analysis program attaches a generic trace element interface to + * receive the output from the trace decode operations. + * + * @param *i_gen_trace_elem : Pointer to the interface. + */ + void setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem); + + /*! @brief Return the connected generic element interface */ + ITrcGenElemIn *getGenTraceElemOutI() const { return m_i_gen_elem_out; }; + +/** @}*/ + +/** @name Decoder Management +@{*/ + + /*! + * Creates a decoder that is registered with the library under the supplied name. + * createFlags determine if a full packet processor / packet decoder pair or + * packet processor only is created. + * Uses the supplied configuration structure. + * + * @param &decoderName : registered name of decoder + * @param createFlags : Decoder creation options. + * @param *pConfig : Pointer to a valid configuration structure for the named decoder. + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t createDecoder(const std::string &decoderName, const int createFlags, const CSConfig *pConfig);
- /* remove a decoder / packet processor attached to an ID - allows another decoder to be substituted. */ + /* */ + /*! + * Remove a decoder / packet processor attached to an Trace ID output on the frame de-mux. + * + * Once removed another decoder can be created that has a CSConfig using that ID. + * + * @param CSID : Trace ID to remove. + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t removeDecoder(const uint8_t CSID);
- /* set key interfaces - attach / replace on any existing tree components? */ + +/* get decoder elements currently in use */ + + /*! + * Find a decode tree element associated with a specific CoreSight trace ID. * + */ + DecodeTreeElement *getDecoderElement(const uint8_t CSID) const; + /* iterate decoder elements */ + + /*! + * Decode tree iteration. Return the first tree element 0 if no elements avaiable. + * + * @param &elemID : CoreSight Trace ID associated with this element + */ + DecodeTreeElement *getFirstElement(uint8_t &elemID); + /*! + * Return the next tree element - or 0 if no futher elements avaiable. + * + * @param &elemID : CoreSight Trace ID associated with this element + */ + DecodeTreeElement *getNextElement(uint8_t &elemID); + +/* set key interfaces - attach / replace on any existing tree components */ + + /*! + * Set an ARM instruction opcode decoder. + * + * @param *i_instr_decode : Pointer to the interface. + */ void setInstrDecoder(IInstrDecode *i_instr_decode); + /*! + * Set a target memory access interface - used to access program image memory for instruction + * trace decode. + * + * @param *i_mem_access : Pointer to the interface. + */ void setMemAccessI(ITargetMemAccess *i_mem_access); - void setGenTraceElemOutI(ITrcGenElemIn *i_gen_trace_elem);
- /* create mapper within the decode tree - also allows direct manipulation of the mapper object to set up custom arrangements of accessors. */ + +/** @}*/ + +/** @name Memory Access Mapper + + A memory mapper is used to organise a collection of memory accessor objects that contain the + memory images for different areas of traced instruction memory. These areas could be the executed + program and a set of loaded .so libraries for example - each of which would have code sections in + different memory locations. + + A memory accessor represents a snapshot of an area of memory as it appeared during trace capture, + for a given memory space. Memory spaces are described by the ocsd_mem_space_acc_t enum. The most + general memory space is OCSD_MEM_SPACE_ANY. This represents memory that can be secure or none-secure, + available at any exception level. + + The memory mapper will not allow two accessors to overlap in the same memory space. + + The trace decdoer will access memory with a memory space parameter that represents the current core + state - the mapper will find the closest memory space match for the address. + + e.g. if the core is accessing secure EL3, then the most specialised matching space will be accessed. + If an EL3 space matches that will be used, otherwise the any secure, and finally _ANY. + + It is no necessary for clients to register memory accessors for all spaces - _ANY will be sufficient + in many cases. + + +@{*/ + + /* */ + /*! + * This creates a memory mapper within the decode tree. + * + * @param type : defaults to MEMACC_MAP_GLOBAL (only type available at present) + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t createMemAccMapper(memacc_mapper_t type = MEMACC_MAP_GLOBAL); + + /*! + * Get a pointer to the memory mapper. Allows a client to add memory accessors directly to the mapper. + * @return TrcMemAccMapper : Pointer to the mapper. + */ TrcMemAccMapper *getMemAccMapper() const { return m_default_mapper; }; + + /*! + * Set an external mapper rather than create a mapper in the decode tree. + * Setting this will also destroy any internal mapper that was previously created. + * + * @param pMapper : pointer to the mapper to add. + */ void setExternMemAccMapper(TrcMemAccMapper * pMapper); + + /*! + * Return true if a mapper has been set (internal or external + */ const bool hasMemAccMapper() const { return (bool)(m_default_mapper != 0); }; - void logMappedRanges();
- /* create and destroy accessor types - all using global CSID value - on default accessor */ + void logMappedRanges(); //!< Log the mapped memory ranges to the default message logger. + +/** @}*/ + +/** @name Memory Accessors + A memory accessor represents a snapshot of an area of memory as it appeared during trace capture. + + Memory spaces represent either common global memory, or Secure / none-secure and EL specific spaces. + +@{*/ + + /*! + * Creates a memory accessor for a memory block in the supplied buffer and adds to the current mapper. + * + * @param address : Start address for the memory block in the memory map. + * @param mem_space : Memory space + * @param *p_mem_buffer : start of the buffer. + * @param mem_length : length of the buffer. + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t addBufferMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length); + + /*! + * Creates a memory accessor for a memory block supplied as a contiguous binary data file, and adds to the current mapper. + * + * @param address : Start address for the memory block in the memory map. + * @param mem_space : Memory space + * @param &filepath : Path to the binary data file + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t addBinFileMemAcc(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const std::string &filepath); + + /*! + * Creates a memory accessor for a memory block supplied as a one or more memory regions in a binary file. + * Region structures are created that describe the memory start address, the offset within the binary file + * for that address, and the length of the region. This accessor can be used to point to the code section + * in a program file for example. + * + * @param *region_array : array of valid memory regions in the file. + * @param num_regions : number of regions + * @param mem_space : Memory space + * @param &filepath : Path to the binary data file + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t addBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath); + + /*! + * This memory accessor allows the client to supply a callback function for the region + * defined by the start and end addresses. This can be used to supply a custom memory accessor, + * or to directly access memory if the decode is running live on a target system. + * + * @param st_address : start address of region. + * @param en_address : end address of region. + * @param mem_space : Memory space + * @param p_cb_func : Callback function + * @param *p_context : client supplied context information + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t addCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context); + + /*! + * Remove the memory accessor from the map, that begins at the given address, for the memory space provided. + * + * @param address : Start address of the memory accessor. + * @param mem_space : Memory space for the memory accessor. + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ ocsd_err_t removeMemAccByAddress(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space);
- /* get decoder elements currently in use */ - DecodeTreeElement *getDecoderElement(const uint8_t CSID) const; - /* iterate decoder elements */ - DecodeTreeElement *getFirstElement(uint8_t &elemID); - DecodeTreeElement *getNextElement(uint8_t &elemID); +/** @}*/
+/** @name CoreSight Trace Frame De-mux +@{*/ + + //! Get the Trace Frame de-mux. TraceFormatterFrameDecoder *getFrameDeformatter() const { return m_frame_deformatter_root; }; - ITrcGenElemIn *getGenTraceElemOutI() const { return m_i_gen_elem_out; };
- /* ID filtering - sets the output filter on the trace deformatter. No effect if no decoder attached for the ID */ + + /*! @brief ID filtering - sets the output filter on the trace deformatter. + + Only supplied IDs will be decoded. + + No effect if no decoder attached for the ID + + @param ids : Vector of CS Trace IDs + */ ocsd_err_t setIDFilter(std::vector<uint8_t> &ids); // only supplied IDs will be decoded - ocsd_err_t clearIDFilter(); // remove filter, all IDs will be decoded + + ocsd_err_t clearIDFilter(); //!< remove filter, all IDs will be decoded + +/** @}*/
private: bool initialise(const ocsd_dcd_tree_src_t type, uint32_t formatterCfgFlags); diff --git a/decoder/include/common/ocsd_dcd_tree_elem.h b/decoder/include/common/ocsd_dcd_tree_elem.h index 82c2159..2b609fb 100644 --- a/decoder/include/common/ocsd_dcd_tree_elem.h +++ b/decoder/include/common/ocsd_dcd_tree_elem.h @@ -38,29 +38,32 @@ #include "common/ocsd_dcd_mngr_i.h" #include "common/trc_component.h"
-/** @class decoder_elements - * @brief Decode tree element base structure. - * @addtogroup dcd_tree +/** @addtogroup dcd_tree +@{*/ + +/*! @struct _decoder_elements + * @brief Decode tree element base structure. * * Element describes the protocol supported for this element and * contains pointers to the decoder manager interface and component handle. - * */ typedef struct _decoder_elements { - std::string dcd_name; - TraceComponent *dcd_handle; - IDecoderMngr *dcd_mngr; - ocsd_trace_protocol_t protocol; + std::string dcd_name; //!< Registered name of the decoder + TraceComponent *dcd_handle; //!< handle to the decoder object + IDecoderMngr *dcd_mngr; //!< pointer to the decoder manager interface for the decodcer + ocsd_trace_protocol_t protocol;//!< protocol type bool created; /**< decode tree created this element (destroy it on tree destruction) */ } decoder_element;
/*! * @class DecodeTreeElement * @brief Decode tree element - * @addtogroup dcd_tree * - * + * Decoder tree elements are references to individual decoders in the tree. + * These allow iteration of all decoders in the tree to perform common operations. + * + * The DecodeTree contains a list of elements. */ class DecodeTreeElement : protected decoder_element { @@ -103,6 +106,7 @@ inline void DecodeTreeElement::DestroyElem() dcd_mngr->destroyDecoder(dcd_handle); }
+/** @}*/ #endif // ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
/* End of File ocsd_dcd_tree_elem.h */ diff --git a/decoder/include/common/trc_cs_config.h b/decoder/include/common/trc_cs_config.h index 58398f7..9b2c130 100644 --- a/decoder/include/common/trc_cs_config.h +++ b/decoder/include/common/trc_cs_config.h @@ -35,8 +35,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/** @addtogroup ocsd_protocol_cfg +@{*/ + /*! - * @class CSConfig : Base class for configuration data on CoreSight trace component. + * @class CSConfig + * @brief Base class for configuration data on CoreSight trace component. * * Defines common access functionality, common to all components. * (e.g. trace ID). @@ -51,6 +55,8 @@ public: virtual const uint8_t getTraceID() const = 0; //!< CoreSight Trace ID for this device. };
+/** @}*/ + #endif // ARM_TRC_CS_CONFIG_H_INCLUDED
/* End of File trc_cs_config.h */ \ No newline at end of file diff --git a/decoder/include/common/trc_pkt_proc_base.h b/decoder/include/common/trc_pkt_proc_base.h index 86ad690..f09ad61 100644 --- a/decoder/include/common/trc_pkt_proc_base.h +++ b/decoder/include/common/trc_pkt_proc_base.h @@ -45,13 +45,22 @@ #include "comp_attach_pt_t.h"
/** @defgroup ocsd_pkt_proc OpenCSD Library : Packet Processors. - @brief Classes providing Protocol Packet Processing capability.
Packet processors take an incoming byte stream and convert into discrete packets for the required trace protocol. @{*/
+ + +/*! + * @class TrcPktProcI + * @brief Base Packet processing interface + * + * Defines the packet processing methods that protocol specific processors must + * implement. + * + */ class TrcPktProcI : public TraceComponent, public ITrcDataIn { public: @@ -59,7 +68,8 @@ public: TrcPktProcI(const char *component_name, int instIDNum); virtual ~TrcPktProcI() {};
- /* generic trace data input interface */ + /** Trace byte data input interface - from ITrcDataIn. + */ virtual ocsd_datapath_resp_t TraceDataIn( const ocsd_datapath_op_t op, const ocsd_trc_index_t index, const uint32_t dataBlockSize, @@ -69,15 +79,18 @@ public: protected:
/* implementation packet processing interface */ + + /*! @brief Implementation function for the OCSD_OP_DATA operation */ virtual ocsd_datapath_resp_t processData( const ocsd_trc_index_t index, const uint32_t dataBlockSize, const uint8_t *pDataBlock, uint32_t *numBytesProcessed) = 0; - virtual ocsd_datapath_resp_t onEOT() = 0; - virtual ocsd_datapath_resp_t onReset() = 0; - virtual ocsd_datapath_resp_t onFlush() = 0; - virtual ocsd_err_t onProtocolConfig() = 0; - virtual const bool isBadPacket() const = 0; // check if the current packet is an error / bad packet + + virtual ocsd_datapath_resp_t onEOT() = 0; //!< Implementation function for the OCSD_OP_EOT operation + virtual ocsd_datapath_resp_t onReset() = 0; //!< Implementation function for the OCSD_OP_RESET operation + virtual ocsd_datapath_resp_t onFlush() = 0; //!< Implementation function for the OCSD_OP_FLUSH operation + virtual ocsd_err_t onProtocolConfig() = 0; //!< Called when the configuration object is passed to the decoder. + virtual const bool isBadPacket() const = 0; //!< check if the current packet is an error / bad packet };
inline TrcPktProcI::TrcPktProcI(const char *component_name) : @@ -95,15 +108,15 @@ inline TrcPktProcI::TrcPktProcI(const char *component_name, int instIDNum) : * @brief Packet Processor base class. Provides common infrastructure and interconnections for packet processors. * * The class is a templated base class. - * P - this is the packet object class. - * Pt - this is the packet type class. - * Pc - this is the packet configuration class. + * - P - this is the packet object class. + * - Pt - this is the packet type class. + * - Pc - this is the packet configuration class. * * implementations will provide concrete classes for each of these to operate under the common infrastructures. * The base provides the trace data in (ITrcDataIn) interface and operates on the incoming operation type. * - * Implementions override the 'onFn()' and data process functions, with the base class ensuring consistent - * ordering of operations. + * Implementions override the 'onFn()' and data process functions defined in TrcPktProcI, + * with the base class ensuring consistent ordering of operations. * */ template <class P, class Pt, class Pc> @@ -114,7 +127,11 @@ public: TrcPktProcBase(const char *component_name, int instIDNum); virtual ~TrcPktProcBase();
- /* generic trace data input interface */ + /** Byte trace data input interface defined in ITrcDataIn + + The base class implementation processes the operation to call the + interface functions on TrcPktProcI. + */ virtual ocsd_datapath_resp_t TraceDataIn( const ocsd_datapath_op_t op, const ocsd_trc_index_t index, const uint32_t dataBlockSize, @@ -122,14 +139,20 @@ public: uint32_t *numBytesProcessed);
- /* component attachment points */ +/* component attachment points */ + + //! Attachement point for the protocol packet output componentAttachPt<IPktDataIn<P>> *getPacketOutAttachPt() { return &m_pkt_out_i; }; + //! Attachment point for the protocol packet monitor componentAttachPt<IPktRawDataMon<P>> *getRawPacketMonAttachPt() { return &m_pkt_raw_mon_i; };
+ //! Attachment point for a packet indexer componentAttachPt<ITrcPktIndexer<Pt>> *getTraceIDIndexerAttachPt() { return &m_pkt_indexer_i; };
- /* protocol configuration */ +/* protocol configuration */ + //!< Set the protocol specific configuration for the decoder. virtual ocsd_err_t setProtocolConfig(const Pc *config); + //!< Get the configuration for the decoder. virtual const Pc *getProtocolConfig() const { return m_config; };
protected: diff --git a/decoder/include/interfaces/trc_abs_typed_base_i.h b/decoder/include/interfaces/trc_abs_typed_base_i.h index 034ecd3..0db6077 100644 --- a/decoder/include/interfaces/trc_abs_typed_base_i.h +++ b/decoder/include/interfaces/trc_abs_typed_base_i.h @@ -37,13 +37,14 @@ #define ARM_TRC_ABS_TYPED_BASE_I_H_INCLUDED
/*! - * @class ITrcTypedBase : Abstract base class to for interfaces templated types. + * @class ITrcTypedBase + * @brief Abstract base class to for interfaces templated types. * * This class is used as an abstract base for any interfaces that are specialised using * template<> types. * * Designed to allow interface objects to be passed through generic interfaces into type - * specific templated implmentation handlers. + * specific templated implmentation handlers and converted/checked using RTTI. */ class ITrcTypedBase { diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index f026d4e..f581499 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -511,7 +511,7 @@ typedef enum _ocsd_trace_protocol_t { OCSD_PROTOCOL_BUILTIN_END, /**< Invalid protocol - built-in protocol types end marker */
/* Custom / external decoders */ - OCSD_PROTOCOL_CUSTOM_0 = 100, + OCSD_PROTOCOL_CUSTOM_0 = 100, /**< Values from this onwards are assigned to external registered decoders */ OCSD_PROTOCOL_CUSTOM_1, OCSD_PROTOCOL_CUSTOM_2, OCSD_PROTOCOL_CUSTOM_3, @@ -525,9 +525,11 @@ typedef enum _ocsd_trace_protocol_t { OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ } ocsd_trace_protocol_t;
-#define OCSD_PROTOCOL_IS_BUILTIN(P) ((P > OCSD_PROTOCOL_UNKNOWN) && (P < OCSD_PROTOCOL_BUILTIN_END)) -#define OCSD_PROTOCOL_IS_CUSTOM(P) ((P > OCSD_PROTOCOL_CUSTOM_0) && (P < OCSD_PROTOCOL_END )) +/** Test if protocol type is a library built-in decoder */ +#define OCSD_PROTOCOL_IS_BUILTIN(P) ((P > OCSD_PROTOCOL_UNKNOWN) && (P < OCSD_PROTOCOL_BUILTIN_END))
+/** Test if protocol type is a custom external registered decoder */ +#define OCSD_PROTOCOL_IS_CUSTOM(P) ((P > OCSD_PROTOCOL_CUSTOM_0) && (P < OCSD_PROTOCOL_END ))
/** @}*/
diff --git a/decoder/include/opencsd.h b/decoder/include/opencsd.h index 9ae283b..ad6e2d2 100644 --- a/decoder/include/opencsd.h +++ b/decoder/include/opencsd.h @@ -50,9 +50,6 @@ #include "interfaces/trc_pkt_raw_in_i.h" #include "interfaces/trc_tgt_mem_access_i.h"
-/* TBD : include the indexers and reader interfaces in here when implmented. */ - - /* protocol base classes and generic elements */ #include "common/ocsd_version.h" #include "common/ocsd_error.h" diff --git a/decoder/include/ptm/trc_cmp_cfg_ptm.h b/decoder/include/ptm/trc_cmp_cfg_ptm.h index 5a4dae2..e086aae 100644 --- a/decoder/include/ptm/trc_cmp_cfg_ptm.h +++ b/decoder/include/ptm/trc_cmp_cfg_ptm.h @@ -39,9 +39,9 @@ #include "trc_pkt_types_ptm.h" #include "common/trc_cs_config.h"
-/** @defgroup ocsd_protocol_cfg OpenCSD Library : Protcol Generator Configuration. +/** @defgroup ocsd_protocol_cfg OpenCSD Library : Trace Source Protocol Configuration.
- @brief Classes describing the trace capture time configuration of the protocol generators. + @brief Classes describing the trace capture time configuration of the trace source hardware.
Protocol configuration represents the trace capture time settings for the CoreSight hardware component generating the trace. The packet processors and packet decoders require this configuration diff --git a/decoder/include/trc_gen_elem_types.h b/decoder/include/trc_gen_elem_types.h index a274eb8..3f3108e 100644 --- a/decoder/include/trc_gen_elem_types.h +++ b/decoder/include/trc_gen_elem_types.h @@ -92,7 +92,7 @@ typedef struct _ocsd_generic_trace_elem { ocsd_instr_type last_i_type; /**< Last instruction type if instruction execution range */ ocsd_instr_subtype last_i_subtype; /**< sub type for last instruction in range */
- // per element flags + //! per element flags struct { uint32_t last_instr_exec:1; /**< 1 if last instruction in range was executed; */ uint32_t has_cc:1; /**< 1 if this packet has a valid cycle count included (e.g. cycle count included as part of instruction range packet, always 1 for pure cycle count packet.*/ @@ -101,7 +101,7 @@ typedef struct _ocsd_generic_trace_elem { uint32_t excep_data_marker:1; /**< 1 if the exception entry packet is a data push marker only, with no address information (used typically in v7M trace for marking data pushed onto stack) */ };
- // packet specific payloads + //! packet specific payloads union { uint32_t exception_number; /**< exception number for exception type packets */ trace_event_t trace_event; /**< Trace event - trigger etc */ diff --git a/decoder/tests/source/gen_elem_printer.h b/decoder/tests/source/gen_elem_printer.h index 2ab2e47..f3e9717 100644 --- a/decoder/tests/source/gen_elem_printer.h +++ b/decoder/tests/source/gen_elem_printer.h @@ -1,6 +1,6 @@ /* * \file gen_elem_printer.h - * \brief OpenCSD : + * \brief OpenCSD : Generic element printer class. * * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. */
Extraction of multibyte payload values using the 0x80 cont bit per byte was incorrectly handling the cont bit when extracting the value bits.
Masking added to processing of 32bit and 64 bit payloads. --- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp index 0125788..d7f0fbf 100644 --- a/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp +++ b/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp @@ -1462,7 +1462,7 @@ void EtmV4IPktProcImpl::BuildIPacketTable() // each byte has seven bits + cont bit byteVal = buffer[(st_idx + idx)]; lastByte = (byteVal & 0x80) != 0x80; - value |= ((uint32_t)byteVal) << (idx * 7); + value |= ((uint32_t)(byteVal & 0x7F)) << (idx * 7); idx++; } else @@ -1479,14 +1479,14 @@ unsigned EtmV4IPktProcImpl::extractContField64(const std::vector<uint8_t> &buffe bool lastByte = false; uint8_t byteVal; value = 0; - while(!lastByte && (idx < byte_limit)) // max 9 bytes for 32 bit value; + while(!lastByte && (idx < byte_limit)) // max 9 bytes for 64 bit value; { if(buffer.size() > (st_idx + idx)) { // each byte has seven bits + cont bit byteVal = buffer[(st_idx + idx)]; lastByte = (byteVal & 0x80) != 0x80; - value |= ((uint64_t)byteVal) << (idx * 7); + value |= ((uint64_t)(byteVal & 0x7F)) << (idx * 7); idx++; } else
On 1 August 2016 at 07:19, Mike Leach mike.leach@linaro.org wrote:
Patchset for the OpenCSD 0v004 release.
Updates to allow decoder registration and decoder selection by name. Adds generic handling of decoders in the APIs. First stage in providing custom external decoder interface.
C API and decode tree API updates to use the new functionality.
Updated test programs. C-API test program re-written to use new API and re-names.
Deprecated functionality still available on conditional compile for regression testing.
Signed-off-by: Mike Leach mike.leach@linaro.org
There is usually no need to SoB a cover letter.
Mike Leach (19): opencsd: Updated version numbers to 0v004. opencsd: Updated docs and help opencsd: Add .bash scripts - library testing in perf opencsd: bugfix - ETMv4, PTM - output packet error. opencsd: Add new base class for trace component config. opencsd: Adds abstract base class interface opencsd: adds classes to handle decoder registration and management opencsd: updates to code to utilize decoder registration. opencsd: Add protocol type ID to decoder manager opencsd: DecodeTree modifications - using new API fns. opencsd: bugfix - etmv4 trace info packet opencsd: Updates to decoder registration code opencsd: Update C API functions to reflect new create decoder API. opencsd: Rework memory accessor API on decode tree. opencsd: Udpated linux makefiles for recent code updates. opencsd: Bugfix - initialisation of associated component pointer opencsd: remove C API deprecated types. opencsd: Doxygen comment updates. opencsd: bugfix - extraction of multibyte payload values from packets.
HOWTO.md | 134 +++- README.md | 10 +- decoder/build/linux/makefile | 2 + decoder/build/linux/rctdl_c_api_lib/makefile | 3 +- decoder/build/linux/ref_trace_decode_lib/makefile | 1 + .../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 +- .../ref_trace_decode_lib.vcxproj | 10 + .../ref_trace_decode_lib.vcxproj.filters | 30 + decoder/docs/doxygen_config.dox | 5 +- decoder/include/c_api/ocsd_c_api_deprc_fn.h | 233 ++++++ decoder/include/c_api/ocsd_c_api_types.h | 81 +- decoder/include/c_api/opencsd_c_api.h | 190 ++--- decoder/include/common/comp_attach_pt_t.h | 15 + decoder/include/common/ocsd_dcd_mngr.h | 397 ++++++++++ decoder/include/common/ocsd_dcd_mngr_i.h | 98 +++ decoder/include/common/ocsd_dcd_tree.h | 286 +++++-- decoder/include/common/ocsd_dcd_tree_elem.h | 169 ++--- decoder/include/common/ocsd_lib_dcd_register.h | 122 +++ decoder/include/common/trc_component.h | 22 +- decoder/include/common/trc_cs_config.h | 62 ++ decoder/include/common/trc_gen_elem.h | 6 + decoder/include/common/trc_pkt_decode_base.h | 36 +- decoder/include/common/trc_pkt_proc_base.h | 53 +- decoder/include/etmv3/trc_cmp_cfg_etmv3.h | 6 +- decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 57 ++ decoder/include/etmv4/trc_cmp_cfg_etmv4.h | 102 +-- decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 31 + decoder/include/interfaces/trc_abs_typed_base_i.h | 58 ++ decoder/include/interfaces/trc_indexer_pkt_i.h | 4 +- decoder/include/interfaces/trc_pkt_in_i.h | 4 +- decoder/include/interfaces/trc_pkt_raw_in_i.h | 4 +- decoder/include/ocsd_if_types.h | 88 ++- decoder/include/opencsd.h | 6 +- decoder/include/ptm/trc_cmp_cfg_ptm.h | 55 +- decoder/include/ptm/trc_dcd_mngr_ptm.h | 57 ++ decoder/include/stm/trc_cmp_cfg_stm.h | 55 +- decoder/include/stm/trc_dcd_mngr_stm.h | 55 ++ decoder/include/trc_gen_elem_types.h | 4 +- decoder/source/c_api/ocsd_c_api.cpp | 546 +++++--------- decoder/source/c_api/ocsd_c_api_deprc_fn.cpp | 200 +++++ decoder/source/c_api/ocsd_c_api_obj.h | 57 ++ decoder/source/etmv3/trc_pkt_proc_etmv3.cpp | 2 +- decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp | 40 +- decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp | 14 +- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp | 76 +- decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h | 22 +- decoder/source/ocsd_dcd_tree.cpp | 518 ++++--------- decoder/source/ocsd_error.cpp | 6 + decoder/source/ocsd_lib_dcd_register.cpp | 172 +++++ decoder/source/ptm/trc_cmp_cfg_ptm.cpp | 17 +- decoder/source/ptm/trc_pkt_decode_ptm.cpp | 11 +- decoder/source/trc_component.cpp | 1 + .../build/linux/c_api_pkt_print_test/makefile | 82 ++ .../c_api_pkt_print_test.vcxproj | 325 ++++++++ .../c_api_pkt_print_test.vcxproj.filters | 22 + .../tests/perf-test-scripts/perf-setup-env.bash | 42 ++ .../tests/perf-test-scripts/perf-test-report.bash | 14 + .../tests/perf-test-scripts/perf-test-script.bash | 11 + .../snapshot_parser_lib/source/ss_to_dcdtree.cpp | 65 +- decoder/tests/source/c_api_pkt_print_test.c | 825 +++++++++++++++++++++ decoder/tests/source/gen_elem_printer.h | 2 +- decoder/tests/source/simple_pkt_c_api.c | 1 + decoder/tests/source/trc_pkt_lister.cpp | 30 +- 65 files changed, 4294 insertions(+), 1391 deletions(-) create mode 100644 decoder/include/c_api/ocsd_c_api_deprc_fn.h create mode 100644 decoder/include/common/ocsd_dcd_mngr.h create mode 100644 decoder/include/common/ocsd_dcd_mngr_i.h create mode 100644 decoder/include/common/ocsd_lib_dcd_register.h create mode 100644 decoder/include/common/trc_cs_config.h create mode 100644 decoder/include/etmv3/trc_dcd_mngr_etmv3.h create mode 100644 decoder/include/etmv4/trc_dcd_mngr_etmv4i.h create mode 100644 decoder/include/interfaces/trc_abs_typed_base_i.h create mode 100644 decoder/include/ptm/trc_dcd_mngr_ptm.h create mode 100644 decoder/include/stm/trc_dcd_mngr_stm.h create mode 100644 decoder/source/c_api/ocsd_c_api_deprc_fn.cpp create mode 100644 decoder/source/ocsd_lib_dcd_register.cpp create mode 100644 decoder/tests/build/linux/c_api_pkt_print_test/makefile 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 100755 decoder/tests/perf-test-scripts/perf-setup-env.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-report.bash create mode 100755 decoder/tests/perf-test-scripts/perf-test-script.bash create mode 100644 decoder/tests/source/c_api_pkt_print_test.c
-- 2.7.4
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight