Search in sources :

Example 1 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class ImageFactory method hasJavaRuntime.

/**
 * Checks to see if the supplied image has an available DTFJ Java Runtime. This is to force the parsing of the jextract XML
 * for legacy DTFJ and blob parsing for DDR. It does not make any guarantees about the quality and availability of the
 * run time data.
 * @return true if a non-corrupt runtime is returned
 */
private static boolean hasJavaRuntime(ImageReference imageReference) {
    if (null == imageReference || null == imageReference.image) {
        return false;
    }
    Iterator<?> spaces = imageReference.image.getAddressSpaces();
    while ((null != spaces) && spaces.hasNext()) {
        // search address spaces
        Object obj = spaces.next();
        if ((null != obj) && (obj instanceof ImageAddressSpace)) {
            ImageAddressSpace space = (ImageAddressSpace) obj;
            Iterator<?> procs = space.getProcesses();
            while ((null != procs) && procs.hasNext()) {
                // search processes
                Object procobj = procs.next();
                if ((null != procobj) && (procobj instanceof ImageProcess)) {
                    ImageProcess proc = (ImageProcess) procobj;
                    Iterator<?> runtimes = proc.getRuntimes();
                    while ((null != runtimes) && runtimes.hasNext()) {
                        Object rtobj = runtimes.next();
                        if ((null != rtobj) && (rtobj instanceof JavaRuntime)) {
                            // found a non-corrupt java runtime
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess)

Example 2 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class ImageStackFrame method getProcedureName.

public String getProcedureName() throws CorruptDataException {
    if (null == _procedureName) {
        ImageModule bestModule = null;
        ImageSymbol bestClosest = null;
        long bestDelta = Long.MAX_VALUE;
        for (Iterator i = this._space.getProcesses(); i.hasNext(); ) {
            Object nexti = i.next();
            if (nexti instanceof CorruptData)
                continue;
            ImageProcess process = (ImageProcess) nexti;
            if ((_procedureAddress.getAddress() != ((1L << process.getPointerSize()) - 1))) {
                try {
                    ImageModule module = process.getExecutable();
                    ImageSymbol closest = getClosestSymbolFrom(module);
                    long delta = getDelta(module, closest);
                    if (delta >= 0 && delta < bestDelta) {
                        bestModule = module;
                        bestClosest = closest;
                        bestDelta = delta;
                    }
                } catch (DataUnavailable e) {
                } catch (CorruptDataException e) {
                }
                try {
                    for (Iterator j = process.getLibraries(); j.hasNext(); ) {
                        Object next = j.next();
                        if (next instanceof CorruptData)
                            continue;
                        ImageModule module = (ImageModule) next;
                        ImageSymbol closest = getClosestSymbolFrom(module);
                        long delta = getDelta(module, closest);
                        if (delta >= 0 && delta < bestDelta) {
                            bestModule = module;
                            bestClosest = closest;
                            bestDelta = delta;
                        }
                    }
                } catch (DataUnavailable e) {
                } catch (CorruptDataException e) {
                }
            }
        }
        ImageSymbol closest = bestClosest;
        ImageModule module = bestModule;
        long delta = bestDelta;
        if (null != module) {
            String deltaString = "";
            if (delta == Long.MAX_VALUE) {
                deltaString = "<offset not available>";
            } else {
                if (delta >= 0) {
                    deltaString = "+0x" + Long.toHexString(delta);
                } else {
                    deltaString = "-0x" + Long.toHexString(delta);
                }
            }
            if (null != closest) {
                _procedureName = module.getName() + "::" + closest.getName() + deltaString;
            } else {
                _procedureName = module.getName() + deltaString;
            }
        }
    }
    // If we haven't found the symbol, we might as well record that fact.
    if (null == _procedureName) {
        _procedureName = "<unknown location>";
    }
    return _procedureName;
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 3 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class XKCommand method printSymbol.

private boolean printSymbol(long pointer, long diff, int pointerSize) {
    ImageProcess ip = ctx.getProcess();
    Iterator itModule;
    try {
        itModule = ip.getLibraries();
    } catch (CorruptDataException e) {
        // FIXME
        itModule = null;
    } catch (DataUnavailable e) {
        // FIXME
        itModule = null;
    }
    while (null != itModule && itModule.hasNext()) {
        ImageModule im = (ImageModule) itModule.next();
        Iterator itImageSection = im.getSections();
        while (itImageSection.hasNext()) {
            ImageSection is = (ImageSection) itImageSection.next();
            long startAddr = is.getBaseAddress().getAddress();
            long endAddr = startAddr + is.getSize();
            if (pointer >= startAddr && pointer < endAddr) {
                /* can we find a matching symbol? */
                long maxDifference = pointer - startAddr;
                ImageSymbol bestSymbol = null;
                for (Iterator iter = im.getSymbols(); iter.hasNext(); ) {
                    Object next = iter.next();
                    if (next instanceof CorruptData)
                        continue;
                    ImageSymbol symbol = (ImageSymbol) next;
                    long symbolAddress = symbol.getAddress().getAddress();
                    if (symbolAddress <= pointer && pointer - symbolAddress < maxDifference) {
                        maxDifference = pointer - symbolAddress;
                        bestSymbol = symbol;
                    }
                }
                try {
                    out.print(im.getName());
                } catch (CorruptDataException e) {
                    out.print(Exceptions.getCorruptDataExceptionString());
                }
                out.print("::");
                if (bestSymbol == null) {
                    out.print(is.getName());
                } else {
                    out.print(bestSymbol.getName());
                }
                out.print("+");
                out.print(Long.toString(maxDifference));
                // trying to find it elsewhere in the address space
                return true;
            }
        }
    }
    return false;
}
Also used : ImageSymbol(com.ibm.dtfj.image.ImageSymbol) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 4 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class PHDImageAddressSpace method getImageSections.

public Iterator<ImageSection> getImageSections() {
    List<ImageSection> list = new ArrayList<ImageSection>();
    for (Iterator<ImageProcess> ip = getProcesses(); ip.hasNext(); ) {
        ImageProcess p = ip.next();
        if (p instanceof CorruptData)
            continue;
        for (Iterator<ManagedRuntime> jr = p.getRuntimes(); jr.hasNext(); ) {
            ManagedRuntime mr = jr.next();
            if (mr instanceof CorruptData)
                continue;
            if (mr instanceof JavaRuntime) {
                for (Iterator<JavaHeap> jh = ((JavaRuntime) mr).getHeaps(); jh.hasNext(); ) {
                    JavaHeap hp = jh.next();
                    if (hp instanceof CorruptData)
                        continue;
                    for (Iterator<ImageSection> is = hp.getSections(); is.hasNext(); ) {
                        // Add the corrupt sections too
                        list.add(is.next());
                    }
                }
            }
        }
    }
    if (metaImageAddressSpace != null) {
        for (Iterator it = metaImageAddressSpace.getImageSections(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof ImageSection) {
                ImageSection section = (ImageSection) next;
                ImageSection newSection = new PHDImageSection(section.getName(), getPointer(section.getBaseAddress().getAddress()), section.getSize());
                list.add(newSection);
            }
        }
    }
    return list.iterator();
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaHeap(com.ibm.dtfj.java.JavaHeap) ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.CorruptData) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime)

Example 5 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class InfoProcCommand method printAddressSpaceInfo.

private void printAddressSpaceInfo() {
    ImageAddressSpace ias = ctx.getAddressSpace();
    ImageProcess ip = ias.getCurrentProcess();
    if (ip == null) {
        out.print("\t(No process in this address space)\n");
    } else {
        printProcessInfo();
    }
    out.print("\n");
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess)

Aggregations

ImageProcess (com.ibm.dtfj.image.ImageProcess)22 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)11 Iterator (java.util.Iterator)11 CorruptData (com.ibm.dtfj.image.CorruptData)9 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)9 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)8 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)8 Image (com.ibm.dtfj.image.Image)6 ImageModule (com.ibm.dtfj.image.ImageModule)5 ImageFactory (com.ibm.dtfj.image.ImageFactory)4 JavaObject (com.ibm.dtfj.java.JavaObject)3 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)2 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)2 ManagedRuntime (com.ibm.dtfj.runtime.ManagedRuntime)2 File (java.io.File)2 IOException (java.io.IOException)2