Adds two new functions to SBTarget FindGlobalVariables and FindGlobalFunctions that lets you search by name, by regular expression and by starts with.

llvm-svn: 218140
This commit is contained in:
Carlo Kok 2014-09-19 19:38:19 +00:00
parent 5a6edad3d8
commit 0fd6fd4fd4
6 changed files with 173 additions and 0 deletions

View File

@ -683,7 +683,47 @@ public:
//------------------------------------------------------------------
lldb::SBValue
FindFirstGlobalVariable (const char* name);
//------------------------------------------------------------------
/// Find global and static variables by pattern.
///
/// @param[in] name
/// The pattern to search for global or static variables
///
/// @param[in] max_matches
/// Allow the number of matches to be limited to \a max_matches.
///
/// @param[in] matchtype
/// The match type to use.
///
/// @return
/// A list of matched variables in an SBValueList.
//------------------------------------------------------------------
lldb::SBValueList
FindGlobalVariables(const char *name,
uint32_t max_matches,
MatchType matchtype);
//------------------------------------------------------------------
/// Find global functions by their name with pattern matching.
///
/// @param[in] name
/// The pattern to search for global or static variables
///
/// @param[in] max_matches
/// Allow the number of matches to be limited to \a max_matches.
///
/// @param[in] matchtype
/// The match type to use.
///
/// @return
/// A list of matched variables in an SBValueList.
//------------------------------------------------------------------
lldb::SBSymbolContextList
FindGlobalFunctions(const char *name,
uint32_t max_matches,
MatchType matchtype);
void
Clear ();

View File

@ -278,6 +278,16 @@ public:
uint32_t name_type_mask,
SymbolContextList& sc_list);
//------------------------------------------------------------------
/// @see Module::FindFunctions ()
//------------------------------------------------------------------
size_t
FindFunctions(const RegularExpression &name,
bool include_symbols,
bool include_inlines,
bool append,
SymbolContextList& sc_list);
//------------------------------------------------------------------
/// Find global and static variables by name.
///

View File

@ -864,6 +864,16 @@ namespace lldb {
eMemberFunctionKindStaticMethod // A function that applies to a type rather than any instance
} MemberFunctionKind;
//----------------------------------------------------------------------
// String matching algorithm used by SBTarget
//----------------------------------------------------------------------
typedef enum MatchType {
eMatchTypeNormal,
eMatchTypeRegex,
eMatchTypeStartsWith
} MatchType;
} // namespace lldb

View File

@ -113,6 +113,15 @@ public:
void
SetDetachOnError(bool enable);
lldb::SBValueList
FindGlobalVariables(const char *name,
uint32_t max_matches,
MatchType matchtype);
lldb::SBSymbolContextList
FindGlobalFunctions(const char *name,
uint32_t max_matches,
MatchType matchtype);
};
class SBAttachInfo

View File

@ -58,6 +58,7 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "../source/Commands/CommandObjectBreakpoint.h"
#include "llvm/Support/Regex.h"
using namespace lldb;
@ -2154,6 +2155,34 @@ SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
return sb_sc_list;
}
lldb::SBSymbolContextList
SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
{
lldb::SBSymbolContextList sb_sc_list;
if (name && name[0])
{
TargetSP target_sp(GetSP());
if (target_sp)
{
std::string regexstr;
switch (matchtype)
{
case eMatchTypeRegex:
target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
break;
case eMatchTypeStartsWith:
regexstr = llvm::Regex::escape(name) + ".*";
target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
break;
default:
target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
break;
}
}
}
return sb_sc_list;
}
lldb::SBType
SBTarget::FindFirstType (const char* typename_cstr)
{
@ -2321,6 +2350,61 @@ SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
return sb_value_list;
}
SBValueList
SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
{
SBValueList sb_value_list;
TargetSP target_sp(GetSP());
if (name && target_sp)
{
VariableList variable_list;
const bool append = true;
std::string regexstr;
uint32_t match_count;
switch (matchtype)
{
case eMatchTypeNormal:
match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
append,
max_matches,
variable_list);
break;
case eMatchTypeRegex:
match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
append,
max_matches,
variable_list);
break;
case eMatchTypeStartsWith:
regexstr = llvm::Regex::escape(name) + ".*";
match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
append,
max_matches,
variable_list);
break;
}
if (match_count > 0)
{
ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
if (exe_scope == NULL)
exe_scope = target_sp.get();
for (uint32_t i = 0; i<match_count; ++i)
{
lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
if (valobj_sp)
sb_value_list.Append(SBValue(valobj_sp));
}
}
}
return sb_value_list;
}
lldb::SBValue
SBTarget::FindFirstGlobalVariable (const char* name)
{

View File

@ -484,6 +484,26 @@ ModuleList::FindFunctionSymbols (const ConstString &name,
return sc_list.GetSize() - old_size;
}
size_t
ModuleList::FindFunctions(const RegularExpression &name,
bool include_symbols,
bool include_inlines,
bool append,
SymbolContextList& sc_list)
{
const size_t old_size = sc_list.GetSize();
Mutex::Locker locker(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos)
{
(*pos)->FindFunctions (name, include_symbols, include_inlines, append, sc_list);
}
return sc_list.GetSize() - old_size;
}
size_t
ModuleList::FindCompileUnits (const FileSpec &path,
bool append,