[Lldb-commits] [lldb] r367102 - [lldb] Don't dynamically allocate the posix option validator.

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 26 04:46:21 PDT 2019


Author: teemperor
Date: Fri Jul 26 04:46:21 2019
New Revision: 367102

URL: http://llvm.org/viewvc/llvm-project?rev=367102&view=rev
Log:
[lldb] Don't dynamically allocate the posix option validator.

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.

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

Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=367102&r1=367101&r2=367102&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Fri Jul 26 04:46:21 2019
@@ -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;

Modified: lldb/trunk/source/Commands/Options.td
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/Options.td?rev=367102&r1=367101&r2=367102&view=diff
==============================================================================
--- lldb/trunk/source/Commands/Options.td (original)
+++ lldb/trunk/source/Commands/Options.td Fri Jul 26 04:46:21 2019
@@ -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">,

Modified: lldb/trunk/source/Commands/OptionsBase.td
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/OptionsBase.td?rev=367102&r1=367101&r2=367102&view=diff
==============================================================================
--- lldb/trunk/source/Commands/OptionsBase.td (original)
+++ lldb/trunk/source/Commands/OptionsBase.td Fri Jul 26 04:46:21 2019
@@ -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> completio
 class Completion<string completion> {
   list<string> Completions = [completion];
 }
+
+// Sets the validator for a given option.
+class Validator<string validator> {
+  string Validator = validator;
+}

Modified: lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp?rev=367102&r1=367101&r2=367102&view=diff
==============================================================================
--- lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp (original)
+++ lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp Fri Jul 26 04:46:21 2019
@@ -81,7 +81,13 @@ static void emitOption(Record *Option, r
       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");




More information about the lldb-commits mailing list