annotate src/os/windows/vm/decoder_windows.cpp @ 7580:dd7248d3e151

7152671: RFE: Windows decoder should add some std dirs to the symbol search path Summary: Added JRE/JDK bin directories to decoder's symbol search path Reviewed-by: dcubed, sla
author zgu
date Wed, 09 Jan 2013 14:46:55 -0500
parents b9a9ed0f8eeb
children 63e54c37ac64
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 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 6258
diff changeset
2 * Copyright (c) 1997, 2012, 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"
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
27 #include "decoder_windows.hpp"
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
28
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
29 WindowsDecoder::WindowsDecoder() {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
30 _dbghelp_handle = NULL;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
31 _can_decode_in_vm = false;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
32 _pfnSymGetSymFromAddr64 = NULL;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
33 _pfnUndecorateSymbolName = NULL;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
34
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
35 _decoder_status = no_error;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
36 initialize();
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
37 }
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
38
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
39 void WindowsDecoder::initialize() {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
40 if (!has_error() && _dbghelp_handle == NULL) {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
41 HMODULE handle = ::LoadLibrary("dbghelp.dll");
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
42 if (!handle) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
43 _decoder_status = helper_not_found;
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
44 return;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
45 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
46
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
47 _dbghelp_handle = handle;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
48
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
49 pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
50 pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
51 _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
52 _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName");
2022
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 if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
55 _pfnSymGetSymFromAddr64 = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
56 _pfnUndecorateSymbolName = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
57 ::FreeLibrary(handle);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
58 _dbghelp_handle = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
59 _decoder_status = helper_func_error;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
60 return;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
61 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
62
7580
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
63 HANDLE hProcess = ::GetCurrentProcess();
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
64 _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
65 if (!_pfnSymInitialize(hProcess, NULL, TRUE)) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
66 _pfnSymGetSymFromAddr64 = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
67 _pfnUndecorateSymbolName = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
68 ::FreeLibrary(handle);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
69 _dbghelp_handle = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
70 _decoder_status = helper_init_error;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
71 return;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
72 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
73
7580
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
74 // set pdb search paths
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
75 pfn_SymSetSearchPath _pfn_SymSetSearchPath =
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
76 (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
77 pfn_SymGetSearchPath _pfn_SymGetSearchPath =
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
78 (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
79 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
80 char paths[MAX_PATH];
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
81 int len = sizeof(paths);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
82 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
83 paths[0] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
84 } else {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
85 // 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
86 len -= (int)strlen(paths);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
87 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
88
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
89 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
90 DWORD dwSize;
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
91 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
92 tmp_path[0] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
93 // 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
94 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
95 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
96 dwSize --;
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
97 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
98
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
99 tmp_path[dwSize] = '\0';
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
100
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
101 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
102 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
103 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
104 len -= dwSize + 1;
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
105 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
106 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
107
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
108 // 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
109 // path
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
110 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
111 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
112 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
113 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
114 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
115 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
116 strncat(paths, "\\bin", 4);
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
117 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
118 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
119
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
120 // 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
121 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
122 // 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
123 // 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
124 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
125 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
126 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
127 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
128
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
129 // if the directory exists
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
130 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
131 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
132 (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
133 // 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
134 // replaced 'jre' with 'bin'
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
135 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
136 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
137 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
138 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
139 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
140 }
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
141
dd7248d3e151 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 6842
diff changeset
142 _pfn_SymSetSearchPath(hProcess, paths);
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
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
145 // 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
146 // current function and comparing the result
6258
3b01d0321dfa 7186778: MachO decoder implementation for MacOSX
zgu
parents: 4803
diff changeset
147 address addr = (address)Decoder::demangle;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
148 char buf[MAX_PATH];
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
149 if (decode(addr, buf, sizeof(buf), NULL)) {
6258
3b01d0321dfa 7186778: MachO decoder implementation for MacOSX
zgu
parents: 4803
diff changeset
150 _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
151 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
152 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
153 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
154
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
155 void WindowsDecoder::uninitialize() {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
156 _pfnSymGetSymFromAddr64 = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
157 _pfnUndecorateSymbolName = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
158 if (_dbghelp_handle != NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
159 ::FreeLibrary(_dbghelp_handle);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
160 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
161 _dbghelp_handle = NULL;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
162 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
163
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
164 bool WindowsDecoder::can_decode_C_frame_in_vm() const {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
165 return (!has_error() && _can_decode_in_vm);
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
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
169 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
170 if (_pfnSymGetSymFromAddr64 != NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
171 PIMAGEHLP_SYMBOL64 pSymbol;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
172 char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
173 pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
174 pSymbol->MaxNameLength = MAX_PATH;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
175 pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
176 DWORD64 displacement;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
177 if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
178 if (buf != NULL) {
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
179 if (demangle(pSymbol->Name, buf, buflen)) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
180 jio_snprintf(buf, buflen, "%s", pSymbol->Name);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
181 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
182 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
183 if(offset != NULL) *offset = (int)displacement;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
184 return true;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
185 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
186 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
187 if (buf != NULL && buflen > 0) buf[0] = '\0';
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
188 if (offset != NULL) *offset = -1;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
189 return false;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
190 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
191
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3833
diff changeset
192 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
193 return _pfnUndecorateSymbolName != NULL &&
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
194 _pfnUndecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
195 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
196