Updated copyright notices for most files.
[deliverable/binutils-gdb.git] / gdb / cli / cli-cmds.c
index 8d3416764ba37964291e9c7e3f1a888ea60d2e01..96abe8ce710a841e7539d2a0938c7e4aa3235b36 100644 (file)
@@ -1,12 +1,13 @@
 /* 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,
@@ -15,9 +16,7 @@
    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"
@@ -50,6 +49,8 @@
 #include "tui/tui.h"           /* For tui_active et.al.   */
 #endif
 
+#include <fcntl.h>
+
 /* Prototypes for local command functions */
 
 static void complete_command (char *, int);
@@ -119,6 +120,10 @@ struct cmd_list_element *stoplist;
 
 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;
@@ -170,6 +175,11 @@ struct cmd_list_element *showdebuglist;
 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. */
@@ -421,22 +431,33 @@ cd_command (char *dir, int from_tty)
 }
 \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);
@@ -444,11 +465,57 @@ source_command (char *args, int from_tty)
        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)
 {
@@ -651,9 +718,9 @@ static void
 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 = { };
+  struct symtab_and_line sal_end = { };
+  struct symtab_and_line cursal = { };
   struct symbol *sym;
   char *arg1;
   int no_end = 1;
@@ -846,10 +913,7 @@ disassemble_command (char *arg, int from_tty)
   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)
@@ -859,7 +923,7 @@ disassemble_command (char *arg, int from_tty)
        /* 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, ' ')))
     {
@@ -874,7 +938,7 @@ disassemble_command (char *arg, int from_tty)
        /* 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
     {
@@ -1024,6 +1088,7 @@ init_cmd_lists (void)
   togglelist = NULL;
   stoplist = NULL;
   deletelist = NULL;
+  detachlist = NULL;
   enablebreaklist = NULL;
   setlist = NULL;
   unsetlist = NULL;
@@ -1166,8 +1231,10 @@ Commands defined in this way may have up to ten arguments."));
 
   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);
@@ -1348,4 +1415,12 @@ Show the max call depth for user-defined commands."), NULL,
                           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);
 }
This page took 0.030165 seconds and 4 git commands to generate.