This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: GDB MI Reverse Commands added [1 of 3]
- From: Michael Snyder <msnyder at vmware dot com>
- To: Vladimir Prus <vladimir at codesourcery dot com>
- Cc: Jakob Engblom <jakob at virtutech dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 15 Dec 2009 11:37:09 -0800
- Subject: Re: GDB MI Reverse Commands added [1 of 3]
- References: <00ce01ca265a$ccb66ca0$662345e0$@com> <4A95E670.9040402@vmware.com>
Michael Snyder wrote:
Jakob Engblom wrote:
Here are the patches adding the MI commands for reverse execution to gdb.
Changelog entry: "Added reverse debugging support to gdb MI"
Group, this patch seemed to have gotten a little munged in email.
I've taken the liberty of re-diffing it, to restore white space context.
Vladimir, as far as I can tell, this seems to be the most recent
version of part 1 of this patch, awaiting approval now that the
copyright paperwork is completed.
2009-08-31 Tomas Holmberg >th@virtutech.com>
* mi/mi-main.c: Added the --reverse flag to the following MI
commands: exec-continue, exec-finish, exec-next, exec-step,
exec-next-instruction, exec-step-instruction. This is to
support reverse execution over the MI interface to gdb.
Index: mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.156
diff -u -p -r1.156 mi-main.c
--- mi-main.c 2 Jul 2009 17:25:59 -0000 1.156
+++ mi-main.c 27 Aug 2009 01:45:23 -0000
@@ -88,8 +88,8 @@ static void mi_cmd_execute (struct mi_pa
static void mi_execute_cli_command (const char *cmd, int args_p,
const char *args);
-static void mi_execute_async_cli_command (char *cli_command,
- char **argv, int argc);
+static void mi_execute_async_cli_command (char *cli_command,
+ char **argv, int argc);
static int register_changed_p (int regnum, struct regcache *,
struct regcache *);
static void get_register (struct frame_info *, int regnum, int format);
@@ -119,35 +119,50 @@ void
mi_cmd_exec_next (char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
- mi_execute_async_cli_command ("next", argv, argc);
+ if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
+ mi_execute_async_cli_command ("reverse-next", argv + 1, argc - 1);
+ else
+ mi_execute_async_cli_command ("next", argv, argc);
}
void
mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
- mi_execute_async_cli_command ("nexti", argv, argc);
+ if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
+ mi_execute_async_cli_command ("reverse-nexti", argv + 1, argc - 1);
+ else
+ mi_execute_async_cli_command ("nexti", argv, argc);
}
void
mi_cmd_exec_step (char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
- mi_execute_async_cli_command ("step", argv, argc);
+ if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
+ mi_execute_async_cli_command ("reverse-step", argv + 1, argc - 1);
+ else
+ mi_execute_async_cli_command ("step", argv, argc);
}
void
mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
- mi_execute_async_cli_command ("stepi", argv, argc);
+ if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
+ mi_execute_async_cli_command ("reverse-stepi", argv + 1, argc - 1);
+ else
+ mi_execute_async_cli_command ("stepi", argv, argc);
}
void
mi_cmd_exec_finish (char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
- mi_execute_async_cli_command ("finish", argv, argc);
+ if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
+ mi_execute_async_cli_command ("reverse-finish", argv + 1, argc - 1);
+ else
+ mi_execute_async_cli_command ("finish", argv, argc);
}
void
@@ -175,7 +190,7 @@ mi_cmd_exec_jump (char *args, char **arg
/* FIXME: Should call a libgdb function, not a cli wrapper. */
return mi_execute_async_cli_command ("jump", argv, argc);
}
-
+
static int
proceed_thread_callback (struct thread_info *thread, void *arg)
{
@@ -193,8 +208,8 @@ proceed_thread_callback (struct thread_i
return 0;
}
-void
-mi_cmd_exec_continue (char *command, char **argv, int argc)
+static void
+exec_continue (char **argv, int argc)
{
if (argc == 0)
continue_1 (0);
@@ -212,10 +227,50 @@ mi_cmd_exec_continue (char *command, cha
old_chain = make_cleanup_restore_current_thread ();
iterate_over_threads (proceed_thread_callback, &pid);
- do_cleanups (old_chain);
+ do_cleanups (old_chain);
}
else
- error ("Usage: -exec-continue [--all|--thread-group id]");
+ error ("Usage: -exec-continue [--reverse] [--all|--thread-group id]");
+}
+
+/* continue in reverse direction:
+ XXX: code duplicated from reverse.c */
+
+static void
+exec_direction_default (void *notused)
+{
+ /* Return execution direction to default state. */
+ execution_direction = EXEC_FORWARD;
+}
+
+static void
+exec_reverse_continue (char **argv, int argc)
+{
+ enum exec_direction_kind dir = execution_direction;
+ struct cleanup *old_chain;
+
+ if (dir == EXEC_ERROR)
+ error (_("Target %s does not support this command."), target_shortname);
+
+ if (dir == EXEC_REVERSE)
+ error (_("Already in reverse mode."));
+
+ if (!target_can_execute_reverse)
+ error (_("Target %s does not support this command."), target_shortname);
+
+ old_chain = make_cleanup (exec_direction_default, NULL);
+ execution_direction = EXEC_REVERSE;
+ exec_continue (argv, argc);
+ do_cleanups (old_chain);
+}
+
+void
+mi_cmd_exec_continue (char *command, char **argv, int argc)
+{
+ if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
+ exec_reverse_continue (argv + 1, argc - 1);
+ else
+ exec_continue (argv, argc);
}
static int
@@ -252,7 +307,7 @@ mi_cmd_exec_interrupt (char *command, ch
{
if (!any_running ())
error ("Inferior not running.");
-
+
interrupt_target_1 (1);
}
else if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
@@ -349,7 +404,7 @@ void
mi_cmd_thread_info (char *command, char **argv, int argc)
{
int thread = -1;
-
+
if (argc != 0 && argc != 1)
error ("Invalid MI command");
@@ -367,7 +422,7 @@ print_one_inferior (struct inferior *inf
ui_out_field_fmt (uiout, "id", "%d", inferior->pid);
ui_out_field_string (uiout, "type", "process");
ui_out_field_int (uiout, "pid", inferior->pid);
-
+
do_cleanups (back_to);
return 0;
}
@@ -433,14 +488,14 @@ mi_cmd_list_thread_groups (char *command
int pid = atoi (id);
if (!in_inferior_list (pid))
error ("Invalid thread group id '%s'", id);
- print_thread_info (uiout, -1, pid);
+ print_thread_info (uiout, -1, pid);
}
else
{
make_cleanup_ui_out_list_begin_end (uiout, "groups");
iterate_over_inferiors (print_one_inferior, NULL);
}
-
+
do_cleanups (back_to);
}
@@ -713,7 +768,7 @@ get_register (struct frame_info *frame,
}
/* Write given values into registers. The registers and values are
- given as pairs. The corresponding MI command is
+ given as pairs. The corresponding MI command is
-data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]*/
void
mi_cmd_data_write_register_values (char *command, char **argv, int argc)
@@ -810,7 +865,7 @@ mi_cmd_data_evaluate_expression (char *c
/* DATA-MEMORY-READ:
ADDR: start address of data to be dumped.
- WORD-FORMAT: a char indicating format for the ``word''. See
+ WORD-FORMAT: a char indicating format for the ``word''. See
the ``x'' command.
WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes.
NR_ROW: Number of rows.
@@ -823,7 +878,7 @@ mi_cmd_data_evaluate_expression (char *c
{addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
- Returns:
+ Returns:
The number of bytes read is SIZE*ROW*COL. */
void
@@ -1019,7 +1074,7 @@ mi_cmd_data_read_memory (char *command,
ADDR: start address of the row in the memory grid where the memory
cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
the location to write to.
- FORMAT: a char indicating format for the ``word''. See
+ FORMAT: a char indicating format for the ``word''. See
the ``x'' command.
WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
VALUE: value to be written into the memory address.
@@ -1112,7 +1167,7 @@ mi_cmd_enable_timings (char *command, ch
}
else
goto usage_error;
-
+
return;
usage_error:
@@ -1125,16 +1180,16 @@ mi_cmd_list_features (char *command, cha
if (argc == 0)
{
struct cleanup *cleanup = NULL;
- cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
+ cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
ui_out_field_string (uiout, NULL, "frozen-varobjs");
ui_out_field_string (uiout, NULL, "pending-breakpoints");
ui_out_field_string (uiout, NULL, "thread-info");
-
+
#if HAVE_PYTHON
ui_out_field_string (uiout, NULL, "python");
#endif
-
+
do_cleanups (cleanup);
return;
}
@@ -1148,11 +1203,11 @@ mi_cmd_list_target_features (char *comma
if (argc == 0)
{
struct cleanup *cleanup = NULL;
- cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
+ cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
if (target_can_async_p ())
ui_out_field_string (uiout, NULL, "async");
-
+
do_cleanups (cleanup);
return;
}
@@ -1196,8 +1251,8 @@ captured_mi_execute_command (struct ui_o
/* Print the result if there were no errors.
Remember that on the way out of executing a command, you have
- to directly use the mi_interp's uiout, since the command could
- have reset the interpreter, in which case the current uiout
+ to directly use the mi_interp's uiout, since the command could
+ have reset the interpreter, in which case the current uiout
will most likely crash in the mi_out_* routines. */
if (!running_result_record_printed)
{
@@ -1244,7 +1299,7 @@ captured_mi_execute_command (struct ui_o
mi_out_put (uiout, raw_stdout);
mi_out_rewind (uiout);
mi_print_timing_maybe ();
- fputs_unfiltered ("\n", raw_stdout);
+ fputs_unfiltered ("\n", raw_stdout);
}
else
mi_out_rewind (uiout);
@@ -1302,9 +1357,9 @@ mi_execute_command (char *cmd, int from_
}
if (/* The notifications are only output when the top-level
- interpreter (specified on the command line) is MI. */
+ interpreter (specified on the command line) is MI. */
ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ()))
- /* Don't try report anything if there are no threads --
+ /* Don't try report anything if there are no threads --
the program is dead. */
&& thread_count () != 0
/* -thread-select explicitly changes thread. If frontend uses that
@@ -1328,10 +1383,10 @@ mi_execute_command (char *cmd, int from_
}
if (report_change)
- {
+ {
struct thread_info *ti = inferior_thread ();
target_terminal_ours ();
- fprintf_unfiltered (mi->event_channel,
+ fprintf_unfiltered (mi->event_channel,
"thread-selected,id=\"%d\"",
ti->num);
gdb_flush (mi->event_channel);
@@ -1446,7 +1501,7 @@ mi_execute_async_cli_command (char *cli_
run = xstrprintf ("%s %s&", cli_command, argc ? *argv : "");
else
run = xstrprintf ("%s %s", cli_command, argc ? *argv : "");
- old_cleanups = make_cleanup (xfree, run);
+ old_cleanups = make_cleanup (xfree, run);
execute_command ( /*ui */ run, 0 /*from_tty */ );
@@ -1551,7 +1606,7 @@ mi_load_progress (const char *section_na
uiout = saved_uiout;
}
-static void
+static void
timestamp (struct mi_timestamp *tv)
{
long usec;
@@ -1571,7 +1626,7 @@ timestamp (struct mi_timestamp *tv)
#endif
}
-static void
+static void
print_diff_now (struct mi_timestamp *start)
{
struct mi_timestamp now;
@@ -1588,20 +1643,20 @@ mi_print_timing_maybe (void)
print_diff_now (current_command_ts);
}
-static long
+static long
timeval_diff (struct timeval start, struct timeval end)
{
return ((end.tv_sec - start.tv_sec) * 1000000L)
+ (end.tv_usec - start.tv_usec);
}
-static void
+static void
print_diff (struct mi_timestamp *start, struct mi_timestamp *end)
{
fprintf_unfiltered
(raw_stdout,
- ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
- timeval_diff (start->wallclock, end->wallclock) / 1000000.0,
- timeval_diff (start->utime, end->utime) / 1000000.0,
+ ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
+ timeval_diff (start->wallclock, end->wallclock) / 1000000.0,
+ timeval_diff (start->utime, end->utime) / 1000000.0,
timeval_diff (start->stime, end->stime) / 1000000.0);
}