From 9c4c909ba9db15130bb5378aecc1080dc78daab3 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 2 Feb 2011 02:14:28 +0000 Subject: [PATCH] Bug 336013: [launch] Environment variables that contain a space are not properly set at launch time --- .../service/command/commands/MIGDBSetEnv.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 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 7c7acc155c2..18397a72d6d 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 @@ -32,14 +32,17 @@ public class MIGDBSetEnv extends MIGDBSet } public MIGDBSetEnv(ICommandControlDMContext dmc, String name, String value) { - // 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); + // MICommand wraps a parameter with double quotes if it contains a space. If the + // value of the environment variable has a space, and we bundle the var name, the + // '=' and the value as a single parameter, then we'll end up with something like + // + // -gdb-set env "MYVAR=MY VAR" + // + // which defines an environment variable named "MYVAR=MY VAR", with an empty + // string for a value. To avoid this, we send each element as a separate parameter + // + // -gdb-set env MYVAR = MY VAR + super(dmc, null); if (value == null || value.length() == 0) { setParameters(new String[] { "env", name }); //$NON-NLS-1$