From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17762 invoked by alias); 24 Aug 2012 17:58:08 -0000 Received: (qmail 17743 invoked by uid 22791); 24 Aug 2012 17:58:06 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS 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; Fri, 24 Aug 2012 17:57:47 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7OHvkYp029535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 24 Aug 2012 13:57:46 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7OHvjsf000499 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 24 Aug 2012 13:57:45 -0400 From: Tom Tromey To: Aaron Gamble Cc: Sergio Durigan Junior , gdb-patches@sourceware.org Subject: Re: [patch] info threads sort by name and name regex matching References: <87pq6isqt9.fsf@fleche.redhat.com> <87pq6hppiz.fsf@fleche.redhat.com> Date: Fri, 24 Aug 2012 17:58:00 -0000 In-Reply-To: (Aaron Gamble's message of "Thu, 23 Aug 2012 18:09:12 -0700") Message-ID: <87obm0jhpi.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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-08/txt/msg00757.txt.bz2 >>>>> "Aaron" == Aaron Gamble writes: Aaron> -a enables sorting by thread name Is '-a' mnemonic for something? Aaron> +static int Aaron> +print_thread_sort_cmp (const void *p1, const void *p2) Aaron> +{ Aaron> + const char *name1 = (*(struct thread_info **) p1)->cached_name; Aaron> + const char *name2 = (*(struct thread_info **) p2)->cached_name; Aaron> + if (name1 && name2) Aaron> + return strcmp (name1, name2); The gdb style is to have a blank line between declarations and code. Aaron> +static void Aaron> +thread_cache_name (struct thread_info *tp) Aaron> +{ Aaron> + /* Does not need to be freed, is only transient. */ Aaron> + tp->cached_name = tp->name ? tp->name : target_thread_name (tp); I realized while re-reading the patch that this isn't safe. target_thread_name has a funny contract, as you note, where it returns static data. But this means that the result can't be cached -- otherwise all threads with non-NULL names will end up with the same cached name. Either you have to copy the name here or change target_thread_name to do so; and then make sure to free at the right spots, etc. Tom