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]

[PATCH 1/1] gdb, python: update threads in Inferior.threads ()


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-24 Markus Metzger <markus.t.metzger@intel.com>

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

gdb/testsuite/gdb.python/
	* py-threads.c: New file.
	* py-threads.exp: New file.


---
 gdb/python/py-inferior.c                |    5 +++
 gdb/testsuite/gdb.python/py-threads.c   |   59 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.python/py-threads.exp |   30 ++++++++++++++++
 3 files changed, 94 insertions(+), 0 deletions(-)
 create mode 100644 gdb/testsuite/gdb.python/py-threads.c
 create mode 100644 gdb/testsuite/gdb.python/py-threads.exp

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 2b229be..22adf8c 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -300,6 +300,11 @@ infpy_threads (PyObject *self, PyObject *args)
   struct threadlist_entry *entry;
   inferior_object *inf_obj = (inferior_object *) self;
   PyObject *tuple;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    update_thread_list ();
+  GDB_PY_HANDLE_EXCEPTION (except);
 
   INFPY_REQUIRE_VALID (inf_obj);
 
diff --git a/gdb/testsuite/gdb.python/py-threads.c b/gdb/testsuite/gdb.python/py-threads.c
new file mode 100644
index 0000000..23eadb5
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-threads.c
@@ -0,0 +1,59 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see  <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+
+#define NUMTH 8
+
+static void *
+thread (void *param)
+{
+  pthread_barrier_t *barrier = (pthread_barrier_t *) param;
+
+  pthread_barrier_wait (barrier);
+
+  return param;
+}
+
+static void
+check (pthread_barrier_t *barrier)
+{
+  pthread_barrier_wait (barrier);
+}
+
+extern int
+main (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 (&barrier);
+
+  for (i = 0; i < NUMTH; ++i)
+    pthread_join (threads[i], NULL);
+
+  pthread_barrier_destroy (&barrier);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.python/py-threads.exp b/gdb/testsuite/gdb.python/py-threads.exp
new file mode 100644
index 0000000..9459c00
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-threads.exp
@@ -0,0 +1,30 @@
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    return -1
+}
+clean_restart $testfile
+
+if { [skip_python_tests] } { continue }
+
+if ![runto check] {
+	untested "py-threads"
+	return -1
+}
+
+gdb_test "python print len(gdb.selected_inferior().threads())" "\r\n9" "py-threads"
-- 
1.7.1


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