1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 12:25:35 +02:00

Bug 497693/ Sysroot with spaces

If the sysroot path contains a space, CDT adds doubles quote to escape
the space (in MIStandardParameterAdjustable class) . But Gdb client (7.5
and 7.11) doesn’t understand the double quotes path.
This patch do not add double quotes when the path contains spaces.
Add test case.

Change-Id: I8c54fa625ce1fb1f1b9249361ca07060b56ba90c
Signed-off-by: Vincent Guignot <vincent.guignot@ingenico.com>
This commit is contained in:
Vincent Guignot 2016-08-26 15:06:35 +02:00 committed by Gerrit Code Review @ Eclipse.org
parent 2a4e3e11e4
commit 2b728ed027
7 changed files with 145 additions and 50 deletions

View file

@ -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,

View file

@ -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> T getAdapter(Class<T> adapter) {
return null;
}
@Override
public String getCommandControlId() {
return null;
}
}
}

View file

@ -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<MIInfo>
{
/*
* 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();
}
}
}

View file

@ -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<V extends MIInfo> implements ICommand<V> {
List<Adjustable> fOptions = new ArrayList<>();
List<Adjustable> fParameters = new ArrayList<>();
String fOperation = ""; //$NON-NLS-1$
Function<String, Adjustable> fParamToAdjustable;
IDMContext fCtx;
/*
@ -49,13 +54,22 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
}
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<String, Adjustable> 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<Adjustable> optionsToAdjustables(String[] options) {
List<Adjustable> result = new ArrayList<>();
if (options != null) {
@ -67,13 +81,8 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
}
private final List<Adjustable> parametersToAdjustables(String[] parameters) {
List<Adjustable> 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<V extends MIInfo> implements ICommand<V> {
}
}
/**
* @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;

View file

@ -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<MIInfo>
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<String, Adjustable> paramToAdjustable) {
super(ctx, "-gdb-set", null, params, paramToAdjustable); //$NON-NLS-1$
}
}

View file

@ -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$
}
}

View file

@ -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$
}
}