diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/tests/AllTests.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/tests/AllTests.java index 451dd8eaece..9bcdeff4be6 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/tests/AllTests.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/tests/AllTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 Ericsson AB and others. + * Copyright (c) 2014, 2016 Ericsson AB 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 @@ -12,6 +12,7 @@ package org.eclipse.cdt.dsf.gdb.tests; import org.eclipse.cdt.dsf.mi.service.command.commands.TestMIBreakInsertCommand; import org.eclipse.cdt.dsf.mi.service.command.commands.TestMICommandConstructCommand; +import org.eclipse.cdt.dsf.mi.service.command.commands.TestMIGDBSetSysroot; import org.eclipse.cdt.dsf.mi.service.command.output.MIStringHandlerTests; import org.eclipse.cdt.dsf.mi.service.command.output.MIThreadTests; import org.junit.runner.RunWith; @@ -24,6 +25,7 @@ import org.junit.runners.Suite.SuiteClasses; @SuiteClasses({MIThreadTests.class, TestMIBreakInsertCommand.class, TestMICommandConstructCommand.class, + TestMIGDBSetSysroot.class, LaunchUtilsTest.class, MIStringHandlerTests.class, ProcStatParserTest.class, diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java new file mode 100644 index 00000000000..2de9908980d --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2016 Ingenico. + * 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: + * Ingenico - Sysroot with spaces (Bug 497693) + *******************************************************************************/ +package org.eclipse.cdt.dsf.mi.service.command.commands; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor; +import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; +import org.eclipse.cdt.dsf.gdb.service.command.GDBControlDMContext; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.junit.Test; + +/** + * Verifies that the set sysroot MI command don't add double quotes if path contains space. + * + */ +public class TestMIGDBSetSysroot { + + @Test + public void pathWithSpaceShouldNotBe() { + MIGDBSetSysroot setSysrootCommand = new MIGDBSetSysroot(new TestContext(), "/tmp/test with space/"); + assertEquals("Wrong syntax for command", "-gdb-set sysroot /tmp/test with space/\n", + setSysrootCommand.constructCommand()); + } + + @Test + public void pathWithDoubleQuotesShouldNotBe() { + MIGDBSetSysroot setSysrootCommand = new MIGDBSetSysroot(new TestContext(), "/tmp/test with\"double quotes/"); + assertEquals("Wrong syntax for command", "-gdb-set sysroot /tmp/test with\"double quotes/\n", + setSysrootCommand.constructCommand()); + + + } + + private class TestContext implements ICommandControlDMContext { + private DsfSession session = null; + + public TestContext() { + session = DsfSession.startSession(new DefaultDsfExecutor(GdbPlugin.PLUGIN_ID), GdbPlugin.PLUGIN_ID); + } + + @Override + public IDMContext[] getParents() { + return new IDMContext[] { new GDBControlDMContext(getSessionId(), "1") }; + } + + @Override + public String getSessionId() { + return session.getId(); + } + + @Override + public T getAdapter(Class adapter) { + return null; + } + + @Override + public String getCommandControlId() { + return null; + } + } + +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIBreakCondition.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIBreakCondition.java index 9a3d642c957..c2436365418 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIBreakCondition.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIBreakCondition.java @@ -15,48 +15,32 @@ import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContex import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; /** - * + * * -break-condition NUMBER EXPR - * + * * Breakpoint NUMBER will stop the program only if the condition in * EXPR is true. The condition becomes part of the `-break-list' output * (see the description of the DsfMIBreakList). */ - + public class MIBreakCondition extends MICommand { - /* - * MICommand wraps a parameter with double quotes if it contains a space. + /* + * MICommand wraps a parameter with double quotes if it contains a space. * However, GDB does not want quotes around a condition. * To avoid the double quotes, we create our own adjustable parameter. * It is important to send the breakpoint and condition as parameters because * MI can insert flags such as --thread-group between the command and the * parameters. If we make the entire output be the command, then the * --thread-group flag will end up at the end, and the syntax will not be valid. - * + * * See bug 213076 for more information. - */ + */ /** @since 5.0 */ public MIBreakCondition(IBreakpointsTargetDMContext ctx, String breakpoint, String condition) { super(ctx, "-break-condition"); //$NON-NLS-1$ - + setParameters(new Adjustable[]{ new MIStandardParameterAdjustable(breakpoint), - new NoChangeAdjustable(condition) }); + new MINoChangeAdjustable(condition) }); } - - /** - * This adjustable makes sure that the condition parameter will not get surrounded - * by double quotes. We simply send the condition exactly as specified - */ - private class NoChangeAdjustable extends MICommandAdjustable { - - public NoChangeAdjustable(String param) { - super(param); - } - - @Override - public String getAdjustedValue() { - return getValue(); - } - } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MICommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MICommand.java index e92cae51d6e..fbb2fcaf284 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MICommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MICommand.java @@ -10,12 +10,16 @@ * Wind River Systems - Modified for new DSF Reference Implementation * Ericsson - Modified for additional features in DSF Reference implementation and bug 219920 * Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306) + * Ingenico - Sysroot with spaces (Bug 497693) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.commands; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; @@ -34,6 +38,7 @@ public class MICommand implements ICommand { List fOptions = new ArrayList<>(); List fParameters = new ArrayList<>(); String fOperation = ""; //$NON-NLS-1$ + Function fParamToAdjustable; IDMContext fCtx; /* @@ -49,13 +54,22 @@ public class MICommand implements ICommand { } public MICommand(IDMContext ctx, String operation, String[] options, String[] params) { - assert(ctx != null && DMContexts.getAncestorOfType(ctx, MIControlDMContext.class) != null); - fCtx = ctx; - fOperation = operation; - fOptions = optionsToAdjustables(options); - fParameters = parametersToAdjustables(params); + this(ctx, operation, options, params, null); } + /** + * @since 5.2 + */ + public MICommand(IDMContext ctx, String operation, String[] options, String[] params, + Function paramToAdjustable) { + assert (ctx != null && DMContexts.getAncestorOfType(ctx, MIControlDMContext.class) != null); + fCtx = ctx; + fOperation = operation; + fOptions = optionsToAdjustables(options); + fParamToAdjustable = paramToAdjustable == null ? x -> new MIStandardParameterAdjustable(x) : paramToAdjustable; + fParameters = parametersToAdjustables(params); + } + private final List optionsToAdjustables(String[] options) { List result = new ArrayList<>(); if (options != null) { @@ -67,13 +81,8 @@ public class MICommand implements ICommand { } private final List parametersToAdjustables(String[] parameters) { - List result = new ArrayList<>(); - if (parameters != null) { - for (String parameter : parameters) { - result.add(new MIStandardParameterAdjustable(parameter)); - } - } - return result; + return parameters != null ? Arrays.stream(parameters).map(fParamToAdjustable).collect(Collectors.toList()) + : Collections.emptyList(); } public String getCommandControlFilter() { @@ -352,6 +361,21 @@ public class MICommand implements ICommand { } } + /** + * @since 5.2 + */ + public static class MINoChangeAdjustable extends MICommandAdjustable { + + public MINoChangeAdjustable(String param) { + super(param); + } + + @Override + public String getAdjustedValue() { + return getValue(); + } + } + public static abstract class MICommandAdjustable implements Adjustable { protected final String value; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSet.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSet.java index 8da8d5d9422..1b9f8ab3e40 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSet.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSet.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Ericsson and others. + * Copyright (c) 2008, 2016 Ericsson 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 @@ -7,9 +7,12 @@ * * Contributors: * Ericsson - Initial API and implementation + * Ingenico - Sysroot with spaces (Bug 497693) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.commands; +import java.util.function.Function; + import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; @@ -23,4 +26,11 @@ public class MIGDBSet extends MICommand public MIGDBSet(IDMContext ctx, String[] params) { super(ctx, "-gdb-set", null, params); //$NON-NLS-1$ } + + /** + * @since 5.2 + */ + public MIGDBSet(IDMContext ctx, String[] params, Function paramToAdjustable) { + super(ctx, "-gdb-set", null, params, paramToAdjustable); //$NON-NLS-1$ + } } \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSolibAbsolutePrefix.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSolibAbsolutePrefix.java index d7be37ae4f8..db370fc2b1c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSolibAbsolutePrefix.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSolibAbsolutePrefix.java @@ -4,23 +4,24 @@ * 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: * Anna Dushistova (Mentor Graphics) - initial API and implementation + * Ingenico - Sysroot with spaces (Bug 497693) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.commands; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; /** - * + * * -gdb-set solib-absolute-prefix PATH * @since 4.0 - * + * */ public class MIGDBSetSolibAbsolutePrefix extends MIGDBSet { public MIGDBSetSolibAbsolutePrefix(ICommandControlDMContext ctx, String prefix) { - super(ctx, new String[] {"solib-absolute-prefix", prefix}); //$NON-NLS-1$ + super(ctx, new String[] {"solib-absolute-prefix", prefix}, x-> new MINoChangeAdjustable(x)); //$NON-NLS-1$ } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSysroot.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSysroot.java index 129d12d728d..6bdc560af6e 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSysroot.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetSysroot.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Ericsson and others. + * Copyright (c) 2008, 2016 Ericsson 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 @@ -7,25 +7,26 @@ * * Contributors: * Ericsson - Initial API and implementation + * Ingenico - Sysroot with spaces (Bug 497693) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.commands; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; /** - * + * * -gdb-set sysroot PATH * @since 1.1 - * + * */ -public class MIGDBSetSysroot extends MIGDBSet +public class MIGDBSetSysroot extends MIGDBSet { public MIGDBSetSysroot(ICommandControlDMContext ctx, String path) { - super(ctx, new String[] {"sysroot", path});//$NON-NLS-1$ + super(ctx, new String[] {"sysroot", path}, x-> new MINoChangeAdjustable(x));//$NON-NLS-1$ } - + // Using /dev/null is the recommended way to disable sysroot public MIGDBSetSysroot(ICommandControlDMContext ctx) { - this(ctx, "/dev/null"); //$NON-NLS-1$ + this(ctx, "/dev/null"); //$NON-NLS-1$ } }