Search in sources :

Example 11 with MemoryFault

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

the class ELFMemorySource method getBytes.

/* (non-Javadoc)
	 * @see com.ibm.j9ddr.corereaders.memory.IMemoryRange#getBytes(long, byte[], int, int)
	 */
public int getBytes(long address, byte[] buffer, int offset, int length) throws MemoryFault {
    if (Addresses.greaterThan(address + length - 1, getTopAddress())) {
        throw new MemoryFault(address + length, "Address out of range of memory range (overflow): " + this.toString());
    }
    if (Addresses.lessThan(address, baseAddress)) {
        throw new MemoryFault(address, "Address out of range of memory range (underflow): " + this.toString());
    }
    long rangeOffset = address - baseAddress;
    long seekAddress = fileOffset + rangeOffset;
    try {
        reader.seek(seekAddress);
        reader.readFully(buffer, offset, length);
    } catch (IOException e) {
        throw new MemoryFault(address, "IOException accessing ELF storage in " + reader, e);
    }
    return length;
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) IOException(java.io.IOException)

Example 12 with MemoryFault

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

the class ModuleStream method readFrom.

@Override
public void readFrom(MiniDumpReader dump, IAddressSpace as, boolean is64Bit) throws IOException, CorruptDataException {
    dump.seek(getLocation());
    int numberOfModules = dump.readInt();
    if (numberOfModules > 1024) {
        throw new CorruptDataException("Improbably high number of modules found: " + numberOfModules + ", location = " + Long.toHexString(getLocation()));
    }
    class ModuleData {

        long imageBaseAddress;

        Properties properties;

        int nameAddress;
    }
    ModuleData[] moduleData = new ModuleData[numberOfModules];
    for (int i = 0; i < numberOfModules; i++) {
        moduleData[i] = new ModuleData();
        moduleData[i].imageBaseAddress = dump.readLong();
        int imageSize = dump.readInt();
        int checksum = dump.readInt();
        int timeDateStamp = dump.readInt();
        moduleData[i].nameAddress = dump.readInt();
        moduleData[i].properties = readProperties(dump, imageSize, checksum, timeDateStamp);
    }
    for (ModuleData thisModule : moduleData) {
        final long imageBaseAddress = thisModule.imageBaseAddress;
        final String moduleName = getModuleName(dump, thisModule.nameAddress);
        final Properties properties = thisModule.properties;
        short magic;
        try {
            magic = as.getShortAt(imageBaseAddress);
            if (0x5A4D != magic) {
                logger.logp(Level.WARNING, "com.ibm.j9ddr.corereaders.minidump.ModuleStream", "readFrom", "Magic number was: " + Integer.toHexString(0xFFFF & magic) + " expected 0x5A4D");
            }
        } catch (MemoryFault e1) {
            logger.logp(Level.WARNING, "com.ibm.j9ddr.corereaders.minidump.ModuleStream", "readFrom", "MemoryFault reading magic number", e1);
        }
        long e_lfanewAddress = imageBaseAddress + 0x3c;
        // load the e_lfanew since that is the load-address-relative location of
        // the PE Header
        Collection<IMemoryRange> sections = new LinkedList<IMemoryRange>();
        try {
            long e_lfanew = 0xFFFFFFFFL & as.getIntAt(e_lfanewAddress);
            // push us to the start of the PE header
            long readingAddress = e_lfanew + imageBaseAddress;
            List<ISymbol> symbols = null;
            if (0 != e_lfanew) {
                loadModuleSections(as, imageBaseAddress, readingAddress, e_lfanew, sections);
                symbols = buildSymbols(dump, as, imageBaseAddress);
            }
            if (symbols == null) {
                symbols = new LinkedList<ISymbol>();
            }
            // Load the list of RUNTIME_FUNCTION structures that map code
            // ranges to stack unwind information.
            List<RuntimeFunction> runtimeFunctionList = null;
            runtimeFunctionList = buildRuntimeFunctionList(dump, as, imageBaseAddress);
            IModule module;
            if (runtimeFunctionList != null) {
                module = new UnwindModule(as.getProcesses().iterator().next(), moduleName, symbols, sections, thisModule.imageBaseAddress, properties, runtimeFunctionList);
            // Uncommend to dump unwind info as we find it. This is very verbose.
            // ((UnwindModule)module).dumpUndwindInfo(System.err);
            } else {
                module = new Module(as.getProcesses().iterator().next(), moduleName, symbols, sections, thisModule.imageBaseAddress, properties);
            }
            if (moduleName.toLowerCase().endsWith(".exe")) {
                dump.setExecutable(module);
            } else {
                dump.addLibrary(module);
            }
        } catch (RuntimeException e) {
            // Don't want to prevent RTE's propogating
            throw e;
        } catch (Exception e) {
            // this needs to be here in order to not fail completely whenever we
            // encounter a strange record
            logger.logp(Level.WARNING, "com.ibm.j9ddr.corereaders.minidump.ModuleStream", "readFrom", "Problem reading symbols", e);
        }
    }
}
Also used : IModule(com.ibm.j9ddr.corereaders.memory.IModule) ISymbol(com.ibm.j9ddr.corereaders.memory.ISymbol) CorruptDataException(com.ibm.j9ddr.CorruptDataException) Properties(java.util.Properties) LinkedList(java.util.LinkedList) IOException(java.io.IOException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) CorruptCoreException(com.ibm.j9ddr.corereaders.CorruptCoreException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) UnwindModule(com.ibm.j9ddr.corereaders.minidump.unwind.UnwindModule) IModule(com.ibm.j9ddr.corereaders.memory.IModule) Module(com.ibm.j9ddr.corereaders.memory.Module) UnwindModule(com.ibm.j9ddr.corereaders.minidump.unwind.UnwindModule) RuntimeFunction(com.ibm.j9ddr.corereaders.minidump.unwind.RuntimeFunction)

