From patchwork Sat Oct 28 17:18:56 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: 23949 Received: (qmail 19683 invoked by alias); 28 Oct 2017 17:19:22 -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 19674 invoked by uid 89); 28 Oct 2017 17:19:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=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=Hx-languages-length:2706, 5115 X-HELO: mail-lf0-f52.google.com Received: from mail-lf0-f52.google.com (HELO mail-lf0-f52.google.com) (209.85.215.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 28 Oct 2017 17:19:20 +0000 Received: by mail-lf0-f52.google.com with SMTP id b190so10474670lfg.9 for ; Sat, 28 Oct 2017 10:19:19 -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=AiAxzWaCwdIDF+/e52mI1K9IPLhLQe4p5awitEaOPZ0=; b=ewMoJE93gLSGLRTc+tP1jCXTA+Pqo8CQgDSAqFRoMG0F9hgoJmxJ7V7ajLPtg7rS1W NpFVbJgKcJZAoWThKCVzZ1OfECpac8w/EJwsGrKqkfUb//GL4rYXZ5nNvrsywCu8mX48 dyFZ7J6t+4Y2yF+n9YQBcPyUXJUwSESyz1yDh6JuexYtD4bDwYp8AZxDd88nMLPB6AAg CJBvZCpmhsBQBfJ52DRVViXmzCleVwCev/Srbllkn9pwt28/ezh0+dEHwhd5WCeAhijt zNjJ79galUJDi5ICGAs28qtZ6VgfyezeDEv+RgSU90wpnT/hVngsbuQ/qSBDTgzknN/l OW3Q== X-Gm-Message-State: AMCzsaUVkXqtcdp8DddubKXnao5h5DGex/2kEXxPjkygqCgIUFYHx4y3 SvkNos55kCZXxmeAQNp1zhY275M53GA= X-Google-Smtp-Source: ABhQp+TtaqP4JuVXrNe0HqbKEAv5qgSLWB4HXIIrpYPxkPN1rkgkHHZ2NGiIZPdYxmkD2NSBk2gAjQ== X-Received: by 10.46.75.25 with SMTP id y25mr1886253lja.141.1509211157607; Sat, 28 Oct 2017 10:19:17 -0700 (PDT) Received: from dza-svk.tomtelnet.ru (nightik.qwertynet.ru. [79.136.160.17]) by smtp.googlemail.com with ESMTPSA id 84sm2541274ljc.67.2017.10.28.10.19.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 Oct 2017 10:19:16 -0700 (PDT) From: Maksim Dzabraev To: gdb-patches@sourceware.org Cc: simon.marchi@polymtl.ca, tom@tromney.com, dzabraew@gmail.com Subject: [PATCH] fix bug PR 21213 and add test case Date: Sun, 29 Oct 2017 00:18:56 +0700 Message-Id: <20171028171856.3540-1-dzabraew@gmail.com> In-Reply-To: References: --- gdb/ChangeLog | 7 +++++++ gdb/python/py-infthread.c | 1 + gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-infthread.exp | 9 +++++++++ 4 files changed, 23 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9fe632985e..160c521c96 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +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"