Index: lldb/trunk/include/lldb/Core/StringList.h =================================================================== --- lldb/trunk/include/lldb/Core/StringList.h +++ lldb/trunk/include/lldb/Core/StringList.h @@ -133,8 +133,15 @@ operator << (const char* str); StringList& + operator << (const std::string &s); + + StringList& operator << (StringList strings); + // Copy assignment for a vector of strings + StringList& + operator = (const std::vector &rhs); + // This string list contains a list of valid auto completion // strings, and the "s" is passed in. "matches" is filled in // with zero or more string values that start with "s", and @@ -147,6 +154,23 @@ StringList &matches, size_t &exact_matches_idx) const; + // Dump the StringList to the given lldb_private::Log, `log`, one item per line. + // If given, `name` will be used to identify the start and end of the list in the output. + virtual void LogDump(Log *log, const char *name = nullptr); + + // Static helper to convert an iterable of strings to a StringList, and then + // dump it with the semantics of the `LogDump` method. + template static void LogDump(Log *log, T s_iterable, const char *name = nullptr) + { + if (!log) + return; + // Make a copy of the iterable as a StringList + StringList l{}; + for (const auto &s : s_iterable) + l << s; + + l.LogDump(log, name); + } private: STLStringArray m_strings; }; Index: lldb/trunk/source/Core/StringList.cpp =================================================================== --- lldb/trunk/source/Core/StringList.cpp +++ lldb/trunk/source/Core/StringList.cpp @@ -11,6 +11,8 @@ #include "lldb/Core/StreamString.h" #include "lldb/Host/FileSpec.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/StreamString.h" #include @@ -305,12 +307,29 @@ } StringList& +StringList::operator << (const std::string& str) +{ + AppendString(str); + return *this; +} + +StringList& StringList::operator << (StringList strings) { AppendList(strings); return *this; } +StringList& +StringList::operator = (const std::vector &rhs) +{ + Clear(); + for (const auto &s : rhs) + m_strings.push_back(s); + + return *this; +} + size_t StringList::AutoComplete (const char *s, StringList &matches, size_t &exact_idx) const { @@ -339,3 +358,21 @@ return matches.GetSize(); } +void +StringList::LogDump(Log *log, const char *name) +{ + if (!log) + return; + + StreamString strm; + if (name) + strm.Printf("Begin %s:\n", name); + for (const auto &s : m_strings) { + strm.Indent(); + strm.Printf("%s\n", s.c_str()); + } + if (name) + strm.Printf("End %s.\n", name); + + log->Debug("%s", strm.GetData()); +}