zgu@2364: /* zgu@2364: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. zgu@2364: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. zgu@2364: * zgu@2364: * This code is free software; you can redistribute it and/or modify it zgu@2364: * under the terms of the GNU General Public License version 2 only, as zgu@2364: * published by the Free Software Foundation. zgu@2364: * zgu@2364: * This code is distributed in the hope that it will be useful, but WITHOUT zgu@2364: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or zgu@2364: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License zgu@2364: * version 2 for more details (a copy is included in the LICENSE file that zgu@2364: * accompanied this code). zgu@2364: * zgu@2364: * You should have received a copy of the GNU General Public License version zgu@2364: * 2 along with this work; if not, write to the Free Software Foundation, zgu@2364: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. zgu@2364: * zgu@2364: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA zgu@2364: * or visit www.oracle.com if you need additional information or have any zgu@2364: * questions. zgu@2364: * zgu@2364: */ zgu@2364: zgu@2364: #ifndef __ELF_FILE_HPP zgu@2364: #define __ELF_FILE_HPP zgu@2364: zgu@2364: #ifndef _WINDOWS zgu@2364: zgu@2364: #include zgu@2364: #include zgu@2364: zgu@2364: #ifdef _LP64 zgu@2364: zgu@2364: typedef Elf64_Half Elf_Half; zgu@2364: typedef Elf64_Word Elf_Word; zgu@2364: typedef Elf64_Off Elf_Off; zgu@2364: typedef Elf64_Addr Elf_Addr; zgu@2364: zgu@2364: typedef Elf64_Ehdr Elf_Ehdr; zgu@2364: typedef Elf64_Shdr Elf_Shdr; zgu@2364: typedef Elf64_Sym Elf_Sym; zgu@2364: zgu@2364: #define ELF_ST_TYPE ELF64_ST_TYPE zgu@2364: zgu@2364: #else zgu@2364: zgu@2364: typedef Elf32_Half Elf_Half; zgu@2364: typedef Elf32_Word Elf_Word; zgu@2364: typedef Elf32_Off Elf_Off; zgu@2364: typedef Elf32_Addr Elf_Addr; zgu@2364: zgu@2364: zgu@2364: typedef Elf32_Ehdr Elf_Ehdr; zgu@2364: typedef Elf32_Shdr Elf_Shdr; zgu@2364: typedef Elf32_Sym Elf_Sym; zgu@2364: zgu@2364: #define ELF_ST_TYPE ELF32_ST_TYPE zgu@2364: #endif zgu@2364: zgu@2364: #include "globalDefinitions.hpp" zgu@2364: #include "memory/allocation.hpp" zgu@2364: #include "utilities/decoder.hpp" zgu@2364: zgu@2364: zgu@2364: class ElfStringTable; zgu@2364: class ElfSymbolTable; zgu@2364: zgu@2364: zgu@2364: // On Solaris/Linux platforms, libjvm.so does contain all private symbols. zgu@2364: // ElfFile is basically an elf file parser, which can lookup the symbol zgu@2364: // that is the nearest to the given address. zgu@2364: // Beware, this code is called from vm error reporting code, when vm is already zgu@2364: // in "error" state, so there are scenarios, lookup will fail. We want this zgu@2364: // part of code to be very defensive, and bait out if anything went wrong. zgu@2364: zgu@2364: class ElfFile: public CHeapObj { zgu@2364: friend class Decoder; zgu@2364: public: zgu@2364: ElfFile(const char* filepath); zgu@2364: ~ElfFile(); zgu@2364: zgu@2364: const char* decode(address addr, int* offset); zgu@2364: const char* filepath() { zgu@2364: return m_filepath; zgu@2364: } zgu@2364: zgu@2364: bool same_elf_file(const char* filepath) { zgu@2364: assert(filepath, "null file path"); zgu@2364: assert(m_filepath, "already out of memory"); zgu@2364: return (m_filepath && !strcmp(filepath, m_filepath)); zgu@2364: } zgu@2364: zgu@2364: Decoder::decoder_status get_status() { zgu@2364: return m_status; zgu@2364: } zgu@2364: zgu@2364: private: zgu@2364: // sanity check, if the file is a real elf file zgu@2364: bool is_elf_file(Elf_Ehdr&); zgu@2364: zgu@2364: // load string tables from the elf file zgu@2364: bool load_tables(); zgu@2364: zgu@2364: // string tables are stored in a linked list zgu@2364: void add_string_table(ElfStringTable* table); zgu@2364: zgu@2364: // symbol tables are stored in a linked list zgu@2364: void add_symbol_table(ElfSymbolTable* table); zgu@2364: zgu@2364: // return a string table at specified section index zgu@2364: ElfStringTable* get_string_table(int index); zgu@2364: zgu@2364: // look up an address and return the nearest symbol zgu@2364: const char* look_up(Elf_Shdr shdr, address addr, int* offset); zgu@2364: zgu@2364: protected: zgu@2364: ElfFile* m_next; zgu@2364: zgu@2364: private: zgu@2364: // file zgu@2364: const char* m_filepath; zgu@2364: FILE* m_file; zgu@2364: zgu@2364: // Elf header zgu@2364: Elf_Ehdr m_elfHdr; zgu@2364: zgu@2364: // symbol tables zgu@2364: ElfSymbolTable* m_symbol_tables; zgu@2364: zgu@2364: // string tables zgu@2364: ElfStringTable* m_string_tables; zgu@2364: zgu@2364: Decoder::decoder_status m_status; zgu@2364: }; zgu@2364: zgu@2364: #endif // _WINDOWS zgu@2364: zgu@2364: #endif // __ELF_FILE_HPP zgu@2364: