如何在〜/ .lldbinit中编写多行宏?

时间:2016-10-14 13:00:54

标签: syntax macros multiline lldb

我想在~/.lldbinit中编写此宏:

command regex pxml 's/(.+)/p xmlElemDump(stdout, %1, xmlDocGetRootElement(%1))/' -h "Dump the contents of an XML tree."

但它太长了,我想把它分成这样的多行:

command regex pxml
    's/(.+)/p xmlElemDump(stdout, %1, xmlDocGetRootElement(%1))/'
    -h "Dump the contents of an XML tree."

command regex pxml\
    's/(.+)/p xmlElemDump(stdout, %1, xmlDocGetRootElement(%1))/'\
    -h "Dump the contents of an XML tree."

不幸的是,它们都会导致此错误:

Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.
Terminate the substitution list with an empty line.

如何将宏分成多行?

2 个答案:

答案 0 :(得分:1)

lldb没有延续字符。在一些自由格式命令中,这将是棘手的,特别是“打印”命令。但在这些情况下会很有用。请随意使用lldb / llvm错误跟踪器提交请求此错误的错误:https://llvm.org/bugs/

在大多数情况下,如果某个命令有几个选项,则需要一组输入,该命令可以为该组输入输入一个小型编辑器。这适用于command regex。所以在命令行lldb中,你会看到:

(lldb) command regex whatever -h "some help" -s "some syntax"
Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.
Terminate the substitution list with an empty line.
> s/First/Replacement/ 
> s/Second/Replacement/ 
>  

同时读取.lldbinit的command source函数通过将命令文件作为流提供给解释器来工作。所以你需要模拟命令行的作用:

command regex whatever -h "some help" -s "some syntax"
s/First/Replacement/
s/Second/Replacement/

这不太正确,在最后一次替换后输入文件中必须有一个空行来终止替换,但是我不能说服这个标记将它包含在代码块中。但是你明白了。

答案 1 :(得分:0)

我在.py文件中写入别名,然后将其导入~/.lldbinit
在python文件中,我们可以使用延续字符。

例如)

您将以下代码另存为something.py

def __lldb_init_module(debugger, internal_dict):
    debugger.HandleCommand("command regex pos 's/(.*)?-op?(.*)/ exp -l swift -O  %2 -- %1/'\
                                              's/(.*)/ exp -l swift -O -- %1/'")

将此内容写在~/.lldbinit

command script import <path>/something.py