尽管可以通过gdb.Parameter
直接实例化并稍后添加属性来在 gdb 中创建新参数-也许有人可以回答-通常的方法是定义一个新类, 的子类gdb.Parameter
,定义必要的属性,例如set_doc
在该类中,并实例化该类。这是您的示例,已重做:
$ cat test.py
class TestParameter(gdb.Parameter):
"""Manage the test parameter.
Usage: set test filename
show test
"""
set_doc = "This is the single-line documentation for set test"
show_doc = "This is the single-line documentation for show test"
def __init__(self):
super(TestParameter, self).__init__("test", gdb.COMMAND_NONE,
gdb.PARAM_OPTIONAL_FILENAME)
self.value=""
def get_set_string(self):
return "You have set test to " + self.value
def get_show_string(self, _):
return "The value of test is " + self.value
TestParameter()
$ gdb -q
(gdb) source test.py
下面显示了各种文档字符串的显示位置和方式:
(gdb) help set test
This is the single-line documentation for set test
Manage the test parameter.
Usage: set test filename
show test
(gdb) help show test
This is the single-line documentation for show test
Manage the test parameter.
Usage: set test filename
show test
(gdb) help set
...
List of set subcommands:
...
set test -- This is the single-line documentation for set test
...
set
这是and产生的输出show
:
(gdb) set test .profile
You have set test to .profile
(gdb) show test
The value of test is .profile