use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.
the class InfoProcCommand method printEnvironmentVariables.
private void printEnvironmentVariables() {
ImageProcess ip = ctx.getProcess();
out.print("\t Environment variables:");
out.print("\n");
Properties variables;
try {
variables = ip.getEnvironment();
} catch (CorruptDataException e) {
out.print("\t " + Exceptions.getCorruptDataExceptionString() + "\n");
return;
} catch (DataUnavailable e) {
out.print("\t " + Exceptions.getDataUnavailableString() + "\n");
return;
}
Enumeration<?> keys = variables.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
printVariableInfo(key, variables.getProperty(key));
}
}
use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.
the class InfoSymCommand method listModules.
private void listModules(String moduleName) {
ImageProcess ip = ctx.getProcess();
try {
Object e = ip.getExecutable();
if (e instanceof ImageModule) {
ImageModule exe = (ImageModule) e;
if (moduleName != null) {
if (checkModuleName(exe.getName(), moduleName)) {
printModule(exe, true);
}
} else {
printModule(exe, false);
}
} else if (e instanceof CorruptData) {
CorruptData corruptObj = (CorruptData) e;
// warn the user that this image library is corrupt
out.print("\t <corrupt executable encountered: " + corruptObj.toString() + ">\n\n");
}
} catch (DataUnavailable e) {
out.println(Exceptions.getDataUnavailableString());
} catch (CorruptDataException e) {
out.println(Exceptions.getCorruptDataExceptionString());
}
Iterator iLibs;
try {
iLibs = ip.getLibraries();
} catch (DataUnavailable du) {
iLibs = null;
out.println(Exceptions.getDataUnavailableString());
} catch (CorruptDataException cde) {
iLibs = null;
out.println(Exceptions.getCorruptDataExceptionString());
}
// iterate through the libraries
while (null != iLibs && iLibs.hasNext()) {
Object next = iLibs.next();
if (next instanceof ImageModule) {
ImageModule mod = (ImageModule) next;
String currentName = null;
try {
currentName = mod.getName();
} catch (CorruptDataException e) {
out.print("\t <corrupt library name: " + mod.toString() + ">\n\n");
}
if (moduleName != null) {
if (checkModuleName(currentName, moduleName)) {
printModule(mod, true);
}
} else {
printModule(mod, false);
}
} else if (next instanceof CorruptData) {
CorruptData corruptObj = (CorruptData) next;
// warn the user that this image library is corrupt
out.print("\t <corrupt library encountered: " + corruptObj.toString() + ">\n\n");
} else {
// unexpected type in iterator
out.print("\t <corrupt library encountered>\n\n");
}
}
}
use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.
the class Utils method getRuntimes.
public static Iterator getRuntimes(Image loadedImage) {
Vector runtimes = new Vector();
Iterator itAddressSpace;
Iterator itProcess;
Iterator itRuntime;
ManagedRuntime mr;
ImageAddressSpace ias;
ImageProcess ip;
itAddressSpace = loadedImage.getAddressSpaces();
while (itAddressSpace.hasNext()) {
ias = (ImageAddressSpace) itAddressSpace.next();
itProcess = ias.getProcesses();
while (itProcess.hasNext()) {
ip = (ImageProcess) itProcess.next();
itRuntime = ip.getRuntimes();
while (itRuntime.hasNext()) {
// this iterator can contain ManagedRuntime or CorruptData objects
Object next = itRuntime.next();
if (next instanceof CorruptData) {
// skip any CorruptData objects
continue;
} else {
mr = (ManagedRuntime) next;
if (!runtimes.contains(mr))
runtimes.add(mr);
}
}
}
}
return runtimes.iterator();
}
use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.
the class OpenCommand method createContexts.
private void createContexts(Image loadedImage, String coreFilePath) {
if (loadedImage == null) {
// cannot create any contexts as an image has not been obtained
return;
}
boolean hasContexts = false;
Iterator<?> spaces = loadedImage.getAddressSpaces();
while (spaces.hasNext()) {
Object o = spaces.next();
if (o instanceof ImageAddressSpace) {
ImageAddressSpace space = (ImageAddressSpace) o;
Iterator<?> procs = space.getProcesses();
if (procs.hasNext()) {
while (procs.hasNext()) {
o = procs.next();
if (o instanceof ImageProcess) {
ImageProcess proc = (ImageProcess) o;
Iterator<?> runtimes = proc.getRuntimes();
if (runtimes.hasNext()) {
while (runtimes.hasNext()) {
o = runtimes.next();
if (o instanceof JavaRuntime) {
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, (JavaRuntime) o, coreFilePath);
hasContexts = true;
} else if (o instanceof CorruptData) {
logger.fine("CorruptData encountered in ImageProcess.getRuntimes(): " + ((CorruptData) o).toString());
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
hasContexts = true;
} else {
logger.fine("Unexpected class encountered in ImageProcess.getRuntimes()");
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
hasContexts = true;
}
}
} else {
// there are no runtimes so create a context for this process
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
hasContexts = true;
}
}
}
} else {
// context with only an address space
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, null, null, coreFilePath);
hasContexts = true;
}
} else {
// need a representation of a corrupt context
logger.fine("Skipping corrupt ImageAddress space");
}
}
if (!hasContexts) {
if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
out.println("Warning : no contexts were found, is this a valid core file ?");
}
}
}
use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.
the class DDRLibraryAdapter method constructLibraryList.
/**
* Constructs the list of libraries required using the DDR implementation of the DTFJ Image* API.
* This ensures that the correct classloading is used for determining which libraries to collect.
* @param coreFile core file to process
*/
@SuppressWarnings({ "unchecked" })
private void constructLibraryList(final File coreFile) {
moduleNames = new ArrayList<String>();
ImageFactory factory = new J9DDRImageFactory();
final Image image;
final boolean isAIX;
try {
image = factory.getImage(coreFile);
isAIX = image.getSystemType().toLowerCase().startsWith("aix");
} catch (IOException e) {
logger.log(SEVERE, "Could not open core file", e);
errorMessages.add(e.getMessage());
return;
} catch (CorruptDataException e) {
logger.log(SEVERE, "Could not determine system type", e);
errorMessages.add(e.getMessage());
return;
} catch (DataUnavailable e) {
logger.log(SEVERE, "Could not determine system type", e);
errorMessages.add(e.getMessage());
return;
}
for (Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
ImageAddressSpace space = (ImageAddressSpace) spaces.next();
for (Iterator procs = space.getProcesses(); procs.hasNext(); ) {
ImageProcess proc = (ImageProcess) procs.next();
try {
// add the executable to the list of libraries to be collected
ImageModule exe = proc.getExecutable();
moduleNames.add(exe.getName());
for (Iterator libraries = proc.getLibraries(); libraries.hasNext(); ) {
ImageModule module = (ImageModule) libraries.next();
String key = null;
try {
// handle CDE thrown by getName(), as this is required further on this call needs to succeed
if (isAIX) {
key = module.getName();
// check on AIX if module is the .a file or library
int pos = key.indexOf(".a(");
if ((pos != -1) && (key.lastIndexOf(')') == key.length() - 1)) {
key = key.substring(0, pos + 2);
}
} else {
key = module.getName();
}
logger.fine("Module : " + key);
if (!moduleNames.contains(key)) {
// don't store duplicate libraries
moduleNames.add(key);
}
} catch (Exception e) {
logger.log(WARNING, "Error getting module name", e);
}
}
} catch (DataUnavailable e) {
logger.log(WARNING, "Error getting library list", e);
errorMessages.add(e.getMessage());
} catch (com.ibm.dtfj.image.CorruptDataException e) {
logger.log(WARNING, "Error getting library list", e);
errorMessages.add(e.getMessage());
}
}
}
}
Aggregations