mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-16 13:35:22 +02:00
Allow to get the lineNumber from a offset of symbol
This commit is contained in:
parent
a07655f08e
commit
f9b97a95f4
5 changed files with 95 additions and 15 deletions
|
@ -86,6 +86,7 @@ public interface IBinaryParser {
|
||||||
int getEndLine();
|
int getEndLine();
|
||||||
IPath getFilename();
|
IPath getFilename();
|
||||||
int getType();
|
int getType();
|
||||||
|
int getLineNumber(long offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
IBinaryFile getBinary(IPath path) throws IOException;
|
IBinaryFile getBinary(IPath path) throws IOException;
|
||||||
|
|
|
@ -58,11 +58,15 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
*/
|
*/
|
||||||
public ISymbol getSymbol(long addr) {
|
public ISymbol getSymbol(long addr) {
|
||||||
ISymbol[] syms = getSymbols();
|
ISymbol[] syms = getSymbols();
|
||||||
int i = Arrays.binarySearch(syms, new Long(addr));
|
int insertion = Arrays.binarySearch(syms, new Long(addr));
|
||||||
if (i < 0 || i >= syms.length) {
|
if (insertion > 0) {
|
||||||
|
return syms[insertion];
|
||||||
|
}
|
||||||
|
if (insertion == -1) {
|
||||||
return null;
|
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("??")) {
|
if (filename != null && filename.equals("??")) {
|
||||||
filename = null;
|
filename = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
if (cygpath != null) {
|
if (cygpath != null) {
|
||||||
sym.filename = new Path(cygpath.getFileName(filename));
|
sym.filename = new Path(cygpath.getFileName(filename));
|
||||||
|
|
|
@ -19,6 +19,8 @@ import org.eclipse.core.runtime.IPath;
|
||||||
public class Symbol implements ISymbol {
|
public class Symbol implements ISymbol {
|
||||||
|
|
||||||
BinaryObject binary;
|
BinaryObject binary;
|
||||||
|
Addr2line addr2line;
|
||||||
|
long timestamp;
|
||||||
|
|
||||||
public IPath filename;
|
public IPath filename;
|
||||||
public int startLine;
|
public int startLine;
|
||||||
|
@ -79,10 +81,9 @@ public class Symbol implements ISymbol {
|
||||||
public int getLineNumber(long offset) {
|
public int getLineNumber(long offset) {
|
||||||
int line = -1;
|
int line = -1;
|
||||||
try {
|
try {
|
||||||
Addr2line addr2line = binary.getAddr2Line();
|
Addr2line addressToLine = startAddr2Line();
|
||||||
if (addr2line != null) {
|
if (addressToLine != null) {
|
||||||
line = addr2line.getLineNumber(addr + offset);
|
line = addressToLine.getLineNumber(addr + offset);
|
||||||
addr2line.dispose();
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
@ -107,4 +108,37 @@ public class Symbol implements ISymbol {
|
||||||
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,15 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
|
||||||
*/
|
*/
|
||||||
public ISymbol getSymbol(long addr) {
|
public ISymbol getSymbol(long addr) {
|
||||||
ISymbol[] syms = getSymbols();
|
ISymbol[] syms = getSymbols();
|
||||||
int i = Arrays.binarySearch(syms, new Long(addr));
|
int insertion = Arrays.binarySearch(syms, new Long(addr));
|
||||||
if (i < 0 || i >= syms.length) {
|
if (insertion > 0) {
|
||||||
|
return syms[insertion];
|
||||||
|
}
|
||||||
|
if (insertion == -1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return syms[i];
|
insertion = -insertion - 1;
|
||||||
|
return syms[insertion - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,6 +19,8 @@ import org.eclipse.core.runtime.IPath;
|
||||||
public class Symbol implements ISymbol, Comparable {
|
public class Symbol implements ISymbol, Comparable {
|
||||||
|
|
||||||
BinaryObject binary;
|
BinaryObject binary;
|
||||||
|
long timestamp;
|
||||||
|
Addr2line addr2line;
|
||||||
|
|
||||||
public IPath filename;
|
public IPath filename;
|
||||||
public int startLine;
|
public int startLine;
|
||||||
|
@ -78,12 +80,11 @@ public class Symbol implements ISymbol, Comparable {
|
||||||
public int getLineNumber(long offset) {
|
public int getLineNumber(long offset) {
|
||||||
int line = -1;
|
int line = -1;
|
||||||
try {
|
try {
|
||||||
Addr2line addr2line = binary.getAddr2Line();
|
Addr2line addressToLine = startAddr2Line();
|
||||||
if (addr2line != null) {
|
if (addressToLine != null) {
|
||||||
line = addr2line.getLineNumber(addr + offset);
|
line = addressToLine.getLineNumber(addr + offset);
|
||||||
addr2line.dispose();
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
@ -102,4 +103,39 @@ public class Symbol implements ISymbol, Comparable {
|
||||||
}
|
}
|
||||||
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue