]> Git Repo - binutils.git/blobdiff - gdb/main.c
* config/mips-gdb.exp, config/udi-gdb.exp, config/vx-gdb.exp,
[binutils.git] / gdb / main.c
index edefa30bb5de3a5a9e64a596b70ce702007a1eed..eb84f2c1f3f93b3b739a91b4734dc292608f6a0f 100644 (file)
@@ -30,6 +30,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "expression.h"
 #include "language.h"
 #include "terminal.h" /* For job_control.  */
+#include "annotate.h"
 
 #include "getopt.h"
 
@@ -40,8 +41,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* readline defines this.  */
 #undef savestring
 
-#ifdef USG
 #include <sys/types.h>
+#ifdef USG
+/* What is this for?  X_OK?  */
 #include <unistd.h>
 #endif
 
@@ -54,13 +56,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/stat.h>
 #include <ctype.h>
 
-#ifdef SET_STACK_LIMIT_HUGE
-#include <sys/time.h>
-#include <sys/resource.h>
-
-int original_stack_limit;
-#endif
-
 /* Prototypes for local functions */
 
 static char *
@@ -146,6 +141,9 @@ show_command PARAMS ((char *, int));
 static void
 info_command PARAMS ((char *, int));
 
+static void
+complete_command PARAMS ((char *, int));
+
 static void
 do_nothing PARAMS ((int));
 
@@ -304,6 +302,14 @@ static char *prompt;
 char *line;
 int linesize = 100;
 
+/* Nonzero if the current command is modified by "server ".  This
+   affects things like recording into the command history, comamnds
+   repeating on RETURN, etc.  This is so a user interface (emacs, GUI,
+   whatever) can issue its own commands and also send along commands
+   from the user, and have the user not notice that the user interface
+   is issuing commands too.  */
+int server_command;
+
 /* Baud rate specified for talking to serial target systems.  Default
    is left as -1, so targets can choose their own defaults.  */
 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
@@ -370,6 +376,18 @@ return_to_top_level (reason)
 
   disable_current_display ();
   do_cleanups (ALL_CLEANUPS);
+
+  if (annotation_level > 1)
+    switch (reason)
+      {
+      case RETURN_QUIT:
+       annotate_quit ();
+       break;
+      case RETURN_ERROR:
+       annotate_error ();
+       break;
+      }
+
   (NORETURN void) longjmp
     (reason == RETURN_ERROR ? error_return : quit_return, 1);
 }
@@ -500,6 +518,24 @@ read_command_file (stream)
   do_cleanups (cleanups);
 }
 \f
+void
+gdb_init ()
+{
+  /* Run the init function of each source file */
+
+  init_cmd_lists ();   /* This needs to be done first */
+  initialize_all_files ();
+  init_main ();                /* But that omits this file!  Do it now */
+  init_signals ();
+
+  /* We need a default language for parsing expressions, so simple things like
+     "set width 0" won't fail if no language is explicitly set in a config file
+     or implicitly set by reading an executable during startup. */
+  set_language (language_c);
+  expected_language = current_language;        /* don't warn about the change.  */
+}
+
+#ifndef MAIN_OVERRIDE
 int
 main (argc, argv)
      int argc;
@@ -539,6 +575,16 @@ main (argc, argv)
 
   register int i;
 
+/* start-sanitize-mpw */
+#ifdef MPW
+  /* Drop into MacsBug, but only if the executable is specially named. */
+  if (strcmp(argv[0], "DEBUGGDB") == 0)
+    DebugStr("\pat start of GDB main");
+
+  if (StandAlone)
+    mac_app = mac_init ();
+#endif /* MPW */
+/* end-sanitize-mpw */
   /* This needs to happen before the first use of malloc.  */
   init_malloc ((PTR) NULL);
 
@@ -568,19 +614,6 @@ main (argc, argv)
   getcwd (dirbuf, sizeof (dirbuf));
   current_directory = dirbuf;
 
