From 54ef22fda292d401f9e1935d08a7df3d1ed4f0ba Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 1 Feb 2011 20:30:32 +0000 Subject: [PATCH] Bug 336013: [launch] Environment variables that contain a space are not properly set at launch time --- .../service/command/commands/MIGDBSetEnv.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetEnv.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetEnv.java index 5b5254777b1..7c7acc155c2 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetEnv.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetEnv.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Ericsson and others. + * Copyright (c) 2010, 2011 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 @@ -32,6 +32,28 @@ public class MIGDBSetEnv extends MIGDBSet } public MIGDBSetEnv(ICommandControlDMContext dmc, String name, String value) { - super(dmc, new String[] { "env", name + (value != null && value.length() > 0 ? "=" + value : "")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } -} \ No newline at end of file + // We need to avoid putting "" around the variable. + // -gdb-set env "MYVAR=MY VAR" + // will not set MYVAR to MY VAR, but instead will create an empty variable with name "MYVAR=MY VAR" + // This is because "" are automatically inserted if there is a space in the parameter. + // What we really want to send is: + // -gdb-set env MYVAR=MY VAR + // To achieve that, we split the value into separate parameters + super(dmc, null); + + if (value == null || value.length() == 0) { + setParameters(new String[] { "env", name }); //$NON-NLS-1$ + } else { + String[] splitValue = value.split(" "); //$NON-NLS-1$ + String[] params = new String[splitValue.length+3]; + params[0] = "env"; //$NON-NLS-1$ + params[1] = name; + params[2] = "="; //$NON-NLS-1$ + for (int i=3; i