[Lldb-commits] [PATCH] D59779: [Args] Handle backticks

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 25 09:49:53 PDT 2019


JDevlieghere created this revision.
JDevlieghere added reviewers: labath, zturner, davide.
Herald added a subscriber: jdoerfert.
Herald added a project: LLDB.

Currently LLDB crashes when autocompleting a command that ends with a backtick.

   ./bin/lldb test.tmp.out
  (lldb) target create "test.tmp.out"
  Current executable set to 'test.tmp.out' (x86_64).
  (lldb) b main
  Breakpoint 1: where = TestGDBRemoteRepro.test.tmp.out`main + 22 at simple.c:16:5, address = 0x0000000100000f76
  (lldb) r
  Process 66563 launched: 'test.tmp.out' (x86_64)
  Process 66563 stopped
  * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
      frame #0: 0x0000000100000f76 TestGDBRemoteRepro.test.tmp.out`main(argc=1, argv=0x00007ffeefbff608) at simple.c:16:5
     13   }
     14
     15   int main (int argc, char const *argv[]) {
  -> 16       foo();
     17       return 0;
     18   }
  (lldb) bt`Assertion failed: (false && "Unhandled quote character"), function EscapeLLDBCommandArgument, file /Users/jonas/llvm/git-mono/llvm-project/llvm/tools/lldb/source/Utility/Args.cpp, line 650.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D59779

Files:
  lldb/source/Utility/Args.cpp
  lldb/unittests/Utility/ArgsTest.cpp


Index: lldb/unittests/Utility/ArgsTest.cpp
===================================================================
--- lldb/unittests/Utility/ArgsTest.cpp
+++ lldb/unittests/Utility/ArgsTest.cpp
@@ -188,3 +188,29 @@
   EXPECT_STREQ("foo", ref[0]);
   EXPECT_STREQ("bar", ref[1]);
 }
+
+TEST(ArgsTest, EscapeLLDBCommandArgument) {
+  const std::string foo = "foo'";
+  EXPECT_EQ("foo\\'", Args::EscapeLLDBCommandArgument(foo, '\0'));
+  EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '\''));
+  EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '`'));
+  EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '"'));
+
+  const std::string bar = "bar\"";
+  EXPECT_EQ("bar\\\"", Args::EscapeLLDBCommandArgument(bar, '\0'));
+  EXPECT_EQ("bar\"", Args::EscapeLLDBCommandArgument(bar, '\''));
+  EXPECT_EQ("bar\"", Args::EscapeLLDBCommandArgument(bar, '`'));
+  EXPECT_EQ("bar\\\"", Args::EscapeLLDBCommandArgument(bar, '"'));
+
+  const std::string baz = "baz`";
+  EXPECT_EQ("baz\\`", Args::EscapeLLDBCommandArgument(baz, '\0'));
+  EXPECT_EQ("baz`", Args::EscapeLLDBCommandArgument(baz, '\''));
+  EXPECT_EQ("baz`", Args::EscapeLLDBCommandArgument(baz, '`'));
+  EXPECT_EQ("baz\\`", Args::EscapeLLDBCommandArgument(baz, '"'));
+
+  const std::string quux = "quux\t";
+  EXPECT_EQ("quux\\\t", Args::EscapeLLDBCommandArgument(quux, '\0'));
+  EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '\''));
+  EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '`'));
+  EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '"'));
+}
Index: lldb/source/Utility/Args.cpp
===================================================================
--- lldb/source/Utility/Args.cpp
+++ lldb/source/Utility/Args.cpp
@@ -640,14 +640,15 @@
   case '\0':
     chars_to_escape = " \t\\'\"`";
     break;
-  case '\'':
-    chars_to_escape = "";
-    break;
   case '"':
     chars_to_escape = "$\"`\\";
     break;
+  case '`':
+  case '\'':
+    return arg;
   default:
     assert(false && "Unhandled quote character");
+    return arg;
   }
 
   std::string res;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59779.192131.patch
Type: text/x-patch
Size: 2071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190325/18cad5bb/attachment.bin>


More information about the lldb-commits mailing list