From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22400 invoked by alias); 24 Nov 2008 23:13:40 -0000 Received: (qmail 22290 invoked by uid 22791); 24 Nov 2008 23:13:38 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Nov 2008 23:13:03 +0000 Received: (qmail 7277 invoked from network); 24 Nov 2008 23:12:53 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 24 Nov 2008 23:12:53 -0000 From: Pedro Alves To: Michael Snyder Subject: Re: [RFA] Add optional argument to "info threads" command Date: Tue, 25 Nov 2008 16:06:00 -0000 User-Agent: KMail/1.9.10 Cc: "gdb-patches@sourceware.org" References: <4928BC24.5020600@vmware.com> <200811241924.14165.pedro@codesourcery.com> <492B2255.4080206@vmware.com> In-Reply-To: <492B2255.4080206@vmware.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_0TzKJZq3ganNAZ9" Message-Id: <200811242312.52342.pedro@codesourcery.com> 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: 2008-11/txt/msg00676.txt.bz2 --Boundary-00=_0TzKJZq3ganNAZ9 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 857 On Monday 24 November 2008 21:53:25, Michael Snyder wrote: > > Isn't this the same reasoning behind having thread_apply_command > > and thread_apply_all implementations, instead of having one call > > into the other? > > OK -- are you suggesting to abstract print_thread_info out > into two separate functions? That, or make print_thread_info itself take a range, something like the attached. If MI wants to be able to specify a range, we could make print_thread_info itself that a char* and do the range parsing there. There's still always both a prune_threads and target_find_new_threads call, but with that I can live. We *could* be smarter about that too. Only prune threads in the passed range iff we're specifying a range (all otherwise); and, only find new threads if any of the range ends is higher than the highest id known. -- Pedro Alves --Boundary-00=_0TzKJZq3ganNAZ9 Content-Type: text/x-diff; charset="iso 8859-15"; name="thread_info_range.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="thread_info_range.diff" Content-length: 6369 --- gdb/thread.c | 135 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 48 deletions(-) Index: src/gdb/thread.c =================================================================== --- src.orig/gdb/thread.c 2008-11-24 22:08:50.000000000 +0000 +++ src/gdb/thread.c 2008-11-24 23:05:22.000000000 +0000 @@ -631,19 +631,22 @@ set_stop_requested (ptid_t ptid, int sto observer_notify_thread_stop_requested (ptid); } -/* Prints the list of threads and their details on UIOUT. - This is a version of 'info_thread_command' suitable for - use from MI. - If REQUESTED_THREAD is not -1, it's the GDB id of the thread - that should be printed. Otherwise, all threads are - printed. - If PID is not -1, only print threads from the process PID. - Otherwise, threads from all attached PIDs are printed. - If both REQUESTED_THREAD and PID are not -1, then the thread - is printed if it belongs to the specified process. Otherwise, - an error is raised. */ -void -print_thread_info (struct ui_out *uiout, int requested_thread, int pid) +/* Prints the list of threads whose id falls in the range specified by + RANGE_START and RANGE_END (inclusive) and their details on UIOUT. + + If RANGE_START is -1, all threads are printed. + + If PID is not -1, only print threads from the process PID (target + id, not GDB inferior number). + + Otherwise, threads from all attached PIDs are printed. If both + RANGE_START and PID are not -1, and RANGE_START equal RANGE_END, + then the RANGE_START thread is printed if it belongs to the + specified process; otherwise, an error is raised. */ + +static void +print_thread_info_1 (struct ui_out *uiout, + int range_start, int range_end, int pid) { struct thread_info *tp; ptid_t current_ptid; @@ -663,12 +666,9 @@ print_thread_info (struct ui_out *uiout, { struct cleanup *chain2; - if (requested_thread != -1 && tp->num != requested_thread) - continue; - if (pid != -1 && PIDGET (tp->ptid) != pid) { - if (requested_thread != -1) + if (range_start != -1 && range_start == range_end) error (_("Requested thread not found in requested process")); continue; } @@ -676,6 +676,10 @@ print_thread_info (struct ui_out *uiout, if (ptid_equal (tp->ptid, current_ptid)) current_thread = tp->num; + if (range_start != -1 + && (tp->num < range_start || range_end < tp->num)) + continue; + if (tp->state_ == THREAD_EXITED) continue; @@ -700,7 +704,12 @@ print_thread_info (struct ui_out *uiout, ui_out_text (uiout, " "); if (tp->state_ == THREAD_RUNNING) - ui_out_text (uiout, "(running)\n"); + { + ui_out_text (uiout, "(running)\n"); + + if (ui_out_is_mi_like_p (uiout)) + ui_out_field_string (uiout, "state", "running"); + } else { /* The switch below puts us at the top of the stack (leaf @@ -710,14 +719,9 @@ print_thread_info (struct ui_out *uiout, /* For MI output, print frame level. */ ui_out_is_mi_like_p (uiout), LOCATION); - } - if (ui_out_is_mi_like_p (uiout)) - { - char *state = "stopped"; - if (tp->state_ == THREAD_RUNNING) - state = "running"; - ui_out_field_string (uiout, "state", state); + if (ui_out_is_mi_like_p (uiout)) + ui_out_field_string (uiout, "state", "stopped"); } do_cleanups (chain2); @@ -727,7 +731,7 @@ print_thread_info (struct ui_out *uiout, the "info threads" command. */ do_cleanups (old_chain); - if (pid == -1 && requested_thread == -1 ) + if (pid == -1 && range_start == -1) { gdb_assert (current_thread != -1 || !thread_list); @@ -741,6 +745,56 @@ The current thread has te } } +/* Prints the list of threads and their details on UIOUT. This is a + version of 'info_thread_command' suitable for use from MI. + + If REQUESTED_THREAD is not -1, it's the GDB id of the thread that + should be printed. Otherwise, all threads are printed. + + If PID is not -1, only print threads from the process PID. + Otherwise, threads from all attached PIDs are printed. If both + REQUESTED_THREAD and PID are not -1, then the thread is printed if + it belongs to the specified process. Otherwise, an error is + raised. */ + +void +print_thread_info (struct ui_out *uiout, int requested_thread, int pid) +{ + print_thread_info_1 (uiout, requested_thread, requested_thread, pid); +} + +/* Parse a thread id or thread id range specified in TIDLIST, and + store it into START and END. */ + +static char * +parse_thread_id_or_range (char *tidlist, int *start, int *end) +{ + char *p; + + *start = strtol (tidlist, &p, 10); + if (p == tidlist) + error (_("Error parsing %s"), tidlist); + tidlist = p; + + while (*tidlist == ' ' || *tidlist == '\t') + tidlist++; + + if (*tidlist == '-') /* Got a range of IDs? */ + { + tidlist++; /* Skip the - */ + *end = strtol (tidlist, &p, 10); + if (p == tidlist) + error (_("Error parsing %s"), tidlist); + tidlist = p; + + while (*tidlist == ' ' || *tidlist == '\t') + tidlist++; + } + else + *end = *start; + + return tidlist; +} /* Print information about currently known threads @@ -752,7 +806,12 @@ The current thread has te static void info_threads_command (char *arg, int from_tty) { - print_thread_info (uiout, -1, -1); + int start = -1, end = -1; + + if (arg && *arg) + parse_thread_range (arg, &start, &end); + + print_thread_info_1 (uiout, start, end, -1); } /* Switch from one thread to another. */ @@ -971,27 +1030,7 @@ thread_apply_command (char *tidlist, int struct thread_info *tp; int start, end; - start = strtol (tidlist, &p, 10); - if (p == tidlist) - error (_("Error parsing %s"), tidlist); - tidlist = p; - - while (*tidlist == ' ' || *tidlist == '\t') - tidlist++; - - if (*tidlist == '-') /* Got a range of IDs? */ - { - tidlist++; /* Skip the - */ - end = strtol (tidlist, &p, 10); - if (p == tidlist) - error (_("Error parsing %s"), tidlist); - tidlist = p; - - while (*tidlist == ' ' || *tidlist == '\t') - tidlist++; - } - else - end = start; + tidlist = parse_thread_range (tidlist, &start, &end); make_cleanup_restore_current_thread (); --Boundary-00=_0TzKJZq3ganNAZ9--