1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 387793: Support for -data-write-memory-bytes

Change-Id: Ib3cc9d376a9e69176fff9eeeba58bcd68352a141
Reviewed-on: https://git.eclipse.org/r/7448
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
John Dallaway 2012-09-21 15:36:05 +01:00 committed by Marc Khouzam
parent ed5dbf2683
commit 285434b5e0
3 changed files with 86 additions and 14 deletions

View file

@ -11,9 +11,11 @@
* Ericsson AB - added support for event handling * Ericsson AB - added support for event handling
* Ericsson AB - added memory cache * Ericsson AB - added memory cache
* Vladimir Prus (CodeSourcery) - support for -data-read-memory-bytes (bug 322658) * Vladimir Prus (CodeSourcery) - support for -data-read-memory-bytes (bug 322658)
* John Dallaway - support for -data-write-memory-bytes (bug 387793)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.mi.service; package org.eclipse.cdt.dsf.mi.service;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.LinkedList; import java.util.LinkedList;
@ -48,6 +50,7 @@ import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
import org.eclipse.cdt.dsf.mi.service.command.output.MIDataReadMemoryBytesInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIDataReadMemoryBytesInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIDataReadMemoryInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIDataReadMemoryInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIDataWriteMemoryInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIDataWriteMemoryInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
import org.eclipse.cdt.dsf.service.AbstractDsfService; import org.eclipse.cdt.dsf.service.AbstractDsfService;
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
import org.eclipse.cdt.dsf.service.DsfSession; import org.eclipse.cdt.dsf.service.DsfSession;
@ -400,22 +403,31 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
protected void writeMemoryBlock(final IDMContext dmc, final IAddress address, final long offset, protected void writeMemoryBlock(final IDMContext dmc, final IAddress address, final long offset,
final int word_size, final int count, final byte[] buffer, final RequestMonitor rm) final int word_size, final int count, final byte[] buffer, final RequestMonitor rm)
{ {
// Each byte is written individually (GDB power...) if (fDataReadMemoryBytes) {
// so we need to keep track of the count // Use -data-write-memory-bytes for performance
final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm);
countingRM.setDoneCount(count);
// We will format the individual bytes in decimal
int format = MIFormat.DECIMAL;
String baseAddress = address.toString();
// Issue an MI request for each byte to write
for (int i = 0; i < count; i++) {
String value = new Byte(buffer[i]).toString();
fCommandCache.execute( fCommandCache.execute(
fCommandFactory.createMIDataWriteMemory(dmc, offset + i, baseAddress, format, word_size, value), fCommandFactory.createMIDataWriteMemoryBytes(dmc, address.add(offset).toString(),
new DataRequestMonitor<MIDataWriteMemoryInfo>(getExecutor(), countingRM) (buffer.length == count) ? buffer : Arrays.copyOf(buffer, count)),
new DataRequestMonitor<MIInfo>(getExecutor(), rm)
); );
} else {
// Each byte is written individually (GDB power...)
// so we need to keep track of the count
final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm);
countingRM.setDoneCount(count);
// We will format the individual bytes in decimal
int format = MIFormat.DECIMAL;
String baseAddress = address.toString();
// Issue an MI request for each byte to write
for (int i = 0; i < count; i++) {
String value = new Byte(buffer[i]).toString();
fCommandCache.execute(
fCommandFactory.createMIDataWriteMemory(dmc, offset + i, baseAddress, format, word_size, value),
new DataRequestMonitor<MIDataWriteMemoryInfo>(getExecutor(), countingRM)
);
}
} }
} }

View file

@ -19,6 +19,7 @@
* Mathias Kunter - New methods for handling different charsets (Bug 370462) * Mathias Kunter - New methods for handling different charsets (Bug 370462)
* Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536) * Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536)
* Vladimir Prus (Mentor Graphics) - Support for -info-os (Bug 360314) * Vladimir Prus (Mentor Graphics) - Support for -info-os (Bug 360314)
* John Dallaway - Support for -data-write-memory-bytes (Bug 387793)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command; package org.eclipse.cdt.dsf.mi.service.command;
@ -73,6 +74,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataListRegisterValues;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataReadMemory; import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataReadMemory;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataReadMemoryBytes; import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataReadMemoryBytes;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataWriteMemory; import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataWriteMemory;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIDataWriteMemoryBytes;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIEnablePrettyPrinting; import org.eclipse.cdt.dsf.mi.service.command.commands.MIEnablePrettyPrinting;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIEnvironmentCD; import org.eclipse.cdt.dsf.mi.service.command.commands.MIEnvironmentCD;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIEnvironmentDirectory; import org.eclipse.cdt.dsf.mi.service.command.commands.MIEnvironmentDirectory;
@ -430,6 +432,11 @@ public class CommandFactory {
return new MIDataWriteMemory(ctx, offset, address, wordFormat, wordSize, value); return new MIDataWriteMemory(ctx, offset, address, wordFormat, wordSize, value);
} }
/** @since 4.2 */
public ICommand<MIInfo> createMIDataWriteMemoryBytes(IDMContext ctx, String address, byte[] contents) {
return new MIDataWriteMemoryBytes(ctx, address, contents);
}
/** @since 4.0 */ /** @since 4.0 */
public ICommand<MIInfo> createMIEnablePrettyPrinting(ICommandControlDMContext ctx) { public ICommand<MIInfo> createMIEnablePrettyPrinting(ICommandControlDMContext ctx) {
return new MIEnablePrettyPrinting(ctx); return new MIEnablePrettyPrinting(ctx);

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2012 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Dallaway - MIDataWriteMemoryBytes based on MIDataWriteMemory (bug 387793)
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.commands;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
/**
* -data-write-memory-bytes ADDRESS CONTENTS
*
* where:
*
* 'ADDRESS'
* An expression specifying the address of the first memory word to be
* written. Complex expressions containing embedded white space should
* be quoted using the C convention.
*
* 'CONTENTS'
* The hex-encoded bytes to write.
* @since 4.2
*/
public class MIDataWriteMemoryBytes extends MICommand<MIInfo> {
public MIDataWriteMemoryBytes(
IDMContext ctx,
String address,
byte[] contents)
{
super(ctx, "-data-write-memory-bytes"); //$NON-NLS-1$
// performance-oriented conversion of byte[] to hex string
final char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char[] hex = new char[contents.length * 2];
for (int n = 0; n < contents.length; n++) {
final int val = contents[n] & 0xFF;
hex[n*2] = digits[val >>> 4];
hex[n*2 + 1] = digits[val & 0x0F];
}
setParameters(
new String[] {
address,
new String(hex)});
}
}