From patchwork Wed Apr 9 08:31:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tristan Gingold X-Patchwork-Id: 437 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id A003E360060 for ; Wed, 9 Apr 2014 01:31:11 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14314964) id 4EE1146E7E9B; Wed, 9 Apr 2014 01:31:11 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 2AFB246E7E5B for ; Wed, 9 Apr 2014 01:31:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:content-type:content-transfer-encoding :subject:message-id:date:to:mime-version; q=dns; s=default; b=OV GnQCW4KGVFjNoYMRwEMAuRZaQawiFo0JDmZG1oll8LAdRwSsVz53RkOaFawNNpWy ARciL/DwEb4B2vxqTjVv+jvq4DDMkJuO+hN6vbonHytQlMtX1fGezaGSqfUWnAyW 3vyOyEsUo5vv7TVFM0B3ZkncpaRDUCuSM5S7n9yRc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:content-type:content-transfer-encoding :subject:message-id:date:to:mime-version; s=default; bh=MmCRMR9R Jd6CHDURMY6CegnHp38=; b=ZinFvwkm1k4WVMpDzrN+Eg9qvCqZtE47NbUz30yO IP9mOFmuweAV5k77yp9mgpp3GunqAapytx4bhbvjoIZQvtTl0kkF+cb0Bl2yNdfE F9JXO0M3R1uaxPEIhFEn/nqpiIOsKAtUzNMuX7xpeYsIqTG6pr7wjW0C6gg37W2q cP8= Received: (qmail 25859 invoked by alias); 9 Apr 2014 08:31:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 25850 invoked by uid 89); 9 Apr 2014 08:31:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 09 Apr 2014 08:31:06 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 8A4352720223 for ; Wed, 9 Apr 2014 10:31:03 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KDQqfITyjQfJ for ; Wed, 9 Apr 2014 10:31:03 +0200 (CEST) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 6F94F27200E2 for ; Wed, 9 Apr 2014 10:31:03 +0200 (CEST) From: Tristan Gingold Subject: [Darwin]: Fix hangs Message-Id: <87AFF524-1EC7-47B7-998D-5377F6D71E86@adacore.com> Date: Wed, 9 Apr 2014 10:31:03 +0200 To: " ml" Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Hello, Due to a thinko, a mach message could be not understood and ignored. The result was a dead-lock (gdb is waiting for an event that never happen). The port of the thread was deallocated before new threads are discovered. As a consequence, the origin of the message was unknown (instead of being linked to the newly created thread). Committed on trunk. Tristan. gdb/ * darwin-nat.c (darwin_check_new_threads): Fix port leak, add comments. (darwin_decode_exception_message): Free port only after use. diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 6f9a64a..0ffa69a 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -303,9 +303,18 @@ darwin_check_new_threads (struct inferior *inf) break; if (i == new_nbr) { + /* Deallocate ports. */ + for (i = 0; i < new_nbr; i++) + { + kret = mach_port_deallocate (mach_task_self (), thread_list[i]); + MACH_CHECK_ERROR (kret); + } + + /* Deallocate the buffer. */ kret = vm_deallocate (gdb_task, (vm_address_t) thread_list, new_nbr * sizeof (int)); MACH_CHECK_ERROR (kret); + return; } } @@ -331,8 +340,10 @@ darwin_check_new_threads (struct inferior *inf) new_ix++; old_ix++; - kret = mach_port_deallocate (gdb_task, old_id); + /* Deallocate the port. */ + kret = mach_port_deallocate (gdb_task, new_id); MACH_CHECK_ERROR (kret); + continue; } if (new_ix < new_nbr && new_id == MACH_PORT_DEAD) @@ -382,6 +393,7 @@ darwin_check_new_threads (struct inferior *inf) VEC_free (darwin_thread_t, darwin_inf->threads); darwin_inf->threads = thread_vec; + /* Deallocate the buffer. */ kret = vm_deallocate (gdb_task, (vm_address_t) thread_list, new_nbr * sizeof (int)); MACH_CHECK_ERROR (kret); @@ -594,11 +606,10 @@ darwin_decode_exception_message (mach_msg_header_t *hdr, task_port = desc[1].name; thread_port = desc[0].name; - /* We got new rights to the task and the thread. Get rid of them. */ + /* We got new rights to the task, get rid of it. Do not get rid of thread + right, as we will need it to find the thread. */ kret = mach_port_deallocate (mach_task_self (), task_port); MACH_CHECK_ERROR (kret); - kret = mach_port_deallocate (mach_task_self (), thread_port); - MACH_CHECK_ERROR (kret); /* Find process by port. */ inf = darwin_find_inferior_by_task (task_port); @@ -611,6 +622,10 @@ darwin_decode_exception_message (mach_msg_header_t *hdr, kern_return_t kret; mig_reply_error_t reply; + /* Free thread port (we don't know it). */ + kret = mach_port_deallocate (mach_task_self (), thread_port); + MACH_CHECK_ERROR (kret); + darwin_encode_reply (&reply, hdr, KERN_SUCCESS); kret = mach_msg (&reply.Head, MACH_SEND_MSG | MACH_SEND_INTERRUPT, @@ -627,6 +642,11 @@ darwin_decode_exception_message (mach_msg_header_t *hdr, message can be deallocated. */ darwin_check_new_threads (inf); + /* Free the thread port (as gdb knows the thread, it has already has a right + for it, so this just decrement a reference counter). */ + kret = mach_port_deallocate (mach_task_self (), thread_port); + MACH_CHECK_ERROR (kret); + thread = darwin_find_thread (inf, thread_port); if (thread == NULL) return -1;