The way Process does it is a little confusing to me. It has this ProcessProperties() class which takes a boolean, is_global. If this value is true, it appends some sub-properties to it, and if it's false, it just initializes itself by calling itself again with true. So false and true make no difference, it's always the same instance (?)
No. is_global is set to true if this is the initial "seed" options for "process" under "target". This is why when "is_global" is set to true that it appends the settings to the "target" global settings, and it doesn't when not.
If you think about it you need a set of options that can be editable before any processes exist. So the "is_global" means we are creating this one set of settings, it has nothing to do with the fact that individual settings can be global or instance based. When a lldb_private::Process is made, it inherits from ProcessProperties, and these are the settings that get modified and any global properties are shared with the global versions, and any instance variables copy the current global settings to be the basis for the initial settings in Process.
So lets say ProcessProperties has two settings "a" which is global and "b" which is not (set by the bool in each property definition). When we first start out we create the global properties which contain default values for "a" and "b":
Global ProcessProperties:
a = true
b = false
Now we run some commands:
(lldb) settings set process.a false
So now we have:
Global ProcessProperties:
a = false
b = false
Now we create a process whose pid is 123:
(lldb) file /bin/ls
(lldb) b malloc
(lldB) r
Now a new process gets created and it makes a copy of "Global ProcessProperties":
Process 123 ProcessProperties:
a = false
b = false
Now someone says:
(lldb) settings set process.a true
Since "a" is global we get:
Global ProcessProperties:
a = true
b = false
Process 123 ProcessProperties:
a = true
b = false
But if we do:
(lldb) settings set process.b true
The Global properties remain unchanged, and only Process 123's settings get changed:
Global ProcessProperties:
a = true
b = false
Process 123 ProcessProperties:
a = true
b = true
Then, to further confuse matters, there's a single PropertyDefinition array, where some of them are specified as global and some not via the third argument. When you call GetGlobalProperties(), it then just returns the whole array. There's not much choice it has, because it's all just one array, so it can't really return a filtered array with only the items where global==true.
I feel like the correct way to do this is to have two separate arrays. One for global properties and one for instance properties. Then, instead of inheriting from Properties, just have two instances of it in the class. An instance instance and a static instance. This way you don't even need the third argument to PropertyDefinition at all. And the global properties are added as a subcategory, such as interpreter.global. This also makes it clear to the user when they run "settings list" which settings are global and which are not. It might be clearer with an example, so I'll upload this patch so you can see what I'm talking about. If you don't like the way I've done it let me know.
Read what I typed above carefully and make sure that:
1 - we need to be able to set non-global properties without any instances so there needs to be global settings that contain all global and all instance based properties so we can set these values before we have any instances around
2 - when a new instance is made, it needs to get a copy of the global pref's global and non-global option values
3 - if you modify a value that is non-global, there needs to be a way to find the right instance so you can set the settings as the code currently does
I would rather you not change this code as it currently works and is relatively bug free. If you do still feel you need to change the code do NOT break anything. This means a lot of testing to make sure it behaves the exact way it used to. Messing with this can really hose things up, so again, don't break anything if you still feel you need to change the code.
Greg