GDB Frame Filter - handling corrupt stack

Simeon S simeon.simeonov.s@gmail.com
Tue Sep 9 12:26:00 GMT 2014


Hi all,

I am trying to decorate the output of "backtrace" command. I have
written a simple gdb Frame Filter coupled with a Frame Decorator. I
have followed the official documentation tutorial
(https://sourceware.org/gdb/current/onlinedocs/gdb/Writing-a-Frame-Filter.html#Writing-a-Frame-Filter).
My gdb is compiled against Python 3.3.2 and my code looks like this:



    import gdb
    import itertools
    from gdb.FrameDecorator import FrameDecorator
    import copy

    class UpperCase_Decorator (FrameDecorator):
        def __init__(self, fobj):
            super(UpperCase_Decorator, self).__init__(fobj)
            self.fobj = fobj

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

            if not frame.is_valid():
                return ""

            name = str(frame.name()).upper()
            return name


    class InlineFilter():
        def __init__(self):
            self.name = "InlinedFrameFilter"
            self.priority = 100
            self.enabled = True
            gdb.frame_filters[self.name] = self

        def filter(self, frame_iter):
            frame_iter = map(UpperCase_Decorator,
                             frame_iter)
            print(type(frame_iter))
            return frame_iter

    ff = InlineFilter()



When the gdb "backtrace" command is issued, frames are decorated
followed by a gdb crash. This is what the last output from gdb is:

    UNIX ERR:tcsetattr:Input/output error
    Segmentation fault (core dumped)

The stack seems to be corrupt which is what I suspect is causing the
crash. If the frame filter is disabled, the last line of the
"backtrace" command is:

    Backtrace stopped: previous frame inner to this frame (corrupt stack?)

I haven't looked into why the stack is corrupt - all the frames of
interest to me are there.  Is there a way to catch this condition to
avoid crashing? I am not interested in any of the corrupt frames -
what is in the stack is enough.

I guess I am looking for a mechanism to stop gdb iterating over
further frames if it detects a corrupt/invalid frame.  The
documentation does say that gdb has to iterate over all stack frames
though.

Regards,
Simeon



More information about the Gdb mailing list