1 /* 2 * \file snapshot_parser.h 3 * \brief OpenCSD : Snapshot Parser Library 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_SNAPSHOT_PARSER_H_INCLUDED 36 #define ARM_SNAPSHOT_PARSER_H_INCLUDED 37 38 #include <cstdint> 39 #include <sstream> 40 #include <exception> 41 #include <string> 42 #include <vector> 43 #include <map> 44 #include <istream> 45 46 #include "snapshot_parser_util.h" 47 #include "snapshot_info.h" 48 49 class ITraceErrorLog; // forward declare the OCSD error log interface. 50 51 namespace Parser 52 { 53 //! \brief Stores a parsed [dump] section 54 struct DumpDef 55 { 56 uint64_t address; 57 std::string path; 58 std::size_t length; 59 std::size_t offset; 60 std::string space; 61 }; 62 63 64 65 //! \brief Stores the entire parsed device ini file 66 struct Parsed 67 { ParsedParsed68 Parsed() : foundGlobal() {} 69 70 bool foundGlobal; 71 std::string core; 72 std::vector<DumpDef> dumpDefs; 73 std::map<std::string, 74 std::string, // register value is stored as a string initially to cope with > 64 bit registers 75 Util::CaseInsensitiveLess> regDefs; 76 std::map<uint32_t, uint32_t> extendRegDefs; 77 std::string deviceName; 78 std::string deviceClass; 79 std::string deviceTypeName; // Cortex-Ax or ETMvN 80 81 82 }; 83 /*! \brief Parse the device ini file and call back on the builder as appropriate. 84 * \param input the ini file 85 * \return parsed definitions 86 */ 87 Parsed ParseSingleDevice(std::istream& input); 88 89 //! \brief Stores the entire device list 90 struct ParsedDevices 91 { 92 std::map<std::string, std::string> deviceList; 93 SnapshotInfo snapshotInfo; 94 std::string traceMetaDataName; 95 }; 96 97 /*! \brief Parse the snapshot.ini file that contains the device list and call back on the builder as appropriate. 98 * \param input the ini file 99 * \return parsed definitions 100 */ 101 ParsedDevices ParseDeviceList(std::istream& input); 102 103 // basic info about the buffer 104 struct TraceBufferInfo 105 { 106 std::string bufferName; 107 std::string dataFileName; 108 std::string dataFormat; 109 }; 110 111 // list of buffers and associations as presented in the ini file. 112 struct ParsedTrace 113 { 114 std::vector<std::string> buffer_section_names; 115 std::vector<TraceBufferInfo> trace_buffers; 116 std::map<std::string, std::string> source_buffer_assoc; // trace source name -> trace buffer name assoc 117 std::map<std::string, std::string> cpu_source_assoc; // trace source name -> cpu_name assoc 118 }; 119 120 // single buffer information containing just the assoc for the buffer 121 // -> created by processing the ini data for a single named buffer. 122 // this can then be used to create a decode tree in the decode library. 123 struct TraceBufferSourceTree 124 { 125 TraceBufferInfo buffer_info; 126 std::map<std::string, std::string> source_core_assoc; // list of source names attached to core device names (e.g. ETM_0:cpu_0) 127 }; 128 129 // parse the trace metadata ini file. 130 ParsedTrace ParseTraceMetaData(std::istream& input); 131 132 // build a source tree for a single buffer 133 bool ExtractSourceTree(const std::string &buffer_name, ParsedTrace &metadata, TraceBufferSourceTree &buffer_data); 134 135 std::vector<std::string> GetBufferNameList(ParsedTrace &metadata); 136 137 138 static ITraceErrorLog *s_pErrorLogger = 0; 139 static ocsd_hndl_err_log_t s_errlog_handle = 0; 140 static bool s_verbose_logging = true; 141 142 void SetIErrorLogger(ITraceErrorLog *i_err_log); 143 void SetVerboseLogging(bool verbose); 144 ITraceErrorLog *GetIErrorLogger(); 145 void LogInfoStr(const std::string &logMsg); 146 147 148 } 149 150 #endif // ARM_SNAPSHOT_PARSER_H_INCLUDED 151 152 /* End of File snapshot_parser.h */ 153