Search in sources :

Example 6 with MemoryFault

use of com.ibm.j9ddr.corereaders.memory.MemoryFault in project openj9 by eclipse.

the class GpInfoCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    long vmAddress = context.vmAddress;
    try {
        long j9rasAddress = CommandUtils.followPointerFromStructure(context, "J9JavaVM", vmAddress, "j9ras");
        long crashInfoAddress = CommandUtils.followPointerFromStructure(context, "J9RAS", j9rasAddress, "crashInfo");
        if (crashInfoAddress != 0l) {
            long failingThread = CommandUtils.followPointerFromStructure(context, "J9RASCrashInfo", crashInfoAddress, "failingThread");
            long failingThreadID = CommandUtils.followPointerFromStructure(context, "J9RASCrashInfo", crashInfoAddress, "failingThreadID");
            long gpinfo = CommandUtils.followPointerFromStructure(context, "J9RASCrashInfo", crashInfoAddress, "gpInfo");
            out.println("Failing Thread: !j9vmthread 0x" + Long.toHexString(failingThread));
            out.println("Failing Thread ID: 0x" + Long.toHexString(failingThreadID) + " (" + failingThreadID + ")");
            out.println("gpInfo:");
            out.println(CommandUtils.getCStringAtAddress(context.process, gpinfo));
        } else {
            out.println("Core does not appear to have been triggered by a gpf. No J9RASCrashInfo found.");
        }
    } catch (MemoryFault e) {
        throw new DDRInteractiveCommandException(e);
    } catch (com.ibm.j9ddr.NoSuchFieldException e) {
        throw new DDRInteractiveCommandException(e);
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 7 with MemoryFault

use of com.ibm.j9ddr.corereaders.memory.MemoryFault in project openj9 by eclipse.

the class VMDataFactory method foundRAS.

private static ImageInputStream foundRAS(IProcess addressSpace, long candidateAddress) throws IOException {
    try {
        j9RASAddress = candidateAddress;
        String structureFileName = System.getProperty(STRUCTUREFILE_PROPERTY);
        if (structureFileName != null) {
            // for it in the blob archive
            try {
                return getStructureDataFromFile(structureFileName, addressSpace);
            } catch (FileNotFoundException e) {
                return getBlobFromArchive(structureFileName, addressSpace);
            }
        }
        int j9RASVersion = addressSpace.getIntAt(candidateAddress + J9RAS_VERSION_OFFSET);
        short j9RASMajorVersion = (short) (j9RASVersion >> 16);
        if (j9RASMajorVersion < MINIMUM_J9RAS_MAJOR_VERSION) {
            return locateInServiceVMStructure(addressSpace);
        }
        long ddrDataStart = addressSpace.getPointerAt(candidateAddress + DDR_DATA_POINTER_OFFSET);
        if (0 == ddrDataStart) {
            // CMVC 172446 : no valid address to DDR blob, so see if we can locate it via the blob archive
            try {
                return locateInServiceVMStructure(addressSpace);
            } catch (IOException e) {
                // failed to locate a blob
                MissingDDRStructuresException ioe = new MissingDDRStructuresException(addressSpace, "System dump was generated by a DDR-enabled JVM, but did not contain embedded DDR structures. This dump cannot be analyzed by DDR. " + "You can specify the location of a DDR structure file to use with the " + STRUCTUREFILE_PROPERTY + " system property");
                ioe.initCause(e);
                throw ioe;
            }
        }
        // the address may be a marker to treat it in a special way, rather than as an actual address
        // -1 = the blob is located directly after this structure
        // -2 = there is only a blob descriptor loaded
        long marker = (addressSpace.bytesPerPointer() == 4) ? 0xFFFFFFFF00000000L | ddrDataStart : ddrDataStart;
        if (marker == -2) {
            StructureHeader header = new StructureHeader((byte) 1);
            ddrDataStart = candidateAddress + DDR_DATA_POINTER_OFFSET + (addressSpace.bytesPerPointer() * 2);
            ImageInputStream stream = new IMemoryImageInputStream(addressSpace, ddrDataStart);
            header.readBlobVersion(stream);
            return getBlobFromLibrary(addressSpace, header);
        }
        if (marker == -1) {
            if (j9RASVersion == 0x100000) {
                // there is one pointer in the way that needs to be skipped over
                ddrDataStart = candidateAddress + DDR_DATA_POINTER_OFFSET + (addressSpace.bytesPerPointer() * 2);
            } else {
                MissingDDRStructuresException ioe = new MissingDDRStructuresException(addressSpace, "System dump was generated by a DDR-enabled JVM, but did not contain embedded DDR structures. This dump cannot be analyzed by DDR. " + "You can specify the location of a DDR structure file to use with the " + STRUCTUREFILE_PROPERTY + " system property");
                throw ioe;
            }
        }
        return new IMemoryImageInputStream(addressSpace, ddrDataStart);
    } catch (MemoryFault e) {
        // put the stack trace to the log
        Logger logger = Logger.getLogger(LoggerNames.LOGGER_STRUCTURE_READER);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        logger.logp(FINE, null, null, sw.toString());
        throw new IOException(e.getMessage());
    }
}
Also used : MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IMemoryImageInputStream(com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Logger(java.util.logging.Logger) IMemoryImageInputStream(com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream) MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) StringWriter(java.io.StringWriter) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) PrintWriter(java.io.PrintWriter)

