Implement --thread and --frame.
authorVladimir Prus <vladimir@codesourcery.com>
Sat, 12 Jul 2008 16:37:57 +0000 (16:37 +0000)
committerVladimir Prus <vladimir@codesourcery.com>
Sat, 12 Jul 2008 16:37:57 +0000 (16:37 +0000)
* gdbthread.h (find_thread_id): Declare.
        * thread.c (find_thread_id): Make non-static.
        * mi/mi-main.c (mi_cmd_execute): Switch to the right
        thread and frame, if necessary.
        * mi/mi-parse.c (mi_parse): Handle --thread and --frame.
        * mi/mi-parse.h (strcut mi_parse): New fields thread and frame.

gdb/ChangeLog
gdb/gdbthread.h
gdb/mi/mi-main.c
gdb/mi/mi-parse.c
gdb/mi/mi-parse.h
gdb/thread.c

index 89072a6d1802fd74f2286a6b901bb846e9df3d81..d8b3e0beaba50dac6b271408aac8b30e92bc5bc7 100644 (file)
@@ -1,3 +1,13 @@
+2008-07-12  Vladimir Prus  <vladimir@codesourcery.com>
+
+       Implement --thread and --frame.
+       * gdbthread.h (find_thread_id): Declare.
+        * thread.c (find_thread_id): Make non-static.
+        * mi/mi-main.c (mi_cmd_execute): Switch to the right
+        thread and frame, if necessary.
+        * mi/mi-parse.c (mi_parse): Handle --thread and --frame.
+        * mi/mi-parse.h (strcut mi_parse): New fields thread and frame.
+
 2008-07-12  Vladimir Prus  <vladimir@codesourcery.com>
 
        * infrun.c (resume): Discard cleanups on early exit path.
index 3f1d217e3e624639a1767502959bdec3f8a88c50..f283865ccc58ef62a8e2334e00decd19ddf421d1 100644 (file)
@@ -148,6 +148,9 @@ extern int valid_thread_id (int thread);
 /* Search function to lookup a thread by 'pid'.  */
 extern struct thread_info *find_thread_pid (ptid_t ptid);
 
+/* Find thread by GDB user-visible thread number.  */
+struct thread_info *find_thread_id (int num);
+
 /* Iterator function to call a user-provided callback function
    once for each known thread.  */
 typedef int (*thread_callback_func) (struct thread_info *, void *);
index a82d2f00b12ecab4f8c5b63b1f74b78966695fb5..f829a93cb7f72b14bc2487ab57f9ba14733114b4 100644 (file)
@@ -1052,11 +1052,42 @@ static void
 mi_cmd_execute (struct mi_parse *parse)
 {
   struct cleanup *cleanup;
+  char *thread_str;
+  char *frame_str;
+  int thread;
+  int i;
   free_all_values ();
 
   current_token = xstrdup (parse->token);
   cleanup = make_cleanup (free_current_contents, &current_token);
 
+  if (parse->frame != -1 && parse->thread == -1)
+    error (_("Cannot specify --frame without --thread"));
+  
+  if (parse->thread != -1)
+    {
+      struct thread_info *tp = find_thread_id (parse->thread);
+      if (!tp)
+       error (_("Invalid thread id: %d"), parse->thread);
+      
+      if (non_stop)
+       context_switch_to (tp->ptid);
+      else
+       switch_to_thread (tp->ptid);
+    }
+  
+  if (parse->frame != -1)
+    {
+      struct frame_info *fid;
+      int frame = parse->frame;
+      fid = find_relative_frame (get_current_frame (), &frame);
+      if (frame == 0)
+       /* find_relative_frame was successful */
+       select_frame (fid);
+      else
+       error (_("Invalid frame id: %s"), frame_str);
+    }
+  
   if (parse->cmd->argv_func != NULL)
     {
       if (target_can_async_p ()
@@ -1093,6 +1124,7 @@ mi_cmd_execute (struct mi_parse *parse)
              error_stream (stb);
            }
        }
+
       parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
     }
   else if (parse->cmd->cli.cmd != 0)
index a2dc50d046632132ed45bf28b2783999bcb0498f..73e04aa3d4bcfbbceb13186cc7144ca7c6e084af 100644 (file)
@@ -150,6 +150,8 @@ mi_parse (char *cmd)
   char *chp;
   struct mi_parse *parse = XMALLOC (struct mi_parse);
   memset (parse, 0, sizeof (*parse));
+  parse->thread = -1;
+  parse->frame = -1;
 
   /* Before starting, skip leading white space. */
   while (isspace (*cmd))
@@ -199,6 +201,40 @@ mi_parse (char *cmd)
   while (isspace (*chp))
     chp++;
 
+  /* Parse the --thread and --frame options, if present.  At present,
+     some important commands, like '-break-*' are implemented by forwarding
+     to the CLI layer directly.  We want to parse --thread and --frame
+     here, so as not to leave those option in the string that will be passed
+     to CLI.  */
+  for (;;)
+    {
+      char *start = chp;
+      size_t ts = sizeof ("--thread ") - 1;
+      size_t fs = sizeof ("--frame ") - 1;
+      if (strncmp (chp, "--thread ", ts) == 0)
+       {
+         if (parse->thread != -1)
+           error ("Duplicate '--thread' option");
+         chp += ts;
+         parse->thread = strtol (chp, &chp, 10);
+       }
+      else if (strncmp (chp, "--frame ", fs) == 0)
+       {
+         if (parse->frame != -1)
+           error ("Duplicate '--frame' option");
+         chp += fs;
+         parse->frame = strtol (chp, &chp, 10);
+       }
+      else
+       break;
+
+      if (*chp != '\0' && !isspace (*chp))
+       error ("Invalid value for the '%s' option",
+              start[2] == 't' ? "--thread" : "--frame");
+      while (isspace (*chp))
+       chp++;
+    }
+
   /* For new argv commands, attempt to return the parsed argument
      list. */
   if (parse->cmd->argv_func != NULL)
index 945c42d4d5288309603041987262cbef15542fbe..aa262f5d721777a7d7d68485ce0f5dcbf72a93b0 100644 (file)
@@ -46,6 +46,8 @@ struct mi_parse
     char *args;
     char **argv;
     int argc;
+    int thread;
+    int frame;
   };
 
 /* Attempts to parse CMD returning a ``struct mi_command''.  If CMD is
index bb821cccfcab9ab1492cc4873ef556687f7b815e..02ef6f1f9a9f9ea7269490076045198a00bd61c6 100644 (file)
@@ -54,8 +54,6 @@ void _initialize_thread (void);
 static struct thread_info *thread_list = NULL;
 static int highest_thread_num;
 
-static struct thread_info *find_thread_id (int num);
-
 static void thread_command (char *tidstr, int from_tty);
 static void thread_apply_all_command (char *, int);
 static int thread_alive (struct thread_info *);
@@ -289,7 +287,7 @@ delete_thread_silent (ptid_t ptid)
   delete_thread_1 (ptid, 1 /* silent */);
 }
 
-static struct thread_info *
+struct thread_info *
 find_thread_id (int num)
 {
   struct thread_info *tp;
This page took 0.050229 seconds and 4 git commands to generate.