]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/top.c
import gdb-1999-10-25 snapshot
[thirdparty/binutils-gdb.git] / gdb / top.c
index 525e0a3fe3701987a8f1fbf5a9660d277a35afa9..73b286caa1d8acf39d635da10949f2079c782d2b 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -34,6 +34,7 @@
 #include "terminal.h"          /* For job_control.  */
 #include "annotate.h"
 #include "top.h"
+#include "version.h"
 
 /* readline include files */
 #include <readline/readline.h>
 #undef savestring
 
 #include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 
-#include "event-loop.h"
+
+#include "event-top.h"
 #include "gdb_string.h"
 #include "gdb_stat.h"
 #include <ctype.h>
@@ -152,10 +151,10 @@ static void disconnect PARAMS ((int));
 
 static void source_cleanup PARAMS ((FILE *));
 
-/* If this definition isn't overridden by the header files, assume
-   that isatty and fileno exist on this system.  */
-#ifndef ISATTY
-#define ISATTY(FP)     (isatty (fileno (FP)))
+/* Default command line prompt.  This is overriden in some configs. */
+
+#ifndef DEFAULT_PROMPT
+#define DEFAULT_PROMPT "(gdb) "
 #endif
 
 /* Initialization file name for gdb.  This is overridden in some configs.  */
@@ -172,18 +171,6 @@ int inhibit_gdbinit = 0;
 
 int use_windows = 1;
 
-/* Version number of GDB, as a string.  */
-
-extern char *version;
-
-/* Canonical host name as a string. */
-
-extern char *host_name;
-
-/* Canonical target name as a string. */
-
-extern char *target_name;
-
 extern char lang_frame_mismatch_warn[];                /* language.c */
 
 /* Flag for whether we want all the "from_tty" gubbish printed.  */
@@ -404,10 +391,6 @@ int (*query_hook) PARAMS ((const char *, va_list));
 
 void (*warning_hook) PARAMS ((const char *, va_list));
 
-/* Called from gdb_flush to flush output.  */
-
-void (*flush_hook) PARAMS ((GDB_FILE * stream));
-
 /* These three functions support getting lines of text from the user.  They
    are used in sequence.  First readline_begin_hook is called with a text
    string that might be (for example) a message for the user to type in a
@@ -430,6 +413,12 @@ void (*create_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
 void (*modify_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
 
+/* Called as appropriate to notify the interface that we have attached
+   to or detached from an already running process. */
+
+void (*attach_hook) PARAMS ((void));
+void (*detach_hook) PARAMS ((void));
+
 /* Called during long calculations to allow GUI to repair window damage, and to
    check for stop buttons, etc... */
 
@@ -459,6 +448,11 @@ int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus * status));
 void (*call_command_hook) PARAMS ((struct cmd_list_element * c, char *cmd,
                                   int from_tty));
 
+/* Called after a `set' command has finished.  Is only run if the
+   `set' command succeeded.  */
+
+void (*set_hook) PARAMS ((struct cmd_list_element *c));
+
 /* Called when the current thread changes.  Argument is thread id.  */
 
 void (*context_hook) PARAMS ((int id));
@@ -479,7 +473,7 @@ PARAMS ((void)) ATTR_NORETURN;
    loop, but can be caught via catch_errors.  */
 
      NORETURN void
