Author: carlokok Date: Fri Sep 19 14:38:19 2014 New Revision: 218140 URL: http://llvm.org/viewvc/llvm-project?rev=218140&view=rev Log: Adds two new functions to SBTarget FindGlobalVariables and FindGlobalFunctions that lets you search by name, by regular expression and by starts with.
Modified: lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/include/lldb/Core/ModuleList.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/scripts/Python/interface/SBTarget.i lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/Core/ModuleList.cpp Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=218140&r1=218139&r2=218140&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Fri Sep 19 14:38:19 2014 @@ -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 (); Modified: lldb/trunk/include/lldb/Core/ModuleList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=218140&r1=218139&r2=218140&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ModuleList.h (original) +++ lldb/trunk/include/lldb/Core/ModuleList.h Fri Sep 19 14:38:19 2014 @@ -279,6 +279,16 @@ public: 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. /// /// @param[in] name Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=218140&r1=218139&r2=218140&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Fri Sep 19 14:38:19 2014 @@ -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 Modified: lldb/trunk/scripts/Python/interface/SBTarget.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=218140&r1=218139&r2=218140&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBTarget.i (original) +++ lldb/trunk/scripts/Python/interface/SBTarget.i Fri Sep 19 14:38:19 2014 @@ -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 Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=218140&r1=218139&r2=218140&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Fri Sep 19 14:38:19 2014 @@ -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 *nam 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 cha 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) { Modified: lldb/trunk/source/Core/ModuleList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=218140&r1=218139&r2=218140&view=diff ============================================================================== --- lldb/trunk/source/Core/ModuleList.cpp (original) +++ lldb/trunk/source/Core/ModuleList.cpp Fri Sep 19 14:38:19 2014 @@ -484,6 +484,26 @@ ModuleList::FindFunctionSymbols (const C 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, _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits