* gdb.arch/altivec-abi.exp: Check for compiler and set
[platform/upstream/binutils.git] / gdb / top.c
1 /* Top level stuff for GDB, the GNU debugger.
2
3    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4    1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
5    Free Software Foundation, Inc.
6
7    This file is part of GDB.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place - Suite 330,
22    Boston, MA 02111-1307, USA.  */
23
24 #include "defs.h"
25 #include "gdbcmd.h"
26 #include "call-cmds.h"
27 #include "cli/cli-cmds.h"
28 #include "cli/cli-script.h"
29 #include "cli/cli-setshow.h"
30 #include "cli/cli-decode.h"
31 #include "symtab.h"
32 #include "inferior.h"
33 #include "exceptions.h"
34 #include <signal.h>
35 #include "target.h"
36 #include "breakpoint.h"
37 #include "gdbtypes.h"
38 #include "expression.h"
39 #include "value.h"
40 #include "language.h"
41 #include "terminal.h"           /* For job_control.  */
42 #include "annotate.h"
43 #include "completer.h"
44 #include "top.h"
45 #include "version.h"
46 #include "serial.h"
47 #include "doublest.h"
48 #include "gdb_assert.h"
49
50 /* readline include files */
51 #include "readline/readline.h"
52 #include "readline/history.h"
53
54 /* readline defines this.  */
55 #undef savestring
56
57 #include <sys/types.h>
58
59 #include "event-top.h"
60 #include "gdb_string.h"
61 #include "gdb_stat.h"
62 #include <ctype.h>
63 #include "ui-out.h"
64 #include "cli-out.h"
65
66 /* Default command line prompt.  This is overriden in some configs. */
67
68 #ifndef DEFAULT_PROMPT
69 #define DEFAULT_PROMPT  "(gdb) "
70 #endif
71
72 /* Initialization file name for gdb.  This is overridden in some configs.  */
73
74 #ifndef GDBINIT_FILENAME
75 #define GDBINIT_FILENAME        ".gdbinit"
76 #endif
77 char gdbinit[] = GDBINIT_FILENAME;
78
79 int inhibit_gdbinit = 0;
80
81 /* If nonzero, and GDB has been configured to be able to use windows,
82    attempt to open them upon startup.  */
83
84 int use_windows = 0;
85
86 extern char lang_frame_mismatch_warn[];         /* language.c */
87
88 /* Flag for whether we want all the "from_tty" gubbish printed.  */
89
90 int caution = 1;                /* Default is yes, sigh. */
91 static void
92 show_caution (struct ui_file *file, int from_tty,
93               struct cmd_list_element *c, const char *value)
94 {
95   fprintf_filtered (file, _("\
96 Whether to confirm potentially dangerous operations is %s.\n"),
97                     value);
98 }
99
100 /* stdio stream that command input is being read from.  Set to stdin normally.
101    Set by source_command to the file we are sourcing.  Set to NULL if we are
102    executing a user-defined command or interacting via a GUI.  */
103
104 FILE *instream;
105
106 /* Current working directory.  */
107
108 char *current_directory;
109
110 /* The directory name is actually stored here (usually).  */
111 char gdb_dirbuf[1024];
112
113 /* Function to call before reading a command, if nonzero.
114    The function receives two args: an input stream,
115    and a prompt string.  */
116
117 void (*window_hook) (FILE *, char *);
118
119 int epoch_interface;
120 int xgdb_verbose;
121
122 /* gdb prints this when reading a command interactively */
123 static char *gdb_prompt_string; /* the global prompt string */
124
125 /* Buffer used for reading command lines, and the size
126    allocated for it so far.  */
127
128 char *line;
129 int linesize = 100;
130
131 /* Nonzero if the current command is modified by "server ".  This
132    affects things like recording into the command history, commands
133    repeating on RETURN, etc.  This is so a user interface (emacs, GUI,
134    whatever) can issue its own commands and also send along commands
135    from the user, and have the user not notice that the user interface
136    is issuing commands too.  */
137 int server_command;
138
139 /* Baud rate specified for talking to serial target systems.  Default
140    is left as -1, so targets can choose their own defaults.  */
141 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
142    or (unsigned int)-1.  This is a Bad User Interface.  */
143
144 int baud_rate = -1;
145
146 /* Timeout limit for response from target. */
147
148 /* The default value has been changed many times over the years.  It 
149    was originally 5 seconds.  But that was thought to be a long time 
150    to sit and wait, so it was changed to 2 seconds.  That was thought
151    to be plenty unless the connection was going through some terminal 
152    server or multiplexer or other form of hairy serial connection.
153
154    In mid-1996, remote_timeout was moved from remote.c to top.c and 
155    it began being used in other remote-* targets.  It appears that the
156    default was changed to 20 seconds at that time, perhaps because the
157    Renesas E7000 ICE didn't always respond in a timely manner.
158
159    But if 5 seconds is a long time to sit and wait for retransmissions,
160    20 seconds is far worse.  This demonstrates the difficulty of using 
161    a single variable for all protocol timeouts.
162
163    As remote.c is used much more than remote-e7000.c, it was changed 
164    back to 2 seconds in 1999. */
165
166 int remote_timeout = 2;
167
168 /* Non-zero tells remote* modules to output debugging info.  */
169
170 int remote_debug = 0;
171
172 /* Non-zero means the target is running. Note: this is different from
173    saying that there is an active target and we are stopped at a
174    breakpoint, for instance. This is a real indicator whether the
175    target is off and running, which gdb is doing something else. */
176 int target_executing = 0;
177
178 /* Level of control structure.  */
179 static int control_level;
180
181 /* Sbrk location on entry to main.  Used for statistics only.  */
182 #ifdef HAVE_SBRK
183 char *lim_at_start;
184 #endif
185
186 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT.  */
187
188 #ifndef STOP_SIGNAL
189 #ifdef SIGTSTP
190 #define STOP_SIGNAL SIGTSTP
191 static void stop_sig (int);
192 #endif
193 #endif
194
195 /* Hooks for alternate command interfaces.  */
196
197 /* Called after most modules have been initialized, but before taking users
198    command file.
199
200    If the UI fails to initialize and it wants GDB to continue
201    using the default UI, then it should clear this hook before returning. */
202
203 void (*deprecated_init_ui_hook) (char *argv0);
204
205 /* This hook is called from within gdb's many mini-event loops which could
206    steal control from a real user interface's event loop. It returns
207    non-zero if the user is requesting a detach, zero otherwise. */
208
209 int (*deprecated_ui_loop_hook) (int);
210
211 /* Called instead of command_loop at top level.  Can be invoked via
212    throw_exception().  */
213
214 void (*deprecated_command_loop_hook) (void);
215
216
217 /* Called from print_frame_info to list the line we stopped in.  */
218
219 void (*deprecated_print_frame_info_listing_hook) (struct symtab * s, int line,
220                                                   int stopline, int noerror);
221 /* Replaces most of query.  */
222
223 int (*deprecated_query_hook) (const char *, va_list);
224
225 /* Replaces most of warning.  */
226
227 void (*deprecated_warning_hook) (const char *, va_list);
228
229 /* These three functions support getting lines of text from the user.
230    They are used in sequence.  First deprecated_readline_begin_hook is
231    called with a text string that might be (for example) a message for
232    the user to type in a sequence of commands to be executed at a
233    breakpoint.  If this function calls back to a GUI, it might take
234    this opportunity to pop up a text interaction window with this
235    message.  Next, deprecated_readline_hook is called with a prompt
236    that is emitted prior to collecting the user input.  It can be
237    called multiple times.  Finally, deprecated_readline_end_hook is
238    called to notify the GUI that we are done with the interaction
239    window and it can close it.  */
240
241 void (*deprecated_readline_begin_hook) (char *, ...);
242 char *(*deprecated_readline_hook) (char *);
243 void (*deprecated_readline_end_hook) (void);
244
245 /* Called as appropriate to notify the interface of the specified breakpoint
246    conditions.  */
247
248 void (*deprecated_create_breakpoint_hook) (struct breakpoint * bpt);
249 void (*deprecated_delete_breakpoint_hook) (struct breakpoint * bpt);
250 void (*deprecated_modify_breakpoint_hook) (struct breakpoint * bpt);
251
252 /* Called as appropriate to notify the interface that we have attached
253    to or detached from an already running process. */
254
255 void (*deprecated_attach_hook) (void);
256 void (*deprecated_detach_hook) (void);
257
258 /* Called during long calculations to allow GUI to repair window damage, and to
259    check for stop buttons, etc... */
260
261 void (*deprecated_interactive_hook) (void);
262
263 /* Called when the registers have changed, as a hint to a GUI
264    to minimize window update. */
265
266 void (*deprecated_registers_changed_hook) (void);
267
268 /* Tell the GUI someone changed the register REGNO. -1 means
269    that the caller does not know which register changed or
270    that several registers have changed (see value_assign). */
271 void (*deprecated_register_changed_hook) (int regno);
272
273 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
274 void (*deprecated_memory_changed_hook) (CORE_ADDR addr, int len);
275
276 /* Called when going to wait for the target.  Usually allows the GUI to run
277    while waiting for target events.  */
278
279 ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
280                                        struct target_waitstatus * status);
281
282 /* Used by UI as a wrapper around command execution.  May do various things
283    like enabling/disabling buttons, etc...  */
284
285 void (*deprecated_call_command_hook) (struct cmd_list_element * c, char *cmd,
286                                       int from_tty);
287
288 /* Called after a `set' command has finished.  Is only run if the
289    `set' command succeeded.  */
290
291 void (*deprecated_set_hook) (struct cmd_list_element * c);
292
293 /* Called when the current thread changes.  Argument is thread id.  */
294
295 void (*deprecated_context_hook) (int id);
296
297 /* Takes control from error ().  Typically used to prevent longjmps out of the
298    middle of the GUI.  Usually used in conjunction with a catch routine.  */
299
300 void (*deprecated_error_hook) (void);
301
302 /* Handler for SIGHUP.  */
303
304 #ifdef SIGHUP
305 /* NOTE 1999-04-29: This function will be static again, once we modify
306    gdb to use the event loop as the default command loop and we merge
307    event-top.c into this file, top.c */
308 /* static */ int
309 quit_cover (void *s)
310 {
311   caution = 0;                  /* Throw caution to the wind -- we're exiting.
312                                    This prevents asking the user dumb questions.  */
313   quit_command ((char *) 0, 0);
314   return 0;
315 }
316 #endif /* defined SIGHUP */
317 \f
318 /* Line number we are currently in in a file which is being sourced.  */
319 /* NOTE 1999-04-29: This variable will be static again, once we modify
320    gdb to use the event loop as the default command loop and we merge
321    event-top.c into this file, top.c */
322 /* static */ int source_line_number;
323
324 /* Name of the file we are sourcing.  */
325 /* NOTE 1999-04-29: This variable will be static again, once we modify
326    gdb to use the event loop as the default command loop and we merge
327    event-top.c into this file, top.c */
328 /* static */ char *source_file_name;
329
330 /* Clean up on error during a "source" command (or execution of a
331    user-defined command).  */
332
333 void
334 do_restore_instream_cleanup (void *stream)
335 {
336   /* Restore the previous input stream.  */
337   instream = stream;
338 }
339
340 /* Read commands from STREAM.  */
341 void
342 read_command_file (FILE *stream)
343 {
344   struct cleanup *cleanups;
345
346   cleanups = make_cleanup (do_restore_instream_cleanup, instream);
347   instream = stream;
348   command_loop ();
349   do_cleanups (cleanups);
350 }
351 \f
352 void (*pre_init_ui_hook) (void);
353
354 #ifdef __MSDOS__
355 void
356 do_chdir_cleanup (void *old_dir)
357 {
358   chdir (old_dir);
359   xfree (old_dir);
360 }
361 #endif
362
363 /* Execute the line P as a command.
364    Pass FROM_TTY as second argument to the defining function.  */
365
366 void
367 execute_command (char *p, int from_tty)
368 {
369   struct cmd_list_element *c;
370   enum language flang;
371   static int warned = 0;
372   char *line;
373   
374   free_all_values ();
375
376   /* Force cleanup of any alloca areas if using C alloca instead of
377      a builtin alloca.  */
378   alloca (0);
379
380   /* This can happen when command_line_input hits end of file.  */
381   if (p == NULL)
382     return;
383
384   serial_log_command (p);
385
386   while (*p == ' ' || *p == '\t')
387     p++;
388   if (*p)
389     {
390       char *arg;
391       line = p;
392
393       c = lookup_cmd (&p, cmdlist, "", 0, 1);
394
395       /* If the target is running, we allow only a limited set of
396          commands. */
397       if (target_can_async_p () && target_executing)
398         if (strcmp (c->name, "help") != 0
399             && strcmp (c->name, "pwd") != 0
400             && strcmp (c->name, "show") != 0
401             && strcmp (c->name, "stop") != 0)
402           error (_("Cannot execute this command while the target is running."));
403
404       /* Pass null arg rather than an empty one.  */
405       arg = *p ? p : 0;
406
407       /* FIXME: cagney/2002-02-02: The c->type test is pretty dodgy
408          while the is_complete_command(cfunc) test is just plain
409          bogus.  They should both be replaced by a test of the form
410          c->strip_trailing_white_space_p.  */
411       /* NOTE: cagney/2002-02-02: The function.cfunc in the below
412          can't be replaced with func.  This is because it is the
413          cfunc, and not the func, that has the value that the
414          is_complete_command hack is testing for.  */
415       /* Clear off trailing whitespace, except for set and complete
416          command.  */
417       if (arg
418           && c->type != set_cmd
419           && !is_complete_command (c))
420         {
421           p = arg + strlen (arg) - 1;
422           while (p >= arg && (*p == ' ' || *p == '\t'))
423             p--;
424           *(p + 1) = '\0';
425         }
426
427       /* If this command has been pre-hooked, run the hook first. */
428       execute_cmd_pre_hook (c);
429
430       if (c->flags & DEPRECATED_WARN_USER)
431         deprecated_cmd_warning (&line);
432
433       if (c->class == class_user)
434         execute_user_command (c, arg);
435       else if (c->type == set_cmd || c->type == show_cmd)
436         do_setshow_command (arg, from_tty & caution, c);
437       else if (!cmd_func_p (c))
438         error (_("That is not a command, just a help topic."));
439       else if (deprecated_call_command_hook)
440         deprecated_call_command_hook (c, arg, from_tty & caution);
441       else
442         cmd_func (c, arg, from_tty & caution);
443        
444       /* If this command has been post-hooked, run the hook last. */
445       execute_cmd_post_hook (c);
446
447     }
448
449   /* Tell the user if the language has changed (except first time).  */
450   if (current_language != expected_language)
451     {
452       if (language_mode == language_mode_auto)
453         {
454           language_info (1);    /* Print what changed.  */
455         }
456       warned = 0;
457     }
458
459   /* Warn the user if the working language does not match the
460      language of the current frame.  Only warn the user if we are
461      actually running the program, i.e. there is a stack. */
462   /* FIXME:  This should be cacheing the frame and only running when
463      the frame changes.  */
464
465   if (target_has_stack)
466     {
467       flang = get_frame_language ();
468       if (!warned
469           && flang != language_unknown
470           && flang != current_language->la_language)
471         {
472           printf_filtered ("%s\n", lang_frame_mismatch_warn);
473           warned = 1;
474         }
475     }
476 }
477
478 /* Read commands from `instream' and execute them
479    until end of file or error reading instream.  */
480
481 void
482 command_loop (void)
483 {
484   struct cleanup *old_chain;
485   char *command;
486   int stdin_is_tty = ISATTY (stdin);
487   long time_at_cmd_start;
488 #ifdef HAVE_SBRK
489   long space_at_cmd_start = 0;
490 #endif
491   extern int display_time;
492   extern int display_space;
493
494   while (instream && !feof (instream))
495     {
496       if (window_hook && instream == stdin)
497         (*window_hook) (instream, get_prompt ());
498
499       quit_flag = 0;
500       if (instream == stdin && stdin_is_tty)
501         reinitialize_more_filter ();
502       old_chain = make_cleanup (null_cleanup, 0);
503
504       /* Get a command-line. This calls the readline package. */
505       command = command_line_input (instream == stdin ?
506                                     get_prompt () : (char *) NULL,
507                                     instream == stdin, "prompt");
508       if (command == 0)
509         return;
510
511       time_at_cmd_start = get_run_time ();
512
513       if (display_space)
514         {
515 #ifdef HAVE_SBRK
516           char *lim = (char *) sbrk (0);
517           space_at_cmd_start = lim - lim_at_start;
518 #endif
519         }
520
521       execute_command (command, instream == stdin);
522       /* Do any commands attached to breakpoint we stopped at.  */
523       bpstat_do_actions (&stop_bpstat);
524       do_cleanups (old_chain);
525
526       if (display_time)
527         {
528           long cmd_time = get_run_time () - time_at_cmd_start;
529
530           printf_unfiltered (_("Command execution time: %ld.%06ld\n"),
531                              cmd_time / 1000000, cmd_time % 1000000);
532         }
533
534       if (display_space)
535         {
536 #ifdef HAVE_SBRK
537           char *lim = (char *) sbrk (0);
538           long space_now = lim - lim_at_start;
539           long space_diff = space_now - space_at_cmd_start;
540
541           printf_unfiltered (_("Space used: %ld (%c%ld for this command)\n"),
542                              space_now,
543                              (space_diff >= 0 ? '+' : '-'),
544                              space_diff);
545 #endif
546         }
547     }
548 }
549
550 /* Read commands from `instream' and execute them until end of file or
551    error reading instream. This command loop doesnt care about any
552    such things as displaying time and space usage. If the user asks
553    for those, they won't work. */
554 void
555 simplified_command_loop (char *(*read_input_func) (char *),
556                          void (*execute_command_func) (char *, int))
557 {
558   struct cleanup *old_chain;
559   char *command;
560   int stdin_is_tty = ISATTY (stdin);
561
562   while (instream && !feof (instream))
563     {
564       quit_flag = 0;
565       if (instream == stdin && stdin_is_tty)
566         reinitialize_more_filter ();
567       old_chain = make_cleanup (null_cleanup, 0);
568
569       /* Get a command-line. */
570       command = (*read_input_func) (instream == stdin ?
571                                     get_prompt () : (char *) NULL);
572
573       if (command == 0)
574         return;
575
576       (*execute_command_func) (command, instream == stdin);
577
578       /* Do any commands attached to breakpoint we stopped at.  */
579       bpstat_do_actions (&stop_bpstat);
580
581       do_cleanups (old_chain);
582     }
583 }
584 \f
585 /* Commands call this if they do not want to be repeated by null lines.  */
586
587 void
588 dont_repeat (void)
589 {
590   if (server_command)
591     return;
592
593   /* If we aren't reading from standard input, we are saving the last
594      thing read from stdin in line and don't want to delete it.  Null lines
595      won't repeat here in any case.  */
596   if (instream == stdin)
597     *line = 0;
598 }
599 \f
600 /* Read a line from the stream "instream" without command line editing.
601
602    It prints PROMPT_ARG once at the start.
603    Action is compatible with "readline", e.g. space for the result is
604    malloc'd and should be freed by the caller.
605
606    A NULL return means end of file.  */
607 char *
608 gdb_readline (char *prompt_arg)
609 {
610   int c;
611   char *result;
612   int input_index = 0;
613   int result_size = 80;
614
615   if (prompt_arg)
616     {
617       /* Don't use a _filtered function here.  It causes the assumed
618          character position to be off, since the newline we read from
619          the user is not accounted for.  */
620       fputs_unfiltered (prompt_arg, gdb_stdout);
621       gdb_flush (gdb_stdout);
622     }
623
624   result = (char *) xmalloc (result_size);
625
626   while (1)
627     {
628       /* Read from stdin if we are executing a user defined command.
629          This is the right thing for prompt_for_continue, at least.  */
630       c = fgetc (instream ? instream : stdin);
631
632       if (c == EOF)
633         {
634           if (input_index > 0)
635             /* The last line does not end with a newline.  Return it, and
636                if we are called again fgetc will still return EOF and
637                we'll return NULL then.  */
638             break;
639           xfree (result);
640           return NULL;
641         }
642
643       if (c == '\n')
644         {
645           if (input_index > 0 && result[input_index - 1] == '\r')
646             input_index--;
647           break;
648         }
649
650       result[input_index++] = c;
651       while (input_index >= result_size)
652         {
653           result_size *= 2;
654           result = (char *) xrealloc (result, result_size);
655         }
656     }
657
658   result[input_index++] = '\0';
659   return result;
660 }
661
662 /* Variables which control command line editing and history
663    substitution.  These variables are given default values at the end
664    of this file.  */
665 static int command_editing_p;
666
667 /* NOTE 1999-04-29: This variable will be static again, once we modify
668    gdb to use the event loop as the default command loop and we merge
669    event-top.c into this file, top.c */
670
671 /* static */ int history_expansion_p;
672
673 static int write_history_p;
674 static void
675 show_write_history_p (struct ui_file *file, int from_tty,
676                       struct cmd_list_element *c, const char *value)
677 {
678   fprintf_filtered (file, _("Saving of the history record on exit is %s.\n"),
679                     value);
680 }
681
682 static int history_size;
683 static void
684 show_history_size (struct ui_file *file, int from_tty,
685                    struct cmd_list_element *c, const char *value)
686 {
687   fprintf_filtered (file, _("The size of the command history is %s.\n"),
688                     value);
689 }
690
691 static char *history_filename;
692 static void
693 show_history_filename (struct ui_file *file, int from_tty,
694                        struct cmd_list_element *c, const char *value)
695 {
696   fprintf_filtered (file, _("\
697 The filename in which to record the command history is \"%s\".\n"),
698                     value);
699 }
700
701 /* This is like readline(), but it has some gdb-specific behavior.
702    gdb can use readline in both the synchronous and async modes during
703    a single gdb invocation.  At the ordinary top-level prompt we might
704    be using the async readline.  That means we can't use
705    rl_pre_input_hook, since it doesn't work properly in async mode.
706    However, for a secondary prompt (" >", such as occurs during a
707    `define'), gdb just calls readline() directly, running it in
708    synchronous mode.  So for operate-and-get-next to work in this
709    situation, we have to switch the hooks around.  That is what
710    gdb_readline_wrapper is for.  */
711 char *
712 gdb_readline_wrapper (char *prompt)
713 {
714   /* Set the hook that works in this case.  */
715   if (after_char_processing_hook)
716     {
717       rl_pre_input_hook = (Function *) after_char_processing_hook;
718       after_char_processing_hook = NULL;
719     }
720
721   return readline (prompt);
722 }
723
724 \f
725 #ifdef STOP_SIGNAL
726 static void
727 stop_sig (int signo)
728 {
729 #if STOP_SIGNAL == SIGTSTP
730   signal (SIGTSTP, SIG_DFL);
731 #if HAVE_SIGPROCMASK
732   {
733     sigset_t zero;
734
735     sigemptyset (&zero);
736     sigprocmask (SIG_SETMASK, &zero, 0);
737   }
738 #elif HAVE_SIGSETMASK
739   sigsetmask (0);
740 #endif
741   kill (getpid (), SIGTSTP);
742   signal (SIGTSTP, stop_sig);
743 #else
744   signal (STOP_SIGNAL, stop_sig);
745 #endif
746   printf_unfiltered ("%s", get_prompt ());
747   gdb_flush (gdb_stdout);
748
749   /* Forget about any previous command -- null line now will do nothing.  */
750   dont_repeat ();
751 }
752 #endif /* STOP_SIGNAL */
753
754 /* Initialize signal handlers. */
755 static void
756 float_handler (int signo)
757 {
758   /* This message is based on ANSI C, section 4.7.  Note that integer
759      divide by zero causes this, so "float" is a misnomer.  */
760   signal (SIGFPE, float_handler);
761   error (_("Erroneous arithmetic operation."));
762 }
763
764 static void
765 do_nothing (int signo)
766 {
767   /* Under System V the default disposition of a signal is reinstated after
768      the signal is caught and delivered to an application process.  On such
769      systems one must restore the replacement signal handler if one wishes
770      to continue handling the signal in one's program.  On BSD systems this
771      is not needed but it is harmless, and it simplifies the code to just do
772      it unconditionally. */
773   signal (signo, do_nothing);
774 }
775
776 /* The current saved history number from operate-and-get-next.
777    This is -1 if not valid.  */
778 static int operate_saved_history = -1;
779
780 /* This is put on the appropriate hook and helps operate-and-get-next
781    do its work.  */
782 static void
783 gdb_rl_operate_and_get_next_completion (void)
784 {
785   int delta = where_history () - operate_saved_history;
786   /* The `key' argument to rl_get_previous_history is ignored.  */
787   rl_get_previous_history (delta, 0);
788   operate_saved_history = -1;
789
790   /* readline doesn't automatically update the display for us.  */
791   rl_redisplay ();
792
793   after_char_processing_hook = NULL;
794   rl_pre_input_hook = NULL;
795 }
796
797 /* This is a gdb-local readline command handler.  It accepts the
798    current command line (like RET does) and, if this command was taken
799    from the history, arranges for the next command in the history to
800    appear on the command line when the prompt returns.
801    We ignore the arguments.  */
802 static int
803 gdb_rl_operate_and_get_next (int count, int key)
804 {
805   int where;
806
807   /* Use the async hook.  */
808   after_char_processing_hook = gdb_rl_operate_and_get_next_completion;
809
810   /* Find the current line, and find the next line to use.  */
811   where = where_history();
812
813   /* FIXME: kettenis/20020817: max_input_history is renamed into
814      history_max_entries in readline-4.2.  When we do a new readline
815      import, we should probably change it here too, even though
816      readline maintains backwards compatibility for now by still
817      defining max_input_history.  */
818   if ((history_is_stifled () && (history_length >= max_input_history)) ||
819       (where >= history_length - 1))
820     operate_saved_history = where;
821   else
822     operate_saved_history = where + 1;
823
824   return rl_newline (1, key);
825 }
826 \f
827 /* Read one line from the command input stream `instream'
828    into the local static buffer `linebuffer' (whose current length
829    is `linelength').
830    The buffer is made bigger as necessary.
831    Returns the address of the start of the line.
832
833    NULL is returned for end of file.
834
835    *If* the instream == stdin & stdin is a terminal, the line read
836    is copied into the file line saver (global var char *line,
837    length linesize) so that it can be duplicated.
838
839    This routine either uses fancy command line editing or
840    simple input as the user has requested.  */
841
842 char *
843 command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
844 {
845   static char *linebuffer = 0;
846   static unsigned linelength = 0;
847   char *p;
848   char *p1;
849   char *rl;
850   char *local_prompt = prompt_arg;
851   char *nline;
852   char got_eof = 0;
853
854   /* The annotation suffix must be non-NULL.  */
855   if (annotation_suffix == NULL)
856     annotation_suffix = "";
857
858   if (annotation_level > 1 && instream == stdin)
859     {
860       local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
861                              + strlen (annotation_suffix) + 40);
862       if (prompt_arg == NULL)
863         local_prompt[0] = '\0';
864       else
865         strcpy (local_prompt, prompt_arg);
866       strcat (local_prompt, "\n\032\032");
867       strcat (local_prompt, annotation_suffix);
868       strcat (local_prompt, "\n");
869     }
870
871   if (linebuffer == 0)
872     {
873       linelength = 80;
874       linebuffer = (char *) xmalloc (linelength);
875     }
876
877   p = linebuffer;
878
879   /* Control-C quits instantly if typed while in this loop
880      since it should not wait until the user types a newline.  */
881   immediate_quit++;
882 #ifdef STOP_SIGNAL
883   if (job_control)
884     signal (STOP_SIGNAL, handle_stop_sig);
885 #endif
886
887   while (1)
888     {
889       /* Make sure that all output has been output.  Some machines may let
890          you get away with leaving out some of the gdb_flush, but not all.  */
891       wrap_here ("");
892       gdb_flush (gdb_stdout);
893       gdb_flush (gdb_stderr);
894
895       if (source_file_name != NULL)
896         ++source_line_number;
897
898       if (annotation_level > 1 && instream == stdin)
899         {
900           puts_unfiltered ("\n\032\032pre-");
901           puts_unfiltered (annotation_suffix);
902           puts_unfiltered ("\n");
903         }
904
905       /* Don't use fancy stuff if not talking to stdin.  */
906       if (deprecated_readline_hook && instream == NULL)
907         {
908           rl = (*deprecated_readline_hook) (local_prompt);
909         }
910       else if (command_editing_p && instream == stdin && ISATTY (instream))
911         {
912           rl = gdb_readline_wrapper (local_prompt);
913         }
914       else
915         {
916           rl = gdb_readline (local_prompt);
917         }
918
919       if (annotation_level > 1 && instream == stdin)
920         {
921           puts_unfiltered ("\n\032\032post-");
922           puts_unfiltered (annotation_suffix);
923           puts_unfiltered ("\n");
924         }
925
926       if (!rl || rl == (char *) EOF)
927         {
928           got_eof = 1;
929           break;
930         }
931       if (strlen (rl) + 1 + (p - linebuffer) > linelength)
932         {
933           linelength = strlen (rl) + 1 + (p - linebuffer);
934           nline = (char *) xrealloc (linebuffer, linelength);
935           p += nline - linebuffer;
936           linebuffer = nline;
937         }
938       p1 = rl;
939       /* Copy line.  Don't copy null at end.  (Leaves line alone
940          if this was just a newline)  */
941       while (*p1)
942         *p++ = *p1++;
943
944       xfree (rl);               /* Allocated in readline.  */
945
946       if (p == linebuffer || *(p - 1) != '\\')
947         break;
948
949       p--;                      /* Put on top of '\'.  */
950       local_prompt = (char *) 0;
951     }
952
953 #ifdef STOP_SIGNAL
954   if (job_control)
955     signal (STOP_SIGNAL, SIG_DFL);
956 #endif
957   immediate_quit--;
958
959   if (got_eof)
960     return NULL;
961
962 #define SERVER_COMMAND_LENGTH 7
963   server_command =
964     (p - linebuffer > SERVER_COMMAND_LENGTH)
965     && strncmp (linebuffer, "server ", SERVER_COMMAND_LENGTH) == 0;
966   if (server_command)
967     {
968       /* Note that we don't set `line'.  Between this and the check in
969          dont_repeat, this insures that repeating will still do the
970          right thing.  */
971       *p = '\0';
972       return linebuffer + SERVER_COMMAND_LENGTH;
973     }
974
975   /* Do history expansion if that is wished.  */
976   if (history_expansion_p && instream == stdin
977       && ISATTY (instream))
978     {
979       char *history_value;
980       int expanded;
981
982       *p = '\0';                /* Insert null now.  */
983       expanded = history_expand (linebuffer, &history_value);
984       if (expanded)
985         {
986           /* Print the changes.  */
987           printf_unfiltered ("%s\n", history_value);
988
989           /* If there was an error, call this function again.  */
990           if (expanded < 0)
991             {
992               xfree (history_value);
993               return command_line_input (prompt_arg, repeat, annotation_suffix);
994             }
995           if (strlen (history_value) > linelength)
996             {
997               linelength = strlen (history_value) + 1;
998               linebuffer = (char *) xrealloc (linebuffer, linelength);
999             }
1000           strcpy (linebuffer, history_value);
1001           p = linebuffer + strlen (linebuffer);
1002           xfree (history_value);
1003         }
1004     }
1005
1006   /* If we just got an empty line, and that is supposed
1007      to repeat the previous command, return the value in the
1008      global buffer.  */
1009   if (repeat && p == linebuffer)
1010     return line;
1011   for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
1012   if (repeat && !*p1)
1013     return line;
1014
1015   *p = 0;
1016
1017   /* Add line to history if appropriate.  */
1018   if (instream == stdin
1019       && ISATTY (stdin) && *linebuffer)
1020     add_history (linebuffer);
1021
1022   /* Note: lines consisting solely of comments are added to the command
1023      history.  This is useful when you type a command, and then
1024      realize you don't want to execute it quite yet.  You can comment
1025      out the command and then later fetch it from the value history
1026      and remove the '#'.  The kill ring is probably better, but some
1027      people are in the habit of commenting things out.  */
1028   if (*p1 == '#')
1029     *p1 = '\0';                 /* Found a comment. */
1030
1031   /* Save into global buffer if appropriate.  */
1032   if (repeat)
1033     {
1034       if (linelength > linesize)
1035         {
1036           line = xrealloc (line, linelength);
1037           linesize = linelength;
1038         }
1039       strcpy (line, linebuffer);
1040       return line;
1041     }
1042
1043   return linebuffer;
1044 }
1045 \f
1046 /* Print the GDB banner. */
1047 void
1048 print_gdb_version (struct ui_file *stream)
1049 {
1050   /* From GNU coding standards, first line is meant to be easy for a
1051      program to parse, and is just canonical program name and version
1052      number, which starts after last space. */
1053
1054   fprintf_filtered (stream, "GNU gdb %s\n", version);
1055
1056   /* Second line is a copyright notice. */
1057
1058   fprintf_filtered (stream, "Copyright 2004 Free Software Foundation, Inc.\n");
1059
1060   /* Following the copyright is a brief statement that the program is
1061      free software, that users are free to copy and change it on
1062      certain conditions, that it is covered by the GNU GPL, and that
1063      there is no warranty. */
1064
1065   fprintf_filtered (stream, "\
1066 GDB is free software, covered by the GNU General Public License, and you are\n\
1067 welcome to change it and/or distribute copies of it under certain conditions.\n\
1068 Type \"show copying\" to see the conditions.\n\
1069 There is absolutely no warranty for GDB.  Type \"show warranty\" for details.\n");
1070
1071   /* After the required info we print the configuration information. */
1072
1073   fprintf_filtered (stream, "This GDB was configured as \"");
1074   if (strcmp (host_name, target_name) != 0)
1075     {
1076       fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
1077     }
1078   else
1079     {
1080       fprintf_filtered (stream, "%s", host_name);
1081     }
1082   fprintf_filtered (stream, "\".");
1083 }
1084 \f
1085 /* get_prompt: access method for the GDB prompt string.  */
1086
1087 char *
1088 get_prompt (void)
1089 {
1090   return PROMPT (0);
1091 }
1092
1093 void
1094 set_prompt (char *s)
1095 {
1096 /* ??rehrauer: I don't know why this fails, since it looks as though
1097    assignments to prompt are wrapped in calls to savestring...
1098    if (prompt != NULL)
1099    xfree (prompt);
1100  */
1101   PROMPT (0) = savestring (s, strlen (s));
1102 }
1103 \f
1104
1105 /* If necessary, make the user confirm that we should quit.  Return
1106    non-zero if we should quit, zero if we shouldn't.  */
1107
1108 int
1109 quit_confirm (void)
1110 {
1111   if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
1112     {
1113       char *s;
1114
1115       /* This is something of a hack.  But there's no reliable way to
1116          see if a GUI is running.  The `use_windows' variable doesn't
1117          cut it.  */
1118       if (deprecated_init_ui_hook)
1119         s = "A debugging session is active.\nDo you still want to close the debugger?";
1120       else if (attach_flag)
1121         s = "The program is running.  Quit anyway (and detach it)? ";
1122       else
1123         s = "The program is running.  Exit anyway? ";
1124
1125       if (!query ("%s", s))
1126         return 0;
1127     }
1128
1129   return 1;
1130 }
1131
1132 /* Helper routine for quit_force that requires error handling.  */
1133
1134 struct qt_args
1135 {
1136   char *args;
1137   int from_tty;
1138 };
1139
1140 static int
1141 quit_target (void *arg)
1142 {
1143   struct qt_args *qt = (struct qt_args *)arg;
1144
1145   if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
1146     {
1147       if (attach_flag)
1148         target_detach (qt->args, qt->from_tty);
1149       else
1150         target_kill ();
1151     }
1152
1153   /* UDI wants this, to kill the TIP.  */
1154   target_close (&current_target, 1);
1155
1156   /* Save the history information if it is appropriate to do so.  */
1157   if (write_history_p && history_filename)
1158     write_history (history_filename);
1159
1160   do_final_cleanups (ALL_CLEANUPS);     /* Do any final cleanups before exiting */
1161
1162   return 0;
1163 }
1164
1165 /* Quit without asking for confirmation.  */
1166
1167 void
1168 quit_force (char *args, int from_tty)
1169 {
1170   int exit_code = 0;
1171   struct qt_args qt;
1172
1173   /* An optional expression may be used to cause gdb to terminate with the 
1174      value of that expression. */
1175   if (args)
1176     {
1177       struct value *val = parse_and_eval (args);
1178
1179       exit_code = (int) value_as_long (val);
1180     }
1181
1182   qt.args = args;
1183   qt.from_tty = from_tty;
1184
1185   /* We want to handle any quit errors and exit regardless.  */
1186   catch_errors (quit_target, &qt,
1187                 "Quitting: ", RETURN_MASK_ALL);
1188
1189   exit (exit_code);
1190 }
1191
1192 /* Returns whether GDB is running on a terminal and whether the user
1193    desires that questions be asked of them on that terminal.  */
1194
1195 int
1196 input_from_terminal_p (void)
1197 {
1198   return gdb_has_a_terminal () && (instream == stdin) & caution;
1199 }
1200 \f
1201 static void
1202 dont_repeat_command (char *ignored, int from_tty)
1203 {
1204   *line = 0;                    /* Can't call dont_repeat here because we're not
1205                                    necessarily reading from stdin.  */
1206 }
1207 \f
1208 /* Functions to manipulate command line editing control variables.  */
1209
1210 /* Number of commands to print in each call to show_commands.  */
1211 #define Hist_print 10
1212 void
1213 show_commands (char *args, int from_tty)
1214 {
1215   /* Index for history commands.  Relative to history_base.  */
1216   int offset;
1217
1218   /* Number of the history entry which we are planning to display next.
1219      Relative to history_base.  */
1220   static int num = 0;
1221
1222   /* The first command in the history which doesn't exist (i.e. one more
1223      than the number of the last command).  Relative to history_base.  */
1224   int hist_len;
1225
1226   /* Print out some of the commands from the command history.  */
1227   /* First determine the length of the history list.  */
1228   hist_len = history_size;
1229   for (offset = 0; offset < history_size; offset++)
1230     {
1231       if (!history_get (history_base + offset))
1232         {
1233           hist_len = offset;
1234           break;
1235         }
1236     }
1237
1238   if (args)
1239     {
1240       if (args[0] == '+' && args[1] == '\0')
1241         /* "info editing +" should print from the stored position.  */
1242         ;
1243       else
1244         /* "info editing <exp>" should print around command number <exp>.  */
1245         num = (parse_and_eval_long (args) - history_base) - Hist_print / 2;
1246     }
1247   /* "show commands" means print the last Hist_print commands.  */
1248   else
1249     {
1250       num = hist_len - Hist_print;
1251     }
1252
1253   if (num < 0)
1254     num = 0;
1255
1256   /* If there are at least Hist_print commands, we want to display the last
1257      Hist_print rather than, say, the last 6.  */
1258   if (hist_len - num < Hist_print)
1259     {
1260       num = hist_len - Hist_print;
1261       if (num < 0)
1262         num = 0;
1263     }
1264
1265   for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
1266     {
1267       printf_filtered ("%5d  %s\n", history_base + offset,
1268                        (history_get (history_base + offset))->line);
1269     }
1270
1271   /* The next command we want to display is the next one that we haven't
1272      displayed yet.  */
1273   num += Hist_print;
1274
1275   /* If the user repeats this command with return, it should do what
1276      "show commands +" does.  This is unnecessary if arg is null,
1277      because "show commands +" is not useful after "show commands".  */
1278   if (from_tty && args)
1279     {
1280       args[0] = '+';
1281       args[1] = '\0';
1282     }
1283 }
1284
1285 /* Called by do_setshow_command.  */
1286 static void
1287 set_history_size_command (char *args, int from_tty, struct cmd_list_element *c)
1288 {
1289   if (history_size == INT_MAX)
1290     unstifle_history ();
1291   else if (history_size >= 0)
1292     stifle_history (history_size);
1293   else
1294     {
1295       history_size = INT_MAX;
1296       error (_("History size must be non-negative"));
1297     }
1298 }
1299
1300 void
1301 set_history (char *args, int from_tty)
1302 {
1303   printf_unfiltered (_("\"set history\" must be followed by the name of a history subcommand.\n"));
1304   help_list (sethistlist, "set history ", -1, gdb_stdout);
1305 }
1306
1307 void
1308 show_history (char *args, int from_tty)
1309 {
1310   cmd_show_list (showhistlist, from_tty, "");
1311 }
1312
1313 int info_verbose = 0;           /* Default verbose msgs off */
1314
1315 /* Called by do_setshow_command.  An elaborate joke.  */
1316 void
1317 set_verbose (char *args, int from_tty, struct cmd_list_element *c)
1318 {
1319   char *cmdname = "verbose";
1320   struct cmd_list_element *showcmd;
1321
1322   showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
1323
1324   if (info_verbose)
1325     {
1326       c->doc = "Set verbose printing of informational messages.";
1327       showcmd->doc = "Show verbose printing of informational messages.";
1328     }
1329   else
1330     {
1331       c->doc = "Set verbosity.";
1332       showcmd->doc = "Show verbosity.";
1333     }
1334 }
1335
1336 /* Init the history buffer.  Note that we are called after the init file(s)
1337  * have been read so that the user can change the history file via his
1338  * .gdbinit file (for instance).  The GDBHISTFILE environment variable
1339  * overrides all of this.
1340  */
1341
1342 void
1343 init_history (void)
1344 {
1345   char *tmpenv;
1346
1347   tmpenv = getenv ("HISTSIZE");
1348   if (tmpenv)
1349     history_size = atoi (tmpenv);
1350   else if (!history_size)
1351     history_size = 256;
1352
1353   stifle_history (history_size);
1354
1355   tmpenv = getenv ("GDBHISTFILE");
1356   if (tmpenv)
1357     history_filename = savestring (tmpenv, strlen (tmpenv));
1358   else if (!history_filename)
1359     {
1360       /* We include the current directory so that if the user changes
1361          directories the file written will be the same as the one
1362          that was read.  */
1363 #ifdef __MSDOS__
1364       /* No leading dots in file names are allowed on MSDOS.  */
1365       history_filename = concat (current_directory, "/_gdb_history", NULL);
1366 #else
1367       history_filename = concat (current_directory, "/.gdb_history", NULL);
1368 #endif
1369     }
1370   read_history (history_filename);
1371 }
1372
1373 static void
1374 show_new_async_prompt (struct ui_file *file, int from_tty,
1375                        struct cmd_list_element *c, const char *value)
1376 {
1377   fprintf_filtered (file, _("Gdb's prompt is \"%s\".\n"), value);
1378 }
1379
1380 static void
1381 show_async_command_editing_p (struct ui_file *file, int from_tty,
1382                               struct cmd_list_element *c, const char *value)
1383 {
1384   fprintf_filtered (file, _("\
1385 Editing of command lines as they are typed is %s.\n"),
1386                     value);
1387 }
1388
1389 static void
1390 show_annotation_level (struct ui_file *file, int from_tty,
1391                        struct cmd_list_element *c, const char *value)
1392 {
1393   fprintf_filtered (file, _("Annotation_level is %s.\n"), value);
1394 }
1395
1396 static void
1397 show_exec_done_display_p (struct ui_file *file, int from_tty,
1398                           struct cmd_list_element *c, const char *value)
1399 {
1400   fprintf_filtered (file, _("\
1401 Notification of completion for asynchronous execution commands is %s.\n"),
1402                     value);
1403 }
1404 static void
1405 init_main (void)
1406 {
1407   struct cmd_list_element *c;
1408
1409   /* initialize the prompt stack to a simple "(gdb) " prompt or to
1410      whatever the DEFAULT_PROMPT is.  */
1411   the_prompts.top = 0;
1412   PREFIX (0) = "";
1413   PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
1414   SUFFIX (0) = "";
1415   /* Set things up for annotation_level > 1, if the user ever decides
1416      to use it.  */
1417   async_annotation_suffix = "prompt";
1418   /* Set the variable associated with the setshow prompt command.  */
1419   new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
1420
1421   /* If gdb was started with --annotate=2, this is equivalent to the
1422      user entering the command 'set annotate 2' at the gdb prompt, so
1423      we need to do extra processing.  */
1424   if (annotation_level > 1)
1425     set_async_annotation_level (NULL, 0, NULL);
1426
1427   /* Set the important stuff up for command editing.  */
1428   command_editing_p = 1;
1429   history_expansion_p = 0;
1430   write_history_p = 0;
1431
1432   /* Setup important stuff for command line editing.  */
1433   rl_completion_entry_function = readline_line_completion_function;
1434   rl_completer_word_break_characters = default_word_break_characters ();
1435   rl_completer_quote_characters = get_gdb_completer_quote_characters ();
1436   rl_readline_name = "gdb";
1437   rl_terminal_name = getenv ("TERM");
1438
1439   /* The name for this defun comes from Bash, where it originated.
1440      15 is Control-o, the same binding this function has in Bash.  */
1441   rl_add_defun ("operate-and-get-next", gdb_rl_operate_and_get_next, 15);
1442
1443   add_setshow_string_cmd ("prompt", class_support,
1444                           &new_async_prompt, _("\
1445 Set gdb's prompt"), _("\
1446 Show gdb's prompt"), NULL,
1447                           set_async_prompt,
1448                           show_new_async_prompt,
1449                           &setlist, &showlist);
1450
1451   add_com ("dont-repeat", class_support, dont_repeat_command, _("\
1452 Don't repeat this command.\n\
1453 Primarily used inside of user-defined commands that should not be repeated when\n\
1454 hitting return."));
1455
1456   add_setshow_boolean_cmd ("editing", class_support,
1457                            &async_command_editing_p, _("\
1458 Set editing of command lines as they are typed."), _("\
1459 Show editing of command lines as they are typed."), _("\
1460 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1461 Without an argument, command line editing is enabled.  To edit, use\n\
1462 EMACS-like or VI-like commands like control-P or ESC."),
1463                            set_async_editing_command,
1464                            show_async_command_editing_p,
1465                            &setlist, &showlist);
1466
1467   add_setshow_boolean_cmd ("save", no_class, &write_history_p, _("\
1468 Set saving of the history record on exit."), _("\
1469 Show saving of the history record on exit."), _("\
1470 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
1471 Without an argument, saving is enabled."),
1472                            NULL,
1473                            show_write_history_p,
1474                            &sethistlist, &showhistlist);
1475
1476   add_setshow_integer_cmd ("size", no_class, &history_size, _("\
1477 Set the size of the command history,"), _("\
1478 Show the size of the command history,"), _("\
1479 ie. the number of previous commands to keep a record of."),
1480                            set_history_size_command,
1481                            show_history_size,
1482                            &sethistlist, &showhistlist);
1483
1484   add_setshow_filename_cmd ("filename", no_class, &history_filename, _("\
1485 Set the filename in which to record the command history"), _("\
1486 Show the filename in which to record the command history"), _("\
1487 (the list of previous commands of which a record is kept)."),
1488                             NULL,
1489                             show_history_filename,
1490                             &sethistlist, &showhistlist);
1491
1492   add_setshow_boolean_cmd ("confirm", class_support, &caution, _("\
1493 Set whether to confirm potentially dangerous operations."), _("\
1494 Show whether to confirm potentially dangerous operations."), NULL,
1495                            NULL,
1496                            show_caution,
1497                            &setlist, &showlist);
1498
1499   add_setshow_zinteger_cmd ("annotate", class_obscure, &annotation_level, _("\
1500 Set annotation_level."), _("\
1501 Show annotation_level."), _("\
1502 0 == normal;     1 == fullname (for use when running under emacs)\n\
1503 2 == output annotated suitably for use by programs that control GDB."),
1504                             set_async_annotation_level,
1505                             show_annotation_level,
1506                             &setlist, &showlist);
1507
1508   add_setshow_boolean_cmd ("exec-done-display", class_support,
1509                            &exec_done_display_p, _("\
1510 Set notification of completion for asynchronous execution commands."), _("\
1511 Show notification of completion for asynchronous execution commands."), _("\
1512 Use \"on\" to enable the notification, and \"off\" to disable it."),
1513                            NULL,
1514                            show_exec_done_display_p,
1515                            &setlist, &showlist);
1516 }
1517
1518 void
1519 gdb_init (char *argv0)
1520 {
1521   if (pre_init_ui_hook)
1522     pre_init_ui_hook ();
1523
1524   /* Run the init function of each source file */
1525
1526   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
1527   current_directory = gdb_dirbuf;
1528
1529 #ifdef __MSDOS__
1530   /* Make sure we return to the original directory upon exit, come
1531      what may, since the OS doesn't do that for us.  */
1532   make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory));
1533 #endif
1534
1535   init_cmd_lists ();            /* This needs to be done first */
1536   initialize_targets ();        /* Setup target_terminal macros for utils.c */
1537   initialize_utils ();          /* Make errors and warnings possible */
1538   initialize_all_files ();
1539   initialize_current_architecture ();
1540   init_cli_cmds();
1541   init_main ();                 /* But that omits this file!  Do it now */
1542
1543   async_init_signals ();
1544
1545   /* We need a default language for parsing expressions, so simple things like
1546      "set width 0" won't fail if no language is explicitly set in a config file
1547      or implicitly set by reading an executable during startup. */
1548   set_language (language_c);
1549   expected_language = current_language;         /* don't warn about the change.  */
1550
1551   /* Allow another UI to initialize. If the UI fails to initialize,
1552      and it wants GDB to revert to the CLI, it should clear
1553      deprecated_init_ui_hook.  */
1554   if (deprecated_init_ui_hook)
1555     deprecated_init_ui_hook (argv0);
1556 }