1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

faster IArchive

This commit is contained in:
David Inglis 2003-02-26 21:01:28 +00:00
parent 7f7de54b77
commit 6940e686c7
6 changed files with 304 additions and 356 deletions

View file

@ -1,3 +1,14 @@
2003-02-26 David Inglis
* model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java
* model/org/eclipse/cdt/internal/core/model/BinaryContainer.java
Remove warning.
* model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryArchive.java
* model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java
* utils/org/eclipse/cdt/utils/elf/AR.java
Improve IBinaryObject creation from IArchive (big speed improvment)
2003-02-24 Alain Magloire
* model/org/eclipse/cdt/internal/core/model/Marker.java:

View file

@ -15,7 +15,6 @@ import org.eclipse.core.resources.IProject;
public class ArchiveContainer extends Parent implements IArchiveContainer {
CProject cProject;
private long modificationStamp;
public ArchiveContainer (CProject cProject) {
super (cProject, null, "lib", CElement.C_CONTAINER);

View file

@ -19,7 +19,6 @@ import org.eclipse.core.runtime.CoreException;
public class BinaryContainer extends Parent implements IBinaryContainer {
CProject cProject;
private long modificationStamp;
public BinaryContainer (CProject cProject) {
this (cProject, "bin");

View file

@ -45,7 +45,7 @@ public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive {
ar = new AR(location.toOSString());
AR.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
IBinaryObject bin = new ElfBinaryFile(file, headers[i].getObjectName());
IBinaryObject bin = new ElfBinaryFile(file, headers[i]);
children.add(bin);
}
} catch (IOException e) {

View file

@ -28,11 +28,9 @@ import org.eclipse.core.runtime.PlatformObject;
/**
*/
public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
IBinaryObject, IBinaryExecutable, IBinaryShared {
public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinaryObject, IBinaryExecutable, IBinaryShared {
IFile file;
String objectName;
AR.ARHeader header;
long timestamp;
String soname;
String[] needed;
@ -44,9 +42,9 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
this(f, null);
}
public ElfBinaryFile(IFile f, String n) throws IOException {
public ElfBinaryFile(IFile f, AR.ARHeader h) throws IOException {
header = h;
file = f;
objectName = n;
loadInformation();
hasChanged();
}
@ -206,25 +204,11 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
public InputStream getContents() {
InputStream stream = null;
// Archive ?
if (file != null && objectName != null) {
IPath location = file.getLocation();
if (location != null) {
AR ar = null;
if (file != null && header != null) {
try {
ar = new AR(file.getLocation().toOSString());
AR.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
if (objectName.equals(headers[i].getObjectName())) {
stream = new ByteArrayInputStream(headers[i].getObjectData());
break;
}
}
stream = new ByteArrayInputStream(header.getObjectData());
} catch (IOException e) {
}
if (ar != null) {
ar.dispose();
}
}
} else if (file != null && file.exists()) {
try {
stream = file.getContents();
@ -241,8 +225,8 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
*/
public String getName() {
if (objectName != null) {
return objectName;
if (header != null) {
return header.getObjectName();
}
if (file != null) {
return file.getName();
@ -283,30 +267,8 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
protected ElfHelper getElfHelper() throws IOException {
// Archive ?
if (file != null && objectName != null) {
IPath location = file.getLocation();
if (location != null) {
ElfHelper helper = null;
AR ar = null;
try {
ar = new AR(file.getLocation().toOSString());
AR.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
AR.ARHeader hdr = headers[i];
if (objectName.equals(hdr.getObjectName())) {
helper = new ElfHelper(hdr.getElf());
break;
}
}
} finally {
if (ar != null) {
ar.dispose();
}
}
if (helper != null) {
return helper;
}
}
if (header != null) {
return new ElfHelper(header.getElf());
} else if (file != null && file.exists()) {
IPath path = file.getLocation();
if (path == null) {
@ -368,8 +330,10 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile,
try {
// This can fail if we use addr2line
// but we can safely ignore the error.
if (header == null) {
sym.filename = array[i].getFilename();
sym.lineno = array[i].getFuncLineNumber();
}
} catch (IOException e) {
//e.printStackTrace();
}

View file

@ -10,7 +10,6 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Vector;
/**
* The <code>AR</code> class is used for parsing standard ELF archive (ar) files.
*
@ -26,27 +25,20 @@ public class AR {
protected long strtbl_pos = -1;
private ARHeader[] headers;
public void dispose() {
try
{
if (efile != null)
{
try {
if (efile != null) {
efile.close();
efile = null;
}
} catch (IOException e) {
}
catch( IOException e )
{}
}
protected void finalize() throws Throwable {
try
{
try {
dispose();
}
finally
{
} finally {
super.finalize();
}
}
@ -66,7 +58,6 @@ public class AR {
private long size;
private long elf_offset;
/**
* Remove the padding from the archive header strings.
*/
@ -76,7 +67,6 @@ public class AR {
return str;
}
/**
* Look up the name stored in the archive's string table based
* on the offset given.
@ -92,25 +82,20 @@ public class AR {
StringBuffer name = new StringBuffer(0);
long pos = efile.getFilePointer();
try
{
if( strtbl_pos != -1 )
{
try {
if (strtbl_pos != -1) {
byte temp;
efile.seek(strtbl_pos + offset);
while ((temp = efile.readByte()) != '\n')
name.append((char) temp);
}
}
finally
{
} finally {
efile.seek(pos);
}
return name.toString();
}
/**
* Creates a new archive header object.
*
@ -158,17 +143,11 @@ public class AR {
// If the name is of the format "/<number>", get name from the
// string table.
//
if( strtbl_pos != -1 &&
this.object_name.length() > 1 &&
this.object_name.charAt( 0 ) == '/' )
{
try
{
if (strtbl_pos != -1 && this.object_name.length() > 1 && this.object_name.charAt(0) == '/') {
try {
long offset = Long.parseLong(this.object_name.substring(1));
this.object_name = nameFromStringTable(offset);
}
catch( java.lang.Exception e )
{
} catch (java.lang.Exception e) {
}
}
@ -176,8 +155,7 @@ public class AR {
// Strip the trailing / from the object name.
//
int len = this.object_name.length();
if( len > 2 && this.object_name.charAt( len - 1 ) == '/' )
{
if (len > 2 && this.object_name.charAt(len - 1) == '/') {
this.object_name = this.object_name.substring(0, len - 1);
}
@ -193,6 +171,10 @@ public class AR {
return size;
}
public String getArchiveName() {
return filename;
}
/**
* Create an new Elf object for the object file.
*
@ -211,13 +193,20 @@ public class AR {
public byte[] getObjectData() throws IOException {
byte[] temp = new byte[(int) size];
if (efile != null) {
efile.seek(elf_offset);
efile.read(temp);
} else {
efile = new ERandomAccessFile(filename, "r");
efile.seek(elf_offset);
efile.read(temp);
efile.close();
efile = null;
}
return temp;
}
}
/**
* Creates a new <code>AR</code> object from the contents of
* the given file.
@ -235,20 +224,17 @@ public class AR {
}
}
/** Load the headers from the file (if required). */
private void loadHeaders() throws IOException {
if (headers != null)
return;
Vector v = new Vector();
try
{
try {
//
// Check for EOF condition
//
while( efile.getFilePointer() < efile.length() )
{
while (efile.getFilePointer() < efile.length()) {
ARHeader header = new ARHeader();
String name = header.getObjectName();
@ -266,7 +252,6 @@ public class AR {
if (name.compareTo("//") == 0)
strtbl_pos = pos;
//
// Compute the location of the next header in the archive.
//
@ -276,14 +261,11 @@ public class AR {
efile.seek(pos);
}
}
catch( IOException e )
{
} catch (IOException e) {
}
headers = (ARHeader[]) v.toArray(new ARHeader[0]);
}
/**
* Get an array of all the object file headers for this archive.
*
@ -297,7 +279,6 @@ public class AR {
return headers;
}
private boolean stringInStrings(String str, String[] set) {
for (int i = 0; i < set.length; i++)
if (str.compareTo(set[i]) == 0)
@ -305,10 +286,7 @@ public class AR {
return false;
}
public String[] extractFiles( String outdir, String[] names )
throws IOException
{
public String[] extractFiles(String outdir, String[] names) throws IOException {
Vector names_used = new Vector();
String object_name;
int count;
@ -316,8 +294,7 @@ public class AR {
loadHeaders();
count = 0;
for( int i=0; i<headers.length; i++ )
{
for (int i = 0; i < headers.length; i++) {
object_name = headers[i].getObjectName();
if (names != null && !stringInStrings(object_name, names))
continue;
@ -341,6 +318,4 @@ public class AR {
return extractFiles(outdir, null);
}
}