elfStringTable.hpp revision 1929:2d4762ec74af
1109998Smarkm/*
2238405Sjkim * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3109998Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4109998Smarkm *
5109998Smarkm * This code is free software; you can redistribute it and/or modify it
6109998Smarkm * under the terms of the GNU General Public License version 2 only, as
7109998Smarkm * published by the Free Software Foundation.
8109998Smarkm *
9109998Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT
10109998Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11109998Smarkm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12109998Smarkm * version 2 for more details (a copy is included in the LICENSE file that
13109998Smarkm * accompanied this code).
14109998Smarkm *
15109998Smarkm * You should have received a copy of the GNU General Public License version
16109998Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
17109998Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18109998Smarkm *
19109998Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20109998Smarkm * or visit www.oracle.com if you need additional information or have any
21109998Smarkm * questions.
22109998Smarkm *
23109998Smarkm */
24109998Smarkm
25109998Smarkm#ifndef __ELF_STRING_TABLE_HPP
26109998Smarkm#define __ELF_STRING_TABLE_HPP
27109998Smarkm
28109998Smarkm#ifndef _WINDOWS
29109998Smarkm
30109998Smarkm#include "memory/allocation.hpp"
31109998Smarkm#include "utilities/decoder.hpp"
32109998Smarkm#include "utilities/elfFile.hpp"
33109998Smarkm
34109998Smarkm
35109998Smarkm// The string table represents a string table section in an elf file.
36109998Smarkm// Whenever there is enough memory, it will load whole string table as
37109998Smarkm// one blob. Otherwise, it will load string from file when requested.
38109998Smarkm
39109998Smarkm#define MAX_SYMBOL_LEN  256
40109998Smarkm
41109998Smarkmclass ElfStringTable: CHeapObj {
42109998Smarkm  friend class ElfFile;
43109998Smarkm public:
44109998Smarkm  ElfStringTable(FILE* file, Elf_Shdr shdr, int index);
45109998Smarkm  ~ElfStringTable();
46109998Smarkm
47109998Smarkm  // section index
48109998Smarkm  int index() { return m_index; };
49109998Smarkm
50109998Smarkm  // get string at specified offset
51160814Ssimon  const char* string_at(int offset);
52109998Smarkm
53109998Smarkm  // get status code
54109998Smarkm  Decoder::decoder_status get_status() { return m_status; };
55109998Smarkm
56160814Ssimon protected:
57109998Smarkm  ElfStringTable*        m_next;
58109998Smarkm
59238405Sjkim  // section index
60238405Sjkim  int                      m_index;
61238405Sjkim
62109998Smarkm  // holds complete string table if can
63109998Smarkm  // allocate enough memory
64109998Smarkm  const char*              m_table;
65109998Smarkm
66238405Sjkim  // file contains string table
67238405Sjkim  FILE*                    m_file;
68238405Sjkim
69238405Sjkim  // section header
70238405Sjkim  Elf_Shdr                 m_shdr;
71109998Smarkm
72109998Smarkm  // buffer for reading individual string
73238405Sjkim  char                     m_symbol[MAX_SYMBOL_LEN];
74238405Sjkim
75238405Sjkim  // error code
76238405Sjkim  Decoder::decoder_status  m_status;
77238405Sjkim};
78238405Sjkim
79238405Sjkim#endif // _WINDOWS
80238405Sjkim
81238405Sjkim#endif // __ELF_STRING_TABLE_HPP
82238405Sjkim
83238405Sjkim