daily update
[deliverable/binutils-gdb.git] / gdb / reverse.c
CommitLineData
b2175913
MS
1/* Reverse execution and reverse debugging.
2
3 Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
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
33static void exec_direction_default (void *notused)
34{
35 /* Return execution direction to default state. */
36 execution_direction = EXEC_FORWARD;
37}
38
39/* exec_reverse_once -- accepts an arbitrary gdb command (string),
40 and executes it with exec-direction set to 'reverse'.
41
42 Used to implement reverse-next etc. commands. */
43
44static void
45exec_reverse_once (char *cmd, char *args, int from_tty)
46{
47 char *reverse_command;
48 enum exec_direction_kind dir = execution_direction;
49 struct cleanup *old_chain;
50
51 if (dir == EXEC_ERROR)
52 error (_("Target %s does not support this command."), target_shortname);
53
54 if (dir == EXEC_REVERSE)
55 error (_("Already in reverse mode. Use '%s' or 'set exec-dir forward'."),
56 cmd);
57
58 if (!target_can_execute_reverse)
59 error (_("Target %s does not support this command."), target_shortname);
60
61 reverse_command = xstrprintf ("%s %s", cmd, args ? args : "");
62 old_chain = make_cleanup (exec_direction_default, NULL);
63 make_cleanup (xfree, reverse_command);
64 execution_direction = EXEC_REVERSE;
65 execute_command (reverse_command, from_tty);
66 do_cleanups (old_chain);
67}
68
69static void
70reverse_step (char *args, int from_tty)
71{
72 exec_reverse_once ("step", args, from_tty);
73}
74
75static void
76reverse_stepi (char *args, int from_tty)
77{
78 exec_reverse_once ("stepi", args, from_tty);
79}
80
81static void
82reverse_next (char *args, int from_tty)
83{
84 exec_reverse_once ("next", args, from_tty);
85}
86
87static void
88reverse_nexti (char *args, int from_tty)
89{
90 exec_reverse_once ("nexti", args, from_tty);
91}
92
93static void
94reverse_continue (char *args, int from_tty)
95{
96 exec_reverse_once ("continue", args, from_tty);
97}
98
99static void
100reverse_finish (char *args, int from_tty)
101{
102 exec_reverse_once ("finish", args, from_tty);
103}
104
105void
106_initialize_reverse (void)
107{
108 add_com ("reverse-step", class_run, reverse_step, _("\
109Step program backward until it reaches the beginning of another source line.\n\
110Argument N means do this N times (or till program stops for another reason).")
111 );
112 add_com_alias ("rs", "reverse-step", class_alias, 1);
113
114 add_com ("reverse-next", class_run, reverse_next, _("\
115Step program backward, proceeding through subroutine calls.\n\
116Like the \"reverse-step\" command as long as subroutine calls do not happen;\n\
117when they do, the call is treated as one instruction.\n\
118Argument N means do this N times (or till program stops for another reason).")
119 );
120 add_com_alias ("rn", "reverse-next", class_alias, 1);
121
122 add_com ("reverse-stepi", class_run, reverse_stepi, _("\
123Step backward exactly one instruction.\n\
124Argument N means do this N times (or till program stops for another reason).")
125 );
126 add_com_alias ("rsi", "reverse-stepi", class_alias, 0);
127
128 add_com ("reverse-nexti", class_run, reverse_nexti, _("\
129Step backward one instruction, but proceed through called subroutines.\n\
130Argument N means do this N times (or till program stops for another reason).")
131 );
132 add_com_alias ("rni", "reverse-nexti", class_alias, 0);
133
134 add_com ("reverse-continue", class_run, reverse_continue, _("\
135Continue program being debugged but run it in reverse.\n\
136If proceeding from breakpoint, a number N may be used as an argument,\n\
137which means to set the ignore count of that breakpoint to N - 1 (so that\n\
138the breakpoint won't break until the Nth time it is reached)."));
139 add_com_alias ("rc", "reverse-continue", class_alias, 0);
140
141 add_com ("reverse-finish", class_run, reverse_finish, _("\
142Execute backward until just before selected stack frame is called."));
143}
This page took 0.034559 seconds and 4 git commands to generate.