From: Maksim Dzabraev Date: Sat, 28 Oct 2017 18:14:34 +0000 (+0700) Subject: Make gdb.selected_thread().inferior return a new reference X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=484d8d361de65a8489252d14511b77c142d859a1;p=binutils-gdb.git Make gdb.selected_thread().inferior return a new reference thpy_get_inferior function should return a new reference to the existing inferior object, and therefore should increment its refcount. Fixed bug looks 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 --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9fe632985e9..4583a78fe59 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 626c15cedb5..31d576f7c74 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 0254a28550d..9d0f8139ad2 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 0711d6994e8..69fc9709b27 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"