From df30a11b1ef6cc3024ce84c43cc083c9655604b2 Mon Sep 17 00:00:00 2001 From: joxe Date: Sun, 29 Aug 2010 18:09:55 +0000 Subject: [PATCH] added more basic dwarf 2.0 support git-svn-id: https://mspsim.svn.sourceforge.net/svnroot/mspsim/mspsim@751 23d1a52b-0c3c-0410-b72d-8f29ab48fe35 --- se/sics/mspsim/debug/DwarfReader.java | 83 ++++++++++++++++++++++++++- se/sics/mspsim/util/ELFSection.java | 21 ++++++- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index 45fa37a..57b4545 100755 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -1,6 +1,9 @@ package se.sics.mspsim.debug; import java.util.ArrayList; + +import javax.sound.sampled.LineEvent; + import se.sics.mspsim.util.Utils; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.ELFSection; @@ -40,6 +43,9 @@ public class DwarfReader { private int lineFile; private int lineLine; private int lineColumn; + private boolean isBasicBlock = false; + private boolean isStatement = false; + private boolean endSequence = false; private ArrayList aranges = new ArrayList(); @@ -70,7 +76,7 @@ public class DwarfReader { int proLen = sec.readElf32(); int minOpLen = sec.readElf8(); - int isStmt = sec.readElf8(); + int defaultIsStmt = sec.readElf8(); int lineBase = sec.readElf8(); int lineRange = sec.readElf8(); int opcodeBase = sec.readElf8(); @@ -79,6 +85,13 @@ public class DwarfReader { System.out.println("Line total length: " + totLen); System.out.println("Line pro length: " + proLen); System.out.println("Line version: " + version); + + if (lineBase > 127) { + lineBase = lineBase - 256; + } + System.out.println("Line base : " + lineBase); + System.out.println("Line range : " + lineRange); + System.out.println("Line - Opcode base: " + opcodeBase); /* first char of includes (skip opcode lens)... */ for (int i = 0; i < opcodeBase - 1; i++) { @@ -124,17 +137,81 @@ public class DwarfReader { 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++) { + isStatement = defaultIsStmt != 0; + for (int i = 0; i < 100; i++) { int ins = sec.readElf8(); System.out.print(Utils.hex8(ins) + " "); switch(ins) { case DW_LNS_EXT: /* extended instruction */ + int len = sec.readElf8(); + int extIns = sec.readElf8(); + switch(extIns) { + case DW_LNE_end_sequence: + endSequence = true; + System.out.println("Line: End sequence executed!!!"); + break; + case DW_LNE_define_file: + System.out.println("Line: Should define a file!!!!"); + break; + case DW_LNE_set_address: + if (len == 2) + lineAddress = sec.readElf8(); + if (len == 3) + lineAddress = sec.readElf16(); + if (len == 5) + lineAddress = sec.readElf32(); + System.out.println("Line: Set address to: " + Utils.hex16(lineAddress) + + " (len: " + len + ")"); + break; + } break; - case DW_LNS_advance_line: + case DW_LNS_copy: + /* copy data to matrix... */ + isBasicBlock = false; break; case DW_LNS_advance_pc: + long add = sec.readLEB128(); + lineAddress += add * minOpLen; + System.out.println("Line: Increased address to: " + Utils.hex16(lineAddress)); break; + case DW_LNS_advance_line: + long addLine = sec.readLEB128S(); + lineLine += addLine; + System.out.println("Line: Increased line to: " + lineLine + + " (incr: " + addLine + ")"); + break; + case DW_LNS_set_file: + lineFile = (int) sec.readLEB128(); + System.out.println("Line: Set file to: " + lineFile); + break; + case DW_LNS_set_column: + lineColumn = (int) sec.readLEB128(); + break; + case DW_LNS_negate_stmt: + isStatement = !isStatement; + System.out.println("Line: Negated is statement"); + break; + case DW_LNS_set_basic_block: + isBasicBlock = true; + System.out.println("Line: Set basic block to true"); + break; + case DW_LNS_const_add_pc: + System.out.println("Line: Should add const to PC - but how much?"); + break; + case DW_LNS_fixed_advance_pc: + int incr = sec.readElf16(); + lineAddress += incr; + System.out.println("Line: Increased address to: " + Utils.hex16(lineAddress)); + break; + default: + + int lineInc = lineBase + ((ins - opcodeBase) % lineRange); + int addrInc = (ins - opcodeBase) / lineRange; + lineAddress += addrInc * minOpLen; + lineLine += lineInc; + System.out.println("Line: *** Special operation => addr: " + + Utils.hex16(lineAddress) + " Line: " + lineLine + " lineInc: " + lineInc); } } System.out.println(); diff --git a/se/sics/mspsim/util/ELFSection.java b/se/sics/mspsim/util/ELFSection.java index b65b246..019fcff 100644 --- a/se/sics/mspsim/util/ELFSection.java +++ b/se/sics/mspsim/util/ELFSection.java @@ -148,7 +148,26 @@ public class ELFSection { } while ((b & 128) != 0); return val; } - + + public long readLEB128S() { + long val = 0; + /* LSB first always? */ + int b; + int bitPos = 0; + do { + b = readElf8(pos++); + val = val + ((b & 127) << bitPos); + bitPos += 7; + } while ((b & 128) != 0); + long negval = 0x1 << bitPos; + if (b < 0x40) + return val; + else { + System.out.println("Line: read negative : " + val + " negval: " + negval); + return -(negval - val); + } + } + public int readElf8(int pos) { return elf.readElf8(pos + offset); }