OpenCSD - CoreSight Trace Decode Library  1.3.3
trc_mem_acc_file.h
Go to the documentation of this file.
1 /*
2  * \file trc_mem_acc_file.h
3  * \brief OpenCSD : Access binary target memory file
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_TRC_MEM_ACC_FILE_H_INCLUDED
36 #define ARM_TRC_MEM_ACC_FILE_H_INCLUDED
37 
38 #include <map>
39 #include <string>
40 #include <fstream>
41 #include <list>
42 
43 #include "opencsd/ocsd_if_types.h"
45 
46 // an add-on region to a file - allows setting of a region at a none-zero offset for a file.
48 {
49 public:
51  virtual ~FileRegionMemAccessor() {};
52 
53  void setOffset(const size_t offset) { m_file_offset = offset; };
54  const size_t getOffset() const { return m_file_offset; };
55 
56  bool operator<(const FileRegionMemAccessor& rhs) { return this->m_startAddress < rhs.m_startAddress; };
57 
58  // not going to use these objects to read bytes - defer to the file class for that.
59  virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer) { return 0; };
60 
61  const ocsd_vaddr_t regionStartAddress() const { return m_startAddress; };
62 
63 private:
64  size_t m_file_offset;
65 };
66 
77 {
78 public:
80  virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer);
81 
82 protected:
87  void IncRefCount() { m_ref_count++; };
88 
90  void DecRefCount() { m_ref_count--; };
91 
93  const int getRefCount() const { return m_ref_count; };
94 
104  ocsd_err_t initAccessor(const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset, size_t size);
105 
107  const std::string &getFilePath() const { return m_file_path; };
108 
111 
112  /* validate ranges */
113  virtual const bool validateRange();
114 
115 public:
116 
126  bool AddOffsetRange(const ocsd_vaddr_t startAddr, const size_t size, const size_t offset);
127 
135  virtual const bool addrInRange(const ocsd_vaddr_t s_address) const;
136 
144  virtual const bool addrStartOfRange(const ocsd_vaddr_t s_address) const;
145 
156  virtual const uint32_t bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const;
157 
165  virtual const bool overLapRange(const TrcMemAccessorBase *p_test_acc) const;
166 
168  virtual void getMemAccString(std::string &accStr) const;
169 
170 
185  static ocsd_err_t createFileAccessor(TrcMemAccessorFile **p_acc, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset = 0, size_t size = 0);
186 
194  static void destroyFileAccessor(TrcMemAccessorFile *p_accessor);
195 
203  static const bool isExistingFileAccessor(const std::string &pathToFile);
204 
214  static TrcMemAccessorFile * getExistingFileAccessor(const std::string &pathToFile);
215 
216 
217 
218 
219 private:
220  static std::map<std::string, TrcMemAccessorFile *> s_FileAccessorMap;
222 private:
223  std::ifstream m_mem_file;
224  ocsd_vaddr_t m_file_size;
225  int m_ref_count;
226  std::string m_file_path;
227  std::list<FileRegionMemAccessor *> m_access_regions;
228  bool m_base_range_set;
229  bool m_has_access_regions;
230 };
231 
232 #endif // ARM_TRC_MEM_ACC_FILE_H_INCLUDED
233 
234 /* End of File trc_mem_acc_file.h */
virtual ~FileRegionMemAccessor()
const size_t getOffset() const
const ocsd_vaddr_t regionStartAddress() const
void setOffset(const size_t offset)
bool operator<(const FileRegionMemAccessor &rhs)
virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer)
Memory range to access by trace decoder.
ocsd_vaddr_t m_startAddress
Memory accessor for a binary file.
bool AddOffsetRange(const ocsd_vaddr_t startAddr, const size_t size, const size_t offset)
virtual const bool addrInRange(const ocsd_vaddr_t s_address) const
FileRegionMemAccessor * getRegionForAddress(const ocsd_vaddr_t startAddr) const
static const bool isExistingFileAccessor(const std::string &pathToFile)
virtual const uint32_t bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const
virtual const bool validateRange()
const int getRefCount() const
static void destroyFileAccessor(TrcMemAccessorFile *p_accessor)
const std::string & getFilePath() const
ocsd_err_t initAccessor(const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset, size_t size)
virtual void getMemAccString(std::string &accStr) const
virtual const bool overLapRange(const TrcMemAccessorBase *p_test_acc) const
virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer)
virtual ~ TrcMemAccessorFile()
virtual const bool addrStartOfRange(const ocsd_vaddr_t s_address) const
static TrcMemAccessorFile * getExistingFileAccessor(const std::string &pathToFile)
static ocsd_err_t createFileAccessor(TrcMemAccessorFile **p_acc, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset=0, size_t size=0)
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
enum _ocsd_err_t ocsd_err_t
uint64_t ocsd_vaddr_t
OpenCSD : Standard Types used in the library interfaces.
OpenCSD : Memory accessor base class.