summaryrefslogtreecommitdiffstats
path: root/covoar/SymbolTable.h
blob: 35321336a3f98a1c5fbf764f7107581f00dda47d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 *  $Id$
 */

/*! @file SymbolTable.h
 *  @brief SymbolTable Specification
 *
 *  This file contains the specification of the SymbolTable class.
 */

#ifndef __SYMBOLTABLE_H__
#define __SYMBOLTABLE_H__

#include <stdint.h>
#include <string>
#include <map>
#include <list>

namespace Coverage {

  /*! @class SymbolTable
   *
   *  This class maintains information for each desired symbol within an
   *  executable.  A desired symbol is a symbol for which analysis is to
   *  be performed.
   */
  class SymbolTable {

  public:

    /*!
     *  This structure defines the information kept for each symbol.
     */
    typedef struct {
      uint32_t startingAddress;
      uint32_t length;
    } symbolInfo_t;
 
   typedef std::list< symbolInfo_t > symbolInfo;
   typedef std::list< symbolInfo_t >::iterator	symbolInfoIterator_t;
 
    

    /*!
     *  This method constructs a SymbolTable instance.
     */
    SymbolTable();

    /*!
     *  This method destructs a SymbolTable instance.
     */
    virtual ~SymbolTable();

    /*!
     *  This method adds the specified symbol information to the
     *  symbol table.
     *
     *  @param[in] symbol specifies the symbol to add
     *  @param[in] start specifies the symbol's start address
     *  @param[in] length specifies the symbol's length
     *
     */
    void addSymbol(
      const std::string& symbol,
      const uint32_t     start,
      const uint32_t     length
    );

    /*!
     *  This method returns the symbol information for the specified symbol.
     *
     *  @param[in] symbol specifies the symbol for which to obtain information
     *
     *  @return Returns a pointer to the symbol information
     */
    symbolInfo* getInfo(
      const std::string& symbol
    );

    /*!
     *  This method returns the length in bytes of the specified symbol.
     *
     *  @param[in] symbol specifies the symbol for which to obtain the length
     *
     *  @return Returns the length of the symbol
     */
    uint32_t getLength(
      const std::string& symbol
    );

    /*!
     *  This method returns the symbol that contains the specified address.
     *
     *  @param[in] address specifies the address for which to obtain the symbol
     *
     *  @return Returns the symbol containing the address
     */
    std::string getSymbol(
      uint32_t address
    );

    /*!
     *  This method prints SymbolTable content to stdout
     *
     */
    void dumpSymbolTable( void );

  private:

    /*!
     *  This map associates the end address of a symbol's address
     *  range with the symbol's address range definition.
     */
    typedef struct {
       uint32_t    low;
       uint32_t    high;
       std::string symbol;
    } symbol_entry_t;
    typedef std::map< uint32_t, symbol_entry_t > contents_t;
    contents_t contents;

    /*!
     *  This map associates each symbol from an executable with
     *  the symbol's information.
     */
    typedef std::map<std::string, symbolInfo> info_t;
    typedef std::map<std::string, symbolInfo>::iterator infoIterator_t;
    info_t info;

  };
}
#endif