#include "defs.h"
#include "target.h"
#include "mi-cmds.h"
#include "ui-out.h"
#include "mi-out.h"
#include "breakpoint.h"
#include "gdb_string.h"
#include "mi-getopt.h"
#include "mi-main.h"
#include "gdb-events.h"
#include "interps.h"
#include "gdb.h"
#include "gdbcmd.h"
#include "filenames.h"
enum
{
FROM_TTY = 0
};
static void
breakpoint_notify (int b, int pending_bp)
{
gdb_breakpoint_query (uiout, b, NULL);
}
struct gdb_events breakpoint_hooks =
{
breakpoint_notify,
breakpoint_notify,
breakpoint_notify,
};
enum bp_type
{
REG_BP,
HW_BP,
FUT_BP,
REGEXP_BP
};
enum mi_cmd_result
mi_cmd_break_insert (char *command, char **argv, int argc)
{
char *address = NULL;
enum bp_type type = REG_BP;
int temp_p = 0;
int thread = -1;
int ignore_count = 0;
char *condition = NULL;
char *requested_shlib = NULL;
char realpath_buf[PATH_MAX];
enum gdb_rc rc;
int *indices = NULL;
struct gdb_events *old_hooks;
enum opt
{
HARDWARE_OPT, TEMP_OPT, FUTURE_OPT , CONDITION_OPT,
IGNORE_COUNT_OPT, THREAD_OPT, SHLIB_OPT, LIST_OPT
};
static struct mi_opt opts[] =
{
{"h", HARDWARE_OPT, 0},
{"t", TEMP_OPT, 0},
{"f", FUTURE_OPT, 0},
{"c", CONDITION_OPT, 1},
{"i", IGNORE_COUNT_OPT, 1},
{"p", THREAD_OPT, 1},
{"s", SHLIB_OPT, 1},
{"l", LIST_OPT, 1},
0
};
int optind = 0;
char *optarg;
struct cleanup *indices_cleanup = NULL;
while (1)
{
int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
if (opt < 0)
break;
switch ((enum opt) opt)
{
case TEMP_OPT:
temp_p = 1;
break;
case HARDWARE_OPT:
type = HW_BP;
break;
case FUTURE_OPT:
type = FUT_BP;
break;
#if 0
case REGEXP_OPT:
type = REGEXP_BP;
break;
#endif
case CONDITION_OPT:
condition = optarg;
break;
case IGNORE_COUNT_OPT:
ignore_count = atol (optarg);
if (ignore_count < 0)
ignore_count = 0;
break;
case THREAD_OPT:
thread = atol (optarg);
break;
case SHLIB_OPT:
requested_shlib = optarg;
break;
case LIST_OPT:
{
char *numptr;
int nelem = 0, i;
numptr = optarg;
while (*numptr)
{
if (*numptr != ' ')
{
nelem++;
while (*numptr != ' ' && *numptr != '\0')
numptr++;
}
else
numptr++;
}
if (nelem == 0)
error ("mi_cmd_break_insert: Got index with no elements");
indices = (int *) xmalloc ((nelem + 1) * sizeof (int *));
indices_cleanup = make_cleanup (xfree, indices);
numptr = optarg;
i = 0;
errno = 0;
while (*numptr != '\0')
{
indices[i++] = strtol (numptr, &numptr, 10);
if (errno == EINVAL)
error ("mi_cmd_break_insert: bad index at \"%s\"", numptr);
}
indices[i] = -1;
break;
}
}
}
if (optind >= argc)
error (_("mi_cmd_break_insert: Missing <location>"));
if (optind < argc - 1)
error (_("mi_cmd_break_insert: Garbage following <location>"));
address = argv[optind];
if (requested_shlib && IS_ABSOLUTE_PATH (requested_shlib))
{
realpath (requested_shlib, realpath_buf);
requested_shlib = realpath_buf;
}
old_hooks = deprecated_set_gdb_event_hooks (&breakpoint_hooks);
switch (type)
{
case REG_BP:
rc = gdb_breakpoint (address, condition,
0 , temp_p,
0 , thread,
ignore_count, indices, requested_shlib,
&mi_error_message);
break;
case HW_BP:
rc = gdb_breakpoint (address, condition,
1 , temp_p,
0 , thread,
ignore_count, indices, requested_shlib,
&mi_error_message);
break;
case FUT_BP:
rc = gdb_breakpoint (address, condition,
0, temp_p,
1 , thread,
ignore_count, indices, requested_shlib,
&mi_error_message);
break;
#if 0
case REGEXP_BP:
if (temp_p)
error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
else
rbreak_command_wrapper (address, FROM_TTY);
return MI_CMD_DONE;
break;
#endif
default:
internal_error (__FILE__, __LINE__,
_("mi_cmd_break_insert: Bad switch."));
}
deprecated_set_gdb_event_hooks (old_hooks);
if (indices_cleanup != NULL)
do_cleanups (indices_cleanup);
if (rc == GDB_RC_FAIL)
return MI_CMD_ERROR;
else
return MI_CMD_DONE;
}
enum wp_type
{
REG_WP,
READ_WP,
ACCESS_WP
};
enum mi_cmd_result
mi_cmd_break_watch (char *command, char **argv, int argc)
{
char *expr = NULL;
enum wp_type type = REG_WP;
int watch_location = 0;
enum opt
{
READ_OPT, ACCESS_OPT, LOCATION_OPT
};
static struct mi_opt opts[] =
{
{"r", READ_OPT, 0},
{"a", ACCESS_OPT, 0},
{"l", LOCATION_OPT, 0},
0
};
int optind = 0;
char *optarg;
while (1)
{
int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
if (opt < 0)
break;
switch ((enum opt) opt)
{
case READ_OPT:
type = READ_WP;
break;
case ACCESS_OPT:
type = ACCESS_WP;
break;
case LOCATION_OPT:
watch_location = 1;
break;
}
}
if (optind >= argc)
error (_("mi_cmd_break_watch: Missing <expression>"));
if (optind < argc - 1)
error (_("mi_cmd_break_watch: Garbage following <expression>"));
expr = argv[optind];
switch (type)
{
case REG_WP:
watch_command_wrapper (expr, watch_location, FROM_TTY);
break;
case READ_WP:
rwatch_command_wrapper (expr, watch_location, FROM_TTY);
break;
case ACCESS_WP:
awatch_command_wrapper (expr, watch_location, FROM_TTY);
break;
default:
error (_("mi_cmd_break_watch: Unknown watchpoint type."));
}
return MI_CMD_DONE;
}
char **mi_command_line_array;
int mi_command_line_array_cnt;
int mi_command_line_array_ptr;
static char *
mi_read_next_line ()
{
if (mi_command_line_array_ptr == mi_command_line_array_cnt)
return NULL;
else
{
return mi_command_line_array[mi_command_line_array_ptr++];
}
}
enum mi_cmd_result
mi_cmd_break_commands (char *command, char **argv, int argc)
{
struct command_line *break_command;
char *endptr;
int bnum;
struct breakpoint *b;
if (argc < 1)
error ("%s: USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command, command);
bnum = strtol (argv[0], &endptr, 0);
if (endptr == argv[0])
{
xasprintf (&mi_error_message,
"%s: breakpoint number argument \"%s\" is not a number.",
command, argv[0]);
return MI_CMD_ERROR;
}
else if (*endptr != '\0')
{
xasprintf (&mi_error_message,
"%s: junk at the end of breakpoint number argument \"%s\".",
command, argv[0]);
return MI_CMD_ERROR;
}
b = find_breakpoint (bnum);
if (b == NULL)
{
xasprintf (&mi_error_message,
"%s: breakpoint %d not found.",
command, bnum);
return MI_CMD_ERROR;
}
if (argc == 1)
{
breakpoint_print_commands (uiout, b);
return MI_CMD_DONE;
}
mi_command_line_array = argv;
mi_command_line_array_ptr = 1;
mi_command_line_array_cnt = argc;
break_command = read_command_lines_1 (mi_read_next_line);
breakpoint_add_commands (b, break_command);
return MI_CMD_DONE;
}
enum mi_cmd_result
mi_cmd_break_catch (char *command, char **argv, int argc)
{
enum exception_event_kind ex_event;
int ret_val;
if (argc < 1)
error ("mi_cmd_break_catch: USAGE: %s [catch|throw] [on|off]", command);
if (strcmp(argv[0], "catch") == 0)
ex_event = EX_EVENT_CATCH;
else if (strcmp(argv[0], "throw") == 0)
ex_event = EX_EVENT_THROW;
else
error ("mi_cmd_break_catch: bad argument, should be \"catch\""
" or \"throw\"");
if (argc == 2)
{
if (strcmp (argv[1], "off") == 0)
{
if (exception_catchpoints_enabled (ex_event))
{
disable_exception_catch (ex_event);
return MI_CMD_DONE;
}
else
{
return MI_CMD_ERROR;
}
}
else if (strcmp (argv[1], "on") != 0)
error ("mi_cmd_break_catch: bad argument 2, should be \"on\""
" or \"off\".");
}
if (exception_catchpoints_enabled (ex_event))
return MI_CMD_DONE;
if (handle_gnu_v3_exceptions (ex_event))
{
gnu_v3_update_exception_catchpoints (ex_event, 0, NULL);
return MI_CMD_DONE;
}
if (target_enable_exception_callback (ex_event, 1))
{
error ("mi_cmd_break_catch: error getting callback routine.");
}
return MI_CMD_DONE;
}
void
mi_interp_create_breakpoint_hook (struct breakpoint *bpt)
{
struct ui_out *saved_ui_out = uiout;
struct cleanup *list_cleanup;
if (bpt->number == 0)
return;
uiout = interp_ui_out (mi_interp);
list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "MI_HOOK_RESULT");
ui_out_field_string (uiout, "HOOK_TYPE", "breakpoint_create");
gdb_breakpoint_query (uiout, bpt->number, NULL);
do_cleanups (list_cleanup);
uiout = saved_ui_out;
}
void
mi_interp_modify_breakpoint_hook (struct breakpoint *bpt)
{
struct ui_out *saved_ui_out = uiout;
struct cleanup *list_cleanup;
if (bpt->number == 0)
return;
uiout = interp_ui_out (mi_interp);
list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "MI_HOOK_RESULT");
ui_out_field_string (uiout, "HOOK_TYPE", "breakpoint_modify");
gdb_breakpoint_query (uiout, bpt->number, NULL);
do_cleanups (list_cleanup);
uiout = saved_ui_out;
}
void
mi_interp_delete_breakpoint_hook (struct breakpoint *bpt)
{
struct ui_out *saved_ui_out = uiout;
struct cleanup *list_cleanup;
if (bpt->number == 0)
return;
uiout = interp_ui_out (mi_interp);
list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "MI_HOOK_RESULT");
ui_out_field_string (uiout, "HOOK_TYPE", "breakpoint_delete");
ui_out_field_int (uiout, "bkptno", bpt->number);
do_cleanups (list_cleanup);
uiout = saved_ui_out;
}
void
mi_async_breakpoint_resolve_event (int pending_b, int new_b)
{
struct cleanup *old_chain;
struct breakpoint *bpt;
if (pending_b <= 0)
return;
old_chain = make_cleanup_ui_out_notify_begin_end (uiout,
"resolve-pending-breakpoint");
ui_out_field_int (uiout, "new_bp", new_b);
ui_out_field_int (uiout, "pended_bp", pending_b);
bpt = find_breakpoint (new_b);
if (bpt->addr_string != NULL)
ui_out_field_string (uiout, "new_expr", bpt->addr_string);
if (bpt->cond_string != NULL)
{
if (bpt->cond == NULL)
ui_out_field_int (uiout, "condition_valid", 0);
else
ui_out_field_int (uiout, "condition_valid", 1);
}
gdb_breakpoint_query (uiout, new_b, NULL);
do_cleanups (old_chain);
}