1/*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef SHARE_UTILITIES_ELFSYMBOLTABLE_HPP
26#define SHARE_UTILITIES_ELFSYMBOLTABLE_HPP
27
28#if !defined(_WINDOWS) && !defined(__APPLE__)
29
30
31#include "memory/allocation.hpp"
32#include "utilities/decoder.hpp"
33#include "utilities/elfFile.hpp"
34
35/*
36 * symbol table object represents a symbol section in an elf file.
37 * Whenever possible, it will load all symbols from the corresponding section
38 * of the elf file into memory. Otherwise, it will walk the section in file
39 * to look up the symbol that nearest the given address.
40 */
41class ElfSymbolTable: public CHeapObj<mtInternal> {
42 friend class ElfFile;
43private:
44 ElfSymbolTable* _next;
45
46 // file contains string table
47 FILE* const _fd;
48
49 // corresponding section
50 ElfSection _section;
51
52 NullDecoder::decoder_status _status;
53public:
54 ElfSymbolTable(FILE* const file, Elf_Shdr& shdr);
55 ~ElfSymbolTable();
56
57 // search the symbol that is nearest to the specified address.
58 bool lookup(address addr, int* stringtableIndex, int* posIndex, int* offset, ElfFuncDescTable* funcDescTable);
59
60 NullDecoder::decoder_status get_status() const { return _status; };
61private:
62 ElfSymbolTable* next() const { return _next; }
63 void set_next(ElfSymbolTable* next) { _next = next; }
64
65 bool compare(const Elf_Sym* sym, address addr, int* stringtableIndex, int* posIndex, int* offset, ElfFuncDescTable* funcDescTable);
66};
67
68#endif // !_WINDOWS and !__APPLE__
69
70#endif // SHARE_UTILITIES_ELFSYMBOLTABLE_HPP
71