-       return_to_top_level (reason)
+return_to_top_level (reason)
      enum return_reason reason;
 {
   quit_flag = 0;
@@ -491,8 +485,10 @@ PARAMS ((void)) ATTR_NORETURN;
 
   disable_current_display ();
   do_cleanups (ALL_CLEANUPS);
-  if (async_p && target_has_async)
+  if (event_loop_p && target_can_async_p ())
     do_exec_cleanups (ALL_CLEANUPS);
+  if (event_loop_p && sync_execution)
+    do_exec_error_cleanups (ALL_CLEANUPS);
 
   if (annotation_level > 1)
     switch (reason)
@@ -680,17 +676,24 @@ gdb_init (argv0)
   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
   current_directory = gdb_dirbuf;
 
+#ifdef __MSDOS__
+  /* Make sure we return to the original directory upon exit, come
+     what may, since the OS doesn't do that for us.  */
+  make_final_cleanup ((make_cleanup_func) chdir, strsave (current_directory));
+#endif
+
   init_cmd_lists ();           /* This needs to be done first */
   initialize_targets ();       /* Setup target_terminal macros for utils.c */
   initialize_utils ();         /* Make errors and warnings possible */
   initialize_all_files ();
+  initialize_current_architecture ();
   init_main ();                        /* But that omits this file!  Do it now */
 
   /* The signal handling mechanism is different depending whether or
      not the async version is run. NOTE: in the future we plan to make
      the event loop be the default engine of gdb, and this difference
      will disappear. */
-  if (async_p)
+  if (event_loop_p)
     async_init_signals ();
   else
     init_signals ();
@@ -1039,7 +1042,7 @@ arg_cleanup ()
 {
   struct user_args *oargs = user_args;
   if (!user_args)
-    fatal ("Internal error, arg_cleanup called with no user args.\n");
+    internal_error ("Internal error, arg_cleanup called with no user args.\n");
 
   user_args = user_args->next;
   free (oargs);
@@ -1277,7 +1280,7 @@ execute_command (p, from_tty)
 
       /* If the target is running, we allow only a limited set of
          commands. */
-      if (async_p && target_has_async && target_executing)
+      if (event_loop_p && target_can_async_p () && target_executing)
        if (!strcmp (c->name, "help")
            && !strcmp (c->name, "pwd")
            && !strcmp (c->name, "show")
@@ -2102,7 +2105,7 @@ command_line_input (prompt_arg, repeat, annotation_suffix)
 #ifdef STOP_SIGNAL
   if (job_control)
     {
-      if (async_p)
+      if (event_loop_p)
        signal (STOP_SIGNAL, handle_stop_sig);
       else
        signal (STOP_SIGNAL, stop_sig);
@@ -2967,7 +2970,7 @@ get_prompt_1 (formatted_prompt)
 {
   char *local_prompt;
 
-  if (async_p)
+  if (event_loop_p)
     local_prompt = PROMPT (0);
   else
     local_prompt = gdb_prompt_string;
@@ -3170,7 +3173,7 @@ get_prompt_1 (formatted_prompt)
                    else
                      {
                        if (available >= 16 /*? */ )    /* overflow protect */
-                         sprintf (outp, "%d", (long) longval);
+                         sprintf (outp, "%ld", (long) longval);
                      }
                    break;
                  }
@@ -3203,7 +3206,7 @@ get_prompt ()
   else
     {
       /* Prompt could not be formatted.  */
-      if (async_p)
+      if (event_loop_p)
        return PROMPT (0);
       else
        return gdb_prompt_string;
@@ -3219,7 +3222,7 @@ set_prompt (s)
    if (prompt != NULL)
    free (prompt);
  */
-  if (async_p)
+  if (event_loop_p)
     PROMPT (0) = savestring (s, strlen (s));
   else
     gdb_prompt_string = savestring (s, strlen (s));
@@ -3362,13 +3365,32 @@ cd_command (dir, from_tty)
   if (chdir (dir) < 0)
     perror_with_name (dir);
 
+#if defined(_WIN32) || defined(__MSDOS__)
+  /* There's too much mess with DOSish names like "d:", "d:.",
+     "d:./foo" etc.  Instead of having lots of special #ifdef'ed code,
+     simply get the canonicalized name of the current directory.  */
+  dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
+#endif
+
   len = strlen (dir);
-  dir = savestring (dir, len - (len > 1 && SLASH_P (dir[len - 1])));
+  if (SLASH_P (dir[len-1]))
+    {
+      /* Remove the trailing slash unless this is a root directory
+        (including a drive letter on non-Unix systems).  */
+      if (!(len == 1) /* "/" */
+#if defined(_WIN32) || defined(__MSDOS__)
+         && !(!SLASH_P (*dir) && ROOTED_P (dir) && len <= 3) /* "d:/" */
+#endif
+         )
+       len--;
+    }
+
+  dir = savestring (dir, len);
   if (ROOTED_P (dir))
     current_directory = dir;
   else
     {
-      if (SLASH_P (current_directory[0]) && current_directory[1] == '\0')
+      if (SLASH_P (current_directory[strlen (current_directory) - 1]))
        current_directory = concat (current_directory, dir, NULL);
       else
        current_directory = concat (current_directory, SLASH_STRING, dir, NULL);
@@ -3755,7 +3777,12 @@ init_history ()
       /* We include the current directory so that if the user changes
          directories the file written will be the same as the one
          that was read.  */
+#ifdef __MSDOS__
+    /* No leading dots in file names are allowed on MSDOS.  */
+    history_filename = concat (current_directory, "/_gdb_history", NULL);
+#else
       history_filename = concat (current_directory, "/.gdb_history", NULL);
+#endif
     }
   read_history (history_filename);
 }
@@ -3767,25 +3794,17 @@ init_main ()
 
   /* If we are running the asynchronous version,
      we initialize the prompts differently. */
-  if (!async_p)
+  if (!event_loop_p)
     {
-#ifdef DEFAULT_PROMPT
       gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
-#else
-      gdb_prompt_string = savestring ("(gdb) ", 6);
-#endif
     }
   else
     {
       /* initialize the prompt stack to a simple "(gdb) " prompt or to
-         whatever the DEFULAT_PROMPT is. */
+         whatever the DEFAULT_PROMPT is. */
       the_prompts.top = 0;
       PREFIX (0) = "";
-#ifdef DEFAULT_PROMPT
       PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
-#else
-      PROMPT (0) = savestring ("(gdb) ", 6);
-#endif
       SUFFIX (0) = "";
       /* Set things up for annotation_level > 1, if the user ever decides
          to use it. */
@@ -3848,7 +3867,7 @@ until the next time it is started.", &cmdlist);
      async version is run. NOTE: this difference is going to
      disappear as we make the event loop be the default engine of
      gdb. */
-  if (!async_p)
+  if (!event_loop_p)
     {
       add_show_from_set
        (add_set_cmd ("prompt", class_support, var_string,
@@ -3924,7 +3943,7 @@ hitting return.");
   /* The set editing command is different depending whether or not the
      async version is run. NOTE: this difference is going to disappear
      as we make the event loop be the default engine of gdb. */
-  if (!async_p)
+  if (!event_loop_p)
     {
       add_show_from_set
        (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
@@ -4048,7 +4067,7 @@ from the target.", &setlist),
      the async version is run. NOTE: this difference is going to
      disappear as we make the event loop be the default engine of
      gdb. */
-  if (!async_p)
+  if (!event_loop_p)
     {
       c = add_set_cmd ("annotate", class_obscure, var_zinteger,
                       (char *) &annotation_level, "Set annotation_level.\n\
@@ -4067,4 +4086,12 @@ from the target.", &setlist),
       add_show_from_set (c, &showlist);
       c->function.sfunc = set_async_annotation_level;
     }
+  if (event_loop_p)
+    {
+      add_show_from_set
+       (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p,
+                     "Set notification of completion for asynchronous execution commands.\n\
+Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),
+        &showlist);
+    }
 }