1 /* -*- Mode: C++ -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is ``elf_symbol_table''
17 * The Initial Developer of the Original Code is Netscape
18 * Communications Corp. Portions created by the Initial Developer are
19 * Copyright (C) 2001 the Initial Developer. All Rights Reserved.
22 * Chris Waterson <waterson@netscape.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef elf_symbol_table_h__
39 #define elf_symbol_table_h__
43 Utility class for reading ELF symbol tables.
50 #include "interval_map.h"
52 class elf_symbol_table
{
58 const Elf32_Sym
*m_symbols
;
62 typedef interval_map
<unsigned int, const Elf32_Sym
*> rsymtab_t
;
65 int verify_elf_header(const Elf32_Ehdr
*hdr
);
71 m_mapping(MAP_FAILED
),
78 ~elf_symbol_table() { finish(); }
81 * Read the symbol table information from the specified file. (This will
82 * memory-map the file.)
84 * Currently, only symbols from the `.text' section are loaded.
86 int init(const char *file
);
89 * Determine what symbol the specified image address corresponds
90 * to. Addresses need not refer to a symbol's start address:
91 * symbol size information is used to reverse-map the address.
93 const Elf32_Sym
*lookup(unsigned int addr
) const;
96 * Determine the symbol name for the specified symbol.
98 const char *get_symbol_name(const Elf32_Sym
*sym
) const;
101 * Return `true' if the specified symbol is a function.
103 bool is_function(const Elf32_Sym
*sym
) const {
104 return (sym
->st_size
> 0) &&
105 (ELF32_ST_TYPE(sym
->st_info
) == STT_FUNC
) &&
106 (sym
->st_shndx
== m_text_shndx
); }
108 typedef const Elf32_Sym
*const_iterator
;
110 const_iterator
begin() const { return const_iterator(m_symbols
); }
111 const_iterator
end() const { return const_iterator(m_symbols
+ m_nsymbols
); }
114 #endif // elf_symbol_table_h__