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

How to write a multi line macro in ~/.lldbinit?

我想在~/.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.

如何将宏分成多行?

lldb 没有续行符。这在一些自由格式的命令中会很棘手,尤其是 "print" 命令。但在这些情况下会有用。请随时使用 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/

不太对,在最后一次替换后输入文件中必须有一个空行以终止替换,但我无法说服此标记将其包含在代码块中。但是你明白了。

我在 .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