/* GDB CLI commands.
- Copyright 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
+ Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "readline/readline.h"
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#include <fcntl.h>
+
/* Prototypes for local command functions */
static void complete_command (char *, int);
struct cmd_list_element *deletelist;
+/* Chain containing all defined detach subcommands. */
+
+struct cmd_list_element *detachlist;
+
/* Chain containing all defined "enable breakpoint" subcommands. */
struct cmd_list_element *enablebreaklist;
struct cmd_list_element *setchecklist;
struct cmd_list_element *showchecklist;
+
+/* Command tracing state. */
+
+int source_verbose = 0;
+int trace_commands = 0;
\f
/* Utility used everywhere when at least one argument is needed and
none is supplied. */
}
\f
void
-source_command (char *args, int from_tty)
+source_script (char *file, int from_tty)
{
FILE *stream;
struct cleanup *old_cleanups;
- char *file = args;
+ char *full_pathname = NULL;
+ int fd;
- if (file == NULL)
+ if (file == NULL || *file == 0)
{
- error (_("source command requires pathname of file to source."));
+ error (_("source command requires file name of file to source."));
}
file = tilde_expand (file);
old_cleanups = make_cleanup (xfree, file);
- stream = fopen (file, FOPEN_RT);
- if (!stream)
+ /* Search for and open 'file' on the search path used for source
+ files. Put the full location in 'full_pathname'. */
+ fd = openp (source_path, OPF_TRY_CWD_FIRST,
+ file, O_RDONLY, 0, &full_pathname);
+
+ /* Use the full path name, if it is found. */
+ if (full_pathname != NULL && fd != -1)
+ {
+ file = full_pathname;
+ }
+
+ if (fd == -1)
{
if (from_tty)
perror_with_name (file);
return;
}
+ stream = fdopen (fd, FOPEN_RT);
script_from_file (stream, file);
do_cleanups (old_cleanups);
}
+/* Return the source_verbose global variable to its previous state
+ on exit from the source command, by whatever means. */
+static void
+source_verbose_cleanup (void *old_value)
+{
+ source_verbose = *(int *)old_value;
+ xfree (old_value);
+}
+
+static void
+source_command (char *args, int from_tty)
+{
+ struct cleanup *old_cleanups;
+ char *file = args;
+ int *old_source_verbose = xmalloc (sizeof(int));
+
+ *old_source_verbose = source_verbose;
+ old_cleanups = make_cleanup (source_verbose_cleanup, old_source_verbose);
+
+ /* -v causes the source command to run in verbose mode.
+ We still have to be able to handle filenames with spaces in a
+ backward compatible way, so buildargv is not appropriate. */
+
+ if (args)
+ {
+ /* Make sure leading white space does not break the comparisons. */
+ while (isspace(args[0]))
+ args++;
+
+ /* Is -v the first thing in the string? */
+ if (args[0] == '-' && args[1] == 'v' && isspace (args[2]))
+ {
+ source_verbose = 1;
+
+ /* Trim -v and whitespace from the filename. */
+ file = &args[3];
+ while (isspace (file[0]))
+ file++;
+ }
+ }
+
+ source_script (file, from_tty);
+}
+
+
static void
echo_command (char *text, int from_tty)
{
list_command (char *arg, int from_tty)
{
struct symtabs_and_lines sals, sals_end;
- struct symtab_and_line sal = { };
- struct symtab_and_line sal_end = { };
- struct symtab_and_line cursal = { };
+ struct symtab_and_line sal = { 0 };
+ struct symtab_and_line sal_end = { 0 };
+ struct symtab_and_line cursal = { 0 };
struct symbol *sym;
char *arg1;
int no_end = 1;
name = NULL;
if (!arg)
{
- if (!deprecated_selected_frame)
- error (_("No frame selected."));
-
- pc = get_frame_pc (deprecated_selected_frame);
+ pc = get_frame_pc (get_selected_frame (_("No frame selected.")));
if (find_pc_partial_function (pc, &name, &low, &high) == 0)
error (_("No function contains program counter for selected frame."));
#if defined(TUI)
/* FIXME: cagney/2004-02-07: This should be an observer. */
low = tui_get_low_disassembly_address (low, pc);
#endif
- low += DEPRECATED_FUNCTION_START_OFFSET;
+ low += gdbarch_deprecated_function_start_offset (current_gdbarch);
}
else if (!(space_index = (char *) strchr (arg, ' ')))
{
/* FIXME: cagney/2004-02-07: This should be an observer. */
low = tui_get_low_disassembly_address (low, pc);
#endif
- low += DEPRECATED_FUNCTION_START_OFFSET;
+ low += gdbarch_deprecated_function_start_offset (current_gdbarch);
}
else
{
togglelist = NULL;
stoplist = NULL;
deletelist = NULL;
+ detachlist = NULL;
enablebreaklist = NULL;
setlist = NULL;
unsetlist = NULL;
source_help_text = xstrprintf (_("\
Read commands from a file named FILE.\n\
+Optional -v switch (before the filename) causes each command in\n\
+FILE to be echoed as it is executed.\n\
Note that the file \"%s\" is read automatically in this way\n\
-when gdb is started."), gdbinit);
+when GDB is started."), gdbinit);
c = add_cmd ("source", class_support, source_command,
source_help_text, &cmdlist);
set_cmd_completer (c, filename_completer);
NULL,
show_max_user_call_depth,
&setlist, &showlist);
+
+ add_setshow_boolean_cmd ("trace-commands", no_class, &trace_commands, _("\
+Set tracing of GDB CLI commands."), _("\
+Show state of GDB CLI command tracing."), _("\
+When 'on', each command is displayed as it is executed."),
+ NULL,
+ NULL,
+ &setlist, &showlist);
}