Reputation: 431
I would like to create an LLDB alias/macro in Python that includes settings an environment variable to be passed to future processes. How to do that?
If it were just Python, I would update os.environ
. However, lldb's script
does not propagate that from Python back to target.env-vars
, so I don't get the desired outcome:
(lldb) settings show target.env-vars
target.env-vars (dictionary of strings) =
(lldb) settings set target.env-vars TEST1='this is test1'
(lldb) settings show target.env-vars
target.env-vars (dictionary of strings) =
TEST1=this is test1
(lldb) script os.environ['TEST2']='this is test2'
(lldb) settings show target.env-vars
target.env-vars (dictionary of strings) =
TEST1=this is test1
(lldb)
I am using lldb-1001.0.13.3 .
Upvotes: 0
Views: 694
Reputation: 27110
Target environment variables are a little complicated. They are really controlled by three settings. One is:
target.inherit-env
If that setting is false, then only the environment vars in target.env-vars
are used in a launch that doesn't override the environment settings.
If it is true, then first the host environment is copied over into the environment array. Then the target.unset-env-vars
are removed from it. Then the target.env-vars
are set into it. So in any case, target.env-vars
contains only the variables the user explicitly set.
Note all this is done by making an SBLaunchInfo and using that to launch the target. If you are running the process from Python, you can make your own SBLaunchInfo and that will override all these calculations.
By the same token, if you want to see the result of this merging, call SBTarget.GetLaunchInfo() on the target in question, and then you can look at its environment with SBLaunchInfo.GetNumEnvironmentEntries
and SBLaunchInfo.GetEnvironmentEntryAtIndex
.
Anyway, that was all by way of background. If you want to use the env-vars settings to propagate new options from Python, you need to use the SBCommandInterpreter.HandleCommand
API to run the settings set
command as you would from the command line. lldb hasn't implemented a scripted API to access the settings yet.
Upvotes: 1