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