From 40ff5c09ead3854c492393e637d12571591719ce Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Thu, 20 Nov 2003 17:06:42 +0000 Subject: [PATCH] implement returning the linenumber of an offset. --- .../eclipse/cdt/utils/coff/parser/Symbol.java | 42 +++++++++++++++-- .../eclipse/cdt/utils/elf/parser/Symbol.java | 46 +++++++++++++++++-- 2 files changed, 79 insertions(+), 9 deletions(-) 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/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; + } + }