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: zgu@2364: #ifndef __DECODER_HPP zgu@2364: #define __DECODER_HPP zgu@2364: zgu@2364: #include "memory/allocation.hpp" zgu@2364: zgu@2364: #ifdef _WINDOWS zgu@2364: #include zgu@2364: #include zgu@2364: zgu@2364: // functions needed for decoding symbols zgu@2364: typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD); zgu@2364: typedef BOOL (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL); zgu@2364: typedef BOOL (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64); zgu@2364: typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD); zgu@2364: zgu@2364: #else zgu@2364: zgu@2364: class ElfFile; zgu@2364: zgu@2364: #endif // _WINDOWS zgu@2364: zgu@2364: zgu@2364: class Decoder: public StackObj { zgu@2364: zgu@2364: public: zgu@2364: // status code for decoding native C frame zgu@2364: enum decoder_status { zgu@2364: no_error, // successfully decoded frames zgu@2364: out_of_memory, // out of memory zgu@2364: file_invalid, // invalid elf file zgu@2364: file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map zgu@2364: helper_not_found, // could not load dbghelp.dll (Windows only) zgu@2364: helper_func_error, // decoding functions not found (Windows only) zgu@2364: helper_init_error, // SymInitialize failed (Windows only) zgu@2364: symbol_not_found // could not find the symbol zgu@2364: }; zgu@2364: zgu@2364: public: zgu@2364: Decoder() { initialize(); }; zgu@2364: ~Decoder() { uninitialize(); }; zgu@2364: zgu@2364: static bool can_decode_C_frame_in_vm(); zgu@2364: zgu@2364: static void initialize(); zgu@2364: static void uninitialize(); zgu@2364: zgu@2364: #ifdef _WINDOWS zgu@2364: static decoder_status decode(address addr, char *buf, int buflen, int *offset); zgu@2364: #else zgu@2364: static decoder_status decode(address addr, const char* filepath, char *buf, int buflen, int *offset); zgu@2364: #endif zgu@2364: zgu@2364: static bool demangle(const char* symbol, char *buf, int buflen); zgu@2364: zgu@2364: static decoder_status get_status() { return _decoder_status; }; zgu@2364: zgu@2364: #ifndef _WINDOWS zgu@2364: private: zgu@2364: static ElfFile* get_elf_file(const char* filepath); zgu@2364: #endif // _WINDOWS zgu@2364: zgu@2364: zgu@2364: private: zgu@2364: static decoder_status _decoder_status; zgu@2364: static bool _initialized; zgu@2364: zgu@2364: #ifdef _WINDOWS zgu@2364: static HMODULE _dbghelp_handle; zgu@2364: static bool _can_decode_in_vm; zgu@2364: static pfn_SymGetSymFromAddr64 _pfnSymGetSymFromAddr64; zgu@2364: static pfn_UndecorateSymbolName _pfnUndecorateSymbolName; zgu@2364: #else zgu@2364: static ElfFile* _opened_elf_files; zgu@2364: #endif // _WINDOWS zgu@2364: }; zgu@2364: zgu@2364: #endif // __DECODER_HPP