* Garbarge collector eats gdb.selected_thread().inferior
@ 2017-08-05 5:58 Максим Дзабраев
2017-08-07 20:57 ` Simon Marchi
0 siblings, 1 reply; 6+ messages in thread
From: Максим Дзабраев @ 2017-08-05 5:58 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 5051 bytes --]
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 #2: gdb.log__py-infthread.exp__after.txt --]
[-- Type: text/plain, Size: 9877 bytes --]
Test Run By maksim on Sat Aug 5 10:48:22 2017
Native configuration is x86_64-pc-linux-gnu
=== gdb tests ===
Schedule of variations:
unix
Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file.
Running /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.exp ...
get_compiler_info: gcc-4-8-4
Executing on host: gcc -c -g -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c (timeout = 300)
spawn gcc -c -g -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c
Executing on host: gcc /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o -g -lm -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread (timeout = 300)
spawn gcc /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o -g -lm -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
spawn /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
GNU gdb (GDB) 8.0.50.20170804-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set height 0
(gdb) set width 0
(gdb) dir
Reinitialize source path to empty? (y or n) y
Source directories searched: $cdir:$cwd
(gdb) dir /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python
Source directories searched: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python:$cdir:$cwd
(gdb) kill
The program is not being run.
(gdb) file /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
Reading symbols from /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread...done.
(gdb) spawn /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
GNU gdb (GDB) 8.0.50.20170804-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set height 0
(gdb) set width 0
(gdb) dir
Reinitialize source path to empty? (y or n) y
Source directories searched: $cdir:$cwd
(gdb) dir /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python
Source directories searched: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python:$cdir:$cwd
(gdb) kill
The program is not being run.
(gdb) file /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
Reading symbols from /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread...done.
(gdb) python print ('test')
test
(gdb) python print (sys.version_info[0])
2
(gdb) python print (sys.version_info[1])
7
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
Breakpoint 1 at 0x40052b: file /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c, line 13.
(gdb) run
Starting program: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
warning: the debug information found in "/lib64/ld-2.19.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).
Breakpoint 1, main (argc=1, argv=0x7fffffffe108) at /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c:13
13 return f1 (1, 2);
(gdb) python gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python import gc; gc.collect()
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
python gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python i0 = gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
python t0 = gdb.selected_thread ()
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python print (t0)
<gdb.InferiorThread object at 0x7f3437783130>
(gdb) PASS: gdb.python/py-infthread.exp: verify InferiorThread object
python print ('result = %s' % t0.num)
result = 1
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.num
python print ('result = %s' % t0.global_num)
result = 1
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.global_num
python print ('result = %s' % str (t0.ptid))
result = (7890, 7890, 0)
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.ptid
python print ('result = %s' % i0.num)
result = 1
(gdb) PASS: gdb.python/py-infthread.exp: test Inferior.num
python name = gdb.selected_thread().name
(gdb) PASS: gdb.python/py-infthread.exp: get supplied name of current thread
python gdb.selected_thread().name = 'hibob'
(gdb) PASS: gdb.python/py-infthread.exp: set name of current thread
python print (gdb.selected_thread().name)
hibob
(gdb) PASS: gdb.python/py-infthread.exp: check name of current thread
python gdb.selected_thread().name = None
(gdb) PASS: gdb.python/py-infthread.exp: reset name of current thread
python print (gdb.selected_thread().name == name)
True
(gdb) PASS: gdb.python/py-infthread.exp: check name of current thread again
python print ('result = %s' % t0.is_stopped ())
result = True
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.is_stopped
python print ('result = %s' % t0.is_running ())
result = False
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.is_running
python print ('result = %s' % t0.is_exited ())
result = False
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.is_exited
python print ('result = %s' % t0.is_valid ())
result = True
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.is_valid
kill inferior 1
(gdb) PASS: gdb.python/py-infthread.exp: kill inferior 1
python print ('result = %s' % t0.is_valid ())
result = False
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.is_valid
testcase /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.exp completed in 2 seconds
=== gdb Summary ===
# of expected passes 23
Executing on host: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory --version (timeout = 300)
spawn /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory --version
GNU gdb (GDB) 8.0.50.20170804-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
/home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb version 8.0.50.20170804-git -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
runtest completed at Sat Aug 5 10:48:24 2017
[-- Attachment #3: gdb.log__py-infthread.exp__before.txt --]
[-- Type: text/plain, Size: 12739 bytes --]
Test Run By maksim on Sat Aug 5 10:41:15 2017
Native configuration is x86_64-pc-linux-gnu
=== gdb tests ===
Schedule of variations:
unix
Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file.
Running /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.exp ...
get_compiler_info: gcc-4-8-4
Executing on host: gcc -c -g -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c (timeout = 300)
spawn gcc -c -g -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c
Executing on host: gcc /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o -g -lm -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread (timeout = 300)
spawn gcc /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread0.o -g -lm -o /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
spawn /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
GNU gdb (GDB) 8.0.50.20170804-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set height 0
(gdb) set width 0
(gdb) dir
Reinitialize source path to empty? (y or n) y
Source directories searched: $cdir:$cwd
(gdb) dir /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python
Source directories searched: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python:$cdir:$cwd
(gdb) kill
The program is not being run.
(gdb) file /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
Reading symbols from /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread...done.
(gdb) spawn /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
GNU gdb (GDB) 8.0.50.20170804-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set height 0
(gdb) set width 0
(gdb) dir
Reinitialize source path to empty? (y or n) y
Source directories searched: $cdir:$cwd
(gdb) dir /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python
Source directories searched: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python:$cdir:$cwd
(gdb) kill
The program is not being run.
(gdb) file /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
Reading symbols from /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread...done.
(gdb) python print ('test')
test
(gdb) python print (sys.version_info[0])
2
(gdb) python print (sys.version_info[1])
7
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
Breakpoint 1 at 0x40052b: file /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c, line 13.
(gdb) run
Starting program: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/outputs/gdb.python/py-infthread/py-infthread
warning: the debug information found in "/lib64/ld-2.19.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).
Breakpoint 1, main (argc=1, argv=0x7fffffffe108) at /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.c:13
13 return f1 (1, 2);
(gdb) python import gc; gc.collect()
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
python gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python gdb.selected_thread ().inferior
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python import gc; gc.collect()
(gdb) PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
python gdb.selected_thread ().inferior
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'inferior'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test gdb.selected_thread
python gdb.selected_thread ().inferior
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'inferior'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test gdb.selected_thread
python i0 = gdb.selected_thread ().inferior
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'inferior'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.inferior
python t0 = gdb.selected_thread ()
(gdb) PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
python print (t0)
None
(gdb) FAIL: gdb.python/py-infthread.exp: verify InferiorThread object
python print ('result = %s' % t0.num)
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'num'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.num
python print ('result = %s' % t0.global_num)
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'global_num'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.global_num
python print ('result = %s' % str (t0.ptid))
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'ptid'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.ptid
python print ('result = %s' % i0.num)
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'i0' is not defined
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test Inferior.num
python name = gdb.selected_thread().name
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'name'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: get supplied name of current thread
python gdb.selected_thread().name = 'hibob'
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'name'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: set name of current thread
python print (gdb.selected_thread().name)
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'name'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: check name of current thread
python gdb.selected_thread().name = None
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'name'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: reset name of current thread
python print (gdb.selected_thread().name == name)
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'name'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: check name of current thread again
python print ('result = %s' % t0.is_stopped ())
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'is_stopped'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_stopped
python print ('result = %s' % t0.is_running ())
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'is_running'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_running
python print ('result = %s' % t0.is_exited ())
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'is_exited'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_exited
python print ('result = %s' % t0.is_valid ())
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'is_valid'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_valid
kill inferior 1
(gdb) PASS: gdb.python/py-infthread.exp: kill inferior 1
python print ('result = %s' % t0.is_valid ())
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'is_valid'
Error while executing Python code.
(gdb) FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_valid
testcase /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.exp completed in 0 seconds
=== gdb Summary ===
# of expected passes 6
# of unexpected failures 18
Executing on host: /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory --version (timeout = 300)
spawn /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory --version
GNU gdb (GDB) 8.0.50.20170804-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
/home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb version 8.0.50.20170804-git -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
runtest completed at Sat Aug 5 10:41:15 2017
[-- Attachment #4: gdb.sum__py-infthread.exp__after.txt --]
[-- Type: text/plain, Size: 1972 bytes --]
Test Run By maksim on Sat Aug 5 10:48:22 2017
Native configuration is x86_64-pc-linux-gnu
=== gdb tests ===
Schedule of variations:
unix
Running target unix
Running /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.exp ...
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: verify InferiorThread object
PASS: gdb.python/py-infthread.exp: test InferiorThread.num
PASS: gdb.python/py-infthread.exp: test InferiorThread.global_num
PASS: gdb.python/py-infthread.exp: test InferiorThread.ptid
PASS: gdb.python/py-infthread.exp: test Inferior.num
PASS: gdb.python/py-infthread.exp: get supplied name of current thread
PASS: gdb.python/py-infthread.exp: set name of current thread
PASS: gdb.python/py-infthread.exp: check name of current thread
PASS: gdb.python/py-infthread.exp: reset name of current thread
PASS: gdb.python/py-infthread.exp: check name of current thread again
PASS: gdb.python/py-infthread.exp: test InferiorThread.is_stopped
PASS: gdb.python/py-infthread.exp: test InferiorThread.is_running
PASS: gdb.python/py-infthread.exp: test InferiorThread.is_exited
PASS: gdb.python/py-infthread.exp: test InferiorThread.is_valid
PASS: gdb.python/py-infthread.exp: kill inferior 1
PASS: gdb.python/py-infthread.exp: test InferiorThread.is_valid
=== gdb Summary ===
# of expected passes 23
/home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb version 8.0.50.20170804-git -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
[-- Attachment #5: gdb.sum__py-infthread.exp__before.txt --]
[-- Type: text/plain, Size: 2063 bytes --]
Test Run By maksim on Sat Aug 5 10:41:15 2017
Native configuration is x86_64-pc-linux-gnu
=== gdb tests ===
Schedule of variations:
unix
Running target unix
Running /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.python/py-infthread.exp ...
PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
PASS: gdb.python/py-infthread.exp: test InferiorThread.inferior
FAIL: gdb.python/py-infthread.exp: test gdb.selected_thread
FAIL: gdb.python/py-infthread.exp: test gdb.selected_thread
FAIL: gdb.python/py-infthread.exp: test InferiorThread.inferior
PASS: gdb.python/py-infthread.exp: test gdb.selected_thread
FAIL: gdb.python/py-infthread.exp: verify InferiorThread object
FAIL: gdb.python/py-infthread.exp: test InferiorThread.num
FAIL: gdb.python/py-infthread.exp: test InferiorThread.global_num
FAIL: gdb.python/py-infthread.exp: test InferiorThread.ptid
FAIL: gdb.python/py-infthread.exp: test Inferior.num
FAIL: gdb.python/py-infthread.exp: get supplied name of current thread
FAIL: gdb.python/py-infthread.exp: set name of current thread
FAIL: gdb.python/py-infthread.exp: check name of current thread
FAIL: gdb.python/py-infthread.exp: reset name of current thread
FAIL: gdb.python/py-infthread.exp: check name of current thread again
FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_stopped
FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_running
FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_exited
FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_valid
PASS: gdb.python/py-infthread.exp: kill inferior 1
FAIL: gdb.python/py-infthread.exp: test InferiorThread.is_valid
=== gdb Summary ===
# of expected passes 6
# of unexpected failures 18
/home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../../gdb/gdb version 8.0.50.20170804-git -nw -nx -data-directory /home/maksim/sources/obj-binutils-gdb/gdb/testsuite/../data-directory
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Garbarge collector eats gdb.selected_thread().inferior
2017-08-05 5:58 Garbarge collector eats gdb.selected_thread().inferior Максим Дзабраев
@ 2017-08-07 20:57 ` Simon Marchi
2017-10-28 17:19 ` [PATCH] fix bug PR 21213 and add test case Maksim Dzabraev
2017-10-28 18:14 ` [PATCH] Make gdb.selected_thread().inferior return a new reference Maksim Dzabraev
0 siblings, 2 replies; 6+ messages in thread
From: Simon Marchi @ 2017-08-07 20:57 UTC (permalink / raw)
To: Максим
Дзабраев
Cc: gdb-patches, Tom Tromey
Hi Maksim,
The fix looks right, and Tom also said so in Bugzilla.
However, I'm unable to apply your patch to look at the test case. The
long lines have been wrapped, presumably by your email client. Can you
send it again using the "git send-email" command? I'll still make the
comments I can about the current version.
On 2017-08-05 07:57, ÐакÑим ÐзабÑаев wrote:
> 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
Please consult this page for details about the ChangeLog entries.
https://sourceware.org/gdb/wiki/ContributionChecklist
In short, each change should be documented in the ChangeLog closest to
it (then for each file you write the relative path to it), and should
describe what changed a bit more precisely. For example:
gdb/ChangeLog:
* python/py-infthread.c (thpy_get_inferior): Increment reference
of inferior before returning it.
gdb/testsuite/ChangeLog:
* gdb.python/py-infthread.exp: Test calling
InferiorThread.inferior () multiple times in a row.
> ---
>
> 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
It's nice to give a bit of context so that readers don't have to visit
the PR to have an idea of what it's about. I suggest:
# Make sure that InferiorThread.inferior returns a new reference (see PR
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"
You have one too many parameter to gdb_test_no_output. Also, the test
name should probably be something like "call Python garbage collection".
> +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
All tests (here one line == one test) should have a unique name, so you
could name them "test InferiorThread.inferior #" where # is 1, 2, 3, 4.
> +
> +
> 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
Thanks!
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH] fix bug PR 21213 and add test case
2017-08-07 20:57 ` Simon Marchi
@ 2017-10-28 17:19 ` Maksim Dzabraev
2017-10-28 17:46 ` Simon Marchi
2017-10-28 18:14 ` [PATCH] Make gdb.selected_thread().inferior return a new reference Maksim Dzabraev
1 sibling, 1 reply; 6+ messages in thread
From: Maksim Dzabraev @ 2017-10-28 17:19 UTC (permalink / raw)
To: gdb-patches; +Cc: simon.marchi, tom, dzabraew
---
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 <dzabraew@gmail.com>
+
+ PR python/21213
+ * python/py-infthread.c (thpy_get_inferior): Increment reference
+ of inferior before returning it.
+
+
2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
* 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 <dzabraew@gmail.com>
+
+ PR python/21213
+ * gdb.python/py-infthread.exp: Test calling
+ InferiorThread.inferior () multiple times in a row.
+
2017-10-27 Keith Seitz <keiths@redhat.com>
* 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)" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num"
--
2.13.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] fix bug PR 21213 and add test case
2017-10-28 17:19 ` [PATCH] fix bug PR 21213 and add test case Maksim Dzabraev
@ 2017-10-28 17:46 ` Simon Marchi
0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2017-10-28 17:46 UTC (permalink / raw)
To: Maksim Dzabraev; +Cc: gdb-patches, tom
Hi Maksim,
Thanks for the update. Your patch would need a more descriptive name
than just the PR number. I suggest "Make gdb.selected_thread().inferior
return a new reference".
It would also need a summary in the commit log. What you had in your
original email was good, and you can also mention that the
thpy_get_inferior function should return a new reference to the existing
inferior object, and therefore should increment its refcount.
On 2017-10-28 13:18, Maksim Dzabraev wrote:
> ---
> 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 <dzabraew@gmail.com>
Please use two spaces between each field (between date and name, and
between name and email).
> +
> + PR python/21213
> + * python/py-infthread.c (thpy_get_inferior): Increment reference
> + of inferior before returning it.
> +
> +
> 2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
>
> * 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 <dzabraew@gmail.com>
Same here.
> +
> + PR python/21213
> + * gdb.python/py-infthread.exp: Test calling
> + InferiorThread.inferior () multiple times in a row.
> +
> 2017-10-27 Keith Seitz <keiths@redhat.com>
>
> * 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)" "\\<gdb.InferiorThread object at
> 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
> gdb_test "python print ('result = %s' % t0.num)" " = 1" "test
> InferiorThread.num"
Thanks,
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] Make gdb.selected_thread().inferior return a new reference
2017-08-07 20:57 ` Simon Marchi
2017-10-28 17:19 ` [PATCH] fix bug PR 21213 and add test case Maksim Dzabraev
@ 2017-10-28 18:14 ` Maksim Dzabraev
2017-10-28 18:21 ` Simon Marchi
1 sibling, 1 reply; 6+ messages in thread
From: Maksim Dzabraev @ 2017-10-28 18:14 UTC (permalink / raw)
To: gdb-patches; +Cc: simon.marchi, tom, dzabraew
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.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
---
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 <dzabraew@gmail.com>
+
+ PR python/21213
+ * python/py-infthread.c (thpy_get_inferior): Increment reference
+ of inferior before returning it.
+
2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
* 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 <dzabraew@gmail.com>
+
+ PR python/21213
+ * gdb.python/py-infthread.exp: Test calling
+ InferiorThread.inferior () multiple times in a row.
+
2017-10-27 Keith Seitz <keiths@redhat.com>
* 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)" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num"
--
2.13.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Make gdb.selected_thread().inferior return a new reference
2017-10-28 18:14 ` [PATCH] Make gdb.selected_thread().inferior return a new reference Maksim Dzabraev
@ 2017-10-28 18:21 ` Simon Marchi
0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2017-10-28 18:21 UTC (permalink / raw)
To: Maksim Dzabraev; +Cc: gdb-patches, tom
Thanks! I pushed the patch with the following changes:
On 2017-10-28 14:14, Maksim Dzabraev wrote:
> 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.
lokks -> looks
> If multiple time call gdb.selected_thread ().inferior, gdb throws
> exception:
> (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
> ---
> 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 <dzabraew@gmail.com>
> +
> + PR python/21213
> + * python/py-infthread.c (thpy_get_inferior): Increment reference
> + of inferior before returning it.
> +
> 2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
>
> * 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 <dzabraew@gmail.com>
Used two spaces between fields.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-10-28 18:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-05 5:58 Garbarge collector eats gdb.selected_thread().inferior Максим Дзабраев
2017-08-07 20:57 ` Simon Marchi
2017-10-28 17:19 ` [PATCH] fix bug PR 21213 and add test case Maksim Dzabraev
2017-10-28 17:46 ` Simon Marchi
2017-10-28 18:14 ` [PATCH] Make gdb.selected_thread().inferior return a new reference Maksim Dzabraev
2017-10-28 18:21 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox