From: Vladimir Prus <vladimir@codesourcery.com>
To: gdb-patches@sources.redhat.com
Subject: Re: [MI non-stop 04/11] Implement --thread and --frame.
Date: Sun, 13 Jul 2008 05:45:00 -0000 [thread overview]
Message-ID: <g5c4md$dbm$2@ger.gmane.org> (raw)
In-Reply-To: <200806282044.14246.vladimir@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
Vladimir Prus wrote:
>
> 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.
I've checked in the below. It checks for "--thread " as opposed to "--thread"
as suggested by Marc and uses sizeof.
- Volodya
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: thread.diff --]
[-- Type: text/x-diff; name="thread.diff", Size: 5404 bytes --]
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 89072a6..d8b3e0b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
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.
2008-07-12 Vladimir Prus <vladimir@codesourcery.com>
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 3f1d217..f283865 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -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 *);
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index a82d2f0..f829a93 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -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, ¤t_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)
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index a2dc50d..73e04aa 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,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)
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 bb821cc..02ef6f1 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -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;
prev parent reply other threads:[~2008-07-13 5:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-28 16:54 Vladimir Prus
2008-06-28 17:30 ` Eli Zaretskii
2008-06-28 18:00 ` Vladimir Prus
2008-06-28 18:23 ` Eli Zaretskii
2008-06-28 18:26 ` Marc Khouzam
2008-06-29 6:10 ` Vladimir Prus
2008-06-29 20:15 ` Eli Zaretskii
2008-07-01 3:53 ` Vladimir Prus
2008-06-30 18:35 ` Michael Snyder
2008-06-30 18:42 ` Daniel Jacobowitz
2008-06-28 18:13 ` Marc Khouzam
2008-06-28 18:26 ` Eli Zaretskii
2008-06-28 18:27 ` Marc Khouzam
2008-06-29 6:08 ` Vladimir Prus
2008-06-29 19:42 ` Eli Zaretskii
2008-06-30 0:09 ` Tom Tromey
2008-06-30 8:39 ` Eli Zaretskii
2008-06-30 18:35 ` Michael Snyder
2008-06-30 19:19 ` Tom Tromey
2008-06-30 20:47 ` Daniel Jacobowitz
2008-07-11 12:50 ` Daniel Jacobowitz
2008-07-12 20:15 ` Ulrich Weigand
2008-07-13 3:54 ` Vladimir Prus
2008-07-15 18:42 ` Ulrich Weigand
2008-07-13 5:45 ` Vladimir Prus [this message]
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='g5c4md$dbm$2@ger.gmane.org' \
--to=vladimir@codesourcery.com \
--cc=gdb-patches@sources.redhat.com \
/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