Search in sources :

Example 1 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace 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 ImageAddressSpace

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

the class XXCommand method doCommand.

public void doCommand(String[] args) {
    Long address;
    String param = args[0];
    address = Utils.longFromStringWithPrefix(param);
    if (null == address) {
        out.println("invalid hex address specify; address must be specified as " + "\"0x<hex_address>\"");
        return;
    }
    out.print("\n");
    boolean found = false;
    for (int index = 0; index < argUnitNumber; index++) {
        long currAddr = address.longValue() + (index * argUnitSize);
        out.print("\t");
        out.print(Utils.toHex(currAddr));
        out.print(": ");
        ImageAddressSpace ias = ctx.getAddressSpace();
        ImagePointer ip = ias.getPointer(currAddr);
        byte b = 0;
        short s = 0;
        int i = 0;
        long l = 0;
        try {
            switch(argUnitSize) {
                case 1:
                    b = ip.getByteAt(0);
                    break;
                case 2:
                    s = ip.getShortAt(0);
                    break;
                case 4:
                    i = ip.getIntAt(0);
                    break;
                case 8:
                    l = ip.getLongAt(0);
                    break;
            }
            found = true;
        } catch (CorruptDataException e) {
            found = false;
        } catch (MemoryAccessException e) {
            found = false;
        }
        if (found) {
            switch(argUnitSize) {
                case 1:
                    out.print(Utils.toFixedWidthHex(b));
                    break;
                case 2:
                    out.print(Utils.toFixedWidthHex(s));
                    break;
                case 4:
                    out.print(Utils.toFixedWidthHex(i));
                    break;
                case 8:
                    out.print(Utils.toFixedWidthHex(l));
                    break;
            }
        }
        out.print("\n");
    }
    if (!found) {
        out.print("<address not found in any address space>");
    }
    out.print("\n");
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImagePointer(com.ibm.dtfj.image.ImagePointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 3 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace 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)

Example 4 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace 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();
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) Vector(java.util.Vector) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime)

Example 5 with ImageAddressSpace

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

the class HexdumpCommand method doCommand.

public void doCommand(String[] args) {
    StringBuffer stringBuffer = new StringBuffer();
    ImageAddressSpace imageAddressSpace = ctx.getAddressSpace();
    if (null == imageAddressSpace) {
        out.println("Could not find an address space which contains a process in this core file");
        return;
    }
    long addressInDecimal = 0;
    // dump 256 bytes by default
    int numBytesToPrint = 16 * 16;
    int asciiIndex = 0;
    if (args.length != 0) {
        Long address = Utils.longFromString(args[0]);
        if (null == address) {
            out.println("Specified address is invalid");
            return;
        }
        addressInDecimal = address.longValue();
    } else {
        out.println("\"hexdump\" requires at least an address parameter");
        return;
    }
    if (args.length > 1) {
        try {
            numBytesToPrint = Integer.parseInt(args[1]);
        } catch (NumberFormatException nfe) {
            out.println("Specified length is invalid");
            return;
        }
    }
    ImagePointer imagePointerBase = imageAddressSpace.getPointer(addressInDecimal);
    boolean is_zOSdump = false;
    try {
        is_zOSdump = ctx.getImage().getSystemType().toLowerCase().indexOf("z/os") >= 0;
    } catch (DataUnavailable e1) {
    // unable to get the dump OS type, continue without the additional zOS EBCDIC option
    } catch (CorruptDataException e1) {
    // unable to get the dump OS type, continue without the additional zOS EBCDIC option
    }
    String asciiChars = "";
    String ebcdicChars = "";
    long i;
    for (i = 0; i < numBytesToPrint; i++) {
        ImagePointer imagePointer = imagePointerBase.add(i);
        // stringBuffer.append(Long.toHexString(imagePointer.getAddress())+":\t");
        try {
            Byte byteValue = new Byte(imagePointer.getByteAt(0));
            asciiIndex = (int) byteValue.byteValue();
            if (asciiIndex < 0) {
                asciiIndex += 256;
            }
            String rawHexString = Integer.toHexString(byteValue.intValue());
            String fixedHexString = fixHexStringLength(rawHexString);
            String hexText = fixedHexString;
            if (0 == i % 4) {
                hexText = " " + hexText;
            }
            if (0 == i % 16) {
                hexText = "\n" + Long.toHexString(imagePointer.getAddress()) + ":" + hexText;
                asciiChars = "  |";
                ebcdicChars = " |";
            }
            stringBuffer.append(hexText);
            asciiChars += Utils.byteToAscii.substring(asciiIndex, asciiIndex + 1);
            if (15 == i % 16 && i != 0) {
                asciiChars += "|";
                stringBuffer.append(asciiChars);
            }
            if (is_zOSdump) {
                // for zOS dumps, output additional EBCDIC interpretation of the memory byes
                ebcdicChars += Utils.byteToEbcdic.substring(asciiIndex, asciiIndex + 1);
                if (15 == i % 16 && i != 0) {
                    ebcdicChars += "|";
                    stringBuffer.append(ebcdicChars);
                }
            }
        } catch (MemoryAccessException e) {
            out.println("Address not in memory - 0x" + Long.toHexString(imagePointer.getAddress()));
            return;
        } catch (CorruptDataException e) {
            out.println("Dump data is corrupted");
            return;
        }
    }
    long undisplayedBytes = 16 - i % 16;
    if (16 != undisplayedBytes) {
        stringBuffer.append(padSpace(undisplayedBytes, asciiChars));
        if (is_zOSdump) {
            // Add padding and output the remaining EBCDIC characters
            for (int j = 0; j < undisplayedBytes; j++) {
                ebcdicChars = " " + ebcdicChars;
            }
            stringBuffer.append(" " + ebcdicChars);
        }
    }
    stringBuffer.append("\n");
    out.println(new String(stringBuffer));
    /*properties.put(Utils.CURRENT_MEM_ADDRESS, 
				Long.toHexString(addressInDecimal+numBytesToPrint));*/
    ctx.getProperties().put(Utils.CURRENT_MEM_ADDRESS, new Long(addressInDecimal));
    ctx.getProperties().put(Utils.CURRENT_NUM_BYTES_TO_PRINT, new Integer(numBytesToPrint));
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImagePointer(com.ibm.dtfj.image.ImagePointer) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Aggregations

ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)20 ImageProcess (com.ibm.dtfj.image.ImageProcess)11 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)8 Iterator (java.util.Iterator)8 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)7 Image (com.ibm.dtfj.image.Image)7 CorruptData (com.ibm.dtfj.image.CorruptData)5 ImageFactory (com.ibm.dtfj.image.ImageFactory)5 ImagePointer (com.ibm.dtfj.image.ImagePointer)5 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)4 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)4 IOException (java.io.IOException)4 JavaObject (com.ibm.dtfj.java.JavaObject)3 File (java.io.File)3 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImageModule (com.ibm.dtfj.image.ImageModule)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Vector (java.util.Vector)2 ImageSection (com.ibm.dtfj.image.ImageSection)1