summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/plugins/symbols.H
blob: 3ff38289813201eb20ea4163e95c7850008c6447 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/errl/plugins/symbols.H $                              */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */





#ifndef ERRL_PLUGINS_SYMS_H
#define ERRL_PLUGINS_SYMS_H

#include <vector>
#include <stdint.h>

/**
 *  @file symbols.H
 *
 *  @brief read HB symbols file and provide a lookup mechanism.
 *
 */


/**
 *  @brief  hbSymbol
 *
 *  This class contains the data from a line of the HB syms file.
 */

class hbSymbol
{
    public:

    // Data from a line from hbicore.syms
    uint64_t  iv_Address;
    uint64_t  iv_Length;
    char *    iv_pszName;

    // The char in column 1 of hbicore.syms
    int       iv_Type;

    hbSymbol();

    /** @brief Set the starting address of the symbol.
     */
    void setAddress( const char * i_pszAddress );


    /** @brief Set the length of the data over which
     *  this symbol spans.
     */
    void setLength( const char * i_pszLength );


    /** @brief Set the symbol name.
     */
    void setSymbolName( char * i_pszName );


    /** @brief Set the type of symbol. This is
     *  the char found in column 1 of Hostboot
     *  symbol files.  F is function, V is variable.
     */
    void setType( int i_type );


    /** @brief Checks to see if all four set functions
     *  have been called.  If so, then this symbol is considered
     *  valid.  These symbols are built piecemeal as values are
     *  scanned from the input line of text.
     */
    bool isValid();


    ~hbSymbol();

    // A validation scheme, since instance
    // vars are set piecemeal.
    enum
    {
        ADDRESS  =  0x0001,
        LENGTH   =  0x0002,
        NAME     =  0x0004,
        TYPE     =  0x0008,
    };

    private:
    int iv_validationBits;

};






/**
 * @brief  hbSymbolTable
 *
 * Container for hbSymbols with methods to initialize and access.
 */


class hbSymbolTable
{
    public:

    /** @brief Contructor. To use: create instance, then
     *  call readSymbols() to populate the symbol table.
     *  Then call nearestSymbol().
     */
    hbSymbolTable();

    /** @brief Read the symbols file, return zero for success.
     *  On success, then you can call nearestSymbol()
     */
    int readSymbols( const char * i_filename );

    /** @brief Find and return the nearest symbol for the address given.
     *  Returns null when not found.
     */
    char * nearestSymbol( uint64_t  i_address );

    /** @brief Destructor.
     */
    ~hbSymbolTable();

    private:

    bool iv_fPopulated;
    char * iv_pFileName;
    std::vector<hbSymbol*> iv_vecSymbols;

    // Read the file and populate the symbol vector.
    int populateSymbolVector();

    // Given the address, find the vector index of the symbol.
    // Return -1 if not found.
    // Return 0 for exact match.
    // Return 1 for nearest (previous) symbol
    int locateSymbol( uint64_t i_address, int & o_index );
};



#endif       // ERRL_PLUGINS_SYMS_H

OpenPOWER on IntegriCloud