[Lldb-commits] [lldb] r256927 - Add LogDump methods to lldb_private::StringList.
Ewan Crawford via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 6 03:06:31 PST 2016
Author: ewancrawford
Date: Wed Jan 6 05:06:30 2016
New Revision: 256927
URL: http://llvm.org/viewvc/llvm-project?rev=256927&view=rev
Log:
Add LogDump methods to lldb_private::StringList.
This patch eases the printing of iterable string containers.
Author: Luke Drummond <luke.drummond at codeplay.com>
Differential Revision: http://reviews.llvm.org/D15773
Modified:
lldb/trunk/include/lldb/Core/StringList.h
lldb/trunk/source/Core/StringList.cpp
Modified: lldb/trunk/include/lldb/Core/StringList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StringList.h?rev=256927&r1=256926&r2=256927&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/StringList.h (original)
+++ lldb/trunk/include/lldb/Core/StringList.h Wed Jan 6 05:06:30 2016
@@ -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;
};
Modified: lldb/trunk/source/Core/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StringList.cpp?rev=256927&r1=256926&r2=256927&view=diff
==============================================================================
--- lldb/trunk/source/Core/StringList.cpp (original)
+++ lldb/trunk/source/Core/StringList.cpp Wed Jan 6 05:06:30 2016
@@ -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,
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());
+}
More information about the lldb-commits
mailing list