1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import java.util.ArrayList ; 14 import org.eclipse.debug.internal.core.memory.MemoryByte; 15 16 19 20 public class MemoryViewLine extends Object { 21 private String fAddress; 22 private String fStrRep; 23 private MemoryByte[] fBytes; 24 private byte[] fByteArray; 25 private int fTableIndex = -1; 26 private String fPaddedString; 27 public boolean isMonitored; 28 29 public static final String P_ADDRESS = "address"; 31 private static final int numCharPerByteForHex = 2; 33 34 public MemoryViewLine(String address, MemoryByte[] bytes, int tableIndex, String paddedString) { 35 fAddress = address; 36 fBytes = bytes; 37 fTableIndex = tableIndex; 38 fPaddedString = paddedString; 39 } 40 41 public String getAddress() { 42 return fAddress; 43 } 44 45 public void setAddress(String address) { 46 fAddress = address; 47 } 48 49 public MemoryByte[] getBytes() 50 { 51 return fBytes; 52 } 53 54 public MemoryByte getByte(int offset) 55 { 56 if (fBytes == null) 57 return null; 58 59 if (offset < fBytes.length) 60 return fBytes[offset]; 61 else 62 return null; 63 64 } 65 66 public MemoryByte[] getBytes(int start, int end) 67 { 68 ArrayList ret = new ArrayList (); 69 70 for (int i=start; i<end; i++) 71 { 72 ret.add(fBytes[i]); 73 } 74 return (MemoryByte[]) ret.toArray(new MemoryByte[ret.size()]); 75 } 76 77 public String getRawMemoryString() 78 { 79 if (fStrRep == null) 80 { 81 StringBuffer buffer = new StringBuffer (); 82 fStrRep = HexRenderer.convertByteArrayToHexString(getByteArray()); 83 fStrRep = fStrRep.toUpperCase(); 84 85 buffer = buffer.append(fStrRep); 86 87 String paddedString = null; 89 int bufferCounter = 0; 90 for (int i=0; i<fBytes.length; i++) 91 { 92 if ((fBytes[i].flags & MemoryByte.VALID) != MemoryByte.VALID) 94 { 95 if (paddedString == null) 96 { 97 paddedString = fPaddedString; 98 99 if (paddedString.length() > MemoryViewLine.numCharPerByteForHex) 100 paddedString = paddedString.substring(0, MemoryViewLine.numCharPerByteForHex); 101 } 102 buffer.replace(bufferCounter, bufferCounter+MemoryViewLine.numCharPerByteForHex, paddedString); 103 bufferCounter += MemoryViewLine.numCharPerByteForHex; 104 } 105 } 106 107 fStrRep = buffer.toString(); 108 } 109 110 return fStrRep; 111 } 112 113 118 public String getPaddedString(int start, int end) { 119 StringBuffer buf = new StringBuffer (); 120 121 for (int i=start; i<end; i++) 122 { 123 buf.append(fPaddedString); 124 } 125 return buf.toString(); 126 } 127 128 public String getPaddedString() 129 { 130 return fPaddedString; 131 } 132 133 138 public boolean isAvailable(int start, int end) { 139 boolean available = true; 140 for (int i=start; i<end; i++) 141 { 142 if ((fBytes[i].flags & MemoryByte.VALID) != MemoryByte.VALID) 143 { 144 available = false; 145 break; 146 } 147 } 148 return available; 149 } 150 151 152 public byte[] getByteArray() 153 { 154 if (fByteArray == null) 155 { 156 fByteArray = new byte[fBytes.length]; 157 for (int i=0; i<fBytes.length; i++) 158 { 159 fByteArray[i] = fBytes[i].value; 160 } 161 } 162 163 return fByteArray; 164 } 165 166 public byte[] getByteArray(int start, int end) 167 { 168 byte[] ret = new byte[end-start]; 169 int j=0; 170 171 for (int i=start; i<end; i++) 172 { 173 ret[j] = fBytes[i].value; 174 j++; 175 } 176 return ret; 177 } 178 179 public void markDeltas(MemoryViewLine oldData) 180 { 181 if (oldData == null) 182 return; 183 184 if (!oldData.getAddress().equals(this.getAddress())) 186 return; 187 188 if (oldData.getRawMemoryString().equals(getRawMemoryString())) 190 return; 191 192 MemoryByte[] oldMemory = oldData.getBytes(); 193 194 if (oldMemory.length != fBytes.length) 195 return; 196 197 for (int i=0; i<fBytes.length; i++) 198 { 199 if ((fBytes[i].flags & MemoryByte.VALID) != (oldMemory[i].flags & MemoryByte.VALID)) 200 { 201 fBytes[i].flags |= MemoryByte.CHANGED; 202 continue; 203 } 204 205 if (((fBytes[i].flags & MemoryByte.VALID) == MemoryByte.VALID) && 206 ((oldMemory[i].flags & MemoryByte.VALID) == MemoryByte.VALID)) 207 { 208 if (fBytes[i].value != oldMemory[i].value) 209 { 210 fBytes[i].flags |= MemoryByte.CHANGED; 211 } 212 } 213 } 214 } 215 216 public void copyDeltas(MemoryViewLine oldData) 217 { 218 if (oldData == null) 219 return; 220 221 if (!oldData.getAddress().equals(this.getAddress())) 223 return; 224 225 MemoryByte[] oldMemory = oldData.getBytes(); 227 228 if (oldMemory.length != fBytes.length) 229 return; 230 231 for (int i=0; i<fBytes.length; i++) 232 { 233 fBytes[i].flags = oldMemory[i].flags; 234 } 235 } 236 237 public boolean isLineChanged(MemoryViewLine oldData) 238 { 239 if (oldData == null) 240 return false; 241 242 if (!oldData.getAddress().equals(this.getAddress())) 244 return false; 245 246 if (oldData.getRawMemoryString().equals(getRawMemoryString())) 248 return false; 249 else 250 return true; 251 } 252 253 258 259 public boolean isRangeChange(int offset, int endOffset) 260 { 261 byte ret = fBytes[offset].flags; 262 for (int i=offset; i<=endOffset; i++) 263 { 264 ret |= fBytes[i].flags; 265 } 266 267 if ((ret&MemoryByte.CHANGED) == MemoryByte.CHANGED) 268 return true; 269 else 270 return false; 271 } 272 273 public void unmarkDeltas() 274 { 275 for (int i=0; i<fBytes.length; i++) 276 { 277 if ((fBytes[i].flags & MemoryByte.CHANGED) == MemoryByte.CHANGED) 279 fBytes[i].flags ^= MemoryByte.CHANGED; 280 } 281 } 282 283 286 public String toString() 287 { 288 StringBuffer buf = new StringBuffer (); 289 buf.append(getAddress()); 290 291 buf.append(": "); 293 buf.append(getRawMemoryString()); 294 295 return buf.toString(); 296 } 297 298 public int getTableIndex() 299 { 300 return fTableIndex; 301 } 302 303 } 304 305 | Popular Tags |