|
Lines 73-78
Link Here
|
| 73 |
} |
73 |
} |
| 74 |
} |
74 |
} |
| 75 |
|
75 |
|
|
|
76 |
// Back-end commands cache |
| 77 |
private CommandCache fCommandCache; |
| 78 |
// Local memory cache |
| 76 |
private MIMemoryCache fMemoryCache; |
79 |
private MIMemoryCache fMemoryCache; |
| 77 |
|
80 |
|
| 78 |
/** |
81 |
/** |
|
Lines 111-122
Link Here
|
| 111 |
* @param requestMonitor |
114 |
* @param requestMonitor |
| 112 |
*/ |
115 |
*/ |
| 113 |
private void doInitialize(final RequestMonitor requestMonitor) { |
116 |
private void doInitialize(final RequestMonitor requestMonitor) { |
|
|
117 |
// Create the command cache |
| 118 |
ICommandControlService commandControl = getServicesTracker().getService(ICommandControlService.class); |
| 119 |
fCommandCache = new CommandCache(getSession(), commandControl); |
| 120 |
fCommandCache.setContextAvailable(commandControl.getContext(), true); |
| 114 |
|
121 |
|
| 115 |
// Register this service |
122 |
// Register this service |
| 116 |
register(new String[] { MIMemory.class.getName(), IMemory.class.getName() }, new Hashtable<String, String>()); |
123 |
register(new String[] { MIMemory.class.getName(), IMemory.class.getName() }, new Hashtable<String, String>()); |
| 117 |
|
124 |
|
| 118 |
// Create the memory requests cache |
125 |
// Create the memory requests cache |
| 119 |
setMemoryCache(new MIMemoryCache()); |
126 |
fMemoryCache = new MIMemoryCache(); |
| 120 |
|
127 |
|
| 121 |
// Register as service event listener |
128 |
// Register as service event listener |
| 122 |
getSession().addServiceEventListener(this, null); |
129 |
getSession().addServiceEventListener(this, null); |
|
Lines 149-163
Link Here
|
| 149 |
return MIPlugin.getBundleContext(); |
156 |
return MIPlugin.getBundleContext(); |
| 150 |
} |
157 |
} |
| 151 |
|
158 |
|
| 152 |
/** |
|
|
| 153 |
* This method resets the memory cache. It allows an overriding class to provide |
| 154 |
* its own overridden memory cache class. |
| 155 |
* |
| 156 |
* @since 1.1 |
| 157 |
*/ |
| 158 |
protected void setMemoryCache(MIMemoryCache cache) { fMemoryCache = cache; } |
| 159 |
|
| 160 |
|
| 161 |
/////////////////////////////////////////////////////////////////////////// |
159 |
/////////////////////////////////////////////////////////////////////////// |
| 162 |
// IMemory |
160 |
// IMemory |
| 163 |
/////////////////////////////////////////////////////////////////////////// |
161 |
/////////////////////////////////////////////////////////////////////////// |
|
Lines 279-284
Link Here
|
| 279 |
fMemoryCache.setMemory(memoryDMC, address, offset, word_size, count * length, buffer, rm); |
277 |
fMemoryCache.setMemory(memoryDMC, address, offset, word_size, count * length, buffer, rm); |
| 280 |
} |
278 |
} |
| 281 |
|
279 |
|
|
|
280 |
/////////////////////////////////////////////////////////////////////// |
| 281 |
// Back-end functions |
| 282 |
/////////////////////////////////////////////////////////////////////// |
| 283 |
|
| 284 |
/** |
| 285 |
* @param memoryDMC |
| 286 |
* @param address |
| 287 |
* @param offset |
| 288 |
* @param word_size |
| 289 |
* @param count |
| 290 |
* @param drm |
| 291 |
* |
| 292 |
* @since 1.1 |
| 293 |
*/ |
| 294 |
protected void readMemoryBlock(IDMContext dmc, IAddress address, final long offset, |
| 295 |
final int word_size, final int count, final DataRequestMonitor<MemoryByte[]> drm) |
| 296 |
{ |
| 297 |
/* To simplify the parsing of the MI result, we request the output to |
| 298 |
* be on 1 row of [count] columns, no char interpretation. |
| 299 |
*/ |
| 300 |
int mode = MIFormat.HEXADECIMAL; |
| 301 |
int nb_rows = 1; |
| 302 |
int nb_cols = count; |
| 303 |
Character asChar = null; |
| 304 |
|
| 305 |
fCommandCache.execute( |
| 306 |
new MIDataReadMemory(dmc, offset, address.toString(), mode, word_size, nb_rows, nb_cols, asChar), |
| 307 |
new DataRequestMonitor<MIDataReadMemoryInfo>(getExecutor(), drm) { |
| 308 |
@Override |
| 309 |
protected void handleSuccess() { |
| 310 |
// Retrieve the memory block |
| 311 |
drm.setData(getData().getMIMemoryBlock()); |
| 312 |
drm.done(); |
| 313 |
} |
| 314 |
@Override |
| 315 |
protected void handleFailure() { |
| 316 |
// Bug234289: If memory read fails, return a block marked as invalid |
| 317 |
MemoryByte[] block = new MemoryByte[word_size * count]; |
| 318 |
for (int i = 0; i < block.length; i++) |
| 319 |
block[i] = new MemoryByte((byte) 0, (byte) 0); |
| 320 |
drm.setData(block); |
| 321 |
drm.done(); |
| 322 |
} |
| 323 |
} |
| 324 |
); |
| 325 |
} |
| 326 |
|
| 327 |
/** |
| 328 |
* @param memoryDMC |
| 329 |
* @param address |
| 330 |
* @param offset |
| 331 |
* @param word_size |
| 332 |
* @param count |
| 333 |
* @param buffer |
| 334 |
* @param rm |
| 335 |
* |
| 336 |
* @since 1.1 |
| 337 |
*/ |
| 338 |
protected void writeMemoryBlock(final IDMContext dmc, final IAddress address, final long offset, |
| 339 |
final int word_size, final int count, final byte[] buffer, final RequestMonitor rm) |
| 340 |
{ |
| 341 |
// Each byte is written individually (GDB power...) |
| 342 |
// so we need to keep track of the count |
| 343 |
final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm); |
| 344 |
countingRM.setDoneCount(count); |
| 345 |
|
| 346 |
// We will format the individual bytes in decimal |
| 347 |
int format = MIFormat.DECIMAL; |
| 348 |
String baseAddress = address.toString(); |
| 349 |
|
| 350 |
// Issue an MI request for each byte to write |
| 351 |
for (int i = 0; i < count; i++) { |
| 352 |
String value = new Byte(buffer[i]).toString(); |
| 353 |
fCommandCache.execute( |
| 354 |
new MIDataWriteMemory(dmc, offset + i, baseAddress, format, word_size, value), |
| 355 |
new DataRequestMonitor<MIDataWriteMemoryInfo>(getExecutor(), countingRM) |
| 356 |
); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 282 |
////////////////////////////////////////////////////////////////////////// |
360 |
////////////////////////////////////////////////////////////////////////// |
| 283 |
// Event handlers |
361 |
// Event handlers |
| 284 |
////////////////////////////////////////////////////////////////////////// |
362 |
////////////////////////////////////////////////////////////////////////// |
|
Lines 290-299
Link Here
|
| 290 |
@DsfServiceEventHandler |
368 |
@DsfServiceEventHandler |
| 291 |
public void eventDispatched(IResumedDMEvent e) { |
369 |
public void eventDispatched(IResumedDMEvent e) { |
| 292 |
if (e instanceof IContainerResumedDMEvent) { |
370 |
if (e instanceof IContainerResumedDMEvent) { |
| 293 |
fMemoryCache.setTargetAvailable(e.getDMContext(), false); |
371 |
fCommandCache.setContextAvailable(e.getDMContext(), false); |
| 294 |
} |
372 |
} |
| 295 |
|
373 |
|
| 296 |
if (e.getReason() != StateChangeReason.STEP) { |
374 |
if (e.getReason() != StateChangeReason.STEP) { |
|
|
375 |
fCommandCache.reset(); |
| 297 |
fMemoryCache.reset(); |
376 |
fMemoryCache.reset(); |
| 298 |
} |
377 |
} |
| 299 |
} |
378 |
} |
|
Lines 305-312
Link Here
|
| 305 |
@DsfServiceEventHandler |
384 |
@DsfServiceEventHandler |
| 306 |
public void eventDispatched(ISuspendedDMEvent e) { |
385 |
public void eventDispatched(ISuspendedDMEvent e) { |
| 307 |
if (e instanceof IContainerSuspendedDMEvent) { |
386 |
if (e instanceof IContainerSuspendedDMEvent) { |
| 308 |
fMemoryCache.setTargetAvailable(e.getDMContext(), true); |
387 |
fCommandCache.setContextAvailable(e.getDMContext(), true); |
| 309 |
} |
388 |
} |
|
|
389 |
fCommandCache.reset(); |
| 310 |
fMemoryCache.reset(); |
390 |
fMemoryCache.reset(); |
| 311 |
} |
391 |
} |
| 312 |
|
392 |
|
|
Lines 449-491
Link Here
|
| 449 |
// MIMemoryCache |
529 |
// MIMemoryCache |
| 450 |
/////////////////////////////////////////////////////////////////////////// |
530 |
/////////////////////////////////////////////////////////////////////////// |
| 451 |
|
531 |
|
| 452 |
/** |
532 |
private class MIMemoryCache { |
| 453 |
* This class can now be overridden. |
|
|
| 454 |
* |
| 455 |
* @since 1.1 |
| 456 |
*/ |
| 457 |
protected class MIMemoryCache { |
| 458 |
|
| 459 |
// Back-end commands cache |
| 460 |
private CommandCache fCommandCache; |
| 461 |
|
| 462 |
// The memory cache data structure |
533 |
// The memory cache data structure |
| 463 |
private SortedMemoryBlockList fMemoryBlockList; |
534 |
private SortedMemoryBlockList fMemoryBlockList; |
| 464 |
|
535 |
|
| 465 |
public MIMemoryCache() { |
536 |
public MIMemoryCache() { |
| 466 |
// Create the command cache |
|
|
| 467 |
ICommandControlService commandControl = getServicesTracker().getService(ICommandControlService.class); |
| 468 |
fCommandCache = new CommandCache(getSession(), commandControl); |
| 469 |
fCommandCache.setContextAvailable(commandControl.getContext(), true); |
| 470 |
|
| 471 |
// Create the memory block cache |
537 |
// Create the memory block cache |
| 472 |
fMemoryBlockList = new SortedMemoryBlockList(); |
538 |
fMemoryBlockList = new SortedMemoryBlockList(); |
| 473 |
} |
539 |
} |
| 474 |
|
540 |
|
| 475 |
public void reset() { |
541 |
public void reset() { |
| 476 |
// Clear the command cache |
|
|
| 477 |
fCommandCache.reset(); |
| 478 |
// Clear the memory cache |
542 |
// Clear the memory cache |
| 479 |
fMemoryBlockList.clear(); |
543 |
fMemoryBlockList.clear(); |
| 480 |
} |
544 |
} |
| 481 |
|
|
|
| 482 |
public void setTargetAvailable(IDMContext dmc, boolean isAvailable) { |
| 483 |
fCommandCache.setContextAvailable(dmc, isAvailable); |
| 484 |
} |
| 485 |
|
| 486 |
public boolean isTargetAvailable(IDMContext dmc) { |
| 487 |
return fCommandCache.isTargetAvailable(dmc); |
| 488 |
} |
| 489 |
|
545 |
|
| 490 |
/** |
546 |
/** |
| 491 |
* This function walks the address-sorted memory block list to identify |
547 |
* This function walks the address-sorted memory block list to identify |
|
Lines 849-931
Link Here
|
| 849 |
} |
905 |
} |
| 850 |
}); |
906 |
}); |
| 851 |
} |
907 |
} |
| 852 |
|
|
|
| 853 |
/////////////////////////////////////////////////////////////////////// |
| 854 |
// Back-end functions |
| 855 |
/////////////////////////////////////////////////////////////////////// |
| 856 |
|
| 857 |
/** |
| 858 |
* @param memoryDMC |
| 859 |
* @param address |
| 860 |
* @param offset |
| 861 |
* @param word_size |
| 862 |
* @param count |
| 863 |
* @param drm |
| 864 |
*/ |
| 865 |
protected void readMemoryBlock(IDMContext dmc, IAddress address, final long offset, |
| 866 |
final int word_size, final int count, final DataRequestMonitor<MemoryByte[]> drm) |
| 867 |
{ |
| 868 |
/* To simplify the parsing of the MI result, we request the output to |
| 869 |
* be on 1 row of [count] columns, no char interpretation. |
| 870 |
*/ |
| 871 |
int mode = MIFormat.HEXADECIMAL; |
| 872 |
int nb_rows = 1; |
| 873 |
int nb_cols = count; |
| 874 |
Character asChar = null; |
| 875 |
|
| 876 |
fCommandCache.execute( |
| 877 |
new MIDataReadMemory(dmc, offset, address.toString(), mode, word_size, nb_rows, nb_cols, asChar), |
| 878 |
new DataRequestMonitor<MIDataReadMemoryInfo>(getExecutor(), drm) { |
| 879 |
@Override |
| 880 |
protected void handleSuccess() { |
| 881 |
// Retrieve the memory block |
| 882 |
drm.setData(getData().getMIMemoryBlock()); |
| 883 |
drm.done(); |
| 884 |
} |
| 885 |
@Override |
| 886 |
protected void handleFailure() { |
| 887 |
// Bug234289: If memory read fails, return a block marked as invalid |
| 888 |
MemoryByte[] block = new MemoryByte[word_size * count]; |
| 889 |
for (int i = 0; i < block.length; i++) |
| 890 |
block[i] = new MemoryByte((byte) 0, (byte) 0); |
| 891 |
drm.setData(block); |
| 892 |
drm.done(); |
| 893 |
} |
| 894 |
} |
| 895 |
); |
| 896 |
} |
| 897 |
|
| 898 |
/** |
| 899 |
* @param memoryDMC |
| 900 |
* @param address |
| 901 |
* @param offset |
| 902 |
* @param word_size |
| 903 |
* @param count |
| 904 |
* @param buffer |
| 905 |
* @param rm |
| 906 |
*/ |
| 907 |
protected void writeMemoryBlock(final IDMContext dmc, final IAddress address, final long offset, |
| 908 |
final int word_size, final int count, final byte[] buffer, final RequestMonitor rm) |
| 909 |
{ |
| 910 |
// Each byte is written individually (GDB power...) |
| 911 |
// so we need to keep track of the count |
| 912 |
final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm); |
| 913 |
countingRM.setDoneCount(count); |
| 914 |
|
| 915 |
// We will format the individual bytes in decimal |
| 916 |
int format = MIFormat.DECIMAL; |
| 917 |
String baseAddress = address.toString(); |
| 918 |
|
| 919 |
// Issue an MI request for each byte to write |
| 920 |
for (int i = 0; i < count; i++) { |
| 921 |
String value = new Byte(buffer[i]).toString(); |
| 922 |
fCommandCache.execute( |
| 923 |
new MIDataWriteMemory(dmc, offset + i, baseAddress, format, word_size, value), |
| 924 |
new DataRequestMonitor<MIDataWriteMemoryInfo>(getExecutor(), countingRM) |
| 925 |
); |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
} |
908 |
} |
| 930 |
|
909 |
|
| 931 |
/** |
910 |
/** |
|
Lines 933-938
Link Here
|
| 933 |
* @since 1.1 |
912 |
* @since 1.1 |
| 934 |
*/ |
913 |
*/ |
| 935 |
public void flushCache(IDMContext context) { |
914 |
public void flushCache(IDMContext context) { |
|
|
915 |
fCommandCache.reset(); |
| 936 |
fMemoryCache.reset(); |
916 |
fMemoryCache.reset(); |
| 937 |
} |
917 |
} |
| 938 |
} |
918 |
} |