Example 8 with MemoryFault

use of com.ibm.j9ddr.corereaders.memory.MemoryFault in project openj9 by eclipse.

the class VMDataFactory method getJ9VMBuildInCore.

private static String getJ9VMBuildInCore(IProcess process) throws IOException {
    try {
        // Find J9VM build ID
        byte[] pattern = null;
        try {
            // "J9VM - YYYYMMDD_BUILD_FLAGS"
            pattern = "J9VM - ".getBytes("ASCII");
        } catch (UnsupportedEncodingException e) {
            // This shouldn't happen
            throw new Error(e);
        }
        long addr = process.findPattern(pattern, 1, 0);
        if (addr != -1) {
            // get string between first and second underscores
            // we can't hard-code offset as z/OS processes may contain extra bit
            long startBuildIDAddr = -1;
            for (long i = 0; i < 30; i++) {
                // search max of 30 bytes
                if (process.getByteAt(addr + i) == (byte) '_') {
                    if (startBuildIDAddr == -1) {
                        startBuildIDAddr = addr + i + 1;
                    } else {
                        // we've found second underscore
                        byte[] buildID = new byte[(int) (addr + i - startBuildIDAddr)];
                        for (int j = 0; j < addr + i - startBuildIDAddr; j++) {
                            buildID[j] = process.getByteAt(startBuildIDAddr + j);
                        }
                        return new String(buildID, "UTF-8");
                    }
                }
            }
        }
    } catch (MemoryFault e) {
        throw new IOException(e.getMessage());
    }
    throw new JVMNotDDREnabledException(process, "No J9VM build ID found in process");
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException)

Example 9 with MemoryFault

use of com.ibm.j9ddr.corereaders.memory.MemoryFault in project openj9 by eclipse.

the class JniImageInputStream method read.

@Override
public int read() throws IOException {
    try {
        byte readAddress = memory.getByteAt(streamPos);
        streamPos++;
        return readAddress;
    } catch (MemoryFault e) {
        throw new IOException(e.getMessage() + ":" + e.getAddress());
    }
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) IOException(java.io.IOException)

Example 10 with MemoryFault

use of com.ibm.j9ddr.corereaders.memory.MemoryFault in project openj9 by eclipse.

the class BaseWindowsOSThread method walkStack32.

private void walkStack32() throws CorruptDataException {
    // Windows stack frames can be read by following the ebp to the base of
    // the stack: old ebp is at ebp(0) and and return address to parent context
    // is ebp(sizeof(void*))
    // 1) find the ebp in the register file
    long ebp = getBasePointer();
    long eip = getInstructionPointer();
    long esp = getStackPointer();
    long stackStart = getStackStart();
    long stackEnd = getStackEnd();
    // eip may be -1 if we're in a system call
    if (-1 == eip && stackStart <= esp && esp < stackEnd) {
        try {
            eip = process.getPointerAt(esp);
        } catch (MemoryFault e) {
        // ignore
        }
    }
    int bytesPerPointer = process.bytesPerPointer();
    // Add the current frame first. If ebp doesn't point into the stack, try esp.
    if (Addresses.lessThanOrEqual(stackStart, ebp) && Addresses.lessThan(ebp, stackEnd)) {
        stackFrames.add(new OSStackFrame(ebp, eip));
    } else if (Addresses.lessThan(stackStart, esp) && Addresses.lessThan(esp, stackEnd)) {
        stackFrames.add(new OSStackFrame(esp, eip));
        ebp = esp + bytesPerPointer;
    }
    while (stackStart <= ebp && ebp < stackEnd) {
        try {
            long newBP = process.getPointerAt(ebp);
            long retAddress = process.getPointerAt(ebp + bytesPerPointer);
            stackFrames.add(new OSStackFrame(newBP, retAddress));
            ebp = newBP;
        } catch (MemoryFault e) {
            // stop trying to read meaningless memory
            break;
        }
    }
}
Also used : IOSStackFrame(com.ibm.j9ddr.corereaders.osthread.IOSStackFrame) OSStackFrame(com.ibm.j9ddr.corereaders.osthread.OSStackFrame) MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault)

Aggregations

MemoryFault (com.ibm.j9ddr.corereaders.memory.MemoryFault)15 IOException (java.io.IOException)10 CorruptDataException (com.ibm.j9ddr.CorruptDataException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 IMemoryImageInputStream (com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream)2 IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)2 IModule (com.ibm.j9ddr.corereaders.memory.IModule)2 Module (com.ibm.j9ddr.corereaders.memory.Module)2 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Properties (java.util.Properties)2 Logger (java.util.logging.Logger)2 ImageInputStream (javax.imageio.stream.ImageInputStream)2 CorruptCoreException (com.ibm.j9ddr.corereaders.CorruptCoreException)1 IMemorySource (com.ibm.j9ddr.corereaders.memory.IMemorySource)1 IProcess (com.ibm.j9ddr.corereaders.memory.IProcess)1 ISymbol (com.ibm.j9ddr.corereaders.memory.ISymbol)1 MissingFileModule (com.ibm.j9ddr.corereaders.memory.MissingFileModule)1