From b4cb4ecb76196da3f557a2c7179aac7af5da37b0 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 9 Jan 2004 22:07:48 +0000 Subject: [PATCH] Fix a bug when doing the getSymbols() in the binarySearch --- .../utils/org/eclipse/cdt/utils/elf/Elf.java | 18 +++++++++++++++--- .../cdt/utils/elf/parser/BinaryObject.java | 11 ++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java index 76285236294..45fbaabd1e8 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java @@ -607,8 +607,13 @@ public class Elf { public static final int ELF_TYPE_OBJ = 3; public static final int ELF_TYPE_CORE = 4; + public static final int DEBUG_TYPE_NONE = 0; + public static final int DEBUG_TYPE_STABS = 1; + public static final int DEBUG_TYPE_DWARF = 2; + String cpu; int type; + int debugType; boolean bDebug; boolean isle; @@ -621,9 +626,13 @@ public class Elf { } public boolean hasDebug() { - return bDebug; + return debugType != DEBUG_TYPE_NONE; } + public int getDebugType() { + return debugType; + } + public boolean isLittleEndian() { return isle; } @@ -691,8 +700,11 @@ public class Elf { Section [] sec = getSections(); for (int i = 0; i < sec.length; i++) { String s = sec[i].toString(); - attrib.bDebug = (s.startsWith(".debug") || s. equals(".stab")); - if (attrib.bDebug) { + if (s.equals(".debug_info")) { + attrib.debugType = Attribute.DEBUG_TYPE_DWARF; + break; + } else if (s.equals(".stab")) { + attrib.debugType = Attribute.DEBUG_TYPE_STABS; break; } } 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 b5acdff0844..1adc8adf007 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 @@ -57,14 +57,18 @@ public class BinaryObject extends BinaryFile implements IBinaryObject { public ISymbol getSymbol(long addr) { ISymbol[] syms = getSymbols(); int insertion = Arrays.binarySearch(syms, new Long(addr)); - if (insertion > 0) { + if (insertion >= 0) { return syms[insertion]; } if (insertion == -1) { return null; } insertion = -insertion - 1; - return syms[insertion - 1]; + ISymbol symbol = syms[insertion - 1]; + if (addr < (symbol.getAddress() + symbol.getSize())) { + return syms[insertion - 1]; + } + return null; } /** @@ -273,6 +277,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject { } } sym.addr = array[i].st_value; + sym.size = array[i].st_size; sym.filename = null; sym.startLine = 0; sym.endLine = sym.startLine; @@ -282,7 +287,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject { // Addr2line returns the funny "??" when it can not find the file. sym.filename = (filename != null && !filename.equals("??")) ? new Path(filename) : null; sym.startLine = addr2line.getLineNumber(sym.addr); - sym.endLine = addr2line.getLineNumber(sym.addr + array[i].st_size - 1); + sym.endLine = addr2line.getLineNumber(sym.addr + sym.size - 1); } catch (IOException e) { } }