diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index 3ba994c..45fa37a 100755 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -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 directories = new ArrayList(); + directories.add("./"); + ArrayList files = new ArrayList(); 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 */