[Lldb-commits] [lldb] r320366 - Add a StringList constructor to Args class

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 11 06:22:30 PST 2017


Author: labath
Date: Mon Dec 11 06:22:30 2017
New Revision: 320366

URL: http://llvm.org/viewvc/llvm-project?rev=320366&view=rev
Log:
Add a StringList constructor to Args class

Host::GetEnvironment returns a StringList, but the interface for
launching a process takes Args. The fact that we use two classes for
representing an environment is not ideal, but for now we should at least
have an easy way to convert between the two.

Modified:
    lldb/trunk/include/lldb/Interpreter/Args.h
    lldb/trunk/include/lldb/Utility/StringList.h
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/unittests/Interpreter/TestArgs.cpp

Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=320366&r1=320365&r2=320366&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Mon Dec 11 06:22:30 2017
@@ -86,6 +86,7 @@ public:
   Args(llvm::StringRef command = llvm::StringRef());
 
   Args(const Args &rhs);
+  explicit Args(const StringList &list);
 
   Args &operator=(const Args &rhs);
 

Modified: lldb/trunk/include/lldb/Utility/StringList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StringList.h?rev=320366&r1=320365&r2=320366&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/StringList.h (original)
+++ lldb/trunk/include/lldb/Utility/StringList.h Mon Dec 11 06:22:30 2017
@@ -29,7 +29,7 @@ class StringList {
 public:
   StringList();
 
-  StringList(const char *str);
+  explicit StringList(const char *str);
 
   StringList(const char **strv, int strc);
 

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=320366&r1=320365&r2=320366&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Mon Dec 11 06:22:30 2017
@@ -185,6 +185,11 @@ Args::Args(llvm::StringRef command) { Se
 
 Args::Args(const Args &rhs) { *this = rhs; }
 
+Args::Args(const StringList &list) : Args() {
+  for(size_t i = 0; i < list.GetSize(); ++i)
+    AppendArgument(list[i]);
+}
+
 Args &Args::operator=(const Args &rhs) {
   Clear();
 

Modified: lldb/trunk/unittests/Interpreter/TestArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestArgs.cpp?rev=320366&r1=320365&r2=320366&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestArgs.cpp (original)
+++ lldb/trunk/unittests/Interpreter/TestArgs.cpp Mon Dec 11 06:22:30 2017
@@ -10,6 +10,7 @@
 #include "gtest/gtest.h"
 
 #include "lldb/Interpreter/Args.h"
+#include "lldb/Utility/StringList.h"
 
 #include <limits>
 #include <sstream>
@@ -117,6 +118,16 @@ TEST(ArgsTest, TestArgv) {
   EXPECT_EQ(nullptr, args.GetArgumentVector()[5]);
 }
 
+TEST(ArgsTest, StringListConstructor) {
+  StringList list;
+  list << "foo" << "bar" << "baz";
+  Args args(list);
+  ASSERT_EQ(3u, args.GetArgumentCount());
+  EXPECT_EQ("foo", args[0].ref);
+  EXPECT_EQ("bar", args[1].ref);
+  EXPECT_EQ("baz", args[2].ref);
+}
+
 TEST(ArgsTest, GetQuotedCommandString) {
   Args args;
   const char *str = "process launch -o stdout.txt -- \"a b c\"";




More information about the lldb-commits mailing list