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

Fix a bug when doing the getSymbols() in the binarySearch

This commit is contained in:
Alain Magloire 2004-01-09 22:07:48 +00:00
parent 522d6bc8b3
commit b4cb4ecb76
2 changed files with 23 additions and 6 deletions

View file

@ -607,8 +607,13 @@ public class Elf {
public static final int ELF_TYPE_OBJ = 3; public static final int ELF_TYPE_OBJ = 3;
public static final int ELF_TYPE_CORE = 4; 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; String cpu;
int type; int type;
int debugType;
boolean bDebug; boolean bDebug;
boolean isle; boolean isle;
@ -621,7 +626,11 @@ public class Elf {
} }
public boolean hasDebug() { public boolean hasDebug() {
return bDebug; return debugType != DEBUG_TYPE_NONE;
}
public int getDebugType() {
return debugType;
} }
public boolean isLittleEndian() { public boolean isLittleEndian() {
@ -691,8 +700,11 @@ public class Elf {
Section [] sec = getSections(); Section [] sec = getSections();
for (int i = 0; i < sec.length; i++) { for (int i = 0; i < sec.length; i++) {
String s = sec[i].toString(); String s = sec[i].toString();
attrib.bDebug = (s.startsWith(".debug") || s. equals(".stab")); if (s.equals(".debug_info")) {
if (attrib.bDebug) { attrib.debugType = Attribute.DEBUG_TYPE_DWARF;
break;
} else if (s.equals(".stab")) {
attrib.debugType = Attribute.DEBUG_TYPE_STABS;
break; break;
} }
} }

View file

@ -57,15 +57,19 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
public ISymbol getSymbol(long addr) { public ISymbol getSymbol(long addr) {
ISymbol[] syms = getSymbols(); ISymbol[] syms = getSymbols();
int insertion = Arrays.binarySearch(syms, new Long(addr)); int insertion = Arrays.binarySearch(syms, new Long(addr));
if (insertion > 0) { if (insertion >= 0) {
return syms[insertion]; return syms[insertion];
} }
if (insertion == -1) { if (insertion == -1) {
return null; return null;
} }
insertion = -insertion - 1; insertion = -insertion - 1;
ISymbol symbol = syms[insertion - 1];
if (addr < (symbol.getAddress() + symbol.getSize())) {
return syms[insertion - 1]; return syms[insertion - 1];
} }
return null;
}
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS() * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getBSS()
@ -273,6 +277,7 @@ public class BinaryObject extends BinaryFile implements IBinaryObject {
} }
} }
sym.addr = array[i].st_value; sym.addr = array[i].st_value;
sym.size = array[i].st_size;
sym.filename = null; sym.filename = null;
sym.startLine = 0; sym.startLine = 0;
sym.endLine = sym.startLine; 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. // Addr2line returns the funny "??" when it can not find the file.
sym.filename = (filename != null && !filename.equals("??")) ? new Path(filename) : null; sym.filename = (filename != null && !filename.equals("??")) ? new Path(filename) : null;
sym.startLine = addr2line.getLineNumber(sym.addr); 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) { } catch (IOException e) {
} }
} }