1.1 --- a/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/elf/ElfHeader.java Mon Nov 07 18:55:23 2016 +0300
1.2 +++ b/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/elf/ElfHeader.java Tue Nov 08 14:49:23 2016 +0300
1.3 @@ -45,6 +45,7 @@
1.4 package org.netbeans.modules.cnd.dwarfdump.elf;
1.5
1.6 import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.ElfConstants;
1.7 +import org.netbeans.modules.cnd.dwarfdump.reader.ByteStreamReader;
1.8
1.9 public class ElfHeader {
1.10 public int elfClass = 0; /* File class */
1.11 @@ -97,10 +98,10 @@
1.12 }
1.13
1.14 public int getNumberOfSectionHeaders() {
1.15 - return e_shnum & 0xFFFF;
1.16 + return ByteStreamReader.ushortToInt(e_shnum);
1.17 }
1.18
1.19 public int getELFStringTableSectionIndex() {
1.20 - return e_shstrndx & 0xFFFF;
1.21 + return ByteStreamReader.ushortToInt(e_shstrndx);
1.22 }
1.23 }
2.1 --- a/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/reader/ByteStreamReader.java Mon Nov 07 18:55:23 2016 +0300
2.2 +++ b/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/reader/ByteStreamReader.java Tue Nov 08 14:49:23 2016 +0300
2.3 @@ -366,10 +366,19 @@
2.4 }
2.5
2.6 public long read3264() throws IOException {
2.7 - return (fileClass == ElfConstants.ELFCLASS32) ? intToLong(readInt()) : readLong();
2.8 + return (fileClass == ElfConstants.ELFCLASS32) ? ByteStreamReader.uintToLong(readInt()) : readLong();
2.9 }
2.10
2.11 - public static long intToLong(int value) {
2.12 + public static int ubyteToInt(byte value) {
2.13 + return 0xFF & value;
2.14 + }
2.15 +
2.16 + public static int ushortToInt(short value) {
2.17 + return 0xFFFF & value;
2.18 + }
2.19 +
2.20 + public static long uintToLong(int value) {
2.21 return 0xFFFFFFFFL & value;
2.22 }
2.23 +
2.24 }
3.1 --- a/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/reader/ElfReader.java Mon Nov 07 18:55:23 2016 +0300
3.2 +++ b/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/reader/ElfReader.java Tue Nov 08 14:49:23 2016 +0300
3.3 @@ -577,14 +577,14 @@
3.4 private SectionHeader readSectionHeader() throws IOException {
3.5 SectionHeader h = new SectionHeader();
3.6
3.7 - h.sh_name = intToLong(readInt());
3.8 - h.sh_type = intToLong(readInt());
3.9 + h.sh_name = ByteStreamReader.uintToLong(readInt());
3.10 + h.sh_type = ByteStreamReader.uintToLong(readInt());
3.11 h.sh_flags = read3264();
3.12 h.sh_addr = read3264();
3.13 h.sh_offset = read3264()+shiftIvArchive;
3.14 h.sh_size = read3264();
3.15 - h.sh_link = intToLong(readInt());
3.16 - h.sh_info = intToLong(readInt());
3.17 + h.sh_link = ByteStreamReader.uintToLong(readInt());
3.18 + h.sh_info = ByteStreamReader.uintToLong(readInt());
3.19 h.sh_addralign = read3264();
3.20 h.sh_entsize = read3264();
3.21
4.1 --- a/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/section/DwarfLineInfoSection.java Mon Nov 07 18:55:23 2016 +0300
4.2 +++ b/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/section/DwarfLineInfoSection.java Tue Nov 08 14:49:23 2016 +0300
4.3 @@ -63,6 +63,7 @@
4.4 import java.util.Set;
4.5 import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.LNE;
4.6 import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.LNS;
4.7 +import org.netbeans.modules.cnd.dwarfdump.reader.ByteStreamReader;
4.8
4.9 /**
4.10 *
4.11 @@ -95,11 +96,11 @@
4.12 stmt_list.total_length = reader.readDWlen();
4.13 stmt_list.version = reader.readShort();
4.14 stmt_list.prologue_length = reader.read3264();
4.15 - stmt_list.minimum_instruction_length = 0xFF & reader.readByte();
4.16 - stmt_list.default_is_stmt = 0xFF & reader.readByte();
4.17 + stmt_list.minimum_instruction_length = ByteStreamReader.ubyteToInt(reader.readByte());
4.18 + stmt_list.default_is_stmt = ByteStreamReader.ubyteToInt(reader.readByte());
4.19 stmt_list.line_base = reader.readByte();
4.20 - stmt_list.line_range = 0xFF & reader.readByte();
4.21 - stmt_list.opcode_base = 0xFF & reader.readByte();
4.22 + stmt_list.line_range = ByteStreamReader.ubyteToInt(reader.readByte());
4.23 + stmt_list.opcode_base = ByteStreamReader.ubyteToInt(reader.readByte());
4.24
4.25 stmt_list.standard_opcode_lengths = new long[stmt_list.opcode_base - 1];
4.26
4.27 @@ -186,7 +187,7 @@
4.28
4.29 while (reader.getFilePointer() < header.getSectionOffset() + shift + section.total_length) {
4.30
4.31 - int opcode = reader.readByte() & 0xFF;
4.32 + int opcode = ByteStreamReader.ubyteToInt(reader.readByte());
4.33
4.34 if (opcode < section.opcode_base) {
4.35 switch (LNS.get(opcode)) {
4.36 @@ -297,7 +298,7 @@
4.37
4.38 case DW_LNS_fixed_advance_pc:
4.39 {
4.40 - int amt = reader.readShort() & 0xFFFF;
4.41 + int amt = ByteStreamReader.ushortToInt(reader.readShort());
4.42 address += amt;
4.43 }
4.44 break;
5.1 --- a/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/section/DwarfMacroInfoSection.java Mon Nov 07 18:55:23 2016 +0300
5.2 +++ b/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/section/DwarfMacroInfoSection.java Tue Nov 08 14:49:23 2016 +0300
5.3 @@ -64,6 +64,7 @@
5.4 import org.netbeans.modules.cnd.dwarfdump.dwarf.DwarfMacinfoTable;
5.5 import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.MACINFO;
5.6 import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.SECTIONS;
5.7 +import org.netbeans.modules.cnd.dwarfdump.reader.ByteStreamReader;
5.8 import org.netbeans.modules.cnd.dwarfdump.reader.DwarfReader;
5.9
5.10 /**
5.11 @@ -117,7 +118,7 @@
5.12 }
5.13 }
5.14 if ((bitness & 4)==4) {
5.15 - int count = reader.readByte() & 0xFF;
5.16 + int count = ByteStreamReader.ubyteToInt(reader.readByte());
5.17 for(int i = 0; i < count; i++) {
5.18 byte opcode = reader.readByte();
5.19 long arg = reader.readUnsignedLEB128();
5.20 @@ -278,7 +279,7 @@
5.21 }
5.22 }
5.23 if ((bitness & 4)==4) {
5.24 - int count = reader.readByte() & 0xFF;
5.25 + int count = ByteStreamReader.ubyteToInt(reader.readByte());
5.26 for(int i = 0; i < count; i++) {
5.27 byte opcode = reader.readByte();
5.28 long arg = reader.readUnsignedLEB128();
6.1 --- a/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/section/StabIndexSection.java Mon Nov 07 18:55:23 2016 +0300
6.2 +++ b/cnd.dwarfdump/src/org/netbeans/modules/cnd/dwarfdump/section/StabIndexSection.java Tue Nov 08 14:49:23 2016 +0300
6.3 @@ -48,6 +48,7 @@
6.4 import org.netbeans.modules.cnd.dwarfdump.CompilationUnitStab;
6.5 import org.netbeans.modules.cnd.dwarfdump.Dwarf.CompilationUnitIterator;
6.6 import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.SECTIONS;
6.7 +import org.netbeans.modules.cnd.dwarfdump.reader.ByteStreamReader;
6.8 import org.netbeans.modules.cnd.dwarfdump.reader.DwarfReader;
6.9 import org.netbeans.modules.cnd.dwarfdump.source.CompileLineOrigin;
6.10 import org.netbeans.modules.cnd.dwarfdump.source.DefaultDriver;
6.11 @@ -99,8 +100,8 @@
6.12 int lang = 0;
6.13 while(reader.getFilePointer() < sectionEnd) {
6.14 int offset = reader.readInt();
6.15 - int type = reader.readByte() & 0xFF;
6.16 - int other = reader.readByte() & 0xFF;
6.17 + int type = ByteStreamReader.ubyteToInt(reader.readByte());
6.18 + int other = ByteStreamReader.ubyteToInt(reader.readByte());
6.19 int desc = reader.readShort();
6.20 int value = reader.readInt();
6.21 //System.err.println(" "+offset+" "+type+" "+other+" "+desc+" "+value );