Search in sources :

Example 1 with IMemoryRange

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

the class DDRSymbolFinder method getModuleForInstructionAddress.

/* Logic stolen from SymbolUtil. */
private static IModule getModuleForInstructionAddress(IProcess process, long address) throws CorruptDataException {
    Collection<? extends IModule> modules = process.getModules();
    IModule matchingModule = null;
    OUTER_LOOP: for (IModule thisModule : modules) {
        for (IMemoryRange thisRange : thisModule.getMemoryRanges()) {
            if (thisRange.contains(address)) {
                matchingModule = thisModule;
                break OUTER_LOOP;
            }
        }
    }
    return matchingModule;
}
Also used : IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) IModule(com.ibm.j9ddr.corereaders.memory.IModule)

Example 2 with IMemoryRange

use of com.ibm.j9ddr.corereaders.memory.IMemoryRange 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 3 with IMemoryRange

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

the class JniMemory method getMemoryRanges.

public Collection<? extends IMemoryRange> getMemoryRanges() {
    List<MemoryRange> ranges = new LinkedList<MemoryRange>();
    MemoryRange region = getValidRegionVirtual(0, searchSize);
    while (region != null) {
        ranges.add(region);
        region = getValidRegionVirtual(region.getBaseAddress() + region.getSize(), searchSize);
    }
    return ranges;
}
Also used : IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) MemoryRange(com.ibm.j9ddr.corereaders.memory.MemoryRange) LinkedList(java.util.LinkedList)

Example 4 with IMemoryRange

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

the class ModuleStream method loadModuleSections.

private void loadModuleSections(IAddressSpace as, long imageBaseAddress, long readingAddress, long e_lfanew, Collection<IMemoryRange> sections) throws MemoryFault {
    int pemagic = as.getIntAt(readingAddress);
    readingAddress += 4;
    if (0x4550 != pemagic) {
        logger.logp(Level.WARNING, "com.ibm.j9ddr.corereaders.minidump.ModuleStream", "loadModuleSections", "PE Magic is: \"" + Integer.toHexString(pemagic));
    }
    // typedef struct _IMAGE_FILE_HEADER {
    // dump.readShort(); //machine
    readingAddress += 2;
    short numberOfSections = as.getShortAt(readingAddress);
    readingAddress += 2;
    // dump.readInt(); //date/time stamp
    readingAddress += 4;
    // dump.readInt(); //pointerToSymbolTable
    readingAddress += 4;
    // dump.readInt(); //numberOfSymbols
    readingAddress += 4;
    short sizeOfOptionalHeader = as.getShortAt(readingAddress);
    readingAddress += 2;
    // dump.readShort(); //characteristics
    readingAddress += 2;
    // now skip ahead to after the optional header since that is where section
    // headers can be found
    readingAddress = imageBaseAddress + e_lfanew + 24 + /* sizeof PE header */
    (0xFFFFL & sizeOfOptionalHeader);
    for (int j = 0; j < numberOfSections; j++) {
        // typedef struct _IMAGE_SECTION_HEADER
        byte[] rawName = new byte[8];
        as.getBytesAt(readingAddress, rawName);
        readingAddress += 8;
        long virtualSize = as.getIntAt(readingAddress);
        readingAddress += 4;
        long virtualAddress = as.getIntAt(readingAddress);
        readingAddress += 4;
        // dump.readInt(); //sizeOfRawData
        readingAddress += 4;
        // dump.readInt(); //pointerToRawData
        readingAddress += 4;
        // dump.readInt(); //pointerToRelocations
        readingAddress += 4;
        // dump.readInt(); //pointerToLineNumbers
        readingAddress += 4;
        // dump.readShort(); //numberOfRelocations
        readingAddress += 2;
        // dump.readShort(); //numberOfLineNumbers
        readingAddress += 2;
        // dump.readInt(); //section_characteristics
        readingAddress += 4;
        long relocatedAddress = virtualAddress + imageBaseAddress;
        String name;
        try {
            name = new String(rawName, "ASCII");
            // Trim off any trailing nulls.
            name = name.trim();
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        IMemoryRange section = new MemoryRange(as, relocatedAddress, virtualSize, name);
        sections.add(section);
    }
}
Also used : IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) MemoryRange(com.ibm.j9ddr.corereaders.memory.MemoryRange) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with IMemoryRange

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

IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)16 ArrayList (java.util.ArrayList)7 IModule (com.ibm.j9ddr.corereaders.memory.IModule)5 MemoryRange (com.ibm.j9ddr.corereaders.memory.MemoryRange)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 ImageSection (com.ibm.dtfj.image.ImageSection)3 CorruptDataException (com.ibm.j9ddr.CorruptDataException)3 Module (com.ibm.j9ddr.corereaders.memory.Module)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Properties (java.util.Properties)3 IMemorySource (com.ibm.j9ddr.corereaders.memory.IMemorySource)2 IProcess (com.ibm.j9ddr.corereaders.memory.IProcess)2 ISymbol (com.ibm.j9ddr.corereaders.memory.ISymbol)2 MemoryFault (com.ibm.j9ddr.corereaders.memory.MemoryFault)2 MissingFileModule (com.ibm.j9ddr.corereaders.memory.MissingFileModule)2 UnwindModule (com.ibm.j9ddr.corereaders.minidump.unwind.UnwindModule)2 Test (org.junit.Test)2 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)1 DataUnavailableException (com.ibm.j9ddr.DataUnavailableException)1