blob: 9878abdf00f2592c8ae5bb51483bb03f103e1e11 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010, 2011 Nokia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nokia - Initial API and implementation
* Broadcom - implementation of getProperties() & ctor with properties
*******************************************************************************/
package org.eclipse.cdt.debug.edc.internal.symbols.files;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.debug.edc.IStreamBuffer;
import org.eclipse.cdt.debug.edc.internal.EDCDebugger;
import org.eclipse.cdt.debug.edc.symbols.IExecutableSection;
/**
*
*/
public class ExecutableSection implements IExecutableSection {
private final String name;
private final ISectionMapper executableSectionMapper;
private final SectionInfo section;
private IStreamBuffer buffer;
private boolean deadSection;
private HashMap<String, Object> properties;
/**
* @param executableSectionMapper
* @param name
* @param section
*/
public ExecutableSection(ISectionMapper executableSectionMapper,
String name, SectionInfo section) {
this(executableSectionMapper, name, section, new HashMap<String,Object>(0));
}
/**
* @param executableSectionMapper
* @param name
* @param section
* @param properties
*/
public ExecutableSection(ISectionMapper executableSectionMapper,
String name, SectionInfo section, Map<String, Object> properties) {
this.executableSectionMapper = executableSectionMapper;
this.name = name;
this.section = section;
this.deadSection = false;
this.properties = new HashMap<String, Object>(properties); // make a copy
}
@Override
public String toString() {
return name + " @ " + section + (deadSection ? " <<BROKEN>>": ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public String getName() {
return name;
}
public IStreamBuffer getBuffer() {
if (buffer == null && !deadSection && executableSectionMapper != null) {
try {
buffer = executableSectionMapper.getSectionBuffer(section);
} catch (IOException e) {
deadSection = true;
EDCDebugger.getMessageLogger().logError("Failed to read section " + name, e);
}
}
return buffer;
}
public void dispose() {
executableSectionMapper.releaseSectionBuffer(section);
buffer = null;
}
public long getSize() {
if (buffer == null && !deadSection) {
getBuffer();
}
if (buffer != null) {
return buffer.capacity();
} else if (section != null) {
return section.sectionSize;
} else {
return 0;
}
}
public long getFileOffset() {
return section.fileOffset;
}
public IAddress getLinkAddress() {
return section.virtualAddress;
}
public boolean hasEmptyRange() {
return section.sectionSize == 0 || section.virtualAddress == null;
}
public IAddress getLowAddress() {
return getLinkAddress();
}
public IAddress getHighAddress() {
IAddress address = getLinkAddress();
return (address != null) ? address.add(section.sectionSize) : null;
}
public Map<String, Object> getProperties() {
return properties;
}
}