From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64100 invoked by alias); 23 Jun 2016 16:15:01 -0000 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 Received: (qmail 64083 invoked by uid 89); 23 Jun 2016 16:15:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=dereference, Hx-languages-length:2011, scripting X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 23 Jun 2016 16:14:50 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A81CC04B31C; Thu, 23 Jun 2016 16:14:49 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5NGElBx015311; Thu, 23 Jun 2016 12:14:48 -0400 Subject: Re: [PATCH] Fix use of a dangling pointer for Python breakpoint objects To: Pierre-Marie de Rodat , gdb-patches@sourceware.org References: <20160621104021.15093-1-derodat@adacore.com> From: Pedro Alves Message-ID: <02138a22-5087-44ad-6023-7c87251f3d19@redhat.com> Date: Thu, 23 Jun 2016 16:15:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20160621104021.15093-1-derodat@adacore.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-06/txt/msg00382.txt.bz2 On 06/21/2016 11:40 AM, Pierre-Marie de Rodat wrote: > Hello, > > When a Python script tries to create a breakpoint but fails to do so, > gdb.Breakpoint.__init__ raises an exception and the breakpoint does not > exist anymore in the Python interpreter. However, GDB still keeps a > reference to the Python object to be used for a later hook, which is > wrong. Urgh, this code is ugly. So the problem is that the next time gdbpy_breakpoint_created is called, for some other breakpoint, we'll dereference the dangling pointer then, correct? > + > +# Skip all tests if Python scripting is not enabled. > +if { [skip_python_tests] } { continue } > + > +gdb_test "source py-breakpoint2.py" > + > +# The following used to trigger an internal error because of a dangling > +# reference to a Python breakpoint object. > +gdb_test "start" "start" doesn't work with "target remote" testing. Try: $ make check \ RUNTESTFLAGS="--target_board=native-gdbserver" \ TESTS="gdb.python/py-breakpoint2.exp" Can we instead run to main first, and then source the python script? > + > +bp1 = gdb.Breakpoint('main', gdb.BP_BREAKPOINT) I don't understand the idea behind creating this breakpoint before the failing watchpoint one. > + > +# The following will create a breakpoint whose construction will abort (there > +# is no such symbol), so GDB should not keep a reference to the corresponding > +# Python object. > +try: > + bp2 = gdb.Breakpoint('does_not_exist', gdb.BP_WATCHPOINT) > +except RuntimeError: > + pass > +else: > + assert False Wouldn't it better to create a breakpoint after the one that failed, explicitly? Either in python, or perhaps simpler, a regular command line breakpoint directly in the .exp file. Ah, I think I see -- I guess the test is relying on "start" creating a magic breakpoint at "main", and that one being the one that dereferences the dangling pointer. But, see above about remote testing. Thanks, Pedro Alves