2009-11-17 Daniel Jacobowitz <dan@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / reverse.c
CommitLineData
b2175913
MS
1/* Reverse execution and reverse debugging.
2
0fb0cc75 3 Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
b2175913
MS
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
5b1ba0e5 9 the Free Software Foundation; either version 3 of the License, or
b2175913
MS
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
5b1ba0e5 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b2175913
MS
19
20#include "defs.h"
21#include "gdb_string.h"
22#include "target.h"
23#include "top.h"
24#include "cli/cli-cmds.h"
25#include "cli/cli-decode.h"
26#include "inferior.h"
27
28/* User interface:
29 reverse-step, reverse-next etc. */
30
b4f899bb
MS
31static void
32exec_direction_default (void *notused)
b2175913
MS
33{
34 /* Return execution direction to default state. */
35 execution_direction = EXEC_FORWARD;
36}
37
38/* exec_reverse_once -- accepts an arbitrary gdb command (string),
39 and executes it with exec-direction set to 'reverse'.
40
41 Used to implement reverse-next etc. commands. */
42
43static void
44exec_reverse_once (char *cmd, char *args, int from_tty)
45{
46 char *reverse_command;
47 enum exec_direction_kind dir = execution_direction;
48 struct cleanup *old_chain;
49
50 if (dir == EXEC_ERROR)
51 error (_("Target %s does not support this command."), target_shortname);
52
53 if (dir == EXEC_REVERSE)
54 error (_("Already in reverse mode. Use '%s' or 'set exec-dir forward'."),
55 cmd);
56
57 if (!target_can_execute_reverse)
58 error (_("Target %s does not support this command."), target_shortname);
59
60 reverse_command = xstrprintf ("%s %s", cmd, args ? args : "");
61 old_chain = make_cleanup (exec_direction_default, NULL);
62 make_cleanup (xfree, reverse_command);
63 execution_direction = EXEC_REVERSE;
64 execute_command (reverse_command, from_tty);
65 do_cleanups (old_chain);
66}
67
68static void
69reverse_step (char *args, int from_tty)
70{
71 exec_reverse_once ("step", args, from_tty);
72}
73
74static void
75reverse_stepi (char *args, int from_tty)
76{
77 exec_reverse_once ("stepi", args, from_tty);
78}
79
80static void
81reverse_next (char *args, int from_tty)
82{
83 exec_reverse_once ("next", args, from_tty);
84}
85
86static void
87reverse_nexti (char *args, int from_tty)
88{
89 exec_reverse_once ("nexti", args, from_tty);
90}
91
92static void
93reverse_continue (char *args, int from_tty)
94{
95 exec_reverse_once ("continue", args, from_tty);
96}
97
98static void
99reverse_finish (char *args, int from_tty)
100{
101 exec_reverse_once ("finish", args, from_tty);
102}
103
2c0b251b
PA
104/* Provide a prototype to silence -Wmissing-prototypes. */
105extern initialize_file_ftype _initialize_reverse;
106
b2175913
MS
107void
108_initialize_reverse (void)
109{
110 add_com ("reverse-step", class_run, reverse_step, _("\
111Step program backward until it reaches the beginning of another source line.\n\
112Argument N means do this N times (or till program stops for another reason).")
113 );
114 add_com_alias ("rs", "reverse-step", class_alias, 1);
115
116 add_com ("reverse-next", class_run, reverse_next, _("\
117Step program backward, proceeding through subroutine calls.\n\
118Like the \"reverse-step\" command as long as subroutine calls do not happen;\n\
119when they do, the call is treated as one instruction.\n\
120Argument N means do this N times (or till program stops for another reason).")
121 );
122 add_com_alias ("rn", "reverse-next", class_alias, 1);
123
124 add_com ("reverse-stepi", class_run, reverse_stepi, _("\
125Step backward exactly one instruction.\n\
126Argument N means do this N times (or till program stops for another reason).")
127 );
128 add_com_alias ("rsi", "reverse-stepi", class_alias, 0);
129
130 add_com ("reverse-nexti", class_run, reverse_nexti, _("\
131Step backward one instruction, but proceed through called subroutines.\n\
132Argument N means do this N times (or till program stops for another reason).")
133 );
134 add_com_alias ("rni", "reverse-nexti", class_alias, 0);
135
136 add_com ("reverse-continue", class_run, reverse_continue, _("\
137Continue program being debugged but run it in reverse.\n\
138If proceeding from breakpoint, a number N may be used as an argument,\n\
139which means to set the ignore count of that breakpoint to N - 1 (so that\n\
140the breakpoint won't break until the Nth time it is reached)."));
141 add_com_alias ("rc", "reverse-continue", class_alias, 0);
142
143 add_com ("reverse-finish", class_run, reverse_finish, _("\
144Execute backward until just before selected stack frame is called."));
145}
This page took 0.129924 seconds and 4 git commands to generate.