-#ifdef SET_STACK_LIMIT_HUGE
-  {
-    struct rlimit rlim;
-
-    /* Set the stack limit huge so that alloca (particularly stringtab
-     * in dbxread.c) does not fail. */
-    getrlimit (RLIMIT_STACK, &rlim);
-    original_stack_limit = rlim.rlim_cur;
-    rlim.rlim_cur = rlim.rlim_max;
-    setrlimit (RLIMIT_STACK, &rlim);
-  }
-#endif /* SET_STACK_LIMIT_HUGE */
-
   /* Parse arguments and options.  */
   {
     int c;
@@ -600,8 +633,14 @@ main (argc, argv)
        {"n", no_argument, &inhibit_gdbinit, 1},
        {"batch", no_argument, &batch, 1},
        {"epoch", no_argument, &epoch_interface, 1},
-       {"fullname", no_argument, &frame_file_full_name, 1},
-       {"f", no_argument, &frame_file_full_name, 1},
+
+       /* This is a synonym for "--annotate=1".  --annotate is now preferred,
+          but keep this here for a long time because people will be running
+          emacses which use --fullname.  */
+       {"fullname", no_argument, 0, 'f'},
+       {"f", no_argument, 0, 'f'},
+
+       {"annotate", required_argument, 0, 12},
        {"help", no_argument, &print_help, 1},
        {"se", required_argument, 0, 10},
        {"symbols", required_argument, 0, 's'},
@@ -650,6 +689,13 @@ main (argc, argv)
          case 11:
            cdarg = optarg;
            break;
+         case 12:
+           /* FIXME: what if the syntax is wrong (e.g. not digits)?  */
+           annotation_level = atoi (optarg);
+           break;
+         case 'f':
+           annotation_level = 1;
+           break;
          case 's':
            symarg = optarg;
            break;
@@ -735,12 +781,7 @@ main (argc, argv)
       quiet = 1;
   }
 
-  /* Run the init function of each source file */
-
-  init_cmd_lists ();   /* This needs to be done first */
-  initialize_all_files ();
-  init_main ();                /* But that omits this file!  Do it now */
-  init_signals ();
+  gdb_init ();
 
   /* Do these (and anything which might call wrap_here or *_filtered)
      after initialize_all_files.  */
@@ -765,6 +806,12 @@ main (argc, argv)
 
       /* 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.  */
+/* start-sanitize-mpw */
+/* For reasons too ugly to describe... */
+#ifdef MPW_C
+      fputs_unfiltered ("This is the GNU debugger.\n", gdb_stdout);
+#else
+/* end-sanitize-mpw */
       fputs_unfiltered ("\
 This is the GNU debugger.  Usage:\n\
     gdb [options] [executable-file [core-file or process-id]]\n\
@@ -787,6 +834,9 @@ Options:\n\
   --mapped           Use mapped symbol files if supported on this system.\n\
   --readnow          Fully read symbol files on first access.\n\
 ", gdb_stdout);
+/* start-sanitize-mpw */
+#endif /* MPW_C */
+/* end-sanitize-mpw */
 #ifdef ADDITIONAL_OPTION_HELP
       fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout);
 #endif
@@ -812,12 +862,6 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
   /* We may get more than one warning, don't double space all of them... */
   warning_pre_print = "\nwarning: ";
 
-  /* We need a default language for parsing expressions, so simple things like
-     "set width 0" won't fail if no language is explicitly set in a config file
-     or implicitly set by reading an executable during startup. */
-  set_language (language_c);
-  expected_language = current_language;        /* don't warn about the change.  */
-
   /* Read and execute $HOME/.gdbinit file, if it exists.  This is done
      *before* all the command line arguments are processed; it sets
      global parameters, which are independent of what file you are
@@ -856,7 +900,6 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
       if (!SET_TOP_LEVEL ())
        {
          cd_command (cdarg, 0);
-         init_source_path ();
        }
     }
   do_cleanups (ALL_CLEANUPS);
@@ -966,12 +1009,24 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
       if (!SET_TOP_LEVEL ())
        {
          do_cleanups (ALL_CLEANUPS);           /* Do complete cleanup */
+/* start-sanitize-mpw */
+#ifdef MPW
+         /* If we're being a Mac application, go into a Mac-specific
+            event-handling loop instead.  We still want to be inside
+            the outer loop, because that will catch longjmps resulting
+            from some command executions. */
+         if (mac_app)
+           mac_command_loop ();
+         else
+#endif /* MPW */
+/* end-sanitize-mpw */
          command_loop ();
           quit_command ((char *)0, instream == stdin);
        }
     }
   /* No exit -- exit is through quit_command.  */
 }
