4

在 GDB 中(通常在 .gdbinit 文件中)我用来记录我添加的自定义命令,如下所示:

define parg    <-- this define my custom command
p *($arg0*)($ebp+8+(4*$arg1))     <--- what in does
end

document parg   <--- HERE IS THE COMMENT / DOCUMENTATION ON THIS CUSTOM COMMAND
Prints current function arguments

parg <type> <index>
Prints the <index>th argument of the current function as type <type>
<index> is 0-based
end 

我知道如何在 LLDB 中添加命令(命令别名 ...),但我该如何记录呢?

4

2 回答 2

3

记录命令别名没有任何余地——它们通常非常简单,在它们上运行“帮助”将显示它们扩展的内容——但如果你在 python 中定义一个命令,你可以向该命令添加文档。例如,

(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> def say_hello(debugger, command, result, dict):
...   print 'hello!'
...   description = '''This command says hello.'''
...   usage = 'usage: say_hello'
... 
>>> ^D
(lldb) command script add -f say_hello say_hello
(lldb) say_hello
hello!
(lldb) help say_hello
   Run Python function say_hello  This command takes 'raw' input (no need to quote stuff).

Syntax: say_hello
(lldb) 

请注意我在空行上按回车键的第四行“...”。

有关 lldb 中的 python 脚本的更多信息,请参阅http://lldb.llvm.org/python-reference.html

但是不,您的问题的答案是您今天不能记录命令别名。

于 2012-09-24T21:52:56.903 回答
0

您可以使用Python 参考中记录的文档字符串记录自定义 lldb 命令:

或者,您还可以提供 Python 文档字符串,LLDB 将在为您的命令提供帮助时使用它,如下所示:

(lldb) script
>>> def documented(*args):
...     '''
...     This command is documented using a docstring.
...
...     You can write anything!
...     '''
...     pass
...
>>> exit
(lldb) command script add -f documented documented
(lldb) help documented

    This command is documented using a docstring.

    You can write anything!

Syntax: documented
(lldb)
于 2015-09-29T15:07:48.000 回答