Can lldb execute a command with argument contain a

2019-07-14 19:43发布

问题:

I define a new lldb command named jspatch like this:

command regex jspatch 's/(.+)/p (id)[JPEngine evaluateScript:@"%1"]/'

This command accept a string as argument.

But I can't execute a command like this?

jspatch 'var a = 10
var b = 20
a = a + b'

I just get 'var a = 10 in evaluateScript:.

But I cant pass it a string contain unescaped return char, anyone has a solution for this?

回答1:

That won't work given the way the lldb command interpreter is set up. An unescaped return currently always submits the command for parsing.

LLDB does have rigorously structured commands - where we could presumably detect that we're in the middle of an argument w/o a terminating quote when we got the return, and continue collecting the argument. But it also supports "unparsed" commands like expr and the command that handles regex alias commands where there's no requirement on the format of the command. The latter would make it pretty hard to do anything other than treat the return as a command terminator.



回答2:

Regular expression commands are not multi-line commands. So your approach of doing:

(lldb) command regex jspatch 's/(.+)/p (id)[JPEngine evaluateScript:@"%1"]/'

won't work with:

jspatch 'var a = 10
var b = 20
a = a + b'

because this will get executed as 3 separate commands:

(lldb) jspatch 'var a = 10
(lldb) var b = 20
(lldb) a = a + b'

You can run this as:

(lldb) jspatch 'var a = 10; var b = 20; a = a+b;'

Or you might be able to put newlines in as escaped sequences:

(lldb) jspatch 'var a = 10\nvar b = 20\na = a+b'

This depends on how input is parsed in [JPEngine evaluateScript:].

The best thing you can probably do is write this as a python command. See http://lldb.llvm.org/python-reference.html in the section named "CREATE A NEW LLDB COMMAND USING A PYTHON FUNCTION". This will allow you to make a new command line command that calls into a python module and runs the code. You can use the builtin "raw_input" command to fetch as many lines as you need and then run the expression from python as needed.



标签: lldb