From: Aaron Gamble <agamble@google.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [patch] info threads sort by name and name regex matching
Date: Fri, 24 Aug 2012 22:23:00 -0000 [thread overview]
Message-ID: <CAHX8C+LKEScbpJvr466qoQAFDM-HQ-swYdj9jYMaiakc1oeXgQ@mail.gmail.com> (raw)
In-Reply-To: <87obm0jhpi.fsf@fleche.redhat.com>
On Fri, Aug 24, 2012 at 10:57 AM, Tom Tromey <tromey@redhat.com> wrote:
>
>>>>>> "Aaron" == Aaron Gamble <agamble@google.com> 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.
next prev parent reply other threads:[~2012-08-24 22:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-21 21:19 Aaron Gamble
2012-08-22 10:06 ` Abid, Hafiz
2012-08-22 17:15 ` Eli Zaretskii
2012-08-22 18:52 ` Tom Tromey
2012-08-22 22:37 ` Aaron Gamble
2012-08-22 23:30 ` Sergio Durigan Junior
2012-08-23 16:00 ` Tom Tromey
2012-08-24 1:09 ` Aaron Gamble
2012-08-24 17:58 ` Tom Tromey
2012-08-24 22:23 ` Aaron Gamble [this message]
2012-08-24 22:32 ` Sergio Durigan Junior
2012-08-24 23:21 ` Aaron Gamble
2012-08-24 23:28 ` Aaron Gamble
2012-08-25 3:12 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHX8C+LKEScbpJvr466qoQAFDM-HQ-swYdj9jYMaiakc1oeXgQ@mail.gmail.com \
--to=agamble@google.com \
--cc=gdb-patches@sourceware.org \
--cc=sergiodj@redhat.com \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox