use of com.ibm.dtfj.image.ImageModule 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.ImageModule in project openj9 by eclipse.
the class ImageSymbolTest method slurpSymbolsFromLibraryIterator.
private void slurpSymbolsFromLibraryIterator(Iterator<?> it, List<Object> list) {
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof ImageModule) {
ImageModule mod = (ImageModule) obj;
Iterator<?> symIt = mod.getSymbols();
while (symIt.hasNext()) {
Object symObj = symIt.next();
if (symObj instanceof ImageSymbol) {
list.add(symObj);
} else {
System.err.println("Skipping symbol object: " + symObj + ", type " + symObj.getClass().getName());
}
}
} else {
System.err.println("Skipping module object: " + obj + ", type " + obj.getClass().getName());
}
}
}
use of com.ibm.dtfj.image.ImageModule in project openj9 by eclipse.
the class ThreadSectionParser method parseNativeStackTrace.
/**
* Parse the native stack line information
* @throws ParserException
*/
private void parseNativeStackTrace(long threadID, boolean buildModel) throws ParserException {
IAttributeValueMap results = null;
// Process the version lines
processTagLineOptional(T_3XMTHREADINFO3);
while ((results = processTagLineOptional(T_4XENATIVESTACK)) != null) {
if (!buildModel)
continue;
String module = results.getTokenValue(STACK_MODULE);
String routine = results.getTokenValue(STACK_ROUTINE);
long address = results.getLongValue(STACK_PROC_ADDRESS);
long routine_address = results.getLongValue(STACK_ROUTINE_ADDRESS);
long routine_offset = results.getLongValue(STACK_ROUTINE_OFFSET);
long module_offset = results.getLongValue(STACK_MODULE_OFFSET);
String file = results.getTokenValue(STACK_FILE);
int line = results.getIntValue(STACK_LINE);
// Allow for missing data
if (routine_address == IBuilderData.NOT_AVAILABLE && address != IBuilderData.NOT_AVAILABLE && routine_offset != IBuilderData.NOT_AVAILABLE) {
routine_address = address - routine_offset;
} else if (routine_offset == IBuilderData.NOT_AVAILABLE && address != IBuilderData.NOT_AVAILABLE && routine_address != IBuilderData.NOT_AVAILABLE) {
routine_offset = address - routine_address;
} else if (address == IBuilderData.NOT_AVAILABLE && routine_offset != IBuilderData.NOT_AVAILABLE && routine_address != IBuilderData.NOT_AVAILABLE) {
address = routine_address + routine_offset;
}
String name;
if (module != null) {
name = module;
} else {
name = "";
}
if (file != null) {
name = name + "(" + file;
if (line != IBuilderData.NOT_AVAILABLE) {
name = name + ":" + line;
}
name = name + ")";
}
if (module != null) {
ImageModule mod = fImageProcessBuilder.addLibrary(module);
if (address != IBuilderData.NOT_AVAILABLE && module_offset != IBuilderData.NOT_AVAILABLE) {
String modAddress = "0x" + Long.toHexString(address - module_offset);
fImageProcessBuilder.addProperty(mod, "Load address", modAddress);
}
if (routine != null && address != IBuilderData.NOT_AVAILABLE && routine_offset != IBuilderData.NOT_AVAILABLE && routine_address != IBuilderData.NOT_AVAILABLE) {
fImageProcessBuilder.addRoutine(mod, routine, routine_address);
name = name + "::" + routine + (routine_offset >= 0 ? "+" : "-") + routine_offset;
} else {
if (routine_offset != IBuilderData.NOT_AVAILABLE) {
name = name + (routine_offset >= 0 ? "+" : "-") + routine_offset;
} else {
if (address != IBuilderData.NOT_AVAILABLE) {
name = name + "::0x" + Long.toHexString(address);
}
}
}
} else {
if (routine != null) {
if (routine_offset != IBuilderData.NOT_AVAILABLE) {
name = "::" + routine + (routine_offset >= 0 ? "+" : "-") + routine_offset;
} else {
name = "::" + routine;
}
} else {
if (address != IBuilderData.NOT_AVAILABLE) {
name = "::0x" + Long.toHexString(address);
} else {
name = null;
}
}
}
fImageProcessBuilder.addImageStackFrame(threadID, name, 0, address);
}
}
use of com.ibm.dtfj.image.ImageModule 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());
}
}
}
}
use of com.ibm.dtfj.image.ImageModule in project openj9 by eclipse.
the class J9DDRImageProcess method getLibraries.
public Iterator<?> getLibraries() throws DataUnavailable, CorruptDataException {
try {
Collection<? extends IModule> modules = process.getModules();
List<ImageModule> libraries = new ArrayList<ImageModule>();
for (IModule module : modules) {
libraries.add(new J9DDRImageModule(process, module));
}
return libraries.iterator();
} catch (com.ibm.j9ddr.CorruptDataException e) {
throw new DTFJCorruptDataException(new J9DDRCorruptData(process, e));
}
}
Aggregations