Skip to content

Commit 2980b60

Browse files
committed
Include system environment when debugging core build
When doing a local launch, the only environment passed to the debuggee was the modified variables, typically just PATH. This meant all the other environment was lost. This change does the same thing as all the other calls to setBuildEnvironment and passes in the initial system environment. I added a small note to the API of setBuildEnvironment to try to avoid this error in the future.
1 parent e138646 commit 2980b60

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ default IBinary[] getBuildOutput() throws CoreException {
151151
* @param env
152152
* build environment
153153
* @since 6.1
154+
* @implNote Ensure you pass a new non-empty map containing the base environment
155+
* as this method modifies the passed in map adding the ICBuildConfiguration specific
156+
* overrides, such as applying the project's build environment.
154157
*/
155158
default void setBuildEnvironment(Map<String, String> env) {
156159
}

dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/launching/CoreBuildLocalDebugLaunchDelegate.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactory;
3535
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
3636
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
37+
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
3738
import org.eclipse.core.runtime.CoreException;
3839
import org.eclipse.core.runtime.IProgressMonitor;
3940
import org.eclipse.core.runtime.IStatus;
@@ -76,10 +77,20 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
7677
ILaunchTarget target = ((ITargetedLaunch) launch).getLaunchTarget();
7778
ICBuildConfiguration buildConfig = getBuildConfiguration(configuration, mode, target, monitor);
7879

79-
Map<String, String> buildEnv = new HashMap<>();
80-
buildConfig.setBuildEnvironment(buildEnv);
80+
Map<String, String> systemEnv = new HashMap<>();
81+
Properties environmentVariables = EnvironmentReader.getEnvVars();
82+
for (String key : environmentVariables.stringPropertyNames()) {
83+
String value = environmentVariables.getProperty(key);
84+
systemEnv.put(key, value);
85+
}
86+
87+
var before = new HashMap<>(systemEnv);
88+
buildConfig.setBuildEnvironment(systemEnv);
89+
90+
before.forEach((k, v) -> systemEnv.remove(k, v));
91+
8192
Properties envProps = new Properties();
82-
envProps.putAll(buildEnv);
93+
envProps.putAll(systemEnv);
8394
gdbLaunch.setInitialEnvironment(envProps);
8495

8596
String debugger = configuration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME,

0 commit comments

Comments
 (0)