summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Core/StringList.h24
-rw-r--r--lldb/source/Core/StringList.cpp37
2 files changed, 61 insertions, 0 deletions
diff --git a/lldb/include/lldb/Core/StringList.h b/lldb/include/lldb/Core/StringList.h
index 3e341b99407..53bdb6994a5 100644
--- a/lldb/include/lldb/Core/StringList.h
+++ b/lldb/include/lldb/Core/StringList.h
@@ -133,8 +133,15 @@ public:
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<std::string> &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 @@ public:
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<typename T> 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;
};
diff --git a/lldb/source/Core/StringList.cpp b/lldb/source/Core/StringList.cpp
index 4e07ba4a457..ce197ac7bd4 100644
--- a/lldb/source/Core/StringList.cpp
+++ b/lldb/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 <string>
@@ -305,12 +307,29 @@ StringList::operator << (const char* str)
}
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<std::string> &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 @@ StringList::AutoComplete (const char *s, StringList &matches, size_t &exact_idx)
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());
+}
OpenPOWER on IntegriCloud