src/os/windows/vm/decoder_windows.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef OS_WINDOWS_VM_DECODER_WINDOWS_HPP
aoqi@0 26 #define OS_WINDOWS_VM_DECIDER_WINDOWS_HPP
aoqi@0 27
aoqi@0 28 #include <windows.h>
aoqi@0 29 #include <imagehlp.h>
aoqi@0 30
aoqi@0 31 #include "utilities/decoder.hpp"
aoqi@0 32
aoqi@0 33 // functions needed for decoding symbols
aoqi@0 34 typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD);
aoqi@0 35 typedef BOOL (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL);
aoqi@0 36 typedef BOOL (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
aoqi@0 37 typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD);
aoqi@0 38 typedef BOOL (WINAPI *pfn_SymSetSearchPath)(HANDLE, PCTSTR);
aoqi@0 39 typedef BOOL (WINAPI *pfn_SymGetSearchPath)(HANDLE, PTSTR, int);
aoqi@0 40
aoqi@0 41 #ifdef AMD64
aoqi@0 42 typedef BOOL (WINAPI *pfn_StackWalk64)(DWORD MachineType,
aoqi@0 43 HANDLE hProcess,
aoqi@0 44 HANDLE hThread,
aoqi@0 45 LPSTACKFRAME64 StackFrame,
aoqi@0 46 PVOID ContextRecord,
aoqi@0 47 PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
aoqi@0 48 PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
aoqi@0 49 PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
aoqi@0 50 PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
aoqi@0 51 typedef PVOID (WINAPI *pfn_SymFunctionTableAccess64)(HANDLE hProcess, DWORD64 AddrBase);
aoqi@0 52 typedef DWORD64 (WINAPI *pfn_SymGetModuleBase64)(HANDLE hProcess, DWORD64 dwAddr);
aoqi@0 53 #endif
aoqi@0 54
aoqi@0 55 class WindowsDecoder : public AbstractDecoder {
aoqi@0 56
aoqi@0 57 public:
aoqi@0 58 WindowsDecoder();
aoqi@0 59 ~WindowsDecoder() { uninitialize(); };
aoqi@0 60
aoqi@0 61 bool can_decode_C_frame_in_vm() const;
aoqi@0 62 bool demangle(const char* symbol, char *buf, int buflen);
aoqi@0 63 bool decode(address addr, char *buf, int buflen, int* offset, const char* modulepath = NULL);
aoqi@0 64 bool decode(address addr, char *buf, int buflen, int* offset, const void* base) {
aoqi@0 65 ShouldNotReachHere();
aoqi@0 66 return false;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 private:
aoqi@0 70 void initialize();
aoqi@0 71 void uninitialize();
aoqi@0 72
aoqi@0 73 private:
aoqi@0 74 HMODULE _dbghelp_handle;
aoqi@0 75 bool _can_decode_in_vm;
aoqi@0 76 pfn_SymGetSymFromAddr64 _pfnSymGetSymFromAddr64;
aoqi@0 77 pfn_UndecorateSymbolName _pfnUndecorateSymbolName;
aoqi@0 78 #ifdef AMD64
aoqi@0 79 pfn_StackWalk64 _pfnStackWalk64;
aoqi@0 80 pfn_SymFunctionTableAccess64 _pfnSymFunctionTableAccess64;
aoqi@0 81 pfn_SymGetModuleBase64 _pfnSymGetModuleBase64;
aoqi@0 82
aoqi@0 83 friend class WindowsDbgHelp;
aoqi@0 84 #endif
aoqi@0 85 };
aoqi@0 86
aoqi@0 87 #ifdef AMD64
aoqi@0 88 // TODO: refactor and move the handling of dbghelp.dll outside of Decoder
aoqi@0 89 class WindowsDbgHelp : public Decoder {
aoqi@0 90 public:
aoqi@0 91 static BOOL StackWalk64(DWORD MachineType,
aoqi@0 92 HANDLE hProcess,
aoqi@0 93 HANDLE hThread,
aoqi@0 94 LPSTACKFRAME64 StackFrame,
aoqi@0 95 PVOID ContextRecord,
aoqi@0 96 PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
aoqi@0 97 PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
aoqi@0 98 PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
aoqi@0 99 PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
aoqi@0 100 static PVOID SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase);
aoqi@0 101
aoqi@0 102 static pfn_SymFunctionTableAccess64 pfnSymFunctionTableAccess64();
aoqi@0 103 static pfn_SymGetModuleBase64 pfnSymGetModuleBase64();
aoqi@0 104 };
aoqi@0 105 #endif
aoqi@0 106
aoqi@0 107 #endif // OS_WINDOWS_VM_DECODER_WINDOWS_HPP
aoqi@0 108

mercurial