[Lldb-commits] [lldb] r252111 - LLDB needs a mutex around getopt_long_only() function calls to avoid multi-threading option parsing issues.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 4 16:38:39 PST 2015


Author: jingham
Date: Wed Nov  4 18:38:39 2015
New Revision: 252111

URL: http://llvm.org/viewvc/llvm-project?rev=252111&view=rev
Log:
LLDB needs a mutex around getopt_long_only() function calls to avoid multi-threading option parsing issues.

<rdar://problem/17052381>

Modified:
    lldb/trunk/include/lldb/Host/OptionParser.h
    lldb/trunk/source/Host/common/OptionParser.cpp
    lldb/trunk/source/Interpreter/Args.cpp

Modified: lldb/trunk/include/lldb/Host/OptionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/OptionParser.h?rev=252111&r1=252110&r2=252111&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/OptionParser.h (original)
+++ lldb/trunk/include/lldb/Host/OptionParser.h Wed Nov  4 18:38:39 2015
@@ -11,6 +11,7 @@
 #define liblldb_OptionParser_h_
 
 #include <string>
+#include "lldb/Host/Mutex.h"
 
 struct option;
 
@@ -38,7 +39,7 @@ public:
         eOptionalArgument
     };
 
-    static void Prepare();
+    static void Prepare(Mutex::Locker &locker);
 
     static void EnableError(bool error);
 

Modified: lldb/trunk/source/Host/common/OptionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/OptionParser.cpp?rev=252111&r1=252110&r2=252111&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/OptionParser.cpp (original)
+++ lldb/trunk/source/Host/common/OptionParser.cpp Wed Nov  4 18:38:39 2015
@@ -16,8 +16,10 @@
 using namespace lldb_private;
 
 void
-OptionParser::Prepare()
+OptionParser::Prepare(Mutex::Locker &locker)
 {
+    static Mutex g_mutex(Mutex::eMutexTypeNormal);
+    locker.Lock(g_mutex);
 #ifdef __GLIBC__
     optind = 0;
 #else

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=252111&r1=252110&r2=252111&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Wed Nov  4 18:38:39 2015
@@ -575,7 +575,8 @@ Args::ParseOptions (Options &options)
             }
         }
     }
-    OptionParser::Prepare();
+    Mutex::Locker options_locker(NULL);
+    OptionParser::Prepare(options_locker);
     int val;
     while (1)
     {
@@ -1189,7 +1190,8 @@ Args::ParseAliasOptions (Options &option
         }
     }
 
-    OptionParser::Prepare();
+    Mutex::Locker options_locker(NULL);
+    OptionParser::Prepare(options_locker);
     int val;
     while (1)
     {
@@ -1366,7 +1368,8 @@ Args::ParseArgsForCompletion
         }
     }
 
-    OptionParser::Prepare();
+    Mutex::Locker options_locker(NULL);
+    OptionParser::Prepare(options_locker);
     OptionParser::EnableError(false);
 
     int val;




More information about the lldb-commits mailing list