symtab.hh revision 1762
12330SN/A/*
22330SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32330SN/A * All rights reserved.
42330SN/A *
52330SN/A * Redistribution and use in source and binary forms, with or without
62330SN/A * modification, are permitted provided that the following conditions are
72330SN/A * met: redistributions of source code must retain the above copyright
82330SN/A * notice, this list of conditions and the following disclaimer;
92330SN/A * redistributions in binary form must reproduce the above copyright
102330SN/A * notice, this list of conditions and the following disclaimer in the
112330SN/A * documentation and/or other materials provided with the distribution;
122330SN/A * neither the name of the copyright holders nor the names of its
132330SN/A * contributors may be used to endorse or promote products derived from
142330SN/A * this software without specific prior written permission.
152330SN/A *
162330SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172330SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182330SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192330SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202330SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212330SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222330SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232330SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242330SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252330SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262330SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu */
282689Sktlim@umich.edu
292330SN/A#ifndef __SYMTAB_HH__
302292SN/A#define __SYMTAB_HH__
312292SN/A
322292SN/A#include <map>
332292SN/A#include "targetarch/isa_traits.hh"	// for Addr
342980Sgblack@eecs.umich.edu
356658Snate@binkert.orgclass SymbolTable
368229Snate@binkert.org{
372362SN/A  private:
382680Sktlim@umich.edu    typedef std::map<Addr, std::string> ATable;
392683Sktlim@umich.edu    typedef std::map<std::string, Addr> STable;
402683Sktlim@umich.edu
412678Sktlim@umich.edu    ATable addrTable;
422292SN/A    STable symbolTable;
432292SN/A
442292SN/A  public:
453548Sgblack@eecs.umich.edu    SymbolTable() {}
463548Sgblack@eecs.umich.edu    SymbolTable(const std::string &file) { load(file); }
473548Sgblack@eecs.umich.edu    ~SymbolTable() {}
483548Sgblack@eecs.umich.edu
492330SN/A    bool insert(Addr address, std::string symbol);
502292SN/A    bool load(const std::string &file);
512862Sktlim@umich.edu
528706Sandreas.hansson@arm.com    /// Find the nearest symbol equal to or less than the supplied
538706Sandreas.hansson@arm.com    /// address (e.g., the label for the enclosing function).
548706Sandreas.hansson@arm.com    /// @param address The address to look up.
552862Sktlim@umich.edu    /// @param symbol  Return reference for symbol string.
562330SN/A    /// @param sym_address Return reference for symbol address.
572330SN/A    /// @param next_sym_address Address of following symbol (for
582330SN/A    /// determining valid range of symbol).
592330SN/A    /// @retval True if a symbol was found.
602330SN/A    bool findNearestSymbol(Addr address, std::string &symbol,
612330SN/A                           Addr &sym_address, Addr &next_sym_address) const;
622292SN/A
632683Sktlim@umich.edu    /// Overload for findNearestSymbol() for callers who don't care
642683Sktlim@umich.edu    /// about next_sym_address.
656331Sgblack@eecs.umich.edu    bool findNearestSymbol(Addr address, std::string &symbol,
662683Sktlim@umich.edu                           Addr &sym_address) const
673486Sktlim@umich.edu    {
683486Sktlim@umich.edu        Addr dummy;
692862Sktlim@umich.edu        return findNearestSymbol(address, symbol, sym_address, dummy);
702862Sktlim@umich.edu    }
712862Sktlim@umich.edu
722862Sktlim@umich.edu
735712Shsul@eecs.umich.edu    bool findSymbol(Addr address, std::string &symbol) const;
742683Sktlim@umich.edu    bool findAddress(const std::string &symbol, Addr &address) const;
755714Shsul@eecs.umich.edu};
765714Shsul@eecs.umich.edu
775714Shsul@eecs.umich.edu/// Global unified debugging symbol table (for target).  Conceptually
785714Shsul@eecs.umich.edu/// there should be one of these per System object for full system,
796221Snate@binkert.org/// and per Process object for non-full-system, but so far one big
802683Sktlim@umich.edu/// global one has worked well enough.
816221Snate@binkert.orgextern SymbolTable *debugSymbolTable;
822683Sktlim@umich.edu
832683Sktlim@umich.edu#endif // __SYMTAB_HH__
842683Sktlim@umich.edu