llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Nerixyz (Nerixyz) <details> <summary>Changes</summary> All enum settings on the lldb website didn't show the possible values and their default value. This PR uses the TableGen definitions and generates `:enum name: description` entries from them. I didn't scope the inclusion of available enum values to the `Enum` type. This means that the values are also shown on other types. Notably `Dictionary`. For example on `target.auto-load-scripts-for-modules`, this shows the possible values - without that, you wouldn't know which ones you could input. You can see a preview at <https://nerixyz.github.io/test-gh-pages/use/settings.html> --- Full diff: https://github.com/llvm/llvm-project/pull/224641.diff 10 Files Affected: - (modified) lldb/include/lldb/Core/CMakeLists.txt (+4) - (modified) lldb/include/lldb/Interpreter/CMakeLists.txt (+4) - (modified) lldb/scripts/gen-property-docs-from-json.py (+72-5) - (modified) lldb/source/Core/CMakeLists.txt (+4) - (modified) lldb/source/Interpreter/CMakeLists.txt (+4) - (modified) lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt (+4) - (modified) lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt (+4) - (modified) lldb/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt (+4) - (modified) lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt (+4) - (modified) lldb/source/Target/CMakeLists.txt (+8) ``````````diff diff --git a/lldb/include/lldb/Core/CMakeLists.txt b/lldb/include/lldb/Core/CMakeLists.txt index 9a29e181e5571..53251f2667f82 100644 --- a/lldb/include/lldb/Core/CMakeLists.txt +++ b/lldb/include/lldb/Core/CMakeLists.txt @@ -1,3 +1,7 @@ lldb_tablegen(ModuleListEnums.inc -gen-lldb-option-enum-defs SOURCE ModuleListEnums.td TARGET LLDBModuleListEnumsGen) + +lldb_tablegen(ModuleListEnums.json -dump-json + SOURCE ModuleListEnums.td + TARGET LLDBModuleListEnumsJsonGen) diff --git a/lldb/include/lldb/Interpreter/CMakeLists.txt b/lldb/include/lldb/Interpreter/CMakeLists.txt index 9c9511f6abc43..aa365b9dcc5c7 100644 --- a/lldb/include/lldb/Interpreter/CMakeLists.txt +++ b/lldb/include/lldb/Interpreter/CMakeLists.txt @@ -1,3 +1,7 @@ lldb_tablegen(CommandOptionArgumentTableEnums.inc -gen-lldb-option-enum-defs SOURCE CommandOptionArgumentTableEnums.td TARGET LLDBCommandOptionArgumentTableEnumsGen) + +lldb_tablegen(CommandOptionArgumentTableEnums.json -dump-json + SOURCE CommandOptionArgumentTableEnums.td + TARGET LLDBCommandOptionArgumentTableEnumsJsonGen) diff --git a/lldb/scripts/gen-property-docs-from-json.py b/lldb/scripts/gen-property-docs-from-json.py index 5d90f9f7ec8e1..d873b1c06ac5d 100644 --- a/lldb/scripts/gen-property-docs-from-json.py +++ b/lldb/scripts/gen-property-docs-from-json.py @@ -4,8 +4,34 @@ import json import re - PropertyDef = Dict[str, Any] +DefTree = Dict[str, Any] +EnumValueDef = Dict[str, Any] +EnumDefDict = Dict[str, Any] + + +@dataclass +class EnumValue: + value: str + name: str + description: str + + def __init__(self, definition: EnumValueDef, prefix: str): + self.value = prefix + definition["Value"] + self.name = definition["Name"] + self.description = definition["Description"] + + def matches(self, value: str): + return self.value.removeprefix("lldb::") == value.removeprefix("lldb::") + + +@dataclass +class EnumDef: + items: list[EnumValue] + + def __init__(self, definition: EnumDefDict, tree: DefTree): + prefix = definition.get("Prefix", "") + self.items = [EnumValue(tree[d["def"]], prefix) for d in definition["Values"]] class Property: @@ -14,6 +40,8 @@ class Property: type: str description: str default: Optional[str] + enum_name: Optional[str] + enum_values: Optional[EnumDef] def __init__(self, definition: PropertyDef): self.name = definition["Name"] @@ -21,10 +49,13 @@ def __init__(self, definition: PropertyDef): self.type = definition["Type"] self.description = definition.get("Description", "").strip() self.default = None + self.enum_name = None + self.enum_values = None has_default_unsigned = definition.get("HasDefaultUnsignedValue") has_default_bool = definition.get("HasDefaultBooleanValue") has_default_str = definition.get("HasDefaultStringValue") + has_default_enum = definition.get("HasDefaultEnumValue") if has_default_bool == 1: assert has_default_unsigned self.default = ( @@ -34,6 +65,30 @@ def __init__(self, definition: PropertyDef): self.default = str(definition.get("DefaultUnsignedValue", 0)) elif has_default_str: self.default = definition.get("DefaultStringValue") + elif has_default_enum and self.type != "Language": + self.default = definition.get("DefaultEnumValue") + + enum_values: Optional[str] = definition.get("EnumValues") + if enum_values: + self.enum_name = enum_values.removeprefix("OptionEnumValues(").removesuffix( + ")" + ) + + def find_enum_values(self, enums: Dict[str, EnumDef]): + if self.enum_name is None: + return + + self.enum_values = enums[self.enum_name] + if self.default is not None: + default = next( + (v.name for v in self.enum_values.items if v.matches(self.default)), + None, + ) + if not default: + raise RuntimeError( + f"Failed to find enum value for {self.default} in {self.enum_values}" + ) + self.default = default class PropertyGroup(TypedDict): @@ -74,6 +129,9 @@ def print_property(f: TextIO, path: str, property: Property): f.write(f':type: "{property.type}"\n\n') f.write(property.description) f.write("\n\n") + if property.enum_values: + for enum in property.enum_values.items: + f.write(f":enum {enum.name}: {enum.description}\n") if property.default: f.write(f":default: {wrap_inline_code(property.default)}\n") # FIXME: add enumerations (":enum {name}: {description}") @@ -126,16 +184,25 @@ def main(): parser.add_argument("inputs", nargs="*") args = parser.parse_args() - root = PropertyTree(items={}) + all_properties: list[Property] = [] + enums = dict[str, EnumDef]() + for input in args.inputs: with open(input, encoding="utf-8") as f: properties: dict[str, PropertyDef] = json.load(f) for key, prop in properties.items(): if key.startswith("!"): continue # tablegen metadata - if "Property" not in prop["!superclasses"]: - continue # not a property - append_property(root, Property(prop)) + superclasses = prop["!superclasses"] + if "Property" in superclasses: + all_properties.append(Property(prop)) + if "EnumDef" in superclasses: + enums["g_" + key] = EnumDef(prop, properties) + + root = PropertyTree(items={}) + for prop in all_properties: + prop.find_enum_values(enums) + append_property(root, prop) with open(args.output, "w", encoding="utf-8") as f: f.write(HEADER) diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index 58b0794bcae95..41f1dab242812 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -10,6 +10,10 @@ lldb_tablegen(DebuggerEnums.inc -gen-lldb-option-enum-defs SOURCE DebuggerEnums.td TARGET LLDBDebuggerEnumsGen) +lldb_tablegen(DebuggerEnums.json -dump-json + SOURCE DebuggerEnums.td + TARGET LLDBDebuggerEnumsJsonGen) + lldb_tablegen(CoreProperties.json -dump-json SOURCE CoreProperties.td TARGET LLDBCorePropertiesJsonGen) diff --git a/lldb/source/Interpreter/CMakeLists.txt b/lldb/source/Interpreter/CMakeLists.txt index 27625676b9425..2377909da8f85 100644 --- a/lldb/source/Interpreter/CMakeLists.txt +++ b/lldb/source/Interpreter/CMakeLists.txt @@ -10,6 +10,10 @@ lldb_tablegen(OptionGroupWatchpointEnums.inc -gen-lldb-option-enum-defs SOURCE OptionGroupWatchpointEnums.td TARGET LLDBOptionGroupWatchpointEnumsGen) +lldb_tablegen(OptionGroupWatchpointEnums.json -dump-json + SOURCE OptionGroupWatchpointEnums.td + TARGET LLDBOptionGroupWatchpointEnumsJsonGen) + lldb_tablegen(InterpreterProperties.json -dump-json SOURCE InterpreterProperties.td TARGET LLDBInterpreterPropertiesJsonGen) diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt index 977dad935fa12..8e495d2fb33bd 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt @@ -10,6 +10,10 @@ lldb_tablegen(DynamicLoaderDarwinKernelEnums.inc -gen-lldb-option-enum-defs SOURCE DynamicLoaderDarwinKernelEnums.td TARGET LLDBPluginDynamicLoaderDarwinKernelEnumsGen) +lldb_tablegen(DynamicLoaderDarwinKernelEnums.json -dump-json + SOURCE DynamicLoaderDarwinKernelEnums.td + TARGET LLDBPluginDynamicLoaderDarwinKernelEnumsJsonGen) + lldb_tablegen(DynamicLoaderDarwinKernelProperties.json -dump-json SOURCE DynamicLoaderDarwinKernelProperties.td TARGET LLDBPluginDynamicLoaderDarwinKernelPropertiesJsonGen) diff --git a/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt b/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt index e62efe476fad9..742ae2f361495 100644 --- a/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt +++ b/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt @@ -10,6 +10,10 @@ lldb_tablegen(JITLoaderGDBEnums.inc -gen-lldb-option-enum-defs SOURCE JITLoaderGDBEnums.td TARGET LLDBPluginJITLoaderGDBEnumsGen) +lldb_tablegen(JITLoaderGDBEnums.json -dump-json + SOURCE JITLoaderGDBEnums.td + TARGET LLDBPluginJITLoaderGDBEnumsJsonGen) + lldb_tablegen(JITLoaderGDBProperties.json -dump-json SOURCE JITLoaderGDBProperties.td TARGET LLDBPluginJITLoaderGDBPropertiesJsonGen) diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt b/lldb/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt index 6d9781c42f228..3edb9dfd9883d 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt +++ b/lldb/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt @@ -17,6 +17,10 @@ lldb_tablegen(ObjectFilePECOFFEnums.inc -gen-lldb-option-enum-defs SOURCE ObjectFilePECOFFEnums.td TARGET LLDBPluginObjectFilePECOFFEnumsGen) +lldb_tablegen(ObjectFilePECOFFEnums.json -dump-json + SOURCE ObjectFilePECOFFEnums.td + TARGET LLDBPluginObjectFilePECOFFEnumsJsonGen) + lldb_tablegen(ObjectFilePECOFFProperties.json -dump-json SOURCE ObjectFilePECOFFProperties.td TARGET LLDBPluginObjectFilePECOFFPropertiesJsonGen) diff --git a/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt index 076f607797d80..6092e85d9eb04 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt +++ b/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt @@ -10,6 +10,10 @@ lldb_tablegen(SymbolFilePDBEnums.inc -gen-lldb-option-enum-defs SOURCE SymbolFilePDBEnums.td TARGET LLDBPluginSymbolFilePDBEnumsGen) +lldb_tablegen(SymbolFilePDBEnums.json -dump-json + SOURCE SymbolFilePDBEnums.td + TARGET LLDBPluginSymbolFilePDBEnumsJsonGen) + lldb_tablegen(SymbolFilePDBProperties.json -dump-json SOURCE SymbolFilePDBProperties.td TARGET LLDBPluginSymbolFilePDBPropertiesJsonGen) diff --git a/lldb/source/Target/CMakeLists.txt b/lldb/source/Target/CMakeLists.txt index 37d32b1033a84..1fa4cfa25f440 100644 --- a/lldb/source/Target/CMakeLists.txt +++ b/lldb/source/Target/CMakeLists.txt @@ -10,10 +10,18 @@ lldb_tablegen(ProcessEnums.inc -gen-lldb-option-enum-defs SOURCE ProcessEnums.td TARGET LLDBProcessEnumsGen) +lldb_tablegen(ProcessEnums.json -dump-json + SOURCE ProcessEnums.td + TARGET LLDBProcessEnumsJsonGen) + lldb_tablegen(TargetEnums.inc -gen-lldb-option-enum-defs SOURCE TargetEnums.td TARGET LLDBTargetEnumsGen) +lldb_tablegen(TargetEnums.json -dump-json + SOURCE TargetEnums.td + TARGET LLDBTargetEnumsJsonGen) + lldb_tablegen(TargetProperties.json -dump-json SOURCE TargetProperties.td TARGET LLDBTargetPropertiesJsonGen) `````````` </details> https://github.com/llvm/llvm-project/pull/224641 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
