Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Snyder <msnyder@vmware.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [commit] Simplify "thread apply" with get_number_or_range
Date: Sat, 19 Feb 2011 02:18:00 -0000	[thread overview]
Message-ID: <4D5F1C3A.7000403@vmware.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 77 bytes --]

I love this.  I'm going to look for other commands to which it could apply.


[-- Attachment #2: getnum2.txt --]
[-- Type: text/plain, Size: 2384 bytes --]

2011-02-18  Michael Snyder  <msnyder@vmware.com>

	* thread.c (thread_apply_command): Re-implement using 
	get_number_or_range.	

Index: thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.134
diff -u -p -u -p -r1.134 thread.c
--- thread.c	19 Feb 2011 01:02:56 -0000	1.134
+++ thread.c	19 Feb 2011 01:22:56 -0000
@@ -1212,7 +1212,6 @@ static void
 thread_apply_command (char *tidlist, int from_tty)
 {
   char *cmd;
-  char *p;
   struct cleanup *old_chain;
   char *saved_cmd;
 
@@ -1231,51 +1230,29 @@ thread_apply_command (char *tidlist, int
   while (tidlist < cmd)
     {
       struct thread_info *tp;
-      int start, end;
+      int start;
+      char *p = tidlist;
 
-      start = strtol (tidlist, &p, 10);
-      if (p == tidlist)
-	error (_("Error parsing %s"), tidlist);
-      tidlist = p;
+      start = get_number_or_range (&tidlist);
 
-      while (*tidlist == ' ' || *tidlist == '\t')
-	tidlist++;
+      make_cleanup_restore_current_thread ();
 
-      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;
+      tp = find_thread_id (start);
 
-	  while (*tidlist == ' ' || *tidlist == '\t')
-	    tidlist++;
-	}
+      if (!tp)
+	warning (_("Unknown thread %d."), start);
+      else if (!thread_alive (tp))
+	warning (_("Thread %d has terminated."), start);
       else
-	end = start;
-
-      make_cleanup_restore_current_thread ();
-
-      for (; start <= end; start++)
 	{
-	  tp = find_thread_id (start);
+	  switch_to_thread (tp->ptid);
 
-	  if (!tp)
-	    warning (_("Unknown thread %d."), start);
-	  else if (!thread_alive (tp))
-	    warning (_("Thread %d has terminated."), start);
-	  else
-	    {
-	      switch_to_thread (tp->ptid);
+	  printf_filtered (_("\nThread %d (%s):\n"), tp->num,
+			   target_pid_to_str (inferior_ptid));
+	  execute_command (cmd, from_tty);
 
-	      printf_filtered (_("\nThread %d (%s):\n"), tp->num,
-			       target_pid_to_str (inferior_ptid));
-	      execute_command (cmd, from_tty);
-
-	      /* Restore exact command used previously.  */
-	      strcpy (cmd, saved_cmd);
-	    }
+	  /* Restore exact command used previously.  */
+	  strcpy (cmd, saved_cmd);
 	}
     }
 

             reply	other threads:[~2011-02-19  1:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-19  2:18 Michael Snyder [this message]
2011-02-24 20:30 ` Tom Tromey
2011-02-24 20:33   ` Michael Snyder
2011-02-24 20:40     ` Tom Tromey
2011-02-24 21:27   ` info inferior, was " Michael Snyder
2011-02-25 13:22     ` Pedro Alves

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=4D5F1C3A.7000403@vmware.com \
    --to=msnyder@vmware.com \
    --cc=gdb-patches@sourceware.org \
    /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