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

Bug 323466

Summary: [launch][cdi]Can not use dynamic variables in DSF/GDB command
Product: [Tools] CDT Reporter: Hans-Erik Floryd <hef-cdt>
Component: cdt-debug-dsf-gdbAssignee: Marc Khouzam <marc.khouzam>
Status: RESOLVED FIXED QA Contact: Marc Khouzam <marc.khouzam>
Severity: normal    
Priority: P3 CC: aleherb+eclipse, pawel.1.piech
Version: 7.0   
Target Milestone: 8.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch to perform variable substitution marc.khouzam: iplog+

Description Hans-Erik Floryd CLA 2010-08-24 04:32:37 EDT
Build Identifier: I20100608-0911

This problem was in the CDI debugger also, but was fixed by https://bugs.eclipse.org/bugs/show_bug.cgi?id=244193

There is no variable substitution performed on the gdb command given by the
user. When sharing launch configurations, it would be useful to be able to give
the gdb command as .e.g ${GDB_PATH}/gdb so that different users can have gdb
installed in different locations, without relying on the gdb executable being
on the system PATH.

A patch is attached that calls the VariableManager to perform variable
substitution on the command. This works for eclipse dynamic variables but not
for environment variables.

Reproducible: Always
Comment 1 Hans-Erik Floryd CLA 2010-08-24 04:36:04 EDT
Created attachment 177287 [details]
Patch to perform variable substitution
Comment 2 Marc Khouzam CLA 2010-08-24 22:04:27 EDT
Looks good.

Wouldn't we want it to work with environment variables as well, or is it not the way Eclipse usually does things?
Comment 3 Hans-Erik Floryd CLA 2010-08-26 04:58:02 EDT
(In reply to comment #2)
> Wouldn't we want it to work with environment variables as well, or is it not
> the way Eclipse usually does things?

That would probably be a good thing, but I did not have time to look into how to resolve environment variables.
Comment 4 Anton Leherbauer CLA 2010-08-26 05:08:13 EDT
FYI, you can use the dynamic variable "env_var" to resolve environment variables, e.g.: ${env_var:HOME}
I am not sure, though, if this takes into account any custom environment of a launch config.
Comment 5 Marc Khouzam CLA 2010-08-26 05:24:57 EDT
(In reply to comment #4)
> FYI, you can use the dynamic variable "env_var" to resolve environment
> variables, e.g.: ${env_var:HOME}
> I am not sure, though, if this takes into account any custom environment of a
> launch config.

Nice trick!  But it does not seem to work on Windows.  I tried ${env_var:win_dir}\gdb and got the error of not being able to launch \gdb.  I'll have to try it on Linux.
Comment 6 Marc Khouzam CLA 2010-08-26 05:41:20 EDT
(In reply to comment #5)
> (In reply to comment #4)
> > FYI, you can use the dynamic variable "env_var" to resolve environment
> > variables, e.g.: ${env_var:HOME}
> > I am not sure, though, if this takes into account any custom environment of a
> > launch config.
> 
> Nice trick!  But it does not seem to work on Windows.  I tried
> ${env_var:win_dir}\gdb and got the error of not being able to launch \gdb. 
> I'll have to try it on Linux.

Sorry, it _does_ work on windows (the env var is $windir instead of $win_dir)

I think this is a good enough solution.
Thanks!
Comment 7 Marc Khouzam CLA 2010-08-26 05:49:56 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > FYI, you can use the dynamic variable "env_var" to resolve environment
> > > variables, e.g.: ${env_var:HOME}
> > > I am not sure, though, if this takes into account any custom environment of a launch config.

Oh, and no, it does not take the custom environment of a launch config, which makes sense since it is the actual launch code that has to push this updated environment to the debug session.

I committed the patch to HEAD.
Thanks Hans-Erik.
Comment 8 Marc Khouzam CLA 2010-08-26 05:50:33 EDT
Fixed
Comment 9 CDT Genie CLA 2010-08-26 06:23:04 EDT
*** cdt cvs genie on behalf of mkhouzam ***
Bug 323466: Allow for dynamic variables in gdb patch within the launch.

[*] LaunchUtils.java 1.15 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java?root=Tools_Project&r1=1.14&r2=1.15