[patch] info threads sort by name and name regex matching
Tom Tromey
tromey@redhat.com
Fri Aug 24 17:58:00 GMT 2012
>>>>> "Aaron" == Aaron Gamble <agamble@google.com> 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
More information about the Gdb-patches
mailing list