/* GDB CLI commands.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2017 Free Software Foundation, Inc.
This file is part of GDB.
static void make_command (char *, int);
-static void shell_escape (char *, int);
+static void shell_escape (const char *, int);
static void edit_command (char *, int);
[Is that why this function writes output with *_unfiltered?] */
static void
-complete_command (char *arg, int from_tty)
+complete_command (char *arg_entry, int from_tty)
{
+ const char *arg = arg_entry;
int argpoint;
- char *point, *arg_prefix;
+ char *arg_prefix;
VEC (char_ptr) *completions;
dont_repeat ();
{
/* Only print this for non-mi frontends. An MI frontend may not
be able to handle this. */
- if (!ui_out_is_mi_like_p (current_uiout))
+ if (!current_uiout->is_mi_like_p ())
{
printf_unfiltered (_("max-completions is zero,"
" completion is disabled.\n"));
within, and except for filenames at the beginning of, the word to
be completed. The following crude imitation of readline's
word-breaking tries to accomodate this. */
- point = arg + argpoint;
+ const char *point = arg + argpoint;
while (point > arg)
{
if (strchr (rl_completer_word_break_characters, point[-1]) != 0)
repeat might be useful but is more likely to be a mistake. */
dont_repeat ();
- if (dir == 0)
- dir = "~";
-
- dir = tilde_expand (dir);
+ dir = tilde_expand (dir != NULL ? dir : "~");
cleanup = make_cleanup (xfree, dir);
if (chdir (dir) < 0)
}
static void
-shell_escape (char *arg, int from_tty)
+shell_escape (const char *arg, int from_tty)
{
#if defined(CANT_FORK) || \
(!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
#endif /* Can fork. */
}
+/* Implementation of the "shell" command. */
+
+static void
+shell_command (char *arg, int from_tty)
+{
+ shell_escape (arg, from_tty);
+}
+
static void
edit_command (char *arg, int from_tty)
{
struct symtabs_and_lines sals;
struct symtab_and_line sal;
struct symbol *sym;
- char *editor;
+ const char *editor;
char *p;
const char *fn;
}
else
{
- struct cleanup *cleanup;
- struct event_location *location;
char *arg1;
/* Now should only be one argument -- decode it in SAL. */
arg1 = arg;
- location = string_to_event_location (&arg1, current_language);
- cleanup = make_cleanup_delete_event_location (location);
- sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, NULL, NULL, 0);
+ event_location_up location = string_to_event_location (&arg1,
+ current_language);
+ sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+ NULL, NULL, 0);
filter_sals (&sals);
if (! sals.nelts)
{
/* C++ */
- do_cleanups (cleanup);
return;
}
if (sals.nelts > 1)
{
ambiguous_line_spec (&sals);
xfree (sals.sals);
- do_cleanups (cleanup);
return;
}
if (sal.symtab == 0)
error (_("No line number known for %s."), arg);
- do_cleanups (cleanup);
}
if ((editor = (char *) getenv ("EDITOR")) == NULL)
int dummy_beg = 0;
int linenum_beg = 0;
char *p;
- struct cleanup *cleanup;
-
- cleanup = make_cleanup (null_cleanup, NULL);
/* Pull in the current default source line if necessary. */
if (arg == NULL || ((arg[0] == '+' || arg[0] == '-') && arg[1] == '\0'))
dummy_beg = 1;
else
{
- struct event_location *location;
-
- location = string_to_event_location (&arg1, current_language);
- make_cleanup_delete_event_location (location);
- sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, NULL, NULL, 0);
+ event_location_up location = string_to_event_location (&arg1,
+ current_language);
+ sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+ NULL, NULL, 0);
filter_sals (&sals);
if (!sals.nelts)
{
/* C++ */
- do_cleanups (cleanup);
return;
}
if (sals.nelts > 1)
{
ambiguous_line_spec (&sals);
xfree (sals.sals);
- do_cleanups (cleanup);
return;
}
dummy_end = 1;
else
{
- struct event_location *location;
-
- location = string_to_event_location (&arg1, current_language);
- make_cleanup_delete_event_location (location);
+ event_location_up location
+ = string_to_event_location (&arg1, current_language);
if (dummy_beg)
- sals_end = decode_line_1 (location,
+ sals_end = decode_line_1 (location.get (),
DECODE_LINE_LIST_MODE, NULL, NULL, 0);
else
- sals_end = decode_line_1 (location, DECODE_LINE_LIST_MODE,
+ sals_end = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
NULL, sal.symtab, sal.line);
filter_sals (&sals_end);
if (sals_end.nelts == 0)
- {
- do_cleanups (cleanup);
- return;
- }
+ return;
if (sals_end.nelts > 1)
{
ambiguous_line_spec (&sals_end);
xfree (sals_end.sals);
- do_cleanups (cleanup);
return;
}
sal_end = sals_end.sals[0];
? sal.line + get_lines_to_list ()
: sal_end.line + 1),
0);
- do_cleanups (cleanup);
}
/* Subroutine of disassemble_command to simplify it.
paddress (gdbarch, low), paddress (gdbarch, high));
/* Dump the specified range. */
- gdb_disassembly (gdbarch, current_uiout, 0, flags, -1, low, high);
+ gdb_disassembly (gdbarch, current_uiout, flags, -1, low, high);
printf_filtered ("End of assembler dump.\n");
gdb_flush (gdb_stdout);
static void
make_command (char *arg, int from_tty)
{
- char *p;
-
if (arg == 0)
- p = "make";
+ shell_escape ("make", from_tty);
else
{
- p = (char *) xmalloc (sizeof ("make ") + strlen (arg));
- strcpy (p, "make ");
- strcpy (p + sizeof ("make ") - 1, arg);
- }
+ std::string cmd = std::string ("make ") + arg;
- shell_escape (p, from_tty);
+ shell_escape (cmd.c_str (), from_tty);
+ }
}
static void
static void
apropos_command (char *searchstr, int from_tty)
{
- regex_t pattern;
- int code;
-
if (searchstr == NULL)
error (_("REGEXP string is empty"));
- code = regcomp (&pattern, searchstr, REG_ICASE);
- if (code == 0)
- {
- struct cleanup *cleanups;
-
- cleanups = make_regfree_cleanup (&pattern);
- apropos_cmd (gdb_stdout, cmdlist, &pattern, "");
- do_cleanups (cleanups);
- }
- else
- {
- char *err = get_regcomp_error (code, &pattern);
+ compiled_regex pattern (searchstr, REG_ICASE,
+ _("Error in regular expression"));
- make_cleanup (xfree, err);
- error (_("Error in regular expression: %s"), err);
- }
+ apropos_cmd (gdb_stdout, cmdlist, pattern, "");
}
/* Subroutine of alias_command to simplify it.
_("Generic command for showing gdb debugging flags"),
&showdebuglist, "show debug ", 0, &showlist);
- c = add_com ("shell", class_support, shell_escape, _("\
+ c = add_com ("shell", class_support, shell_command, _("\
Execute the rest of the line as a shell command.\n\
With no arguments, run an inferior shell."));
set_cmd_completer (c, filename_completer);