From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24627 invoked by alias); 14 Feb 2011 19:54:21 -0000 Received: (qmail 24617 invoked by uid 22791); 14 Feb 2011 19:54:19 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-outbound-2.vmware.com (HELO smtp-outbound-2.vmware.com) (65.115.85.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Feb 2011 19:54:14 +0000 Received: from mailhost2.vmware.com (mailhost2.vmware.com [10.16.67.167]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id D4FBA34006; Mon, 14 Feb 2011 11:54:11 -0800 (PST) Received: from msnyder-server.eng.vmware.com (promd-2s-dhcp138.eng.vmware.com [10.20.124.138]) by mailhost2.vmware.com (Postfix) with ESMTP id C707C8EDD2; Mon, 14 Feb 2011 11:54:11 -0800 (PST) Message-ID: <4D598863.1030507@vmware.com> Date: Mon, 14 Feb 2011 20:03:00 -0000 From: Michael Snyder User-Agent: Thunderbird 2.0.0.24 (X11/20101201) MIME-Version: 1.0 To: Tom Tromey , "gdb-patches@sourceware.org" Subject: Re: [RFC] info threads takes an argument References: <4D54964A.2070401@vmware.com> <20110211060855.GT2384@adacore.com> <4D558CA9.7070302@vmware.com> <4D55B1ED.5020808@vmware.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------050204020200060009020302" 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: 2011-02/txt/msg00293.txt.bz2 This is a multi-part message in MIME format. --------------050204020200060009020302 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 635 Tom Tromey wrote: > > Michael> add_info ("threads", info_threads_command, > Michael> _("Usage: info threads [ID]. Display currently known > Michael> threads.\n\ > Michael> If ID is given, display only that thread;\ > Michael> otherwise, all threads are displayed.")); > > I think I'd like it if the Usage was always on its own line. > How about: > > Display currently known threads. > Usage: info threads [ID] > If ID is given, it is the id of the sole thread to display. > Otherwise, all threads are displayed. OK, so modified, and combined with the new 'thread find' patch. Documentation and NEWS also attached. --------------050204020200060009020302 Content-Type: text/plain; name="find.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="find.txt" Content-length: 7084 2011-02-14 Michael Snyder * thread.c (info_threads_command): Process arg as thread id, or list of thread ids. (thread_find_command): New command. (_initialize_thread): Document argument for info threads. Document 'thread find' command. * NEWS: Document new command "thread find". 2011-02-14 Michael Snyder * gdb.texinfo (threads): Document argument for "info threads" cmd. Document new command "thread find". Index: thread.c =================================================================== RCS file: /cvs/src/src/gdb/thread.c,v retrieving revision 1.131 diff -u -p -u -p -r1.131 thread.c --- thread.c 19 Jan 2011 17:21:36 -0000 1.131 +++ thread.c 14 Feb 2011 19:51:42 -0000 @@ -43,6 +43,7 @@ #include "observer.h" #include "annotate.h" #include "cli/cli-decode.h" +#include "gdb_regex.h" /* Definition of struct thread_info exported to gdbthread.h. */ @@ -957,15 +958,35 @@ No selected thread. See `help thread'.\ /* Print information about currently known threads - * Note: this has the drawback that it _really_ switches - * threads, which frees the frame cache. A no-side - * effects info-threads command would be nicer. - */ + Optional ARG is a thread id, or list of thread ids. + + Note: this has the drawback that it _really_ switches + threads, which frees the frame cache. A no-side + effects info-threads command would be nicer. */ static void info_threads_command (char *arg, int from_tty) { - print_thread_info (uiout, -1, -1); + int tid = -1; + + if (arg == NULL || *arg == '\0') + { + print_thread_info (uiout, -1, -1); + return; + } + + while (arg != NULL && *arg != '\0') + { + int tmp_tid + = (int) parse_and_eval_long (scan_expression_with_cleanup (&arg, + NULL)); + + if (tmp_tid != 0) + { + tid = tmp_tid; + print_thread_info (uiout, tid, -1); + } + } } /* Switch from one thread to another. */ @@ -1313,6 +1334,56 @@ thread_name_command (char *arg, int from info->name = arg ? xstrdup (arg) : NULL; } +/* Find thread ids with a name, target pid, or extra info matching ARG. */ + +static void +thread_find_command (char *arg, int from_tty) +{ + struct thread_info *tp; + char *tmp; + unsigned long match = 0; + + if (arg == NULL || *arg == '\0') + error (_("Command requires an argument.")); + + tmp = re_comp (arg); + if (tmp != 0) + error (_("Invalid regexp (%s): %s"), tmp, arg); + + update_thread_list (); + for (tp = thread_list; tp; tp = tp->next) + { + if (tp->name != NULL && re_exec (tp->name)) + { + printf_filtered ("Thread %d has name '%s'\n", tp->num, tp->name); + match++; + } + + tmp = target_thread_name (tp); + if (tmp != NULL && re_exec (tmp)) + { + printf_filtered ("Thread %d has target name '%s'\n", tp->num, tmp); + match++; + } + + tmp = target_pid_to_str (tp->ptid); + if (tmp != NULL && re_exec (tmp)) + { + printf_filtered ("Thread %d has target id '%s'\n", tp->num, tmp); + match++; + } + + tmp = target_extra_thread_info (tp); + if (tmp != NULL && re_exec (tmp)) + { + printf_filtered ("Thread %d has extra info '%s'\n", tp->num, tmp); + match++; + } + } + if (!match) + printf_filtered ("No threads match '%s'\n", arg); +} + /* Print notices when new threads are attached and detached. */ int print_thread_events = 1; static void @@ -1403,8 +1474,11 @@ _initialize_thread (void) { static struct cmd_list_element *thread_apply_list = NULL; - add_info ("threads", info_threads_command, - _("IDs of currently known threads.")); + add_info ("threads", info_threads_command, + _("Display currently known threads.\n\ +Usage: info threads [ID [ID]...]\n\ +If ID is given, display only that thread or those threads;\n\ +otherwise, all threads are displayed.")); add_prefix_cmd ("thread", class_run, thread_command, _("\ Use this command to switch between threads.\n\ @@ -1418,11 +1492,15 @@ The new thread ID must be currently know add_cmd ("all", class_run, thread_apply_all_command, _("Apply a command to all threads."), &thread_apply_list); - add_cmd ("name", class_run, thread_name_command, + add_cmd ("name", no_class, thread_name_command, _("Set the current thread's name.\n\ Usage: thread name [NAME]\n\ If NAME is not given, then any existing name is removed."), &thread_cmd_list); + add_cmd ("find", no_class, thread_find_command, _("\ +Find thread ids with a name, target pid, or extra info matching REGEXP."), + &thread_cmd_list); + if (!xdb_commands) add_com_alias ("t", "thread", class_run, 1); Index: NEWS =================================================================== RCS file: /cvs/src/src/gdb/NEWS,v retrieving revision 1.425 diff -u -p -u -p -r1.425 NEWS --- NEWS 5 Feb 2011 05:27:23 -0000 1.425 +++ NEWS 14 Feb 2011 19:51:42 -0000 @@ -3,6 +3,10 @@ *** Changes since GDB 7.2 +* GDB has a new command: "thread find [regexp]". + It finds the thread id whose name, target id, or thread extra info + matches the given regular expression. + * The "catch syscall" command now works on mips*-linux* targets. * The -data-disassemble MI command now supports modes 2 and 3 for Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.797 diff -u -p -u -p -r1.797 gdb.texinfo --- doc/gdb.texinfo 4 Feb 2011 21:54:15 -0000 1.797 +++ doc/gdb.texinfo 14 Feb 2011 19:51:44 -0000 @@ -2706,9 +2706,10 @@ number---always a single integer---with @table @code @kindex info threads -@item info threads -Display a summary of all threads currently in your -program. @value{GDBN} displays for each thread (in this order): +@item info threads @r{[}@var{ids}@r{]} +Display a summary of all threads currently in your program. Optional +argument @var{ids} means print information only about the specified +thread or threads. @value{GDBN} displays for each thread (in this order): @enumerate @item @@ -2805,6 +2806,24 @@ systems, a name specified with @samp{thr system-give name, and removing the user-specified name will cause @value{GDBN} to once again display the system-specified name. +@kindex thread find +@cindex search for a thread +@item thread find [@var{regexp}] +Search for and display thread ids whose name, target thread id, or +target extra info matches the supplied regular expression. + +As well as being the complement to the @samp{thread name} command, +this command also allows you to identify a thread by its target thread +id. For instance, on Linux, the target thread id is the LWP id. + +@smallexample +(@value{GDBN}) thread find 26688 +Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)' +(@value{GDBN}) info thread 4 + Id Target Id Frame + 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select () +@end smallexample + @kindex set print thread-events @cindex print messages on thread start and exit @item set print thread-events --------------050204020200060009020302--