From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23242 invoked by alias); 24 Aug 2012 22:23:36 -0000 Received: (qmail 23234 invoked by uid 22791); 24 Aug 2012 22:23:35 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-iy0-f169.google.com (HELO mail-iy0-f169.google.com) (209.85.210.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Aug 2012 22:23:22 +0000 Received: by iahk25 with SMTP id k25so4951372iah.0 for ; Fri, 24 Aug 2012 15:23:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-system-of-record:x-gm-message-state; bh=vM6gyhUrYhXO4cdWkmw15QVuFfLadDy3BemovJLcxL0=; b=KzSH83WgPoKr5ELxXa/V4h22tgUTzzsx9SiHY2TivT/yyQDHcMlcogMv820ox/Tcld JgQUXctw7DR2sQwy5PaHiJEVBu0uw3O+XIgknutHO0Wtf/5+vN99MwXwT0tGk/JLIcah QgpaulLTnlKDV7d/VnFrabDBlzB1PkpcOHKjhfVUOYi8YoJpEBhQ7Ayc9UI4FoldnnyX S9PBjm0DIepfW3ZiWkT23OeFHNVBUlk5YiyEdd0JmyQSdGqVz7xB/3Cq2aey9V5ze3DR VphFPWVLsBBe416W/z0MshfE8ubmJSqXddiGYcL9mWfSiz8Kb3U4GEqcDQQWovKVypfR myQA== Received: by 10.42.60.139 with SMTP id q11mr5646986ich.53.1345847002175; Fri, 24 Aug 2012 15:23:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.42.60.139 with SMTP id q11mr5646976ich.53.1345847002011; Fri, 24 Aug 2012 15:23:22 -0700 (PDT) Received: by 10.50.104.233 with HTTP; Fri, 24 Aug 2012 15:23:21 -0700 (PDT) In-Reply-To: <87obm0jhpi.fsf@fleche.redhat.com> References: <87pq6isqt9.fsf@fleche.redhat.com> <87pq6hppiz.fsf@fleche.redhat.com> <87obm0jhpi.fsf@fleche.redhat.com> Date: Fri, 24 Aug 2012 22:23:00 -0000 Message-ID: Subject: Re: [patch] info threads sort by name and name regex matching From: Aaron Gamble To: Tom Tromey Cc: Sergio Durigan Junior , gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true X-Gm-Message-State: ALoCoQkE9mchc5Y8RA3yQoIVcSfph6iQtK2pn7tiJGk6m0ynvHawr7Np8GsCNJ86Seof6xFRBJLGcB5I+yb/NIh0NwmZsHXiRSdv2GRPiSmQrYgmbVeQ7qj9mZCeweeheg//+kSVRwI4p61oU1jhUPWYKjfIC0/f1Ejgru5Z5lRb081jkUSOuV8LYh/6YiNBjTG0eGkHMkLck1J1WVcE8UZs/1DyuueEQg== 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-08/txt/msg00774.txt.bz2 On Fri, Aug 24, 2012 at 10:57 AM, Tom Tromey wrote: > >>>>>> "Aaron" == Aaron Gamble writes: > > Aaron> -a enables sorting by thread name > > Is '-a' mnemonic for something? -a is for alphabetical. Would -s be more appropriate? > 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. Ack. > 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. Would it be safe to use target_thread_name in print_thread_sort_cmp each time the name is used in the sort function? I'm not entirely sure why it's unsafe to store the NULL pointers when the name could not be determined.