/* GDB CLI commands.
- Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ Copyright (C) 2000-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "readline/tilde.h"
#include "completer.h"
#include "target.h" /* For baud_rate, remote_debug and remote_timeout. */
-#include "gdb_wait.h" /* For shell escape implementation. */
+#include "common/gdb_wait.h" /* For shell escape implementation. */
#include "gdb_regex.h" /* Used by apropos_command. */
#include "gdb_vfork.h"
#include "linespec.h"
#include "source.h"
#include "disasm.h"
#include "tracepoint.h"
-#include "filestuff.h"
+#include "common/filestuff.h"
#include "location.h"
#include "block.h"
#include "cli/cli-utils.h"
#include "extension.h"
+#include "common/pathstuff.h"
#ifdef TUI
#include "tui/tui.h" /* For tui_active et.al. */
if (arg == NULL)
arg = "";
- completion_tracker tracker_handle_brkchars;
- completion_tracker tracker_handle_completions;
- completion_tracker *tracker;
-
int quote_char = '\0';
const char *word;
- TRY
- {
- word = completion_find_completion_word (tracker_handle_brkchars,
- arg, "e_char);
-
- /* Completers that provide a custom word point in the
- handle_brkchars phase also compute their completions then.
- Completers that leave the completion word handling to readline
- must be called twice. */
- if (tracker_handle_brkchars.use_custom_word_point ())
- tracker = &tracker_handle_brkchars;
- else
- {
- complete_line (tracker_handle_completions, word, arg, strlen (arg));
- tracker = &tracker_handle_completions;
- }
- }
- CATCH (ex, RETURN_MASK_ALL)
- {
- return;
- }
- END_CATCH
+ completion_result result = complete (arg, &word, "e_char);
std::string arg_prefix (arg, word - arg);
- completion_result result
- = tracker->build_completion_result (word, word - arg, strlen (arg));
-
if (result.number_matches != 0)
{
if (result.number_matches == 1)
printf_filtered ("%c", c);
}
+ reset_terminal_style (gdb_stdout);
+
/* Force this output to appear now. */
wrap_here ("");
gdb_flush (gdb_stdout);
arg = "inferior shell";
if (rc == -1)
- {
- fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
- safe_strerror (errno));
- gdb_flush (gdb_stderr);
- }
+ fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
+ safe_strerror (errno));
else if (rc)
- {
- fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
- gdb_flush (gdb_stderr);
- }
+ fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
#ifdef GLOBAL_CURDIR
/* Make sure to return to the directory GDB thinks it is, in case
the shell command we just ran changed it. */
if ((pid = vfork ()) == 0)
{
- const char *p, *user_shell;
+ const char *p, *user_shell = get_shell ();
close_most_fds ();
- if ((user_shell = getenv ("SHELL")) == NULL)
- user_shell = "/bin/sh";
-
/* Get the name of the shell for arg0. */
p = lbasename (user_shell);
fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
safe_strerror (errno));
- gdb_flush (gdb_stderr);
_exit (0177);
}
&& get_lines_to_list () == 1 && first > 1)
first -= 1;
- print_source_lines (cursal.symtab, first,
- first + get_lines_to_list (), 0);
+ print_source_lines (cursal.symtab, source_lines_range (first), 0);
}
/* "l" or "l +" lists next ten lines. */
else if (arg == NULL || arg[0] == '+')
- print_source_lines (cursal.symtab, cursal.line,
- cursal.line + get_lines_to_list (), 0);
+ print_source_lines (cursal.symtab,
+ source_lines_range (cursal.line), 0);
/* "l -" lists previous ten lines, the ones before the ten just
listed. */
if (get_first_line_listed () == 1)
error (_("Already at the start of %s."),
symtab_to_filename_for_display (cursal.symtab));
- print_source_lines (cursal.symtab,
- std::max (get_first_line_listed ()
- - get_lines_to_list (), 1),
- get_first_line_listed (), 0);
+ source_lines_range range (get_first_line_listed (),
+ source_lines_range::BACKWARD);
+ print_source_lines (cursal.symtab, range, 0);
}
return;
if (dummy_beg && sal_end.symtab == 0)
error (_("No default source file yet. Do \"help list\"."));
if (dummy_beg)
- print_source_lines (sal_end.symtab,
- std::max (sal_end.line - (get_lines_to_list () - 1), 1),
- sal_end.line + 1, 0);
+ {
+ source_lines_range range (sal_end.line + 1,
+ source_lines_range::BACKWARD);
+ print_source_lines (sal_end.symtab, range, 0);
+ }
else if (sal.symtab == 0)
error (_("No default source file yet. Do \"help list\"."));
else if (no_end)
first_line = 1;
if (sals.size () > 1)
print_sal_location (sal);
- print_source_lines (sal.symtab,
- first_line,
- first_line + get_lines_to_list (),
- 0);
+ print_source_lines (sal.symtab, source_lines_range (first_line), 0);
}
}
+ else if (dummy_end)
+ print_source_lines (sal.symtab, source_lines_range (sal.line), 0);
else
- print_source_lines (sal.symtab, sal.line,
- (dummy_end
- ? sal.line + get_lines_to_list ()
- : sal_end.line + 1),
+ print_source_lines (sal.symtab,
+ source_lines_range (sal.line, (sal_end.line + 1)),
0);
}
}
}
printf_filtered ("End of assembler dump.\n");
- gdb_flush (gdb_stdout);
}
#if defined(TUI)
else
}
/* Subroutine of alias_command to simplify it.
- Return TRUE if COMMAND exists, unambiguously. Otherwise FALSE. */
+ Return true if COMMAND exists, unambiguously. Otherwise false. */
-static int
+static bool
valid_command_p (const char *command)
{
struct cmd_list_element *c;
c = lookup_cmd_1 (& command, cmdlist, NULL, 1);
if (c == NULL || c == (struct cmd_list_element *) -1)
- return FALSE;
+ return false;
/* This is the slightly tricky part.
lookup_cmd_1 will return a pointer to the last part of COMMAND
With no arguments, run an inferior shell."));
set_cmd_completer (c, filename_completer);
+ add_com_alias ("!", "shell", class_support, 0);
+
c = add_com ("edit", class_files, edit_command, _("\
Edit specified file or function.\n\
With no argument, edits file containing most recent line listed.\n\
you must type \"disassemble 'foo.c'::bar\" and not \"disassemble foo.c:bar\"."));
set_cmd_completer (c, location_completer);
- add_com_alias ("!", "shell", class_support, 0);
-
c = add_com ("make", class_support, make_command, _("\
Run the ``make'' program using the rest of the line as arguments."));
set_cmd_completer (c, filename_completer);