mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Work on the Stabs debug format implementation.
This commit is contained in:
parent
0bde2ce901
commit
8c26ef7560
2 changed files with 61 additions and 59 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.utils.stabs;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.utils.elf.Elf;
|
||||
|
@ -22,17 +23,33 @@ public class Stabs {
|
|||
byte[] stabData;
|
||||
byte[] stabstrData;
|
||||
boolean isLe;
|
||||
List entries;
|
||||
Entry[] entries;
|
||||
|
||||
public class Entry {
|
||||
public class Entry implements Comparable{
|
||||
public long addr;
|
||||
public long size;
|
||||
public int startLine;
|
||||
public String string;
|
||||
|
||||
public Entry(String s) {
|
||||
string = s;
|
||||
}
|
||||
public int compareTo(Object obj) {
|
||||
long thisVal = 0;
|
||||
long anotherVal = 0;
|
||||
if (obj instanceof Entry) {
|
||||
Entry entry = (Entry) obj;
|
||||
thisVal = this.addr;
|
||||
anotherVal = entry.addr;
|
||||
} else if (obj instanceof Long) {
|
||||
Long val = (Long) obj;
|
||||
anotherVal = val.longValue();
|
||||
thisVal = (long) this.addr;
|
||||
}
|
||||
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("Name: ").append(string).append("\n");
|
||||
|
@ -201,14 +218,31 @@ public class Stabs {
|
|||
if (entries == null) {
|
||||
parse();
|
||||
}
|
||||
Entry[] array = new Entry[entries.size()];
|
||||
entries.toArray(array);
|
||||
return array;
|
||||
return entries;
|
||||
}
|
||||
|
||||
public Entry getEntry(long addr) throws IOException {
|
||||
if (entries == null) {
|
||||
parse();
|
||||
}
|
||||
int insertion = Arrays.binarySearch(entries, new Long(addr));
|
||||
if (insertion >= 0) {
|
||||
return entries[insertion];
|
||||
}
|
||||
if (insertion == -1) {
|
||||
return null;
|
||||
}
|
||||
insertion = -insertion - 1;
|
||||
Entry entry = entries[insertion - 1];
|
||||
if (addr < (entry.addr + entry.size)) {
|
||||
return entries[insertion - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void parse() throws IOException {
|
||||
|
||||
entries = new ArrayList();
|
||||
List list = new ArrayList();
|
||||
|
||||
long nstab = stabData.length / StabConstant.SIZE;
|
||||
int i, offset, bracket;
|
||||
|
@ -325,7 +359,7 @@ public class Stabs {
|
|||
variable.startLine = desc;
|
||||
variable.function = currentFunction;
|
||||
variable.filename = currentFile;
|
||||
entries.add(variable);
|
||||
list.add(variable);
|
||||
if (currentFunction != null) {
|
||||
currentFunction.variables.add(variable);
|
||||
}
|
||||
|
@ -336,6 +370,7 @@ public class Stabs {
|
|||
currentFunction.endLine = currentFunction.startLine = desc;
|
||||
} else {
|
||||
currentFunction.endLine = desc;
|
||||
currentFunction.size = value;
|
||||
}
|
||||
currentFunction.lines.add(new Integer(desc));
|
||||
}
|
||||
|
@ -349,7 +384,7 @@ public class Stabs {
|
|||
currentFunction.addr = value;
|
||||
currentFunction.startLine = desc;
|
||||
currentFunction.filename = currentFile;
|
||||
entries.add(currentFunction);
|
||||
list.add(currentFunction);
|
||||
break;
|
||||
case StabConstant.N_LBRAC :
|
||||
bracket++;
|
||||
|
@ -360,7 +395,7 @@ public class Stabs {
|
|||
case StabConstant.N_BINCL :
|
||||
Include include = new Include(name);
|
||||
include.index = includeCount++;
|
||||
entries.add(include);
|
||||
list.add(include);
|
||||
break;
|
||||
case StabConstant.N_EINCL :
|
||||
break;
|
||||
|
@ -379,11 +414,15 @@ public class Stabs {
|
|||
//System.out.println(" " + i + "\t" + Stab.type2String(type) + "\t" + other + "\t\t" +
|
||||
// desc + "\t" + Long.toHexString(value) + "\t" + + stroff + "\t\t" +name);
|
||||
}
|
||||
entries = new Entry[list.size()];
|
||||
list.toArray(entries);
|
||||
list.clear();
|
||||
Arrays.sort(entries);
|
||||
}
|
||||
|
||||
public void print() {
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
Entry entry = (Entry) entries.get(i);
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
Entry entry = entries[i];
|
||||
System.out.println(entry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ import org.eclipse.cdt.utils.elf.Elf;
|
|||
public class StabsAddr2line {
|
||||
|
||||
Stabs stabs;
|
||||
long lastAddress;
|
||||
Stabs.Entry entry;
|
||||
|
||||
public StabsAddr2line(byte[] stab, byte[] stabstr, boolean le) throws IOException {
|
||||
stabs = new Stabs(stab, stabstr, le);
|
||||
|
@ -44,17 +42,8 @@ public class StabsAddr2line {
|
|||
* @see IAddr2line#getStartLine(long)
|
||||
*/
|
||||
public int getStartLine(long address) throws IOException {
|
||||
if (address != lastAddress || entry == null) {
|
||||
Stabs.Entry[] entries = stabs.getEntries();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].addr == address) {
|
||||
lastAddress = address;
|
||||
entry = entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (address == lastAddress && entry != null) {
|
||||
Stabs.Entry entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
return entry.startLine;
|
||||
}
|
||||
return 0;
|
||||
|
@ -66,17 +55,8 @@ public class StabsAddr2line {
|
|||
* @see IAddr2line#getEndLine(long)
|
||||
*/
|
||||
public int getEndLine(long address) throws IOException {
|
||||
if (address != lastAddress || entry == null) {
|
||||
Stabs.Entry[] entries = stabs.getEntries();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].addr == address) {
|
||||
lastAddress = address;
|
||||
entry = entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (address == lastAddress && entry != null) {
|
||||
Stabs.Entry entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
if (entry instanceof Stabs.Function) {
|
||||
return ((Stabs.Function)entry).endLine;
|
||||
}
|
||||
|
@ -91,17 +71,8 @@ public class StabsAddr2line {
|
|||
* @see IAddr2line#getFunction(long)
|
||||
*/
|
||||
public String getFunction(long address) throws IOException {
|
||||
if (address != lastAddress || entry == null) {
|
||||
Stabs.Entry[] entries = stabs.getEntries();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].addr == address) {
|
||||
lastAddress = address;
|
||||
entry = entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (address == lastAddress && entry != null) {
|
||||
Stabs.Entry entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
return entry.string;
|
||||
}
|
||||
return null;
|
||||
|
@ -113,17 +84,8 @@ public class StabsAddr2line {
|
|||
* @see IAddr2line#getFileName(long)
|
||||
*/
|
||||
public String getFileName(long address) throws IOException {
|
||||
if (address != lastAddress || entry == null) {
|
||||
Stabs.Entry[] entries = stabs.getEntries();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].addr == address) {
|
||||
lastAddress = address;
|
||||
entry = entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (address == lastAddress && entry instanceof Stabs.LocatableEntry) {
|
||||
Stabs.Entry entry = stabs.getEntry(address);
|
||||
if (entry instanceof Stabs.LocatableEntry) {
|
||||
return ((Stabs.LocatableEntry)entry).filename;
|
||||
}
|
||||
return null;
|
||||
|
@ -150,11 +112,12 @@ public class StabsAddr2line {
|
|||
byte[] strtab = stabstr.loadSectionData();
|
||||
StabsAddr2line addr2line = new StabsAddr2line(array, strtab, true);
|
||||
long address = Integer.decode(args[1]).longValue();
|
||||
int line = addr2line.getStartLine(address);
|
||||
int startLine = addr2line.getStartLine(address);
|
||||
int endLine = addr2line.getEndLine(address);
|
||||
String function = addr2line.getFunction(address);
|
||||
String filename = addr2line.getFileName(address);
|
||||
System.out.println(Long.toHexString(address));
|
||||
System.out.println(filename + ":" + function + ":" + line);
|
||||
System.out.println(filename + ":" + function + ":" + startLine + ":" + endLine);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Add table
Reference in a new issue