Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 336013 - [launch] Environment variables that contain a space are not properly set at launch time
Summary: [launch] Environment variables that contain a space are not properly set at l...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 7.0.2   Edit
Assignee: Marc Khouzam CLA
QA Contact: Marc Khouzam CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-01 15:27 EST by Marc Khouzam CLA
Modified: 2011-02-01 21:23 EST (History)
3 users (show)

See Also:
marc.khouzam: review?


Attachments
Fix (1.88 KB, patch)
2011-02-01 15:28 EST, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Khouzam CLA 2011-02-01 15:27:39 EST
When we send the 
  -gdb-set env
command 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".  What we really want to send is:
  -gdb-set env MYVAR=MY VAR
  
Quotes are automatically being added by MICommand when there is a space in the parameter.  To fix that, we can treat each entry in the variable value as a separate parameter.

Note that GDB does not accept env variable with a space in the name, so we don't need to worry about that.
Comment 1 Marc Khouzam CLA 2011-02-01 15:28:16 EST
Created attachment 188081 [details]
Fix

Fix
Comment 2 Marc Khouzam CLA 2011-02-01 16:01:24 EST
Committed to HEAD and 7_0

John, can you review (one-file patch)?
Comment 4 John Cortell CLA 2011-02-01 16:46:05 EST
The fix looks good but I think the explanation in the code is a bit confusing. Here's how I would phrase it:

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
Comment 5 Marc Khouzam CLA 2011-02-01 21:15:10 EST
(In reply to comment #4)
> The fix looks good but I think the explanation in the code is a bit confusing.
> Here's how I would phrase it:
> 
> 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

Yes, that's better.  Thanks.
I updated HEAD.
(I didn't bother with 7_0 since that code is not going to be maintained for much longer).
Comment 6 CDT Genie CLA 2011-02-01 21:23:01 EST
*** cdt cvs genie on behalf of mkhouzam ***
Bug 336013: [launch] Environment variables that contain a space are not properly set at launch time

[*] MIGDBSetEnv.java 1.3 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetEnv.java?root=Tools_Project&r1=1.2&r2=1.3