1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/elfFile.hpp Sat Dec 11 13:20:56 2010 -0500 1.3 @@ -0,0 +1,140 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef __ELF_FILE_HPP 1.29 +#define __ELF_FILE_HPP 1.30 + 1.31 +#ifndef _WINDOWS 1.32 + 1.33 +#include <elf.h> 1.34 +#include <stdio.h> 1.35 + 1.36 +#ifdef _LP64 1.37 + 1.38 +typedef Elf64_Half Elf_Half; 1.39 +typedef Elf64_Word Elf_Word; 1.40 +typedef Elf64_Off Elf_Off; 1.41 +typedef Elf64_Addr Elf_Addr; 1.42 + 1.43 +typedef Elf64_Ehdr Elf_Ehdr; 1.44 +typedef Elf64_Shdr Elf_Shdr; 1.45 +typedef Elf64_Sym Elf_Sym; 1.46 + 1.47 +#define ELF_ST_TYPE ELF64_ST_TYPE 1.48 + 1.49 +#else 1.50 + 1.51 +typedef Elf32_Half Elf_Half; 1.52 +typedef Elf32_Word Elf_Word; 1.53 +typedef Elf32_Off Elf_Off; 1.54 +typedef Elf32_Addr Elf_Addr; 1.55 + 1.56 + 1.57 +typedef Elf32_Ehdr Elf_Ehdr; 1.58 +typedef Elf32_Shdr Elf_Shdr; 1.59 +typedef Elf32_Sym Elf_Sym; 1.60 + 1.61 +#define ELF_ST_TYPE ELF32_ST_TYPE 1.62 +#endif 1.63 + 1.64 +#include "globalDefinitions.hpp" 1.65 +#include "memory/allocation.hpp" 1.66 +#include "utilities/decoder.hpp" 1.67 + 1.68 + 1.69 +class ElfStringTable; 1.70 +class ElfSymbolTable; 1.71 + 1.72 + 1.73 +// On Solaris/Linux platforms, libjvm.so does contain all private symbols. 1.74 +// ElfFile is basically an elf file parser, which can lookup the symbol 1.75 +// that is the nearest to the given address. 1.76 +// Beware, this code is called from vm error reporting code, when vm is already 1.77 +// in "error" state, so there are scenarios, lookup will fail. We want this 1.78 +// part of code to be very defensive, and bait out if anything went wrong. 1.79 + 1.80 +class ElfFile: public CHeapObj { 1.81 + friend class Decoder; 1.82 + public: 1.83 + ElfFile(const char* filepath); 1.84 + ~ElfFile(); 1.85 + 1.86 + const char* decode(address addr, int* offset); 1.87 + const char* filepath() { 1.88 + return m_filepath; 1.89 + } 1.90 + 1.91 + bool same_elf_file(const char* filepath) { 1.92 + assert(filepath, "null file path"); 1.93 + assert(m_filepath, "already out of memory"); 1.94 + return (m_filepath && !strcmp(filepath, m_filepath)); 1.95 + } 1.96 + 1.97 + Decoder::decoder_status get_status() { 1.98 + return m_status; 1.99 + } 1.100 + 1.101 + private: 1.102 + // sanity check, if the file is a real elf file 1.103 + bool is_elf_file(Elf_Ehdr&); 1.104 + 1.105 + // load string tables from the elf file 1.106 + bool load_tables(); 1.107 + 1.108 + // string tables are stored in a linked list 1.109 + void add_string_table(ElfStringTable* table); 1.110 + 1.111 + // symbol tables are stored in a linked list 1.112 + void add_symbol_table(ElfSymbolTable* table); 1.113 + 1.114 + // return a string table at specified section index 1.115 + ElfStringTable* get_string_table(int index); 1.116 + 1.117 + // look up an address and return the nearest symbol 1.118 + const char* look_up(Elf_Shdr shdr, address addr, int* offset); 1.119 + 1.120 + protected: 1.121 + ElfFile* m_next; 1.122 + 1.123 + private: 1.124 + // file 1.125 + const char* m_filepath; 1.126 + FILE* m_file; 1.127 + 1.128 + // Elf header 1.129 + Elf_Ehdr m_elfHdr; 1.130 + 1.131 + // symbol tables 1.132 + ElfSymbolTable* m_symbol_tables; 1.133 + 1.134 + // string tables 1.135 + ElfStringTable* m_string_tables; 1.136 + 1.137 + Decoder::decoder_status m_status; 1.138 +}; 1.139 + 1.140 +#endif // _WINDOWS 1.141 + 1.142 +#endif // __ELF_FILE_HPP 1.143 +