author | goetz |
Thu, 26 Jun 2014 16:05:15 +0200 | |
changeset 25468 | 5331df506290 |
parent 19952 | bc974e92f881 |
child 31352 | a6ab7217b5cc |
permissions | -rw-r--r-- |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 |
/* |
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
19952
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
4 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
8 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
13 |
* accompanied this code). |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
14 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
18 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
21 |
* questions. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
22 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
23 |
*/ |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
24 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
26 |
#include "prims/jvm.h" |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15186
diff
changeset
|
27 |
#include "runtime/arguments.hpp" |
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
19952
diff
changeset
|
28 |
#include "runtime/os.hpp" |
11483 | 29 |
#include "decoder_windows.hpp" |
30 |
||
31 |
WindowsDecoder::WindowsDecoder() { |
|
32 |
_dbghelp_handle = NULL; |
|
33 |
_can_decode_in_vm = false; |
|
34 |
_pfnSymGetSymFromAddr64 = NULL; |
|
35 |
_pfnUndecorateSymbolName = NULL; |
|
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
36 |
#ifdef AMD64 |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
37 |
_pfnStackWalk64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
38 |
_pfnSymFunctionTableAccess64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
39 |
_pfnSymGetModuleBase64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
40 |
#endif |
11483 | 41 |
_decoder_status = no_error; |
42 |
initialize(); |
|
43 |
} |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
44 |
|
11483 | 45 |
void WindowsDecoder::initialize() { |
46 |
if (!has_error() && _dbghelp_handle == NULL) { |
|
47 |
HMODULE handle = ::LoadLibrary("dbghelp.dll"); |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
48 |
if (!handle) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
49 |
_decoder_status = helper_not_found; |
11483 | 50 |
return; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
51 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
52 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
53 |
_dbghelp_handle = handle; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
54 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
55 |
pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions"); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
56 |
pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize"); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
57 |
_pfnSymGetSymFromAddr64 = (pfn_SymGetSymFromAddr64)::GetProcAddress(handle, "SymGetSymFromAddr64"); |
15186
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
58 |
_pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName"); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
59 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
60 |
if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) { |
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
61 |
uninitialize(); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
62 |
_decoder_status = helper_func_error; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
63 |
return; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
64 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
65 |
|
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
66 |
#ifdef AMD64 |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
67 |
_pfnStackWalk64 = (pfn_StackWalk64)::GetProcAddress(handle, "StackWalk64"); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
68 |
_pfnSymFunctionTableAccess64 = (pfn_SymFunctionTableAccess64)::GetProcAddress(handle, "SymFunctionTableAccess64"); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
69 |
_pfnSymGetModuleBase64 = (pfn_SymGetModuleBase64)::GetProcAddress(handle, "SymGetModuleBase64"); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
70 |
if (_pfnStackWalk64 == NULL || _pfnSymFunctionTableAccess64 == NULL || _pfnSymGetModuleBase64 == NULL) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
71 |
// We can't call StackWalk64 to walk the stack, but we are still |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
72 |
// able to decode the symbols. Let's limp on. |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
73 |
_pfnStackWalk64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
74 |
_pfnSymFunctionTableAccess64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
75 |
_pfnSymGetModuleBase64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
76 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
77 |
#endif |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
78 |
|
15186
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
79 |
HANDLE hProcess = ::GetCurrentProcess(); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
80 |
_pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
81 |
if (!_pfnSymInitialize(hProcess, NULL, TRUE)) { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
82 |
_pfnSymGetSymFromAddr64 = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
83 |
_pfnUndecorateSymbolName = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
84 |
::FreeLibrary(handle); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
85 |
_dbghelp_handle = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
86 |
_decoder_status = helper_init_error; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
87 |
return; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
88 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
89 |
|
15186
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
90 |
// set pdb search paths |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
91 |
pfn_SymSetSearchPath _pfn_SymSetSearchPath = |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
92 |
(pfn_SymSetSearchPath)::GetProcAddress(handle, "SymSetSearchPath"); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
93 |
pfn_SymGetSearchPath _pfn_SymGetSearchPath = |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
94 |
(pfn_SymGetSearchPath)::GetProcAddress(handle, "SymGetSearchPath"); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
95 |
if (_pfn_SymSetSearchPath != NULL && _pfn_SymGetSearchPath != NULL) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
96 |
char paths[MAX_PATH]; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
97 |
int len = sizeof(paths); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
98 |
if (!_pfn_SymGetSearchPath(hProcess, paths, len)) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
99 |
paths[0] = '\0'; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
100 |
} else { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
101 |
// available spaces in path buffer |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
102 |
len -= (int)strlen(paths); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
103 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
104 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
105 |
char tmp_path[MAX_PATH]; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
106 |
DWORD dwSize; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
107 |
HMODULE hJVM = ::GetModuleHandle("jvm.dll"); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
108 |
tmp_path[0] = '\0'; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
109 |
// append the path where jvm.dll is located |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
110 |
if (hJVM != NULL && (dwSize = ::GetModuleFileName(hJVM, tmp_path, sizeof(tmp_path))) > 0) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
111 |
while (dwSize > 0 && tmp_path[dwSize] != '\\') { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
112 |
dwSize --; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
113 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
114 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
115 |
tmp_path[dwSize] = '\0'; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
116 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
117 |
if (dwSize > 0 && len > (int)dwSize + 1) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
118 |
strncat(paths, os::path_separator(), 1); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
119 |
strncat(paths, tmp_path, dwSize); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
120 |
len -= dwSize + 1; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
121 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
122 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
123 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
124 |
// append $JRE/bin. Arguments::get_java_home actually returns $JRE |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
125 |
// path |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
126 |
char *p = Arguments::get_java_home(); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
127 |
assert(p != NULL, "empty java home"); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
128 |
size_t java_home_len = strlen(p); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
129 |
if (len > (int)java_home_len + 5) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
130 |
strncat(paths, os::path_separator(), 1); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
131 |
strncat(paths, p, java_home_len); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
132 |
strncat(paths, "\\bin", 4); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
133 |
len -= (int)(java_home_len + 5); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
134 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
135 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
136 |
// append $JDK/bin path if it exists |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
137 |
assert(java_home_len < MAX_PATH, "Invalid path length"); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
138 |
// assume $JRE is under $JDK, construct $JDK/bin path and |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
139 |
// see if it exists or not |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
140 |
if (strncmp(&p[java_home_len - 3], "jre", 3) == 0) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
141 |
strncpy(tmp_path, p, java_home_len - 3); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
142 |
tmp_path[java_home_len - 3] = '\0'; |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
143 |
strncat(tmp_path, "bin", 3); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
144 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
145 |
// if the directory exists |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
146 |
DWORD dwAttrib = GetFileAttributes(tmp_path); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
147 |
if (dwAttrib != INVALID_FILE_ATTRIBUTES && |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
148 |
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
149 |
// tmp_path should have the same length as java_home_len, since we only |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
150 |
// replaced 'jre' with 'bin' |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
151 |
if (len > (int)java_home_len + 1) { |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
152 |
strncat(paths, os::path_separator(), 1); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
153 |
strncat(paths, tmp_path, java_home_len); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
154 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
155 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
156 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
157 |
|
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
158 |
_pfn_SymSetSearchPath(hProcess, paths); |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
159 |
} |
1a255c84cf6a
7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents:
13963
diff
changeset
|
160 |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
161 |
// find out if jvm.dll contains private symbols, by decoding |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
162 |
// current function and comparing the result |
13340 | 163 |
address addr = (address)Decoder::demangle; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
164 |
char buf[MAX_PATH]; |
11483 | 165 |
if (decode(addr, buf, sizeof(buf), NULL)) { |
13340 | 166 |
_can_decode_in_vm = !strcmp(buf, "Decoder::demangle"); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
167 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
168 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
169 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
170 |
|
11483 | 171 |
void WindowsDecoder::uninitialize() { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
172 |
_pfnSymGetSymFromAddr64 = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
173 |
_pfnUndecorateSymbolName = NULL; |
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
174 |
#ifdef AMD64 |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
175 |
_pfnStackWalk64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
176 |
_pfnSymFunctionTableAccess64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
177 |
_pfnSymGetModuleBase64 = NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
178 |
#endif |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
179 |
if (_dbghelp_handle != NULL) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
180 |
::FreeLibrary(_dbghelp_handle); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
181 |
} |
11483 | 182 |
_dbghelp_handle = NULL; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
183 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
184 |
|
11483 | 185 |
bool WindowsDecoder::can_decode_C_frame_in_vm() const { |
186 |
return (!has_error() && _can_decode_in_vm); |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
187 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
188 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
189 |
|
11483 | 190 |
bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath) { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
191 |
if (_pfnSymGetSymFromAddr64 != NULL) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
192 |
PIMAGEHLP_SYMBOL64 pSymbol; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
193 |
char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)]; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
194 |
pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
195 |
pSymbol->MaxNameLength = MAX_PATH; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
196 |
pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
197 |
DWORD64 displacement; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
198 |
if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
199 |
if (buf != NULL) { |
11483 | 200 |
if (demangle(pSymbol->Name, buf, buflen)) { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
201 |
jio_snprintf(buf, buflen, "%s", pSymbol->Name); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
202 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
203 |
} |
11483 | 204 |
if(offset != NULL) *offset = (int)displacement; |
205 |
return true; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
206 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
207 |
} |
11483 | 208 |
if (buf != NULL && buflen > 0) buf[0] = '\0'; |
209 |
if (offset != NULL) *offset = -1; |
|
210 |
return false; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
211 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
212 |
|
11483 | 213 |
bool WindowsDecoder::demangle(const char* symbol, char *buf, int buflen) { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
214 |
return _pfnUndecorateSymbolName != NULL && |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
215 |
_pfnUndecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
216 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
217 |
|
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
218 |
#ifdef AMD64 |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
219 |
BOOL WindowsDbgHelp::StackWalk64(DWORD MachineType, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
220 |
HANDLE hProcess, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
221 |
HANDLE hThread, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
222 |
LPSTACKFRAME64 StackFrame, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
223 |
PVOID ContextRecord, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
224 |
PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
225 |
PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
226 |
PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
227 |
PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
228 |
DecoderLocker locker; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
229 |
WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
230 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
231 |
if (!wd->has_error() && wd->_pfnStackWalk64) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
232 |
return wd->_pfnStackWalk64(MachineType, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
233 |
hProcess, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
234 |
hThread, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
235 |
StackFrame, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
236 |
ContextRecord, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
237 |
ReadMemoryRoutine, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
238 |
FunctionTableAccessRoutine, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
239 |
GetModuleBaseRoutine, |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
240 |
TranslateAddress); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
241 |
} else { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
242 |
return false; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
243 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
244 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
245 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
246 |
PVOID WindowsDbgHelp::SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
247 |
DecoderLocker locker; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
248 |
WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
249 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
250 |
if (!wd->has_error() && wd->_pfnSymFunctionTableAccess64) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
251 |
return wd->_pfnSymFunctionTableAccess64(hProcess, AddrBase); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
252 |
} else { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
253 |
return NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
254 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
255 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
256 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
257 |
pfn_SymFunctionTableAccess64 WindowsDbgHelp::pfnSymFunctionTableAccess64() { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
258 |
DecoderLocker locker; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
259 |
WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
260 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
261 |
if (!wd->has_error()) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
262 |
return wd->_pfnSymFunctionTableAccess64; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
263 |
} else { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
264 |
return NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
265 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
266 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
267 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
268 |
pfn_SymGetModuleBase64 WindowsDbgHelp::pfnSymGetModuleBase64() { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
269 |
DecoderLocker locker; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
270 |
WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
271 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
272 |
if (!wd->has_error()) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
273 |
return wd->_pfnSymGetModuleBase64; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
274 |
} else { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
275 |
return NULL; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
276 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
277 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
278 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
15855
diff
changeset
|
279 |
#endif // AMD64 |