added more dwarf reading code

git-svn-id: https://mspsim.svn.sourceforge.net/svnroot/mspsim/mspsim@749 23d1a52b-0c3c-0410-b72d-8f29ab48fe35
This commit is contained in:
joxe 2010-08-16 14:04:06 +00:00
parent 4c9b00118e
commit a5992778f9
1 changed files with 54 additions and 26 deletions

View File

@ -1,7 +1,6 @@
package se.sics.mspsim.debug;
import java.util.ArrayList;
import se.sics.mspsim.util.Utils;
import se.sics.mspsim.util.ELF;
import se.sics.mspsim.util.ELFSection;
@ -9,6 +8,8 @@ import se.sics.mspsim.util.ELFSection;
public class DwarfReader {
/* Operands for lines */
public static final int DW_LNS_EXT = 0;
public static final int DW_LNS_copy = 1;
public static final int DW_LNS_advance_pc = 2;
public static final int DW_LNS_advance_line = 3;
@ -19,6 +20,11 @@ public class DwarfReader {
public static final int DW_LNS_const_add_pc = 8;
public static final int DW_LNS_fixed_advance_pc = 9;
/* Extended operands (preceded by DW_LNS_EXT + len) */
public static final int DW_LNE_end_sequence = 1;
public static final int DW_LNE_set_address = 2;
public static final int DW_LNE_define_file = 3;
ELF elfFile;
class Arange {
@ -58,16 +64,16 @@ public class DwarfReader {
private void readLines(ELFSection sec) {
System.out.println("DWARF Line - ELF Section length: " + sec.getSize());
int pos = 0;
sec.reset();
int totLen = sec.readElf32();
int version = sec.readElf16();
int proLen = sec.readElf32();
int minOpLen = sec.readElf8();
int totLen = sec.readElf32(pos + 0);
int version = sec.readElf16(pos + 4);
int proLen = sec.readElf32(pos + 6);
int minOpLen = sec.readElf8(pos + 10);
int isStmt = sec.readElf8(pos + 11);
int lineBase = sec.readElf8(pos + 12);
int lineRange = sec.readElf8(pos + 13);
int opcodeBase = sec.readElf8(pos + 14);
int isStmt = sec.readElf8();
int lineBase = sec.readElf8();
int lineRange = sec.readElf8();
int opcodeBase = sec.readElf8();
System.out.println("Line total length: " + totLen);
@ -75,15 +81,24 @@ public class DwarfReader {
System.out.println("Line version: " + version);
/* first char of includes (skip opcode lens)... */
pos = pos + 15 + opcodeBase - 1;
for (int i = 0; i < opcodeBase - 1; i++) {
sec.readElf8();
}
// pos = pos + 15 + opcodeBase - 1;
// System.out.println("Line pos = " + pos + " sec-pos = " + sec.getPosition());
System.out.println("Line --- include files ---");
ArrayList<String> directories = new ArrayList<String>();
directories.add("./");
ArrayList<String> files = new ArrayList<String>();
StringBuilder sb = new StringBuilder();
/* if first char is zero => no more include directories... */
int c;
while ((c = sec.readElf8(pos++)) != 0) {
while ((c = sec.readElf8()) != 0) {
sb.append((char)c);
while((c = sec.readElf8(pos++)) != 0) sb.append((char) c);
while((c = sec.readElf8()) != 0) sb.append((char) c);
System.out.println("Line: include file: " + sb.toString());
directories.add(sb.toString());
sb.setLength(0);
}
@ -91,25 +106,38 @@ public class DwarfReader {
long dirIndex = 0;
long time = 0;
long size = 0;
while ((c = sec.readElf8(pos++)) != 0) {
while ((c = sec.readElf8()) != 0) {
sb.append((char)c);
while((c = sec.readElf8(pos++)) != 0) sb.append((char) c);
/* TODO: maybe move pos to the ELF section for easy and safe reading? */
dirIndex = sec.readLEB128(pos);
pos += sec.LEB128Size(dirIndex);
time = sec.readLEB128(pos);
pos += sec.LEB128Size(time);
size = sec.readLEB128(pos);
pos += sec.LEB128Size(size);
while((c = sec.readElf8()) != 0) sb.append((char) c);
dirIndex = sec.readLEB128();
time = sec.readLEB128();
size = sec.readLEB128();
System.out.println("Line: source file: " + sb.toString() + " dir: " + dirIndex + " size: " + size);
files.add(directories.get((int) dirIndex) + sb.toString());
sb.setLength(0);
}
System.out.println();
/* Now we should have entered the position of the "code" for generating the
* line <=> address table
*/
System.out.println("Line: position: " + sec.getPosition());
System.out.println("Line: first bytes of the machine: ");
System.out.print("Line: ");
for (int i = 0; i < 20; i++) {
int ins = sec.readElf8();
System.out.print(Utils.hex8(ins) + " ");
switch(ins) {
case DW_LNS_EXT:
/* extended instruction */
break;
case DW_LNS_advance_line:
break;
case DW_LNS_advance_pc:
break;
}
}
System.out.println();
}
/* DWARF - address ranges information */