1 /* MI Command Set - breakpoint and watchpoint commands.
2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions (a Red Hat company).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "gdb_string.h"
28 #include "mi-getopt.h"
30 #include "exceptions.h"
38 /* True if MI breakpoint observers have been registered. */
40 static int mi_breakpoint_observers_installed
;
42 /* Control whether breakpoint_notify may act. */
44 static int mi_can_breakpoint_notify
;
46 /* Output a single breakpoint, when allowed. */
49 breakpoint_notify (int b
)
51 if (mi_can_breakpoint_notify
)
52 gdb_breakpoint_query (uiout
, b
, NULL
);
62 /* Implements the -break-insert command.
63 See the MI manual for the list of possible options. */
66 mi_cmd_break_insert (char *command
, char **argv
, int argc
)
73 char *condition
= NULL
;
77 struct cleanup
*back_to
;
81 HARDWARE_OPT
, TEMP_OPT
, CONDITION_OPT
,
82 IGNORE_COUNT_OPT
, THREAD_OPT
, PENDING_OPT
, DISABLE_OPT
,
85 static struct mi_opt opts
[] =
87 {"h", HARDWARE_OPT
, 0},
89 {"c", CONDITION_OPT
, 1},
90 {"i", IGNORE_COUNT_OPT
, 1},
92 {"f", PENDING_OPT
, 0},
93 {"d", DISABLE_OPT
, 0},
94 {"a", TRACEPOINT_OPT
, 0},
98 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
99 to denote the end of the option list. */
105 int opt
= mi_getopt ("mi_cmd_break_insert", argc
, argv
, opts
, &optind
, &optarg
);
108 switch ((enum opt
) opt
)
119 case IGNORE_COUNT_OPT
:
120 ignore_count
= atol (optarg
);
123 thread
= atol (optarg
);
138 error (_("mi_cmd_break_insert: Missing <location>"));
139 if (optind
< argc
- 1)
140 error (_("mi_cmd_break_insert: Garbage following <location>"));
141 address
= argv
[optind
];
143 /* Now we have what we need, let's insert the breakpoint! */
144 if (! mi_breakpoint_observers_installed
)
146 observer_attach_breakpoint_created (breakpoint_notify
);
147 observer_attach_breakpoint_modified (breakpoint_notify
);
148 observer_attach_breakpoint_deleted (breakpoint_notify
);
149 mi_breakpoint_observers_installed
= 1;
152 back_to
= make_cleanup_restore_integer (&mi_can_breakpoint_notify
);
153 mi_can_breakpoint_notify
= 1;
154 create_breakpoint (get_current_arch (), address
, condition
, thread
,
155 0 /* condition and thread are valid. */,
156 temp_p
, hardware
, tracepoint
,
158 pending
? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
160 do_cleanups (back_to
);
172 mi_cmd_break_passcount (char *command
, char **argv
, int argc
)
176 struct breakpoint
*t
;
179 error (_("Usage: tracepoint-number passcount"));
183 t
= get_tracepoint (n
);
188 observer_notify_tracepoint_modified (n
);
192 error (_("Cound not find tracepoint %d"), n
);
196 /* Insert a watchpoint. The type of watchpoint is specified by the
198 -break-watch <expr> --> insert a regular wp.
199 -break-watch -r <expr> --> insert a read watchpoint.
200 -break-watch -a <expr> --> insert an access wp. */
203 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
206 enum wp_type type
= REG_WP
;
211 static struct mi_opt opts
[] =
214 {"a", ACCESS_OPT
, 0},
218 /* Parse arguments. */
224 int opt
= mi_getopt ("mi_cmd_break_watch", argc
, argv
,
225 opts
, &optind
, &optarg
);
229 switch ((enum opt
) opt
)
240 error (_("mi_cmd_break_watch: Missing <expression>"));
241 if (optind
< argc
- 1)
242 error (_("mi_cmd_break_watch: Garbage following <expression>"));
245 /* Now we have what we need, let's insert the watchpoint! */
249 watch_command_wrapper (expr
, FROM_TTY
);
252 rwatch_command_wrapper (expr
, FROM_TTY
);
255 awatch_command_wrapper (expr
, FROM_TTY
);
258 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
262 /* The mi_read_next_line consults these variable to return successive
263 command lines. While it would be clearer to use a closure pointer,
264 it is not expected that any future code will use read_command_lines_1,
265 therefore no point of overengineering. */
267 static char **mi_command_line_array
;
268 static int mi_command_line_array_cnt
;
269 static int mi_command_line_array_ptr
;
272 mi_read_next_line (void)
274 if (mi_command_line_array_ptr
== mi_command_line_array_cnt
)
277 return mi_command_line_array
[mi_command_line_array_ptr
++];
281 mi_cmd_break_commands (char *command
, char **argv
, int argc
)
283 struct command_line
*break_command
;
286 struct breakpoint
*b
;
289 error ("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command
);
291 bnum
= strtol (argv
[0], &endptr
, 0);
292 if (endptr
== argv
[0])
293 error ("breakpoint number argument \"%s\" is not a number.",
295 else if (*endptr
!= '\0')
296 error ("junk at the end of breakpoint number argument \"%s\".",
299 b
= get_breakpoint (bnum
);
301 error ("breakpoint %d not found.", bnum
);
303 mi_command_line_array
= argv
;
304 mi_command_line_array_ptr
= 1;
305 mi_command_line_array_cnt
= argc
;
307 if (is_tracepoint (b
))
308 break_command
= read_command_lines_1 (mi_read_next_line
, 1,
309 check_tracepoint_command
, b
);
311 break_command
= read_command_lines_1 (mi_read_next_line
, 1, 0, 0);
313 breakpoint_set_commands (b
, break_command
);