From patchwork Sat Oct 28 18:14:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0JzQsNC60YHQuNC8INCU0LfQsNCx0YDQsNC10LI=?= X-Patchwork-Id: 23950 Received: (qmail 73585 invoked by alias); 28 Oct 2017 18:14:51 -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 71483 invoked by uid 89); 28 Oct 2017 18:14:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-lf0-f49.google.com Received: from mail-lf0-f49.google.com (HELO mail-lf0-f49.google.com) (209.85.215.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 28 Oct 2017 18:14:46 +0000 Received: by mail-lf0-f49.google.com with SMTP id b190so10562690lfg.9 for ; Sat, 28 Oct 2017 11:14:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6QMCUdZ0IzZBwe1lsYBEaJU6D5ZWld/DYefpsWGEXmI=; b=OpzKv8YKtz+8vs83FI8XZvy0nmcqTjf0CehWGUbaANLEdiHYiaSz3TSPFbUy+0Lt/k QRYjEysSoMVOLBTrjqJEjgRQhcl9/xZhiKGkB6gBj21Cdn+3zFEPemgzT/6HUUAmgI3p n0M00qkCu+ZZgibYR8GcUHdRaLZT8zJsOsfswQcihEkuJZghLisPMx9kJKDrFJsMPveJ MCFj50I8S/niVQMM1RMQ1kcLcEmgrCHIThqyta4ZeEZsjcnK6Prcxzig4HTXuAL9rjyj T1tqVuWXLjgFl1iBiCGaVn9ELcCK8QpFw1rdQULMXG4IAvDLsNKb0EZucl11qNu3hZ/I zcCg== X-Gm-Message-State: AMCzsaUqtTUur/y2zRJAFRTJKUbgJpttVb3m1b9yfpcPxyFMsI+U1RSm fQ6+3IuTQZ3YWLBkMnYwoRLLBsbKu9c= X-Google-Smtp-Source: ABhQp+TQSp19bM2K41Q495ogQJonD9waDLTmwWD9l6z1cl2OVH2mbggbwp5greUPXd7fBQ+M6ywr0Q== X-Received: by 10.46.69.6 with SMTP id s6mr1714434lja.76.1509214484317; Sat, 28 Oct 2017 11:14:44 -0700 (PDT) Received: from dza-svk.tomtelnet.ru (nightik.qwertynet.ru. [79.136.160.17]) by smtp.googlemail.com with ESMTPSA id w9sm2580563ljw.49.2017.10.28.11.14.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 Oct 2017 11:14:43 -0700 (PDT) From: Maksim Dzabraev To: gdb-patches@sourceware.org Cc: simon.marchi@polymtl.ca, tom@tromey.com, dzabraew@gmail.com Subject: [PATCH] Make gdb.selected_thread().inferior return a new reference Date: Sun, 29 Oct 2017 01:14:34 +0700 Message-Id: <20171028181434.3825-1-dzabraew@gmail.com> In-Reply-To: References: thpy_get_inferior function should return a new reference to the existing inferior object, and therefore should increment its refcount. Fixed bug lokks like this. If multiple time call gdb.selected_thread ().inferior, gdb throws exception: (gdb) pi gdb.selected_thread().inferior (gdb) pi gdb.selected_thread().inferior Python Exception 'NoneType' object has no attribute 'inferior': Error while executing Python code. (gdb) info threads Id Target Id Frame * 1 Thread 0x7f54f0474740 (LWP 584) "mc" 0x00007f54ef055c33 in --- gdb/ChangeLog | 6 ++++++ gdb/python/py-infthread.c | 1 + gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-infthread.exp | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9fe632985e..4583a78fe5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2017-10-28 Maksim Dzabraev + + PR python/21213 + * python/py-infthread.c (thpy_get_inferior): Increment reference + of inferior before returning it. + 2017-10-27 Simon Marchi * unittests/common-utils-selftests.c (format): Add diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 626c15cedb..31d576f7c7 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -162,6 +162,7 @@ thpy_get_inferior (PyObject *self, void *ignore) thread_object *thread_obj = (thread_object *) self; THPY_REQUIRE_VALID (thread_obj); + Py_INCREF (thread_obj->inf_obj); return thread_obj->inf_obj; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0254a28550..72334fd3e2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-10-28 Maksim Dzabraev + + PR python/21213 + * gdb.python/py-infthread.exp: Test calling + InferiorThread.inferior () multiple times in a row. + 2017-10-27 Keith Seitz * gdb.opt/inline-break.exp (break_info_1): New procedure. diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp index 0711d6994e..69fc9709b2 100644 --- a/gdb/testsuite/gdb.python/py-infthread.exp +++ b/gdb/testsuite/gdb.python/py-infthread.exp @@ -51,6 +51,15 @@ gdb_test "python print(seen_a_thread)" "True" # Test basic gdb.Inferior attributes and methods. +# Make sure that InferiorThread.inferior returns a new reference (see PR 21213). + +gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 1" 1 +gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 2" 1 +gdb_test_no_output "python import gc; gc.collect()" "call Python garbage collection" +gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 3" 1 +gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 4" 1 + + gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1 gdb_test "python print (t0)" "\\" "verify InferiorThread object" gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num"