From 843606db1dfbd5897edf8ef9a706ac9d93239b80 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 10 Feb 2004 23:18:09 +0000 Subject: [PATCH] Fix for bug 40108: The memory view does not handle big/little endian. --- debug/org.eclipse.cdt.debug.ui/ChangeLog | 4 ++++ .../ui/views/memory/MemoryPresentation.java | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 979223dca7f..f2c0769c999 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,7 @@ +2004-02-10 Mikhail Khodjaiants + Fix for bug 40108: The memory view does not handle big/little endian. + * MemoryPresentation.java + 2004-02-10 Mikhail Khodjaiants Fix for bug 51519: Enable 'Format' action if multiple variables are selected. * VariableFormatActionDelegate.java diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java index d6bb6fd5f83..6b4bb3561fc 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java @@ -425,7 +425,7 @@ public class MemoryPresentation switch( getDataFormat() ) { case IFormattedMemoryBlock.MEMORY_FORMAT_HEX: - return item; + return convertToHex( getWordSize(), item ); case IFormattedMemoryBlock.MEMORY_FORMAT_SIGNED_DECIMAL: return convertToDecimal( getWordSize(), item, true ); case IFormattedMemoryBlock.MEMORY_FORMAT_UNSIGNED_DECIMAL: @@ -456,6 +456,25 @@ public class MemoryPresentation } return 0; } + + /** + * Performs endianness swap (in a brainless, but right most of the time) fashion. + * @param item + * @return + */ + private String convertToHex( int wordsize, String item ) + { + if( !getMemoryBlock().isLittleEndian() || wordsize == IFormattedMemoryBlock.MEMORY_SIZE_BYTE ) + return item; + + int length = item.length(); + StringBuffer ret = new StringBuffer( length ); + for( int i = length - 2 ; i >= 0 ; i -= 2 ) + { + ret.append( item.substring( i, i + 2 ) ); + } + return ret.toString(); + } private String convertToDecimal( int wordSize, String item, boolean signed ) {