Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_VM/src/com/ibm/j9ddr/libraries/DTFJLibraryAdapter.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
package com.ibm.j9ddr.libraries;
24
25
import static java.util.logging.Level.SEVERE;
26
27
import java.io.File;
28
import java.io.FileNotFoundException;
29
import java.io.IOException;
30
import java.util.ArrayList;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Properties;
34
import java.util.logging.Level;
35
import java.util.logging.Logger;
36
37
import com.ibm.dtfj.corereaders.Builder;
38
import com.ibm.dtfj.corereaders.ClosingFileReader;
39
import com.ibm.dtfj.corereaders.DumpFactory;
40
import com.ibm.dtfj.corereaders.NewElfDump;
41
import com.ibm.dtfj.corereaders.NewAixDump;
42
import com.ibm.dtfj.corereaders.ICoreFileReader;
43
44
@SuppressWarnings("restriction")
45
public class DTFJLibraryAdapter implements Builder, LibraryAdapter {
46
private static final Logger logger = Logger.getLogger(LibraryCollector.LOGGER_NAME);
47
private File _parentDir;
48
private ArrayList<String> moduleNames = null;
49
private final ArrayList<String> errorMessages = new ArrayList<String>();
50
private boolean isAIX = false; //flag to indicate if running on AIX
51
52
public static void main(String[] args)
53
{
54
if (args.length > 0) {
55
for (int x = 0; x < args.length; x++) {
56
File coreFile = new File(args[x]);
57
System.out.println("Reading \"" + coreFile.getAbsolutePath() + "\"...");
58
DTFJLibraryAdapter adapter = new DTFJLibraryAdapter();
59
ArrayList<String> modules = adapter.getLibraryList(coreFile);
60
for(String module : modules) {
61
System.out.println("\t" + module);
62
}
63
}
64
} else {
65
System.out.println("Usage: \"LibraryAdapter <core files> ...\"");
66
System.exit(1);
67
}
68
}
69
70
public boolean isLibraryCollectionRequired(File coreFile) {
71
ICoreFileReader reader = null;
72
try {
73
ClosingFileReader closingFile = new ClosingFileReader(coreFile);
74
reader = DumpFactory.createDumpForCore(closingFile);
75
} catch (Exception e) {
76
logger.log(SEVERE, "Could not determine if library collection is required for " + coreFile.getAbsolutePath(), e);
77
errorMessages.add(e.getMessage());
78
return false; //if this fails, then so would any collection attempt as well
79
}
80
if (reader instanceof NewElfDump) {
81
return true;
82
}
83
if (reader instanceof NewAixDump) {
84
return true;
85
}
86
return false;
87
}
88
89
90
91
public ArrayList<String> getLibraryList(final File coreFile)
92
{
93
if(moduleNames == null) {
94
moduleNames = new ArrayList<String>();
95
try {
96
_parentDir = coreFile.getParentFile();
97
logger.fine("Creating DTFJ core file reader");
98
ClosingFileReader closingFile = new ClosingFileReader(coreFile);
99
ICoreFileReader reader = DumpFactory.createDumpForCore(closingFile);
100
isAIX = (reader instanceof NewAixDump);
101
logger.fine("Extracting modules");
102
reader.extract(this);
103
} catch (FileNotFoundException e) {
104
logger.log(SEVERE, "Could not open core file " + coreFile.getAbsolutePath(), e);
105
errorMessages.add(e.getMessage());
106
} catch (IOException e) {
107
logger.log(SEVERE, "Error processing core file " + coreFile.getAbsolutePath(), e);
108
errorMessages.add(e.getMessage());
109
}
110
}
111
return moduleNames;
112
}
113
114
public ArrayList<String> getErrorMessages() {
115
return errorMessages;
116
}
117
118
public ClosingFileReader openFile(String filename) throws IOException
119
{
120
//given that we may be looking for a file which came from another system, look it up in our support file dir first (we need that to over-ride the absolute path since it may be looking for a file in the same location as one on the local machine - this happens often if moving a core file from one Unix system to another)
121
ClosingFileReader candidate = null;
122
File absolute = new File(filename);
123
String fileName = absolute.getName();
124
File supportFileCopy = new File(_parentDir, fileName);
125
if (supportFileCopy.exists()) {
126
candidate = new ClosingFileReader(supportFileCopy);
127
} else {
128
candidate = new ClosingFileReader(absolute);
129
}
130
return candidate;
131
}
132
133
@SuppressWarnings("unchecked")
134
public Object buildModule(String name, Properties properties, Iterator sections, Iterator symbols, long loadAddress)
135
{
136
logger.fine("Module : " + name);
137
if(isAIX) {
138
int pos = name.indexOf(".a("); //check on AIX if module is the .a file or library
139
if((pos != -1) && (name.lastIndexOf(')') == name.length() - 1)) {
140
moduleNames.add(name.substring(0, pos + 2));
141
} else {
142
moduleNames.add(name);
143
}
144
} else {
145
moduleNames.add(name);
146
}
147
return null;
148
}
149
150
@SuppressWarnings("unchecked")
151
public Object buildProcess(Object addressSpace, String pid, String commandLine, Properties environment, Object currentThread, Iterator threads, Object executable, Iterator libraries, int addressSize)
152
{
153
if(logger.isLoggable(Level.FINEST)) {
154
String msg = String.format("Building process %s : %s", pid, commandLine);
155
logger.finest(msg);
156
}
157
return null; //no-op
158
}
159
160
public Object buildAddressSpace(String name, int id)
161
{
162
if(logger.isLoggable(Level.FINEST)) {
163
String msg = String.format("Building address space %s[%d]", name, id);
164
logger.finest(msg);
165
}
166
return null; //no-op
167
}
168
169
public Object buildRegister(String name, Number value)
170
{
171
return null; //no-op
172
}
173
174
public Object buildStackSection(Object addressSpace, long stackStart, long stackEnd)
175
{
176
return null; //no-op
177
}
178
179
@SuppressWarnings("unchecked")
180
public Object buildThread(String name, Iterator registers, Iterator stackSections, Iterator stackFrames, Properties properties, int signalNumber)
181
{
182
if(logger.isLoggable(Level.FINEST)) {
183
String msg = String.format("Building thread %s [signal %d]", name, signalNumber);
184
logger.finest(msg);
185
}
186
return null; //no-op
187
}
188
189
public Object buildModuleSection(Object addressSpace, String name, long imageStart, long imageEnd)
190
{
191
if(logger.isLoggable(Level.FINEST)) {
192
String msg = String.format("Building module %s [0x%s - 0x%s]", name, Long.toHexString(imageStart), Long.toHexString(imageEnd));
193
logger.finest(msg);
194
}
195
return null; //no-op
196
}
197
198
public Object buildStackFrame(Object addressSpace, long stackBasePointer, long pc)
199
{
200
return null; //no-op
201
}
202
203
public Object buildSymbol(Object addressSpace, String functionName, long relocatedFunctionAddress)
204
{
205
return null; //no-op
206
}
207
208
public Object buildCorruptData(Object addressSpace, String message, long address)
209
{
210
return null; //no-op
211
}
212
213
public long getEnvironmentAddress()
214
{
215
return 0; //no-op
216
}
217
218
@SuppressWarnings("unchecked")
219
public long getValueOfNamedRegister(List registers, String string)
220
{
221
return 0; //no-op
222
}
223
224
public void setExecutableUnavailable(String description)
225
{
226
errorMessages.add("Library collection not possible as the executable cannot be found [" + description + "]");
227
if(logger.isLoggable(Level.FINEST)) {
228
String msg = String.format("Executable not available : %s", description);
229
logger.warning(msg);
230
}
231
}
232
233
public void setOSType(String osType)
234
{
235
if(logger.isLoggable(Level.FINEST)) {
236
String msg = String.format("OS Type : %s", osType);
237
logger.finest(msg);
238
}
239
}
240
241
public void setCPUType(String cpuType)
242
{
243
//no-op
244
}
245
246
public void setCPUSubType(String subType)
247
{
248
//no-op
249
}
250
251
public void setCreationTime(long millis)
252
{
253
//no-op
254
}
255
256
@SuppressWarnings("unchecked")
257
public Object buildModule(String name, Properties properties, Iterator sections, Iterator symbols)
258
{
259
if(logger.isLoggable(Level.FINEST)) {
260
String msg = String.format("Building module %s", name);
261
logger.finest(msg);
262
}
263
return null;
264
}
265
266
}
267
268