From patchwork Thu May 19 03:34:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 12367 Received: (qmail 327 invoked by alias); 19 May 2016 03:34:39 -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 123727 invoked by uid 89); 19 May 2016 03:34:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, FSL_HELO_HOME, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=H*m:tromey, H*MI:tom X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 19 May 2016 03:34:24 +0000 Received: (qmail 30218 invoked by uid 0); 19 May 2016 03:34:21 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy6.mail.unifiedlayer.com with SMTP; 19 May 2016 03:34:21 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id w3aJ1s00J2f2jeq013aMSa; Wed, 18 May 2016 21:34:21 -0600 X-Authority-Analysis: v=2.1 cv=cYhB8BzM c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=PnD2wP_eR3oA:10 a=_v2sUkyEFrwA:10 a=yrkiwgmsf1kA:10 a=zstS-IiYAAAA:8 a=0FD05c-RAAAA:8 a=SRGLT1jvePSvRLSR_gkA:9 a=4G6NA9xxw8l3yy4pmD5M:22 a=l1rpMCqCXRGZwUSuRcM3:22 Received: from [71.215.116.141] (port=40696 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1b3Ej4-0002rJ-42; Wed, 18 May 2016 21:34:18 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Fix PR python/19438, PR python/18393 - initialize dictionaries Date: Wed, 18 May 2016 21:34:09 -0600 Message-Id: <1463628849-311-1-git-send-email-tom@tromey.com> X-Identified-User: {36111:box522.bluehost.com:elynrobi:tromey.com} {sentby:smtp auth 71.215.116.141 authed with tom+tromey.com} This fixes PR python/19438 and PR python/18393. Both bugs are about invoking dir() on some Python object implemented by gdb, and getting a crash. The crash happens because the dictionary field of these objects was not initialized. Apparently what happens is that this field can be lazily initialized by Python when assigning to an attribute; and it can also be handled ok when using dir() but without __dict__ defined; but gdb defines __dict__ because this isn't supplied automatically by Python. The docs on this seem rather sparse, but this patch works ok. An alternative might be to lazily create the dictionary in gdb_py_generic_dict, but I went with this approach because it seemed more straightforward. Built and regtested on x86-64 Fedora 23. 2016-05-18 Tom Tromey PR python/19438, PR python/18393: * python/py-objfile.c (objfpy_initialize): Initialize self->dict. * python/py-progspace.c (pspy_initialize): Initialize self->dict. 2016-05-18 Tom Tromey PR python/19438, PR python/18393: * gdb.python/py-progspace.exp: Add "dir" test. * gdb.python/py-objfile.exp: Add "dir" test. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-objfile.c | 5 ++++- gdb/python/py-progspace.c | 5 ++++- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-objfile.exp | 2 ++ gdb/testsuite/gdb.python/py-progspace.exp | 2 ++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 92024b6..7da1385 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2016-05-18 Tom Tromey + PR python/19438, PR python/18393: + * python/py-objfile.c (objfpy_initialize): Initialize self->dict. + * python/py-progspace.c (pspy_initialize): Initialize self->dict. + +2016-05-18 Tom Tromey + * rust-lang.c (rust_subscript): Initialize "high". 2016-05-17 Simon Marchi diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index cd26c5b..82df4b2 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -196,7 +196,10 @@ static int objfpy_initialize (objfile_object *self) { self->objfile = NULL; - self->dict = NULL; + + self->dict = PyDict_New (); + if (self->dict == NULL) + return 0; self->printers = PyList_New (0); if (self->printers == NULL) diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index e1258c7..6fc53cb 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -97,7 +97,10 @@ static int pspy_initialize (pspace_object *self) { self->pspace = NULL; - self->dict = NULL; + + self->dict = PyDict_New (); + if (self->dict == NULL) + return 0; self->printers = PyList_New (0); if (self->printers == NULL) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a773c63..c813436 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-05-18 Tom Tromey + + PR python/19438, PR python/18393: + * gdb.python/py-progspace.exp: Add "dir" test. + * gdb.python/py-objfile.exp: Add "dir" test. + 2016-05-18 Simon Marchi * gdb.mi/mi-threads-interrupt.c: New file. diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 1bbb4cf..62ca309 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -45,6 +45,8 @@ gdb_test "python print (objfile.filename)" "${testfile}" \ gdb_test "python print (objfile.username)" "${testfile}" \ "Get objfile user name" +gdb_test_no_output "python dir(objfile)" + gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \ "${testfile}" "print lookup_objfile filename" gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \ diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index 5c1db1c..396d0f2 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -37,6 +37,8 @@ gdb_test "python print (gdb.current_progspace().filename)" "None" \ "current progspace filename (None)" gdb_test "python print (gdb.progspaces())" "\\\[\\\]" +gdb_test_no_output "python dir(gdb.current_progspace())" + gdb_load ${binfile} gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \