Search in sources :

Example 1 with Module

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

the class ELFDumpReader method createModuleFromElfReader.

/**
 * Given an ELF reader, read the symbols, memory ranges and properties from the module
 * and construct a Module object. The ELF reader may point to a segment within the core file
 * or may point to a copy of the module on disk or appended to the core file.
 *
 * @param loadedBaseAddress of the module
 * @param name of the module
 * @param elfReader to the module
 *
 * @return IModule
 * @throws IOException
 */
private IModule createModuleFromElfReader(final long loadedBaseAddress, String name, ELFFileReader inCoreReader, ELFFileReader diskReader) {
    if (name == null) {
        return null;
    }
    if (inCoreReader == null) {
        return new MissingFileModule(_process, name, Collections.<IMemoryRange>emptyList());
    }
    List<? extends ISymbol> symbols = null;
    Map<Long, String> sectionHeaderStringTable = null;
    List<SectionHeaderEntry> sectionHeaderEntries = null;
    Properties properties;
    Collection<? extends IMemorySource> declaredRanges;
    ProgramHeaderEntry ehFrameEntry = null;
    // so don't raise an error if it isn't present.
    for (ProgramHeaderEntry ph : inCoreReader.getProgramHeaderEntries()) {
        if (ph.isEhFrame()) {
            ehFrameEntry = ph;
        }
    }
    try {
        if (ehFrameEntry != null) {
            unwinder.addCallFrameInformation(loadedBaseAddress, ehFrameEntry, name);
        }
    } catch (MemoryFault mf) {
        // We get known memory faults for ld-linux-x86-64.so.2 in AMD64 dumps (at the first address it's loaded at)
        // and linux-vdso.so.1. The first of these turns up again at a location that works, the second is
        // "magic" so we don't worry about them. We want this code to be as resilient as possible.
        logger.log(Level.FINER, "MemoryFault reading GNU_EH_FRAME data for module with name " + name + " and base address " + Long.toHexString(loadedBaseAddress));
    } catch (CorruptDataException cde) {
        logger.log(Level.FINER, "CorruptDataException reading GNU_EH_FRAME data for module with name " + name + " and base address " + Long.toHexString(loadedBaseAddress));
    } catch (IOException e) {
        logger.log(Level.FINER, "IOException reading GNU_EH_FRAME data for module with name " + name + " and base address " + Long.toHexString(loadedBaseAddress));
    }
    try {
        if (diskReader != null) {
            symbols = diskReader.getSymbols(loadedBaseAddress, true);
            sectionHeaderStringTable = diskReader.getSectionHeaderStringTable();
            sectionHeaderEntries = diskReader.getSectionHeaderEntries();
        } else {
            symbols = inCoreReader.getSymbols(loadedBaseAddress, false);
            sectionHeaderStringTable = inCoreReader.getSectionHeaderStringTable();
            sectionHeaderEntries = inCoreReader.getSectionHeaderEntries();
        }
        properties = inCoreReader.getProperties();
        // Only ever get memory ranges from the data loaded into the core file!
        // But we can use the section headers and string table from the disk or zipped library
        // to navigate. (Section headers are redundant once the library is loaded so may not
        // be in memory.)
        declaredRanges = inCoreReader.getMemoryRanges(loadedBaseAddress, sectionHeaderEntries, sectionHeaderStringTable);
    } catch (IOException e) {
        logger.log(Level.FINER, "Error generating module with name " + name + " and base address " + Long.toHexString(loadedBaseAddress));
        return null;
    }
    // Of the declared memory ranges, some will already be in core (i.e. .data) others will have been declared
    // in the core, but not backed.
    List<IMemoryRange> ranges = new ArrayList<IMemoryRange>(declaredRanges.size());
    for (IMemorySource source : declaredRanges) {
        IMemorySource coreSource = _process.getRangeForAddress(source.getBaseAddress());
        /**
         * The following test skips sections that originally had an address of 0
         * the section header table.
         *
         * Explanation follows - see also the example section header table at the top
         * of SectionHeaderEntry.java
         *
         * Some of the later sections in the section header table have an address field
         * 0. That is a relative address, relative to the base address of the module.
         * They are usually the sections from .comment onwards.
         *
         * When the entry is constructed the code that creates the entry creates it with
         * address (base address of the module) + (address field in the SHT) hence those
         * that had an address of 0 will have an address == base address of the module.
         * These entries are precisely those that are often not in the core file so it is
         * not safe to create them as sections - they were there in the on-disk version of
         * the library but often not in memory. The code above that called elfReader.getMemoryRanges
         * may have been reading the version of the module from disk (which is good, it means
         * you get a good section header string table so you get good names for all the
         * sections) but not all the sections exist in memory. The danger of adding them
         * as memory ranges is that they start to overlay the segments in the core file
         * that come immediately afterwards; that is, they cause jdmpview, for example, to
         * believe that the contents of these later areas of memory are backed by the
         * contents of the library on disk when they are not.
         * See CMVC 185753
         *
         * So, don't add sections that originally had address 0.
         */
        if (source.getBaseAddress() == loadedBaseAddress) {
            // must have originally had address 0 in the section header table
            continue;
        }
        if (null != coreSource) {
            if (coreSource.isBacked()) {
            // Range already exists
            } else {
                // from the library
                if (source.getSize() > 0) {
                    _process.removeMemorySource(coreSource);
                    _process.addMemorySource(source);
                }
            }
        } else {
            if (source.getSize() > 0) {
                _process.addMemorySource(source);
            }
        }
        ranges.add(source);
    }
    return new Module(_process, name, symbols, ranges, loadedBaseAddress, properties);
}
Also used : IMemorySource(com.ibm.j9ddr.corereaders.memory.IMemorySource) ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.j9ddr.CorruptDataException) IOException(java.io.IOException) Properties(java.util.Properties) MissingFileModule(com.ibm.j9ddr.corereaders.memory.MissingFileModule) IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) MissingFileModule(com.ibm.j9ddr.corereaders.memory.MissingFileModule) IModule(com.ibm.j9ddr.corereaders.memory.IModule) Module(com.ibm.j9ddr.corereaders.memory.Module)

