gdb - frame decorator example

The FrameDecorator example given in the documentation does not work?

If you naïvely try the implement your own MyFrameFilter following the example of the InlineFilter given in the gdb (holy?) documentation [1], you may face the following python errors.

Import issue

  class MyFrameDecorator(FrameDecorator):
TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)

According to this answer [2], This means that you are trying to inherit from a module, not from a class.

Use from gdb.FrameDecorator import FrameDecorator or gdb.FrameDecorator.FrameDecorator.

Missing member issue

Python Exception <type 'exceptions.NameError'> global name 'fobj' is not defined

fobj was not saved in the class in the constructor.

Add self.fobj = fobj.

Complete example

# Based on:

import gdb
from gdb.FrameDecorator import FrameDecorator
import itertools

class MyFrameDecorator(FrameDecorator):

    def __init__(self, fobj):
        super(self.__class__, self).__init__(fobj)
        self.fobj = fobj

    def function(self):
        frame = self.fobj.inferior_frame()
        name = str(

        return name

class MyFrameFilter():

    def __init__(self):
        # Frame filter attribute creation.
        # 'name' is the name of the filter that GDB will display.
        # 'priority' is the priority of the filter relative to other
        # filters.
        # 'enabled' is a boolean that indicates whether this filter is
        # enabled and should be executed. = "my_filter"
        self.priority = 100
        self.enabled = True

        # Register this frame filter with the global frame_filters
        # dictionary.
        gdb.frame_filters[] = self

    def filter(self, frame_iter):
        frame_iter = itertools.imap(MyFrameDecorator, frame_iter)

        # Just return the original iterator.
        return frame_iter
# gdbinit
source /mnt/data/gdb/
python MyFrameFilter()


Use info frame-filter to check whether the new python filter was successfully registered.


[1]gdb documentation, Writing a Frame Filter,
[2]Andrea Corbellini, stackoverflow answer,