Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift REPL] Inherit the environment for the Swift REPL #9853

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,18 @@ lldb::REPLSP SwiftREPL::CreateInstanceFromDebugger(Status &err,
// breakpoint above, it better
// say it is internal

lldb_private::ProcessLaunchInfo launch_info;
llvm::StringRef target_settings_argv0 = target_sp->GetArg0();

if (target_sp->GetDisableASLR())
launch_info.GetFlags().Set(eLaunchFlagDisableASLR);

if (target_sp->GetDisableSTDIO())
launch_info.GetFlags().Set(eLaunchFlagDisableSTDIO);
lldb_private::ProcessLaunchInfo launch_info =
target_sp->GetProcessLaunchInfo();

// FIXME: Why is this necessary? Document or change once we know the answer.
llvm::StringRef target_settings_argv0 = target_sp->GetArg0();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this dead code anyway?

if (!target_settings_argv0.empty()) {
launch_info.GetArguments().AppendArgument(target_settings_argv0);
launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), false);
} else {
launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
}

Copy link

@jimingham jimingham Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you get the LaunchEnvironment from the target, these should also be properly set already. I don't think you want to override them here either. The benefit of this change is it allows you to set everything you need to set for the REPL execution in the Target you make for it, then we don't have to overwrite anything here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same thing, but All the REPL test fail without this code. I didn't want to get sidetracked so I left a FIXME to figure out why this is necessary and document it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Looking more closely, if you have set up the arguments properly in the Target, we won't muck with them, so I guess having a "If you don't, we'll fix it for you..." is okay for now.

launch_info.GetEnvironment() = target_sp->GetTargetEnvironment();
debugger.SetAsyncExecution(false);
err = target_sp->Launch(launch_info, nullptr);
debugger.SetAsyncExecution(true);
Expand Down
10 changes: 10 additions & 0 deletions lldb/test/Shell/SwiftREPL/EnvVars.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test inheriting environment variables in the REPL.
// REQUIRES: system-darwin
// REQUIRES: swift

// RUN: FOO=foo %lldb --repl -O 'settings set target.inherit-env true' < %s 2>&1 \
// RUN: | FileCheck %s

import Foundation
ProcessInfo.processInfo.environment["FOO"]
// CHECK: $R0: String? = "foo"