summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Core/RegularExpression.h69
-rw-r--r--lldb/source/Core/ConnectionFileDescriptor.cpp9
-rw-r--r--lldb/source/Core/Disassembler.cpp17
-rw-r--r--lldb/source/Core/RegularExpression.cpp79
-rw-r--r--lldb/source/Interpreter/Args.cpp11
-rw-r--r--lldb/source/Interpreter/CommandObjectRegexCommand.cpp6
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp11
-rw-r--r--lldb/source/Symbol/ObjectFile.cpp7
-rw-r--r--lldb/source/Symbol/Variable.cpp7
-rw-r--r--lldb/source/Target/ThreadPlanStepInRange.cpp7
10 files changed, 127 insertions, 96 deletions
diff --git a/lldb/include/lldb/Core/RegularExpression.h b/lldb/include/lldb/Core/RegularExpression.h
index 36d611eb826..eeeb914bfa9 100644
--- a/lldb/include/lldb/Core/RegularExpression.h
+++ b/lldb/include/lldb/Core/RegularExpression.h
@@ -35,6 +35,52 @@ namespace lldb_private {
class RegularExpression
{
public:
+ class Match
+ {
+ public:
+ Match (uint32_t max_matches) :
+ m_matches ()
+ {
+ if (max_matches > 0)
+ m_matches.resize(max_matches + 1);
+ }
+
+ void
+ Clear()
+ {
+ const size_t num_matches = m_matches.size();
+ regmatch_t invalid_match = { -1, -1 };
+ for (size_t i=0; i<num_matches; ++i)
+ m_matches[i] = invalid_match;
+ }
+
+ size_t
+ GetSize () const
+ {
+ return m_matches.size();
+ }
+
+ regmatch_t *
+ GetData ()
+ {
+ if (m_matches.empty())
+ return NULL;
+ return m_matches.data();
+ }
+
+ bool
+ GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const;
+
+ bool
+ GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const;
+
+ bool
+ GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const;
+
+ protected:
+
+ std::vector<regmatch_t> m_matches; ///< Where parenthesized subexpressions results are stored
+ };
//------------------------------------------------------------------
/// Default constructor.
///
@@ -115,8 +161,10 @@ public:
/// @param[in] string
/// The string to match against the compile regular expression.
///
- /// @param[in] match_count
- /// The number of regmatch_t objects in \a match_ptr
+ /// @param[in] match
+ /// A pointer to a RegularExpression::Match structure that was
+ /// 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.
@@ -126,24 +174,11 @@ public:
/// expression, \b false otherwise.
//------------------------------------------------------------------
bool
- Execute (const char* string, size_t match_count = 0, int execute_flags = 0) const;
+ Execute (const char* string, Match *match = NULL, int execute_flags = 0) const;
- bool
- ExecuteThreadSafe (const char* s,
- llvm::StringRef *matches,
- size_t num_matches,
- int execute_flags = 0) const;
size_t
GetErrorAsCString (char *err_str, size_t err_str_max_len) const;
- bool
- GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const;
-
- bool
- GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const;
-
- bool
- GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const;
//------------------------------------------------------------------
/// Free the compiled regular expression.
///
@@ -210,8 +245,6 @@ private:
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.
- mutable std::vector<regmatch_t> m_matches; ///< Where parenthesized subexpressions results are stored
-
};
} // namespace lldb_private
diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp
index cf8944a8e18..348895c18ce 100644
--- a/lldb/source/Core/ConnectionFileDescriptor.cpp
+++ b/lldb/source/Core/ConnectionFileDescriptor.cpp
@@ -53,11 +53,12 @@ DecodeHostAndPort (const char *host_and_port,
int32_t& port,
Error *error_ptr)
{
- RegularExpression regex ("([^:]+):([0-9]+)");
- if (regex.Execute (host_and_port, 2))
+ static RegularExpression g_regex ("([^:]+):([0-9]+)");
+ RegularExpression::Match regex_match(2);
+ if (g_regex.Execute (host_and_port, &regex_match))
{
- if (regex.GetMatchAtIndex (host_and_port, 1, host_str) &&
- regex.GetMatchAtIndex (host_and_port, 2, port_str))
+ if (regex_match.GetMatchAtIndex (host_and_port, 1, host_str) &&
+ regex_match.GetMatchAtIndex (host_and_port, 2, port_str))
{
port = Args::StringToSInt32 (port_str.c_str(), INT32_MIN);
if (port != INT32_MIN)
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index 3d4b7ffd19b..2a67f1db165 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -684,10 +684,11 @@ Instruction::ReadArray (FILE *in_file, Stream *out_stream, OptionValue::Type dat
if (line.size() > 0)
{
std::string value;
- RegularExpression reg_exp ("^[ \t]*([^ \t]+)[ \t]*$");
- bool reg_exp_success = reg_exp.Execute (line.c_str(), 1);
+ static RegularExpression g_reg_exp ("^[ \t]*([^ \t]+)[ \t]*$");
+ RegularExpression::Match regex_match(1);
+ bool reg_exp_success = g_reg_exp.Execute (line.c_str(), &regex_match);
if (reg_exp_success)
- reg_exp.GetMatchAtIndex (line.c_str(), 1, value);
+ regex_match.GetMatchAtIndex (line.c_str(), 1, value);
else
value = line;
@@ -752,14 +753,16 @@ Instruction::ReadDictionary (FILE *in_file, Stream *out_stream)
// Try to find a key-value pair in the current line and add it to the dictionary.
if (line.size() > 0)
{
- RegularExpression reg_exp ("^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$");
- bool reg_exp_success = reg_exp.Execute (line.c_str(), 2);
+ static RegularExpression g_reg_exp ("^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$");
+ RegularExpression::Match regex_match(2);
+
+ bool reg_exp_success = g_reg_exp.Execute (line.c_str(), &regex_match);
std::string key;
std::string value;
if (reg_exp_success)
{
- reg_exp.GetMatchAtIndex (line.c_str(), 1, key);
- reg_exp.GetMatchAtIndex (line.c_str(), 2, value);
+ regex_match.GetMatchAtIndex (line.c_str(), 1, key);
+ regex_match.GetMatchAtIndex (line.c_str(), 2, value);
}
else
{
diff --git a/lldb/source/Core/RegularExpression.cpp b/lldb/source/Core/RegularExpression.cpp
index 1f99bc745f8..731974ad76b 100644
--- a/lldb/source/Core/RegularExpression.cpp
+++ b/lldb/source/Core/RegularExpression.cpp
@@ -20,8 +20,7 @@ RegularExpression::RegularExpression() :
m_re(),
m_comp_err (1),
m_preg(),
- m_compile_flags(REG_EXTENDED),
- m_matches()
+ m_compile_flags(REG_EXTENDED)
{
memset(&m_preg,0,sizeof(m_preg));
}
@@ -125,59 +124,45 @@ RegularExpression::Compile(const char* re, int flags)
// matches "match_count" should indicate the number of regmatch_t
// values that are present in "match_ptr". The regular expression
// will be executed using the "execute_flags".
-//----------------------------------------------------------------------
-bool
-RegularExpression::Execute(const char* s, size_t num_matches, int execute_flags) const
-{
- int match_result = 1;
- if (m_comp_err == 0)
- {
- if (num_matches > 0)
- m_matches.resize(num_matches + 1);
- else
- m_matches.clear();
-
- match_result = ::regexec (&m_preg,
- s,
- m_matches.size(),
- &m_matches[0],
- execute_flags);
- }
- return match_result == 0;
-}
-
+//---------------------------------------------------------------------
bool
-RegularExpression::ExecuteThreadSafe (const char* s, llvm::StringRef *match_srefs, size_t count, int execute_flags) const
+RegularExpression::Execute(const char* s, Match *match, int execute_flags) const
{
- bool success = false;
+ int err = 1;
if (m_comp_err == 0)
{
- std::vector<regmatch_t> matches;
-
- if (match_srefs && count > 0)
- matches.resize(count + 1);
-
- success = ::regexec (&m_preg,
+ if (match)
+ {
+ err = ::regexec (&m_preg,
s,
- matches.size(),
- matches.data(),
- execute_flags) == 0;
- for (size_t i=0; i<count; ++i)
+ match->GetSize(),
+ match->GetData(),
+ execute_flags);
+ }
+ else
{
- size_t match_idx = i+1;
- if (success && matches[match_idx].rm_so < matches[match_idx].rm_eo)
- match_srefs[i] = llvm::StringRef(s + matches[match_idx].rm_so, matches[match_idx].rm_eo - matches[match_idx].rm_so);
- else
- match_srefs[i] = llvm::StringRef();
+ err = ::regexec (&m_preg,
+ s,
+ 0,
+ NULL,
+ execute_flags);
}
}
- return success;
+
+ if (err != 0)
+ {
+ // The regular expression didn't compile, so clear the matches
+ if (match)
+ match->Clear();
+ return false;
+ }
+ return true;
}
bool
-RegularExpression::GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const
+RegularExpression::Match::GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const
{
- if (idx <= m_preg.re_nsub && idx < m_matches.size())
+ if (idx < m_matches.size())
{
if (m_matches[idx].rm_eo == m_matches[idx].rm_so)
{
@@ -196,9 +181,9 @@ RegularExpression::GetMatchAtIndex (const char* s, uint32_t idx, std::string& ma
}
bool
-RegularExpression::GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const
+RegularExpression::Match::GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const
{
- if (idx <= m_preg.re_nsub && idx < m_matches.size())
+ if (idx < m_matches.size())
{
if (m_matches[idx].rm_eo == m_matches[idx].rm_so)
{
@@ -216,9 +201,9 @@ RegularExpression::GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef
}
bool
-RegularExpression::GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const
+RegularExpression::Match::GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const
{
- if (idx1 <= m_preg.re_nsub && idx1 < m_matches.size() && idx2 <= m_preg.re_nsub && idx2 < m_matches.size())
+ if (idx1 < m_matches.size() && idx2 < m_matches.size())
{
if (m_matches[idx1].rm_so == m_matches[idx2].rm_eo)
{
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index 16f26e6ef2b..c3f32c3ed1f 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -854,20 +854,21 @@ Args::StringToAddress (const ExecutionContext *exe_ctx, const char *s, lldb::add
// Since the compiler can't handle things like "main + 12" we should
// try to do this for now. The compliler doesn't like adding offsets
// to function pointer types.
- RegularExpression symbol_plus_offset_regex("^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
- if (symbol_plus_offset_regex.Execute(s, 3))
+ static RegularExpression g_symbol_plus_offset_regex("^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
+ RegularExpression::Match regex_match(3);
+ if (g_symbol_plus_offset_regex.Execute(s, &regex_match))
{
uint64_t offset = 0;
bool add = true;
std::string name;
std::string str;
- if (symbol_plus_offset_regex.GetMatchAtIndex(s, 1, name))
+ if (regex_match.GetMatchAtIndex(s, 1, name))
{
- if (symbol_plus_offset_regex.GetMatchAtIndex(s, 2, str))
+ if (regex_match.GetMatchAtIndex(s, 2, str))
{
add = str[0] == '+';
- if (symbol_plus_offset_regex.GetMatchAtIndex(s, 3, str))
+ if (regex_match.GetMatchAtIndex(s, 3, str))
{
offset = Args::StringToUInt64(str.c_str(), 0, 0, &success);
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
index 0fc454eb4da..59cf1f05fb6 100644
--- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -60,7 +60,9 @@ CommandObjectRegexCommand::DoExecute
EntryCollection::const_iterator pos, end = m_entries.end();
for (pos = m_entries.begin(); pos != end; ++pos)
{
- if (pos->regex.Execute (command, m_max_matches))
+ RegularExpression::Match regex_match(m_max_matches);
+
+ if (pos->regex.Execute (command, &regex_match))
{
std::string new_command(pos->command);
std::string match_str;
@@ -68,7 +70,7 @@ CommandObjectRegexCommand::DoExecute
size_t idx, percent_var_idx;
for (uint32_t match_idx=1; match_idx <= m_max_matches; ++match_idx)
{
- if (pos->regex.GetMatchAtIndex (command, match_idx, match_str))
+ if (regex_match.GetMatchAtIndex (command, match_idx, match_str))
{
const int percent_var_len = ::snprintf (percent_var, sizeof(percent_var), "%%%u", match_idx);
for (idx = 0; (percent_var_idx = new_command.find(percent_var, idx)) != std::string::npos; )
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
index ebfd1e0420d..73d5ff93b58 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -958,15 +958,16 @@ DWARFCompileUnit::ParseProducerInfo ()
}
else if (strstr(producer_cstr, "clang"))
{
- RegularExpression clang_regex("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)");
- if (clang_regex.Execute (producer_cstr, 3))
+ static RegularExpression g_clang_version_regex("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)");
+ RegularExpression::Match regex_match(3);
+ if (g_clang_version_regex.Execute (producer_cstr, &regex_match))
{
std::string str;
- if (clang_regex.GetMatchAtIndex (producer_cstr, 1, str))
+ if (regex_match.GetMatchAtIndex (producer_cstr, 1, str))
m_producer_version_major = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
- if (clang_regex.GetMatchAtIndex (producer_cstr, 2, str))
+ if (regex_match.GetMatchAtIndex (producer_cstr, 2, str))
m_producer_version_minor = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
- if (clang_regex.GetMatchAtIndex (producer_cstr, 3, str))
+ if (regex_match.GetMatchAtIndex (producer_cstr, 3, str))
m_producer_version_update = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
}
m_producer = eProducerClang;
diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp
index 5451f6941f7..1187e7996b3 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -517,12 +517,13 @@ bool
ObjectFile::SplitArchivePathWithObject (const char *path_with_object, FileSpec &archive_file, ConstString &archive_object, bool must_exist)
{
RegularExpression g_object_regex("(.*)\\(([^\\)]+)\\)$");
- if (g_object_regex.Execute (path_with_object, 2))
+ RegularExpression::Match regex_match(2);
+ if (g_object_regex.Execute (path_with_object, &regex_match))
{
std::string path;
std::string obj;
- if (g_object_regex.GetMatchAtIndex (path_with_object, 1, path) &&
- g_object_regex.GetMatchAtIndex (path_with_object, 2, obj))
+ if (regex_match.GetMatchAtIndex (path_with_object, 1, path) &&
+ regex_match.GetMatchAtIndex (path_with_object, 2, obj))
{
archive_file.SetFile (path.c_str(), false);
archive_object.SetCString(obj.c_str());
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 309e3926c87..3632eb86017 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -396,11 +396,12 @@ Variable::GetValuesForVariableExpressionPath (const char *variable_expr_path,
default:
{
- RegularExpression regex ("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)");
- if (regex.Execute(variable_expr_path, 1))
+ static RegularExpression g_regex ("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)");
+ RegularExpression::Match regex_match(1);
+ if (g_regex.Execute(variable_expr_path, &regex_match))
{
std::string variable_name;
- if (regex.GetMatchAtIndex(variable_expr_path, 1, variable_name))
+ if (regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name))
{
variable_list.Clear();
if (callback (baton, variable_name.c_str(), variable_list))
diff --git a/lldb/source/Target/ThreadPlanStepInRange.cpp b/lldb/source/Target/ThreadPlanStepInRange.cpp
index 36751cda58b..e6da7a037c0 100644
--- a/lldb/source/Target/ThreadPlanStepInRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepInRange.cpp
@@ -279,13 +279,16 @@ ThreadPlanStepInRange::FrameMatchesAvoidRegexp ()
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
if (log)
num_matches = 1;
- bool return_value = avoid_regexp_to_use->Execute(frame_function_name, num_matches);
+
+ RegularExpression::Match regex_match(num_matches);
+
+ bool return_value = avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
if (return_value)
{
if (log)
{
std::string match;
- avoid_regexp_to_use->GetMatchAtIndex(frame_function_name,0, match);
+ regex_match.GetMatchAtIndex(frame_function_name,0, match);
log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".",
frame_function_name,
avoid_regexp_to_use->GetText(),
OpenPOWER on IntegriCloud