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