Search in sources :

Example 1 with ImageSymbol

use of com.ibm.dtfj.image.ImageSymbol 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 2 with ImageSymbol

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

the class ImageProcessBuilder method addRoutine.

public ImageSymbol addRoutine(ImageModule library, String name, long address) {
    ImagePointer addr = fImageAddressSpace.getPointer(address);
    ImageSymbol symbol = new JCImageSymbol(name, addr);
    JCImageModule mod = (JCImageModule) library;
    mod.addSymbol(symbol);
    return symbol;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCImageSymbol(com.ibm.dtfj.image.javacore.JCImageSymbol) ImageSymbol(com.ibm.dtfj.image.ImageSymbol) JCImageModule(com.ibm.dtfj.image.javacore.JCImageModule) JCImageSymbol(com.ibm.dtfj.image.javacore.JCImageSymbol)

Example 3 with ImageSymbol

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

the class ImageSymbolTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    Exception ddrException = null;
    Exception jextractException = null;
    Iterator<?> ddrLibIt = null;
    try {
        ddrLibIt = ddrProcess.getLibraries();
    } catch (Exception e) {
        e.printStackTrace();
        ddrException = e;
    }
    Iterator<?> jextractLibIt = null;
    try {
        jextractLibIt = jextractProcess.getLibraries();
    } catch (Exception e) {
        e.printStackTrace();
        jextractException = e;
    }
    if (ddrException != null || jextractException != null) {
        if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
            return;
        }
        if (ddrException != null) {
            fail("DDR threw an exception getting libraries and JExtract didn't");
        }
        if (jextractException != null) {
            fail("JExtract threw an exception getting libraries and DDR didn't");
        }
    }
    slurpSymbolsFromLibraryIterator(ddrLibIt, ddrObjects);
    slurpSymbolsFromLibraryIterator(jextractLibIt, jextractObjects);
    Comparator<Object> c = new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            ImageSymbol sym1 = (ImageSymbol) o1;
            ImageSymbol sym2 = (ImageSymbol) o2;
            return (int) Long.signum(sym1.getAddress().getAddress() - sym2.getAddress().getAddress());
        }
    };
    Collections.sort(ddrObjects, c);
    Collections.sort(jextractObjects, c);
}
Also used : ImageSymbol(com.ibm.dtfj.image.ImageSymbol) Comparator(java.util.Comparator) ImageSymbolComparator(com.ibm.j9ddr.view.dtfj.comparators.ImageSymbolComparator)

Example 4 with ImageSymbol

use of com.ibm.dtfj.image.ImageSymbol 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());
        }
    }
}
Also used : ImageSymbol(com.ibm.dtfj.image.ImageSymbol) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 5 with ImageSymbol

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

the class J9DDRImageModule method getSymbols.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.image.ImageModule#getSymbols()
	 */
public Iterator<?> getSymbols() {
    Collection<? extends ISymbol> symbols;
    try {
        symbols = delegate.getSymbols();
    } catch (DataUnavailableException e) {
        // JEXTRACT slightly arbitrary code here. DTFJ/JExtract uses the base address of the .text section as the
        // address of the corrupt data. We do the same for compatibility's sake.
        Collection<? extends IMemoryRange> memoryRanges = delegate.getMemoryRanges();
        long baseAddress = 0;
        for (IMemoryRange range : memoryRanges) {
            if (range.getName().contains(".text")) {
                baseAddress = range.getBaseAddress();
                break;
            }
        }
        return Collections.singletonList(new J9DDRCorruptData(process, e.getMessage(), baseAddress)).iterator();
    }
    List<ImageSymbol> dtfjSymbols = new ArrayList<ImageSymbol>(symbols.size());
    for (ISymbol symbol : symbols) {
        dtfjSymbols.add(new J9DDRImageSymbol(symbol.getName(), new J9DDRImagePointer(process, symbol.getAddress())));
    }
    return dtfjSymbols.iterator();
}
Also used : IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) DataUnavailableException(com.ibm.j9ddr.DataUnavailableException) ImageSymbol(com.ibm.dtfj.image.ImageSymbol) ISymbol(com.ibm.j9ddr.corereaders.memory.ISymbol) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

ImageSymbol (com.ibm.dtfj.image.ImageSymbol)8 ImageModule (com.ibm.dtfj.image.ImageModule)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)2 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImageProcess (com.ibm.dtfj.image.ImageProcess)2 ImageSection (com.ibm.dtfj.image.ImageSection)2 Iterator (java.util.Iterator)2 Image (com.ibm.dtfj.image.Image)1 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)1 ImageFactory (com.ibm.dtfj.image.ImageFactory)1 ImagePointer (com.ibm.dtfj.image.ImagePointer)1 JCImageModule (com.ibm.dtfj.image.javacore.JCImageModule)1 JCImageSymbol (com.ibm.dtfj.image.javacore.JCImageSymbol)1 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)1 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)1 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)1 DataUnavailableException (com.ibm.j9ddr.DataUnavailableException)1 IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)1 ISymbol (com.ibm.j9ddr.corereaders.memory.ISymbol)1