[Lldb-commits] [lldb] r178789 - <rdar://problem/13457391>

Greg Clayton gclayton at apple.com
Thu Apr 4 13:35:25 PDT 2013


Author: gclayton
Date: Thu Apr  4 15:35:24 2013
New Revision: 178789

URL: http://llvm.org/viewvc/llvm-project?rev=178789&view=rev
Log:
<rdar://problem/13457391>

LLDB now can use a single dash for all long options for all commands form the command line and from the command interpreter. This involved just switching all calls from getopt_long() to getopt_long_only().


Modified:
    lldb/trunk/include/lldb/Interpreter/Options.h
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp
    lldb/trunk/source/Interpreter/Options.cpp
    lldb/trunk/tools/darwin-debug/darwin-debug.cpp
    lldb/trunk/tools/debugserver/source/debugserver.cpp
    lldb/trunk/tools/driver/Driver.cpp
    lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp
    lldb/trunk/tools/lldb-perf/common/stepping/lldb-perf-stepping.cpp
    lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp
    lldb/trunk/tools/lldb-platform/lldb-platform.cpp

Modified: lldb/trunk/include/lldb/Interpreter/Options.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Options.h?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Options.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Options.h Thu Apr  4 15:35:24 2013
@@ -45,10 +45,10 @@ namespace lldb_private {
 /// \endcode
 ///
 /// The options are specified using the format defined for the libc
-/// options parsing function getopt_long:
+/// options parsing function getopt_long_only:
 /// \code
 ///     #include <getopt.h>
-///     int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
+///     int getopt_long_only(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
 /// \endcode
 ///
 /// Example code:
@@ -139,7 +139,7 @@ public:
     /// Get the option definitions to use when parsing Args options.
     ///
     /// @see Args::ParseOptions (Options&)
-    /// @see man getopt_long
+    /// @see man getopt_long_only
     //------------------------------------------------------------------
     struct option *
     GetLongOptions ();
@@ -200,7 +200,7 @@ public:
     ///
     ///
     /// @see Args::ParseOptions (Options&)
-    /// @see man getopt_long
+    /// @see man getopt_long_only
     //------------------------------------------------------------------
     virtual Error
     SetOptionValue (uint32_t option_idx, const char *option_arg) = 0;

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Thu Apr  4 15:35:24 2013
@@ -655,11 +655,11 @@ Args::ParseOptions (Options &options)
     while (1)
     {
         int long_options_index = -1;
-        val = ::getopt_long(GetArgumentCount(),
-                            GetArgumentVector(),
-                            sstr.GetData(),
-                            long_options,
-                            &long_options_index);
+        val = ::getopt_long_only(GetArgumentCount(),
+                                 GetArgumentVector(),
+                                 sstr.GetData(),
+                                 long_options,
+                                 &long_options_index);
         if (val == -1)
             break;
 
@@ -1314,8 +1314,11 @@ Args::ParseAliasOptions (Options &option
     while (1)
     {
         int long_options_index = -1;
-        val = ::getopt_long (GetArgumentCount(), GetArgumentVector(), sstr.GetData(), long_options,
-                             &long_options_index);
+        val = ::getopt_long_only (GetArgumentCount(),
+                                  GetArgumentVector(),
+                                  sstr.GetData(),
+                                  long_options,
+                                  &long_options_index);
 
         if (val == -1)
             break;
@@ -1492,8 +1495,8 @@ Args::ParseArgsForCompletion
     int val;
     const OptionDefinition *opt_defs = options.GetDefinitions();
 
-    // Fooey... getopt_long permutes the GetArgumentVector to move the options to the front.
-    // So we have to build another Arg and pass that to getopt_long so it doesn't
+    // Fooey... getopt_long_only permutes the GetArgumentVector to move the options to the front.
+    // So we have to build another Arg and pass that to getopt_long_only so it doesn't
     // change the one we have.
 
     std::vector<const char *> dummy_vec (GetArgumentVector(), GetArgumentVector() + GetArgumentCount() + 1);
@@ -1507,11 +1510,11 @@ Args::ParseArgsForCompletion
         int parse_start = optind;
         int long_options_index = -1;
         
-        val = ::getopt_long (dummy_vec.size() - 1,
-                             (char *const *) &dummy_vec.front(), 
-                             sstr.GetData(), 
-                             long_options,
-                             &long_options_index);
+        val = ::getopt_long_only (dummy_vec.size() - 1,
+                                  (char *const *) &dummy_vec.front(),
+                                  sstr.GetData(),
+                                  long_options,
+                                  &long_options_index);
 
         if (val == -1)
         {
@@ -1525,7 +1528,7 @@ Args::ParseArgsForCompletion
             // Handling the "--" is a little tricky, since that may mean end of options or arguments, or the
             // user might want to complete options by long name.  I make this work by checking whether the
             // cursor is in the "--" argument, and if so I assume we're completing the long option, otherwise
-            // I let it pass to getopt_long which will terminate the option parsing.
+            // I let it pass to getopt_long_only which will terminate the option parsing.
             // Note, in either case we continue parsing the line so we can figure out what other options
             // were passed.  This will be useful when we come to restricting completions based on what other
             // options we've seen on the line.
@@ -1641,7 +1644,7 @@ Args::ParseArgsForCompletion
     }
     
     // Finally we have to handle the case where the cursor index points at a single "-".  We want to mark that in
-    // the option_element_vector, but only if it is not after the "--".  But it turns out that getopt_long just ignores
+    // the option_element_vector, but only if it is not after the "--".  But it turns out that getopt_long_only just ignores
     // an isolated "-".  So we have to look it up by hand here.  We only care if it is AT the cursor position.
     
     if ((dash_dash_pos == -1 || cursor_index < dash_dash_pos)

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Thu Apr  4 15:35:24 2013
@@ -169,7 +169,7 @@ CommandObject::ParseOptions
         Error error;
         options->NotifyOptionParsingStarting();
 
-        // ParseOptions calls getopt_long, which always skips the zero'th item in the array and starts at position 1,
+        // ParseOptions calls getopt_long_only, which always skips the zero'th item in the array and starts at position 1,
         // so we need to push a dummy value into position zero.
         args.Unshift("dummy_string");
         error = args.ParseOptions (*options);
@@ -416,7 +416,7 @@ CommandObject::HandleCompletion
 
 
             // I stick an element on the end of the input, because if the last element is
-            // option that requires an argument, getopt_long will freak out.
+            // option that requires an argument, getopt_long_only will freak out.
 
             input.AppendArgument ("<FAKE-VALUE>");
 

Modified: lldb/trunk/source/Interpreter/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Options.cpp (original)
+++ lldb/trunk/source/Interpreter/Options.cpp Thu Apr  4 15:35:24 2013
@@ -310,7 +310,7 @@ Options::GetLongOptions ()
             }
         }
 
-        //getopt_long requires a NULL final entry in the table:
+        //getopt_long_only requires a NULL final entry in the table:
 
         m_getopt_table[i].name    = NULL;
         m_getopt_table[i].has_arg = 0;
@@ -796,7 +796,7 @@ Options::HandleOptionCompletion
             }
             else if (opt_defs_index != OptionArgElement::eUnrecognizedArg)
             {
-                // We recognized it, if it an incomplete long option, complete it anyway (getopt_long is
+                // We recognized it, if it an incomplete long option, complete it anyway (getopt_long_only is
                 // happy with shortest unique string, but it's still a nice thing to do.)  Otherwise return
                 // The string so the upper level code will know this is a full match and add the " ".
                 if (cur_opt_str && strlen (cur_opt_str) > 2
@@ -819,7 +819,7 @@ Options::HandleOptionCompletion
                 // FIXME - not handling wrong options yet:
                 // Check to see if they are writing a long option & complete it.
                 // I think we will only get in here if the long option table has two elements
-                // that are not unique up to this point.  getopt_long does shortest unique match
+                // that are not unique up to this point.  getopt_long_only does shortest unique match
                 // for long options already.
 
                 if (cur_opt_str && strlen (cur_opt_str) > 2

Modified: lldb/trunk/tools/darwin-debug/darwin-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/darwin-debug/darwin-debug.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/darwin-debug/darwin-debug.cpp (original)
+++ lldb/trunk/tools/darwin-debug/darwin-debug.cpp Thu Apr  4 15:35:24 2013
@@ -184,7 +184,7 @@ int main (int argc, char *const *argv, c
     int pass_env = 1;
     std::string unix_socket_name;
     std::string working_dir;
-	while ((ch = getopt_long(argc, argv, "a:dehsu:?", g_long_options, NULL)) != -1)
+	while ((ch = getopt_long_only(argc, argv, "a:dehsu:?", g_long_options, NULL)) != -1)
 	{
 		switch (ch) 
 		{

Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver.cpp (original)
+++ lldb/trunk/tools/debugserver/source/debugserver.cpp Thu Apr  4 15:35:24 2013
@@ -760,7 +760,7 @@ show_usage_and_exit (int exit_code)
 
 
 //----------------------------------------------------------------------
-// option descriptors for getopt_long()
+// option descriptors for getopt_long_only()
 //----------------------------------------------------------------------
 static struct option g_long_options[] =
 {
@@ -880,7 +880,7 @@ main (int argc, char *argv[])
     }
     // NULL terminate the short option string.
     short_options[short_options_idx++] = '\0';
-    while ((ch = getopt_long(argc, argv, short_options, g_long_options, &long_option_index)) != -1)
+    while ((ch = getopt_long_only(argc, argv, short_options, g_long_options, &long_option_index)) != -1)
     {
         DNBLogDebug("option: ch == %c (0x%2.2x) --%s%c%s\n",
                     ch, (uint8_t)ch,
@@ -1106,7 +1106,7 @@ main (int argc, char *argv[])
 //        fprintf(stderr, "error: no architecture was specified\n");
 //        exit (8);
 //    }
-    // Skip any options we consumed with getopt_long
+    // Skip any options we consumed with getopt_long_only
     argc -= optind;
     argv += optind;
 

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Thu Apr  4 15:35:24 2013
@@ -510,7 +510,7 @@ Driver::ParseArgs (int argc, const char
         return error;
     }
 
-    // Build the option_string argument for call to getopt_long.
+    // Build the option_string argument for call to getopt_long_only.
 
     for (int i = 0; long_options[i].name != NULL; ++i)
     {
@@ -541,7 +541,7 @@ Driver::ParseArgs (int argc, const char
     m_debugger.SkipLLDBInitFiles (false);
     m_debugger.SkipAppInitFiles (false);
 
-    // Prepare for & make calls to getopt_long.
+    // Prepare for & make calls to getopt_long_only.
 #if __GLIBC__
     optind = 0;
 #else
@@ -552,7 +552,7 @@ Driver::ParseArgs (int argc, const char
     while (1)
     {
         int long_options_index = -1;
-        val = ::getopt_long (argc, const_cast<char **>(argv), option_string.c_str(), long_options, &long_options_index);
+        val = ::getopt_long_only (argc, const_cast<char **>(argv), option_string.c_str(), long_options, &long_options_index);
 
         if (val == -1)
             break;
@@ -738,7 +738,7 @@ Driver::ParseArgs (int argc, const char
         // are arguments for the inferior program. If no file was specified with
         // -f, then what is left is the program name followed by any arguments.
 
-        // Skip any options we consumed with getopt_long
+        // Skip any options we consumed with getopt_long_only
         argc -= optind;
         argv += optind;
 
@@ -755,7 +755,7 @@ Driver::ParseArgs (int argc, const char
     }
     else
     {
-        // Skip any options we consumed with getopt_long
+        // Skip any options we consumed with getopt_long_only
         argc -= optind;
         //argv += optind; // Commented out to keep static analyzer happy
 

Modified: lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp (original)
+++ lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp Thu Apr  4 15:35:24 2013
@@ -333,7 +333,7 @@ GetShortOptionString (struct option *lon
 int main(int argc, const char * argv[])
 {
 
-    // Prepare for & make calls to getopt_long.
+    // Prepare for & make calls to getopt_long_only.
     
     std::string short_option_string (GetShortOptionString(g_long_options));
     

Modified: lldb/trunk/tools/lldb-perf/common/stepping/lldb-perf-stepping.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/common/stepping/lldb-perf-stepping.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/common/stepping/lldb-perf-stepping.cpp (original)
+++ lldb/trunk/tools/lldb-perf/common/stepping/lldb-perf-stepping.cpp Thu Apr  4 15:35:24 2013
@@ -222,7 +222,7 @@ GetShortOptionString (struct option *lon
 int main(int argc, const char * argv[])
 {
 
-    // Prepare for & make calls to getopt_long.
+    // Prepare for & make calls to getopt_long_only.
     
     std::string short_option_string (GetShortOptionString(g_long_options));
     

Modified: lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp (original)
+++ lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp Thu Apr  4 15:35:24 2013
@@ -304,7 +304,7 @@ GetShortOptionString (struct option *lon
 int main(int argc, const char * argv[])
 {
     
-    // Prepare for & make calls to getopt_long.
+    // Prepare for & make calls to getopt_long_only.
     
     SketchTest test;
     

Modified: lldb/trunk/tools/lldb-platform/lldb-platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-platform/lldb-platform.cpp?rev=178789&r1=178788&r2=178789&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-platform/lldb-platform.cpp (original)
+++ lldb/trunk/tools/lldb-platform/lldb-platform.cpp Thu Apr  4 15:35:24 2013
@@ -32,7 +32,7 @@ using namespace lldb;
 using namespace lldb_private;
 
 //----------------------------------------------------------------------
-// option descriptors for getopt_long()
+// option descriptors for getopt_long_only()
 //----------------------------------------------------------------------
 
 int g_debug = 0;
@@ -117,7 +117,7 @@ main (int argc, char *argv[])
 //        return 3;
 //    }
     
-    while ((ch = getopt_long(argc, argv, "l:f:L:", g_long_options, &long_option_index)) != -1)
+    while ((ch = getopt_long_only(argc, argv, "l:f:L:", g_long_options, &long_option_index)) != -1)
     {
 //        DNBLogDebug("option: ch == %c (0x%2.2x) --%s%c%s\n",
 //                    ch, (uint8_t)ch,
@@ -177,7 +177,7 @@ main (int argc, char *argv[])
         ProcessGDBRemoteLog::EnableLog (log_stream_sp, 0,log_args.GetConstArgumentVector(), log_stream_sp.get());
     }
 
-    // Skip any options we consumed with getopt_long
+    // Skip any options we consumed with getopt_long_only
     argc -= optind;
     argv += optind;
 





More information about the lldb-commits mailing list