comparison 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
comparison
equal deleted inserted replaced
7460:6c3f47d964f3 7580:dd7248d3e151
47 _dbghelp_handle = handle; 47 _dbghelp_handle = handle;
48 48
49 pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions"); 49 pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions");
50 pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize"); 50 pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize");
51 _pfnSymGetSymFromAddr64 = (pfn_SymGetSymFromAddr64)::GetProcAddress(handle, "SymGetSymFromAddr64"); 51 _pfnSymGetSymFromAddr64 = (pfn_SymGetSymFromAddr64)::GetProcAddress(handle, "SymGetSymFromAddr64");
52 _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)GetProcAddress(handle, "UnDecorateSymbolName"); 52 _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName");
53 53
54 if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) { 54 if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) {
55 _pfnSymGetSymFromAddr64 = NULL; 55 _pfnSymGetSymFromAddr64 = NULL;
56 _pfnUndecorateSymbolName = NULL; 56 _pfnUndecorateSymbolName = NULL;
57 ::FreeLibrary(handle); 57 ::FreeLibrary(handle);
58 _dbghelp_handle = NULL; 58 _dbghelp_handle = NULL;
59 _decoder_status = helper_func_error; 59 _decoder_status = helper_func_error;
60 return; 60 return;
61 } 61 }
62 62
63 _pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS); 63 HANDLE hProcess = ::GetCurrentProcess();
64 if (!_pfnSymInitialize(GetCurrentProcess(), NULL, TRUE)) { 64 _pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS);
65 if (!_pfnSymInitialize(hProcess, NULL, TRUE)) {
65 _pfnSymGetSymFromAddr64 = NULL; 66 _pfnSymGetSymFromAddr64 = NULL;
66 _pfnUndecorateSymbolName = NULL; 67 _pfnUndecorateSymbolName = NULL;
67 ::FreeLibrary(handle); 68 ::FreeLibrary(handle);
68 _dbghelp_handle = NULL; 69 _dbghelp_handle = NULL;
69 _decoder_status = helper_init_error; 70 _decoder_status = helper_init_error;
70 return; 71 return;
72 }
73
74 // set pdb search paths
75 pfn_SymSetSearchPath _pfn_SymSetSearchPath =
76 (pfn_SymSetSearchPath)::GetProcAddress(handle, "SymSetSearchPath");
77 pfn_SymGetSearchPath _pfn_SymGetSearchPath =
78 (pfn_SymGetSearchPath)::GetProcAddress(handle, "SymGetSearchPath");
79 if (_pfn_SymSetSearchPath != NULL && _pfn_SymGetSearchPath != NULL) {
80 char paths[MAX_PATH];
81 int len = sizeof(paths);
82 if (!_pfn_SymGetSearchPath(hProcess, paths, len)) {
83 paths[0] = '\0';
84 } else {
85 // available spaces in path buffer
86 len -= (int)strlen(paths);
87 }
88
89 char tmp_path[MAX_PATH];
90 DWORD dwSize;
91 HMODULE hJVM = ::GetModuleHandle("jvm.dll");
92 tmp_path[0] = '\0';
93 // append the path where jvm.dll is located
94 if (hJVM != NULL && (dwSize = ::GetModuleFileName(hJVM, tmp_path, sizeof(tmp_path))) > 0) {
95 while (dwSize > 0 && tmp_path[dwSize] != '\\') {
96 dwSize --;
97 }
98
99 tmp_path[dwSize] = '\0';
100
101 if (dwSize > 0 && len > (int)dwSize + 1) {
102 strncat(paths, os::path_separator(), 1);
103 strncat(paths, tmp_path, dwSize);
104 len -= dwSize + 1;
105 }
106 }
107
108 // append $JRE/bin. Arguments::get_java_home actually returns $JRE
109 // path
110 char *p = Arguments::get_java_home();
111 assert(p != NULL, "empty java home");
112 size_t java_home_len = strlen(p);
113 if (len > (int)java_home_len + 5) {
114 strncat(paths, os::path_separator(), 1);
115 strncat(paths, p, java_home_len);
116 strncat(paths, "\\bin", 4);
117 len -= (int)(java_home_len + 5);
118 }
119
120 // append $JDK/bin path if it exists
121 assert(java_home_len < MAX_PATH, "Invalid path length");
122 // assume $JRE is under $JDK, construct $JDK/bin path and
123 // see if it exists or not
124 if (strncmp(&p[java_home_len - 3], "jre", 3) == 0) {
125 strncpy(tmp_path, p, java_home_len - 3);
126 tmp_path[java_home_len - 3] = '\0';
127 strncat(tmp_path, "bin", 3);
128
129 // if the directory exists
130 DWORD dwAttrib = GetFileAttributes(tmp_path);
131 if (dwAttrib != INVALID_FILE_ATTRIBUTES &&
132 (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
133 // tmp_path should have the same length as java_home_len, since we only
134 // replaced 'jre' with 'bin'
135 if (len > (int)java_home_len + 1) {
136 strncat(paths, os::path_separator(), 1);
137 strncat(paths, tmp_path, java_home_len);
138 }
139 }
140 }
141
142 _pfn_SymSetSearchPath(hProcess, paths);
71 } 143 }
72 144
73 // find out if jvm.dll contains private symbols, by decoding 145 // find out if jvm.dll contains private symbols, by decoding
74 // current function and comparing the result 146 // current function and comparing the result
75 address addr = (address)Decoder::demangle; 147 address addr = (address)Decoder::demangle;