From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19099 invoked by alias); 25 Jul 2012 08:27:12 -0000 Received: (qmail 19065 invoked by uid 22791); 25 Jul 2012 08:27:09 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Jul 2012 08:26:56 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 25 Jul 2012 01:26:55 -0700 X-ExtLoop1: 1 Received: from swsutil001.isw.intel.com ([10.237.237.11]) by orsmga002.jf.intel.com with ESMTP; 25 Jul 2012 01:26:54 -0700 Received: from ulslx001.iul.intel.com (ulslx001.iul.intel.com [172.28.207.63]) by swsutil001.isw.intel.com (8.13.6/8.13.6/MailSET/Hub) with ESMTP id q6P8Qr09032557; Wed, 25 Jul 2012 09:26:53 +0100 Received: from ulslx001.iul.intel.com (localhost [127.0.0.1]) by ulslx001.iul.intel.com with ESMTP id q6P8Qqol023417; Wed, 25 Jul 2012 10:26:52 +0200 Received: (from mmetzger@localhost) by ulslx001.iul.intel.com with id q6P8QqYY023412; Wed, 25 Jul 2012 10:26:52 +0200 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 Subject: [PATCH 1/1] gdb, python: update threads in Inferior.threads () Date: Wed, 25 Jul 2012 08:27:00 -0000 Message-Id: <1343204804-23172-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00515.txt.bz2 From: Markus Metzger 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-25 Markus Metzger * 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. --- gdb/python/py-inferior.c | 5 +++ gdb/testsuite/gdb.python/py-inferior.c | 41 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-inferior.exp | 13 +++++++-- 3 files changed, 56 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 #include #include +#include #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..b351f3e 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,15 @@ 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 ()" "\\(,\\)" "test Inferior.threads" +# Test the number of inferior threads. + +runto check_threads +gdb_test "python print len (i0.threads ())" "\r\n9" "test Inferior.threads 2" + +# Proceed to the next test. + +runto [gdb_get_line_number "Break here."] + # Test memory read and write operations. gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ -- 1.7.1