From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18463 invoked by alias); 10 Aug 2010 10:57:13 -0000 Received: (qmail 18451 invoked by uid 22791); 10 Aug 2010 10:57:11 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from atlantis.wh2.tu-dresden.de (HELO atlantis.wh2.tu-dresden.de) (141.30.228.39) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Aug 2010 10:57:06 +0000 Received: from [141.30.223.201] (x0862b.wh5.tu-dresden.de [141.30.223.201]) by atlantis.wh2.tu-dresden.de (Postfix) with ESMTPSA id 8B7596AC01 for ; Tue, 10 Aug 2010 12:57:01 +0200 (CEST) Message-ID: <4C613080.903@wh2.tu-dresden.de> Date: Tue, 10 Aug 2010 10:57:00 -0000 From: Joachim Protze User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100515 Icedove/3.0.4 MIME-Version: 1.0 To: gdb@sourceware.org Subject: Re: Crashing gdb with python-prettyprinting References: <4C4EFC98.7080105@wh2.tu-dresden.de> <4C5FF231.7030203@zih.tu-dresden.de> In-Reply-To: <4C5FF231.7030203@zih.tu-dresden.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 X-SW-Source: 2010-08/txt/msg00055.txt.bz2 I found a little mistake in my condensed version of the python part. Appended the corrected versions. -Joachim ----------------- pptest.c ----------------- enum test_enum{ zero, one, two, three, four, five, }; typedef int testint; enum test_enum get_test_enum(int i){ return (enum test_enum)i; } int main(int argc, char* argv[]){ testint a, b, c, d, e, f; testint arr[]={0,1,2,3,4,5}; a=0; b=1; c=2; d=3; e=4; f=5; return 0; } ----------------- pptest.py ----------------- import gdb import re class pp_test: """testprinter with code interaction""" def __init__(self, id): self.id = id def to_string(self): return str(gdb.parse_and_eval("get_test_enum(%i)" % self.id)) def lookup_function (val): '''Look-up and return a pretty-printer that can print val.''' type = val.type; # If it points to a reference, get the reference. if type.code == gdb.TYPE_CODE_REF: type = type.target () typename = str(type) for function in pp_dict: if function.search (typename): result = pp_dict[function] (val) return result return None pp_dict = {} pp_dict[re.compile('^testint$')] = lambda val: pp_test(val) gdb.pretty_printers = [] gdb.pretty_printers.append (lookup_function)