* mips-tdep.c (init_extra_frame_info): Use frame relative stack
[deliverable/binutils-gdb.git] / gdb / main.c
index d0a5d29b9573fb03b3a2545380a3f847e2fd670b..1dafb9f03b7bdb323c165ec45ef41ce551ab2d8e 100644 (file)
@@ -1,5 +1,5 @@
 /* Top level `main' program for GDB, the GNU debugger.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -29,7 +29,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "gdbtypes.h"
 #include "expression.h"
 #include "language.h"
-#include "serial.h" /* For job_control.  */
+#include "terminal.h" /* For job_control.  */
 
 #include "getopt.h"
 
@@ -73,7 +73,7 @@ static void
 command_loop_marker PARAMS ((int));
 
 static void
-print_gdb_version PARAMS ((FILE *));
+print_gdb_version PARAMS ((GDB_FILE *));
 
 static void
 quit_command PARAMS ((char *, int));
@@ -186,14 +186,6 @@ extern char *host_canonical;
 
 extern char *target_canonical;
 
-/* Message to be printed before the error message, when an error occurs.  */
-
-extern char *error_pre_print;
-
-/* Message to be printed before the warning message, when a warning occurs.  */
-
-extern char *warning_pre_print;
-
 extern char lang_frame_mismatch_warn[];                /* language.c */
 
 /* Flag for whether we want all the "from_tty" gubbish printed.  */
@@ -278,7 +270,9 @@ struct cmd_list_element *setchecklist;
 
 struct cmd_list_element *showchecklist;
 
-/* stdio stream that command input is being read from.  */
+/* stdio stream that command input is being read from.  Set to stdin normally.
+   Set by source_command to the file we are sourcing.  Set to NULL if we are
+   executing a user-defined command.  */
 
 FILE *instream;
 
@@ -311,9 +305,13 @@ char *line;
 int linesize = 100;
 
 /* Baud rate specified for talking to serial target systems.  Default
-   is left as a zero pointer, so targets can choose their own defaults.  */
+   is left as -1, so targets can choose their own defaults.  */
+
+int baud_rate = -1;
 
-char *baud_rate;
+/* Non-zero tells remote* modules to output debugging info.  */
+
+int remote_debug = 0;
 
 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT.  */
 
@@ -375,6 +373,11 @@ return_to_top_level (reason)
    print ERRSTRING, print the specific error message, then return
    zero.
 
+   Must not be called with immediate_quit in effect (bad things might
+   happen, say we got a signal in the middle of a memcpy to quit_return).
+   This is an OK restriction; with very few exceptions immediate_quit can
+   be replaced by judicious use of QUIT.
+
    MASK specifies what to catch; it is normally set to
    RETURN_MASK_ALL, if for no other reason than that the code which
    calls catch_errors might not be set up to deal with a quit which
@@ -452,6 +455,21 @@ char *s;
   return 0;
 }
 \f
+/* Line number we are currently in in a file which is being sourced.  */
+static int source_line_number;
+
+/* Name of the file we are sourcing.  */
+static char *source_file_name;
+
+/* Buffer containing the error_pre_print used by the source stuff.
+   Malloc'd.  */
+static char *source_error;
+static int source_error_allocated;
+
+/* Something to glom on to the start of error_pre_print if source_file_name
+   is set.  */
+static char *source_pre_error;
+
 /* Clean up on error during a "source" command (or execution of a
    user-defined command).  */
 
@@ -660,13 +678,23 @@ main (argc, argv)
            quiet = 1;
            break;
          case 'b':
-           baud_rate = optarg;
+           {
+             int i;
+             char *p;
+
+             i = strtol (optarg, &p, 0);
+             if (i == 0 && p == optarg)
+               warning ("Could not set baud rate to `%s'.\n", optarg);
+             else
+               baud_rate = i;
+           }
            break;
+
 #ifdef ADDITIONAL_OPTION_CASES
          ADDITIONAL_OPTION_CASES
 #endif
          case '?':
-           fprintf (stderr,
+           fprintf_unfiltered (gdb_stderr,
                     "Use `%s --help' for a complete list of options.\n",
                     argv[0]);
            exit (1);
@@ -686,7 +714,7 @@ main (argc, argv)
          corearg = argv[optind];
          break;
        case 3:
-         fprintf (stderr,
+         fprintf_unfiltered (gdb_stderr,
                   "Excess command line arguments ignored. (%s%s)\n",
                   argv[optind], (optind == argc - 1) ? "" : " ...");
          break;
@@ -706,7 +734,7 @@ main (argc, argv)
      after initialize_all_files.  */
   if (print_version)
     {
-      print_gdb_version (stdout);
+      print_gdb_version (gdb_stdout);
       wrap_here ("");
       printf_filtered ("\n");
       exit (0);
@@ -718,14 +746,14 @@ main (argc, argv)
         are printing the version here, and the help is long enough
         already.  */
 
-      print_gdb_version (stdout);
+      print_gdb_version (gdb_stdout);
       /* Make sure the output gets printed.  */
       wrap_here ("");
       printf_filtered ("\n");
 
       /* But don't use *_filtered here.  We don't want to prompt for continue
         no matter how small the screen or how much we're going to print.  */
-      fputs ("\
+      fputs_unfiltered ("\
 This is the GNU debugger.  Usage:\n\
     gdb [options] [executable-file [core-file or process-id]]\n\
 Options:\n\
@@ -746,13 +774,13 @@ Options:\n\
   -b BAUDRATE        Set serial port baud rate used for remote debugging.\n\
   --mapped           Use mapped symbol files if supported on this system.\n\
   --readnow          Fully read symbol files on first access.\n\
-", stdout);
+", gdb_stdout);
 #ifdef ADDITIONAL_OPTION_HELP
-      fputs (ADDITIONAL_OPTION_HELP, stdout);
+      fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout);
 #endif
-      fputs ("\n\
+      fputs_unfiltered ("\n\
 For more information, type \"help\" from within GDB, or consult the\n\
-GDB manual (available as on-line info or a printed manual).\n", stdout);
+GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
       exit (0);
     }
     
@@ -761,11 +789,11 @@ GDB manual (available as on-line info or a printed manual).\n", stdout);
       /* Print all the junk at the top, with trailing "..." if we are about
         to read a symbol file (possibly slowly).  */
       print_gnu_advertisement ();
-      print_gdb_version (stdout);
+      print_gdb_version (gdb_stdout);
       if (symarg)
        printf_filtered ("..");
       wrap_here("");
-      fflush (stdout);         /* Force to screen during slow operations */
+      gdb_flush (gdb_stdout);          /* Force to screen during slow operations */
     }
 
   error_pre_print = "\n\n";
@@ -1098,8 +1126,8 @@ gdb_readline (prrompt)
       /* Don't use a _filtered function here.  It causes the assumed
         character position to be off, since the newline we read from
         the user is not accounted for.  */
-      fputs (prrompt, stdout);
-      fflush (stdout);
+      fputs_unfiltered (prrompt, gdb_stdout);
+      gdb_flush (gdb_stdout);
     }
   
   result = (char *) xmalloc (result_size);
@@ -1112,6 +1140,11 @@ gdb_readline (prrompt)
 
       if (c == EOF)
        {
+         if (input_index > 0)
+           /* The last line does not end with a newline.  Return it, and
+              if we are called again fgetc will still return EOF and
+              we'll return NULL then.  */
+           break;
          free (result);
          return NULL;
        }
@@ -1567,8 +1600,8 @@ int signo;
 #else
   signal (STOP_SIGNAL, stop_sig);
 #endif
-  printf ("%s", prompt);
-  fflush (stdout);
+  printf_unfiltered ("%s", prompt);
+  gdb_flush (gdb_stdout);
 
   /* Forget about any previous command -- null line now will do nothing.  */
   dont_repeat ();
