From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22423 invoked by alias); 10 Jul 2013 17:55:51 -0000 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 Received: (qmail 22412 invoked by uid 89); 10 Jul 2013 17:55:51 -0000 X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,TW_CP autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 10 Jul 2013 17:55:50 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6AHtm4R030373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 10 Jul 2013 13:55:48 -0400 Received: from barimba (ovpn-113-131.phx2.redhat.com [10.3.113.131]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r6AHtkXZ021340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 10 Jul 2013 13:55:47 -0400 From: Tom Tromey To: ali_anwar Cc: Pedro Alves , Subject: Re: Updated patch for Bug 13217 - thread apply all detach throws a SEGFAULT References: <5062EA9B.1060505@codesourcery.com> <871uhnwkf3.fsf@fleche.redhat.com> <50C62BBB.6010404@codesourcery.com> <87hantek1p.fsf@fleche.redhat.com> <50C75319.9080903@codesourcery.com> <50C7628F.5080004@redhat.com> <51DD37FA.8010306@codesourcery.com> Date: Wed, 10 Jul 2013 17:55:00 -0000 In-Reply-To: <51DD37FA.8010306@codesourcery.com> (ali anwar's message of "Wed, 10 Jul 2013 15:31:22 +0500") Message-ID: <87k3kyfgf1.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-07/txt/msg00288.txt.bz2 >>>>> "Ali" == ali anwar writes: Ali> + /* Save a copy of the thread_list in case we execute detach Ali> + command. */ Ali> + tp_array = xmalloc (sizeof (struct thread_info*) * tc); Extra space after the "=". Missing space before the "*" in the type name. Ali> + ta_cleanup.tp_array = tp_array; Ali> + ta_cleanup.count = tc; Ali> + Ali> + ALL_THREADS (tp) Ali> + { Ali> + tp_array[i] = tp; Ali> + tp->refcount++; Ali> + i++; Ali> + } Ali> + for (k = 0; k != i; k++) Ali> + if (thread_alive (tp_array[k])) Ali> + { Ali> + switch_to_thread (tp_array[k]->ptid); Ali> + printf_filtered (_("\nThread %d (%s):\n"), Ali> + tp_array[k]->num, target_pid_to_str (inferior_ptid)); Ali> + execute_command (cmd, from_tty); Ali> + strcpy (cmd, saved_cmd); /* Restore exact command used Ali> + previously. */ Ali> + } Ali> + Ali> + make_cleanup (xfree, tp_array); Ali> + make_cleanup (make_cleanup_thread_refcount, &ta_cleanup); This installs the cleanups at the wrong point. They must be installed before any potential exception is thrown. That is, the xfree cleanup ought to be created just after initialization; and the refcount cleanup ought to be created after the refcounts are incremented. Also, make_cleanup_thread_refcount is misnamed. By convention, a "make_cleanup_" function creates a new cleanup. The function that does the work of cleaning up is given a different name. Tom