+#endif /* MAIN_OVERRIDE */
 
 void
 execute_user_command (c, args)
@@ -1095,7 +1150,7 @@ command_loop ()
        reinitialize_more_filter ();
       old_chain = make_cleanup (command_loop_marker, 0);
       command = command_line_input (instream == stdin ? prompt : (char *) NULL,
-                                     instream == stdin);
+                                   instream == stdin, "prompt");
       if (command == 0)
        return;
       execute_command (command, instream == stdin);
@@ -1110,6 +1165,9 @@ command_loop ()
 void
 dont_repeat ()
 {
+  if (server_command)
+    return;
+
   /* If we aren't reading from standard input, we are saving the last
      thing read from stdin in line and don't want to delete it.  Null lines
      won't repeat here in any case.  */
@@ -1139,6 +1197,13 @@ gdb_readline (prrompt)
         character position to be off, since the newline we read from
         the user is not accounted for.  */
       fputs_unfiltered (prrompt, gdb_stdout);
+/* start-sanitize-mpw */
+#ifdef MPW
+      /* Move to a new line so the entered line doesn't have a prompt
+        on the front of it. */
+      fputs_unfiltered ("\n", gdb_stdout);
+#endif /* MPW */
+/* end-sanitize-mpw */
       gdb_flush (gdb_stdout);
     }
   
@@ -1323,7 +1388,7 @@ filename_completer (text, word)
    "p b-a" ambiguous (all symbols starting with a)
    "p b-" ambiguous (all symbols)
    "file Make" "file" (word break hard to screw up here)
-   "file ../gdb.stabs/wi" "erd" (needs to not break word at slash)
+   "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
    */
 
 /* Generate completions one by one for the completer.  Each time we are
@@ -1359,8 +1424,6 @@ symbol_completion_function (text, matches)
   /* Pointer within tmp_command which corresponds to text.  */
   char *word;
   struct cmd_list_element *c, *result_list;
-  extern char *rl_line_buffer;
-  extern int rl_point;
 
   if (matches == 0)
     {
@@ -1666,9 +1729,10 @@ init_signals ()
    simple input as the user has requested.  */
 
 char *
-command_line_input (prrompt, repeat)
+command_line_input (prrompt, repeat, annotation_suffix)
      char *prrompt;
      int repeat;
+     char *annotation_suffix;
 {
   static char *linebuffer = 0;
   static unsigned linelength = 0;
@@ -1680,6 +1744,19 @@ command_line_input (prrompt, repeat)
   char *nline;
   char got_eof = 0;
 
+  if (annotation_level > 1 && instream == stdin)
+    {
+      local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt))
+                            + strlen (annotation_suffix) + 40);
+      if (prrompt == NULL)
+       local_prompt[0] = '\0';
+      else
+       strcpy (local_prompt, prrompt);
+      strcat (local_prompt, "\n\032\032");
+      strcat (local_prompt, annotation_suffix);
+      strcat (local_prompt, "\n");
+    }
+
   if (linebuffer == 0)
     {
       linelength = 80;
@@ -1698,10 +1775,9 @@ command_line_input (prrompt, repeat)
 
   while (1)
     {
-      /* 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.  */
+      /* Make sure that all output has been output.  Some machines may let
+        you get away with leaving out some of the gdb_flush, but not all.  */
+      wrap_here ("");
       gdb_flush (gdb_stdout);
       gdb_flush (gdb_stderr);
 
@@ -1716,6 +1792,13 @@ command_line_input (prrompt, repeat)
          error_pre_print = source_error;
        }
 
+      if (annotation_level > 1 && instream == stdin)
+       {
+         printf_unfiltered ("\n\032\032pre-");
+         printf_unfiltered (annotation_suffix);
+         printf_unfiltered ("\n");
+       }
+
       /* Don't use fancy stuff if not talking to stdin.  */
       if (command_editing_p && instream == stdin
          && ISATTY (instream))
@@ -1723,6 +1806,13 @@ command_line_input (prrompt, repeat)
       else
        rl = gdb_readline (local_prompt);
 
+      if (annotation_level > 1 && instream == stdin)
+       {
+         printf_unfiltered ("\n\032\032post-");
+         printf_unfiltered (annotation_suffix);
+         printf_unfiltered ("\n");
+       }
+
       if (!rl || rl == (char *) EOF)
        {
          got_eof = 1;
@@ -1759,6 +1849,19 @@ command_line_input (prrompt, repeat)
   if (got_eof)
     return NULL;
 
+#define SERVER_COMMAND_LENGTH 7
+  server_command =
+    (p - linebuffer > SERVER_COMMAND_LENGTH)
+      && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
+  if (server_command)
+    {
+      /* Note that we don't set `line'.  Between this and the check in
+        dont_repeat, this insures that repeating will still do the
+        right thing.  */
+      *p = '\0';
+      return linebuffer + SERVER_COMMAND_LENGTH;
+    }
+
   /* Do history expansion if that is wished.  */
   if (history_expansion_p && instream == stdin
       && ISATTY (instream))
@@ -1777,7 +1880,7 @@ command_line_input (prrompt, repeat)
          if (expanded < 0)
            {
              free (history_value);
-             return command_line_input (prrompt, repeat);
+             return command_line_input (prrompt, repeat, annotation_suffix);
            }
          if (strlen (history_value) > linelength)
            {
@@ -1811,7 +1914,7 @@ command_line_input (prrompt, repeat)
       && ISATTY (stdin) && *linebuffer)
     add_history (linebuffer);
 
-  /* Note: lines consisting soley of comments are added to the command
+  /* Note: lines consisting solely of comments are added to the command
      history.  This is useful when you type a command, and then
      realize you don't want to execute it quite yet.  You can comment
      out the command and then later fetch it from the value history
@@ -1878,7 +1981,7 @@ read_command_lines ()
   while (1)
     {
       dont_repeat ();
-      p = command_line_input ((char *) NULL, instream == stdin);
+      p = command_line_input ((char *) NULL, instream == stdin, "commands");
       if (p == NULL)
        /* Treat end of file like "end".  */
        break;
@@ -1973,6 +2076,36 @@ info_command (arg, from_tty)
   help_list (infolist, "info ", -1, gdb_stdout);
 }
 
+/* The "complete" command is used by Emacs to implement completion.  */
+
+/* ARGSUSED */
+static void
+complete_command (arg, from_tty)
+     char *arg;
+     int from_tty;
+{
+  int i;
+  char *completion;
+
+  dont_repeat ();
+
+  if (arg == NULL)
+    {
+      rl_line_buffer[0] = '\0';
+      rl_point = 0;
+    }
+  else
+    {
+      strcpy (rl_line_buffer, arg);
+      rl_point = strlen (arg);
+    }
+
+  for (completion = symbol_completion_function (rl_line_buffer, i = 0);
+       completion;
+       completion = symbol_completion_function (rl_line_buffer, ++i))
+    printf_unfiltered ("%s\n", completion);
+}
+
 /* The "show" command with no arguments shows all the settings.  */
 
 /* ARGSUSED */
@@ -2214,7 +2347,8 @@ show_version (args, from_tty)
   immediate_quit--;
 }
 \f
-/* xgdb calls this to reprint the usual GDB prompt.  */
+/* xgdb calls this to reprint the usual GDB prompt.  Obsolete now that xgdb
+   is obsolete.  */
 
 void
 print_prompt ()
@@ -2492,7 +2626,6 @@ show_commands (args, from_tty)
   int hist_len;
 
   extern HIST_ENTRY *history_get PARAMS ((int));
-  extern int history_base;
 
   /* Print out some of the commands from the command history.  */
   /* First determine the length of the history list.  */
@@ -2856,6 +2989,9 @@ ie. the number of previous commands to keep a record of.", &sethistlist);
                  &infolist, "info ", 0, &cmdlist);
   add_com_alias ("i", "info", class_info, 1);
 
+  add_com ("complete", class_obscure, complete_command,
+          "List the completions for the rest of the line as a command.");
+
   add_prefix_cmd ("show", class_info, show_command,
                  "Generic command for showing things about the debugger.",
                  &showlist, "show ", 0, &cmdlist);
This page took 0.047264 seconds and 4 git commands to generate.