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:
parent
522d6bc8b3
commit
b4cb4ecb76
2 changed files with 23 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue