GDB Frame Filter - handling corrupt stack

Simeon S <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CAGwyPpEkdfuwFiS_afffoHk_1nGjMFjG+v3yKLhioiRyasdYyQ@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.