Loading...
Searching...
No Matches
trc_mem_acc_file.h
Go to the documentation of this file.
/*
* \file trc_mem_acc_file.h
* \brief OpenCSD : Access binary target memory file
*
* \copyright Copyright (c) 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.
*/
#ifndef ARM_TRC_MEM_ACC_FILE_H_INCLUDED
#define ARM_TRC_MEM_ACC_FILE_H_INCLUDED
#include <map>
#include <string>
#include <fstream>
#include <list>
#include "opencsd/ocsd_if_types.h"
#include "mem_acc/trc_mem_acc_base.h"
// an add-on region to a file - allows setting of a region at a none-zero offset for a file.
class FileRegionMemAccessor : public TrcMemAccessorBase
{
public:
FileRegionMemAccessor() : TrcMemAccessorBase(MEMACC_FILE) {};
virtual ~FileRegionMemAccessor() {};
void setOffset(const size_t offset) { m_file_offset = offset; };
const size_t getOffset() const { return m_file_offset; };
bool operator<(const FileRegionMemAccessor& rhs) { return this->m_startAddress < rhs.m_startAddress; };
// not going to use these objects to read bytes - defer to the file class for that.
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; };
const ocsd_vaddr_t regionStartAddress() const { return m_startAddress; };
private:
size_t m_file_offset;
};
class TrcMemAccessorFile : public TrcMemAccessorBase
{
public:
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);
protected:
TrcMemAccessorFile();
virtual ~ TrcMemAccessorFile();
void IncRefCount() { m_ref_count++; };
void DecRefCount() { m_ref_count--; };
const int getRefCount() const { return m_ref_count; };
ocsd_err_t initAccessor(const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset, size_t size);
const std::string &getFilePath() const { return m_file_path; };
FileRegionMemAccessor *getRegionForAddress(const ocsd_vaddr_t startAddr) const;
/* validate ranges */
virtual const bool validateRange();
public:
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;
virtual const bool addrStartOfRange(const ocsd_vaddr_t s_address) const;
virtual const uint32_t bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const;
virtual const bool overLapRange(const TrcMemAccessorBase *p_test_acc) const;
virtual void getMemAccString(std::string &accStr) const;
static ocsd_err_t createFileAccessor(TrcMemAccessorFile **p_acc, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset = 0, size_t size = 0);
static void destroyFileAccessor(TrcMemAccessorFile *p_accessor);
static const bool isExistingFileAccessor(const std::string &pathToFile);
static TrcMemAccessorFile * getExistingFileAccessor(const std::string &pathToFile);
private:
static std::map<std::string, TrcMemAccessorFile *> s_FileAccessorMap;
private:
std::ifstream m_mem_file;
ocsd_vaddr_t m_file_size;
int m_ref_count;
std::string m_file_path;
std::list<FileRegionMemAccessor *> m_access_regions;
bool m_base_range_set;
bool m_has_access_regions;
};
#endif // ARM_TRC_MEM_ACC_FILE_H_INCLUDED
/* End of File trc_mem_acc_file.h */
FileRegionMemAccessor
Definition trc_mem_acc_file.h:48
FileRegionMemAccessor::~FileRegionMemAccessor
virtual ~FileRegionMemAccessor()
Definition trc_mem_acc_file.h:51
FileRegionMemAccessor::getOffset
const size_t getOffset() const
Definition trc_mem_acc_file.h:54
FileRegionMemAccessor::regionStartAddress
const ocsd_vaddr_t regionStartAddress() const
Definition trc_mem_acc_file.h:61
FileRegionMemAccessor::setOffset
void setOffset(const size_t offset)
Definition trc_mem_acc_file.h:53
FileRegionMemAccessor::operator<
bool operator<(const FileRegionMemAccessor &rhs)
Definition trc_mem_acc_file.h:56
FileRegionMemAccessor::readBytes
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)
Definition trc_mem_acc_file.h:59
FileRegionMemAccessor::FileRegionMemAccessor
FileRegionMemAccessor()
Definition trc_mem_acc_file.h:50
TrcMemAccessorBase
Memory range to access by trace decoder.
Definition trc_mem_acc_base.h:53
TrcMemAccessorBase::MEMACC_FILE
@ MEMACC_FILE
Definition trc_mem_acc_base.h:59
TrcMemAccessorBase::m_startAddress
ocsd_vaddr_t m_startAddress
Definition trc_mem_acc_base.h:153
TrcMemAccessorFile
Memory accessor for a binary file.
Definition trc_mem_acc_file.h:77
TrcMemAccessorFile::AddOffsetRange
bool AddOffsetRange(const ocsd_vaddr_t startAddr, const size_t size, const size_t offset)
TrcMemAccessorFile::addrInRange
virtual const bool addrInRange(const ocsd_vaddr_t s_address) const
TrcMemAccessorFile::isExistingFileAccessor
static const bool isExistingFileAccessor(const std::string &pathToFile)
TrcMemAccessorFile::bytesInRange
virtual const uint32_t bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const
TrcMemAccessorFile::DecRefCount
void DecRefCount()
Definition trc_mem_acc_file.h:90
TrcMemAccessorFile::IncRefCount
void IncRefCount()
Definition trc_mem_acc_file.h:87
TrcMemAccessorFile::validateRange
virtual const bool validateRange()
TrcMemAccessorFile::getRegionForAddress
FileRegionMemAccessor * getRegionForAddress(const ocsd_vaddr_t startAddr) const
TrcMemAccessorFile::getRefCount
const int getRefCount() const
Definition trc_mem_acc_file.h:93
TrcMemAccessorFile::destroyFileAccessor
static void destroyFileAccessor(TrcMemAccessorFile *p_accessor)
TrcMemAccessorFile::initAccessor
ocsd_err_t initAccessor(const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset, size_t size)
TrcMemAccessorFile::getExistingFileAccessor
static TrcMemAccessorFile * getExistingFileAccessor(const std::string &pathToFile)
TrcMemAccessorFile::getMemAccString
virtual void getMemAccString(std::string &accStr) const
TrcMemAccessorFile::overLapRange
virtual const bool overLapRange(const TrcMemAccessorBase *p_test_acc) const
TrcMemAccessorFile::readBytes
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)
TrcMemAccessorFile::addrStartOfRange
virtual const bool addrStartOfRange(const ocsd_vaddr_t s_address) const
TrcMemAccessorFile::createFileAccessor
static ocsd_err_t createFileAccessor(TrcMemAccessorFile **p_acc, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset=0, size_t size=0)
TrcMemAccessorFile::getFilePath
const std::string & getFilePath() const
Definition trc_mem_acc_file.h:107
TrcMemAccessorFile::TrcMemAccessorFile
TrcMemAccessorFile()
ocsd_mem_space_acc_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
ocsd_vaddr_t
uint64_t ocsd_vaddr_t
Definition ocsd_if_types.h:310
ocsd_if_types.h
OpenCSD : Standard Types used in the library interfaces.
trc_mem_acc_base.h
OpenCSD : Memory accessor base class.