From 4b0c9bd6cef05da8c6b39375fcfd182f03b461ef Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Mon, 3 May 2010 15:20:05 +0000 Subject: [PATCH] Bug 311210 - [commands][cdi] Missing support for "target-download". --- .../mi/service/command/CommandFactory.java | 10 ++ .../command/commands/MITargetDownload.java | 41 ++++++ .../command/output/MITargetDownloadInfo.java | 135 ++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetDownload.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITargetDownloadInfo.java diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java index 36173f62211..2e84d04338a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java @@ -98,6 +98,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIStackListLocals; import org.eclipse.cdt.dsf.mi.service.command.commands.MIStackSelectFrame; import org.eclipse.cdt.dsf.mi.service.command.commands.MITargetAttach; import org.eclipse.cdt.dsf.mi.service.command.commands.MITargetDetach; +import org.eclipse.cdt.dsf.mi.service.command.commands.MITargetDownload; import org.eclipse.cdt.dsf.mi.service.command.commands.MITargetSelect; import org.eclipse.cdt.dsf.mi.service.command.commands.MITargetSelectCore; import org.eclipse.cdt.dsf.mi.service.command.commands.MITargetSelectTFile; @@ -144,6 +145,7 @@ import org.eclipse.cdt.dsf.mi.service.command.output.MIStackInfoDepthInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIStackListArgumentsInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIStackListFramesInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIStackListLocalsInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MITargetDownloadInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIThreadInfoInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIThreadListIdsInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MITraceFindInfo; @@ -639,6 +641,14 @@ public class CommandFactory { return new MITargetSelectTFile(ctx, traceFilePath); } + public ICommand createMITargetDownload(ICommandControlDMContext ctx) { + return new MITargetDownload(ctx); + } + + public ICommand createMITargetDownload(ICommandControlDMContext ctx, String file) { + return new MITargetDownload(ctx, file); + } + public ICommand createMIThreadInfo(ICommandControlDMContext dmc) { return new MIThreadInfo(dmc); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetDownload.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetDownload.java new file mode 100644 index 00000000000..d641265d8c4 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetDownload.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2010 CodeSourcery 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: + * CodeSourcery - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.mi.service.command.commands; + +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MITargetDownloadInfo; + +/** + * This command downloads a file to a remote target. + * + * @since 3.0 + */ +public class MITargetDownload extends MICommand { + + public MITargetDownload(ICommandControlDMContext ctx) { + super(ctx, "-target-download"); //$NON-NLS-1$ + } + + public MITargetDownload(ICommandControlDMContext ctx, String file) { + super(ctx, "-target-download", null, new String[] { file }); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.dsf.mi.service.command.commands.MICommand#getResult(org.eclipse.cdt.dsf.mi.service.command.output.MIOutput) + */ + @Override + public MIInfo getResult( MIOutput MIresult ) { + return new MITargetDownloadInfo( MIresult ); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITargetDownloadInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITargetDownloadInfo.java new file mode 100644 index 00000000000..f11f53456da --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITargetDownloadInfo.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2010 CodeSourcery 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: + * CodeSourcery - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.mi.service.command.output; + +/** + * Parsing of GDB/MI "target-download" + * + * Example: + * -target-download + * +download,{section=".text",section-size="6668",total-size="9880"} + * +download,{section=".text",section-sent="512",section-size="6668", + * total-sent="512",total-size="9880"} + * +download,{section=".text",section-sent="1024",section-size="6668", + * total-sent="1024",total-size="9880"} + * +download,{section=".text",section-sent="1536",section-size="6668", + * total-sent="1536",total-size="9880"} + * +download,{section=".text",section-sent="2048",section-size="6668", + * total-sent="2048",total-size="9880"} + * +download,{section=".text",section-sent="2560",section-size="6668", + * total-sent="2560",total-size="9880"} + * +download,{section=".text",section-sent="3072",section-size="6668", + * total-sent="3072",total-size="9880"} + * +download,{section=".text",section-sent="3584",section-size="6668", + * total-sent="3584",total-size="9880"} + * +download,{section=".text",section-sent="4096",section-size="6668", + * total-sent="4096",total-size="9880"} + * +download,{section=".text",section-sent="4608",section-size="6668", + * total-sent="4608",total-size="9880"} + * +download,{section=".text",section-sent="5120",section-size="6668", + * total-sent="5120",total-size="9880"} + * +download,{section=".text",section-sent="5632",section-size="6668", + * total-sent="5632",total-size="9880"} + * +download,{section=".text",section-sent="6144",section-size="6668", + * total-sent="6144",total-size="9880"} + * +download,{section=".text",section-sent="6656",section-size="6668", + * total-sent="6656",total-size="9880"} + * +download,{section=".init",section-size="28",total-size="9880"} + * +download,{section=".fini",section-size="28",total-size="9880"} + * +download,{section=".data",section-size="3156",total-size="9880"} + * +download,{section=".data",section-sent="512",section-size="3156", + * total-sent="7236",total-size="9880"} + * +download,{section=".data",section-sent="1024",section-size="3156", + * total-sent="7748",total-size="9880"} + * +download,{section=".data",section-sent="1536",section-size="3156", + * total-sent="8260",total-size="9880"} + * +download,{section=".data",section-sent="2048",section-size="3156", + * total-sent="8772",total-size="9880"} + * +download,{section=".data",section-sent="2560",section-size="3156", + * total-sent="9284",total-size="9880"} + * +download,{section=".data",section-sent="3072",section-size="3156", + * total-sent="9796",total-size="9880"} + * ^done,address="0x10004",load-size="9880",transfer-rate="6586", + * write-rate="429" + * + * @since 3.0 + */ +public class MITargetDownloadInfo extends MIInfo { + + private String fAddress = ""; //$NON-NLS-1$ + private long fLoadSize = 0; + private long fTransferRate = 0; + private long fWriteRate = 0; + + public MITargetDownloadInfo( MIOutput record ) { + super( record ); + parse(); + } + + public String getAddress() { + return fAddress; + } + + public long getLoadSize() { + return fLoadSize; + } + + public long getTransferRate() { + return fTransferRate; + } + + public long getWriteRate() { + return fWriteRate; + } + + private void parse() { + if ( isDone() ) { + MIOutput out = getMIOutput(); + MIResultRecord rr = out.getMIResultRecord(); + if ( rr != null ) { + MIResult[] results = rr.getMIResults(); + for( int i = 0; i < results.length; i++ ) { + String var = results[i].getVariable(); + MIValue value = results[i].getMIValue(); + String str = ""; //$NON-NLS-1$ + if ( value != null && value instanceof MIConst ) { + str = ((MIConst)value).getCString().trim(); + } + if ( var.equals( "address" ) ) { //$NON-NLS-1$ + fAddress = str; + } + else if ( var.equals( "load-size" ) ) { //$NON-NLS-1$ + try { + fLoadSize = Long.parseLong( str ); + } + catch( NumberFormatException e ) { + } + } + else if ( var.equals( "transfer-rate" ) ) { //$NON-NLS-1$ + try { + fTransferRate = Long.parseLong( str ); + } + catch( NumberFormatException e ) { + } + } + else if ( var.equals( "write-rate" ) ) { //$NON-NLS-1$ + try { + fWriteRate = Long.parseLong( str ); + } + catch( NumberFormatException e ) { + } + } + } + } + } + } +}