I’ve been following this amazing (video) tutorial to create custom user defined GDB command using python
here is my code
JavaScript
x
20
20
1
import os
2
import gdb
3
4
class BugReport (gdb.Command):
5
"""Collect required info for a bug report"""
6
7
def __init__(self):
8
super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER)
9
10
def invoke(self, arg, from_tty):
11
pagination = gdb.parameter("pagination")
12
if pagination: gdb.execute("set pagination off")
13
f = open("/tmp/bugreport.txt", "w")
14
f.write(gdb.execute("thread apply all backtrace full", to_string=True))
15
f.close()
16
os.system("uname -a >> /tmp/bugreport.txt")
17
if pagination: gdb.execute("set pagination on")
18
19
BugReport()
20
but when I try to source this code inside gdb I get following error:
JavaScript
1
6
1
(gdb) source mybugreport.py
2
Traceback (most recent call last):
3
File "mybugreport.py", line 19, in <module>
4
BugReport()
5
TypeError: function missing required argument 'name' (pos 1)
6
what I’m doing wrong?
Advertisement
Answer
what I’m doing wrong?
Python is indentation-sensitive. You want:
JavaScript
1
12
12
1
class BugReport (gdb.Command):
2
"""Collect required info for a bug report"""
3
4
def __init__(self):
5
super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER)
6
7
def invoke(self, arg, from_tty):
8
pagination = gdb.parameter("pagination")
9
10
11
BugReport()
12