source: rtems-tools/tester/covoar/SymbolTable.cc @ fb987e8

5
Last change on this file since fb987e8 was 100f517, checked in by Chris Johns <chrisj@…>, on 05/09/14 at 11:50:37

covoar: Merger the covoar source from rtems-testing.git.

Use waf to build covoar.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*! @file SymbolTable.cc
2 *  @brief SymbolTable Implementation
3 *
4 *  This file contains ...
5 */
6
7#include <assert.h>
8#include <ctype.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include "SymbolTable.h"
14#include "app_common.h"
15
16namespace Coverage {
17
18  SymbolTable::SymbolTable()
19  {
20  }
21
22  SymbolTable::~SymbolTable()
23  {
24  }
25
26  void SymbolTable::addSymbol(
27    const std::string& symbol,
28    const uint32_t     start,
29    const uint32_t     length
30  )
31  {
32    uint32_t         end = 0;
33    symbol_entry_t   entry;
34    symbolInfo_t     symbolData;
35
36    // Add an entry to the address map.
37    end = start + length - 1;
38    entry.low = start;
39    entry.high = end;
40    entry.symbol = symbol;
41    contents[ end ] = entry;
42
43    // Add an entry to the symbol information map.
44    symbolData.startingAddress = start;
45    symbolData.length = length;
46     
47    if ( info[ symbol ].empty() == false ) {
48      if ( info[ symbol ].front().length != length ) {
49        fprintf(stderr,
50          "ERROR==> Different lengths for the symbol %s (%d and %d)\n",
51          symbol.c_str(),
52          info[ symbol ].front().length,
53          length
54        );
55        exit( 0 );
56      }
57    }
58
59    info[ symbol ].push_back( symbolData );
60  }
61
62  SymbolTable::symbolInfo* SymbolTable::getInfo(
63    const std::string& symbol
64  )
65  {
66    info_t::iterator it = info.find( symbol );
67
68    if (it == info.end())
69      return NULL;
70    else
71      return (&(it->second));
72  }
73
74  uint32_t SymbolTable::getLength(
75    const std::string& symbol
76  )
77  {
78    info_t::iterator it = info.find( symbol );
79
80    if (it == info.end())
81      return 0;
82    else
83      return ((*it).second.front().length);
84  }
85
86  std::string SymbolTable::getSymbol(
87    uint32_t address
88  )
89  {
90    contents_t::iterator it;
91
92    // Ensure that the symbol table is not empty.
93    if ( contents.size() == 0 )
94      return "";
95
96    // Find the first entry whose end address is greater
97    // than the specified address.
98    it = contents.lower_bound( address );
99
100    // If an entry was found and its low address is less than or
101    // equal to the specified address, then return the symbol.
102    if ((it != contents.end()) && ((it->second).low <= address ))
103      return (it->second).symbol;
104
105    return "";
106  }
107
108  void SymbolTable::dumpSymbolTable( void )
109  {
110    symbolInfo                  symbolTable;
111    symbolInfoIterator_t        symbolIterator;
112    infoIterator_t              infoIterator;
113
114    for (infoIterator = info.begin() ; infoIterator != info.end(); infoIterator++)
115    {
116      for (symbolIterator = infoIterator->second.begin() ; symbolIterator != infoIterator->second.end(); symbolIterator++)
117      {
118         fprintf( stdout, "%s:\tStarting address = %#x\tLength = %u\n", infoIterator->first.c_str(), symbolIterator->startingAddress, symbolIterator->length );
119      }
120    }
121  }
122
123}
Note: See TracBrowser for help on using the repository browser.