From: Matthew Khouzam Date: Fri, 13 May 2016 03:25:12 +0000 (-0400) Subject: ctf: fix bug 491382. Properly display bytefields X-Git-Url: http://git.efficios.com/?p=deliverable%2Ftracecompass.git;a=commitdiff_plain;h=c9c50ae19781e9d60653e4d8d27f387bd2efd387 ctf: fix bug 491382. Properly display bytefields 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 Reviewed-on: https://git.eclipse.org/r/72672 Reviewed-by: Hudson CI Reviewed-by: Alexandre Montplaisir --- diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfEventFieldTest.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfEventFieldTest.java index 78f34bbb30..13ce88db88 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfEventFieldTest.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfEventFieldTest.java @@ -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); diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java index 4f502d68f0..bef8078208 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java @@ -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();