Added the ability to get error strings back from failed
lldb_private::RegularExpression compiles and matches with:
size_t
RegularExpression::GetErrorAsCString (char *err_str,
size_t err_str_max_len) const;
Added the ability to search a variable list for variables whose names match
a regular expression:
size_t
VariableList::AppendVariablesIfUnique (const RegularExpression& regex,
VariableList &var_list,
size_t& total_matches);
Also added the ability to append a variable to a VariableList only if it is
not already in the list:
bool
VariableList::AddVariableIfUnique (const lldb::VariableSP &var_sp);
Cleaned up the "frame variable" command:
- Removed the "-n NAME" option as this is the default way for the command to
work.
- Enable uniqued regex searches on variable names by fixing the "--regex RE"
command to work correctly. It will match all variables that match any
regular expressions and only print each variable the first time it matches.
- Fixed the option type for the "--regex" command to by eArgTypeRegularExpression
instead of eArgTypeCount
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@116178 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Symbol/VariableList.cpp b/source/Symbol/VariableList.cpp
index 5ee5299..75106ff 100644
--- a/source/Symbol/VariableList.cpp
+++ b/source/Symbol/VariableList.cpp
@@ -8,6 +8,8 @@
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/VariableList.h"
+
+#include "lldb/Core/RegularExpression.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/CompileUnit.h"
@@ -30,13 +32,22 @@
{
}
-
void
-VariableList::AddVariable(const VariableSP &variable_sp)
+VariableList::AddVariable(const VariableSP &var_sp)
{
- m_variables.push_back(variable_sp);
+ m_variables.push_back(var_sp);
}
+bool
+VariableList::AddVariableIfUnique (const lldb::VariableSP &var_sp)
+{
+ if (FindVariableIndex (var_sp) == UINT32_MAX)
+ {
+ m_variables.push_back(var_sp);
+ return true;
+ }
+ return false;
+}
void
VariableList::AddVariables(VariableList *variable_list)
@@ -46,25 +57,32 @@
back_inserter(m_variables)); // destination
}
-
void
VariableList::Clear()
{
m_variables.clear();
}
-
-
VariableSP
VariableList::GetVariableAtIndex(uint32_t idx)
{
- VariableSP variable_sp;
+ VariableSP var_sp;
if (idx < m_variables.size())
- variable_sp = m_variables[idx];
- return variable_sp;
+ var_sp = m_variables[idx];
+ return var_sp;
}
-
+uint32_t
+VariableList::FindVariableIndex (const VariableSP &var_sp)
+{
+ iterator pos, end = m_variables.end();
+ for (pos = m_variables.begin(); pos != end; ++pos)
+ {
+ if (pos->get() == var_sp.get())
+ return std::distance (m_variables.begin(), pos);
+ }
+ return UINT32_MAX;
+}
VariableSP
VariableList::FindVariable(const ConstString& name)
@@ -82,6 +100,25 @@
return var_sp;
}
+size_t
+VariableList::AppendVariablesIfUnique (const RegularExpression& regex, VariableList &var_list, size_t& total_matches)
+{
+ const size_t initial_size = var_list.GetSize();
+ iterator pos, end = m_variables.end();
+ for (pos = m_variables.begin(); pos != end; ++pos)
+ {
+ if (regex.Execute ((*pos)->GetName().AsCString()))
+ {
+ // Note the total matches found
+ total_matches++;
+ // Only add this variable if it isn't already in the "var_list"
+ var_list.AddVariableIfUnique (*pos);
+ }
+ }
+ // Return the number of new unique variables added to "var_list"
+ return var_list.GetSize() - initial_size;
+}
+
uint32_t
VariableList::FindIndexForVariable (Variable* variable)
{
@@ -113,7 +150,6 @@
return m_variables.size();
}
-
void
VariableList::Dump(Stream *s, bool show_context) const
{