Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336013

Summary: [launch] Environment variables that contain a space are not properly set at launch time
Product: [Tools] CDT Reporter: Marc Khouzam <marc.khouzam>
Component: cdt-debug-dsf-gdbAssignee: Marc Khouzam <marc.khouzam>
Status: RESOLVED FIXED QA Contact: Marc Khouzam <marc.khouzam>
Severity: normal    
Priority: P3 CC: cdtdoug, john.cortell, pawel.1.piech
Version: 8.0Flags: marc.khouzam: review?
Target Milestone: 7.0.2   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Fix marc.khouzam: iplog-

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