-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathcommand.py
30 lines (27 loc) · 831 Bytes
/
command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Define a new GDB command with Python.
https://sourceware.org/gdb/onlinedocs/gdb/Commands-In-Python.html
"""
class NewCmd(gdb.Command):
# Will appear on help newcmd.
"docstring"
def __init__(self):
super().__init__(
'newcmd', # Name.
gdb.COMMAND_NONE, # Category when `help` is entered.
gdb.COMPLETE_NONE, # No autocomplete.
False # Take subcommand?
)
def invoke(self, arg, from_tty):
"""
Everything printed here to stdout is captured by `execute to_string=True`.
"""
print('newcmd')
assert type(arg) is str
print('arg = ' + arg)
print('from_tty = ' + str(from_tty))
# This already registers it.
NewCmd()
gdb.execute('help newcmd')
print()
gdb.execute('newcmd a b')