1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

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.
This commit is contained in:
Jonah Graham 2025-02-24 20:52:18 -05:00
parent e138646434
commit 2980b60439
2 changed files with 17 additions and 3 deletions

View file

@ -151,6 +151,9 @@ public interface ICBuildConfiguration extends IAdaptable, IScannerInfoProvider {
* @param env * @param env
* build environment * build environment
* @since 6.1 * @since 6.1
* @implNote Ensure you pass a new non-empty map containing the base environment
* as this method modifies the passed in map adding the ICBuildConfiguration specific
* overrides, such as applying the project's build environment.
*/ */
default void setBuildEnvironment(Map<String, String> env) { default void setBuildEnvironment(Map<String, String> env) {
} }

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.dsf.gdb.launching.ServicesLaunchSequence;
import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactory; import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactory;
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfServicesTracker;
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
@ -76,10 +77,20 @@ public class CoreBuildLocalDebugLaunchDelegate extends CoreBuildLaunchConfigDele
ILaunchTarget target = ((ITargetedLaunch) launch).getLaunchTarget(); ILaunchTarget target = ((ITargetedLaunch) launch).getLaunchTarget();
ICBuildConfiguration buildConfig = getBuildConfiguration(configuration, mode, target, monitor); ICBuildConfiguration buildConfig = getBuildConfiguration(configuration, mode, target, monitor);
Map<String, String> buildEnv = new HashMap<>(); Map<String, String> systemEnv = new HashMap<>();
buildConfig.setBuildEnvironment(buildEnv); Properties environmentVariables = EnvironmentReader.getEnvVars();
for (String key : environmentVariables.stringPropertyNames()) {
String value = environmentVariables.getProperty(key);
systemEnv.put(key, value);
}
var before = new HashMap<>(systemEnv);
buildConfig.setBuildEnvironment(systemEnv);
before.forEach((k, v) -> systemEnv.remove(k, v));
Properties envProps = new Properties(); Properties envProps = new Properties();
envProps.putAll(buildEnv); envProps.putAll(systemEnv);
gdbLaunch.setInitialEnvironment(envProps); gdbLaunch.setInitialEnvironment(envProps);
String debugger = configuration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME, String debugger = configuration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME,