1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fixed problem with not getting line no. all the time

This commit is contained in:
David Inglis 2003-11-06 18:40:24 +00:00
parent 14df45f11f
commit 91f05a8d02

View file

@ -83,17 +83,21 @@ public class Addr2line {
* hello.c:39 * hello.c:39
*/ */
public int getLineNumber(long address) throws IOException { public int getLineNumber(long address) throws IOException {
int lineno = -1; // We try to get the nearest match
String line = getLine(address); // since the symbol may not exactly align with debug info.
int colon; // In C line number 0 is invalid, line starts at 1 for file, we use
if (line != null && (colon = line.lastIndexOf(':')) != -1) { // this for validation.
try { for (int i = 0; i <= 20; i += 4, address += i) {
lineno = Integer.parseInt(line.substring(colon + 1)); String line = getLine(address);
lineno = (lineno == 0) ? -1 : lineno; if (line != null) {
} catch(Exception e) { 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() { public void dispose() {