From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18646 invoked by alias); 19 Jul 2012 15:30:19 -0000 Received: (qmail 18635 invoked by uid 22791); 19 Jul 2012 15:30:17 -0000 X-SWARE-Spam-Status: No, hits=-7.2 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 mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Jul 2012 15:30:00 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 19 Jul 2012 08:29:33 -0700 X-ExtLoop1: 1 Received: from swsutil001.isw.intel.com ([10.237.237.11]) by orsmga002.jf.intel.com with ESMTP; 19 Jul 2012 08:29:31 -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 q6JFTUOw006063; Thu, 19 Jul 2012 16:29:31 +0100 Received: from ulslx001.iul.intel.com (localhost [127.0.0.1]) by ulslx001.iul.intel.com with ESMTP id q6JFTUbQ007498; Thu, 19 Jul 2012 17:29:30 +0200 Received: (from mmetzger@localhost) by ulslx001.iul.intel.com with id q6JFTTuU007484; Thu, 19 Jul 2012 17:29:29 +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, Markus Metzger Subject: [PATCH 1/1] gdb, python: update threads in Inferior.threads () Date: Thu, 19 Jul 2012 15:30:00 -0000 Message-Id: <1342711757-7243-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/msg00345.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-19 Markus Metzger 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 | 51 +++++++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-threads.exp | 30 ++++++++++++++++++ 3 files changed, 86 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..bb08979 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-threads.c @@ -0,0 +1,51 @@ +/* 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 . +*/ + +#include + +#define NUMTH 8 + +static void * +thread (void *param) +{ + for (;;) + ; + return param; +} + +static void +check (void) +{ +} + +extern int +main (void) +{ + pthread_t threads[NUMTH]; + int i; + + for (i = 0; i < NUMTH; ++i) + pthread_create (&threads[i], NULL, thread, NULL); + + check (); + + for (i = 0; i < NUMTH; ++i) + pthread_join (threads[i], NULL); + + 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..ab2bccb --- /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 . + +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())" "9" "py-threads" -- 1.7.1