]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/top.c
2004-06-25 Chris Demetriou <cgd@broadcom.com>
[thirdparty/binutils-gdb.git] / gdb / top.c
CommitLineData
c906108c 1/* Top level stuff for GDB, the GNU debugger.
a752853e
AC
2
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
0bc2134e 4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
a752853e 5 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
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.
c906108c 13
c5aa993b
JM
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.
c906108c 18
c5aa993b
JM
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. */
c906108c
SS
23
24#include "defs.h"
25#include "gdbcmd.h"
26#include "call-cmds.h"
210661e7
EZ
27#include "cli/cli-cmds.h"
28#include "cli/cli-script.h"
29#include "cli/cli-setshow.h"
18a642a1 30#include "cli/cli-decode.h"
c906108c
SS
31#include "symtab.h"
32#include "inferior.h"
042be3a9 33#include <signal.h>
c906108c
SS
34#include "target.h"
35#include "breakpoint.h"
36#include "gdbtypes.h"
37#include "expression.h"
38#include "value.h"
39#include "language.h"
c5aa993b 40#include "terminal.h" /* For job_control. */
c906108c 41#include "annotate.h"
c5f0f3d0 42#include "completer.h"
c906108c 43#include "top.h"
d4f3574e 44#include "version.h"
210661e7 45#include "serial.h"
d16aafd8 46#include "doublest.h"
f9c696d2 47#include "gdb_assert.h"
c906108c
SS
48
49/* readline include files */
dbda9972
AC
50#include "readline/readline.h"
51#include "readline/history.h"
c906108c
SS
52
53/* readline defines this. */
54#undef savestring
55
56#include <sys/types.h>
c906108c 57
c4093a6a 58#include <setjmp.h>
2acceee2 59
c2c6d25f 60#include "event-top.h"
c906108c
SS
61#include "gdb_string.h"
62#include "gdb_stat.h"
63#include <ctype.h>
8b93c638
JM
64#include "ui-out.h"
65#include "cli-out.h"
c906108c 66
104c1213
JM
67/* Default command line prompt. This is overriden in some configs. */
68
69#ifndef DEFAULT_PROMPT
70#define DEFAULT_PROMPT "(gdb) "
c906108c
SS
71#endif
72
73/* Initialization file name for gdb. This is overridden in some configs. */
74
75#ifndef GDBINIT_FILENAME
76#define GDBINIT_FILENAME ".gdbinit"
77#endif
78char gdbinit[] = GDBINIT_FILENAME;
79
80int inhibit_gdbinit = 0;
81
82/* If nonzero, and GDB has been configured to be able to use windows,
83 attempt to open them upon startup. */
84
f15ab4a7 85int use_windows = 0;
c906108c 86
c906108c
SS
87extern char lang_frame_mismatch_warn[]; /* language.c */
88
89/* Flag for whether we want all the "from_tty" gubbish printed. */
90
c5aa993b 91int caution = 1; /* Default is yes, sigh. */
c906108c 92
c906108c
SS
93/* stdio stream that command input is being read from. Set to stdin normally.
94 Set by source_command to the file we are sourcing. Set to NULL if we are
95 executing a user-defined command or interacting via a GUI. */
96
97FILE *instream;
98
99/* Current working directory. */
100
101char *current_directory;
102
103/* The directory name is actually stored here (usually). */
104char gdb_dirbuf[1024];
105
106/* Function to call before reading a command, if nonzero.
107 The function receives two args: an input stream,
108 and a prompt string. */
109
507f3c78 110void (*window_hook) (FILE *, char *);
c906108c
SS
111
112int epoch_interface;
113int xgdb_verbose;
114
115/* gdb prints this when reading a command interactively */
c5aa993b 116static char *gdb_prompt_string; /* the global prompt string */
c906108c
SS
117
118/* Buffer used for reading command lines, and the size
119 allocated for it so far. */
120
121char *line;
122int linesize = 100;
123
124/* Nonzero if the current command is modified by "server ". This
c2d11a7d 125 affects things like recording into the command history, commands
c906108c
SS
126 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
127 whatever) can issue its own commands and also send along commands
128 from the user, and have the user not notice that the user interface
129 is issuing commands too. */
130int server_command;
131
132/* Baud rate specified for talking to serial target systems. Default
133 is left as -1, so targets can choose their own defaults. */
134/* FIXME: This means that "show remotebaud" and gr_files_info can print -1
135 or (unsigned int)-1. This is a Bad User Interface. */
136
137int baud_rate = -1;
138
139/* Timeout limit for response from target. */
140
ce808e91
AC
141/* The default value has been changed many times over the years. It
142 was originally 5 seconds. But that was thought to be a long time
143 to sit and wait, so it was changed to 2 seconds. That was thought
144 to be plenty unless the connection was going through some terminal
145 server or multiplexer or other form of hairy serial connection.
146
147 In mid-1996, remote_timeout was moved from remote.c to top.c and
148 it began being used in other remote-* targets. It appears that the
149 default was changed to 20 seconds at that time, perhaps because the
85a453d5 150 Renesas E7000 ICE didn't always respond in a timely manner.
ce808e91
AC
151
152 But if 5 seconds is a long time to sit and wait for retransmissions,
153 20 seconds is far worse. This demonstrates the difficulty of using
154 a single variable for all protocol timeouts.
155
156 As remote.c is used much more than remote-e7000.c, it was changed
157 back to 2 seconds in 1999. */
158
159int remote_timeout = 2;
c906108c
SS
160
161/* Non-zero tells remote* modules to output debugging info. */
162
163int remote_debug = 0;
164
43ff13b4
JM
165/* Non-zero means the target is running. Note: this is different from
166 saying that there is an active target and we are stopped at a
167 breakpoint, for instance. This is a real indicator whether the
168 target is off and running, which gdb is doing something else. */
169int target_executing = 0;
170
c906108c
SS
171/* Level of control structure. */
172static int control_level;
173
6dd77b81
RH
174/* Sbrk location on entry to main. Used for statistics only. */
175#ifdef HAVE_SBRK
176char *lim_at_start;
177#endif
178
c906108c
SS
179/* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
180
181#ifndef STOP_SIGNAL
182#ifdef SIGTSTP
183#define STOP_SIGNAL SIGTSTP
a14ed312 184static void stop_sig (int);
c906108c
SS
185#endif
186#endif
187
c906108c
SS
188/* Hooks for alternate command interfaces. */
189
190/* Called after most modules have been initialized, but before taking users
1ad24239
KS
191 command file.
192
193 If the UI fails to initialize and it wants GDB to continue
194 using the default UI, then it should clear this hook before returning. */
c906108c 195
9a4105ab 196void (*deprecated_init_ui_hook) (char *argv0);
7a292a7a
SS
197
198/* This hook is called from within gdb's many mini-event loops which could
199 steal control from a real user interface's event loop. It returns
200 non-zero if the user is requesting a detach, zero otherwise. */
201
507f3c78 202int (*ui_loop_hook) (int);
c906108c
SS
203
204/* Called instead of command_loop at top level. Can be invoked via
b5a2688f 205 throw_exception(). */
c906108c 206
9a4105ab 207void (*deprecated_command_loop_hook) (void);
c906108c
SS
208
209
c906108c
SS
210/* Called from print_frame_info to list the line we stopped in. */
211
9a4105ab
AC
212void (*deprecated_print_frame_info_listing_hook) (struct symtab * s, int line,
213 int stopline, int noerror);
c906108c
SS
214/* Replaces most of query. */
215
9a4105ab 216int (*deprecated_query_hook) (const char *, va_list);
c906108c
SS
217
218/* Replaces most of warning. */
219
9a4105ab 220void (*deprecated_warning_hook) (const char *, va_list);
c906108c 221
9a4105ab
AC
222/* These three functions support getting lines of text from the user.
223 They are used in sequence. First deprecated_readline_begin_hook is
224 called with a text string that might be (for example) a message for
225 the user to type in a sequence of commands to be executed at a
226 breakpoint. If this function calls back to a GUI, it might take
227 this opportunity to pop up a text interaction window with this
228 message. Next, deprecated_readline_hook is called with a prompt
229 that is emitted prior to collecting the user input. It can be
230 called multiple times. Finally, deprecated_readline_end_hook is
231 called to notify the GUI that we are done with the interaction
232 window and it can close it. */
c906108c 233
9a4105ab
AC
234void (*deprecated_readline_begin_hook) (char *, ...);
235char *(*deprecated_readline_hook) (char *);
236void (*deprecated_readline_end_hook) (void);
c906108c
SS
237
238/* Called as appropriate to notify the interface of the specified breakpoint
239 conditions. */
240
9a4105ab
AC
241void (*deprecated_create_breakpoint_hook) (struct breakpoint * bpt);
242void (*deprecated_delete_breakpoint_hook) (struct breakpoint * bpt);
243void (*deprecated_modify_breakpoint_hook) (struct breakpoint * bpt);
c906108c 244
6426a772
JM
245/* Called as appropriate to notify the interface that we have attached
246 to or detached from an already running process. */
247
9a4105ab
AC
248void (*deprecated_attach_hook) (void);
249void (*deprecated_detach_hook) (void);
6426a772 250
c906108c
SS
251/* Called during long calculations to allow GUI to repair window damage, and to
252 check for stop buttons, etc... */
253
9a4105ab 254void (*deprecated_interactive_hook) (void);
c906108c
SS
255
256/* Called when the registers have changed, as a hint to a GUI
257 to minimize window update. */
258
9a4105ab 259void (*deprecated_registers_changed_hook) (void);
c906108c
SS
260
261/* Tell the GUI someone changed the register REGNO. -1 means
262 that the caller does not know which register changed or
c5aa993b 263 that several registers have changed (see value_assign). */
9a4105ab 264void (*deprecated_register_changed_hook) (int regno);
c906108c
SS
265
266/* Tell the GUI someone changed LEN bytes of memory at ADDR */
9a4105ab 267void (*deprecated_memory_changed_hook) (CORE_ADDR addr, int len);
c906108c
SS
268
269/* Called when going to wait for the target. Usually allows the GUI to run
270 while waiting for target events. */
271
9a4105ab
AC
272ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
273 struct target_waitstatus * status);
c906108c
SS
274
275/* Used by UI as a wrapper around command execution. May do various things
276 like enabling/disabling buttons, etc... */
277
9a4105ab
AC
278void (*deprecated_call_command_hook) (struct cmd_list_element * c, char *cmd,
279 int from_tty);
c906108c 280
96baa820
JM
281/* Called after a `set' command has finished. Is only run if the
282 `set' command succeeded. */
283
9a4105ab 284void (*deprecated_set_hook) (struct cmd_list_element * c);
96baa820 285
c906108c
SS
286/* Called when the current thread changes. Argument is thread id. */
287
9a4105ab 288void (*deprecated_context_hook) (int id);
c906108c
SS
289
290/* Takes control from error (). Typically used to prevent longjmps out of the
291 middle of the GUI. Usually used in conjunction with a catch routine. */
292
9a4105ab 293NORETURN void (*deprecated_error_hook) (void) ATTR_NORETURN;
c906108c 294\f
c5aa993b 295
99eeeb0f
ND
296/* One should use catch_errors rather than manipulating these
297 directly. */
c4093a6a
JM
298#if defined(HAVE_SIGSETJMP)
299#define SIGJMP_BUF sigjmp_buf
ae9d9b96
CF
300#define SIGSETJMP(buf) sigsetjmp((buf), 1)
301#define SIGLONGJMP(buf,val) siglongjmp((buf), (val))
c4093a6a
JM
302#else
303#define SIGJMP_BUF jmp_buf
304#define SIGSETJMP(buf) setjmp(buf)
ae9d9b96 305#define SIGLONGJMP(buf,val) longjmp((buf), (val))
c4093a6a
JM
306#endif
307
b5a2688f 308/* Where to go for throw_exception(). */
99eeeb0f 309static SIGJMP_BUF *catch_return;
c906108c 310
99eeeb0f 311/* Return for reason REASON to the nearest containing catch_errors(). */
c906108c 312
c2d11a7d 313NORETURN void
b5a2688f 314throw_exception (enum return_reason reason)
c906108c
SS
315{
316 quit_flag = 0;
317 immediate_quit = 0;
318
319 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
320 I can think of a reason why that is vital, though). */
c5aa993b 321 bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */
c906108c
SS
322
323 disable_current_display ();
324 do_cleanups (ALL_CLEANUPS);
c4093a6a 325 if (event_loop_p && target_can_async_p () && !target_executing)
43ff13b4 326 do_exec_cleanups (ALL_CLEANUPS);
6426a772
JM
327 if (event_loop_p && sync_execution)
328 do_exec_error_cleanups (ALL_CLEANUPS);
c906108c
SS
329
330 if (annotation_level > 1)
331 switch (reason)
332 {
333 case RETURN_QUIT:
334 annotate_quit ();
335 break;
336 case RETURN_ERROR:
337 annotate_error ();
338 break;
339 }
340
99eeeb0f
ND
341 /* Jump to the containing catch_errors() call, communicating REASON
342 to that call via setjmp's return value. Note that REASON can't
343 be zero, by definition in defs.h. */
344
eb2f494a 345 (NORETURN void) SIGLONGJMP (*catch_return, (int) reason);
c906108c
SS
346}
347
f9c696d2
AC
348/* Call FUNC() with args FUNC_UIOUT and FUNC_ARGS, catching any
349 errors. Set FUNC_CAUGHT to an ``enum return_reason'' if the
b5a2688f 350 function is aborted (using throw_exception() or zero if the
f9c696d2
AC
351 function returns normally. Set FUNC_VAL to the value returned by
352 the function or 0 if the function was aborted.
c906108c
SS
353
354 Must not be called with immediate_quit in effect (bad things might
355 happen, say we got a signal in the middle of a memcpy to quit_return).
356 This is an OK restriction; with very few exceptions immediate_quit can
357 be replaced by judicious use of QUIT.
358
359 MASK specifies what to catch; it is normally set to
360 RETURN_MASK_ALL, if for no other reason than that the code which
361 calls catch_errors might not be set up to deal with a quit which
362 isn't caught. But if the code can deal with it, it generally
363 should be RETURN_MASK_ERROR, unless for some reason it is more
364 useful to abort only the portion of the operation inside the
365 catch_errors. Note that quit should return to the command line
366 fairly quickly, even if some further processing is being done. */
367
11cf8741
JM
368/* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
369 error() et.al. could maintain a set of flags that indicate the the
370 current state of each of the longjmp buffers. This would give the
371 longjmp code the chance to detect a longjmp botch (before it gets
372 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
373 code also randomly used a SET_TOP_LEVEL macro that directly
374 initialize the longjmp buffers. */
375
e26cc349 376/* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code
11cf8741
JM
377 be consolidated into a single file instead of being distributed
378 between utils.c and top.c? */
379
f9c696d2
AC
380static void
381catcher (catch_exceptions_ftype *func,
382 struct ui_out *func_uiout,
383 void *func_args,
384 int *func_val,
385 enum return_reason *func_caught,
386 char *errstring,
4fcef00a 387 char **gdberrmsg,
f9c696d2 388 return_mask mask)
c906108c 389{
99eeeb0f
ND
390 SIGJMP_BUF *saved_catch;
391 SIGJMP_BUF catch;
c906108c
SS
392 struct cleanup *saved_cleanup_chain;
393 char *saved_error_pre_print;
394 char *saved_quit_pre_print;
f9c696d2 395 struct ui_out *saved_uiout;
c906108c 396
99eeeb0f
ND
397 /* Return value from SIGSETJMP(): enum return_reason if error or
398 quit caught, 0 otherwise. */
399 int caught;
400
f9c696d2
AC
401 /* Return value from FUNC(): Hopefully non-zero. Explicitly set to
402 zero if an error quit was caught. */
403 int val;
404
99eeeb0f
ND
405 /* Override error/quit messages during FUNC. */
406
c906108c
SS
407 saved_error_pre_print = error_pre_print;
408 saved_quit_pre_print = quit_pre_print;
409
410 if (mask & RETURN_MASK_ERROR)
99eeeb0f 411 error_pre_print = errstring;
c906108c 412 if (mask & RETURN_MASK_QUIT)
99eeeb0f
ND
413 quit_pre_print = errstring;
414
f9c696d2
AC
415 /* Override the global ``struct ui_out'' builder. */
416
417 saved_uiout = uiout;
418 uiout = func_uiout;
419
99eeeb0f
ND
420 /* Prevent error/quit during FUNC from calling cleanups established
421 prior to here. */
422
423 saved_cleanup_chain = save_cleanups ();
424
425 /* Call FUNC, catching error/quit events. */
426
427 saved_catch = catch_return;
428 catch_return = &catch;
429 caught = SIGSETJMP (catch);
430 if (!caught)
f9c696d2 431 val = (*func) (func_uiout, func_args);
7f7e9482 432 else
4fcef00a
JJ
433 {
434 val = 0;
435 /* If caller wants a copy of the low-level error message, make one.
436 This is used in the case of a silent error whereby the caller
437 may optionally want to issue the message. */
438 if (gdberrmsg)
439 *gdberrmsg = error_last_message ();
440 }
99eeeb0f
ND
441 catch_return = saved_catch;
442
e26cc349 443 /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
99eeeb0f 444 clean things up (restoring the cleanup chain) to the state they
e26cc349 445 were just prior to the call. Unfortunately, many FUNC's are not
99eeeb0f
ND
446 that well behaved. This could be fixed by adding either a
447 do_cleanups call (to cover the problem) or an assertion check to
448 detect bad FUNCs code. */
449
f9c696d2
AC
450 /* Restore the cleanup chain, the error/quit messages, and the uiout
451 builder, to their original states. */
c906108c
SS
452
453 restore_cleanups (saved_cleanup_chain);
454
f9c696d2
AC
455 uiout = saved_uiout;
456
c906108c 457 if (mask & RETURN_MASK_QUIT)
99eeeb0f
ND
458 quit_pre_print = saved_quit_pre_print;
459 if (mask & RETURN_MASK_ERROR)
460 error_pre_print = saved_error_pre_print;
461
f9c696d2
AC
462 /* Return normally if no error/quit event occurred or this catcher
463 can handle this exception. The caller analyses the func return
464 values. */
99eeeb0f 465
f9c696d2
AC
466 if (!caught || (mask & RETURN_MASK (caught)))
467 {
468 *func_val = val;
469 *func_caught = caught;
470 return;
471 }
99eeeb0f 472
f9c696d2 473 /* The caller didn't request that the event be caught, relay the
99eeeb0f
ND
474 event to the next containing catch_errors(). */
475
b5a2688f 476 throw_exception (caught);
f9c696d2 477}
99eeeb0f 478
f9c696d2
AC
479int
480catch_exceptions (struct ui_out *uiout,
481 catch_exceptions_ftype *func,
482 void *func_args,
483 char *errstring,
484 return_mask mask)
485{
486 int val;
487 enum return_reason caught;
4fcef00a
JJ
488 catcher (func, uiout, func_args, &val, &caught, errstring, NULL, mask);
489 gdb_assert (val >= 0);
490 gdb_assert (caught <= 0);
491 if (caught < 0)
492 return caught;
493 return val;
494}
495
496int
497catch_exceptions_with_msg (struct ui_out *uiout,
498 catch_exceptions_ftype *func,
499 void *func_args,
500 char *errstring,
501 char **gdberrmsg,
502 return_mask mask)
503{
504 int val;
505 enum return_reason caught;
506 catcher (func, uiout, func_args, &val, &caught, errstring, gdberrmsg, mask);
f9c696d2
AC
507 gdb_assert (val >= 0);
508 gdb_assert (caught <= 0);
509 if (caught < 0)
510 return caught;
511 return val;
512}
99eeeb0f 513
f9c696d2
AC
514struct catch_errors_args
515{
516 catch_errors_ftype *func;
517 void *func_args;
518};
99eeeb0f 519
b9362cc7 520static int
f9c696d2
AC
521do_catch_errors (struct ui_out *uiout, void *data)
522{
523 struct catch_errors_args *args = data;
524 return args->func (args->func_args);
525}
99eeeb0f 526
f9c696d2
AC
527int
528catch_errors (catch_errors_ftype *func, void *func_args, char *errstring,
529 return_mask mask)
530{
531 int val;
532 enum return_reason caught;
533 struct catch_errors_args args;
534 args.func = func;
535 args.func_args = func_args;
4fcef00a
JJ
536 catcher (do_catch_errors, uiout, &args, &val, &caught, errstring,
537 NULL, mask);
f9c696d2
AC
538 if (caught != 0)
539 return 0;
540 return val;
c906108c
SS
541}
542
11cf8741
JM
543struct captured_command_args
544 {
545 catch_command_errors_ftype *command;
546 char *arg;
547 int from_tty;
548 };
549
550static int
551do_captured_command (void *data)
552{
553 struct captured_command_args *context = data;
554 context->command (context->arg, context->from_tty);
555 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
556 isn't needed. Instead an assertion check could be made that
557 simply confirmed that the called function correctly cleaned up
e26cc349 558 after itself. Unfortunately, old code (prior to 1999-11-04) in
11cf8741
JM
559 main.c was calling SET_TOP_LEVEL(), calling the command function,
560 and then *always* calling do_cleanups(). For the moment we
561 remain ``bug compatible'' with that old code.. */
562 do_cleanups (ALL_CLEANUPS);
563 return 1;
564}
565
566int
eb2f494a 567catch_command_errors (catch_command_errors_ftype * command,
11cf8741
JM
568 char *arg, int from_tty, return_mask mask)
569{
570 struct captured_command_args args;
571 args.command = command;
572 args.arg = arg;
573 args.from_tty = from_tty;
574 return catch_errors (do_captured_command, &args, "", mask);
575}
576
577
c906108c
SS
578/* Handler for SIGHUP. */
579
580#ifdef SIGHUP
c906108c
SS
581/* Just a little helper function for disconnect(). */
582
392a587b 583/* NOTE 1999-04-29: This function will be static again, once we modify
cd0fc7c3
SS
584 gdb to use the event loop as the default command loop and we merge
585 event-top.c into this file, top.c */
586/* static */ int
d0c8cdfb 587quit_cover (void *s)
c906108c 588{
c5aa993b
JM
589 caution = 0; /* Throw caution to the wind -- we're exiting.
590 This prevents asking the user dumb questions. */
591 quit_command ((char *) 0, 0);
c906108c
SS
592 return 0;
593}
64cdedad
EZ
594
595static void
596disconnect (int signo)
597{
598 catch_errors (quit_cover, NULL,
599 "Could not kill the program being debugged", RETURN_MASK_ALL);
600 signal (SIGHUP, SIG_DFL);
601 kill (getpid (), SIGHUP);
602}
c906108c
SS
603#endif /* defined SIGHUP */
604\f
605/* Line number we are currently in in a file which is being sourced. */
392a587b 606/* NOTE 1999-04-29: This variable will be static again, once we modify
cd0fc7c3
SS
607 gdb to use the event loop as the default command loop and we merge
608 event-top.c into this file, top.c */
609/* static */ int source_line_number;
c906108c
SS
610
611/* Name of the file we are sourcing. */
392a587b 612/* NOTE 1999-04-29: This variable will be static again, once we modify
cd0fc7c3
SS
613 gdb to use the event loop as the default command loop and we merge
614 event-top.c into this file, top.c */
615/* static */ char *source_file_name;
c906108c
SS
616
617/* Buffer containing the error_pre_print used by the source stuff.
618 Malloc'd. */
392a587b 619/* NOTE 1999-04-29: This variable will be static again, once we modify
cd0fc7c3
SS
620 gdb to use the event loop as the default command loop and we merge
621 event-top.c into this file, top.c */
622/* static */ char *source_error;
c906108c
SS
623static int source_error_allocated;
624
625/* Something to glom on to the start of error_pre_print if source_file_name
626 is set. */
392a587b 627/* NOTE 1999-04-29: This variable will be static again, once we modify
cd0fc7c3
SS
628 gdb to use the event loop as the default command loop and we merge
629 event-top.c into this file, top.c */
630/* static */ char *source_pre_error;
c906108c
SS
631
632/* Clean up on error during a "source" command (or execution of a
633 user-defined command). */
634
d318976c 635void
e41a3b1a 636do_restore_instream_cleanup (void *stream)
c906108c
SS
637{
638 /* Restore the previous input stream. */
639 instream = stream;
640}
641
642/* Read commands from STREAM. */
643void
fba45db2 644read_command_file (FILE *stream)
c906108c
SS
645{
646 struct cleanup *cleanups;
647
e41a3b1a 648 cleanups = make_cleanup (do_restore_instream_cleanup, instream);
c906108c 649 instream = stream;
c5aa993b 650 command_loop ();
c906108c
SS
651 do_cleanups (cleanups);
652}
653\f
507f3c78 654void (*pre_init_ui_hook) (void);
c906108c 655
e41a3b1a
AC
656#ifdef __MSDOS__
657void
658do_chdir_cleanup (void *old_dir)
659{
660 chdir (old_dir);
b8c9b27d 661 xfree (old_dir);
e41a3b1a
AC
662}
663#endif
664
d318976c
FN
665/* Execute the line P as a command.
666 Pass FROM_TTY as second argument to the defining function. */
c906108c 667
d318976c
FN
668void
669execute_command (char *p, int from_tty)
c906108c 670{
52f0bd74
AC
671 struct cmd_list_element *c;
672 enum language flang;
d318976c
FN
673 static int warned = 0;
674 char *line;
67e1e03a 675
d318976c 676 free_all_values ();
c906108c 677
d318976c
FN
678 /* Force cleanup of any alloca areas if using C alloca instead of
679 a builtin alloca. */
680 alloca (0);
c906108c 681
d318976c
FN
682 /* This can happen when command_line_input hits end of file. */
683 if (p == NULL)
684 return;
c906108c 685
d318976c 686 serial_log_command (p);
8b93c638 687
d318976c
FN
688 while (*p == ' ' || *p == '\t')
689 p++;
690 if (*p)
8b93c638 691 {
d318976c
FN
692 char *arg;
693 line = p;
8b93c638 694
d318976c 695 c = lookup_cmd (&p, cmdlist, "", 0, 1);
8b93c638 696
d318976c
FN
697 /* If the target is running, we allow only a limited set of
698 commands. */
699 if (event_loop_p && target_can_async_p () && target_executing)
d8fe84e3
EZ
700 if (strcmp (c->name, "help") != 0
701 && strcmp (c->name, "pwd") != 0
702 && strcmp (c->name, "show") != 0
703 && strcmp (c->name, "stop") != 0)
d318976c 704 error ("Cannot execute this command while the target is running.");
8b93c638 705
d318976c
FN
706 /* Pass null arg rather than an empty one. */
707 arg = *p ? p : 0;
8b93c638 708
9f60d481
AC
709 /* FIXME: cagney/2002-02-02: The c->type test is pretty dodgy
710 while the is_complete_command(cfunc) test is just plain
711 bogus. They should both be replaced by a test of the form
712 c->strip_trailing_white_space_p. */
713 /* NOTE: cagney/2002-02-02: The function.cfunc in the below
714 can't be replaced with func. This is because it is the
715 cfunc, and not the func, that has the value that the
716 is_complete_command hack is testing for. */
717 /* Clear off trailing whitespace, except for set and complete
718 command. */
d318976c
FN
719 if (arg
720 && c->type != set_cmd
bbaca940 721 && !is_complete_command (c))
8b93c638 722 {
d318976c
FN
723 p = arg + strlen (arg) - 1;
724 while (p >= arg && (*p == ' ' || *p == '\t'))
725 p--;
726 *(p + 1) = '\0';
8b93c638
JM
727 }
728
d318976c 729 /* If this command has been pre-hooked, run the hook first. */
5913bcb0 730 execute_cmd_pre_hook (c);
c906108c 731
d318976c
FN
732 if (c->flags & DEPRECATED_WARN_USER)
733 deprecated_cmd_warning (&line);
c906108c 734
d318976c
FN
735 if (c->class == class_user)
736 execute_user_command (c, arg);
737 else if (c->type == set_cmd || c->type == show_cmd)
738 do_setshow_command (arg, from_tty & caution, c);
f436dd25 739 else if (!cmd_func_p (c))
d318976c 740 error ("That is not a command, just a help topic.");
9a4105ab
AC
741 else if (deprecated_call_command_hook)
742 deprecated_call_command_hook (c, arg, from_tty & caution);
d318976c 743 else
f436dd25 744 cmd_func (c, arg, from_tty & caution);
d318976c
FN
745
746 /* If this command has been post-hooked, run the hook last. */
5913bcb0 747 execute_cmd_post_hook (c);
c906108c 748
c906108c
SS
749 }
750
d318976c
FN
751 /* Tell the user if the language has changed (except first time). */
752 if (current_language != expected_language)
c906108c 753 {
d318976c 754 if (language_mode == language_mode_auto)
c906108c 755 {
d318976c 756 language_info (1); /* Print what changed. */
c906108c 757 }
d318976c 758 warned = 0;
c906108c
SS
759 }
760
d318976c
FN
761 /* Warn the user if the working language does not match the
762 language of the current frame. Only warn the user if we are
763 actually running the program, i.e. there is a stack. */
764 /* FIXME: This should be cacheing the frame and only running when
765 the frame changes. */
766
767 if (target_has_stack)
c906108c 768 {
d318976c
FN
769 flang = get_frame_language ();
770 if (!warned
771 && flang != language_unknown
772 && flang != current_language->la_language)
c906108c 773 {
d318976c
FN
774 printf_filtered ("%s\n", lang_frame_mismatch_warn);
775 warned = 1;
c906108c 776 }
c906108c
SS
777 }
778}
779
d318976c
FN
780/* Read commands from `instream' and execute them
781 until end of file or error reading instream. */
c906108c 782
d318976c
FN
783void
784command_loop (void)
c906108c 785{
d318976c
FN
786 struct cleanup *old_chain;
787 char *command;
788 int stdin_is_tty = ISATTY (stdin);
789 long time_at_cmd_start;
790#ifdef HAVE_SBRK
791 long space_at_cmd_start = 0;
792#endif
793 extern int display_time;
794 extern int display_space;
c5aa993b 795
d318976c
FN
796 while (instream && !feof (instream))
797 {
d318976c
FN
798 if (window_hook && instream == stdin)
799 (*window_hook) (instream, get_prompt ());
c906108c 800
d318976c
FN
801 quit_flag = 0;
802 if (instream == stdin && stdin_is_tty)
803 reinitialize_more_filter ();
804 old_chain = make_cleanup (null_cleanup, 0);
c906108c 805
d318976c
FN
806 /* Get a command-line. This calls the readline package. */
807 command = command_line_input (instream == stdin ?
808 get_prompt () : (char *) NULL,
809 instream == stdin, "prompt");
d318976c
FN
810 if (command == 0)
811 return;
c906108c 812
d318976c 813 time_at_cmd_start = get_run_time ();
c906108c 814
d318976c 815 if (display_space)
9e0b60a8 816 {
d318976c 817#ifdef HAVE_SBRK
d318976c 818 char *lim = (char *) sbrk (0);
6dd77b81 819 space_at_cmd_start = lim - lim_at_start;
9e0b60a8 820#endif
d318976c 821 }
9e0b60a8 822
d318976c
FN
823 execute_command (command, instream == stdin);
824 /* Do any commands attached to breakpoint we stopped at. */
825 bpstat_do_actions (&stop_bpstat);
826 do_cleanups (old_chain);
9e0b60a8 827
d318976c 828 if (display_time)
9e0b60a8 829 {
d318976c 830 long cmd_time = get_run_time () - time_at_cmd_start;
9e0b60a8 831
d318976c
FN
832 printf_unfiltered ("Command execution time: %ld.%06ld\n",
833 cmd_time / 1000000, cmd_time % 1000000);
9e0b60a8 834 }
9e0b60a8 835
d318976c 836 if (display_space)
9e0b60a8 837 {
d318976c 838#ifdef HAVE_SBRK
d318976c 839 char *lim = (char *) sbrk (0);
6dd77b81 840 long space_now = lim - lim_at_start;
d318976c
FN
841 long space_diff = space_now - space_at_cmd_start;
842
843 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
844 space_now,
845 (space_diff >= 0 ? '+' : '-'),
846 space_diff);
847#endif
9e0b60a8 848 }
9e0b60a8 849 }
9e0b60a8 850}
9e0b60a8 851
d318976c
FN
852/* Read commands from `instream' and execute them until end of file or
853 error reading instream. This command loop doesnt care about any
854 such things as displaying time and space usage. If the user asks
855 for those, they won't work. */
856void
857simplified_command_loop (char *(*read_input_func) (char *),
858 void (*execute_command_func) (char *, int))
9e0b60a8 859{
d318976c
FN
860 struct cleanup *old_chain;
861 char *command;
862 int stdin_is_tty = ISATTY (stdin);
9e0b60a8 863
d318976c 864 while (instream && !feof (instream))
9e0b60a8 865 {
d318976c
FN
866 quit_flag = 0;
867 if (instream == stdin && stdin_is_tty)
868 reinitialize_more_filter ();
869 old_chain = make_cleanup (null_cleanup, 0);
870
871 /* Get a command-line. */
872 command = (*read_input_func) (instream == stdin ?
873 get_prompt () : (char *) NULL);
9e0b60a8 874
d318976c
FN
875 if (command == 0)
876 return;
9e0b60a8 877
d318976c 878 (*execute_command_func) (command, instream == stdin);
9e0b60a8 879
d318976c
FN
880 /* Do any commands attached to breakpoint we stopped at. */
881 bpstat_do_actions (&stop_bpstat);
9e0b60a8 882
d318976c 883 do_cleanups (old_chain);
c5aa993b 884 }
9e0b60a8 885}
d318976c
FN
886\f
887/* Commands call this if they do not want to be repeated by null lines. */
9e0b60a8 888
d318976c
FN
889void
890dont_repeat (void)
9e0b60a8 891{
d318976c
FN
892 if (server_command)
893 return;
9e0b60a8 894
d318976c
FN
895 /* If we aren't reading from standard input, we are saving the last
896 thing read from stdin in line and don't want to delete it. Null lines
897 won't repeat here in any case. */
898 if (instream == stdin)
899 *line = 0;
9e0b60a8 900}
d318976c
FN
901\f
902/* Read a line from the stream "instream" without command line editing.
9e0b60a8 903
d318976c
FN
904 It prints PROMPT_ARG once at the start.
905 Action is compatible with "readline", e.g. space for the result is
906 malloc'd and should be freed by the caller.
9e0b60a8 907
d318976c
FN
908 A NULL return means end of file. */
909char *
910gdb_readline (char *prompt_arg)
9e0b60a8 911{
d318976c
FN
912 int c;
913 char *result;
914 int input_index = 0;
915 int result_size = 80;
9e0b60a8 916
d318976c 917 if (prompt_arg)
9e0b60a8 918 {
d318976c
FN
919 /* Don't use a _filtered function here. It causes the assumed
920 character position to be off, since the newline we read from
921 the user is not accounted for. */
922 fputs_unfiltered (prompt_arg, gdb_stdout);
9e0b60a8
JM
923 gdb_flush (gdb_stdout);
924 }
925
d318976c 926 result = (char *) xmalloc (result_size);
9e0b60a8
JM
927
928 while (1)
929 {
d318976c
FN
930 /* Read from stdin if we are executing a user defined command.
931 This is the right thing for prompt_for_continue, at least. */
932 c = fgetc (instream ? instream : stdin);
9e0b60a8 933
d318976c 934 if (c == EOF)
9e0b60a8 935 {
d318976c
FN
936 if (input_index > 0)
937 /* The last line does not end with a newline. Return it, and
938 if we are called again fgetc will still return EOF and
939 we'll return NULL then. */
9e0b60a8 940 break;
b8c9b27d 941 xfree (result);
d318976c 942 return NULL;
9e0b60a8 943 }
c5aa993b 944
d318976c
FN
945 if (c == '\n')
946#ifndef CRLF_SOURCE_FILES
947 break;
948#else
9e0b60a8 949 {
d318976c
FN
950 if (input_index > 0 && result[input_index - 1] == '\r')
951 input_index--;
952 break;
9e0b60a8 953 }
d318976c 954#endif
9e0b60a8 955
d318976c
FN
956 result[input_index++] = c;
957 while (input_index >= result_size)
9e0b60a8 958 {
d318976c
FN
959 result_size *= 2;
960 result = (char *) xrealloc (result, result_size);
9e0b60a8 961 }
9e0b60a8
JM
962 }
963
d318976c
FN
964 result[input_index++] = '\0';
965 return result;
9e0b60a8
JM
966}
967
d318976c
FN
968/* Variables which control command line editing and history
969 substitution. These variables are given default values at the end
970 of this file. */
971static int command_editing_p;
972/* NOTE 1999-04-29: This variable will be static again, once we modify
973 gdb to use the event loop as the default command loop and we merge
974 event-top.c into this file, top.c */
975/* static */ int history_expansion_p;
976static int write_history_p;
977static int history_size;
978static char *history_filename;
9e0b60a8 979
b4f5539f
TT
980/* This is like readline(), but it has some gdb-specific behavior.
981 gdb can use readline in both the synchronous and async modes during
982 a single gdb invocation. At the ordinary top-level prompt we might
983 be using the async readline. That means we can't use
984 rl_pre_input_hook, since it doesn't work properly in async mode.
985 However, for a secondary prompt (" >", such as occurs during a
986 `define'), gdb just calls readline() directly, running it in
987 synchronous mode. So for operate-and-get-next to work in this
988 situation, we have to switch the hooks around. That is what
989 gdb_readline_wrapper is for. */
990char *
991gdb_readline_wrapper (char *prompt)
992{
993 /* Set the hook that works in this case. */
994 if (event_loop_p && after_char_processing_hook)
995 {
996 rl_pre_input_hook = (Function *) after_char_processing_hook;
997 after_char_processing_hook = NULL;
998 }
999
1000 return readline (prompt);
1001}
1002
9e0b60a8 1003\f
d318976c
FN
1004#ifdef STOP_SIGNAL
1005static void
1006stop_sig (int signo)
9e0b60a8 1007{
d318976c
FN
1008#if STOP_SIGNAL == SIGTSTP
1009 signal (SIGTSTP, SIG_DFL);
46711df8
MK
1010#if HAVE_SIGPROCMASK
1011 {
1012 sigset_t zero;
1013
1014 sigemptyset (&zero);
1015 sigprocmask (SIG_SETMASK, &zero, 0);
1016 }
1017#elif HAVE_SIGSETMASK
d318976c 1018 sigsetmask (0);
46711df8 1019#endif
d318976c
FN
1020 kill (getpid (), SIGTSTP);
1021 signal (SIGTSTP, stop_sig);
1022#else
1023 signal (STOP_SIGNAL, stop_sig);
1024#endif
1025 printf_unfiltered ("%s", get_prompt ());
1026 gdb_flush (gdb_stdout);
9e0b60a8 1027
d318976c
FN
1028 /* Forget about any previous command -- null line now will do nothing. */
1029 dont_repeat ();
9e0b60a8 1030}
d318976c 1031#endif /* STOP_SIGNAL */
9e0b60a8 1032
d318976c 1033/* Initialize signal handlers. */
64cdedad
EZ
1034static void
1035float_handler (int signo)
1036{
1037 /* This message is based on ANSI C, section 4.7. Note that integer
1038 divide by zero causes this, so "float" is a misnomer. */
1039 signal (SIGFPE, float_handler);
1040 error ("Erroneous arithmetic operation.");
1041}
1042
9e0b60a8 1043static void
d318976c 1044do_nothing (int signo)
9e0b60a8 1045{
d318976c
FN
1046 /* Under System V the default disposition of a signal is reinstated after
1047 the signal is caught and delivered to an application process. On such
1048 systems one must restore the replacement signal handler if one wishes
1049 to continue handling the signal in one's program. On BSD systems this
1050 is not needed but it is harmless, and it simplifies the code to just do
1051 it unconditionally. */
1052 signal (signo, do_nothing);
9e0b60a8
JM
1053}
1054
9e0b60a8 1055static void
d318976c 1056init_signals (void)
9e0b60a8 1057{
d318976c 1058 signal (SIGINT, request_quit);
9e0b60a8 1059
d318976c
FN
1060 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
1061 to the inferior and breakpoints will be ignored. */
1062#ifdef SIGTRAP
1063 signal (SIGTRAP, SIG_DFL);
1064#endif
9e0b60a8 1065
d318976c
FN
1066 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1067 passed to the inferior, which we don't want. It would be
1068 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1069 on BSD4.3 systems using vfork, that can affect the
1070 GDB process as well as the inferior (the signal handling tables
1071 might be in memory, shared between the two). Since we establish
1072 a handler for SIGQUIT, when we call exec it will set the signal
1073 to SIG_DFL for us. */
1074 signal (SIGQUIT, do_nothing);
1075#ifdef SIGHUP
1076 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1077 signal (SIGHUP, disconnect);
1078#endif
1079 signal (SIGFPE, float_handler);
9e0b60a8 1080
d318976c
FN
1081#if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1082 signal (SIGWINCH, SIGWINCH_HANDLER);
1083#endif
9e0b60a8
JM
1084}
1085\f
467d8519
TT
1086/* The current saved history number from operate-and-get-next.
1087 This is -1 if not valid. */
1088static int operate_saved_history = -1;
1089
1090/* This is put on the appropriate hook and helps operate-and-get-next
1091 do its work. */
b9362cc7 1092static void
5ae5f592 1093gdb_rl_operate_and_get_next_completion (void)
467d8519
TT
1094{
1095 int delta = where_history () - operate_saved_history;
1096 /* The `key' argument to rl_get_previous_history is ignored. */
1097 rl_get_previous_history (delta, 0);
1098 operate_saved_history = -1;
1099
1100 /* readline doesn't automatically update the display for us. */
1101 rl_redisplay ();
1102
1103 after_char_processing_hook = NULL;
1104 rl_pre_input_hook = NULL;
1105}
1106
1107/* This is a gdb-local readline command handler. It accepts the
1108 current command line (like RET does) and, if this command was taken
1109 from the history, arranges for the next command in the history to
1110 appear on the command line when the prompt returns.
1111 We ignore the arguments. */
1112static int
1113gdb_rl_operate_and_get_next (int count, int key)
1114{
b5686e99
MK
1115 int where;
1116
467d8519
TT
1117 if (event_loop_p)
1118 {
1119 /* Use the async hook. */
1120 after_char_processing_hook = gdb_rl_operate_and_get_next_completion;
1121 }
1122 else
1123 {
1124 /* This hook only works correctly when we are using the
1125 synchronous readline. */
1126 rl_pre_input_hook = (Function *) gdb_rl_operate_and_get_next_completion;
1127 }
1128
b5686e99
MK
1129 /* Find the current line, and find the next line to use. */
1130 where = where_history();
1131
1132 /* FIXME: kettenis/20020817: max_input_history is renamed into
1133 history_max_entries in readline-4.2. When we do a new readline
1134 import, we should probably change it here too, even though
1135 readline maintains backwards compatibility for now by still
1136 defining max_input_history. */
1137 if ((history_is_stifled () && (history_length >= max_input_history)) ||
1138 (where >= history_length - 1))
1139 operate_saved_history = where;
1140 else
1141 operate_saved_history = where + 1;
1142
467d8519
TT
1143 return rl_newline (1, key);
1144}
1145\f
d318976c
FN
1146/* Read one line from the command input stream `instream'
1147 into the local static buffer `linebuffer' (whose current length
1148 is `linelength').
1149 The buffer is made bigger as necessary.
1150 Returns the address of the start of the line.
9e0b60a8 1151
d318976c 1152 NULL is returned for end of file.
9e0b60a8 1153
d318976c
FN
1154 *If* the instream == stdin & stdin is a terminal, the line read
1155 is copied into the file line saver (global var char *line,
1156 length linesize) so that it can be duplicated.
9e0b60a8 1157
d318976c
FN
1158 This routine either uses fancy command line editing or
1159 simple input as the user has requested. */
10689f25 1160
d318976c
FN
1161char *
1162command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
9e0b60a8 1163{
d318976c
FN
1164 static char *linebuffer = 0;
1165 static unsigned linelength = 0;
52f0bd74 1166 char *p;
d318976c
FN
1167 char *p1;
1168 char *rl;
1169 char *local_prompt = prompt_arg;
1170 char *nline;
1171 char got_eof = 0;
1172
1173 /* The annotation suffix must be non-NULL. */
1174 if (annotation_suffix == NULL)
1175 annotation_suffix = "";
9e0b60a8 1176
d318976c
FN
1177 if (annotation_level > 1 && instream == stdin)
1178 {
1179 local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
1180 + strlen (annotation_suffix) + 40);
1181 if (prompt_arg == NULL)
1182 local_prompt[0] = '\0';
1183 else
1184 strcpy (local_prompt, prompt_arg);
1185 strcat (local_prompt, "\n\032\032");
1186 strcat (local_prompt, annotation_suffix);
1187 strcat (local_prompt, "\n");
1188 }
9e0b60a8 1189
d318976c 1190 if (linebuffer == 0)
9e0b60a8 1191 {
d318976c
FN
1192 linelength = 80;
1193 linebuffer = (char *) xmalloc (linelength);
9e0b60a8 1194 }
9e0b60a8 1195
d318976c 1196 p = linebuffer;
9e0b60a8 1197
d318976c
FN
1198 /* Control-C quits instantly if typed while in this loop
1199 since it should not wait until the user types a newline. */
1200 immediate_quit++;
1201#ifdef STOP_SIGNAL
1202 if (job_control)
73bc900d 1203 {
d318976c
FN
1204 if (event_loop_p)
1205 signal (STOP_SIGNAL, handle_stop_sig);
1206 else
1207 signal (STOP_SIGNAL, stop_sig);
1208 }
1209#endif
1210
1211 while (1)
9e0b60a8 1212 {
d318976c
FN
1213 /* Make sure that all output has been output. Some machines may let
1214 you get away with leaving out some of the gdb_flush, but not all. */
1215 wrap_here ("");
1216 gdb_flush (gdb_stdout);
1217 gdb_flush (gdb_stderr);
1218
1219 if (source_file_name != NULL)
1220 {
1221 ++source_line_number;
1222 sprintf (source_error,
1223 "%s%s:%d: Error in sourced command file:\n",
1224 source_pre_error,
1225 source_file_name,
1226 source_line_number);
1227 error_pre_print = source_error;
1228 }
1229
1230 if (annotation_level > 1 && instream == stdin)
1231 {
306d9ac5
DC
1232 puts_unfiltered ("\n\032\032pre-");
1233 puts_unfiltered (annotation_suffix);
1234 puts_unfiltered ("\n");
d318976c
FN
1235 }
1236
1237 /* Don't use fancy stuff if not talking to stdin. */
9a4105ab 1238 if (deprecated_readline_hook && instream == NULL)
d318976c 1239 {
9a4105ab 1240 rl = (*deprecated_readline_hook) (local_prompt);
d318976c
FN
1241 }
1242 else if (command_editing_p && instream == stdin && ISATTY (instream))
1243 {
b4f5539f 1244 rl = gdb_readline_wrapper (local_prompt);
d318976c 1245 }
9e0b60a8 1246 else
d318976c
FN
1247 {
1248 rl = gdb_readline (local_prompt);
1249 }
9e0b60a8 1250
d318976c
FN
1251 if (annotation_level > 1 && instream == stdin)
1252 {
306d9ac5
DC
1253 puts_unfiltered ("\n\032\032post-");
1254 puts_unfiltered (annotation_suffix);
1255 puts_unfiltered ("\n");
d318976c 1256 }
9e0b60a8 1257
d318976c 1258 if (!rl || rl == (char *) EOF)
9e0b60a8 1259 {
d318976c
FN
1260 got_eof = 1;
1261 break;
9e0b60a8 1262 }
d318976c
FN
1263 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
1264 {
1265 linelength = strlen (rl) + 1 + (p - linebuffer);
1266 nline = (char *) xrealloc (linebuffer, linelength);
1267 p += nline - linebuffer;
1268 linebuffer = nline;
1269 }
1270 p1 = rl;
1271 /* Copy line. Don't copy null at end. (Leaves line alone
1272 if this was just a newline) */
1273 while (*p1)
1274 *p++ = *p1++;
9e0b60a8 1275
b8c9b27d 1276 xfree (rl); /* Allocated in readline. */
9e0b60a8 1277
d318976c
FN
1278 if (p == linebuffer || *(p - 1) != '\\')
1279 break;
9e0b60a8 1280
d318976c
FN
1281 p--; /* Put on top of '\'. */
1282 local_prompt = (char *) 0;
1283 }
9e0b60a8 1284
d318976c
FN
1285#ifdef STOP_SIGNAL
1286 if (job_control)
1287 signal (STOP_SIGNAL, SIG_DFL);
1288#endif
1289 immediate_quit--;
9e0b60a8 1290
d318976c
FN
1291 if (got_eof)
1292 return NULL;
9e0b60a8 1293
d318976c
FN
1294#define SERVER_COMMAND_LENGTH 7
1295 server_command =
1296 (p - linebuffer > SERVER_COMMAND_LENGTH)
bf896cb0 1297 && strncmp (linebuffer, "server ", SERVER_COMMAND_LENGTH) == 0;
d318976c 1298 if (server_command)
9e0b60a8 1299 {
d318976c
FN
1300 /* Note that we don't set `line'. Between this and the check in
1301 dont_repeat, this insures that repeating will still do the
1302 right thing. */
1303 *p = '\0';
1304 return linebuffer + SERVER_COMMAND_LENGTH;
9e0b60a8 1305 }
9e0b60a8 1306
d318976c
FN
1307 /* Do history expansion if that is wished. */
1308 if (history_expansion_p && instream == stdin
1309 && ISATTY (instream))
1310 {
1311 char *history_value;
1312 int expanded;
9e0b60a8 1313
d318976c
FN
1314 *p = '\0'; /* Insert null now. */
1315 expanded = history_expand (linebuffer, &history_value);
1316 if (expanded)
1317 {
1318 /* Print the changes. */
1319 printf_unfiltered ("%s\n", history_value);
9e0b60a8 1320
d318976c
FN
1321 /* If there was an error, call this function again. */
1322 if (expanded < 0)
1323 {
b8c9b27d 1324 xfree (history_value);
d318976c
FN
1325 return command_line_input (prompt_arg, repeat, annotation_suffix);
1326 }
1327 if (strlen (history_value) > linelength)
1328 {
1329 linelength = strlen (history_value) + 1;
1330 linebuffer = (char *) xrealloc (linebuffer, linelength);
1331 }
1332 strcpy (linebuffer, history_value);
1333 p = linebuffer + strlen (linebuffer);
b8c9b27d 1334 xfree (history_value);
d318976c
FN
1335 }
1336 }
9e0b60a8 1337
d318976c
FN
1338 /* If we just got an empty line, and that is supposed
1339 to repeat the previous command, return the value in the
1340 global buffer. */
1341 if (repeat && p == linebuffer)
1342 return line;
1343 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
1344 if (repeat && !*p1)
1345 return line;
9e0b60a8 1346
d318976c 1347 *p = 0;
9e0b60a8 1348
d318976c
FN
1349 /* Add line to history if appropriate. */
1350 if (instream == stdin
1351 && ISATTY (stdin) && *linebuffer)
1352 add_history (linebuffer);
9e0b60a8 1353
d318976c
FN
1354 /* Note: lines consisting solely of comments are added to the command
1355 history. This is useful when you type a command, and then
1356 realize you don't want to execute it quite yet. You can comment
1357 out the command and then later fetch it from the value history
1358 and remove the '#'. The kill ring is probably better, but some
1359 people are in the habit of commenting things out. */
1360 if (*p1 == '#')
1361 *p1 = '\0'; /* Found a comment. */
9e0b60a8 1362
d318976c
FN
1363 /* Save into global buffer if appropriate. */
1364 if (repeat)
1365 {
1366 if (linelength > linesize)
1367 {
1368 line = xrealloc (line, linelength);
1369 linesize = linelength;
1370 }
1371 strcpy (line, linebuffer);
1372 return line;
1373 }
9e0b60a8 1374
d318976c 1375 return linebuffer;
9e0b60a8
JM
1376}
1377\f
1378/* Print the GDB banner. */
1379void
fba45db2 1380print_gdb_version (struct ui_file *stream)
9e0b60a8
JM
1381{
1382 /* From GNU coding standards, first line is meant to be easy for a
1383 program to parse, and is just canonical program name and version
1384 number, which starts after last space. */
1385
1386 fprintf_filtered (stream, "GNU gdb %s\n", version);
1387
1388 /* Second line is a copyright notice. */
1389
0bc2134e 1390 fprintf_filtered (stream, "Copyright 2004 Free Software Foundation, Inc.\n");
9e0b60a8
JM
1391
1392 /* Following the copyright is a brief statement that the program is
1393 free software, that users are free to copy and change it on
1394 certain conditions, that it is covered by the GNU GPL, and that
1395 there is no warranty. */
1396
1397 fprintf_filtered (stream, "\
1398GDB is free software, covered by the GNU General Public License, and you are\n\
1399welcome to change it and/or distribute copies of it under certain conditions.\n\
1400Type \"show copying\" to see the conditions.\n\
1401There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
1402
1403 /* After the required info we print the configuration information. */
1404
1405 fprintf_filtered (stream, "This GDB was configured as \"");
6314a349 1406 if (strcmp (host_name, target_name) != 0)
9e0b60a8
JM
1407 {
1408 fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
1409 }
1410 else
1411 {
1412 fprintf_filtered (stream, "%s", host_name);
1413 }
1414 fprintf_filtered (stream, "\".");
1415}
9e0b60a8
JM
1416\f
1417/* get_prompt: access method for the GDB prompt string. */
1418
9e0b60a8 1419char *
fba45db2 1420get_prompt (void)
9e0b60a8 1421{
7989c619
AC
1422 if (event_loop_p)
1423 return PROMPT (0);
9e0b60a8 1424 else
7989c619 1425 return gdb_prompt_string;
9e0b60a8
JM
1426}
1427
1428void
fba45db2 1429set_prompt (char *s)
9e0b60a8
JM
1430{
1431/* ??rehrauer: I don't know why this fails, since it looks as though
1432 assignments to prompt are wrapped in calls to savestring...
c5aa993b 1433 if (prompt != NULL)
b8c9b27d 1434 xfree (prompt);
c5aa993b 1435 */
6426a772 1436 if (event_loop_p)
9e0b60a8
JM
1437 PROMPT (0) = savestring (s, strlen (s));
1438 else
1439 gdb_prompt_string = savestring (s, strlen (s));
1440}
9e0b60a8 1441\f
c5aa993b 1442
9e0b60a8
JM
1443/* If necessary, make the user confirm that we should quit. Return
1444 non-zero if we should quit, zero if we shouldn't. */
1445
1446int
fba45db2 1447quit_confirm (void)
9e0b60a8 1448{
39f77062 1449 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
9e0b60a8
JM
1450 {
1451 char *s;
1452
1453 /* This is something of a hack. But there's no reliable way to
c5aa993b
JM
1454 see if a GUI is running. The `use_windows' variable doesn't
1455 cut it. */
9a4105ab 1456 if (deprecated_init_ui_hook)
9e0b60a8
JM
1457 s = "A debugging session is active.\nDo you still want to close the debugger?";
1458 else if (attach_flag)
1459 s = "The program is running. Quit anyway (and detach it)? ";
1460 else
1461 s = "The program is running. Exit anyway? ";
1462
306d9ac5 1463 if (!query ("%s", s))
9e0b60a8
JM
1464 return 0;
1465 }
1466
1467 return 1;
1468}
1469
b0abbc58 1470/* Helper routine for quit_force that requires error handling. */
9e0b60a8 1471
b0abbc58 1472struct qt_args
9e0b60a8 1473{
b0abbc58
JJ
1474 char *args;
1475 int from_tty;
1476};
9e0b60a8 1477
b0abbc58
JJ
1478static int
1479quit_target (void *arg)
1480{
1481 struct qt_args *qt = (struct qt_args *)arg;
9e0b60a8 1482
39f77062 1483 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
9e0b60a8
JM
1484 {
1485 if (attach_flag)
b0abbc58 1486 target_detach (qt->args, qt->from_tty);
9e0b60a8 1487 else
b0abbc58 1488 target_kill ();
9e0b60a8
JM
1489 }
1490
1491 /* UDI wants this, to kill the TIP. */
f1c07ab0 1492 target_close (&current_target, 1);
9e0b60a8
JM
1493
1494 /* Save the history information if it is appropriate to do so. */
1495 if (write_history_p && history_filename)
1496 write_history (history_filename);
1497
c5aa993b 1498 do_final_cleanups (ALL_CLEANUPS); /* Do any final cleanups before exiting */
9e0b60a8 1499
b0abbc58
JJ
1500 return 0;
1501}
1502
1503/* Quit without asking for confirmation. */
1504
1505void
1506quit_force (char *args, int from_tty)
1507{
1508 int exit_code = 0;
365c70b1 1509 struct qt_args qt;
b0abbc58
JJ
1510
1511 /* An optional expression may be used to cause gdb to terminate with the
1512 value of that expression. */
1513 if (args)
1514 {
1515 struct value *val = parse_and_eval (args);
1516
1517 exit_code = (int) value_as_long (val);
1518 }
1519
365c70b1
JJ
1520 qt.args = args;
1521 qt.from_tty = from_tty;
1522
b0abbc58 1523 /* We want to handle any quit errors and exit regardless. */
365c70b1 1524 catch_errors (quit_target, &qt,
b0abbc58
JJ
1525 "Quitting: ", RETURN_MASK_ALL);
1526
9e0b60a8
JM
1527 exit (exit_code);
1528}
1529
9e0b60a8
JM
1530/* Returns whether GDB is running on a terminal and whether the user
1531 desires that questions be asked of them on that terminal. */
1532
1533int
fba45db2 1534input_from_terminal_p (void)
9e0b60a8
JM
1535{
1536 return gdb_has_a_terminal () && (instream == stdin) & caution;
1537}
1538\f
9e0b60a8 1539static void
fba45db2 1540dont_repeat_command (char *ignored, int from_tty)
9e0b60a8 1541{
c5aa993b
JM
1542 *line = 0; /* Can't call dont_repeat here because we're not
1543 necessarily reading from stdin. */
9e0b60a8
JM
1544}
1545\f
1546/* Functions to manipulate command line editing control variables. */
1547
1548/* Number of commands to print in each call to show_commands. */
1549#define Hist_print 10
d318976c 1550void
fba45db2 1551show_commands (char *args, int from_tty)
9e0b60a8
JM
1552{
1553 /* Index for history commands. Relative to history_base. */
1554 int offset;
1555
1556 /* Number of the history entry which we are planning to display next.
1557 Relative to history_base. */
1558 static int num = 0;
1559
1560 /* The first command in the history which doesn't exist (i.e. one more
1561 than the number of the last command). Relative to history_base. */
1562 int hist_len;
1563
9e0b60a8
JM
1564 /* Print out some of the commands from the command history. */
1565 /* First determine the length of the history list. */
1566 hist_len = history_size;
1567 for (offset = 0; offset < history_size; offset++)
1568 {
1569 if (!history_get (history_base + offset))
1570 {
1571 hist_len = offset;
1572 break;
1573 }
1574 }
1575
1576 if (args)
1577 {
1578 if (args[0] == '+' && args[1] == '\0')
1579 /* "info editing +" should print from the stored position. */
1580 ;
1581 else
1582 /* "info editing <exp>" should print around command number <exp>. */
0e828ed1 1583 num = (parse_and_eval_long (args) - history_base) - Hist_print / 2;
9e0b60a8
JM
1584 }
1585 /* "show commands" means print the last Hist_print commands. */
1586 else
1587 {
1588 num = hist_len - Hist_print;
1589 }
1590
1591 if (num < 0)
1592 num = 0;
1593
1594 /* If there are at least Hist_print commands, we want to display the last
1595 Hist_print rather than, say, the last 6. */
1596 if (hist_len - num < Hist_print)
1597 {
1598 num = hist_len - Hist_print;
1599 if (num < 0)
1600 num = 0;
1601 }
1602
1603 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
1604 {
1605 printf_filtered ("%5d %s\n", history_base + offset,
c5aa993b 1606 (history_get (history_base + offset))->line);
9e0b60a8
JM
1607 }
1608
1609 /* The next command we want to display is the next one that we haven't
1610 displayed yet. */
1611 num += Hist_print;
1612
1613 /* If the user repeats this command with return, it should do what
1614 "show commands +" does. This is unnecessary if arg is null,
1615 because "show commands +" is not useful after "show commands". */
1616 if (from_tty && args)
1617 {
1618 args[0] = '+';
1619 args[1] = '\0';
1620 }
1621}
1622
1623/* Called by do_setshow_command. */
9e0b60a8 1624static void
fba45db2 1625set_history_size_command (char *args, int from_tty, struct cmd_list_element *c)
9e0b60a8
JM
1626{
1627 if (history_size == INT_MAX)
1628 unstifle_history ();
1629 else if (history_size >= 0)
1630 stifle_history (history_size);
1631 else
1632 {
1633 history_size = INT_MAX;
1634 error ("History size must be non-negative");
1635 }
1636}
1637
d318976c 1638void
fba45db2 1639set_history (char *args, int from_tty)
9e0b60a8
JM
1640{
1641 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
1642 help_list (sethistlist, "set history ", -1, gdb_stdout);
1643}
1644
d318976c 1645void
fba45db2 1646show_history (char *args, int from_tty)
9e0b60a8
JM
1647{
1648 cmd_show_list (showhistlist, from_tty, "");
1649}
1650
1651int info_verbose = 0; /* Default verbose msgs off */
1652
1653/* Called by do_setshow_command. An elaborate joke. */
d318976c 1654void
fba45db2 1655set_verbose (char *args, int from_tty, struct cmd_list_element *c)
9e0b60a8
JM
1656{
1657 char *cmdname = "verbose";
1658 struct cmd_list_element *showcmd;
1659
1660 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
1661
1662 if (info_verbose)
1663 {
1664 c->doc = "Set verbose printing of informational messages.";
1665 showcmd->doc = "Show verbose printing of informational messages.";
1666 }
1667 else
1668 {
1669 c->doc = "Set verbosity.";
1670 showcmd->doc = "Show verbosity.";
1671 }
1672}
1673
9e0b60a8
JM
1674/* Init the history buffer. Note that we are called after the init file(s)
1675 * have been read so that the user can change the history file via his
1676 * .gdbinit file (for instance). The GDBHISTFILE environment variable
1677 * overrides all of this.
1678 */
1679
1680void
fba45db2 1681init_history (void)
9e0b60a8
JM
1682{
1683 char *tmpenv;
1684
1685 tmpenv = getenv ("HISTSIZE");
1686 if (tmpenv)
1687 history_size = atoi (tmpenv);
1688 else if (!history_size)
1689 history_size = 256;
1690
1691 stifle_history (history_size);
1692
1693 tmpenv = getenv ("GDBHISTFILE");
1694 if (tmpenv)
c5aa993b
JM
1695 history_filename = savestring (tmpenv, strlen (tmpenv));
1696 else if (!history_filename)
1697 {
1698 /* We include the current directory so that if the user changes
1699 directories the file written will be the same as the one
1700 that was read. */
a0b3c4fd 1701#ifdef __MSDOS__
eb2f494a
AC
1702 /* No leading dots in file names are allowed on MSDOS. */
1703 history_filename = concat (current_directory, "/_gdb_history", NULL);
a0b3c4fd 1704#else
c5aa993b 1705 history_filename = concat (current_directory, "/.gdb_history", NULL);
a0b3c4fd 1706#endif
c5aa993b 1707 }
9e0b60a8
JM
1708 read_history (history_filename);
1709}
1710
1711static void
fba45db2 1712init_main (void)
9e0b60a8
JM
1713{
1714 struct cmd_list_element *c;
1715
1716 /* If we are running the asynchronous version,
1717 we initialize the prompts differently. */
6426a772 1718 if (!event_loop_p)
9e0b60a8 1719 {
c5aa993b 1720 gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
9e0b60a8
JM
1721 }
1722 else
1723 {
1724 /* initialize the prompt stack to a simple "(gdb) " prompt or to
96baa820 1725 whatever the DEFAULT_PROMPT is. */
9e0b60a8 1726 the_prompts.top = 0;
c5aa993b 1727 PREFIX (0) = "";
c5aa993b 1728 PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
c5aa993b 1729 SUFFIX (0) = "";
9e0b60a8 1730 /* Set things up for annotation_level > 1, if the user ever decides
c5aa993b 1731 to use it. */
9e0b60a8
JM
1732 async_annotation_suffix = "prompt";
1733 /* Set the variable associated with the setshow prompt command. */
1734 new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
0191bed7
EZ
1735
1736 /* If gdb was started with --annotate=2, this is equivalent to
1737 the user entering the command 'set annotate 2' at the gdb
1738 prompt, so we need to do extra processing. */
1739 if (annotation_level > 1)
1740 set_async_annotation_level (NULL, 0, NULL);
9e0b60a8 1741 }
9e0b60a8
JM
1742
1743 /* Set the important stuff up for command editing. */
1744 command_editing_p = 1;
9e0b60a8
JM
1745 history_expansion_p = 0;
1746 write_history_p = 0;
1747
1748 /* Setup important stuff for command line editing. */
38017ce8 1749 rl_completion_entry_function = readline_line_completion_function;
51065942 1750 rl_completer_word_break_characters = default_word_break_characters ();
d318976c 1751 rl_completer_quote_characters = get_gdb_completer_quote_characters ();
9e0b60a8 1752 rl_readline_name = "gdb";
7cb3ec5e 1753 rl_terminal_name = getenv ("TERM");
9e0b60a8 1754
467d8519
TT
1755 /* The name for this defun comes from Bash, where it originated.
1756 15 is Control-o, the same binding this function has in Bash. */
1757 rl_add_defun ("operate-and-get-next", gdb_rl_operate_and_get_next, 15);
1758
9e0b60a8
JM
1759 /* The set prompt command is different depending whether or not the
1760 async version is run. NOTE: this difference is going to
1761 disappear as we make the event loop be the default engine of
1762 gdb. */
6426a772 1763 if (!event_loop_p)
9e0b60a8
JM
1764 {
1765 add_show_from_set
c5aa993b 1766 (add_set_cmd ("prompt", class_support, var_string,
9e0b60a8
JM
1767 (char *) &gdb_prompt_string, "Set gdb's prompt",
1768 &setlist),
1769 &showlist);
1770 }
1771 else
1772 {
c5aa993b
JM
1773 c = add_set_cmd ("prompt", class_support, var_string,
1774 (char *) &new_async_prompt, "Set gdb's prompt",
9e0b60a8
JM
1775 &setlist);
1776 add_show_from_set (c, &showlist);
9f60d481 1777 set_cmd_sfunc (c, set_async_prompt);
9e0b60a8
JM
1778 }
1779
9e0b60a8
JM
1780 add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
1781Primarily used inside of user-defined commands that should not be repeated when\n\
1782hitting return.");
1783
9e0b60a8
JM
1784 /* The set editing command is different depending whether or not the
1785 async version is run. NOTE: this difference is going to disappear
1786 as we make the event loop be the default engine of gdb. */
6426a772 1787 if (!event_loop_p)
9e0b60a8
JM
1788 {
1789 add_show_from_set
c5aa993b 1790 (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
9e0b60a8
JM
1791 "Set editing of command lines as they are typed.\n\
1792Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1793Without an argument, command line editing is enabled. To edit, use\n\
1794EMACS-like or VI-like commands like control-P or ESC.", &setlist),
1795 &showlist);
1796 }
1797 else
1798 {
c5aa993b 1799 c = add_set_cmd ("editing", class_support, var_boolean, (char *) &async_command_editing_p,
9e0b60a8
JM
1800 "Set editing of command lines as they are typed.\n\
1801Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1802Without an argument, command line editing is enabled. To edit, use\n\
1803EMACS-like or VI-like commands like control-P or ESC.", &setlist);
1804
1805 add_show_from_set (c, &showlist);
9f60d481 1806 set_cmd_sfunc (c, set_async_editing_command);
9e0b60a8
JM
1807 }
1808
9e0b60a8 1809 add_show_from_set
c5aa993b
JM
1810 (add_set_cmd ("save", no_class, var_boolean, (char *) &write_history_p,
1811 "Set saving of the history record on exit.\n\
9e0b60a8
JM
1812Use \"on\" to enable the saving, and \"off\" to disable it.\n\
1813Without an argument, saving is enabled.", &sethistlist),
1814 &showhistlist);
1815
c5aa993b 1816 c = add_set_cmd ("size", no_class, var_integer, (char *) &history_size,
d4654627 1817 "Set the size of the command history,\n\
9e0b60a8
JM
1818ie. the number of previous commands to keep a record of.", &sethistlist);
1819 add_show_from_set (c, &showhistlist);
9f60d481 1820 set_cmd_sfunc (c, set_history_size_command);
9e0b60a8 1821
7a1bd56a
EZ
1822 c = add_set_cmd ("filename", no_class, var_filename,
1823 (char *) &history_filename,
1824 "Set the filename in which to record the command history\n\
d4654627 1825(the list of previous commands of which a record is kept).", &sethistlist);
5ba2abeb 1826 set_cmd_completer (c, filename_completer);
7a1bd56a 1827 add_show_from_set (c, &showhistlist);
9e0b60a8
JM
1828
1829 add_show_from_set
1830 (add_set_cmd ("confirm", class_support, var_boolean,
c5aa993b 1831 (char *) &caution,
9e0b60a8
JM
1832 "Set whether to confirm potentially dangerous operations.",
1833 &setlist),
1834 &showlist);
1835
9e0b60a8
JM
1836 /* The set annotate command is different depending whether or not
1837 the async version is run. NOTE: this difference is going to
1838 disappear as we make the event loop be the default engine of
1839 gdb. */
6426a772 1840 if (!event_loop_p)
9e0b60a8 1841 {
c5aa993b
JM
1842 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
1843 (char *) &annotation_level, "Set annotation_level.\n\
9e0b60a8
JM
18440 == normal; 1 == fullname (for use when running under emacs)\n\
18452 == output annotated suitably for use by programs that control GDB.",
1846 &setlist);
1847 c = add_show_from_set (c, &showlist);
1848 }
1849 else
1850 {
c5aa993b
JM
1851 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
1852 (char *) &annotation_level, "Set annotation_level.\n\
9e0b60a8
JM
18530 == normal; 1 == fullname (for use when running under emacs)\n\
18542 == output annotated suitably for use by programs that control GDB.",
c5aa993b 1855 &setlist);
9e0b60a8 1856 add_show_from_set (c, &showlist);
9f60d481 1857 set_cmd_sfunc (c, set_async_annotation_level);
9e0b60a8 1858 }
6426a772 1859 if (event_loop_p)
104c1213
JM
1860 {
1861 add_show_from_set
1862 (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p,
1863 "Set notification of completion for asynchronous execution commands.\n\
1864Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),
1865 &showlist);
1866 }
9e0b60a8 1867}
64cdedad
EZ
1868
1869void
1870gdb_init (char *argv0)
1871{
1872 if (pre_init_ui_hook)
1873 pre_init_ui_hook ();
1874
1875 /* Run the init function of each source file */
1876
1877 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
1878 current_directory = gdb_dirbuf;
1879
1880#ifdef __MSDOS__
1881 /* Make sure we return to the original directory upon exit, come
1882 what may, since the OS doesn't do that for us. */
1883 make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory));
1884#endif
1885
1886 init_cmd_lists (); /* This needs to be done first */
1887 initialize_targets (); /* Setup target_terminal macros for utils.c */
1888 initialize_utils (); /* Make errors and warnings possible */
1889 initialize_all_files ();
1890 initialize_current_architecture ();
1891 init_cli_cmds();
1892 init_main (); /* But that omits this file! Do it now */
1893
1894 /* The signal handling mechanism is different depending whether or
1895 not the async version is run. NOTE: in the future we plan to make
1896 the event loop be the default engine of gdb, and this difference
1897 will disappear. */
1898 if (event_loop_p)
1899 async_init_signals ();
1900 else
1901 init_signals ();
1902
1903 /* We need a default language for parsing expressions, so simple things like
1904 "set width 0" won't fail if no language is explicitly set in a config file
1905 or implicitly set by reading an executable during startup. */
1906 set_language (language_c);
1907 expected_language = current_language; /* don't warn about the change. */
1908
9a4105ab
AC
1909 /* Allow another UI to initialize. If the UI fails to initialize,
1910 and it wants GDB to revert to the CLI, it should clear
1911 deprecated_init_ui_hook. */
1912 if (deprecated_init_ui_hook)
1913 deprecated_init_ui_hook (argv0);
64cdedad 1914}