Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: markus.t.metzger@intel.com
To: gdb-patches@sourceware.org
Cc: markus.t.metzger@gmail.com, jan.kratochvil@redhat.com,
	palves@redhat.com,        tromey@redhat.com, pmuldoon@redhat.com,
	       Markus Metzger <markus.t.metzger@intel.com>
Subject: [PATCH 1/1] gdb, python: update threads in Inferior.threads ()
Date: Thu, 26 Jul 2012 12:20:00 -0000	[thread overview]
Message-ID: <1343305180-14899-1-git-send-email-markus.t.metzger@intel.com> (raw)

From: Markus Metzger <markus.t.metzger@intel.com>

When querying an inferior's threads in Python in a remote debugging
configuration, only the already known threads are returned.

Update the thread list in infpy_threads () before creating the Python objects.

2012-07-26 Markus Metzger <markus.t.metzger@intel.com>

	* python/py-inferior.c (infpy_threads): Call update_thread_list ().

testsuite/
	* gdb.python/py-inferior.c (thread): New function.
	(check_threads): New function.
	(test_threads): New function.
	* gdb.python/py-inferior.exp: Added test.
	Replaced runto with continue to breakpoint.


---
 gdb/python/py-inferior.c                 |    5 +++
 gdb/testsuite/gdb.python/py-inferior.c   |   41 ++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.python/py-inferior.exp |   15 ++++++++--
 3 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 2b229be..907b73e 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -300,9 +300,14 @@ infpy_threads (PyObject *self, PyObject *args)
   struct threadlist_entry *entry;
   inferior_object *inf_obj = (inferior_object *) self;
   PyObject *tuple;
+  volatile struct gdb_exception except;
 
   INFPY_REQUIRE_VALID (inf_obj);
 
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    update_thread_list ();
+  GDB_PY_HANDLE_EXCEPTION (except);
+
   tuple = PyTuple_New (inf_obj->nthreads);
   if (!tuple)
     return NULL;
diff --git a/gdb/testsuite/gdb.python/py-inferior.c b/gdb/testsuite/gdb.python/py-inferior.c
index 04ec476..3ee9a46 100644
--- a/gdb/testsuite/gdb.python/py-inferior.c
+++ b/gdb/testsuite/gdb.python/py-inferior.c
@@ -2,9 +2,11 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <pthread.h>
 
 #define CHUNK_SIZE 16000 /* same as findcmd.c's */
 #define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
+#define NUMTH 8
 
 int8_t int8_search_buf[100];
 int16_t int16_search_buf[100];
@@ -43,8 +45,47 @@ init_bufs ()
   memset (search_buf, 'x', search_buf_size);
 }
 
+static void *
+thread (void *param)
+{
+  pthread_barrier_t *barrier = (pthread_barrier_t *) param;
+
+  pthread_barrier_wait (barrier);
+
+  return param;
+}
+
+static void
+check_threads (pthread_barrier_t *barrier)
+{
+  pthread_barrier_wait (barrier);
+}
+
+extern int
+test_threads (void)
+{
+  pthread_t threads[NUMTH];
+  pthread_barrier_t barrier;
+  int i;
+
+  pthread_barrier_init (&barrier, NULL, NUMTH + 1);
+
+  for (i = 0; i < NUMTH; ++i)
+    pthread_create (&threads[i], NULL, thread, &barrier);
+
+  check_threads (&barrier);
+
+  for (i = 0; i < NUMTH; ++i)
+    pthread_join (threads[i], NULL);
+
+  pthread_barrier_destroy (&barrier);
+
+  return 0;
+}
+
 int main (int argc, char *argv[])
 {
+  test_threads ();
   init_bufs ();
 
   return f1 (1, 2);
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index b40a514..15e684a 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -20,7 +20,7 @@ load_lib gdb-python.exp
 
 standard_testfile
 
-if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+if { [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable {debug}] != "" } {
     return -1
 }
 
@@ -48,8 +48,6 @@ if ![runto_main] then {
     return 0
 }
 
-runto [gdb_get_line_number "Break here."]
-
 # Test basic gdb.Inferior attributes and methods.
 
 gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
@@ -62,6 +60,17 @@ gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
 gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
 gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
 
+# Test the number of inferior threads.
+
+gdb_breakpoint check_threads
+gdb_continue_to_breakpoint "cont to check_threads" ".*pthread_barrier_wait.*"
+gdb_test "python print len (i0.threads ())" "\r\n9" "test Inferior.threads 2"
+
+# Proceed to the next test.
+
+gdb_breakpoint [gdb_get_line_number "Break here."]
+gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*"
+
 # Test memory read and write operations.
 
 gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
-- 
1.7.1


             reply	other threads:[~2012-07-26 12:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 12:20 markus.t.metzger [this message]
2012-07-26 19:10 ` [commit] " Jan Kratochvil
2012-07-27  7:10   ` Metzger, Markus T
  -- strict thread matches above, loose matches on Subject: below --
2012-07-25  8:27 markus.t.metzger
2012-07-25 16:15 ` Tom Tromey
2012-07-26  7:51   ` Metzger, Markus T
2012-07-26  8:43     ` Jan Kratochvil
2012-07-26  8:49       ` Metzger, Markus T
2012-07-24  8:12 markus.t.metzger
2012-07-24 14:36 ` Phil Muldoon
2012-07-19 15:30 markus.t.metzger
2012-07-19 18:41 ` Jan Kratochvil
     [not found]   ` <2832024D-3061-4A13-BBF5-656C504C295D@gmail.com>
2012-07-24  8:08     ` Metzger, Markus T
2012-07-25 16:13       ` Tom Tromey
2012-07-26  5:51         ` Metzger, Markus T
2012-07-25 16:16   ` Tom Tromey
2012-07-06  9:50 markus.t.metzger
2012-07-06 18:12 ` Tom Tromey
2012-07-19 15:27   ` Metzger, Markus T
2012-07-18 13:54 ` Jan Kratochvil
2012-07-19 15:27   ` Metzger, Markus T
2012-07-19 18:45     ` Jan Kratochvil
2012-07-20  7:57       ` Metzger, Markus T

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=1343305180-14899-1-git-send-email-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=markus.t.metzger@gmail.com \
    --cc=palves@redhat.com \
    --cc=pmuldoon@redhat.com \
    --cc=tromey@redhat.com \
    /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