ctf: fix bug 491382. Properly display bytefields
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 13 May 2016 03:25:12 +0000 (23:25 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 20 May 2016 20:39:40 +0000 (16:39 -0400)
Display byte arrays as signed or unsigned and
thus properly sign extend them.

Note: the order or precendence for Integer Arrays is:
* Strings
* Byte Arrays
* Other Ints

Change-Id: I6d9537f4866648094f20419de87a64478c17e2c9
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/72672
Reviewed-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@efficios.com>
ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfEventFieldTest.java
ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java

index 78f34bbb30f169b873ea479493d2c40b0642a998..13ce88db88ac5f1806d12c0b1e13414699f54843 100644 (file)
@@ -89,12 +89,13 @@ public class CtfTmfEventFieldTest {
 
         StructDeclaration sDec = new StructDeclaration(1l);
         StringDeclaration strDec = StringDeclaration.getStringDeclaration(Encoding.UTF8);
-        IntegerDeclaration intDec = IntegerDeclaration.UINT_8_DECL;
+        IntegerDeclaration byteDec = IntegerDeclaration.UINT_8_DECL;
+        IntegerDeclaration intDec = IntegerDeclaration.INT_8_DECL;
         FloatDeclaration flDec = new FloatDeclaration(8, 24,
                 ByteOrder.BIG_ENDIAN, 8);
-        SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
+        SequenceDeclaration seqDec = new SequenceDeclaration(LEN, byteDec);
         StructDeclaration structDec = new StructDeclaration(8);
-        EnumDeclaration enumDec = new EnumDeclaration(intDec);
+        EnumDeclaration enumDec = new EnumDeclaration(byteDec);
         VariantDeclaration varDec = new VariantDeclaration();
         ArrayDeclaration arrStrDec = new ArrayDeclaration(ARRAY_SIZE, strDec);
         ArrayDeclaration arrFloatDec = new ArrayDeclaration(ARRAY_SIZE, flDec);
@@ -103,7 +104,7 @@ public class CtfTmfEventFieldTest {
         ArrayDeclaration arrVariantDec = new ArrayDeclaration(ARRAY_SIZE, varDec);
         ArrayDeclaration arrEnumDec = new ArrayDeclaration(ARRAY_SIZE, enumDec);
 
-        sDec.addField(INT, intDec);
+        sDec.addField(INT, byteDec);
         bb.put(TEST_NUMBER);
 
         sDec.addField(ARRAY_INT, arrIntDec);
@@ -111,7 +112,7 @@ public class CtfTmfEventFieldTest {
             bb.put(TEST_NUMBER);
         }
 
-        sDec.addField(LEN, intDec);
+        sDec.addField(LEN, byteDec);
         bb.put(TEST_NUMBER);
 
         sDec.addField(FLOAT, flDec);
@@ -137,7 +138,7 @@ public class CtfTmfEventFieldTest {
         bb.put(TEST_NUMBER);
 
         structDec.addField(STR, strDec);
-        structDec.addField(INT, intDec);
+        structDec.addField(INT, byteDec);
         sDec.addField(STRUCT, structDec);
         bb.put(testStringBytes);
         bb.put((byte) 0);
@@ -160,7 +161,7 @@ public class CtfTmfEventFieldTest {
             bb.put(TEST_NUMBER);
         }
 
-        varDec.addField(LEN, intDec);
+        varDec.addField(LEN, byteDec);
         varDec.addField(FLOAT, flDec);
         varDec.setTag(ENUM);
         sDec.addField(VARIANT, varDec);
index 4f502d68f0bdd8323424cfe49102a5888b6de383..bef8078208cbca2c6c2602f7935019f821ac4de1 100644 (file)
@@ -131,19 +131,6 @@ public abstract class CtfTmfEventField extends TmfEventField {
             CompoundDeclaration arrDecl = (CompoundDeclaration) decl;
             IDeclaration elemType = null;
             elemType = arrDecl.getElementType();
-            if (arrayDef instanceof ByteArrayDefinition) {
-                ByteArrayDefinition byteArrayDefinition = (ByteArrayDefinition) arrayDef;
-                /* it's a CTFIntegerArrayField */
-                int size = arrayDef.getLength();
-                long[] values = new long[size];
-                for (int i = 0; i < size; i++) {
-                    values[i] = Byte.toUnsignedLong(byteArrayDefinition.getByte(i));
-                }
-                field = new CTFIntegerArrayField(fieldName, values,
-                        16,
-                        false);
-
-            }
             if (elemType instanceof IntegerDeclaration) {
                 /*
                  * Array of integers => CTFIntegerArrayField, unless it's a
@@ -154,6 +141,18 @@ public abstract class CtfTmfEventField extends TmfEventField {
                 if (elemIntType.isCharacter()) {
                     /* it's a CTFStringField */
                     field = new CTFStringField(fieldName, arrayDef.toString());
+                } else if (arrayDef instanceof ByteArrayDefinition) { // unsigned byte array
+                    ByteArrayDefinition byteArrayDefinition = (ByteArrayDefinition) arrayDef;
+                    /* it's a CTFIntegerArrayField */
+                    int size = arrayDef.getLength();
+                    long[] values = new long[size];
+                    for (int i = 0; i < size; i++) {
+                        values[i] = Byte.toUnsignedLong(byteArrayDefinition.getByte(i));
+                    }
+                    field = new CTFIntegerArrayField(fieldName, values,
+                            elemIntType.getBase(),
+                            elemIntType.isSigned());
+
                 } else {
                     /* it's a CTFIntegerArrayField */
                     int size = arrayDef.getLength();
This page took 0.027046 seconds and 5 git commands to generate.