Search in sources :

Example 6 with IProcess

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

the class SnapBaseCommand method createAndWriteTraceFileHeader.

private void createAndWriteTraceFileHeader(Context context, long utglobaldataAddress, int bufferSize, PrintStream out) throws CorruptDataException, DDRInteractiveCommandException {
    IProcess process = context.process;
    boolean isBigEndian = process.getByteOrder().equals(ByteOrder.BIG_ENDIAN);
    long j9rasAddress = CommandUtils.followPointerFromStructure(context, "J9JavaVM", context.vmAddress, "j9ras");
    long cpuOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("J9RAS", context), "cpus");
    int cpuCount = context.process.getIntAt(j9rasAddress + cpuOffset);
    long archOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("J9RAS", context), "osarch");
    String arch = getCStringAtAddress(process, j9rasAddress + archOffset, 16);
    // We can't actually work this out.
    String processorSubType = "";
    long serviceInfoOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "serviceInfo");
    long serviceInfoAddress = process.getPointerAt(utglobaldataAddress + serviceInfoOffset);
    String serviceLevel = getCStringAtAddress(process, serviceInfoAddress);
    long propertiesOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "properties");
    long propertiesAddress = process.getPointerAt(utglobaldataAddress + propertiesOffset);
    String startupOptions = getCStringAtAddress(process, propertiesAddress);
    int wordSize = process.bytesPerPointer() * 8;
    // The trace configuration options are in a list.
    String traceConfig = "";
    long commandOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtTraceCfg", context), "command");
    long nextConfigAddress = CommandUtils.followPointerFromStructure(context, "UtGlobalData", utglobaldataAddress, "config");
    while (nextConfigAddress != 0) {
        traceConfig += getCStringAtAddress(process, nextConfigAddress + commandOffset);
        nextConfigAddress = CommandUtils.followPointerFromStructure(context, "UtTraceCfg", nextConfigAddress, "next");
        if (nextConfigAddress != 0) {
            traceConfig += "\n";
        }
    }
    long startPlatformOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "startPlatform");
    long startPlatform = context.process.getLongAt(utglobaldataAddress + startPlatformOffset);
    long startSystemOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "startSystem");
    long startSystem = context.process.getLongAt(utglobaldataAddress + startSystemOffset);
    long externalTraceOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "externalTrace");
    int type = context.process.getIntAt(utglobaldataAddress + externalTraceOffset);
    long traceGenerationsOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "traceGenerations");
    int generations = context.process.getIntAt(utglobaldataAddress + traceGenerationsOffset);
    TraceFileHeaderWriter headerWriter;
    try {
        headerWriter = new TraceFileHeaderWriter(fileName, isBigEndian, cpuCount, wordSize, bufferSize, arch, processorSubType, serviceLevel, startupOptions, traceConfig, startPlatform, startSystem, type, generations);
        byte[] headerBytes = headerWriter.createAndWriteTraceFileHeader();
        writeHeaderBytesToTrace(context, headerBytes, out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess)

Example 7 with IProcess

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

the class DDRInteractive method locateRuntimes.

private void locateRuntimes(ICore reader) {
    currentCore = reader;
    Collection<? extends IAddressSpace> spaces = reader.getAddressSpaces();
    for (IAddressSpace thisSpace : spaces) {
        // indicates if a context has been allocated for the address space
        boolean hasCtxBeenAddedForAS = false;
        Collection<? extends IProcess> processes = thisSpace.getProcesses();
        for (IProcess thisProcess : processes) {
            hasCtxBeenAddedForAS = true;
            try {
                IVMData vmData = VMDataFactory.getVMData(thisProcess);
                if (vmData != null) {
                    contexts.add(new Context(thisProcess, vmData, nonVMCommands));
                } else {
                    addMissingJVMToContexts(thisProcess);
                }
            } catch (JVMNotDDREnabledException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (JVMNotFoundException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (MissingDDRStructuresException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (IOException e) {
                System.err.println("Problem searching for VMData in process " + thisProcess);
                e.printStackTrace();
                // put the stack trace to the log
                Logger logger = Logger.getLogger(LoggerNames.LOGGER_INTERACTIVE_CONTEXT);
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                logger.logp(FINE, null, null, sw.toString());
            }
        }
        if (!hasCtxBeenAddedForAS) {
            ASNoProcess as = new ASNoProcess(thisSpace);
            addMissingJVMToContexts(as);
        }
    }
    if (contexts.size() == 0) {
        throw new RuntimeException("Couldn't find any address spaces in this dump");
    } else {
        // default to the first address space
        currentContext = contexts.get(0);
        for (Context ctx : contexts) {
            // but if there is one with a JVM in it, set it to that
            if (!(ctx.vmData instanceof MissingVMData)) {
                currentContext = ctx;
                break;
            }
        }
    }
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) IOException(java.io.IOException) Logger(java.util.logging.Logger) IVMData(com.ibm.j9ddr.IVMData) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) StringWriter(java.io.StringWriter) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess) PrintWriter(java.io.PrintWriter)

Example 8 with IProcess

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

the class DDRInteractive method addDDRContextFromDTFJ.

private void addDDRContextFromDTFJ(Object dtfjctx) throws Exception {
    Method getAddressSpace = findMethod(dtfjctx.getClass(), "getAddressSpace", (Class<?>[]) null);
    Method getProcess = findMethod(dtfjctx.getClass(), "getProcess", (Class<?>[]) null);
    Method getRuntime = findMethod(dtfjctx.getClass(), "getRuntime", (Class<?>[]) null);
    Object addressSpace = getAddressSpace.invoke(dtfjctx, (Object[]) null);
    Object process = getProcess.invoke(dtfjctx, (Object[]) null);
    Object runtime = getRuntime.invoke(dtfjctx, (Object[]) null);
    if (addressSpace == null) {
        throw new IOException("Cannot create a context without an associated address space");
    }
    if (!(addressSpace instanceof J9DDRImageAddressSpace)) {
        throw new UnsupportedOperationException("The supplied DTFJ context is not backed by a DDR implementation");
    }
    IAddressSpace space = ((J9DDRImageAddressSpace) addressSpace).getIAddressSpace();
    IProcess proc = null;
    if (process != null) {
        proc = ((J9DDRImageProcess) process).getIProcess();
    }
    if (proc == null) {
        ASNoProcess as = new ASNoProcess(space);
        addMissingJVMToContexts(as);
        return;
    }
    if (runtime == null) {
        addMissingJVMToContexts(proc);
        return;
    }
    // DDR will cache the VM data, so if the DTFJ context has already found it then this should be in the cache
    IVMData vmData = VMDataFactory.getVMData(proc);
    if (vmData != null) {
        contexts.add(new Context(proc, vmData, nonVMCommands));
    } else {
        addMissingJVMToContexts(proc);
    }
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) J9DDRImageAddressSpace(com.ibm.j9ddr.view.dtfj.image.J9DDRImageAddressSpace) Method(java.lang.reflect.Method) IOException(java.io.IOException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess) IVMData(com.ibm.j9ddr.IVMData)

Example 9 with IProcess

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

the class FindInMemoryCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    IProcess process = context.process;
    boolean isLittleEndian = process.getByteOrder().equals(ByteOrder.LITTLE_ENDIAN);
    int udataSize = process.bytesPerPointer();
    int udataSearch = udataSize == 4 ? TYPE_U32 : TYPE_U64;
    int searchType = TYPE_NONE;
    String searchTypeName;
    boolean findAll = false;
    byte[] searchPattern;
    int alignment;
    long startAddress;
    int argIndex = 0;
    String arg;
    // check for the findnext and findall variants of the command
    if (command.endsWith("findnext")) {
        findNext(out, process);
        return;
    } else if (command.endsWith("findall")) {
        findAll = true;
    }
    // except for findnext (handled above), there should be parameters following the command
    if (args.length == 0) {
        printHelp(out);
        return;
    }
    // get the first parameter (the search type), and post-increment the parameter index
    arg = args[argIndex++];
    searchTypeName = arg;
    if (arg.equalsIgnoreCase("u8")) {
        searchType = TYPE_U8;
        alignment = 1;
    } else if (arg.equalsIgnoreCase("u16")) {
        searchType = TYPE_U16;
        alignment = 2;
    } else if (arg.equalsIgnoreCase("u32")) {
        searchType = TYPE_U32;
        alignment = 4;
    } else if (arg.equalsIgnoreCase("u64")) {
        searchType = TYPE_U64;
        alignment = 8;
    } else if (arg.equalsIgnoreCase("udata")) {
        searchType = udataSearch;
        alignment = udataSize;
    } else if (arg.equalsIgnoreCase("pointer")) {
        searchType = udataSearch;
        alignment = udataSize;
    } else if (arg.equalsIgnoreCase("ascii")) {
        searchType = TYPE_ASCII;
        alignment = 1;
    } else {
        printHelp(out);
        out.println("Unknown search type '" + searchTypeName + "'\n");
        return;
    }
    /* Now parse the search criteria */
    if (args.length <= argIndex) {
        printHelp(out);
        out.println("Expected pattern as argument " + (argIndex + 1) + "\n");
        return;
    }
    arg = args[argIndex++];
    if (searchType == TYPE_ASCII) {
        if (arg.startsWith("\"")) {
            arg = arg.substring(1, arg.lastIndexOf('"'));
        }
        try {
            searchPattern = arg.getBytes("ASCII");
        } catch (UnsupportedEncodingException e) {
            // fall back to default platform
            searchPattern = arg.getBytes();
        // encoding
        }
    } else {
        searchPattern = new byte[alignment];
        if (arg.startsWith("0x")) {
            arg = arg.substring(2);
        }
        int hexBytes = (arg.length() + 1) / 2;
        if (hexBytes > alignment) {
            out.println("Search pattern too long for type '" + searchTypeName + "'");
            return;
        }
        // Pad for simplicity
        arg = "0000000000000000".concat(arg);
        arg = arg.substring(arg.length() - alignment * 2);
        for (int i = 0; i < alignment; i++) {
            int b = Integer.parseInt(arg.substring(i * 2, i * 2 + 2), 16);
            if (isLittleEndian) {
                searchPattern[alignment - i - 1] = (byte) (b & 0xFF);
            } else {
                searchPattern[i] = (byte) (b & 0xFF);
            }
        }
    }
    /* Now parse the start address (optional) */
    if (args.length <= argIndex) {
        startAddress = 0L;
    } else {
        arg = args[argIndex++];
        if (arg.startsWith("0x")) {
            startAddress = Long.decode(arg);
        } else {
            startAddress = Long.parseLong(arg, 16);
        }
    }
    currentAddress = startAddress;
    currentAlignment = alignment;
    currentPattern = searchPattern;
    boolean result = findFirst(out, process);
    if (findAll) {
        while (result) {
            result = findNext(out, process);
        }
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess)

Example 10 with IProcess

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

the class J9DDRImageAddressSpace method getImageSections.

public Iterator<?> getImageSections() {
    Collection<? extends IMemoryRange> ranges = as.getMemoryRanges();
    List<ImageSection> sections = new ArrayList<ImageSection>(ranges.size());
    IProcess proc = getPointerProcess();
    // it may be the case that we can't determine the pointer size if there are no processes found in the address space
    if (null == proc) {
        return J9DDRDTFJUtils.emptyIterator();
    }
    for (IMemoryRange thisRange : ranges) {
        J9DDRImageSection section = new J9DDRImageSection(proc, thisRange.getBaseAddress(), thisRange.getSize(), thisRange.getName());
        sections.add(section);
    }
    return sections.iterator();
}
Also used : IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess)

Aggregations

IProcess (com.ibm.j9ddr.corereaders.memory.IProcess)18 IOException (java.io.IOException)6 CorruptDataException (com.ibm.j9ddr.CorruptDataException)5 IAddressSpace (com.ibm.j9ddr.corereaders.memory.IAddressSpace)4 ICore (com.ibm.j9ddr.corereaders.ICore)3 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 IVMData (com.ibm.j9ddr.IVMData)2 Platform (com.ibm.j9ddr.corereaders.Platform)2 IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)2 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 J9DDRImageProcess (com.ibm.j9ddr.view.dtfj.image.J9DDRImageProcess)2 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)2 J9RASPointer (com.ibm.j9ddr.vm29.pointer.generated.J9RASPointer)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 ImageSection (com.ibm.dtfj.image.ImageSection)1 ILibraryResolver (com.ibm.j9ddr.corereaders.ILibraryResolver)1 IMemorySource (com.ibm.j9ddr.corereaders.memory.IMemorySource)1 IModule (com.ibm.j9ddr.corereaders.memory.IModule)1