This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[MI non-stop 04/11] Implement --thread and --frame.
- From: Vladimir Prus <vladimir at codesourcery dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 28 Jun 2008 20:44:14 +0400
- Subject: [MI non-stop 04/11] Implement --thread and --frame.
This implements the --thread and --frame options to all MI command.
Please see http://article.gmane.org/gmane.comp.gdb.devel/23414/ for
background design for --thread. The --frame is ideologically same
as --thread.
The only non-MI change here is making find_thread_pid exported from
thread.c, which change seems obvious, so no approval is needed. Comments,
however, are much appreciated.
- Volodya
* 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 (struct mi_parse): New fields thread and frame.
---
gdb/gdbthread.h | 3 +++
gdb/mi/mi-main.c | 32 ++++++++++++++++++++++++++++++++
gdb/mi/mi-parse.c | 34 ++++++++++++++++++++++++++++++++++
gdb/mi/mi-parse.h | 2 ++
gdb/thread.c | 4 +---
5 files changed, 72 insertions(+), 3 deletions(-)
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index a061d86..878e44f 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -138,6 +138,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 *);
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 3c92980..61ef5a4 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1123,6 +1123,10 @@ static void
mi_cmd_execute (struct mi_parse *parse)
{
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+ char *thread_str;
+ char *frame_str;
+ int thread;
+ int i;
free_all_values ();
/* Switch to the frontend selected thread, before invoking the
@@ -1135,6 +1139,33 @@ mi_cmd_execute (struct mi_parse *parse)
the selected thread. */
make_cleanup (do_restore_selected_thread_and_frame_cleanup, NULL);
+ 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 ()
@@ -1171,6 +1202,7 @@ mi_cmd_execute (struct mi_parse *parse)
error_stream (stb);
}
}
+
current_token = xstrdup (parse->token);
cleanup = make_cleanup (free_current_contents, ¤t_token);
parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index a2dc50d..835fb74 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -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,38 @@ 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;
+ if (strncmp (chp, "--thread", 8) == 0)
+ {
+ if (parse->thread != -1)
+ error ("Duplicate '--thread' option");
+ chp += 8;
+ parse->thread = strtol (chp, &chp, 10);
+ }
+ else if (strncmp (chp, "--frame", 7) == 0)
+ {
+ if (parse->frame != -1)
+ error ("Duplicate '--frame' option");
+ chp += 7;
+ 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)
diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
index 945c42d..aa262f5 100644
--- a/gdb/mi/mi-parse.h
+++ b/gdb/mi/mi-parse.h
@@ -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
diff --git a/gdb/thread.c b/gdb/thread.c
index 4e172d8..be0d175 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -55,8 +55,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 *);
@@ -275,7 +273,7 @@ delete_thread (ptid_t ptid)
free_thread (tp);
}
-static struct thread_info *
+struct thread_info *
find_thread_id (int num)
{
struct thread_info *tp;
--
1.5.3.5