From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8031 invoked by alias); 27 Sep 2012 15:27:02 -0000 Received: (qmail 8019 invoked by uid 22791); 27 Sep 2012 15:27:01 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CP X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 27 Sep 2012 15:26:56 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8RFQs3Q003078 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 27 Sep 2012 11:26:55 -0400 Received: from host2.jankratochvil.net (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8RFQosd028499 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 27 Sep 2012 11:26:53 -0400 Date: Thu, 27 Sep 2012 15:27:00 -0000 From: Jan Kratochvil To: ali_anwar Cc: gdb-patches@sourceware.org Subject: Re: Updated patch for Bug 13217 - thread apply all detach throws a SEGFAULT Message-ID: <20120927152650.GA21634@host2.jankratochvil.net> References: <5062EA9B.1060505@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5062EA9B.1060505@codesourcery.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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-09/txt/msg00636.txt.bz2 On Wed, 26 Sep 2012 13:44:27 +0200, ali_anwar wrote: [...] > --- gdb/thread.c 27 Jul 2012 00:52:36 -0000 1.149 > +++ gdb/thread.c 26 Sep 2012 09:51:13 -0000 > @@ -57,6 +57,7 @@ > struct thread_info *thread_list = NULL; > static int highest_thread_num; > > +static int thread_valid (struct thread_info *); Forward declaration not needed when all callers are after the function definition like in this case. > static void thread_command (char *tidstr, int from_tty); > static void thread_apply_all_command (char *, int); > static int thread_alive (struct thread_info *); > @@ -73,6 +74,17 @@ > return tp; > } > > +/* Return true if TP is valid thread. */ Empty line between a function comment tnd the function implementation. Also the comment should end with two spaces: /* Return true if TP is valid thread. */ > +static int > +thread_valid (struct thread_info *tp) > +{ > + struct thread_info *utp; Two spaces, use one. Use empty line between declarations and code statements. > + for (utp = thread_list; utp; utp = utp->next) > + if (tp == utp) > + return 1; > + return 0; > +} > + > void > delete_step_resume_breakpoint (struct thread_info *tp) > { > @@ -1193,7 +1205,7 @@ > execute_command. */ > saved_cmd = xstrdup (cmd); > make_cleanup (xfree, saved_cmd); > - for (tp = thread_list; tp; tp = tp->next) > + for (tp = thread_list; thread_valid(tp); tp = tp->next) Space before function parameters: thread_valid (tp) > if (thread_alive (tp)) > { > switch_to_thread (tp->ptid); > @@ -1203,6 +1215,8 @@ > execute_command (cmd, from_tty); > strcpy (cmd, saved_cmd); /* Restore exact command used > previously. */ > + if (thread_count() == 0) Space before function parameters: thread_count () > + break; This will not work universally. I did not try it but one can do something like: thread apply all call func() Where func() will pthread_cancel some threads but not all of them. In such case thread_count() will not be 0 but still tp->next may be invalid crashing GDB. You can remember 'num' and always try to find 'num + 1' thread or any higher than 'num'. Thanks, Jan