Example 2 with Module

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

the class AIXDumpReader method loadModule.

private void loadModule(ILibraryResolver resolver, IProcess proc, long textVirtualAddress, long textSize, long dataVirtualAddress, long dataSize, String fileName, String objectName, String moduleName, boolean loadingExecutable) {
    // .data range will be loaded in core. .text range will be in the module itself.
    IMemoryRange data = new MemoryRange(proc.getAddressSpace(), dataVirtualAddress, dataSize, ".data");
    IModule module;
    IMemorySource text;
    try {
        LibraryDataSource library = null;
        if (loadingExecutable) {
            library = resolver.getLibrary(fileName, true);
        } else {
            library = resolver.getLibrary(fileName);
        }
        IModuleFile moduleFile = loadModuleFile(library, objectName);
        text = moduleFile.getTextSegment(textVirtualAddress, textSize);
        List<? extends ISymbol> symbols = moduleFile.getSymbols(textVirtualAddress);
        List<IMemoryRange> moduleMemoryRanges = new LinkedList<IMemoryRange>();
        moduleMemoryRanges.add(text);
        moduleMemoryRanges.add(data);
        module = new Module(proc, moduleName, symbols, moduleMemoryRanges, textVirtualAddress, moduleFile.getProperties());
    } catch (Exception e) {
        // Create a non-backed memory range for the text segment (so we know it exists)
        text = new UnbackedMemorySource(textVirtualAddress, textSize, "Native library " + moduleName + " couldn't be found", 0, ".text");
        List<IMemoryRange> moduleMemoryRanges = new LinkedList<IMemoryRange>();
        moduleMemoryRanges.add(text);
        moduleMemoryRanges.add(data);
        // Can't find the library - put a stub in with the information we have.
        module = new MissingFileModule(proc, moduleName, moduleMemoryRanges);
    }
    // Add .text to _memoryRanges so it becomes part of the native address space.
    addMemorySource(text);
    if (loadingExecutable) {
        _executable = module;
        _executableTextSection = text;
    } else {
        _modules.add(module);
    }
}
Also used : IMemorySource(com.ibm.j9ddr.corereaders.memory.IMemorySource) IModule(com.ibm.j9ddr.corereaders.memory.IModule) UnbackedMemorySource(com.ibm.j9ddr.corereaders.memory.UnbackedMemorySource) IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) MemoryRange(com.ibm.j9ddr.corereaders.memory.MemoryRange) LibraryDataSource(com.ibm.j9ddr.corereaders.LibraryDataSource) LinkedList(java.util.LinkedList) IOException(java.io.IOException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) InvalidDumpFormatException(com.ibm.j9ddr.corereaders.InvalidDumpFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MissingFileModule(com.ibm.j9ddr.corereaders.memory.MissingFileModule) IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) IModuleFile(com.ibm.j9ddr.corereaders.IModuleFile) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MissingFileModule(com.ibm.j9ddr.corereaders.memory.MissingFileModule) IModule(com.ibm.j9ddr.corereaders.memory.IModule) Module(com.ibm.j9ddr.corereaders.memory.Module)

Example 3 with Module

use of com.ibm.j9ddr.corereaders.memory.Module 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)

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)3 IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)3 IModule (com.ibm.j9ddr.corereaders.memory.IModule)3 Module (com.ibm.j9ddr.corereaders.memory.Module)3 IOException (java.io.IOException)3 IMemorySource (com.ibm.j9ddr.corereaders.memory.IMemorySource)2 MemoryFault (com.ibm.j9ddr.corereaders.memory.MemoryFault)2 MissingFileModule (com.ibm.j9ddr.corereaders.memory.MissingFileModule)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 CorruptCoreException (com.ibm.j9ddr.corereaders.CorruptCoreException)1 IModuleFile (com.ibm.j9ddr.corereaders.IModuleFile)1 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)1 LibraryDataSource (com.ibm.j9ddr.corereaders.LibraryDataSource)1 ISymbol (com.ibm.j9ddr.corereaders.memory.ISymbol)1 MemoryRange (com.ibm.j9ddr.corereaders.memory.MemoryRange)1 UnbackedMemorySource (com.ibm.j9ddr.corereaders.memory.UnbackedMemorySource)1 RuntimeFunction (com.ibm.j9ddr.corereaders.minidump.unwind.RuntimeFunction)1