[lldb] Don't dynamically allocate the posix option validator.
authorRaphael Isemann <teemperor@gmail.com>
Fri, 26 Jul 2019 11:46:21 +0000 (11:46 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 26 Jul 2019 11:46:21 +0000 (11:46 +0000)
We dynamically allocate the option validator which means we
can't mark this list of OptionDefinitions as constexpr. It's also
more complicated than necessary.

llvm-svn: 367102

lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/Options.td
lldb/source/Commands/OptionsBase.td
lldb/utils/TableGen/LLDBOptionDefEmitter.cpp

index d105402..1088384 100644 (file)
@@ -1041,7 +1041,8 @@ protected:
 
 // "platform process list"
 
-static OptionDefinition g_platform_process_list_options[] = {
+static PosixPlatformCommandOptionValidator posix_validator;
+static constexpr OptionDefinition g_platform_process_list_options[] = {
 #define LLDB_OPTIONS_platform_process_list
 #include "CommandOptions.inc"
 };
@@ -1166,23 +1167,6 @@ protected:
   public:
     CommandOptions()
         : Options(), match_info(), show_args(false), verbose(false) {
-      static llvm::once_flag g_once_flag;
-      llvm::call_once(g_once_flag, []() {
-        PosixPlatformCommandOptionValidator *posix_validator =
-            new PosixPlatformCommandOptionValidator();
-        for (auto &Option : g_platform_process_list_options) {
-          switch (Option.short_option) {
-          case 'u':
-          case 'U':
-          case 'g':
-          case 'G':
-            Option.validator = posix_validator;
-            break;
-          default:
-            break;
-          }
-        }
-      });
     }
 
     ~CommandOptions() override = default;
index 4483d49..d710290 100644 (file)
@@ -576,16 +576,16 @@ let Command = "platform process list" in {
   def platform_process_list_parent : Option<"parent", "P">, GroupRange<2, 6>,
     Arg<"Pid">, Desc<"Find processes that have a matching parent process ID.">;
   def platform_process_list_uid : Option<"uid", "u">, GroupRange<2, 6>,
-    Arg<"UnsignedInteger">,
+    Arg<"UnsignedInteger">, Validator<"&posix_validator">,
     Desc<"Find processes that have a matching user ID.">;
   def platform_process_list_euid : Option<"euid", "U">, GroupRange<2, 6>,
-    Arg<"UnsignedInteger">,
+    Arg<"UnsignedInteger">, Validator<"&posix_validator">,
     Desc<"Find processes that have a matching effective user ID.">;
   def platform_process_list_gid : Option<"gid", "g">, GroupRange<2, 6>,
-    Arg<"UnsignedInteger">,
+    Arg<"UnsignedInteger">, Validator<"&posix_validator">,
     Desc<"Find processes that have a matching group ID.">;
   def platform_process_list_egid : Option<"egid", "G">, GroupRange<2, 6>,
-    Arg<"UnsignedInteger">,
+    Arg<"UnsignedInteger">, Validator<"&posix_validator">,
     Desc<"Find processes that have a matching effective group ID.">;
   def platform_process_list_arch : Option<"arch", "a">, GroupRange<2, 6>,
     Arg<"Architecture">,
index e0ee03f..f6967f0 100644 (file)
@@ -46,7 +46,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 // Field: validator
 // Default value: 0 (No validator for option)
-// Set by: Nothing. This is currently only set after initialization in LLDB.
+// Set by:
+//  - `Validator`: Sets the value to a given validator (which has to exist in
+//                 the surrounding code.
 ////////////////////////////////////////////////////////////////////////////////
 // Field: enum_values
 // Default value: {} (No enum associated with this option)
@@ -169,3 +171,8 @@ class Completions<list<string> completions> {
 class Completion<string completion> {
   list<string> Completions = [completion];
 }
+
+// Sets the validator for a given option.
+class Validator<string validator> {
+  string Validator = validator;
+}
index 537f71c..844d258 100644 (file)
@@ -81,7 +81,13 @@ static void emitOption(Record *Option, raw_ostream &OS) {
       OS << "eRequiredArgument";
   } else
     OS << "eNoArgument";
-  OS << ", nullptr, ";
+  OS << ", ";
+
+  if (Option->getValue("Validator"))
+    OS << Option->getValueAsString("Validator");
+  else
+    OS << "nullptr";
+  OS << ", ";
 
   if (Option->getValue("ArgEnum"))
     OS << Option->getValueAsString("ArgEnum");