[Lldb-commits] [lldb] r226704 - Abstract the details from regex.h a bit more by not allowing people to specify compile and execute flags for regular expressions. Also enable better regular expressions if they are available by check if the REG_ENHANCED is available and using it if it is.

Greg Clayton gclayton at apple.com
Wed Jan 21 13:51:02 PST 2015


Author: gclayton
Date: Wed Jan 21 15:51:02 2015
New Revision: 226704

URL: http://llvm.org/viewvc/llvm-project?rev=226704&view=rev
Log:
Abstract the details from regex.h a bit more by not allowing people to specify compile and execute flags for regular expressions. Also enable better regular expressions if they are available by check if the REG_ENHANCED is available and using it if it is.

Since REG_ENHANCED is available on MacOSX, this allow the use of \d (digits) \b (word boundaries) and much more without affecting other systems.

<rdar://problem/12082562>


Modified:
    lldb/trunk/include/lldb/Core/RegularExpression.h
    lldb/trunk/include/lldb/Interpreter/OptionValueRegex.h
    lldb/trunk/source/Core/RegularExpression.cpp
    lldb/trunk/source/Host/common/FileSpec.cpp
    lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
    lldb/trunk/source/Interpreter/OptionValueRegex.cpp
    lldb/trunk/source/Interpreter/Property.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
    lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/include/lldb/Core/RegularExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegularExpression.h?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegularExpression.h (original)
+++ lldb/trunk/include/lldb/Core/RegularExpression.h Wed Jan 21 15:51:02 2015
@@ -121,23 +121,6 @@ public:
     //------------------------------------------------------------------
     RegularExpression ();
 
-    //------------------------------------------------------------------
-    /// Constructor that takes a regular expression with flags.
-    ///
-    /// Constructor that compiles \a re using \a flags and stores the
-    /// resulting compiled regular expression into this object.
-    ///
-    /// @param[in] re
-    ///     A c string that represents the regular expression to
-    ///     compile.
-    ///
-    /// @param[in] flags
-    ///     Flags that are passed to the \c regcomp() function.
-    //------------------------------------------------------------------
-    explicit
-    RegularExpression (const char* re, int flags);
-
-    // This one uses flags = REG_EXTENDED.
     explicit
     RegularExpression (const char* re);
 
@@ -157,7 +140,7 @@ public:
     /// Compile a regular expression.
     ///
     /// Compile a regular expression using the supplied regular
-    /// expression text and flags. The compiled regular expression lives
+    /// expression text. The compiled regular expression lives
     /// in this object so that it can be readily used for regular
     /// expression matches. Execute() can be called after the regular
     /// expression is compiled. Any previously compiled regular
@@ -167,9 +150,6 @@ public:
     ///     A NULL terminated C string that represents the regular
     ///     expression to compile.
     ///
-    /// @param[in] flags
-    ///     Flags that are passed to the \c regcomp() function.
-    ///
     /// @return
     ///     \b true if the regular expression compiles successfully,
     ///     \b false otherwise.
@@ -177,9 +157,6 @@ public:
     bool
     Compile (const char* re);
 
-    bool
-    Compile (const char* re, int flags);
-
     //------------------------------------------------------------------
     /// Executes a regular expression.
     ///
@@ -187,8 +164,7 @@ public:
     /// expression that is already in this object against the match
     /// string \a s. If any parens are used for regular expression
     /// matches \a match_count should indicate the number of regmatch_t
-    /// values that are present in \a match_ptr. The regular expression
-    /// will be executed using the \a execute_flags
+    /// values that are present in \a match_ptr.
     ///
     /// @param[in] string
     ///     The string to match against the compile regular expression.
@@ -198,15 +174,12 @@ public:
     ///     properly initialized with the desired number of maximum
     ///     matches, or NULL if no parenthesized matching is needed.
     ///
-    /// @param[in] execute_flags
-    ///     Flags to pass to the \c regexec() function.
-    ///
     /// @return
     ///     \b true if \a string matches the compiled regular
     ///     expression, \b false otherwise.
     //------------------------------------------------------------------
     bool
-    Execute (const char* string, Match *match = NULL, int execute_flags = 0) const;
+    Execute (const char* string, Match *match = NULL) const;
 
     size_t
     GetErrorAsCString (char *err_str, size_t err_str_max_len) const;
@@ -233,12 +206,6 @@ public:
     const char*
     GetText () const;
     
-    int
-    GetCompileFlags () const
-    {
-        return m_compile_flags;
-    }
-
     //------------------------------------------------------------------
     /// Test if valid.
     ///
@@ -256,7 +223,6 @@ public:
     {
         Free();
         m_re.clear();
-        m_compile_flags = 0;
         m_comp_err = 1;
     }
     
