* ada-lang.c (ada_convert_actual): Renames convert_actual.
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-break.c
CommitLineData
fb40c209 1/* MI Command Set - breakpoint and watchpoint commands.
9b254dd1 2 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
ab91fdd5 3 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
fb40c209
AC
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb40c209
AC
19
20#include "defs.h"
21#include "mi-cmds.h"
22#include "ui-out.h"
23#include "mi-out.h"
24#include "breakpoint.h"
25#include "gdb_string.h"
26#include "mi-getopt.h"
27#include "gdb-events.h"
5b7f31a4 28#include "gdb.h"
fb40c209 29
fb40c209
AC
30enum
31 {
32 FROM_TTY = 0
33 };
34
35/* Output a single breakpoint. */
36
37static void
38breakpoint_notify (int b)
39{
ce43223b 40 gdb_breakpoint_query (uiout, b, NULL);
fb40c209
AC
41}
42
43
44struct gdb_events breakpoint_hooks =
45{
46 breakpoint_notify,
47 breakpoint_notify,
48 breakpoint_notify,
49};
50
51
52enum bp_type
53 {
54 REG_BP,
55 HW_BP,
56 REGEXP_BP
57 };
58
afe8ab22
VP
59/* Implements the -break-insert command.
60 See the MI manual for the list of possible options. */
fb40c209
AC
61
62enum mi_cmd_result
63mi_cmd_break_insert (char *command, char **argv, int argc)
64{
65 char *address = NULL;
66 enum bp_type type = REG_BP;
67 int temp_p = 0;
68 int thread = -1;
69 int ignore_count = 0;
70 char *condition = NULL;
afe8ab22 71 int pending = 0;
fb40c209
AC
72 enum gdb_rc rc;
73 struct gdb_events *old_hooks;
74 enum opt
75 {
76 HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT,
afe8ab22 77 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT
fb40c209
AC
78 };
79 static struct mi_opt opts[] =
80 {
81 {"h", HARDWARE_OPT, 0},
82 {"t", TEMP_OPT, 0},
83 {"c", CONDITION_OPT, 1},
84 {"i", IGNORE_COUNT_OPT, 1},
85 {"p", THREAD_OPT, 1},
afe8ab22 86 {"f", PENDING_OPT, 0},
d5d6fca5 87 { 0, 0, 0 }
fb40c209
AC
88 };
89
90 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
91 to denote the end of the option list. */
92 int optind = 0;
93 char *optarg;
94 while (1)
95 {
96 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
97 if (opt < 0)
98 break;
99 switch ((enum opt) opt)
100 {
101 case TEMP_OPT:
102 temp_p = 1;
103 break;
104 case HARDWARE_OPT:
105 type = HW_BP;
106 break;
107#if 0
108 case REGEXP_OPT:
109 type = REGEXP_BP;
110 break;
111#endif
112 case CONDITION_OPT:
113 condition = optarg;
114 break;
115 case IGNORE_COUNT_OPT:
116 ignore_count = atol (optarg);
117 break;
118 case THREAD_OPT:
119 thread = atol (optarg);
120 break;
afe8ab22
VP
121 case PENDING_OPT:
122 pending = 1;
123 break;
fb40c209
AC
124 }
125 }
126
127 if (optind >= argc)
8a3fe4f8 128 error (_("mi_cmd_break_insert: Missing <location>"));
fb40c209 129 if (optind < argc - 1)
8a3fe4f8 130 error (_("mi_cmd_break_insert: Garbage following <location>"));
fb40c209
AC
131 address = argv[optind];
132
133 /* Now we have what we need, let's insert the breakpoint! */
2726dafc 134 old_hooks = deprecated_set_gdb_event_hooks (&breakpoint_hooks);
fb40c209
AC
135 switch (type)
136 {
137 case REG_BP:
138 rc = gdb_breakpoint (address, condition,
139 0 /*hardwareflag */ , temp_p,
ce43223b 140 thread, ignore_count,
afe8ab22 141 pending,
ce43223b 142 &mi_error_message);
fb40c209
AC
143 break;
144 case HW_BP:
145 rc = gdb_breakpoint (address, condition,
146 1 /*hardwareflag */ , temp_p,
ce43223b 147 thread, ignore_count,
afe8ab22 148 pending,
ce43223b 149 &mi_error_message);
fb40c209
AC
150 break;
151#if 0
152 case REGEXP_BP:
153 if (temp_p)
8a3fe4f8 154 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
fb40c209
AC
155 else
156 rbreak_command_wrapper (address, FROM_TTY);
157 return MI_CMD_DONE;
158 break;
159#endif
160 default:
8e65ff28 161 internal_error (__FILE__, __LINE__,
e2e0b3e5 162 _("mi_cmd_break_insert: Bad switch."));
fb40c209 163 }
2726dafc 164 deprecated_set_gdb_event_hooks (old_hooks);
fb40c209
AC
165
166 if (rc == GDB_RC_FAIL)
ce43223b 167 return MI_CMD_ERROR;
fb40c209
AC
168 else
169 return MI_CMD_DONE;
170}
171
172enum wp_type
173{
174 REG_WP,
175 READ_WP,
176 ACCESS_WP
177};
178
179/* Insert a watchpoint. The type of watchpoint is specified by the
180 first argument:
181 -break-watch <expr> --> insert a regular wp.
182 -break-watch -r <expr> --> insert a read watchpoint.
183 -break-watch -a <expr> --> insert an access wp. */
184
185enum mi_cmd_result
186mi_cmd_break_watch (char *command, char **argv, int argc)
187{
188 char *expr = NULL;
189 enum wp_type type = REG_WP;
190 enum opt
191 {
192 READ_OPT, ACCESS_OPT
193 };
194 static struct mi_opt opts[] =
195 {
196 {"r", READ_OPT, 0},
197 {"a", ACCESS_OPT, 0},
d5d6fca5 198 { 0, 0, 0 }
fb40c209
AC
199 };
200
201 /* Parse arguments. */
202 int optind = 0;
203 char *optarg;
204 while (1)
205 {
206 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
207 if (opt < 0)
208 break;
209 switch ((enum opt) opt)
210 {
211 case READ_OPT:
212 type = READ_WP;
213 break;
214 case ACCESS_OPT:
215 type = ACCESS_WP;
216 break;
217 }
218 }
219 if (optind >= argc)
8a3fe4f8 220 error (_("mi_cmd_break_watch: Missing <expression>"));
fb40c209 221 if (optind < argc - 1)
8a3fe4f8 222 error (_("mi_cmd_break_watch: Garbage following <expression>"));
fb40c209
AC
223 expr = argv[optind];
224
225 /* Now we have what we need, let's insert the watchpoint! */
226 switch (type)
227 {
228 case REG_WP:
fb40c209 229 watch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
230 break;
231 case READ_WP:
fb40c209 232 rwatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
233 break;
234 case ACCESS_WP:
fb40c209 235 awatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
236 break;
237 default:
8a3fe4f8 238 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
fb40c209
AC
239 }
240 return MI_CMD_DONE;
241}
This page took 0.576876 seconds and 4 git commands to generate.