Fix handling of backslashes in Args parsing
authorPavel Labath <labath@google.com>
Mon, 2 Mar 2015 12:46:22 +0000 (12:46 +0000)
committerPavel Labath <labath@google.com>
Mon, 2 Mar 2015 12:46:22 +0000 (12:46 +0000)
commit00b7f95b122372d57b7d3f00ae435512024bb45e
treede21220b268ac58be38145b2e315040481b43080
parent2689d78909e115573d85075b5030b8acd1d14c75
Fix handling of backslashes in Args parsing

Summary:
Presently Args::SetCommandString allows quotes to be escaped with backslash. However, the
backslash itself is not removed from the argument, nor there is a way to escape the backslash
itself. This leads to surprising results:

"a b" c"   -> 'a b', 'c'  # Here we actually have an unterminated quote, but that is ignored
"a b\" c"  -> 'a b\" c'   # We try to escape the quote. That works but the backslash is not removed.
"a b\\" c" -> 'a b\\" c'  # Escaping the backslash has no effect.

This change changes quote handling to be more shell-like:
- single quotes and backquotes are literal and there is no way to escape the closing quote or
  anything else inside;
- inside double quotes you can use backslash to escape the closing quote and another backslash
- outside any quotes, you can use backslash to escape quotes, spaces and itself.

This makes the parsing more consistent with what the user is familiar and increases the
probability that pasting the command line from shell to the "process launch" command "just work".

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D7855

llvm-svn: 230955
lldb/include/lldb/Interpreter/Args.h
lldb/source/Commands/CommandObjectExpression.cpp
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/CommandObjectWatchpoint.cpp
lldb/source/Interpreter/Args.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/test/settings/quoting/Makefile [new file with mode: 0644]
lldb/test/settings/quoting/TestQuoting.py [new file with mode: 0644]
lldb/test/settings/quoting/main.c [new file with mode: 0644]