@@ -1653,12 +1686,23 @@ command_line_input (prrompt, repeat)
 
   while (1)
     {
-      /* Reports are that some Sys V's don't flush stdout/err on reads
+      /* Reports are that some Sys V's don't flush gdb_stdout/err on reads
         from stdin, when stdin/out are sockets rather than ttys.  So we
         have to do it ourselves, to make emacs-gdb and xxgdb work.
         On other machines, doing this once per input should be a cheap nop.  */
-      fflush (stdout);
-      fflush (stderr);
+      gdb_flush (gdb_stdout);
+      gdb_flush (gdb_stderr);
+
+      if (source_file_name != NULL)
+       {
+         ++source_line_number;
+         sprintf (source_error,
+                  "%s%s:%d: Error in sourced command file:\n",
+                  source_pre_error,
+                  source_file_name,
+                  source_line_number);
+         error_pre_print = source_error;
+       }
 
       /* Don't use fancy stuff if not talking to stdin.  */
       if (command_editing_p && instream == stdin
@@ -1715,7 +1759,7 @@ command_line_input (prrompt, repeat)
       if (expanded)
        {
          /* Print the changes.  */
-         printf ("%s\n", history_value);
+         printf_unfiltered ("%s\n", history_value);
 
          /* If there was an error, call this function again.  */
          if (expanded < 0)
@@ -1913,8 +1957,8 @@ info_command (arg, from_tty)
      char *arg;
      int from_tty;
 {
-  printf ("\"info\" must be followed by the name of an info command.\n");
-  help_list (infolist, "info ", -1, stdout);
+  printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
+  help_list (infolist, "info ", -1, gdb_stdout);
 }
 
 /* The "show" command with no arguments shows all the settings.  */
@@ -1965,7 +2009,7 @@ help_command (command, from_tty)
      char *command;
      int from_tty; /* Ignored */
 {
-  help_cmd (command, stdout);
+  help_cmd (command, gdb_stdout);
 }
 \f
 static void
@@ -2051,9 +2095,9 @@ define_command (comname, from_tty)
 
   if (from_tty)
     {
-      printf ("Type commands for definition of \"%s\".\n\
+      printf_unfiltered ("Type commands for definition of \"%s\".\n\
 End with a line saying just \"end\".\n", comname);
-      fflush (stdout);
+      gdb_flush (gdb_stdout);
     }
 
   cmds = read_command_lines ();
@@ -2092,7 +2136,7 @@ document_command (comname, from_tty)
     error ("Command \"%s\" is built-in.", comname);
 
   if (from_tty)
-    printf ("Type documentation for \"%s\".\n\
+    printf_unfiltered ("Type documentation for \"%s\".\n\
 End with a line saying just \"end\".\n", comname);
 
   doclines = read_command_lines ();
@@ -2123,7 +2167,7 @@ End with a line saying just \"end\".\n", comname);
 static void
 print_gnu_advertisement()
 {
-    printf ("\
+    printf_unfiltered ("\
 GDB is free software and you are welcome to distribute copies of it\n\
  under certain conditions; type \"show copying\" to see the conditions.\n\
 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
@@ -2132,7 +2176,7 @@ There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
 
 static void
 print_gdb_version (stream)
-  FILE *stream;
+  GDB_FILE *stream;
 {
   fprintf_filtered (stream, "\
 GDB %s (%s", version, host_canonical);
@@ -2142,7 +2186,7 @@ GDB %s (%s", version, host_canonical);
 
   fprintf_filtered (stream, "), ");
   wrap_here("");
-  fprintf_filtered (stream, "Copyright 1993 Free Software Foundation, Inc.");
+  fprintf_filtered (stream, "Copyright 1994 Free Software Foundation, Inc.");
 }
 
 /* ARGSUSED */
@@ -2153,7 +2197,7 @@ show_version (args, from_tty)
 {
   immediate_quit++;
   print_gnu_advertisement ();
-  print_gdb_version (stdout);
+  print_gdb_version (gdb_stdout);
   printf_filtered ("\n");
   immediate_quit--;
 }
@@ -2163,8 +2207,8 @@ show_version (args, from_tty)
 void
 print_prompt ()
 {
-  printf ("%s", prompt);
-  fflush (stdout);
+  printf_unfiltered ("%s", prompt);
+  gdb_flush (gdb_stdout);
 }
 \f
 static void
@@ -2214,10 +2258,10 @@ pwd_command (args, from_tty)
   getcwd (dirbuf, sizeof (dirbuf));
 
   if (!STREQ (dirbuf, current_directory))
-    printf ("Working directory %s\n (canonically %s).\n",
+    printf_unfiltered ("Working directory %s\n (canonically %s).\n",
            current_directory, dirbuf);
   else
-    printf ("Working directory %s.\n", current_directory);
+    printf_unfiltered ("Working directory %s.\n", current_directory);
 }
 
 static void
@@ -2302,6 +2346,25 @@ cd_command (dir, from_tty)
     pwd_command ((char *) 0, 1);
 }
 \f
+struct source_cleanup_lines_args {
+  int old_line;
+  char *old_file;
+  char *old_pre_error;
+  char *old_error_pre_print;
+};
+
+static void
+source_cleanup_lines (args)
+     PTR args;
+{
+  struct source_cleanup_lines_args *p =
+    (struct source_cleanup_lines_args *)args;
+  source_line_number = p->old_line;
+  source_file_name = p->old_file;
+  source_pre_error = p->old_pre_error;
+  error_pre_print = p->old_error_pre_print;
+}
+
 /* ARGSUSED */
 static void
 source_command (args, from_tty)
@@ -2309,8 +2372,10 @@ source_command (args, from_tty)
      int from_tty;
 {
   FILE *stream;
-  struct cleanup *cleanups;
+  struct cleanup *old_cleanups;
   char *file = args;
+  struct source_cleanup_lines_args old_lines;
+  int needed_length;
 
   if (file == NULL)
     {
@@ -2318,17 +2383,43 @@ source_command (args, from_tty)
     }
 
   file = tilde_expand (file);
-  make_cleanup (free, file);
+  old_cleanups = make_cleanup (free, file);
 
   stream = fopen (file, FOPEN_RT);
   if (stream == 0)
     perror_with_name (file);
 
-  cleanups = make_cleanup (fclose, stream);
+  make_cleanup (fclose, stream);
+
+  old_lines.old_line = source_line_number;
+  old_lines.old_file = source_file_name;
+  old_lines.old_pre_error = source_pre_error;
+  old_lines.old_error_pre_print = error_pre_print;
+  make_cleanup (source_cleanup_lines, &old_lines);
+  source_line_number = 0;
+  source_file_name = file;
+  source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
+  source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
+  make_cleanup (free, source_pre_error);
+  /* This will get set every time we read a line.  So it won't stay "" for
+     long.  */
+  error_pre_print = "";
+
+  needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
+  if (source_error_allocated < needed_length)
+    {
+      source_error_allocated *= 2;
+      if (source_error_allocated < needed_length)
+       source_error_allocated = needed_length;
+      if (source_error == NULL)
+       source_error = xmalloc (source_error_allocated);
+      else
+       source_error = xrealloc (source_error, source_error_allocated);
+    }
 
   read_command_file (stream);
 
-  do_cleanups (cleanups);
+  do_cleanups (old_cleanups);
 }
 
 /* ARGSUSED */
@@ -2360,7 +2451,7 @@ echo_command (text, from_tty)
 
   /* Force this output to appear now.  */
   wrap_here ("");
-  fflush (stdout);
+  gdb_flush (gdb_stdout);
 }
 
 \f
@@ -2384,7 +2475,7 @@ show_commands (args, from_tty)
      than the number of the last command).  Relative to history_base.  */
   int hist_len;
 
-  extern struct _hist_entry *history_get PARAMS ((int));
+  extern HIST_ENTRY *history_get PARAMS ((int));
   extern int history_base;
 
   /* Print out some of the commands from the command history.  */
@@ -2471,8 +2562,8 @@ set_history (args, from_tty)
      char *args;
      int from_tty;
 {
-  printf ("\"set history\" must be followed by the name of a history subcommand.\n");
-  help_list (sethistlist, "set history ", -1, stdout);
+  printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
+  help_list (sethistlist, "set history ", -1, gdb_stdout);
 }
 
 /* ARGSUSED */
@@ -2763,4 +2854,20 @@ the previous command number shown.",
 
   add_cmd ("version", no_class, show_version,
           "Show what version of GDB this is.", &showlist);
+
+  /* If target is open when baud changes, it doesn't take effect until the
+     next open (I think, not sure).  */
+  add_show_from_set (add_set_cmd ("remotebaud", no_class,
+                                 var_zinteger, (char *)&baud_rate,
+                                 "Set baud rate for remote serial I/O.\n\
+This value is used to set the speed of the serial port when debugging\n\
+using remote targets.", &setlist),
+                    &showlist);
+
+  add_show_from_set (
+    add_set_cmd ("remotedebug", no_class, var_zinteger, (char *)&remote_debug,
+                  "Set debugging of remote protocol.\n\
+When enabled, each packet sent or received with the remote target\n\
+is displayed.", &setlist),
+                    &showlist);
 }
This page took 0.030784 seconds and 4 git commands to generate.