This is an archive of the discontinued LLVM Phabricator instance.

[lldb/API] Overwrite variables with SBLaunchInfo::SetEnvironment(append=true)
ClosedPublic

Authored by labath on Jul 7 2020, 7:12 AM.

Details

Summary

This function was documented to overwrite entries with D76111, which was
adding a couple of similar functions. However, this function (unlike the
functions added in that patch) was/is not actually overwriting variables

  • any pre-existing variables would get ignored.

This behavior does not seem to be intentional. In fact, before the refactor in
D41359, this function could introduce duplicate entries, which could
have very surprising effects both inside lldb and on other applications
(some applications would take the first value, some the second one; in
lldb, attempting to unset a variable could make the second variable
become active, etc.).

Overwriting seems to be the most reasonable behavior here, so change the
code to match documentation.

Diff Detail

Event Timeline

labath created this revision.Jul 7 2020, 7:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2020, 7:12 AM
labath added a comment.Jul 7 2020, 7:15 AM

this is the line that motivated this patch -- if one has a LD_LIBRARY_PATH environment variable already set (as I happen to do), then that line will not overwrite it with the value needed for the test.

wallace accepted this revision.Jul 7 2020, 8:03 AM

Thanks!

This revision is now accepted and ready to land.Jul 7 2020, 8:03 AM
jingham accepted this revision.Jul 7 2020, 9:46 AM

This is fine. If there were a universal convention (e.g. : separated lists) for environment variables, it would be reasonable for "append" behavior to extend rather than replace extant variables, but in the absence of the universality of such a convention, the best we can do is overwrite.

clayborg accepted this revision.Jul 7 2020, 11:45 AM
This revision was automatically updated to reflect the committed changes.
davide added a subscriber: davide.Jul 8 2020, 1:11 PM

This broke macOS:

http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22425/

I reverted it in:

commit 27d52cd86a2cf82214b71519dffd450c54cf87ae (HEAD -> master, origin/master, origin/HEAD)
Author: Davide Italiano <ditaliano@apple.com>
Date:   Wed Jul 8 13:00:29 2020 -0700
    Revert "[lldb/API] Overwrite variables with SBLaunchInfo::SetEnvironment(append=true)"
    This reverts commit 695b33a56919af8873eecb47cb83fa17a271e99f beacuse
    it broke the macOS bot.

Let me know if you need any help/info to reproduce [just shoot me an e-mail], but ToT + ninja check-lldb on a recent'ish 10.15 should do it.

Thanks. It was fairly easy to reproduce the problem. I have a proposed fix in D83552.