Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
blfwk::SourceFile Class Referenceabstract

Abstract base class for a source file containing executable code. More...

#include <SourceFile.h>

+ Inheritance diagram for blfwk::SourceFile:
+ Collaboration diagram for blfwk::SourceFile:

Public Types

enum  source_file_t {
  kBinarySourceFile,
  kELFSourceFile,
  kIntelHexSourceFile,
  kSBSourceFile,
  kSRecordSourceFile
}
 Set of supported executable image file formats. More...
 

Public Member Functions

 SourceFile (const std::string &path, source_file_t filetype)
 Default constructor.
 
virtual ~SourceFile ()
 Destructor. More...
 
void setOptions (OptionContext *context)
 Set the option context. More...
 
const OptionContextgetOptions () const
 Return the option context.
 
source_file_t getFileType () const
 Return the file type.
 
const std::string & getPath () const
 Returns the path to the file.
 
unsigned getSize () const
 Get the size in bytes of the file.
 
Opening and closing
virtual void open ()
 Opens the file. More...
 
virtual void close ()
 Closes the file.
 
virtual bool isOpen () const
 Returns whether the file is already open.
 
Format capabilities
virtual bool supportsNamedSections () const =0
 
virtual bool supportsNamedSymbols () const =0
 
Data source creation
virtual DataSourcecreateDataSource ()=0
 Creates a data source from the entire file.
 
virtual DataSourcecreateDataSource (StringMatcher &matcher)
 Creates a data source out of one or more sections of the file. More...
 
virtual DataSourcecreateDataSource (const std::string &section)
 Creates a data source out of one section of the file. More...
 
Entry point
virtual bool hasEntryPoint ()=0
 Returns true if an entry point was set in the file.
 
virtual uint32_t getEntryPointAddress ()
 Returns the entry point address.
 
Data target creation
virtual DataTargetcreateDataTargetForSection (const std::string &section)
 
virtual DataTargetcreateDataTargetForSymbol (const std::string &symbol)
 
virtual DataTargetcreateDataTargetForEntryPoint ()
 
Symbols
virtual bool hasSymbol (const std::string &name)
 Returns whether a symbol exists in the source file.
 
virtual uint32_t getSymbolValue (const std::string &name)
 Returns the value of a symbol.
 
virtual unsigned getSymbolSize (const std::string &name)
 Returns the size of a symbol.
 

Static Public Member Functions

static SourceFileopenFile (const std::string &path)
 

Protected Member Functions

std::ifstream * getStream ()
 Internal access to the input stream object.
 

Protected Attributes

std::string m_path
 Path to the file.
 
smart_ptr< std::ifstream > m_stream
 File stream, or NULL if file is closed.
 
smart_ptr< OptionContextm_options
 Table of option values.
 
source_file_t m_filetype
 Image file type.
 
unsigned m_size
 The size in bytes of the file.
 

Detailed Description

Abstract base class for a source file containing executable code.

The purpose of this class cluster is to provide a common interface for accessing the contents of different file formats. This is accomplished through several small sets of methods along with the DataSource and DataTarget classes.

The primary interface for creating instances of SourceFile is the static SourceFile::openFile() function. It will create the correct subclass of SourceFile by inspecting the file to determine its type.

Member Enumeration Documentation

Set of supported executable image file formats.

Enumerator
kBinarySourceFile 
See also
blfwk::BinarySourceFile
kELFSourceFile 
See also
blfwk::ELFSourceFile
kIntelHexSourceFile 
See also
blfwk::IntelHexSourceFile
kSBSourceFile 
See also
blfwk::SBSourceFile
kSRecordSourceFile 
See also
blfwk::SRecordSourceFile

Constructor & Destructor Documentation

SourceFile::~SourceFile ( )
virtual

Destructor.

The file is closed if it had been left opened.

Member Function Documentation

virtual DataSource* blfwk::SourceFile::createDataSource ( StringMatcher matcher)
inlinevirtual

Creates a data source out of one or more sections of the file.

The selector object is used to perform the section name comparison. If the file does not support named sections, or if there is not a section with the given name, this method may return NULL.

Reimplemented in blfwk::ELFSourceFile.

DataSource * SourceFile::createDataSource ( const std::string &  section)
virtual

Creates a data source out of one section of the file.

If the file does not support named sections, or if there is not a section with the given name, this method may return NULL.

This method is just a small wrapper that creates an FixedMatcher string matcher instance and uses the createDataSource() that takes a reference to a StringMatcher.

void SourceFile::open ( )
virtual

Opens the file.

Exceptions
std::runtime_errorRaised if the file could not be opened successfully.

Reimplemented in blfwk::ELFSourceFile, blfwk::SRecordSourceFile, and blfwk::IntelHexSourceFile.

SourceFile * SourceFile::openFile ( const std::string &  path)
static

The supported file types are currently:

  • ELF files
  • Motorola S-record files
  • Binary files
  • SB files
  • Intel Hex files

Any file that is not picked up by the other subclasses will result in a an instance of BinaryDataFile.

Returns
An instance of the correct subclass of SourceFile for the given path.
Exceptions
std::runtime_errorThrown if the file cannot be opened.
See also
blfwk::ELFSourceFile
blfwk::SRecordSourceFile
blfwk::BinarySourceFile
blfwk::SBSourceFile
blfwk::IntelHexSourceFile
void blfwk::SourceFile::setOptions ( OptionContext context)
inline

Set the option context.

The source file will take ownership of the context and delete it when the source file is itself deleted.


The documentation for this class was generated from the following files: