This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Garbarge collector eats gdb.selected_thread().inferior


If multiple time call gdb.selected_thread ().inferior, gdb throw exception:

(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
Python Exception <type 'exceptions.AttributeError'> '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
select () from /lib/x86_64-linux-gnu/libc.so.6

I report about this bug here:
https://sourceware.org/bugzilla/show_bug.cgi?id=21213

Following patch fixes this bug and add test of this bug. In attachment
I add gdb.log and gdb.sum before and after apply patch to
thpy_get_inferior.


ChangeLog
2017.08.05 Maksim Dzabraev <dzabraew@gmail.com>

        * gdb/python/py-infthread.c (hpy_get_inferior)
        * gdb/testsuite/gdb.python/py-infthread.exp: Fix bug 21213 and add test

---

diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 626c15c..31d576f 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/gdb.python/py-infthread.exp
b/gdb/testsuite/gdb.python/py-infthread.exp
index a5fed8d..dcb7e26 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -39,6 +39,14 @@ if ![runto_main] then {

 # Test basic gdb.Inferior attributes and methods.

+#testing https://sourceware.org/bugzilla/show_bug.cgi?id=21213
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+gdb_test_no_output "python import gc; gc.collect()" "test
InferiorThread.inferior" "test InferiorThread.inferior"
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+
+
 gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test
gdb.selected_thread" 1
 gdb_test "python print (t0)" "\\<gdb.InferiorThread object at
0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
 gdb_test "python print ('result = %s' % t0.num)" " = 1" "test
InferiorThread.num"If multiple time call gdb.selected_thread
().inferior, gdb throw exception:

(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
Python Exception <type 'exceptions.AttributeError'> '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
select () from /lib/x86_64-linux-gnu/libc.so.6

I report about this bug here:
https://sourceware.org/bugzilla/show_bug.cgi?id=21213

Following path fixes this bug and add test of this bug.


ChangeLog
2017.08.05 Maksim Dzabraev <dzabraew@gmail.com>

        * gdb/python/py-infthread.c (hpy_get_inferior)
        * gdb/testsuite/gdb.python/py-infthread.exp: Fix bug 21213 and add test

---

diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 626c15c..31d576f 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/gdb.python/py-infthread.exp
b/gdb/testsuite/gdb.python/py-infthread.exp
index a5fed8d..dcb7e26 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -39,6 +39,14 @@ if ![runto_main] then {

 # Test basic gdb.Inferior attributes and methods.

+#testing https://sourceware.org/bugzilla/show_bug.cgi?id=21213
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+gdb_test_no_output "python import gc; gc.collect()" "test
InferiorThread.inferior" "test InferiorThread.inferior"
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test
gdb.selected_thread" 1
+
+
 gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test
gdb.selected_thread" 1
 gdb_test "python print (t0)" "\\<gdb.InferiorThread object at
0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
 gdb_test "python print ('result = %s' % t0.num)" " = 1" "test
InferiorThread.num"

Attachment: gdb.log__py-infthread.exp__after.txt
Description: Text document

Attachment: gdb.log__py-infthread.exp__before.txt
Description: Text document

Attachment: gdb.sum__py-infthread.exp__after.txt
Description: Text document

Attachment: gdb.sum__py-infthread.exp__before.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]