diff options
author | John Dallaway | 2021-11-07 17:19:21 +0000 |
---|---|---|
committer | Sarika Sinha | 2021-11-08 17:52:02 +0000 |
commit | a8b1a4953b7317fc4d3a5e6ed1acd1b5c3121346 (patch) | |
tree | 5935ddd893fa4c1f4e194ef4b03912caea2e1c13 | |
parent | c5d70d0268cb58d2bb0d8b2ff4ccc57d7b21d6dc (diff) | |
download | eclipse.platform.debug-a8b1a4953b7317fc4d3a5e6ed1acd1b5c3121346.tar.gz eclipse.platform.debug-a8b1a4953b7317fc4d3a5e6ed1acd1b5c3121346.tar.xz eclipse.platform.debug-a8b1a4953b7317fc4d3a5e6ed1acd1b5c3121346.zip |
Bug 577106: Accommodate addressableSize != 1 in integer renderingsI20211110-0750I20211110-0600I20211109-1800I20211109-0840I20211109-0720I20211108-1800
Change-Id: Iadf8f2c3dabc79a14484e85762144345561cbca9
Signed-off-by: John Dallaway <john@dallaway.org.uk>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.debug/+/187478
Reviewed-by: Jonah Graham <jonah@kichwacoders.com>
Tested-by: Sarika Sinha <sarika.sinha@in.ibm.com>
4 files changed, 218 insertions, 124 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/view/memory/TableRenderingTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/view/memory/TableRenderingTests.java index 9fda86db8..ce9c2b0db 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/view/memory/TableRenderingTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/view/memory/TableRenderingTests.java @@ -23,6 +23,8 @@ import org.eclipse.debug.core.model.MemoryByte; import org.eclipse.debug.internal.ui.views.memory.renderings.AbstractIntegerRendering; import org.eclipse.debug.internal.ui.views.memory.renderings.HexIntegerRendering; import org.eclipse.debug.internal.ui.views.memory.renderings.RenderingsUtil; +import org.eclipse.debug.internal.ui.views.memory.renderings.SignedIntegerRendering; +import org.eclipse.debug.internal.ui.views.memory.renderings.UnsignedIntegerRendering; import org.junit.Test; /** @@ -32,25 +34,62 @@ import org.junit.Test; @SuppressWarnings("restriction") public class TableRenderingTests { - private static final byte[] TWO_BYTES = new byte[] { - (byte) 0x67, (byte) 0x89 }; - private static final byte[] FOUR_BYTES = new byte[] { - (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab }; - private static final byte[] EIGHT_BYTES = new byte[] { - (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, - (byte) 0xab, (byte) 0xcd, (byte) 0xef }; + private static final byte[] BYTES_1 = new byte[] { (byte) 0x87 }; + private static final byte[] BYTES_2 = new byte[] { (byte) 0x98, (byte) 0x76 }; + private static final byte[] BYTES_4 = new byte[] { (byte) 0xba, (byte) 0x98, (byte) 0x76, (byte) 0x54 }; + private static final byte[] BYTES_8 = new byte[] { + (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, + (byte) 0x76, (byte) 0x54, (byte) 0x32, (byte) 0x10 }; + private static final byte[] BYTES_16 = new byte[16]; + private static final byte[] BYTES_24 = new byte[24]; + + static { + BYTES_16[0] = (byte) 0x80; // 2 ^ 127 + BYTES_24[0] = (byte) 0x80; // 2 ^ 191 + } @Test public void testHexIntegerRendering() throws DebugException { - testIntegerRendering(createHexIntegerRendering(1), TWO_BYTES, "6789", "8967"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(2), TWO_BYTES, "6789", "6789"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(1), FOUR_BYTES, "456789AB", "AB896745"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(2), FOUR_BYTES, "456789AB", "89AB4567"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(4), FOUR_BYTES, "456789AB", "456789AB"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(1), EIGHT_BYTES, "0123456789ABCDEF", "EFCDAB8967452301"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(2), EIGHT_BYTES, "0123456789ABCDEF", "CDEF89AB45670123"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(4), EIGHT_BYTES, "0123456789ABCDEF", "89ABCDEF01234567"); //$NON-NLS-1$ //$NON-NLS-2$ - testIntegerRendering(createHexIntegerRendering(8), EIGHT_BYTES, "0123456789ABCDEF", "0123456789ABCDEF"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(1), BYTES_1, "87", "87"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(1), BYTES_2, "9876", "7698"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(2), BYTES_2, "9876", "9876"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(1), BYTES_4, "BA987654", "547698BA"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(2), BYTES_4, "BA987654", "7654BA98"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(4), BYTES_4, "BA987654", "BA987654"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(1), BYTES_8, "FEDCBA9876543210", "1032547698BADCFE"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(4), BYTES_8, "FEDCBA9876543210", "76543210FEDCBA98"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(4), BYTES_16, "80000000000000000000000000000000", "00000000000000000000000080000000"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createHexIntegerRendering(4), BYTES_24, "800000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000080000000"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Test + public void testSignedIntegerRendering() throws DebugException { + testIntegerRendering(createSignedIntegerRendering(1, BYTES_1.length), BYTES_1, "-121", "-121"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(1, BYTES_2.length), BYTES_2, "-26506", "30360"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(2, BYTES_2.length), BYTES_2, "-26506", "-26506"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(1, BYTES_4.length), BYTES_4, "-1164413356", "1417058490"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(2, BYTES_4.length), BYTES_4, "-1164413356", "1985264280"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(4, BYTES_4.length), BYTES_4, "-1164413356", "-1164413356"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(1, BYTES_8.length), BYTES_8, "-81985529216486896", "1167088121787636990"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(4, BYTES_8.length), BYTES_8, "-81985529216486896", "8526495043095935640"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(8, BYTES_8.length), BYTES_8, "-81985529216486896", "-81985529216486896"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createSignedIntegerRendering(2, BYTES_16.length), BYTES_16, BigInteger.valueOf(2).pow(127).negate().toString(), "32768"); //$NON-NLS-1$ + testIntegerRendering(createSignedIntegerRendering(2, BYTES_24.length), BYTES_24, BigInteger.valueOf(2).pow(191).negate().toString(), "32768"); //$NON-NLS-1$ + } + + @Test + public void testUnsignedIntegerRendering() throws DebugException { + testIntegerRendering(createUnsignedIntegerRendering(1, BYTES_1.length), BYTES_1, "135", "135"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(1, BYTES_2.length), BYTES_2, "39030", "30360"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(2, BYTES_2.length), BYTES_2, "39030", "39030"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(1, BYTES_4.length), BYTES_4, "3130553940", "1417058490"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(2, BYTES_4.length), BYTES_4, "3130553940", "1985264280"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(4, BYTES_4.length), BYTES_4, "3130553940", "3130553940"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(1, BYTES_8.length), BYTES_8, "18364758544493064720", "1167088121787636990"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(4, BYTES_8.length), BYTES_8, "18364758544493064720", "8526495043095935640"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(8, BYTES_8.length), BYTES_8, "18364758544493064720", "18364758544493064720"); //$NON-NLS-1$ //$NON-NLS-2$ + testIntegerRendering(createUnsignedIntegerRendering(2, BYTES_16.length), BYTES_16, BigInteger.valueOf(2).pow(127).toString(), "32768"); //$NON-NLS-1$ + testIntegerRendering(createUnsignedIntegerRendering(2, BYTES_24.length), BYTES_24, BigInteger.valueOf(2).pow(191).toString(), "32768"); //$NON-NLS-1$ } private void testIntegerRendering(AbstractIntegerRendering rendering, byte[] bytes, String bigEndianString, String littleEndianString) throws DebugException { @@ -76,4 +115,32 @@ public class TableRenderingTests { }; } + private SignedIntegerRendering createSignedIntegerRendering(int addressableSize, int bytesPerColumn) { + return new SignedIntegerRendering(null) { + @Override + public int getAddressableSize() { + return addressableSize; + } + + @Override + public int getBytesPerColumn() { + return bytesPerColumn; + } + }; + } + + private UnsignedIntegerRendering createUnsignedIntegerRendering(int addressableSize, int bytesPerColumn) { + return new UnsignedIntegerRendering(null) { + @Override + public int getAddressableSize() { + return addressableSize; + } + + @Override + public int getBytesPerColumn() { + return bytesPerColumn; + } + }; + } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/RenderingsUtil.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/RenderingsUtil.java index 9382579d1..e62d485db 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/RenderingsUtil.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/RenderingsUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2015 IBM Corporation and others. + * Copyright (c) 2004, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * John Dallaway - Accommodate addressableSize != 1 (bug 577106) *******************************************************************************/ package org.eclipse.debug.internal.ui.views.memory.renderings; @@ -72,7 +73,7 @@ public class RenderingsUtil { return array; } - static public BigInteger convertByteArrayToUnsignedLong(byte[] array, int endianess) + static public BigInteger convertByteArrayToUnsignedLong(byte[] array, int endianess, int addressableSize) { if (array.length < 8) { @@ -82,14 +83,15 @@ public class RenderingsUtil { BigInteger value = new BigInteger("0"); //$NON-NLS-1$ if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int i=0; i< 8; i++) - { - byte[] temp = new byte[1]; - temp[0] = array[i]; - BigInteger b = new BigInteger(temp); - b = b.and(new BigInteger("ff", 16)); //$NON-NLS-1$ - b = b.shiftLeft(i*8); - value = value.or(b); + for (int i = 0; i < 8; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + byte[] temp = new byte[1]; + temp[0] = array[i + j]; + BigInteger b = new BigInteger(temp); + b = b.and(new BigInteger("ff", 16)); //$NON-NLS-1$ + b = b.shiftLeft((i + addressableSize - j - 1) * 8); + value = value.or(b); + } } } else @@ -111,9 +113,10 @@ public class RenderingsUtil { * Convert byte array to long. * @param array * @param endianess + * @param addressableSize * @return result of the conversion in long */ - static public long convertByteArrayToLong(byte[] array, int endianess) + static public long convertByteArrayToLong(byte[] array, int endianess, int addressableSize) { if (array.length < 8) { @@ -123,10 +126,12 @@ public class RenderingsUtil { if (endianess == RenderingsUtil.LITTLE_ENDIAN) { long value = 0; - for (int i = 0; i < 8; i++) { - long b = array[i]; - b &= 0xff; - value |= (b << (i * 8)); + for (int i = 0; i < 8; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + long b = array[i + j]; + b &= 0xff; + value |= (b << ((i + addressableSize - j - 1) * 8)); + } } return value; } @@ -141,7 +146,7 @@ public class RenderingsUtil { return value; } - static public BigInteger convertByteArrayToSignedBigInt(byte[] array, int endianess) + static public BigInteger convertByteArrayToSignedBigInt(byte[] array, int endianess, int addressableSize) { if (array.length < 16) { @@ -152,10 +157,10 @@ public class RenderingsUtil { { // reverse bytes byte[] holder = new byte[16]; - int j=15; - for (int i=0; i<16; i++, j--) - { - holder[i] = array[j]; + for (int i = 0; i < 16; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + holder[i + j] = array[16 + j - i - addressableSize]; + } } // create BigInteger @@ -166,7 +171,7 @@ public class RenderingsUtil { return value; } - static public BigInteger convertByteArrayToSignedBigInt(byte[] array, int endianess, int arraySize) + static public BigInteger convertByteArrayToSignedBigInt(byte[] array, int endianess, int arraySize, int addressableSize) { if (array.length < arraySize) { @@ -177,10 +182,10 @@ public class RenderingsUtil { { // reverse bytes byte[] holder = new byte[arraySize]; - int j=arraySize-1; - for (int i=0; i<arraySize; i++, j--) - { - holder[i] = array[j]; + for (int i = 0; i < arraySize; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + holder[i + j] = array[arraySize + j - i - addressableSize]; + } } // create BigInteger @@ -191,7 +196,7 @@ public class RenderingsUtil { return value; } - static public BigInteger convertByteArrayToUnsignedBigInt(byte[] array, int endianess) + static public BigInteger convertByteArrayToUnsignedBigInt(byte[] array, int endianess, int addressableSize) { if (array.length < 16) { @@ -201,14 +206,15 @@ public class RenderingsUtil { BigInteger value = new BigInteger("0"); //$NON-NLS-1$ if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int i=0; i< 16; i++) - { - byte[] temp = new byte[1]; - temp[0] = array[i]; - BigInteger b = new BigInteger(temp); - b = b.and(new BigInteger("ff", 16)); //$NON-NLS-1$ - b = b.shiftLeft(i*8); - value = value.or(b); + for (int i = 0; i < 16; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + byte[] temp = new byte[1]; + temp[0] = array[i + j]; + BigInteger b = new BigInteger(temp); + b = b.and(new BigInteger("ff", 16)); //$NON-NLS-1$ + b = b.shiftLeft((i + addressableSize - j - 1) * 8); + value = value.or(b); + } } } else @@ -226,7 +232,7 @@ public class RenderingsUtil { return value; } - static public BigInteger convertByteArrayToUnsignedBigInt(byte[] array, int endianess, int arraySize) + static public BigInteger convertByteArrayToUnsignedBigInt(byte[] array, int endianess, int arraySize, int addressableSize) { if (array.length < arraySize) { @@ -236,14 +242,15 @@ public class RenderingsUtil { BigInteger value = new BigInteger("0"); //$NON-NLS-1$ if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int i=0; i< arraySize; i++) - { - byte[] temp = new byte[1]; - temp[0] = array[i]; - BigInteger b = new BigInteger(temp); - b = b.and(new BigInteger("ff", 16)); //$NON-NLS-1$ - b = b.shiftLeft(i*8); - value = value.or(b); + for (int i = 0; i < arraySize; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + byte[] temp = new byte[1]; + temp[0] = array[i + j]; + BigInteger b = new BigInteger(temp); + b = b.and(new BigInteger("ff", 16)); //$NON-NLS-1$ + b = b.shiftLeft((i + addressableSize - j - 1) * 8); + value = value.or(b); + } } } else @@ -265,9 +272,10 @@ public class RenderingsUtil { * Convert byte array to integer. * @param array * @param endianess + * @param addressableSize * @return result of the conversion in int */ - static public int convertByteArrayToInt(byte[] array, int endianess) + static public int convertByteArrayToInt(byte[] array, int endianess, int addressableSize) { if (array.length < 4) { @@ -277,10 +285,12 @@ public class RenderingsUtil { if (endianess == RenderingsUtil.LITTLE_ENDIAN) { int value = 0; - for (int i = 0; i < 4; i++) { - int b = array[i]; - b &= 0xff; - value |= (b << (i * 8)); + for (int i = 0; i < 4; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + int b = array[i + j]; + b &= 0xff; + value |= (b << ((i + addressableSize - j - 1) * 8)); + } } return value; } @@ -299,9 +309,10 @@ public class RenderingsUtil { * Convert byte array to short. * @param array * @param endianess + * @param addressableSize * @return result of teh conversion in short */ - static public short convertByteArrayToShort(byte[] array, int endianess) + static public short convertByteArrayToShort(byte[] array, int endianess, int addressableSize) { if (array.length < 2) { @@ -311,10 +322,12 @@ public class RenderingsUtil { if (endianess == RenderingsUtil.LITTLE_ENDIAN) { short value = 0; - for (int i = 0; i < 2; i++) { - short b = array[i]; - b &= 0xff; - value |= (b << (i * 8)); + for (int i = 0; i < 2; i += addressableSize) { + for (int j = 0; j < addressableSize; j++) { + short b = array[i + j]; + b &= 0xff; + value |= (b << ((i + addressableSize - j - 1) * 8)); + } } return value; } @@ -332,18 +345,20 @@ public class RenderingsUtil { * Convert big integer to byte array. * @param i * @param endianess + * @param addressableSize * @return result of the conversion in raw byte array */ - static public byte[] convertBigIntegerToByteArray(BigInteger i, int endianess) + static public byte[] convertBigIntegerToByteArray(BigInteger i, int endianess, int addressableSize) { byte buf[]=new byte[16]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int j=0; j<16; j++) - { - BigInteger x = i.shiftRight(j*8); - buf[j] = x.byteValue(); + for (int j = 0; j < 16; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + BigInteger x = i.shiftRight((j + addressableSize - k - 1) * 8); + buf[j + k] = x.byteValue(); + } } return buf; } @@ -355,16 +370,17 @@ public class RenderingsUtil { return buf; } - static public byte[] convertSignedBigIntToByteArray(BigInteger i, int endianess, int arraySize) + static public byte[] convertSignedBigIntToByteArray(BigInteger i, int endianess, int arraySize, int addressableSize) { byte buf[]=new byte[arraySize]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int j=0; j<arraySize; j++) - { - BigInteger x = i.shiftRight(j*8); - buf[j] = x.byteValue(); + for (int j = 0; j < arraySize; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + BigInteger x = i.shiftRight((j + addressableSize - k - 1) * 8); + buf[j + k] = x.byteValue(); + } } return buf; } @@ -380,18 +396,20 @@ public class RenderingsUtil { * Convert big integer to byte array. * @param i * @param endianess + * @param addressableSize * @return result of the conversion in raw byte array */ - static public byte[] convertUnsignedBigIntegerToByteArray(BigInteger i, int endianess) + static public byte[] convertUnsignedBigIntegerToByteArray(BigInteger i, int endianess, int addressableSize) { byte buf[]=new byte[32]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int j=0; j<32; j++) - { - BigInteger x = i.shiftRight(j*8); - buf[j] = x.byteValue(); + for (int j = 0; j < 32; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + BigInteger x = i.shiftRight((j + addressableSize - k - 1) * 8); + buf[j + k] = x.byteValue(); + } } return buf; } @@ -403,16 +421,17 @@ public class RenderingsUtil { return buf; } - static public byte[] convertUnsignedBigIntToByteArray(BigInteger i, int endianess, int arraySize) + static public byte[] convertUnsignedBigIntToByteArray(BigInteger i, int endianess, int arraySize, int addressableSize) { byte buf[]=new byte[arraySize*2]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int j=0; j<arraySize*2; j++) - { - BigInteger x = i.shiftRight(j*8); - buf[j] = x.byteValue(); + for (int j = 0; j < arraySize * 2; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + BigInteger x = i.shiftRight((j + addressableSize - k - 1) * 8); + buf[j + k] = x.byteValue(); + } } return buf; } @@ -428,17 +447,19 @@ public class RenderingsUtil { * Convert long to byte array. * @param i * @param endianess + * @param addressableSize * @return result of the conversion in raw byte array */ - static public byte[] convertLongToByteArray(long i, int endianess) + static public byte[] convertLongToByteArray(long i, int endianess, int addressableSize) { byte buf[]=new byte[8]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int j=0; j<8; j++) - { - buf[j] = Long.valueOf(i>>j*8).byteValue(); + for (int j = 0; j < 8; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + buf[j + k] = Long.valueOf(i >> (j + addressableSize - k - 1) * 8).byteValue(); + } } return buf; } @@ -453,17 +474,19 @@ public class RenderingsUtil { * Convert integer to byte array. * @param i * @param endianess + * @param addressableSize * @return result of the conversion in raw byte array */ - static public byte[] convertIntToByteArray(int i, int endianess) + static public byte[] convertIntToByteArray(int i, int endianess, int addressableSize) { byte buf[]=new byte[4]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (int j=0; j<4; j++) - { - buf[j] = Integer.valueOf(i>>j*8).byteValue(); + for (int j = 0; j < 4; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + buf[j + k] = Integer.valueOf(i >> (j + addressableSize - k - 1) * 8).byteValue(); + } } return buf; } @@ -478,17 +501,19 @@ public class RenderingsUtil { * Convert short to byte array. * @param i * @param endianess + * @param addressableSize * @return result of the conversion in raw byte array */ - static public byte[] convertShortToByteArray(short i, int endianess) + static public byte[] convertShortToByteArray(short i, int endianess, int addressableSize) { byte buf[]=new byte[2]; if (endianess == RenderingsUtil.LITTLE_ENDIAN) { - for (short j=0; j<2; j++) - { - buf[j] = Integer.valueOf(i>>j*8).byteValue(); + for (short j = 0; j < 2; j += addressableSize) { + for (int k = 0; k < addressableSize; k++) { + buf[j + k] = Integer.valueOf(i >> (j + addressableSize - k - 1) * 8).byteValue(); + } } return buf; } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java index ac774e814..30b683183 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * John Dallaway - Accommodate addressableSize != 1 (bug 577106) *******************************************************************************/ package org.eclipse.debug.internal.ui.views.memory.renderings; @@ -47,22 +48,22 @@ public class SignedIntegerRendering extends AbstractIntegerRendering { result = byteArray[0]; break; case 2: - result = RenderingsUtil.convertByteArrayToShort(byteArray, endianess); + result = RenderingsUtil.convertByteArrayToShort(byteArray, endianess, getAddressableSize()); break; case 4: - result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess); + result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess, getAddressableSize()); break; case 8: - result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess); + result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess, getAddressableSize()); break; case 16: { - BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess); + BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess, getAddressableSize()); return bigRet.toString(); } default: { - BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess, columnSize); + BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess, columnSize, getAddressableSize()); return bigRet.toString(); } } @@ -85,19 +86,19 @@ public class SignedIntegerRendering extends AbstractIntegerRendering { case 2: { short i = Short.parseShort(newValue); - bytes = RenderingsUtil.convertShortToByteArray(i, endianess); + bytes = RenderingsUtil.convertShortToByteArray(i, endianess, getAddressableSize()); break; } case 4: { int i = Integer.parseInt(newValue); - bytes = RenderingsUtil.convertIntToByteArray(i, endianess); + bytes = RenderingsUtil.convertIntToByteArray(i, endianess, getAddressableSize()); break; } case 8: { long i = Long.parseLong(newValue); - bytes = RenderingsUtil.convertLongToByteArray(i, endianess); + bytes = RenderingsUtil.convertLongToByteArray(i, endianess, getAddressableSize()); break; } case 16: @@ -105,7 +106,7 @@ public class SignedIntegerRendering extends AbstractIntegerRendering { // special case for colSize == 16 // need to represent number in Big Integer BigInteger i = new BigInteger(newValue); - bytes = RenderingsUtil.convertBigIntegerToByteArray(i, endianess); + bytes = RenderingsUtil.convertBigIntegerToByteArray(i, endianess, getAddressableSize()); return bytes; } @@ -128,7 +129,7 @@ public class SignedIntegerRendering extends AbstractIntegerRendering { throw new NumberFormatException(); } - bytes = RenderingsUtil.convertSignedBigIntToByteArray(i, endianess, colSize); + bytes = RenderingsUtil.convertSignedBigIntToByteArray(i, endianess, colSize, getAddressableSize()); return bytes; } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java index 572bbf293..b6f9ce73f 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * John Dallaway - Accommodate addressableSize != 1 (bug 577106) *******************************************************************************/ package org.eclipse.debug.internal.ui.views.memory.renderings; @@ -43,22 +44,22 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering { result &= 0xff; break; case 2: - result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess); + result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess, getAddressableSize()); break; case 4: - result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess); + result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess, getAddressableSize()); break; case 8: - BigInteger value = RenderingsUtil.convertByteArrayToUnsignedLong(byteArray, endianess); + BigInteger value = RenderingsUtil.convertByteArrayToUnsignedLong(byteArray, endianess, getAddressableSize()); return value.toString(); case 16: { - BigInteger bigRet = RenderingsUtil.convertByteArrayToUnsignedBigInt(byteArray, endianess); + BigInteger bigRet = RenderingsUtil.convertByteArrayToUnsignedBigInt(byteArray, endianess, getAddressableSize()); return bigRet.toString(); } default: { - BigInteger bigRet = RenderingsUtil.convertByteArrayToUnsignedBigInt(byteArray, endianess, columnSize); + BigInteger bigRet = RenderingsUtil.convertByteArrayToUnsignedBigInt(byteArray, endianess, columnSize, getAddressableSize()); return bigRet.toString(); } } @@ -76,7 +77,7 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering { case 1: { short i = Short.parseShort(newValue); - bytes = RenderingsUtil.convertShortToByteArray(i, endianess); + bytes = RenderingsUtil.convertShortToByteArray(i, endianess, getAddressableSize()); bytes = extractBytes(bytes, endianess, colSize); break; } @@ -84,28 +85,28 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering { case 2: { int i = Integer.parseInt(newValue); - bytes = RenderingsUtil.convertIntToByteArray(i, endianess); + bytes = RenderingsUtil.convertIntToByteArray(i, endianess, getAddressableSize()); bytes = extractBytes(bytes, endianess, colSize); break; } case 4: { long i = Long.parseLong(newValue); - bytes = RenderingsUtil.convertLongToByteArray(i, endianess); + bytes = RenderingsUtil.convertLongToByteArray(i, endianess, getAddressableSize()); bytes = extractBytes(bytes, endianess, colSize); break; } case 8: { BigInteger i = new BigInteger(newValue); - bytes = RenderingsUtil.convertBigIntegerToByteArray(i, endianess); + bytes = RenderingsUtil.convertBigIntegerToByteArray(i, endianess, getAddressableSize()); bytes = extractBytes(bytes, endianess, colSize); break; } case 16: { BigInteger i = new BigInteger(newValue); - bytes = RenderingsUtil.convertUnsignedBigIntegerToByteArray(i, endianess); + bytes = RenderingsUtil.convertUnsignedBigIntegerToByteArray(i, endianess, getAddressableSize()); bytes = extractBytes(bytes, endianess, colSize); return bytes; @@ -113,7 +114,7 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering { default: { BigInteger i = new BigInteger(newValue); - bytes = RenderingsUtil.convertUnsignedBigIntToByteArray(i, endianess, colSize); + bytes = RenderingsUtil.convertUnsignedBigIntToByteArray(i, endianess, colSize, getAddressableSize()); bytes = extractBytes(bytes, endianess, colSize); return bytes; } |