1 /*
2  * \file       ss_to_dcdtree.h
3  * \brief      OpenCSD : Create a decode tree given a snapshot database.
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 /*
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ARM_SS_TO_DCDTREE_H_INCLUDED
36 #define ARM_SS_TO_DCDTREE_H_INCLUDED
37 
38 #include <string>
39 
40 #include "opencsd.h"
41 #include "snapshot_parser.h"
42 #include "snapshot_reader.h"
43 
44 class DecodeTree;
45 class ITraceErrorLog;
46 
47 class CreateDcdTreeFromSnapShot
48 {
49 public:
50     CreateDcdTreeFromSnapShot();
51     ~CreateDcdTreeFromSnapShot();
52 
53     void initialise(SnapShotReader *m_pReader, ITraceErrorLog *m_pErrLogInterface);
54 
55     bool createDecodeTree(const std::string &SourceBufferName, bool bPacketProcOnly, uint32_t add_create_flags = 0);
56     void destroyDecodeTree();
getDecodeTree()57     DecodeTree *getDecodeTree() const { return m_pDecodeTree; };
getBufferFileName()58     const char *getBufferFileName() const { return m_BufferFileName.c_str(); };
59 
60     // TBD: add in filters for ID list, first ID found.
61 
62 private:
63     // create a decoder related to a core source (ETM, PTM)
64     bool createPEDecoder(const std::string &coreName, Parser::Parsed *devSrc);
65     // protocol specific core source decoders
66     bool createETMv4Decoder(const std::string &coreName, Parser::Parsed *devSrc, const bool bDataChannel = false);
67     bool createETMv3Decoder(const std::string &coreName, Parser::Parsed *devSrc);
68     bool createPTMDecoder(const std::string &coreName, Parser::Parsed *devSrc);
69     bool createETEDecoder(const std::string &coreName, Parser::Parsed *devSrc);
70     // TBD add etmv4d
71 
72     // create a decoder related to a software trace source (ITM, STM)
73     bool createSTDecoder(Parser::Parsed *devSrc);
74     // protocol specific decoders
75     bool createSTMDecoder(Parser::Parsed *devSrc);
76 
77     typedef struct _regs_to_access {
78         const char *pszName;
79         bool failIfMissing;
80         uint32_t *value;
81         uint32_t val_default;
82     } regs_to_access_t;
83 
84     bool getRegisters(std::map<std::string, std::string, Util::CaseInsensitiveLess> &regDefs, int numRegs, regs_to_access_t *reg_access_array);
85     bool getRegByPrefix(std::map<std::string, std::string, Util::CaseInsensitiveLess> &regDefs,
86                         regs_to_access_t &reg_accessor);
87     bool getCoreProfile(const std::string &coreName, ocsd_arch_version_t &arch_ver, ocsd_core_profile_t &core_prof);
88 
89     void LogError(const std::string &msg);
90     void LogError(const ocsdError &err);
91 
92     void processDumpfiles(std::vector<Parser::DumpDef> &dumps);
93 
94 
95     uint32_t m_add_create_flags;
96 
97     bool m_bInit;
98     DecodeTree *m_pDecodeTree;
99     SnapShotReader *m_pReader;
100     ITraceErrorLog *m_pErrLogInterface;
101     ocsd_hndl_err_log_t m_errlog_handle;
102 
103     bool m_bPacketProcOnly;
104     std::string m_BufferFileName;
105 
106     CoreArchProfileMap m_arch_profiles;
107 };
108 
109 
110 #endif // ARM_SS_TO_DCDTREE_H_INCLUDED
111 
112 /* End of File ss_to_dcdtree.h */
113