[Lldb-commits] [PATCH] D26883: Demonstrate proposed new Args API

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 28 10:06:00 PST 2016

backtick parsing is currently incorrect, because it parses the backtick before doing arg parsing, which means it does the substitutions for “raw” commands:

(lldb) expr char *$foo = "some `1 + 2` string"
(lldb) expr $foo
(char *) $foo = 0x000000010032f100 "some 3 string"

That’s unexpected, and since part of the point of expr is that you can freely cut and paste from a source view into the expr command, it is not desirable.

The most straightforward way to fix this is to make backtick parsing happen as a part of argument parsing - so you would know you were in a raw command and not intervene in the input.

I actually think the full bash quoting rules are overly complex for lldb.  Greg was having fun emulating the bash syntax but that seems an unnecessarily complex model for lldb’s command line.  But that may be water under the bridge at this point.


> On Nov 22, 2016, at 2:59 AM, Pavel Labath <labath at google.com> wrote:
> labath added a comment.
> In https://reviews.llvm.org/D26883#601638, @jingham wrote:
>> The outermost quote character is syntactically significant in the lldb command language.  If you say:
>> memory read -c `count_var` 0x123345
>> then lldb evaluates the expression in the backticks, replacing the argument with the result of the expression.  So you can't get rid of the quote character altogether.  The other use is in completion to figure out what an unterminated quoted string should be completed with.
>> Since only the outermost quoting character is important, I think the problem is more tractable than your examples would suggest.
> I didn't mention backticks, as (to use bash parlor) command substitution and word splitting are two separate passes. backticks can be embedded into a single word, which also contains other kinds of quote characters, so storing the quote character alongside the word-split argument is not going to help you implement command substitution. LLDB actually handles this mostly correctly now (notice that in each case the input gets parsed as a single word):
>  (lldb) `1+1`
>  error: '2' is not a valid command.
>  error: Unrecognized command '2'.
>  (lldb) a`1+1`a
>  error: 'a2a' is not a valid command.
>  error: Unrecognized command 'a2a'.
>  (lldb) `1+1`a`2+2`
>  error: '2a4' is not a valid command.
>  error: Unrecognized command '2a4'.
>  (lldb) "a a"`1+1`"b a"
>  error: unknown command shorthand suffix: ' a'
>  error: Unrecognized command 'a a2b a'.
> The reason this works is because the command substitution is done in a different place in the code, so I still hold my view that the Args class does not need to differentiate between the different quote characters as it is just a holder for a word-split input.
> That said, none of this should affect this patch. If the quote char field has been there until now, it can stay a little longer.
> Repository:
>  rL LLVM
> https://reviews.llvm.org/D26883

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20161128/db2f2d73/attachment-0001.html>

More information about the lldb-commits mailing list