From patchwork Fri May 23 01:30:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 1087 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id B8B3936007A for ; Thu, 22 May 2014 18:33:31 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14314964) id 4E6265B7BF96; Thu, 22 May 2014 18:33:31 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 160125B7BF8B for ; Thu, 22 May 2014 18:33:31 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=ci6v4KqosvNO+feR QvTJPw4prrPMH8rsJmTeW2LhyyOPtuaCH0MQTV+X1pAi6ssLtlDshgh3WPWkj8w9 kxwnvOCDD6mSANUKRp9sz/3HfJdX5zzniHsGW/TCxEa+86X6h7t5QKfW7jMt9cKX IL3iWkii56DX4cKvKhQLLsmJxgw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=default; bh=/8cWDddJtg9n+de8AYS0gu FvQ4o=; b=mQROpn/NF62W3vxpDxhjuw4yd65Z0KgGqgbRmnsUhLdeGzmcJ2uViQ qsDxqVmsuzEtCym2xA/ETfuw4DeKGEorBHH38B9JxHFwO6zYVkLtfcSBw2UYXgiZ a+iLgn0GJguDsYQrws+/JGMCi2gWn9trzOwL1r2whHUprmWSZ+Bc8= Received: (qmail 18337 invoked by alias); 23 May 2014 01:33:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18323 invoked by uid 89); 23 May 2014 01:33:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 23 May 2014 01:33:25 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WneML-0006OG-VR from Yao_Qi@mentor.com ; Thu, 22 May 2014 18:33:22 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 22 May 2014 18:33:21 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Thu, 22 May 2014 18:32:36 -0700 Message-ID: <537EA4D2.2060302@codesourcery.com> Date: Fri, 23 May 2014 09:30:58 +0800 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Tom Tromey CC: Subject: Re: [PATCH 03/12] Iterate over 'struct varobj_item' instead of PyObject References: <1392367471-13527-1-git-send-email-yao@codesourcery.com> <1392367471-13527-4-git-send-email-yao@codesourcery.com> <87oayrj9j6.fsf@fleche.redhat.com> In-Reply-To: <87oayrj9j6.fsf@fleche.redhat.com> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in On 05/22/2014 02:01 AM, Tom Tromey wrote: > Yao> - if (!gdb_python_initialized) > Yao> - return 0; > > Where is this check done now? I couldn't find the location. > Good catch. > IIRC this check was added in response to some bug report; I think it > only arises if Python can't be properly initialized somehow. > > If it was dropped I think it may need to be reinstated somewhere. It should be moved to 'next' method of python varobj iterator, because update_dynamic_varobj_children is independent of python, and all python related code should be moved to python varobj iterator. At the beginning of update_dynamic_varobj_children, if (update_children || var->dynamic->child_iter == NULL) { varobj_iter_delete (var->dynamic->child_iter); var->dynamic->child_iter = varobj_get_iterator (var, var->root->lang_ops); varobj_clear_saved_item (var->dynamic); i = 0; if (var->dynamic->child_iter == NULL) return 0; } else i = VEC_length (varobj_p, var->children); if gdb_python_initialized is false, varobj_get_iterator returns NULL and update_dynamic_varobj_children returns zero too. The behaviour is unchanged. diff --git a/gdb/python/py-varobj.c b/gdb/python/py-varobj.c index 50bea40..40b28f4 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -53,6 +53,12 @@ py_varobj_iter_next (struct varobj_iter *self) struct py_varobj_iter *t = (struct py_varobj_iter *) self; struct cleanup *back_to; PyObject *item; + PyObject *py_v; + varobj_item *vitem; + const char *name = NULL; + + if (!gdb_python_initialized) + return NULL; back_to = varobj_ensure_python_env (self->var); @@ -100,9 +106,21 @@ py_varobj_iter_next (struct varobj_iter *self) } } + if (!PyArg_ParseTuple (item, "sO", &name, &py_v)) + { + gdbpy_print_stack (); + error (_("Invalid item from the child list")); + } + + vitem = xmalloc (sizeof *vitem); + vitem->value = convert_value_from_python (py_v); + if (vitem->value == NULL) + gdbpy_print_stack (); + vitem->name = xstrdup (name); + self->next_raw_index++; do_cleanups (back_to); - return item; + return vitem; } /* The 'vtable' of pretty-printed python varobj iterators. */ diff --git a/gdb/varobj-iter.h b/gdb/varobj-iter.h index 3a530bc..9eb672d 100644 --- a/gdb/varobj-iter.h +++ b/gdb/varobj-iter.h @@ -14,9 +14,18 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -struct varobj_iter_ops; +/* A node or item of varobj, composed of the name and the value. */ + +typedef struct varobj_item +{ + /* Name of this item. */ + char *name; -typedef PyObject varobj_item; + /* Value of this item. */ + struct value *value; +} varobj_item; + +struct varobj_iter_ops; /* A dynamic varobj iterator "class". */ diff --git a/gdb/varobj.c b/gdb/varobj.c index 02cce5a..7e8b364 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -33,6 +33,7 @@ #include "vec.h" #include "gdbthread.h" #include "inferior.h" +#include "varobj-iter.h" #if HAVE_PYTHON #include "python/python.h" @@ -41,8 +42,6 @@ typedef int PyObject; #endif -#include "varobj-iter.h" - /* Non-zero if we want to see trace of varobj level stuff. */ unsigned int varobjdebug = 0; @@ -110,17 +109,6 @@ struct varobj_root struct varobj_root *next; }; -/* A node or item of varobj, composed of the name and the value. */ - -struct varobj_item -{ - /* Name of this item. */ - char *name; - - /* Value of this item. */ - struct value *value; -}; - /* Dynamic part of varobj. */ struct varobj_dynamic @@ -788,6 +776,18 @@ varobj_get_iterator (struct varobj *var) requested an iterator from a non-dynamic varobj")); } +/* Release and clear VAR's saved item, if any. */ + +static void +varobj_clear_saved_item (struct varobj_dynamic *var) +{ + if (var->saved_item != NULL) + { + value_free (var->saved_item->value); + xfree (var->saved_item); + var->saved_item = NULL; + } +} #endif static int @@ -802,14 +802,8 @@ update_dynamic_varobj_children (struct varobj *var, int to) { #if HAVE_PYTHON - struct cleanup *back_to; int i; - if (!gdb_python_initialized) - return 0; - - back_to = varobj_ensure_python_env (var); - *cchanged = 0; if (update_children || var->dynamic->child_iter == NULL) @@ -817,16 +811,12 @@ update_dynamic_varobj_children (struct varobj *var, varobj_iter_delete (var->dynamic->child_iter); var->dynamic->child_iter = varobj_get_iterator (var); - Py_XDECREF (var->dynamic->saved_item); - var->dynamic->saved_item = NULL; + varobj_clear_saved_item (var->dynamic); i = 0; if (var->dynamic->child_iter == NULL) - { - do_cleanups (back_to); - return 0; - } + return 0; } else i = VEC_length (varobj_p, var->children); @@ -835,10 +825,10 @@ update_dynamic_varobj_children (struct varobj *var, are more children. */ for (; to < 0 || i < to + 1; ++i) { - PyObject *item; + varobj_item *item; /* See if there was a leftover from last time. */ - if (var->dynamic->saved_item) + if (var->dynamic->saved_item != NULL) { item = var->dynamic->saved_item; var->dynamic->saved_item = NULL; @@ -846,6 +836,10 @@ update_dynamic_varobj_children (struct varobj *var, else { item = varobj_iter_next (var->dynamic->child_iter); + /* Release vitem->value so its lifetime is not bound to the + execution of a command. */ + if (item != NULL && item->value != NULL) + release_value_or_incref (item->value); } if (item == NULL) @@ -858,36 +852,19 @@ update_dynamic_varobj_children (struct varobj *var, /* We don't want to push the extra child on any report list. */ if (to < 0 || i < to) { - PyObject *py_v; - const char *name; - struct varobj_item varobj_item; - struct cleanup *inner; int can_mention = from < 0 || i >= from; - inner = make_cleanup_py_decref (item); - - if (!PyArg_ParseTuple (item, "sO", &name, &py_v)) - { - gdbpy_print_stack (); - error (_("Invalid item from the child list")); - } - - varobj_item.value = convert_value_from_python (py_v); - if (varobj_item.value == NULL) - gdbpy_print_stack (); - varobj_item.name = xstrdup (name); - install_dynamic_child (var, can_mention ? changed : NULL, can_mention ? type_changed : NULL, can_mention ? new : NULL, can_mention ? unchanged : NULL, can_mention ? cchanged : NULL, i, - &varobj_item); - do_cleanups (inner); + item); + + xfree (item); } else { - Py_XDECREF (var->dynamic->saved_item); var->dynamic->saved_item = item; /* We want to truncate the child list just before this @@ -913,7 +890,6 @@ update_dynamic_varobj_children (struct varobj *var, var->num_children = VEC_length (varobj_p, var->children); - do_cleanups (back_to); return 1; #else gdb_assert_not_reached ("should never be called if Python is not enabled"); @@ -2191,12 +2167,12 @@ free_variable (struct varobj *var) Py_XDECREF (var->dynamic->constructor); Py_XDECREF (var->dynamic->pretty_printer); - Py_XDECREF (var->dynamic->child_iter); - Py_XDECREF (var->dynamic->saved_item); do_cleanups (cleanup); } #endif + varobj_iter_delete (var->dynamic->child_iter); + varobj_clear_saved_item (var->dynamic); value_free (var->value); /* Free the expression if this is a root variable. */