1

I've been following this amazing (video) tutorial to create custom user defined GDB command using python

here is my code

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()

but when I try to source this code inside gdb I get following error:

(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?

1 Answer 1

1

what I'm doing wrong?

Python is indentation-sensitive. You want:

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.