无法获取用户定义的 python gdb 命令
unable to source user defined python gdb command
我一直在关注 this 惊人的(视频)教程,使用 python
创建自定义用户定义的 GDB 命令
这是我的代码
import os
import gdb
class BugReport (gdb.Command):
"""Collect required info for a bug report"""
def __init__(self):
super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
pagination = gdb.parameter("pagination")
if pagination: gdb.execute("set pagination off")
f = open("/tmp/bugreport.txt", "w")
f.write(gdb.execute("thread apply all backtrace full", to_string=True))
f.close()
os.system("uname -a >> /tmp/bugreport.txt")
if pagination: gdb.execute("set pagination on")
BugReport()
但是当我尝试在 gdb 中获取此代码时,出现以下错误:
(gdb) source mybugreport.py
Traceback (most recent call last):
File "mybugreport.py", line 19, in <module>
BugReport()
TypeError: function missing required argument 'name' (pos 1)
我做错了什么?
what I'm doing wrong?
Python 对缩进敏感。你想要:
class BugReport (gdb.Command):
"""Collect required info for a bug report"""
def __init__(self):
super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
pagination = gdb.parameter("pagination")
...
BugReport()
我一直在关注 this 惊人的(视频)教程,使用 python
创建自定义用户定义的 GDB 命令这是我的代码
import os
import gdb
class BugReport (gdb.Command):
"""Collect required info for a bug report"""
def __init__(self):
super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
pagination = gdb.parameter("pagination")
if pagination: gdb.execute("set pagination off")
f = open("/tmp/bugreport.txt", "w")
f.write(gdb.execute("thread apply all backtrace full", to_string=True))
f.close()
os.system("uname -a >> /tmp/bugreport.txt")
if pagination: gdb.execute("set pagination on")
BugReport()
但是当我尝试在 gdb 中获取此代码时,出现以下错误:
(gdb) source mybugreport.py
Traceback (most recent call last):
File "mybugreport.py", line 19, in <module>
BugReport()
TypeError: function missing required argument 'name' (pos 1)
我做错了什么?
what I'm doing wrong?
Python 对缩进敏感。你想要:
class BugReport (gdb.Command):
"""Collect required info for a bug report"""
def __init__(self):
super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
pagination = gdb.parameter("pagination")
...
BugReport()