From 91f05a8d0252344173ccc626afe220596f1384f9 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Thu, 6 Nov 2003 18:40:24 +0000 Subject: [PATCH] fixed problem with not getting line no. all the time --- .../org/eclipse/cdt/utils/Addr2line.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr2line.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr2line.java index 588cdd79877..a68565e775f 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr2line.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr2line.java @@ -83,17 +83,21 @@ public class Addr2line { * hello.c:39 */ public int getLineNumber(long address) throws IOException { - int lineno = -1; - String line = getLine(address); - int colon; - if (line != null && (colon = line.lastIndexOf(':')) != -1) { - try { - lineno = Integer.parseInt(line.substring(colon + 1)); - lineno = (lineno == 0) ? -1 : lineno; - } catch(Exception e) { + // We try to get the nearest match + // since the symbol may not exactly align with debug info. + // In C line number 0 is invalid, line starts at 1 for file, we use + // this for validation. + for (int i = 0; i <= 20; i += 4, address += i) { + String line = getLine(address); + if (line != null) { + int colon = line.lastIndexOf(':'); + String number = line.substring(colon + 1); + if (!number.startsWith("0")) { + return Integer.parseInt(number); + } } } - return lineno; + return -1; } public void dispose() {