Sun, 25 Sep 2011 16:03:29 -0700
7089790: integrate bsd-port changes
Reviewed-by: kvn, twisti, jrose
Contributed-by: Kurt Miller <kurt@intricatesoftware.com>, Greg Lewis <glewis@eyesbeyond.com>, Jung-uk Kim <jkim@freebsd.org>, Christos Zoulas <christos@zoulas.com>, Landon Fuller <landonf@plausible.coop>, The FreeBSD Foundation <board@freebsdfoundation.org>, Michael Franz <mvfranz@gmail.com>, Roger Hoover <rhoover@apple.com>, Alexander Strange <astrange@apple.com>
zgu@2364 | 1 | /* |
zgu@2364 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
zgu@2364 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
zgu@2364 | 4 | * |
zgu@2364 | 5 | * This code is free software; you can redistribute it and/or modify it |
zgu@2364 | 6 | * under the terms of the GNU General Public License version 2 only, as |
zgu@2364 | 7 | * published by the Free Software Foundation. |
zgu@2364 | 8 | * |
zgu@2364 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
zgu@2364 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
zgu@2364 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
zgu@2364 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
zgu@2364 | 13 | * accompanied this code). |
zgu@2364 | 14 | * |
zgu@2364 | 15 | * You should have received a copy of the GNU General Public License version |
zgu@2364 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
zgu@2364 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
zgu@2364 | 18 | * |
zgu@2364 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
zgu@2364 | 20 | * or visit www.oracle.com if you need additional information or have any |
zgu@2364 | 21 | * questions. |
zgu@2364 | 22 | * |
zgu@2364 | 23 | */ |
zgu@2364 | 24 | |
zgu@2364 | 25 | |
zgu@2364 | 26 | #ifndef __DECODER_HPP |
zgu@2364 | 27 | #define __DECODER_HPP |
zgu@2364 | 28 | |
zgu@2364 | 29 | #include "memory/allocation.hpp" |
zgu@2364 | 30 | |
zgu@2364 | 31 | #ifdef _WINDOWS |
zgu@2364 | 32 | #include <windows.h> |
zgu@2364 | 33 | #include <imagehlp.h> |
zgu@2364 | 34 | |
zgu@2364 | 35 | // functions needed for decoding symbols |
zgu@2364 | 36 | typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD); |
zgu@2364 | 37 | typedef BOOL (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL); |
zgu@2364 | 38 | typedef BOOL (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64); |
zgu@2364 | 39 | typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD); |
zgu@2364 | 40 | |
never@3156 | 41 | #elif defined(__APPLE__) |
never@3156 | 42 | |
zgu@2364 | 43 | #else |
zgu@2364 | 44 | |
zgu@2364 | 45 | class ElfFile; |
zgu@2364 | 46 | |
zgu@2364 | 47 | #endif // _WINDOWS |
zgu@2364 | 48 | |
zgu@2364 | 49 | |
zgu@2364 | 50 | class Decoder: public StackObj { |
zgu@2364 | 51 | |
zgu@2364 | 52 | public: |
zgu@2364 | 53 | // status code for decoding native C frame |
zgu@2364 | 54 | enum decoder_status { |
zgu@2364 | 55 | no_error, // successfully decoded frames |
zgu@2364 | 56 | out_of_memory, // out of memory |
zgu@2364 | 57 | file_invalid, // invalid elf file |
zgu@2364 | 58 | file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map |
zgu@2364 | 59 | helper_not_found, // could not load dbghelp.dll (Windows only) |
zgu@2364 | 60 | helper_func_error, // decoding functions not found (Windows only) |
zgu@2364 | 61 | helper_init_error, // SymInitialize failed (Windows only) |
zgu@2364 | 62 | symbol_not_found // could not find the symbol |
zgu@2364 | 63 | }; |
zgu@2364 | 64 | |
zgu@2364 | 65 | public: |
zgu@2364 | 66 | Decoder() { initialize(); }; |
zgu@2364 | 67 | ~Decoder() { uninitialize(); }; |
zgu@2364 | 68 | |
zgu@2364 | 69 | static bool can_decode_C_frame_in_vm(); |
zgu@2364 | 70 | |
zgu@2364 | 71 | static void initialize(); |
zgu@2364 | 72 | static void uninitialize(); |
zgu@2364 | 73 | |
zgu@2364 | 74 | #ifdef _WINDOWS |
zgu@2364 | 75 | static decoder_status decode(address addr, char *buf, int buflen, int *offset); |
zgu@2364 | 76 | #else |
zgu@2364 | 77 | static decoder_status decode(address addr, const char* filepath, char *buf, int buflen, int *offset); |
zgu@2364 | 78 | #endif |
zgu@2364 | 79 | |
zgu@2364 | 80 | static bool demangle(const char* symbol, char *buf, int buflen); |
zgu@2364 | 81 | |
zgu@2364 | 82 | static decoder_status get_status() { return _decoder_status; }; |
zgu@2364 | 83 | |
never@3156 | 84 | #if !defined(_WINDOWS) && !defined(__APPLE__) |
zgu@2364 | 85 | private: |
zgu@2364 | 86 | static ElfFile* get_elf_file(const char* filepath); |
zgu@2364 | 87 | #endif // _WINDOWS |
zgu@2364 | 88 | |
zgu@2364 | 89 | |
zgu@2364 | 90 | private: |
zgu@2364 | 91 | static decoder_status _decoder_status; |
zgu@2364 | 92 | static bool _initialized; |
zgu@2364 | 93 | |
zgu@2364 | 94 | #ifdef _WINDOWS |
zgu@2364 | 95 | static HMODULE _dbghelp_handle; |
zgu@2364 | 96 | static bool _can_decode_in_vm; |
zgu@2364 | 97 | static pfn_SymGetSymFromAddr64 _pfnSymGetSymFromAddr64; |
zgu@2364 | 98 | static pfn_UndecorateSymbolName _pfnUndecorateSymbolName; |
never@3156 | 99 | #elif __APPLE__ |
zgu@2364 | 100 | #else |
zgu@2364 | 101 | static ElfFile* _opened_elf_files; |
zgu@2364 | 102 | #endif // _WINDOWS |
zgu@2364 | 103 | }; |
zgu@2364 | 104 | |
zgu@2364 | 105 | #endif // __DECODER_HPP |