annotate src/os/windows/vm/decoder_windows.cpp @ 21947:9f70fc90169d

Truffle: remove expensive assertion
author Andreas Woess <andreas.woess@oracle.com>
date Wed, 17 Jun 2015 04:09:30 +0200
parents 38f750491293
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
1 /*
8675
63e54c37ac64 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 7580
diff changeset
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2022
2d4762ec74af 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.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
4 *
2d4762ec74af 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
2d4762ec74af 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
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
7 * published by the Free Software Foundation.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
8 *
2d4762ec74af 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
2d4762ec74af 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
2d4762ec74af 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
2d4762ec74af 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
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
13 * accompanied this code).
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
14 *
2d4762ec74af 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
2d4762ec74af 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,
2d4762ec74af 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.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
18 *
2d4762ec74af 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
2d4762ec74af 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
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
21 * questions.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
22 *
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
23 */
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
24
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
25 #include "precompiled.hpp"
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
26 #include "prims/jvm.h"
8675
63e54c37ac64 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 7580
diff changeset
27 #include "runtime/arguments.hpp"
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
28 #include "decoder_windows.hpp"
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
29
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
30 WindowsDecoder::WindowsDecoder() {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
31 _dbghelp_handle = NULL;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
32 _can_decode_in_vm = false;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
33 _pfnSymGetSymFromAddr64 = NULL;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
34 _pfnUndecorateSymbolName = NULL;
12199
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
35 #ifdef AMD64
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
36 _pfnStackWalk64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
37 _pfnSymFunctionTableAccess64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
38 _pfnSymGetModuleBase64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
39 #endif
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
40 _decoder_status = no_error;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
41 initialize();
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
42 }
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
43
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
44 void WindowsDecoder::initialize() {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
45 if (!has_error() && _dbghelp_handle == NULL) {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
46 HMODULE handle = ::LoadLibrary("dbghelp.dll");
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
47 if (!handle) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
48 _decoder_status = helper_not_found;
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
49 return;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
50 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
51
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
52 _dbghelp_handle = handle;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
53
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
54 pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
55 pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
56 _pfnSymGetSymFromAddr64 = (pfn_SymGetSymFromAddr64)::GetProcAddress(handle, "SymGetSymFromAddr64");
7580
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
57 _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName");
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
58
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
59 if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) {
12199
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
60 uninitialize();
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
61 _decoder_status = helper_func_error;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
62 return;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
63 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
64
12199
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
65 #ifdef AMD64
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
66 _pfnStackWalk64 = (pfn_StackWalk64)::GetProcAddress(handle, "StackWalk64");
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
67 _pfnSymFunctionTableAccess64 = (pfn_SymFunctionTableAccess64)::GetProcAddress(handle, "SymFunctionTableAccess64");
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
68 _pfnSymGetModuleBase64 = (pfn_SymGetModuleBase64)::GetProcAddress(handle, "SymGetModuleBase64");
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
69 if (_pfnStackWalk64 == NULL || _pfnSymFunctionTableAccess64 == NULL || _pfnSymGetModuleBase64 == NULL) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
70 // We can't call StackWalk64 to walk the stack, but we are still
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
71 // able to decode the symbols. Let's limp on.
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
72 _pfnStackWalk64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
73 _pfnSymFunctionTableAccess64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
74 _pfnSymGetModuleBase64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
75 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
76 #endif
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
77
7580
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
78 HANDLE hProcess = ::GetCurrentProcess();
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
79 _pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
80 if (!_pfnSymInitialize(hProcess, NULL, TRUE)) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
81 _pfnSymGetSymFromAddr64 = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
82 _pfnUndecorateSymbolName = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
83 ::FreeLibrary(handle);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
84 _dbghelp_handle = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
85 _decoder_status = helper_init_error;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
86 return;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
87 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
88
7580
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
89 // set pdb search paths
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
90 pfn_SymSetSearchPath _pfn_SymSetSearchPath =
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
91 (pfn_SymSetSearchPath)::GetProcAddress(handle, "SymSetSearchPath");
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
92 pfn_SymGetSearchPath _pfn_SymGetSearchPath =
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
93 (pfn_SymGetSearchPath)::GetProcAddress(handle, "SymGetSearchPath");
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
94 if (_pfn_SymSetSearchPath != NULL && _pfn_SymGetSearchPath != NULL) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
95 char paths[MAX_PATH];
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
96 int len = sizeof(paths);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
97 if (!_pfn_SymGetSearchPath(hProcess, paths, len)) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
98 paths[0] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
99 } else {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
100 // available spaces in path buffer
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
101 len -= (int)strlen(paths);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
102 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
103
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
104 char tmp_path[MAX_PATH];
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
105 DWORD dwSize;
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
106 HMODULE hJVM = ::GetModuleHandle("jvm.dll");
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
107 tmp_path[0] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
108 // append the path where jvm.dll is located
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
109 if (hJVM != NULL && (dwSize = ::GetModuleFileName(hJVM, tmp_path, sizeof(tmp_path))) > 0) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
110 while (dwSize > 0 && tmp_path[dwSize] != '\\') {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
111 dwSize --;
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
112 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
113
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
114 tmp_path[dwSize] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
115
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
116 if (dwSize > 0 && len > (int)dwSize + 1) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
117 strncat(paths, os::path_separator(), 1);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
118 strncat(paths, tmp_path, dwSize);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
119 len -= dwSize + 1;
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
120 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
121 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
122
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
123 // append $JRE/bin. Arguments::get_java_home actually returns $JRE
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
124 // path
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
125 char *p = Arguments::get_java_home();
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
126 assert(p != NULL, "empty java home");
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
127 size_t java_home_len = strlen(p);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
128 if (len > (int)java_home_len + 5) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
129 strncat(paths, os::path_separator(), 1);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
130 strncat(paths, p, java_home_len);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
131 strncat(paths, "\\bin", 4);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
132 len -= (int)(java_home_len + 5);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
133 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
134
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
135 // append $JDK/bin path if it exists
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
136 assert(java_home_len < MAX_PATH, "Invalid path length");
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
137 // assume $JRE is under $JDK, construct $JDK/bin path and
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
138 // see if it exists or not
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
139 if (strncmp(&p[java_home_len - 3], "jre", 3) == 0) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
140 strncpy(tmp_path, p, java_home_len - 3);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
141 tmp_path[java_home_len - 3] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
142 strncat(tmp_path, "bin", 3);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
143
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
144 // if the directory exists
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
145 DWORD dwAttrib = GetFileAttributes(tmp_path);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
146 if (dwAttrib != INVALID_FILE_ATTRIBUTES &&
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
147 (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
148 // tmp_path should have the same length as java_home_len, since we only
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
149 // replaced 'jre' with 'bin'
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
150 if (len > (int)java_home_len + 1) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
151 strncat(paths, os::path_separator(), 1);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
152 strncat(paths, tmp_path, java_home_len);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
153 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
154 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
155 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
156
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
157 _pfn_SymSetSearchPath(hProcess, paths);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
158 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
159
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
160 // find out if jvm.dll contains private symbols, by decoding
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
161 // current function and comparing the result
6258
3b01d0321dfa 7186778: MachO decoder implementation for MacOSX
zgu
parents: 4803
diff changeset
162 address addr = (address)Decoder::demangle;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
163 char buf[MAX_PATH];
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
164 if (decode(addr, buf, sizeof(buf), NULL)) {
6258
3b01d0321dfa 7186778: MachO decoder implementation for MacOSX
zgu
parents: 4803
diff changeset
165 _can_decode_in_vm = !strcmp(buf, "Decoder::demangle");
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
166 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
167 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
168 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
169
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
170 void WindowsDecoder::uninitialize() {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
171 _pfnSymGetSymFromAddr64 = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
172 _pfnUndecorateSymbolName = NULL;
12199
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
173 #ifdef AMD64
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
174 _pfnStackWalk64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
175 _pfnSymFunctionTableAccess64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
176 _pfnSymGetModuleBase64 = NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
177 #endif
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
178 if (_dbghelp_handle != NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
179 ::FreeLibrary(_dbghelp_handle);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
180 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
181 _dbghelp_handle = NULL;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
182 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
183
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
184 bool WindowsDecoder::can_decode_C_frame_in_vm() const {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
185 return (!has_error() && _can_decode_in_vm);
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
186 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
187
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
188
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
189 bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
190 if (_pfnSymGetSymFromAddr64 != NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
191 PIMAGEHLP_SYMBOL64 pSymbol;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
192 char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
193 pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
194 pSymbol->MaxNameLength = MAX_PATH;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
195 pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
196 DWORD64 displacement;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
197 if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
198 if (buf != NULL) {
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
199 if (demangle(pSymbol->Name, buf, buflen)) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
200 jio_snprintf(buf, buflen, "%s", pSymbol->Name);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
201 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
202 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
203 if(offset != NULL) *offset = (int)displacement;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
204 return true;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
205 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
206 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
207 if (buf != NULL && buflen > 0) buf[0] = '\0';
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
208 if (offset != NULL) *offset = -1;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
209 return false;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
210 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
211
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
212 bool WindowsDecoder::demangle(const char* symbol, char *buf, int buflen) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
213 return _pfnUndecorateSymbolName != NULL &&
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
214 _pfnUndecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
215 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
216
12199
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
217 #ifdef AMD64
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
218 BOOL WindowsDbgHelp::StackWalk64(DWORD MachineType,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
219 HANDLE hProcess,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
220 HANDLE hThread,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
221 LPSTACKFRAME64 StackFrame,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
222 PVOID ContextRecord,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
223 PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
224 PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
225 PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
226 PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
227 DecoderLocker locker;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
228 WindowsDecoder* wd = (WindowsDecoder*)locker.decoder();
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
229
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
230 if (!wd->has_error() && wd->_pfnStackWalk64) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
231 return wd->_pfnStackWalk64(MachineType,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
232 hProcess,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
233 hThread,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
234 StackFrame,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
235 ContextRecord,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
236 ReadMemoryRoutine,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
237 FunctionTableAccessRoutine,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
238 GetModuleBaseRoutine,
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
239 TranslateAddress);
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
240 } else {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
241 return false;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
242 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
243 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
244
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
245 PVOID WindowsDbgHelp::SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
246 DecoderLocker locker;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
247 WindowsDecoder* wd = (WindowsDecoder*)locker.decoder();
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
248
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
249 if (!wd->has_error() && wd->_pfnSymFunctionTableAccess64) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
250 return wd->_pfnSymFunctionTableAccess64(hProcess, AddrBase);
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
251 } else {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
252 return NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
253 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
254 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
255
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
256 pfn_SymFunctionTableAccess64 WindowsDbgHelp::pfnSymFunctionTableAccess64() {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
257 DecoderLocker locker;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
258 WindowsDecoder* wd = (WindowsDecoder*)locker.decoder();
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
259
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
260 if (!wd->has_error()) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
261 return wd->_pfnSymFunctionTableAccess64;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
262 } else {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
263 return NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
264 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
265 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
266
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
267 pfn_SymGetModuleBase64 WindowsDbgHelp::pfnSymGetModuleBase64() {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
268 DecoderLocker locker;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
269 WindowsDecoder* wd = (WindowsDecoder*)locker.decoder();
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
270
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
271 if (!wd->has_error()) {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
272 return wd->_pfnSymGetModuleBase64;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
273 } else {
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
274 return NULL;
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
275 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
276 }
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
277
38f750491293 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 8675
diff changeset
278 #endif // AMD64