From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25466 invoked by alias); 2 Aug 2012 16:21:40 -0000 Received: (qmail 25453 invoked by uid 22791); 2 Aug 2012 16:21:38 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_DB X-Spam-Check-By: sourceware.org Received: from mail-bk0-f41.google.com (HELO mail-bk0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Aug 2012 16:21:24 +0000 Received: by bkcjc3 with SMTP id jc3so4125430bkc.0 for ; Thu, 02 Aug 2012 09:21:23 -0700 (PDT) Received: by 10.204.152.220 with SMTP id h28mr8511622bkw.30.1343924482922; Thu, 02 Aug 2012 09:21:22 -0700 (PDT) Received: from [10.0.0.6] (188-22-41-65.adsl.highway.telekom.at. [188.22.41.65]) by mx.google.com with ESMTPS id ht18sm3715836bkc.16.2012.08.02.09.21.21 (version=SSLv3 cipher=OTHER); Thu, 02 Aug 2012 09:21:22 -0700 (PDT) Message-ID: <501AA900.8020205@googlemail.com> Date: Thu, 02 Aug 2012 16:21:00 -0000 From: Oliver Buchtala User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: patch for #14363 Content-Type: multipart/mixed; boundary="------------040103020802060204020509" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00078.txt.bz2 This is a multi-part message in MIME format. --------------040103020802060204020509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 832 Hello, this patch can be used to achieve a workaround to bug http://sourceware.org/bugzilla/show_bug.cgi?id=14363 Besides being a workaround, it also is a new feature, enabling a pretty-printer to control the pretty-printing on deeper recursion levels. The bug: Structures/classes which produce cyclic reference lead to an infinite recursion on iterating children during pretty-pretting - leading to endless print and stack-overflow on gdb print. What the patch does: Before calling the pretty-printer, py-prettyprint.c:print_children() informs the pretty-printer about the current recursion level. This is done by setting a property "level" if this property exists. Changelog: 2012-08-02 Oliver Buchtala python/py-prettyprint.c: provide current recursion level to pretty printer. --------------040103020802060204020509 Content-Type: text/x-patch; name="0001-Adapt-py-prettyprint-to-inform-pretty-printer-about-.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Adapt-py-prettyprint-to-inform-pretty-printer-about-.pa"; filename*1="tch" Content-length: 2194 >From 05a921d423793db93dfead59c9fe12d342f55d75 Mon Sep 17 00:00:00 2001 From: Oliver Buchtala Date: Wed, 1 Aug 2012 21:59:43 +0200 Subject: [PATCH] Adapt py-prettyprint to inform pretty-printer about current recursion level. --- gdb/python/py-prettyprint.c | 3 +++ gdb/python/python-internal.h | 1 + gdb/python/python.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 86d4f2c..d5c6b66 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -476,6 +476,9 @@ print_children (PyObject *printer, const char *hint, if (! PyObject_HasAttr (printer, gdbpy_children_cst)) return; + if ( PyObject_HasAttr (printer, gdbpy_level_cst)) + PyObject_SetAttr(printer, gdbpy_level_cst, PyInt_FromLong((long) recurse)); + /* If we are printing a map or an array, we want some special formatting. */ is_map = hint && ! strcmp (hint, "map"); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index bae61c2..e600632 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -328,6 +328,7 @@ extern PyObject *gdbpy_to_string_cst; extern PyObject *gdbpy_display_hint_cst; extern PyObject *gdbpy_enabled_cst; extern PyObject *gdbpy_value_cst; +extern PyObject *gdbpy_level_cst; /* Exception types. */ extern PyObject *gdbpy_gdb_error; diff --git a/gdb/python/python.c b/gdb/python/python.c index c66efe4..ae9e530 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -82,6 +82,7 @@ PyObject *gdbpy_display_hint_cst; PyObject *gdbpy_doc_cst; PyObject *gdbpy_enabled_cst; PyObject *gdbpy_value_cst; +PyObject *gdbpy_level_cst; /* The GdbError exception. */ PyObject *gdbpy_gdberror_exc; @@ -1305,6 +1306,7 @@ message == an error message without a stack will be printed."), gdbpy_doc_cst = PyString_FromString ("__doc__"); gdbpy_enabled_cst = PyString_FromString ("enabled"); gdbpy_value_cst = PyString_FromString ("value"); + gdbpy_level_cst = PyString_FromString ("level"); /* Release the GIL while gdb runs. */ PyThreadState_Swap (NULL); -- 1.7.9.5 --------------040103020802060204020509--