@@ -276,7 +242,6 @@ private:
     std::string m_re;   ///< A copy of the original regular expression text
     int m_comp_err;     ///< Error code for the regular expression compilation
     regex_t m_preg;     ///< The compiled regular expression
-    int     m_compile_flags; ///< Stores the flags from the last compile.
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Interpreter/OptionValueRegex.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValueRegex.h?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValueRegex.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionValueRegex.h Wed Jan 21 15:51:02 2015
@@ -24,9 +24,9 @@ namespace lldb_private {
 class OptionValueRegex : public OptionValue
 {
 public:
-    OptionValueRegex (const char *value = NULL, uint32_t regex_flags = 0) :
+    OptionValueRegex (const char *value = NULL) :
         OptionValue(),
-        m_regex (value, regex_flags)
+        m_regex (value)
     {
     }
 
@@ -75,10 +75,10 @@ public:
     }
     
     void
-    SetCurrentValue (const char *value, uint32_t regex_flags)
+    SetCurrentValue (const char *value)
     {
         if (value && value[0])
-            m_regex.Compile (value, regex_flags);
+            m_regex.Compile (value);
         else
             m_regex.Clear();
     }

Modified: lldb/trunk/source/Core/RegularExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegularExpression.cpp (original)
+++ lldb/trunk/source/Core/RegularExpression.cpp Wed Jan 21 15:51:02 2015
@@ -7,36 +7,34 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <string.h>
 #include "lldb/Core/RegularExpression.h"
 #include "llvm/ADT/StringRef.h"
-#include <string.h>
+#include "lldb/Core/Error.h"
 
-using namespace lldb_private;
 
 //----------------------------------------------------------------------
-// Default constructor
+// Enable enhanced mode if it is available. This allows for things like
+// \d for digit, \s for space, and many more, but it isn't available
+// everywhere.
 //----------------------------------------------------------------------
-RegularExpression::RegularExpression() :
-    m_re(),
-    m_comp_err (1),
-    m_preg(),
-    m_compile_flags(REG_EXTENDED)
-{
-    memset(&m_preg,0,sizeof(m_preg));
-}
+#if defined(REG_ENHANCED)
+#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED|REG_EXTENDED)
+#else
+#define DEFAULT_COMPILE_FLAGS (REG_EXTENDED)
+#endif
+
+using namespace lldb_private;
 
 //----------------------------------------------------------------------
-// Constructor that compiles "re" using "flags" and stores the
-// resulting compiled regular expression into this object.
+// Default constructor
 //----------------------------------------------------------------------
-RegularExpression::RegularExpression(const char* re, int flags) :
+RegularExpression::RegularExpression() :
     m_re(),
     m_comp_err (1),
-    m_preg(),
-    m_compile_flags(flags)
+    m_preg()
 {
     memset(&m_preg,0,sizeof(m_preg));
-    Compile(re);
 }
 
 //----------------------------------------------------------------------
@@ -46,8 +44,7 @@ RegularExpression::RegularExpression(con
 RegularExpression::RegularExpression(const char* re) :
     m_re(),
     m_comp_err (1),
-    m_preg(),
-    m_compile_flags(REG_EXTENDED)
+    m_preg()
 {
     memset(&m_preg,0,sizeof(m_preg));
     Compile(re);
@@ -56,16 +53,14 @@ RegularExpression::RegularExpression(con
 RegularExpression::RegularExpression(const RegularExpression &rhs)
 {
     memset(&m_preg,0,sizeof(m_preg));
-    Compile(rhs.GetText(), rhs.GetCompileFlags());
+    Compile(rhs.GetText());
 }
 
 const RegularExpression &
 RegularExpression::operator= (const RegularExpression &rhs)
 {
     if (&rhs != this)
-    {
-        Compile (rhs.GetText(), rhs.GetCompileFlags());
-    }
+        Compile (rhs.GetText());
     return *this;
 }
 //----------------------------------------------------------------------
@@ -94,19 +89,12 @@ RegularExpression::~RegularExpression()
 bool
 RegularExpression::Compile(const char* re)
 {
-    return Compile (re, m_compile_flags);
-}
-
-bool
-RegularExpression::Compile(const char* re, int flags)
-{
     Free();
-    m_compile_flags = flags;
     
     if (re && re[0])
     {
         m_re = re;
-        m_comp_err = ::regcomp (&m_preg, re, flags);
+        m_comp_err = ::regcomp (&m_preg, re, DEFAULT_COMPILE_FLAGS);
     }
     else
     {
@@ -126,7 +114,7 @@ RegularExpression::Compile(const char* r
 // will be executed using the "execute_flags".
 //---------------------------------------------------------------------
 bool
-RegularExpression::Execute(const char* s, Match *match, int execute_flags) const
+RegularExpression::Execute (const char* s, Match *match) const
 {
     int err = 1;
     if (s != NULL && m_comp_err == 0)
@@ -137,7 +125,7 @@ RegularExpression::Execute(const char* s
                              s,
                              match->GetSize(),
                              match->GetData(),
-                             execute_flags);
+                             0);
         }
         else
         {
@@ -145,7 +133,7 @@ RegularExpression::Execute(const char* s
                              s,
                              0,
                              NULL,
-                             execute_flags);
+                             0);
         }
     }
     

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Wed Jan 21 15:51:02 2015
@@ -1330,8 +1330,7 @@ FileSpec::IsSourceImplementationFile ()
     ConstString extension (GetFileNameExtension());
     if (extension)
     {
-        static RegularExpression g_source_file_regex ("^(c|m|mm|cpp|c\\+\\+|cxx|cc|cp|s|asm|f|f77|f90|f95|f03|for|ftn|fpp|ada|adb|ads)$",
-                                                      REG_EXTENDED | REG_ICASE);
+        static RegularExpression g_source_file_regex ("^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|[cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO][rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])$");
         return g_source_file_regex.Execute (extension.GetCString());
     }
     return false;

Modified: lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp Wed Jan 21 15:51:02 2015
@@ -111,7 +111,7 @@ CommandObjectRegexCommand::AddRegexComma
 {
     m_entries.resize(m_entries.size() + 1);
     // Only add the regular expression if it compiles
-    if (m_entries.back().regex.Compile (re_cstr, REG_EXTENDED))
+    if (m_entries.back().regex.Compile (re_cstr))
     {
         m_entries.back().command.assign (command_cstr);
         return true;

Modified: lldb/trunk/source/Interpreter/OptionValueRegex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueRegex.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueRegex.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueRegex.cpp Wed Jan 21 15:51:02 2015
@@ -62,7 +62,7 @@ OptionValueRegex::SetValueFromCString (c
 
     case eVarSetOperationReplace:
     case eVarSetOperationAssign:
-        if (m_regex.Compile (value_cstr, m_regex.GetCompileFlags()))
+        if (m_regex.Compile (value_cstr))
         {
             m_value_was_set = true;
             NotifyValueChanged();
@@ -84,5 +84,5 @@ OptionValueRegex::SetValueFromCString (c
 lldb::OptionValueSP
 OptionValueRegex::DeepCopy () const
 {
-    return OptionValueSP(new OptionValueRegex(m_regex.GetText(), m_regex.GetCompileFlags()));
+    return OptionValueSP(new OptionValueRegex(m_regex.GetText()));
 }

Modified: lldb/trunk/source/Interpreter/Property.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Property.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Property.cpp (original)
+++ lldb/trunk/source/Interpreter/Property.cpp Wed Jan 21 15:51:02 2015
@@ -129,7 +129,7 @@ Property::Property (const PropertyDefini
             // "definition.default_uint_value" is used to the regular expression flags
             // "definition.default_cstr_value" the default regular expression value
             // value.
-            m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value, definition.default_uint_value));
+            m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value));
             break;
             
         case OptionValue::eTypeSInt64:

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp Wed Jan 21 15:51:02 2015
@@ -371,7 +371,7 @@ public:
                 }
             }
 
-            static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
+            static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?");
 
             RegularExpression::Match matches(3);
 

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=226704&r1=226703&r2=226704&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Wed Jan 21 15:51:02 2015
@@ -66,8 +66,8 @@ g_properties[] =
     { "step-in-avoid-nodebug", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, step-in will not stop in functions with no debug information." },
     { "step-out-avoid-nodebug", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, when step-in/step-out/step-over leave the current frame, they will continue to step out till they come to a function with "
                                                                                     "debug information.  Passing a frame argument to step-out will override this option." },
-    { "step-avoid-regexp",  OptionValue::eTypeRegex  , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
-    { "step-avoid-libraries",  OptionValue::eTypeFileSpecList  , true , REG_EXTENDED, NULL, NULL, "A list of libraries that source stepping won't stop in." },
+    { "step-avoid-regexp",  OptionValue::eTypeRegex  , true , 0, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
+    { "step-avoid-libraries",  OptionValue::eTypeFileSpecList  , true , 0, NULL, NULL, "A list of libraries that source stepping won't stop in." },
     { "trace-thread",       OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." },
     {  NULL               , OptionValue::eTypeInvalid, false, 0    , NULL, NULL, NULL  }
 };





More information about the lldb-commits mailing list