]>
Commit | Line | Data |
---|---|---|
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 | |
9 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 | Boston, MA 02110-1301, USA. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "gdb_string.h" | |
24 | #include "target.h" | |
25 | #include "top.h" | |
26 | #include "cli/cli-cmds.h" | |
27 | #include "cli/cli-decode.h" | |
28 | #include "inferior.h" | |
29 | ||
30 | /* User interface: | |
31 | reverse-step, reverse-next etc. */ | |
32 | ||
b4f899bb MS |
33 | static void |
34 | exec_direction_default (void *notused) | |
b2175913 MS |
35 | { |
36 | /* Return execution direction to default state. */ | |
37 | execution_direction = EXEC_FORWARD; | |
38 | } | |
39 | ||
40 | /* exec_reverse_once -- accepts an arbitrary gdb command (string), | |
41 | and executes it with exec-direction set to 'reverse'. | |
42 | ||
43 | Used to implement reverse-next etc. commands. */ | |
44 | ||
45 | static void | |
46 | exec_reverse_once (char *cmd, char *args, int from_tty) | |
47 | { | |
48 | char *reverse_command; | |
49 | enum exec_direction_kind dir = execution_direction; | |
50 | struct cleanup *old_chain; | |
51 | ||
52 | if (dir == EXEC_ERROR) | |
53 | error (_("Target %s does not support this command."), target_shortname); | |
54 | ||
55 | if (dir == EXEC_REVERSE) | |
56 | error (_("Already in reverse mode. Use '%s' or 'set exec-dir forward'."), | |
57 | cmd); | |
58 | ||
59 | if (!target_can_execute_reverse) | |
60 | error (_("Target %s does not support this command."), target_shortname); | |
61 | ||
62 | reverse_command = xstrprintf ("%s %s", cmd, args ? args : ""); | |
63 | old_chain = make_cleanup (exec_direction_default, NULL); | |
64 | make_cleanup (xfree, reverse_command); | |
65 | execution_direction = EXEC_REVERSE; | |
66 | execute_command (reverse_command, from_tty); | |
67 | do_cleanups (old_chain); | |
68 | } | |
69 | ||
70 | static void | |
71 | reverse_step (char *args, int from_tty) | |
72 | { | |
73 | exec_reverse_once ("step", args, from_tty); | |
74 | } | |
75 | ||
76 | static void | |
77 | reverse_stepi (char *args, int from_tty) | |
78 | { | |
79 | exec_reverse_once ("stepi", args, from_tty); | |
80 | } | |
81 | ||
82 | static void | |
83 | reverse_next (char *args, int from_tty) | |
84 | { | |
85 | exec_reverse_once ("next", args, from_tty); | |
86 | } | |
87 | ||
88 | static void | |
89 | reverse_nexti (char *args, int from_tty) | |
90 | { | |
91 | exec_reverse_once ("nexti", args, from_tty); | |
92 | } | |
93 | ||
94 | static void | |
95 | reverse_continue (char *args, int from_tty) | |
96 | { | |
97 | exec_reverse_once ("continue", args, from_tty); | |
98 | } | |
99 | ||
100 | static void | |
101 | reverse_finish (char *args, int from_tty) | |
102 | { | |
103 | exec_reverse_once ("finish", args, from_tty); | |
104 | } | |
105 | ||
2c0b251b PA |
106 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
107 | extern initialize_file_ftype _initialize_reverse; | |
108 | ||
b2175913 MS |
109 | void |
110 | _initialize_reverse (void) | |
111 | { | |
112 | add_com ("reverse-step", class_run, reverse_step, _("\ | |
113 | Step program backward until it reaches the beginning of another source line.\n\ | |
114 | Argument N means do this N times (or till program stops for another reason).") | |
115 | ); | |
116 | add_com_alias ("rs", "reverse-step", class_alias, 1); | |
117 | ||
118 | add_com ("reverse-next", class_run, reverse_next, _("\ | |
119 | Step program backward, proceeding through subroutine calls.\n\ | |
120 | Like the \"reverse-step\" command as long as subroutine calls do not happen;\n\ | |
121 | when they do, the call is treated as one instruction.\n\ | |
122 | Argument N means do this N times (or till program stops for another reason).") | |
123 | ); | |
124 | add_com_alias ("rn", "reverse-next", class_alias, 1); | |
125 | ||
126 | add_com ("reverse-stepi", class_run, reverse_stepi, _("\ | |
127 | Step backward exactly one instruction.\n\ | |
128 | Argument N means do this N times (or till program stops for another reason).") | |
129 | ); | |
130 | add_com_alias ("rsi", "reverse-stepi", class_alias, 0); | |
131 | ||
132 | add_com ("reverse-nexti", class_run, reverse_nexti, _("\ | |
133 | Step backward one instruction, but proceed through called subroutines.\n\ | |
134 | Argument N means do this N times (or till program stops for another reason).") | |
135 | ); | |
136 | add_com_alias ("rni", "reverse-nexti", class_alias, 0); | |
137 | ||
138 | add_com ("reverse-continue", class_run, reverse_continue, _("\ | |
139 | Continue program being debugged but run it in reverse.\n\ | |
140 | If proceeding from breakpoint, a number N may be used as an argument,\n\ | |
141 | which means to set the ignore count of that breakpoint to N - 1 (so that\n\ | |
142 | the breakpoint won't break until the Nth time it is reached).")); | |
143 | add_com_alias ("rc", "reverse-continue", class_alias, 0); | |
144 | ||
145 | add_com ("reverse-finish", class_run, reverse_finish, _("\ | |
146 | Execute backward until just before selected stack frame is called.")); | |
147 | } |