Example 13 with MemoryFault

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

the class ExtractMemoryCommand method run.

public void run(String command, String[] arguments, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (arguments.length != 3) {
        out.println("Unexpected number of arguments.");
        printUsage(out);
        return;
    }
    long address = 0L;
    if (arguments[0].startsWith("0x")) {
        address = Long.parseLong(arguments[0].substring(2), 16);
    } else {
        address = Long.parseLong(arguments[0], 16);
    }
    int length = 0;
    if (arguments[1].startsWith("0x")) {
        length = Integer.parseInt(arguments[1].substring(2), 16);
    } else {
        length = Integer.parseInt(arguments[1], 16);
    }
    String filename = arguments[2];
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(filename);
    } catch (FileNotFoundException e) {
        throw new DDRInteractiveCommandException("Failed to open output file " + filename, e);
    }
    try {
        byte[] data = new byte[length];
        context.process.getBytesAt(address, data);
        try {
            fos.write(data, 0, length);
        } catch (IOException e) {
            throw new DDRInteractiveCommandException("Failed to write data to file " + filename, e);
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
            /* Whatcha gonna do? */
            }
        }
    } catch (MemoryFault e) {
        throw new DDRInteractiveCommandException("Unable to read memory range", e);
    }
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 14 with MemoryFault

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

the class AbstractPointer method getObjectClassAtOffset.

protected J9ClassPointer getObjectClassAtOffset(long offset) throws CorruptDataException {
    long location = address + offset;
    long classPointer;
    if (J9BuildFlags.interp_compressedObjectHeader) {
        classPointer = (long) getAddressSpace().getIntAt(location) & 0xFFFFFFFFL;
    } else {
        classPointer = getAddressSpace().getPointerAt(location);
    }
    if (classPointer == 0L) {
        throw new MemoryFault(location, "Invalid class address found in object");
    }
    J9ClassPointer cp = checkClassCache(classPointer);
    if (cp == null) {
        cp = J9ClassPointer.cast(classPointer);
        setClassCache(classPointer, cp);
    }
    return cp;
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)

Example 15 with MemoryFault

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

the class J9ObjectStructureFormatter method format.

@Override
public FormatWalkResult format(String type, long address, PrintStream out, Context context, List<IFieldFormatter> fieldFormatters, String[] extraArgs) {
    if (type.equalsIgnoreCase("j9object") || type.equalsIgnoreCase("j9indexableobject")) {
        J9ClassPointer clazz = null;
        J9ObjectPointer object = null;
        try {
            boolean isArray;
            String className;
            object = J9ObjectPointer.cast(address);
            clazz = J9ObjectHelper.clazz(object);
            if (clazz.isNull()) {
                out.println("<can not read RAM class address>");
                return FormatWalkResult.STOP_WALKING;
            }
            isArray = J9ClassHelper.isArrayClass(clazz);
            className = J9UTF8Helper.stringValue(clazz.romClass().className());
            U8Pointer dataStart = U8Pointer.cast(object).add(ObjectModel.getHeaderSize(object));
            if (className.equals("java/lang/String")) {
                formatStringObject(out, 0, clazz, dataStart, object);
            } else if (isArray) {
                int begin = DEFAULT_ARRAY_FORMAT_BEGIN;
                int end = DEFAULT_ARRAY_FORMAT_END;
                if (extraArgs.length > 0) {
                    begin = Integer.parseInt(extraArgs[0]);
                }
                if (extraArgs.length > 1) {
                    end = Integer.parseInt(extraArgs[1]);
                }
                formatArrayObject(out, clazz, dataStart, J9IndexableObjectPointer.cast(object), begin, end);
            } else {
                formatObject(out, clazz, dataStart, object);
            }
        } catch (MemoryFault ex2) {
            out.println("Unable to read object clazz at " + object.getHexAddress() + " (clazz = " + clazz.getHexAddress() + ")");
        } catch (CorruptDataException ex) {
            out.println("Error for ");
            ex.printStackTrace(out);
        }
        return FormatWalkResult.STOP_WALKING;
    } else {
        return FormatWalkResult.KEEP_WALKING;
    }
}
Also used : MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

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