From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 5/7] InferiorThread.global_num
Date: Wed, 06 Jan 2016 13:03:00 -0000 [thread overview]
Message-ID: <1452085418-18300-6-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1452085418-18300-1-git-send-email-palves@redhat.com>
This commit adds a new Python InferiorThread.global_num attribute.
This can be used to pass the correct thread ID to Breakpoint.thread,
which takes a global thread ID, not a per-inferior thread number.
gdb/ChangeLog:
2016-01-06 Pedro Alves <palves@redhat.com>
* NEWS: Mention InferiorThread.global_num.
* python/py-infthread.c (thpy_get_global_num): New function.
(thread_object_getset): Register "global_num".
gdb/testsuite/ChangeLog:
2016-01-06 Pedro Alves <palves@redhat.com>
* gdb.multi/tids.exp: Test InferiorThread.global_num and
Breakpoint.thread.
* gdb.python/py-infthread.exp: Test InferiorThread.global_num.
gdb/doc/ChangeLog:
2016-01-06 Pedro Alves <palves@redhat.com>
* python.texi (Breakpoints In Python) <Breakpoint.thread>: Add
anchor.
(Threads In Python): Document new InferiorThread.global_num
attribute.
---
gdb/NEWS | 7 ++++---
gdb/doc/python.texi | 7 +++++++
gdb/python/py-infthread.c | 14 ++++++++++++++
gdb/testsuite/gdb.multi/tids.exp | 19 ++++++++++++++++++-
gdb/testsuite/gdb.python/py-infthread.exp | 1 +
5 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 03944383..c87a73d 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -184,9 +184,10 @@ show remote exec-event-feature-packet
* Python Scripting
- ** The "num" attribute of gdb.InferiorThread objects now refers to
- the thread's per-inferior number. See "Per-inferior thread
- numbers" above.
+ ** gdb.InferiorThread objects have a new attribute "global_num",
+ which refers to the thread's global thread ID. The existing
+ "num" attribute now refers to the thread's per-inferior number.
+ See "Per-inferior thread numbers" above.
** gdb.InferiorThread objects have a new attribute "inferior", which
is the Inferior object the thread belongs to.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index f9f9e5b..ffbf89a 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2998,6 +2998,12 @@ user-specified thread name.
The per-inferior number of the thread, as assigned by GDB.
@end defvar
+@defvar InferiorThread.global_num
+The global ID of the thread, as assigned by GDB. You can use this to
+make Python breakpoints thread-specific, for example
+(@pxref{python_breakpoint_thread,,The Breakpoint.thread attribute}).
+@end defvar
+
@defvar InferiorThread.ptid
ID of the thread, as assigned by the operating system. This attribute is a
tuple containing three integers. The first is the Process ID (PID); the second
@@ -4642,6 +4648,7 @@ first command is @code{silent}. This is not reported by the
@code{silent} attribute.
@end defvar
+@anchor{python_breakpoint_thread}
@defvar Breakpoint.thread
If the breakpoint is thread-specific, this attribute holds the
thread's global id. If the breakpoint is not thread-specific, this
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index a9dd5cb..3a9bae7 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -127,6 +127,18 @@ thpy_get_num (PyObject *self, void *closure)
return PyLong_FromLong (thread_obj->thread->per_inf_num);
}
+/* Getter for InferiorThread.global_num. */
+
+static PyObject *
+thpy_get_global_num (PyObject *self, void *closure)
+{
+ thread_object *thread_obj = (thread_object *) self;
+
+ THPY_REQUIRE_VALID (thread_obj);
+
+ return PyLong_FromLong (thread_obj->thread->global_num);
+}
+
/* Getter for InferiorThread.ptid -> (pid, lwp, tid).
Returns a tuple with the thread's ptid components. */
@@ -298,6 +310,8 @@ static PyGetSetDef thread_object_getset[] =
"The name of the thread, as set by the user or the OS.", NULL },
{ "num", thpy_get_num, NULL,
"Per-inferior number of the thread, as assigned by GDB.", NULL },
+ { "global_num", thpy_get_global_num, NULL,
+ "Global number of the thread, as assigned by GDB.", NULL },
{ "ptid", thpy_get_ptid, NULL, "ID of the thread, as assigned by the OS.",
NULL },
{ "inferior", thpy_get_inferior, NULL,
diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp
index 7b51c80..12aca07 100644
--- a/gdb/testsuite/gdb.multi/tids.exp
+++ b/gdb/testsuite/gdb.multi/tids.exp
@@ -244,11 +244,28 @@ with_test_prefix "two inferiors" {
if { ![skip_python_tests] } {
with_test_prefix "python" {
- # Check that InferiorThread.num returns the expected number.
+ # Check that InferiorThread.num and InferiorThread.global_num
+ # return the expected numbers.
gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" \
"test gdb.selected_thread" 1
gdb_test "python print ('result = %s' % t0.num)" " = 3" \
"test InferiorThread.num"
+ gdb_test "python print ('result = %s' % t0.global_num)" " = 6" \
+ "test InferiorThread.global_num"
+
+ # Breakpoint.thread expects global IDs. Confirm that that
+ # works as expected.
+ delete_breakpoints
+ gdb_breakpoint "thread_function1"
+
+ gdb_py_test_silent_cmd "python bp = gdb.breakpoints()\[0\]" \
+ "get python breakpoint" 0
+ gdb_test "python bp.thread = 6" "thread = 6" \
+ "make breakpoint thread-specific with python"
+ # Check that the inferior-qualified ID is correct.
+ gdb_test "info breakpoint" \
+ "stop only in thread 1.3\r\n.*" \
+ "thread specific breakpoint right thread"
}
}
diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index e07fd82..11f8d21 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -42,6 +42,7 @@ if ![runto_main] then {
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"
+gdb_test "python print ('result = %s' % t0.global_num)" " = 1" "test InferiorThread.global_num"
gdb_test "python print ('result = %s' % str (t0.ptid))" " = \\(\[0-9\]+, \[0-9\]+, \[0-9\]+\\)" "test InferiorThread.ptid"
gdb_py_test_silent_cmd "python i0 = t0.inferior" "test InferiorThread.inferior" 1
--
1.9.3
next prev parent reply other threads:[~2016-01-06 13:03 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-06 13:03 [PATCH v3 0/7] Per-inferior/Inferior-qualified thread IDs Pedro Alves
2016-01-06 13:03 ` [PATCH v3 3/7] Centralize thread ID printing Pedro Alves
2016-01-06 18:57 ` Simon Marchi
2016-01-06 13:03 ` [PATCH v3 2/7] Add Python InferiorThread.inferior attribute Pedro Alves
2016-01-06 18:57 ` Simon Marchi
2016-01-06 13:03 ` Pedro Alves [this message]
2016-01-06 19:03 ` [PATCH v3 5/7] InferiorThread.global_num Simon Marchi
2016-01-06 13:03 ` [PATCH v3 1/7] Add a new $_inferior convenience variable Pedro Alves
2016-01-06 18:56 ` Simon Marchi
2016-01-06 13:04 ` [PATCH v3 4/7] Per-inferior/Inferior-qualified thread IDs Pedro Alves
2016-01-06 18:51 ` Simon Marchi
2016-01-07 19:45 ` Pedro Alves
2016-01-07 22:28 ` Simon Marchi
2016-01-07 23:37 ` Pedro Alves
2016-12-07 21:10 ` Thomas Schwinge
2016-12-07 21:29 ` Simon Marchi
2016-12-08 8:53 ` Thomas Schwinge
2016-01-07 22:02 ` Simon Marchi
2016-01-07 22:24 ` Pedro Alves
2016-01-06 13:11 ` [PATCH v3 7/7] Add $_gthread convenience variable Pedro Alves
2016-01-06 19:14 ` Simon Marchi
2016-01-06 13:11 ` [PATCH v3 6/7] Implement "info threads -gid" Pedro Alves
2016-01-06 19:12 ` Simon Marchi
2016-01-08 13:54 ` [PATCH v3 0/7] Per-inferior/Inferior-qualified thread IDs Yao Qi
2016-01-13 11:25 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452085418-18300-6-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox