Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2003-11-20 19:42:02 +0000
committerAlain Magloire2003-11-20 19:42:02 +0000
commitf9b97a95f40cedb2236bfc60c9be630f0f953c50 (patch)
treef937cd6f17e9499a84b640e748ba0f08bc8889ce
parenta07655f08e44c1a86f76a2c31ece294870c84df2 (diff)
downloadorg.eclipse.cdt-f9b97a95f40cedb2236bfc60c9be630f0f953c50.tar.gz
org.eclipse.cdt-f9b97a95f40cedb2236bfc60c9be630f0f953c50.tar.xz
org.eclipse.cdt-f9b97a95f40cedb2236bfc60c9be630f0f953c50.zip
Allow to get the lineNumber from a offset of symbol
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java1
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java11
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/Symbol.java42
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java10
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/Symbol.java46
5 files changed, 95 insertions, 15 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java
index 3f7e3a78898..783b54f5d68 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java
@@ -86,6 +86,7 @@ public interface IBinaryParser {
int getEndLine();
IPath getFilename();
int getType();
+ int getLineNumber(long offset);
}
IBinaryFile getBinary(IPath path) throws IOException;
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java
index 19ebe1d4e14..9c9a71df6c3 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/BinaryObject.java
@@ -58,11 +58,15 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
*/
public ISymbol getSymbol(long addr) {
ISymbol[] syms = getSymbols();
- int i = Arrays.binarySearch(syms, new Long(addr));
- if (i < 0 || i >= syms.length) {
+ int insertion = Arrays.binarySearch(syms, new Long(addr));
+ if (insertion > 0) {
+ return syms[insertion];
+ }
+ if (insertion == -1) {
return null;
}
- return syms[i];
+ insertion = -insertion - 1;
+ return syms[insertion - 1];
}
/**
@@ -256,6 +260,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
if (filename != null && filename.equals("??")) {
filename = null;
}
+
if (filename != null) {
if (cygpath != null) {
sym.filename = new Path(cygpath.getFileName(filename));
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/Symbol.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/Symbol.java
index e0535a68416..ddbd1892324 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/Symbol.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/Symbol.java
@@ -19,6 +19,8 @@ import org.eclipse.core.runtime.IPath;
public class Symbol implements ISymbol {
BinaryObject binary;
+ Addr2line addr2line;
+ long timestamp;
public IPath filename;
public int startLine;
@@ -79,10 +81,9 @@ public class Symbol implements ISymbol {
public int getLineNumber(long offset) {
int line = -1;
try {
- Addr2line addr2line = binary.getAddr2Line();
- if (addr2line != null) {
- line = addr2line.getLineNumber(addr + offset);
- addr2line.dispose();
+ Addr2line addressToLine = startAddr2Line();
+ if (addressToLine != null) {
+ line = addressToLine.getLineNumber(addr + offset);
}
} catch (IOException e) {
}
@@ -107,4 +108,37 @@ public class Symbol implements ISymbol {
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
}
+ synchronized Addr2line startAddr2Line () {
+ if (addr2line == null) {
+ addr2line = binary.getAddr2Line();
+ if (addr2line != null) {
+ timestamp = System.currentTimeMillis();
+ Runnable worker = new Runnable () {
+ public void run() {
+ long diff = System.currentTimeMillis() - timestamp;
+ while (diff < 10000) {
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ break;
+ }
+ diff = System.currentTimeMillis() - timestamp;
+ }
+ stopAddr2Line();
+ }
+ };
+ new Thread(worker, "Addr2line Reaper").start();
+ }
+ } else {
+ timestamp = System.currentTimeMillis();
+ }
+ return addr2line;
+ }
+
+ synchronized void stopAddr2Line() {
+ if (addr2line != null) {
+ addr2line.dispose();
+ }
+ addr2line = null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java
index fa0fd575c55..b5acdff0844 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryObject.java
@@ -56,11 +56,15 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
*/
public ISymbol getSymbol(long addr) {
ISymbol[] syms = getSymbols();
- int i = Arrays.binarySearch(syms, new Long(addr));
- if (i < 0 || i >= syms.length) {
+ int insertion = Arrays.binarySearch(syms, new Long(addr));
+ if (insertion > 0) {
+ return syms[insertion];
+ }
+ if (insertion == -1) {
return null;
}
- return syms[i];
+ insertion = -insertion - 1;
+ return syms[insertion - 1];
}
/**
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/Symbol.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/Symbol.java
index f05e274ab4e..5f526baf35f 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/Symbol.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/Symbol.java
@@ -19,6 +19,8 @@ import org.eclipse.core.runtime.IPath;
public class Symbol implements ISymbol, Comparable {
BinaryObject binary;
+ long timestamp;
+ Addr2line addr2line;
public IPath filename;
public int startLine;
@@ -78,12 +80,11 @@ public class Symbol implements ISymbol, Comparable {
public int getLineNumber(long offset) {
int line = -1;
try {
- Addr2line addr2line = binary.getAddr2Line();
- if (addr2line != null) {
- line = addr2line.getLineNumber(addr + offset);
- addr2line.dispose();
+ Addr2line addressToLine = startAddr2Line();
+ if (addressToLine != null) {
+ line = addressToLine.getLineNumber(addr + offset);
}
- } catch (IOException e) {
+ } catch (IOException e) {
}
return line;
}
@@ -102,4 +103,39 @@ public class Symbol implements ISymbol, Comparable {
}
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
}
+
+ synchronized Addr2line startAddr2Line () {
+ if (addr2line == null) {
+ addr2line = binary.getAddr2Line();
+ if (addr2line != null) {
+ timestamp = System.currentTimeMillis();
+ Runnable worker = new Runnable () {
+ public void run() {
+ long diff = System.currentTimeMillis() - timestamp;
+ while (diff < 10000) {
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ break;
+ }
+ diff = System.currentTimeMillis() - timestamp;
+ }
+ stopAddr2Line();
+ }
+ };
+ new Thread(worker, "Addr2line Reaper").start();
+ }
+ } else {
+ timestamp = System.currentTimeMillis();
+ }
+ return addr2line;
+ }
+
+ synchronized void stopAddr2Line() {
+ if (addr2line != null) {
+ addr2line.dispose();
+ }
+ addr2line = null;
+ }
+
}

Back to the top