1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
24 #include "call-cmds.h"
29 #include "breakpoint.h"
31 #include "expression.h"
34 #include "terminal.h" /* For job_control. */
36 #include "completer.h"
40 /* readline include files */
41 #include <readline/readline.h>
42 #include <readline/history.h>
44 /* readline defines this. */
47 #include <sys/types.h>
51 #include "event-top.h"
52 #include "gdb_string.h"
60 /* From completer.c */
62 extern int is_complete_command (void (*func
) (char *args
, int from_tty
));
64 /* From cli/cli-cmds.c */
66 extern void init_cmd_lists (void);
68 extern void init_cli_cmds (void);
70 extern void execute_user_command (struct cmd_list_element
*c
, char *args
);
72 /* From cli/cli-setshow.c */
74 extern void do_setshow_command (char *, int, struct cmd_list_element
*);
76 /* Default command line prompt. This is overriden in some configs. */
78 #ifndef DEFAULT_PROMPT
79 #define DEFAULT_PROMPT "(gdb) "
82 /* Initialization file name for gdb. This is overridden in some configs. */
84 #ifndef GDBINIT_FILENAME
85 #define GDBINIT_FILENAME ".gdbinit"
87 char gdbinit
[] = GDBINIT_FILENAME
;
89 int inhibit_gdbinit
= 0;
91 /* If nonzero, and GDB has been configured to be able to use windows,
92 attempt to open them upon startup. */
96 extern char lang_frame_mismatch_warn
[]; /* language.c */
98 /* Flag for whether we want all the "from_tty" gubbish printed. */
100 int caution
= 1; /* Default is yes, sigh. */
102 /* stdio stream that command input is being read from. Set to stdin normally.
103 Set by source_command to the file we are sourcing. Set to NULL if we are
104 executing a user-defined command or interacting via a GUI. */
108 /* Current working directory. */
110 char *current_directory
;
112 /* The directory name is actually stored here (usually). */
113 char gdb_dirbuf
[1024];
115 /* Function to call before reading a command, if nonzero.
116 The function receives two args: an input stream,
117 and a prompt string. */
119 void (*window_hook
) (FILE *, char *);
124 /* gdb prints this when reading a command interactively */
125 static char *gdb_prompt_string
; /* the global prompt string */
126 extern char *get_prompt (void); /* access function for prompt string */
128 /* Buffer used for reading command lines, and the size
129 allocated for it so far. */
134 /* Nonzero if the current command is modified by "server ". This
135 affects things like recording into the command history, commands
136 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
137 whatever) can issue its own commands and also send along commands
138 from the user, and have the user not notice that the user interface
139 is issuing commands too. */
142 /* Baud rate specified for talking to serial target systems. Default
143 is left as -1, so targets can choose their own defaults. */
144 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
145 or (unsigned int)-1. This is a Bad User Interface. */
149 /* Timeout limit for response from target. */
151 /* The default value has been changed many times over the years. It
152 was originally 5 seconds. But that was thought to be a long time
153 to sit and wait, so it was changed to 2 seconds. That was thought
154 to be plenty unless the connection was going through some terminal
155 server or multiplexer or other form of hairy serial connection.
157 In mid-1996, remote_timeout was moved from remote.c to top.c and
158 it began being used in other remote-* targets. It appears that the
159 default was changed to 20 seconds at that time, perhaps because the
160 Hitachi E7000 ICE didn't always respond in a timely manner.
162 But if 5 seconds is a long time to sit and wait for retransmissions,
163 20 seconds is far worse. This demonstrates the difficulty of using
164 a single variable for all protocol timeouts.
166 As remote.c is used much more than remote-e7000.c, it was changed
167 back to 2 seconds in 1999. */
169 int remote_timeout
= 2;
171 /* Non-zero tells remote* modules to output debugging info. */
173 int remote_debug
= 0;
175 /* Non-zero means the target is running. Note: this is different from
176 saying that there is an active target and we are stopped at a
177 breakpoint, for instance. This is a real indicator whether the
178 target is off and running, which gdb is doing something else. */
179 int target_executing
= 0;
181 /* Level of control structure. */
182 static int control_level
;
184 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
188 #define STOP_SIGNAL SIGTSTP
189 static void stop_sig (int);
193 /* Some System V have job control but not sigsetmask(). */
194 #if !defined (HAVE_SIGSETMASK)
196 #define HAVE_SIGSETMASK 1
198 #define HAVE_SIGSETMASK 0
202 #if 0 == (HAVE_SIGSETMASK)
203 #define sigsetmask(n)
206 /* Hooks for alternate command interfaces. */
208 /* Called after most modules have been initialized, but before taking users
211 void (*init_ui_hook
) (char *argv0
);
213 /* This hook is called from within gdb's many mini-event loops which could
214 steal control from a real user interface's event loop. It returns
215 non-zero if the user is requesting a detach, zero otherwise. */
217 int (*ui_loop_hook
) (int);
219 /* Called instead of command_loop at top level. Can be invoked via
220 return_to_top_level. */
222 void (*command_loop_hook
) (void);
225 /* Called from print_frame_info to list the line we stopped in. */
227 void (*print_frame_info_listing_hook
) (struct symtab
* s
, int line
,
228 int stopline
, int noerror
);
229 /* Replaces most of query. */
231 int (*query_hook
) (const char *, va_list);
233 /* Replaces most of warning. */
235 void (*warning_hook
) (const char *, va_list);
237 /* These three functions support getting lines of text from the user. They
238 are used in sequence. First readline_begin_hook is called with a text
239 string that might be (for example) a message for the user to type in a
240 sequence of commands to be executed at a breakpoint. If this function
241 calls back to a GUI, it might take this opportunity to pop up a text
242 interaction window with this message. Next, readline_hook is called
243 with a prompt that is emitted prior to collecting the user input.
244 It can be called multiple times. Finally, readline_end_hook is called
245 to notify the GUI that we are done with the interaction window and it
248 void (*readline_begin_hook
) (char *, ...);
249 char *(*readline_hook
) (char *);
250 void (*readline_end_hook
) (void);
252 /* Called as appropriate to notify the interface of the specified breakpoint
255 void (*create_breakpoint_hook
) (struct breakpoint
* bpt
);
256 void (*delete_breakpoint_hook
) (struct breakpoint
* bpt
);
257 void (*modify_breakpoint_hook
) (struct breakpoint
* bpt
);
259 /* Called as appropriate to notify the interface that we have attached
260 to or detached from an already running process. */
262 void (*attach_hook
) (void);
263 void (*detach_hook
) (void);
265 /* Called during long calculations to allow GUI to repair window damage, and to
266 check for stop buttons, etc... */
268 void (*interactive_hook
) (void);
270 /* Called when the registers have changed, as a hint to a GUI
271 to minimize window update. */
273 void (*registers_changed_hook
) (void);
275 /* Tell the GUI someone changed the register REGNO. -1 means
276 that the caller does not know which register changed or
277 that several registers have changed (see value_assign). */
278 void (*register_changed_hook
) (int regno
);
280 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
281 void (*memory_changed_hook
) (CORE_ADDR addr
, int len
);
283 /* Called when going to wait for the target. Usually allows the GUI to run
284 while waiting for target events. */
286 ptid_t (*target_wait_hook
) (ptid_t ptid
,
287 struct target_waitstatus
* status
);
289 /* Used by UI as a wrapper around command execution. May do various things
290 like enabling/disabling buttons, etc... */
292 void (*call_command_hook
) (struct cmd_list_element
* c
, char *cmd
,
295 /* Called after a `set' command has finished. Is only run if the
296 `set' command succeeded. */
298 void (*set_hook
) (struct cmd_list_element
* c
);
300 /* Called when the current thread changes. Argument is thread id. */
302 void (*context_hook
) (int id
);
304 /* Takes control from error (). Typically used to prevent longjmps out of the
305 middle of the GUI. Usually used in conjunction with a catch routine. */
307 NORETURN
void (*error_hook
) (void) ATTR_NORETURN
;
310 /* One should use catch_errors rather than manipulating these
312 #if defined(HAVE_SIGSETJMP)
313 #define SIGJMP_BUF sigjmp_buf
314 #define SIGSETJMP(buf) sigsetjmp(buf, 1)
315 #define SIGLONGJMP(buf,val) siglongjmp(buf,val)
317 #define SIGJMP_BUF jmp_buf
318 #define SIGSETJMP(buf) setjmp(buf)
319 #define SIGLONGJMP(buf,val) longjmp(buf,val)
322 /* Where to go for return_to_top_level. */
323 static SIGJMP_BUF
*catch_return
;
325 /* Return for reason REASON to the nearest containing catch_errors(). */
328 return_to_top_level (enum return_reason reason
)
333 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
334 I can think of a reason why that is vital, though). */
335 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
337 disable_current_display ();
338 do_cleanups (ALL_CLEANUPS
);
339 if (event_loop_p
&& target_can_async_p () && !target_executing
)
340 do_exec_cleanups (ALL_CLEANUPS
);
341 if (event_loop_p
&& sync_execution
)
342 do_exec_error_cleanups (ALL_CLEANUPS
);
344 if (annotation_level
> 1)
355 /* Jump to the containing catch_errors() call, communicating REASON
356 to that call via setjmp's return value. Note that REASON can't
357 be zero, by definition in defs.h. */
359 (NORETURN
void) SIGLONGJMP (*catch_return
, (int) reason
);
362 /* Call FUNC with arg ARGS, catching any errors. If there is no
363 error, return the value returned by FUNC. If there is an error,
364 print ERRSTRING, print the specific error message, then return
367 Must not be called with immediate_quit in effect (bad things might
368 happen, say we got a signal in the middle of a memcpy to quit_return).
369 This is an OK restriction; with very few exceptions immediate_quit can
370 be replaced by judicious use of QUIT.
372 MASK specifies what to catch; it is normally set to
373 RETURN_MASK_ALL, if for no other reason than that the code which
374 calls catch_errors might not be set up to deal with a quit which
375 isn't caught. But if the code can deal with it, it generally
376 should be RETURN_MASK_ERROR, unless for some reason it is more
377 useful to abort only the portion of the operation inside the
378 catch_errors. Note that quit should return to the command line
379 fairly quickly, even if some further processing is being done. */
381 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
382 error() et.al. could maintain a set of flags that indicate the the
383 current state of each of the longjmp buffers. This would give the
384 longjmp code the chance to detect a longjmp botch (before it gets
385 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
386 code also randomly used a SET_TOP_LEVEL macro that directly
387 initialize the longjmp buffers. */
389 /* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code
390 be consolidated into a single file instead of being distributed
391 between utils.c and top.c? */
394 catch_errors (catch_errors_ftype
*func
, PTR args
, char *errstring
,
397 SIGJMP_BUF
*saved_catch
;
400 struct cleanup
*saved_cleanup_chain
;
401 char *saved_error_pre_print
;
402 char *saved_quit_pre_print
;
404 /* Return value from SIGSETJMP(): enum return_reason if error or
405 quit caught, 0 otherwise. */
408 /* Override error/quit messages during FUNC. */
410 saved_error_pre_print
= error_pre_print
;
411 saved_quit_pre_print
= quit_pre_print
;
413 if (mask
& RETURN_MASK_ERROR
)
414 error_pre_print
= errstring
;
415 if (mask
& RETURN_MASK_QUIT
)
416 quit_pre_print
= errstring
;
418 /* Prevent error/quit during FUNC from calling cleanups established
421 saved_cleanup_chain
= save_cleanups ();
423 /* Call FUNC, catching error/quit events. */
425 saved_catch
= catch_return
;
426 catch_return
= &catch;
427 caught
= SIGSETJMP (catch);
429 val
= (*func
) (args
);
432 catch_return
= saved_catch
;
434 /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
435 clean things up (restoring the cleanup chain) to the state they
436 were just prior to the call. Unfortunately, many FUNC's are not
437 that well behaved. This could be fixed by adding either a
438 do_cleanups call (to cover the problem) or an assertion check to
439 detect bad FUNCs code. */
441 /* Restore the cleanup chain and error/quit messages to their
444 restore_cleanups (saved_cleanup_chain
);
446 if (mask
& RETURN_MASK_QUIT
)
447 quit_pre_print
= saved_quit_pre_print
;
448 if (mask
& RETURN_MASK_ERROR
)
449 error_pre_print
= saved_error_pre_print
;
451 /* Return normally if no error/quit event occurred. */
456 /* If the caller didn't request that the event be caught, relay the
457 event to the next containing catch_errors(). */
459 if (!(mask
& RETURN_MASK (caught
)))
460 return_to_top_level (caught
);
462 /* Tell the caller that an event was caught.
464 FIXME: nsd/2000-02-22: When MASK is RETURN_MASK_ALL, the caller
465 can't tell what type of event occurred.
467 A possible fix is to add a new interface, catch_event(), that
468 returns enum return_reason after catching an error or a quit.
470 When returning normally, i.e. without catching an error or a
471 quit, catch_event() could return RETURN_NORMAL, which would be
472 added to enum return_reason. FUNC would return information
473 exclusively via ARGS.
475 Alternatively, normal catch_event() could return FUNC's return
476 value. The caller would need to be aware of potential overlap
477 with enum return_reason, which could be publicly restricted to
478 negative values to simplify return value processing in FUNC and
484 struct captured_command_args
486 catch_command_errors_ftype
*command
;
492 do_captured_command (void *data
)
494 struct captured_command_args
*context
= data
;
495 context
->command (context
->arg
, context
->from_tty
);
496 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
497 isn't needed. Instead an assertion check could be made that
498 simply confirmed that the called function correctly cleaned up
499 after itself. Unfortunately, old code (prior to 1999-11-04) in
500 main.c was calling SET_TOP_LEVEL(), calling the command function,
501 and then *always* calling do_cleanups(). For the moment we
502 remain ``bug compatible'' with that old code.. */
503 do_cleanups (ALL_CLEANUPS
);
508 catch_command_errors (catch_command_errors_ftype
* command
,
509 char *arg
, int from_tty
, return_mask mask
)
511 struct captured_command_args args
;
512 args
.command
= command
;
514 args
.from_tty
= from_tty
;
515 return catch_errors (do_captured_command
, &args
, "", mask
);
519 /* Handler for SIGHUP. */
522 /* Just a little helper function for disconnect(). */
524 /* NOTE 1999-04-29: This function will be static again, once we modify
525 gdb to use the event loop as the default command loop and we merge
526 event-top.c into this file, top.c */
530 caution
= 0; /* Throw caution to the wind -- we're exiting.
531 This prevents asking the user dumb questions. */
532 quit_command ((char *) 0, 0);
537 disconnect (int signo
)
539 catch_errors (quit_cover
, NULL
,
540 "Could not kill the program being debugged", RETURN_MASK_ALL
);
541 signal (SIGHUP
, SIG_DFL
);
542 kill (getpid (), SIGHUP
);
544 #endif /* defined SIGHUP */
546 /* Line number we are currently in in a file which is being sourced. */
547 /* NOTE 1999-04-29: This variable will be static again, once we modify
548 gdb to use the event loop as the default command loop and we merge
549 event-top.c into this file, top.c */
550 /* static */ int source_line_number
;
552 /* Name of the file we are sourcing. */
553 /* NOTE 1999-04-29: This variable will be static again, once we modify
554 gdb to use the event loop as the default command loop and we merge
555 event-top.c into this file, top.c */
556 /* static */ char *source_file_name
;
558 /* Buffer containing the error_pre_print used by the source stuff.
560 /* NOTE 1999-04-29: This variable will be static again, once we modify
561 gdb to use the event loop as the default command loop and we merge
562 event-top.c into this file, top.c */
563 /* static */ char *source_error
;
564 static int source_error_allocated
;
566 /* Something to glom on to the start of error_pre_print if source_file_name
568 /* NOTE 1999-04-29: This variable will be static again, once we modify
569 gdb to use the event loop as the default command loop and we merge
570 event-top.c into this file, top.c */
571 /* static */ char *source_pre_error
;
573 /* Clean up on error during a "source" command (or execution of a
574 user-defined command). */
577 do_restore_instream_cleanup (void *stream
)
579 /* Restore the previous input stream. */
583 /* Read commands from STREAM. */
585 read_command_file (FILE *stream
)
587 struct cleanup
*cleanups
;
589 cleanups
= make_cleanup (do_restore_instream_cleanup
, instream
);
592 do_cleanups (cleanups
);
595 extern void init_proc (void);
597 void (*pre_init_ui_hook
) (void);
601 do_chdir_cleanup (void *old_dir
)
608 /* Execute the line P as a command.
609 Pass FROM_TTY as second argument to the defining function. */
612 execute_command (char *p
, int from_tty
)
614 register struct cmd_list_element
*c
;
615 register enum language flang
;
616 static int warned
= 0;
618 /* FIXME: These should really be in an appropriate header file */
619 extern void serial_log_command (const char *);
623 /* Force cleanup of any alloca areas if using C alloca instead of
627 /* This can happen when command_line_input hits end of file. */
631 serial_log_command (p
);
633 while (*p
== ' ' || *p
== '\t')
640 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
642 /* If the target is running, we allow only a limited set of
644 if (event_loop_p
&& target_can_async_p () && target_executing
)
645 if (!strcmp (c
->name
, "help")
646 && !strcmp (c
->name
, "pwd")
647 && !strcmp (c
->name
, "show")
648 && !strcmp (c
->name
, "stop"))
649 error ("Cannot execute this command while the target is running.");
651 /* Pass null arg rather than an empty one. */
654 /* Clear off trailing whitespace, except for set and complete command. */
656 && c
->type
!= set_cmd
657 && !is_complete_command (c
->function
.cfunc
))
659 p
= arg
+ strlen (arg
) - 1;
660 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
665 /* If this command has been pre-hooked, run the hook first. */
666 if ((c
->hook_pre
) && (!c
->hook_in
))
668 c
->hook_in
= 1; /* Prevent recursive hooking */
669 execute_user_command (c
->hook_pre
, (char *) 0);
670 c
->hook_in
= 0; /* Allow hook to work again once it is complete */
673 if (c
->flags
& DEPRECATED_WARN_USER
)
674 deprecated_cmd_warning (&line
);
676 if (c
->class == class_user
)
677 execute_user_command (c
, arg
);
678 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
679 do_setshow_command (arg
, from_tty
& caution
, c
);
680 else if (c
->function
.cfunc
== NO_FUNCTION
)
681 error ("That is not a command, just a help topic.");
682 else if (call_command_hook
)
683 call_command_hook (c
, arg
, from_tty
& caution
);
685 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
687 /* If this command has been post-hooked, run the hook last. */
688 if ((c
->hook_post
) && (!c
->hook_in
))
690 c
->hook_in
= 1; /* Prevent recursive hooking */
691 execute_user_command (c
->hook_post
, (char *) 0);
692 c
->hook_in
= 0; /* allow hook to work again once it is complete */
697 /* Tell the user if the language has changed (except first time). */
698 if (current_language
!= expected_language
)
700 if (language_mode
== language_mode_auto
)
702 language_info (1); /* Print what changed. */
707 /* Warn the user if the working language does not match the
708 language of the current frame. Only warn the user if we are
709 actually running the program, i.e. there is a stack. */
710 /* FIXME: This should be cacheing the frame and only running when
711 the frame changes. */
713 if (target_has_stack
)
715 flang
= get_frame_language ();
717 && flang
!= language_unknown
718 && flang
!= current_language
->la_language
)
720 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
726 /* Read commands from `instream' and execute them
727 until end of file or error reading instream. */
732 struct cleanup
*old_chain
;
734 int stdin_is_tty
= ISATTY (stdin
);
735 long time_at_cmd_start
;
737 long space_at_cmd_start
= 0;
739 extern int display_time
;
740 extern int display_space
;
742 while (instream
&& !feof (instream
))
744 if (window_hook
&& instream
== stdin
)
745 (*window_hook
) (instream
, get_prompt ());
748 if (instream
== stdin
&& stdin_is_tty
)
749 reinitialize_more_filter ();
750 old_chain
= make_cleanup (null_cleanup
, 0);
752 /* Get a command-line. This calls the readline package. */
753 command
= command_line_input (instream
== stdin
?
754 get_prompt () : (char *) NULL
,
755 instream
== stdin
, "prompt");
759 time_at_cmd_start
= get_run_time ();
764 extern char **environ
;
765 char *lim
= (char *) sbrk (0);
767 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
771 execute_command (command
, instream
== stdin
);
772 /* Do any commands attached to breakpoint we stopped at. */
773 bpstat_do_actions (&stop_bpstat
);
774 do_cleanups (old_chain
);
778 long cmd_time
= get_run_time () - time_at_cmd_start
;
780 printf_unfiltered ("Command execution time: %ld.%06ld\n",
781 cmd_time
/ 1000000, cmd_time
% 1000000);
787 extern char **environ
;
788 char *lim
= (char *) sbrk (0);
789 long space_now
= lim
- (char *) &environ
;
790 long space_diff
= space_now
- space_at_cmd_start
;
792 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
794 (space_diff
>= 0 ? '+' : '-'),
801 /* Read commands from `instream' and execute them until end of file or
802 error reading instream. This command loop doesnt care about any
803 such things as displaying time and space usage. If the user asks
804 for those, they won't work. */
806 simplified_command_loop (char *(*read_input_func
) (char *),
807 void (*execute_command_func
) (char *, int))
809 struct cleanup
*old_chain
;
811 int stdin_is_tty
= ISATTY (stdin
);
813 while (instream
&& !feof (instream
))
816 if (instream
== stdin
&& stdin_is_tty
)
817 reinitialize_more_filter ();
818 old_chain
= make_cleanup (null_cleanup
, 0);
820 /* Get a command-line. */
821 command
= (*read_input_func
) (instream
== stdin
?
822 get_prompt () : (char *) NULL
);
827 (*execute_command_func
) (command
, instream
== stdin
);
829 /* Do any commands attached to breakpoint we stopped at. */
830 bpstat_do_actions (&stop_bpstat
);
832 do_cleanups (old_chain
);
836 /* Commands call this if they do not want to be repeated by null lines. */
844 /* If we aren't reading from standard input, we are saving the last
845 thing read from stdin in line and don't want to delete it. Null lines
846 won't repeat here in any case. */
847 if (instream
== stdin
)
851 /* Read a line from the stream "instream" without command line editing.
853 It prints PROMPT_ARG once at the start.
854 Action is compatible with "readline", e.g. space for the result is
855 malloc'd and should be freed by the caller.
857 A NULL return means end of file. */
859 gdb_readline (char *prompt_arg
)
864 int result_size
= 80;
868 /* Don't use a _filtered function here. It causes the assumed
869 character position to be off, since the newline we read from
870 the user is not accounted for. */
871 fputs_unfiltered (prompt_arg
, gdb_stdout
);
872 /* OBSOLETE #ifdef MPW */
873 /* OBSOLETE Move to a new line so the entered line doesn't have a prompt */
874 /* OBSOLETE on the front of it. */
875 /* OBSOLETE fputs_unfiltered ("\n", gdb_stdout); */
876 /* OBSOLETE #endif *//* MPW */
877 gdb_flush (gdb_stdout
);
880 result
= (char *) xmalloc (result_size
);
884 /* Read from stdin if we are executing a user defined command.
885 This is the right thing for prompt_for_continue, at least. */
886 c
= fgetc (instream
? instream
: stdin
);
891 /* The last line does not end with a newline. Return it, and
892 if we are called again fgetc will still return EOF and
893 we'll return NULL then. */
900 #ifndef CRLF_SOURCE_FILES
904 if (input_index
> 0 && result
[input_index
- 1] == '\r')
910 result
[input_index
++] = c
;
911 while (input_index
>= result_size
)
914 result
= (char *) xrealloc (result
, result_size
);
918 result
[input_index
++] = '\0';
922 /* Variables which control command line editing and history
923 substitution. These variables are given default values at the end
925 static int command_editing_p
;
926 /* NOTE 1999-04-29: This variable will be static again, once we modify
927 gdb to use the event loop as the default command loop and we merge
928 event-top.c into this file, top.c */
929 /* static */ int history_expansion_p
;
930 static int write_history_p
;
931 static int history_size
;
932 static char *history_filename
;
939 #if STOP_SIGNAL == SIGTSTP
940 signal (SIGTSTP
, SIG_DFL
);
942 kill (getpid (), SIGTSTP
);
943 signal (SIGTSTP
, stop_sig
);
945 signal (STOP_SIGNAL
, stop_sig
);
947 printf_unfiltered ("%s", get_prompt ());
948 gdb_flush (gdb_stdout
);
950 /* Forget about any previous command -- null line now will do nothing. */
953 #endif /* STOP_SIGNAL */
955 /* Initialize signal handlers. */
957 float_handler (int signo
)
959 /* This message is based on ANSI C, section 4.7. Note that integer
960 divide by zero causes this, so "float" is a misnomer. */
961 signal (SIGFPE
, float_handler
);
962 error ("Erroneous arithmetic operation.");
966 do_nothing (int signo
)
968 /* Under System V the default disposition of a signal is reinstated after
969 the signal is caught and delivered to an application process. On such
970 systems one must restore the replacement signal handler if one wishes
971 to continue handling the signal in one's program. On BSD systems this
972 is not needed but it is harmless, and it simplifies the code to just do
973 it unconditionally. */
974 signal (signo
, do_nothing
);
980 signal (SIGINT
, request_quit
);
982 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
983 to the inferior and breakpoints will be ignored. */
985 signal (SIGTRAP
, SIG_DFL
);
988 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
989 passed to the inferior, which we don't want. It would be
990 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
991 on BSD4.3 systems using vfork, that can affect the
992 GDB process as well as the inferior (the signal handling tables
993 might be in memory, shared between the two). Since we establish
994 a handler for SIGQUIT, when we call exec it will set the signal
995 to SIG_DFL for us. */
996 signal (SIGQUIT
, do_nothing
);
998 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
999 signal (SIGHUP
, disconnect
);
1001 signal (SIGFPE
, float_handler
);
1003 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1004 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1008 /* Read one line from the command input stream `instream'
1009 into the local static buffer `linebuffer' (whose current length
1011 The buffer is made bigger as necessary.
1012 Returns the address of the start of the line.
1014 NULL is returned for end of file.
1016 *If* the instream == stdin & stdin is a terminal, the line read
1017 is copied into the file line saver (global var char *line,
1018 length linesize) so that it can be duplicated.
1020 This routine either uses fancy command line editing or
1021 simple input as the user has requested. */
1024 command_line_input (char *prompt_arg
, int repeat
, char *annotation_suffix
)
1026 static char *linebuffer
= 0;
1027 static unsigned linelength
= 0;
1031 char *local_prompt
= prompt_arg
;
1035 /* The annotation suffix must be non-NULL. */
1036 if (annotation_suffix
== NULL
)
1037 annotation_suffix
= "";
1039 if (annotation_level
> 1 && instream
== stdin
)
1041 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
1042 + strlen (annotation_suffix
) + 40);
1043 if (prompt_arg
== NULL
)
1044 local_prompt
[0] = '\0';
1046 strcpy (local_prompt
, prompt_arg
);
1047 strcat (local_prompt
, "\n\032\032");
1048 strcat (local_prompt
, annotation_suffix
);
1049 strcat (local_prompt
, "\n");
1052 if (linebuffer
== 0)
1055 linebuffer
= (char *) xmalloc (linelength
);
1060 /* Control-C quits instantly if typed while in this loop
1061 since it should not wait until the user types a newline. */
1067 signal (STOP_SIGNAL
, handle_stop_sig
);
1069 signal (STOP_SIGNAL
, stop_sig
);
1075 /* Make sure that all output has been output. Some machines may let
1076 you get away with leaving out some of the gdb_flush, but not all. */
1078 gdb_flush (gdb_stdout
);
1079 gdb_flush (gdb_stderr
);
1081 if (source_file_name
!= NULL
)
1083 ++source_line_number
;
1084 sprintf (source_error
,
1085 "%s%s:%d: Error in sourced command file:\n",
1088 source_line_number
);
1089 error_pre_print
= source_error
;
1092 if (annotation_level
> 1 && instream
== stdin
)
1094 printf_unfiltered ("\n\032\032pre-");
1095 printf_unfiltered (annotation_suffix
);
1096 printf_unfiltered ("\n");
1099 /* Don't use fancy stuff if not talking to stdin. */
1100 if (readline_hook
&& instream
== NULL
)
1102 rl
= (*readline_hook
) (local_prompt
);
1104 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
1106 rl
= readline (local_prompt
);
1110 rl
= gdb_readline (local_prompt
);
1113 if (annotation_level
> 1 && instream
== stdin
)
1115 printf_unfiltered ("\n\032\032post-");
1116 printf_unfiltered (annotation_suffix
);
1117 printf_unfiltered ("\n");
1120 if (!rl
|| rl
== (char *) EOF
)
1125 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
1127 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
1128 nline
= (char *) xrealloc (linebuffer
, linelength
);
1129 p
+= nline
- linebuffer
;
1133 /* Copy line. Don't copy null at end. (Leaves line alone
1134 if this was just a newline) */
1138 xfree (rl
); /* Allocated in readline. */
1140 if (p
== linebuffer
|| *(p
- 1) != '\\')
1143 p
--; /* Put on top of '\'. */
1144 local_prompt
= (char *) 0;
1149 signal (STOP_SIGNAL
, SIG_DFL
);
1156 #define SERVER_COMMAND_LENGTH 7
1158 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
1159 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
1162 /* Note that we don't set `line'. Between this and the check in
1163 dont_repeat, this insures that repeating will still do the
1166 return linebuffer
+ SERVER_COMMAND_LENGTH
;
1169 /* Do history expansion if that is wished. */
1170 if (history_expansion_p
&& instream
== stdin
1171 && ISATTY (instream
))
1173 char *history_value
;
1176 *p
= '\0'; /* Insert null now. */
1177 expanded
= history_expand (linebuffer
, &history_value
);
1180 /* Print the changes. */
1181 printf_unfiltered ("%s\n", history_value
);
1183 /* If there was an error, call this function again. */
1186 xfree (history_value
);
1187 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
1189 if (strlen (history_value
) > linelength
)
1191 linelength
= strlen (history_value
) + 1;
1192 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1194 strcpy (linebuffer
, history_value
);
1195 p
= linebuffer
+ strlen (linebuffer
);
1196 xfree (history_value
);
1200 /* If we just got an empty line, and that is supposed
1201 to repeat the previous command, return the value in the
1203 if (repeat
&& p
== linebuffer
)
1205 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
1211 /* Add line to history if appropriate. */
1212 if (instream
== stdin
1213 && ISATTY (stdin
) && *linebuffer
)
1214 add_history (linebuffer
);
1216 /* Note: lines consisting solely of comments are added to the command
1217 history. This is useful when you type a command, and then
1218 realize you don't want to execute it quite yet. You can comment
1219 out the command and then later fetch it from the value history
1220 and remove the '#'. The kill ring is probably better, but some
1221 people are in the habit of commenting things out. */
1223 *p1
= '\0'; /* Found a comment. */
1225 /* Save into global buffer if appropriate. */
1228 if (linelength
> linesize
)
1230 line
= xrealloc (line
, linelength
);
1231 linesize
= linelength
;
1233 strcpy (line
, linebuffer
);
1240 /* Print the GDB banner. */
1242 print_gdb_version (struct ui_file
*stream
)
1244 /* From GNU coding standards, first line is meant to be easy for a
1245 program to parse, and is just canonical program name and version
1246 number, which starts after last space. */
1249 /* Print it console style until a format is defined */
1250 fprintf_filtered (stream
, "GNU gdb %s (MI_OUT)\n", version
);
1252 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
1255 /* Second line is a copyright notice. */
1257 fprintf_filtered (stream
, "Copyright 2001 Free Software Foundation, Inc.\n");
1259 /* Following the copyright is a brief statement that the program is
1260 free software, that users are free to copy and change it on
1261 certain conditions, that it is covered by the GNU GPL, and that
1262 there is no warranty. */
1264 fprintf_filtered (stream
, "\
1265 GDB is free software, covered by the GNU General Public License, and you are\n\
1266 welcome to change it and/or distribute copies of it under certain conditions.\n\
1267 Type \"show copying\" to see the conditions.\n\
1268 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
1270 /* After the required info we print the configuration information. */
1272 fprintf_filtered (stream
, "This GDB was configured as \"");
1273 if (!STREQ (host_name
, target_name
))
1275 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
1279 fprintf_filtered (stream
, "%s", host_name
);
1281 fprintf_filtered (stream
, "\".");
1284 /* get_prompt: access method for the GDB prompt string. */
1286 #define MAX_PROMPT_SIZE 256
1289 * int get_prompt_1 (char * buf);
1291 * Work-horse for get_prompt (called via catch_errors).
1292 * Argument is buffer to hold the formatted prompt.
1294 * Returns: 1 for success (use formatted prompt)
1295 * 0 for failure (use gdb_prompt_string).
1298 static int gdb_prompt_escape
;
1301 get_prompt_1 (void *data
)
1303 char *formatted_prompt
= data
;
1307 local_prompt
= PROMPT (0);
1309 local_prompt
= gdb_prompt_string
;
1312 if (gdb_prompt_escape
== 0)
1314 return 0; /* do no formatting */
1317 /* formatted prompt */
1319 char fmt
[40], *promptp
, *outp
, *tmp
;
1326 struct type
*arg_type
, *elt_type
;
1328 promptp
= local_prompt
;
1329 outp
= formatted_prompt
;
1331 while (*promptp
!= '\0')
1333 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
1335 if (*promptp
!= gdb_prompt_escape
)
1337 if (available
>= 1) /* overflow protect */
1338 *outp
++ = *promptp
++;
1342 /* GDB prompt string contains escape char. Parse for arg.
1343 Two consecutive escape chars followed by arg followed by
1344 a comma means to insert the arg using a default format.
1345 Otherwise a printf format string may be included between
1346 the two escape chars. eg:
1347 %%foo, insert foo using default format
1348 %2.2f%foo, insert foo using "%2.2f" format
1349 A mismatch between the format string and the data type
1350 of "foo" is an error (which we don't know how to protect
1353 fmt
[0] = '\0'; /* assume null format string */
1354 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
1356 promptp
+= 2; /* skip past two escape chars. */
1360 /* extract format string from between two esc chars */
1364 fmt
[i
++] = *promptp
++; /* copy format string */
1366 while (i
< sizeof (fmt
) - 1 &&
1367 *promptp
!= gdb_prompt_escape
&&
1370 if (*promptp
!= gdb_prompt_escape
)
1371 error ("Syntax error at prompt position %d",
1372 promptp
- local_prompt
);
1375 promptp
++; /* skip second escape char */
1376 fmt
[i
++] = '\0'; /* terminate the format string */
1380 arg_val
= parse_to_comma_and_eval (&promptp
);
1381 if (*promptp
== ',')
1382 promptp
++; /* skip past the comma */
1383 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
1384 switch (TYPE_CODE (arg_type
))
1386 case TYPE_CODE_ARRAY
:
1387 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
1388 if (TYPE_LENGTH (arg_type
) > 0 &&
1389 TYPE_LENGTH (elt_type
) == 1 &&
1390 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
1392 int len
= TYPE_LENGTH (arg_type
);
1394 if (VALUE_LAZY (arg_val
))
1395 value_fetch_lazy (arg_val
);
1396 tmp
= VALUE_CONTENTS (arg_val
);
1398 if (len
> available
)
1399 len
= available
; /* overflow protect */
1401 /* FIXME: how to protect GDB from crashing
1402 from bad user-supplied format string? */
1404 sprintf (outp
, fmt
, tmp
);
1406 strncpy (outp
, tmp
, len
);
1411 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
1412 addrval
= value_as_pointer (arg_val
);
1414 if (TYPE_LENGTH (elt_type
) == 1 &&
1415 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
1418 /* display it as a string */
1419 char *default_fmt
= "%s";
1423 /* Limiting the number of bytes that the following call
1424 will read protects us from sprintf overflow later. */
1425 i
= target_read_string (addrval
, /* src */
1427 available
, /* len */
1429 if (err
) /* read failed */
1430 error ("%s on target_read", safe_strerror (err
));
1432 tmp
[i
] = '\0'; /* force-terminate string */
1433 /* FIXME: how to protect GDB from crashing
1434 from bad user-supplied format string? */
1435 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1441 /* display it as a pointer */
1442 char *default_fmt
= "0x%x";
1444 /* FIXME: how to protect GDB from crashing
1445 from bad user-supplied format string? */
1446 if (available
>= 16 /*? */ ) /* overflow protect */
1447 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1453 char *default_fmt
= "%g";
1455 doubleval
= value_as_double (arg_val
);
1456 /* FIXME: how to protect GDB from crashing
1457 from bad user-supplied format string? */
1458 if (available
>= 16 /*? */ ) /* overflow protect */
1459 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1460 (double) doubleval
);
1465 char *default_fmt
= "%d";
1467 longval
= value_as_long (arg_val
);
1468 /* FIXME: how to protect GDB from crashing
1469 from bad user-supplied format string? */
1470 if (available
>= 16 /*? */ ) /* overflow protect */
1471 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1475 case TYPE_CODE_BOOL
:
1477 /* no default format for bool */
1478 longval
= value_as_long (arg_val
);
1479 if (available
>= 8 /*? */ ) /* overflow protect */
1482 strcpy (outp
, "<true>");
1484 strcpy (outp
, "<false>");
1488 case TYPE_CODE_ENUM
:
1490 /* no default format for enum */
1491 longval
= value_as_long (arg_val
);
1492 len
= TYPE_NFIELDS (arg_type
);
1493 /* find enum name if possible */
1494 for (i
= 0; i
< len
; i
++)
1495 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
1496 break; /* match -- end loop */
1498 if (i
< len
) /* enum name found */
1500 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
1502 strncpy (outp
, name
, available
);
1503 /* in casel available < strlen (name), */
1504 outp
[available
] = '\0';
1508 if (available
>= 16 /*? */ ) /* overflow protect */
1509 sprintf (outp
, "%ld", (long) longval
);
1513 case TYPE_CODE_VOID
:
1515 break; /* void type -- no output */
1517 error ("bad data type at prompt position %d",
1518 promptp
- local_prompt
);
1521 outp
+= strlen (outp
);
1524 *outp
++ = '\0'; /* terminate prompt string */
1532 static char buf
[MAX_PROMPT_SIZE
];
1534 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
1537 return &buf
[0]; /* successful formatted prompt */
1541 /* Prompt could not be formatted. */
1545 return gdb_prompt_string
;
1550 set_prompt (char *s
)
1552 /* ??rehrauer: I don't know why this fails, since it looks as though
1553 assignments to prompt are wrapped in calls to savestring...
1558 PROMPT (0) = savestring (s
, strlen (s
));
1560 gdb_prompt_string
= savestring (s
, strlen (s
));
1564 /* If necessary, make the user confirm that we should quit. Return
1565 non-zero if we should quit, zero if we shouldn't. */
1570 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
1574 /* This is something of a hack. But there's no reliable way to
1575 see if a GUI is running. The `use_windows' variable doesn't
1578 s
= "A debugging session is active.\nDo you still want to close the debugger?";
1579 else if (attach_flag
)
1580 s
= "The program is running. Quit anyway (and detach it)? ";
1582 s
= "The program is running. Exit anyway? ";
1591 /* Quit without asking for confirmation. */
1594 quit_force (char *args
, int from_tty
)
1598 /* An optional expression may be used to cause gdb to terminate with the
1599 value of that expression. */
1602 value_ptr val
= parse_and_eval (args
);
1604 exit_code
= (int) value_as_long (val
);
1607 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
1610 target_detach (args
, from_tty
);
1615 /* UDI wants this, to kill the TIP. */
1618 /* Save the history information if it is appropriate to do so. */
1619 if (write_history_p
&& history_filename
)
1620 write_history (history_filename
);
1622 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
1627 /* Returns whether GDB is running on a terminal and whether the user
1628 desires that questions be asked of them on that terminal. */
1631 input_from_terminal_p (void)
1633 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
1638 dont_repeat_command (char *ignored
, int from_tty
)
1640 *line
= 0; /* Can't call dont_repeat here because we're not
1641 necessarily reading from stdin. */
1644 /* Functions to manipulate command line editing control variables. */
1646 /* Number of commands to print in each call to show_commands. */
1647 #define Hist_print 10
1649 show_commands (char *args
, int from_tty
)
1651 /* Index for history commands. Relative to history_base. */
1654 /* Number of the history entry which we are planning to display next.
1655 Relative to history_base. */
1658 /* The first command in the history which doesn't exist (i.e. one more
1659 than the number of the last command). Relative to history_base. */
1662 extern HIST_ENTRY
*history_get (int);
1664 /* Print out some of the commands from the command history. */
1665 /* First determine the length of the history list. */
1666 hist_len
= history_size
;
1667 for (offset
= 0; offset
< history_size
; offset
++)
1669 if (!history_get (history_base
+ offset
))
1678 if (args
[0] == '+' && args
[1] == '\0')
1679 /* "info editing +" should print from the stored position. */
1682 /* "info editing <exp>" should print around command number <exp>. */
1683 num
= (parse_and_eval_long (args
) - history_base
) - Hist_print
/ 2;
1685 /* "show commands" means print the last Hist_print commands. */
1688 num
= hist_len
- Hist_print
;
1694 /* If there are at least Hist_print commands, we want to display the last
1695 Hist_print rather than, say, the last 6. */
1696 if (hist_len
- num
< Hist_print
)
1698 num
= hist_len
- Hist_print
;
1703 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
1705 printf_filtered ("%5d %s\n", history_base
+ offset
,
1706 (history_get (history_base
+ offset
))->line
);
1709 /* The next command we want to display is the next one that we haven't
1713 /* If the user repeats this command with return, it should do what
1714 "show commands +" does. This is unnecessary if arg is null,
1715 because "show commands +" is not useful after "show commands". */
1716 if (from_tty
&& args
)
1723 /* Called by do_setshow_command. */
1726 set_history_size_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
1728 if (history_size
== INT_MAX
)
1729 unstifle_history ();
1730 else if (history_size
>= 0)
1731 stifle_history (history_size
);
1734 history_size
= INT_MAX
;
1735 error ("History size must be non-negative");
1741 set_history (char *args
, int from_tty
)
1743 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
1744 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
1749 show_history (char *args
, int from_tty
)
1751 cmd_show_list (showhistlist
, from_tty
, "");
1754 int info_verbose
= 0; /* Default verbose msgs off */
1756 /* Called by do_setshow_command. An elaborate joke. */
1759 set_verbose (char *args
, int from_tty
, struct cmd_list_element
*c
)
1761 char *cmdname
= "verbose";
1762 struct cmd_list_element
*showcmd
;
1764 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
1768 c
->doc
= "Set verbose printing of informational messages.";
1769 showcmd
->doc
= "Show verbose printing of informational messages.";
1773 c
->doc
= "Set verbosity.";
1774 showcmd
->doc
= "Show verbosity.";
1778 /* Init the history buffer. Note that we are called after the init file(s)
1779 * have been read so that the user can change the history file via his
1780 * .gdbinit file (for instance). The GDBHISTFILE environment variable
1781 * overrides all of this.
1789 tmpenv
= getenv ("HISTSIZE");
1791 history_size
= atoi (tmpenv
);
1792 else if (!history_size
)
1795 stifle_history (history_size
);
1797 tmpenv
= getenv ("GDBHISTFILE");
1799 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
1800 else if (!history_filename
)
1802 /* We include the current directory so that if the user changes
1803 directories the file written will be the same as the one
1806 /* No leading dots in file names are allowed on MSDOS. */
1807 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
1809 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
1812 read_history (history_filename
);
1818 struct cmd_list_element
*c
;
1820 /* If we are running the asynchronous version,
1821 we initialize the prompts differently. */
1824 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
1828 /* initialize the prompt stack to a simple "(gdb) " prompt or to
1829 whatever the DEFAULT_PROMPT is. */
1830 the_prompts
.top
= 0;
1832 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
1834 /* Set things up for annotation_level > 1, if the user ever decides
1836 async_annotation_suffix
= "prompt";
1837 /* Set the variable associated with the setshow prompt command. */
1838 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
1840 /* If gdb was started with --annotate=2, this is equivalent to
1841 the user entering the command 'set annotate 2' at the gdb
1842 prompt, so we need to do extra processing. */
1843 if (annotation_level
> 1)
1844 set_async_annotation_level (NULL
, 0, NULL
);
1846 gdb_prompt_escape
= 0; /* default to none. */
1848 /* Set the important stuff up for command editing. */
1849 command_editing_p
= 1;
1850 history_expansion_p
= 0;
1851 write_history_p
= 0;
1853 /* Setup important stuff for command line editing. */
1854 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
1855 rl_completer_word_break_characters
=
1856 get_gdb_completer_word_break_characters ();
1857 rl_completer_quote_characters
= get_gdb_completer_quote_characters ();
1858 rl_readline_name
= "gdb";
1860 /* The set prompt command is different depending whether or not the
1861 async version is run. NOTE: this difference is going to
1862 disappear as we make the event loop be the default engine of
1867 (add_set_cmd ("prompt", class_support
, var_string
,
1868 (char *) &gdb_prompt_string
, "Set gdb's prompt",
1874 c
= add_set_cmd ("prompt", class_support
, var_string
,
1875 (char *) &new_async_prompt
, "Set gdb's prompt",
1877 add_show_from_set (c
, &showlist
);
1878 c
->function
.sfunc
= set_async_prompt
;
1882 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
1883 (char *) &gdb_prompt_escape
,
1884 "Set escape character for formatting of gdb's prompt",
1888 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
1889 Primarily used inside of user-defined commands that should not be repeated when\n\
1892 /* The set editing command is different depending whether or not the
1893 async version is run. NOTE: this difference is going to disappear
1894 as we make the event loop be the default engine of gdb. */
1898 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
1899 "Set editing of command lines as they are typed.\n\
1900 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1901 Without an argument, command line editing is enabled. To edit, use\n\
1902 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
1907 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
1908 "Set editing of command lines as they are typed.\n\
1909 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1910 Without an argument, command line editing is enabled. To edit, use\n\
1911 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
1913 add_show_from_set (c
, &showlist
);
1914 c
->function
.sfunc
= set_async_editing_command
;
1918 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
1919 "Set saving of the history record on exit.\n\
1920 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
1921 Without an argument, saving is enabled.", &sethistlist
),
1924 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
1925 "Set the size of the command history, \n\
1926 ie. the number of previous commands to keep a record of.", &sethistlist
);
1927 add_show_from_set (c
, &showhistlist
);
1928 c
->function
.sfunc
= set_history_size_command
;
1930 c
= add_set_cmd ("filename", no_class
, var_filename
,
1931 (char *) &history_filename
,
1932 "Set the filename in which to record the command history\n\
1933 (the list of previous commands of which a record is kept).", &sethistlist
);
1934 c
->completer
= filename_completer
;
1935 add_show_from_set (c
, &showhistlist
);
1938 (add_set_cmd ("confirm", class_support
, var_boolean
,
1940 "Set whether to confirm potentially dangerous operations.",
1944 /* The set annotate command is different depending whether or not
1945 the async version is run. NOTE: this difference is going to
1946 disappear as we make the event loop be the default engine of
1950 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
1951 (char *) &annotation_level
, "Set annotation_level.\n\
1952 0 == normal; 1 == fullname (for use when running under emacs)\n\
1953 2 == output annotated suitably for use by programs that control GDB.",
1955 c
= add_show_from_set (c
, &showlist
);
1959 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
1960 (char *) &annotation_level
, "Set annotation_level.\n\
1961 0 == normal; 1 == fullname (for use when running under emacs)\n\
1962 2 == output annotated suitably for use by programs that control GDB.",
1964 add_show_from_set (c
, &showlist
);
1965 c
->function
.sfunc
= set_async_annotation_level
;
1970 (add_set_cmd ("exec-done-display", class_support
, var_boolean
, (char *) &exec_done_display_p
,
1971 "Set notification of completion for asynchronous execution commands.\n\
1972 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist
),
1978 gdb_init (char *argv0
)
1980 if (pre_init_ui_hook
)
1981 pre_init_ui_hook ();
1983 /* Run the init function of each source file */
1985 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
1986 current_directory
= gdb_dirbuf
;
1989 /* Make sure we return to the original directory upon exit, come
1990 what may, since the OS doesn't do that for us. */
1991 make_final_cleanup (do_chdir_cleanup
, xstrdup (current_directory
));
1994 init_cmd_lists (); /* This needs to be done first */
1995 initialize_targets (); /* Setup target_terminal macros for utils.c */
1996 initialize_utils (); /* Make errors and warnings possible */
1997 initialize_all_files ();
1998 initialize_current_architecture ();
2000 init_main (); /* But that omits this file! Do it now */
2002 /* The signal handling mechanism is different depending whether or
2003 not the async version is run. NOTE: in the future we plan to make
2004 the event loop be the default engine of gdb, and this difference
2007 async_init_signals ();
2011 /* We need a default language for parsing expressions, so simple things like
2012 "set width 0" won't fail if no language is explicitly set in a config file
2013 or implicitly set by reading an executable during startup. */
2014 set_language (language_c
);
2015 expected_language
= current_language
; /* don't warn about the change. */
2018 /* Install the default UI */
2021 uiout
= cli_out_new (gdb_stdout
);
2023 /* All the interpreters should have had a look at things by now.
2024 Initialize the selected interpreter. */
2027 fprintf_unfiltered (gdb_stderr
, "Interpreter `%s' unrecognized.\n",
2035 init_ui_hook (argv0
);