Skip to content

Commit

Permalink
[lldb]/Tablegen] Use ElementType instead of DefaultValueUnsinged
Browse files Browse the repository at this point in the history
The fourth field in the property struct is the default unsigned or enum
value for all types, except for Array and Dictionary types. For those,
it is the element type. During the tablegen conversion, this was
incorrectly translated to DefaultValueUnsigned with a value
corresponding to the OptionValue: enum type. So for
OptionValue::eTypeString this became DefaultUnsignedValue<16>. This
patch extends the tablegen backend to understand ElementType to express
this as ElementType<"String">.

Differential revision: https://reviews.llvm.org/D76535
  • Loading branch information
JDevlieghere committed Mar 21, 2020
1 parent d35a454 commit 09c8845
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lldb/include/lldb/Core/PropertiesBase.td
Expand Up @@ -49,3 +49,9 @@ class DefaultUnsignedValue<int value> {
class EnumValues<string enum> {
string EnumValues = enum;
}

// Determines the element type for arrays and dictionaries.
class ElementType<string value> {
string ElementType = value;
bit HasElementType = 1;
}
6 changes: 3 additions & 3 deletions lldb/source/Target/TargetProperties.td
Expand Up @@ -79,7 +79,7 @@ let Definition = "target" in {
DefaultStringValue<"">,
Desc<"A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0.">;
def EnvVars: Property<"env-vars", "Dictionary">,
DefaultUnsignedValue<16>,
ElementType<"String">,
Desc<"A list of all the environment variables to be passed to the executable's environment, and their values.">;
def InheritEnv: Property<"inherit-env", "Boolean">,
DefaultTrue,
Expand Down Expand Up @@ -140,7 +140,7 @@ let Definition = "target" in {
Desc<"Expressions that crash will show up in crash logs if the host system supports executable specific crash log strings and this setting is set to true.">;
def TrapHandlerNames: Property<"trap-handler-names", "Array">,
Global,
DefaultUnsignedValue<16>,
ElementType<"String">,
Desc<"A list of trap handler function names, e.g. a common Unix user process one is _sigtramp.">;
def DisplayRuntimeSupportValues: Property<"display-runtime-support-values", "Boolean">,
DefaultFalse,
Expand All @@ -164,7 +164,7 @@ let Definition = "process" in {
DefaultFalse,
Desc<"Disable reading and caching of memory in fixed-size units.">;
def ExtraStartCommand: Property<"extra-startup-command", "Array">,
DefaultUnsignedValue<16>,
ElementType<"String">,
Desc<"A list containing extra commands understood by the particular process plugin used. For instance, to turn on debugserver logging set this to 'QSetLogging:bitmask=LOG_DEFAULT;'">;
def IgnoreBreakpointsInExpressions: Property<"ignore-breakpoints-in-expressions", "Boolean">,
Global,
Expand Down
15 changes: 12 additions & 3 deletions lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp
Expand Up @@ -35,8 +35,9 @@ static void emitProperty(Record *Property, raw_ostream &OS) {
OS << ", ";

// Emit the property type.
llvm::StringRef type = Property->getValueAsString("Type");
OS << "OptionValue::eType";
OS << Property->getValueAsString("Type");
OS << type;
OS << ", ";

// Emit the property's global value.
Expand All @@ -46,11 +47,12 @@ static void emitProperty(Record *Property, raw_ostream &OS) {
bool hasDefaultUnsignedValue = Property->getValue("HasDefaultUnsignedValue");
bool hasDefaultEnumValue = Property->getValue("HasDefaultEnumValue");
bool hasDefaultStringValue = Property->getValue("HasDefaultStringValue");
bool hasElementType = Property->getValue("HasElementType");

// Guarantee that every property has a default value.
assert((hasDefaultUnsignedValue || hasDefaultEnumValue ||
hasDefaultStringValue) &&
"Property must have a default value");
hasDefaultStringValue || hasElementType) &&
"Property must have a default value or an element type");

// Guarantee that no property has both a default unsigned value and a default
// enum value, since they're bothed stored in the same field.
Expand All @@ -72,11 +74,18 @@ static void emitProperty(Record *Property, raw_ostream &OS) {
!(Property->getValueAsString("Type") == "Enum" && !hasDefaultEnumValue) &&
"Enum property must have a enum default value.");

// Guarantee that only arrays and dictionaries have an element type;
assert(((type != "Array" && type != "Dictionary") || hasElementType) &&
"Only dictionaries and arrays can have an element type.");

// Emit the default uint value.
if (hasDefaultUnsignedValue) {
OS << std::to_string(Property->getValueAsInt("DefaultUnsignedValue"));
} else if (hasDefaultEnumValue) {
OS << Property->getValueAsString("DefaultEnumValue");
} else if (hasElementType) {
OS << "OptionValue::eType";
OS << Property->getValueAsString("ElementType");
} else {
OS << "0";
}
Expand Down

0 comments on commit 09c8845

Please sign in to comment.