From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4498 invoked by alias); 9 Sep 2014 12:26:12 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 4484 invoked by uid 89); 9 Sep 2014 12:26:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f173.google.com Received: from mail-ie0-f173.google.com (HELO mail-ie0-f173.google.com) (209.85.223.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 09 Sep 2014 12:26:10 +0000 Received: by mail-ie0-f173.google.com with SMTP id x19so1383027ier.32 for ; Tue, 09 Sep 2014 05:26:08 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.136.167 with SMTP id qb7mr31613869igb.31.1410265568583; Tue, 09 Sep 2014 05:26:08 -0700 (PDT) Received: by 10.64.11.198 with HTTP; Tue, 9 Sep 2014 05:26:08 -0700 (PDT) Date: Tue, 09 Sep 2014 12:26:00 -0000 Message-ID: Subject: GDB Frame Filter - handling corrupt stack From: Simeon S To: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2014-09/txt/msg00029.txt.bz2 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