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"
25 #include "cli/cli-cmds.h"
26 #include "cli/cli-script.h"
27 #include "cli/cli-setshow.h"
32 #include "breakpoint.h"
34 #include "expression.h"
37 #include "terminal.h" /* For job_control. */
39 #include "completer.h"
45 /* readline include files */
46 #include <readline/readline.h>
47 #include <readline/history.h>
49 /* readline defines this. */
52 #include <sys/types.h>
56 #include "event-top.h"
57 #include "gdb_string.h"
65 /* Default command line prompt. This is overriden in some configs. */
67 #ifndef DEFAULT_PROMPT
68 #define DEFAULT_PROMPT "(gdb) "
71 /* Initialization file name for gdb. This is overridden in some configs. */
73 #ifndef GDBINIT_FILENAME
74 #define GDBINIT_FILENAME ".gdbinit"
76 char gdbinit
[] = GDBINIT_FILENAME
;
78 int inhibit_gdbinit
= 0;
80 /* If nonzero, and GDB has been configured to be able to use windows,
81 attempt to open them upon startup. */
85 extern char lang_frame_mismatch_warn
[]; /* language.c */
87 /* Flag for whether we want all the "from_tty" gubbish printed. */
89 int caution
= 1; /* Default is yes, sigh. */
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. */
97 /* Current working directory. */
99 char *current_directory
;
101 /* The directory name is actually stored here (usually). */
102 char gdb_dirbuf
[1024];
104 /* Function to call before reading a command, if nonzero.
105 The function receives two args: an input stream,
106 and a prompt string. */
108 void (*window_hook
) (FILE *, char *);
113 /* gdb prints this when reading a command interactively */
114 static char *gdb_prompt_string
; /* the global prompt string */
116 /* Buffer used for reading command lines, and the size
117 allocated for it so far. */
122 /* Nonzero if the current command is modified by "server ". This
123 affects things like recording into the command history, commands
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. */
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. */
137 /* Timeout limit for response from target. */
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.
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.
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.
154 As remote.c is used much more than remote-e7000.c, it was changed
155 back to 2 seconds in 1999. */
157 int remote_timeout
= 2;
159 /* Non-zero tells remote* modules to output debugging info. */
161 int remote_debug
= 0;
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. */
167 int target_executing
= 0;
169 /* Level of control structure. */
170 static int control_level
;
172 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
176 #define STOP_SIGNAL SIGTSTP
177 static void stop_sig (int);
181 /* Hooks for alternate command interfaces. */
183 /* Called after most modules have been initialized, but before taking users
186 void (*init_ui_hook
) (char *argv0
);
188 /* This hook is called from within gdb's many mini-event loops which could
189 steal control from a real user interface's event loop. It returns
190 non-zero if the user is requesting a detach, zero otherwise. */
192 int (*ui_loop_hook
) (int);
194 /* Called instead of command_loop at top level. Can be invoked via
195 return_to_top_level. */
197 void (*command_loop_hook
) (void);
200 /* Called from print_frame_info to list the line we stopped in. */
202 void (*print_frame_info_listing_hook
) (struct symtab
* s
, int line
,
203 int stopline
, int noerror
);
204 /* Replaces most of query. */
206 int (*query_hook
) (const char *, va_list);
208 /* Replaces most of warning. */
210 void (*warning_hook
) (const char *, va_list);
212 /* These three functions support getting lines of text from the user. They
213 are used in sequence. First readline_begin_hook is called with a text
214 string that might be (for example) a message for the user to type in a
215 sequence of commands to be executed at a breakpoint. If this function
216 calls back to a GUI, it might take this opportunity to pop up a text
217 interaction window with this message. Next, readline_hook is called
218 with a prompt that is emitted prior to collecting the user input.
219 It can be called multiple times. Finally, readline_end_hook is called
220 to notify the GUI that we are done with the interaction window and it
223 void (*readline_begin_hook
) (char *, ...);
224 char *(*readline_hook
) (char *);
225 void (*readline_end_hook
) (void);
227 /* Called as appropriate to notify the interface of the specified breakpoint
230 void (*create_breakpoint_hook
) (struct breakpoint
* bpt
);
231 void (*delete_breakpoint_hook
) (struct breakpoint
* bpt
);
232 void (*modify_breakpoint_hook
) (struct breakpoint
* bpt
);
234 /* Called as appropriate to notify the interface that we have attached
235 to or detached from an already running process. */
237 void (*attach_hook
) (void);
238 void (*detach_hook
) (void);
240 /* Called during long calculations to allow GUI to repair window damage, and to
241 check for stop buttons, etc... */
243 void (*interactive_hook
) (void);
245 /* Called when the registers have changed, as a hint to a GUI
246 to minimize window update. */
248 void (*registers_changed_hook
) (void);
250 /* Tell the GUI someone changed the register REGNO. -1 means
251 that the caller does not know which register changed or
252 that several registers have changed (see value_assign). */
253 void (*register_changed_hook
) (int regno
);
255 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
256 void (*memory_changed_hook
) (CORE_ADDR addr
, int len
);
258 /* Called when going to wait for the target. Usually allows the GUI to run
259 while waiting for target events. */
261 ptid_t (*target_wait_hook
) (ptid_t ptid
,
262 struct target_waitstatus
* status
);
264 /* Used by UI as a wrapper around command execution. May do various things
265 like enabling/disabling buttons, etc... */
267 void (*call_command_hook
) (struct cmd_list_element
* c
, char *cmd
,
270 /* Called after a `set' command has finished. Is only run if the
271 `set' command succeeded. */
273 void (*set_hook
) (struct cmd_list_element
* c
);
275 /* Called when the current thread changes. Argument is thread id. */
277 void (*context_hook
) (int id
);
279 /* Takes control from error (). Typically used to prevent longjmps out of the
280 middle of the GUI. Usually used in conjunction with a catch routine. */
282 NORETURN
void (*error_hook
) (void) ATTR_NORETURN
;
285 /* One should use catch_errors rather than manipulating these
287 #if defined(HAVE_SIGSETJMP)
288 #define SIGJMP_BUF sigjmp_buf
289 #define SIGSETJMP(buf) sigsetjmp((buf), 1)
290 #define SIGLONGJMP(buf,val) siglongjmp((buf), (val))
292 #define SIGJMP_BUF jmp_buf
293 #define SIGSETJMP(buf) setjmp(buf)
294 #define SIGLONGJMP(buf,val) longjmp((buf), (val))
297 /* Where to go for return_to_top_level. */
298 static SIGJMP_BUF
*catch_return
;
300 /* Return for reason REASON to the nearest containing catch_errors(). */
303 return_to_top_level (enum return_reason reason
)
308 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
309 I can think of a reason why that is vital, though). */
310 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
312 disable_current_display ();
313 do_cleanups (ALL_CLEANUPS
);
314 if (event_loop_p
&& target_can_async_p () && !target_executing
)
315 do_exec_cleanups (ALL_CLEANUPS
);
316 if (event_loop_p
&& sync_execution
)
317 do_exec_error_cleanups (ALL_CLEANUPS
);
319 if (annotation_level
> 1)
330 /* Jump to the containing catch_errors() call, communicating REASON
331 to that call via setjmp's return value. Note that REASON can't
332 be zero, by definition in defs.h. */
334 (NORETURN
void) SIGLONGJMP (*catch_return
, (int) reason
);
337 /* Call FUNC with arg ARGS, catching any errors. If there is no
338 error, return the value returned by FUNC. If there is an error,
339 print ERRSTRING, print the specific error message, then return
342 Must not be called with immediate_quit in effect (bad things might
343 happen, say we got a signal in the middle of a memcpy to quit_return).
344 This is an OK restriction; with very few exceptions immediate_quit can
345 be replaced by judicious use of QUIT.
347 MASK specifies what to catch; it is normally set to
348 RETURN_MASK_ALL, if for no other reason than that the code which
349 calls catch_errors might not be set up to deal with a quit which
350 isn't caught. But if the code can deal with it, it generally
351 should be RETURN_MASK_ERROR, unless for some reason it is more
352 useful to abort only the portion of the operation inside the
353 catch_errors. Note that quit should return to the command line
354 fairly quickly, even if some further processing is being done. */
356 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
357 error() et.al. could maintain a set of flags that indicate the the
358 current state of each of the longjmp buffers. This would give the
359 longjmp code the chance to detect a longjmp botch (before it gets
360 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
361 code also randomly used a SET_TOP_LEVEL macro that directly
362 initialize the longjmp buffers. */
364 /* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code
365 be consolidated into a single file instead of being distributed
366 between utils.c and top.c? */
369 catch_errors (catch_errors_ftype
*func
, void * args
, char *errstring
,
372 SIGJMP_BUF
*saved_catch
;
375 struct cleanup
*saved_cleanup_chain
;
376 char *saved_error_pre_print
;
377 char *saved_quit_pre_print
;
379 /* Return value from SIGSETJMP(): enum return_reason if error or
380 quit caught, 0 otherwise. */
383 /* Override error/quit messages during FUNC. */
385 saved_error_pre_print
= error_pre_print
;
386 saved_quit_pre_print
= quit_pre_print
;
388 if (mask
& RETURN_MASK_ERROR
)
389 error_pre_print
= errstring
;
390 if (mask
& RETURN_MASK_QUIT
)
391 quit_pre_print
= errstring
;
393 /* Prevent error/quit during FUNC from calling cleanups established
396 saved_cleanup_chain
= save_cleanups ();
398 /* Call FUNC, catching error/quit events. */
400 saved_catch
= catch_return
;
401 catch_return
= &catch;
402 caught
= SIGSETJMP (catch);
404 val
= (*func
) (args
);
407 catch_return
= saved_catch
;
409 /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
410 clean things up (restoring the cleanup chain) to the state they
411 were just prior to the call. Unfortunately, many FUNC's are not
412 that well behaved. This could be fixed by adding either a
413 do_cleanups call (to cover the problem) or an assertion check to
414 detect bad FUNCs code. */
416 /* Restore the cleanup chain and error/quit messages to their
419 restore_cleanups (saved_cleanup_chain
);
421 if (mask
& RETURN_MASK_QUIT
)
422 quit_pre_print
= saved_quit_pre_print
;
423 if (mask
& RETURN_MASK_ERROR
)
424 error_pre_print
= saved_error_pre_print
;
426 /* Return normally if no error/quit event occurred. */
431 /* If the caller didn't request that the event be caught, relay the
432 event to the next containing catch_errors(). */
434 if (!(mask
& RETURN_MASK (caught
)))
435 return_to_top_level (caught
);
437 /* Tell the caller that an event was caught.
439 FIXME: nsd/2000-02-22: When MASK is RETURN_MASK_ALL, the caller
440 can't tell what type of event occurred.
442 A possible fix is to add a new interface, catch_event(), that
443 returns enum return_reason after catching an error or a quit.
445 When returning normally, i.e. without catching an error or a
446 quit, catch_event() could return RETURN_NORMAL, which would be
447 added to enum return_reason. FUNC would return information
448 exclusively via ARGS.
450 Alternatively, normal catch_event() could return FUNC's return
451 value. The caller would need to be aware of potential overlap
452 with enum return_reason, which could be publicly restricted to
453 negative values to simplify return value processing in FUNC and
459 struct captured_command_args
461 catch_command_errors_ftype
*command
;
467 do_captured_command (void *data
)
469 struct captured_command_args
*context
= data
;
470 context
->command (context
->arg
, context
->from_tty
);
471 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
472 isn't needed. Instead an assertion check could be made that
473 simply confirmed that the called function correctly cleaned up
474 after itself. Unfortunately, old code (prior to 1999-11-04) in
475 main.c was calling SET_TOP_LEVEL(), calling the command function,
476 and then *always* calling do_cleanups(). For the moment we
477 remain ``bug compatible'' with that old code.. */
478 do_cleanups (ALL_CLEANUPS
);
483 catch_command_errors (catch_command_errors_ftype
* command
,
484 char *arg
, int from_tty
, return_mask mask
)
486 struct captured_command_args args
;
487 args
.command
= command
;
489 args
.from_tty
= from_tty
;
490 return catch_errors (do_captured_command
, &args
, "", mask
);
494 /* Handler for SIGHUP. */
497 /* Just a little helper function for disconnect(). */
499 /* NOTE 1999-04-29: This function will be static again, once we modify
500 gdb to use the event loop as the default command loop and we merge
501 event-top.c into this file, top.c */
505 caution
= 0; /* Throw caution to the wind -- we're exiting.
506 This prevents asking the user dumb questions. */
507 quit_command ((char *) 0, 0);
512 disconnect (int signo
)
514 catch_errors (quit_cover
, NULL
,
515 "Could not kill the program being debugged", RETURN_MASK_ALL
);
516 signal (SIGHUP
, SIG_DFL
);
517 kill (getpid (), SIGHUP
);
519 #endif /* defined SIGHUP */
521 /* Line number we are currently in in a file which is being sourced. */
522 /* NOTE 1999-04-29: This variable will be static again, once we modify
523 gdb to use the event loop as the default command loop and we merge
524 event-top.c into this file, top.c */
525 /* static */ int source_line_number
;
527 /* Name of the file we are sourcing. */
528 /* NOTE 1999-04-29: This variable will be static again, once we modify
529 gdb to use the event loop as the default command loop and we merge
530 event-top.c into this file, top.c */
531 /* static */ char *source_file_name
;
533 /* Buffer containing the error_pre_print used by the source stuff.
535 /* NOTE 1999-04-29: This variable will be static again, once we modify
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 */ char *source_error
;
539 static int source_error_allocated
;
541 /* Something to glom on to the start of error_pre_print if source_file_name
543 /* NOTE 1999-04-29: This variable will be static again, once we modify
544 gdb to use the event loop as the default command loop and we merge
545 event-top.c into this file, top.c */
546 /* static */ char *source_pre_error
;
548 /* Clean up on error during a "source" command (or execution of a
549 user-defined command). */
552 do_restore_instream_cleanup (void *stream
)
554 /* Restore the previous input stream. */
558 /* Read commands from STREAM. */
560 read_command_file (FILE *stream
)
562 struct cleanup
*cleanups
;
564 cleanups
= make_cleanup (do_restore_instream_cleanup
, instream
);
567 do_cleanups (cleanups
);
570 void (*pre_init_ui_hook
) (void);
574 do_chdir_cleanup (void *old_dir
)
581 /* Execute the line P as a command.
582 Pass FROM_TTY as second argument to the defining function. */
585 execute_command (char *p
, int from_tty
)
587 register struct cmd_list_element
*c
;
588 register enum language flang
;
589 static int warned
= 0;
594 /* Force cleanup of any alloca areas if using C alloca instead of
598 /* This can happen when command_line_input hits end of file. */
602 serial_log_command (p
);
604 while (*p
== ' ' || *p
== '\t')
611 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
613 /* If the target is running, we allow only a limited set of
615 if (event_loop_p
&& target_can_async_p () && target_executing
)
616 if (!strcmp (c
->name
, "help")
617 && !strcmp (c
->name
, "pwd")
618 && !strcmp (c
->name
, "show")
619 && !strcmp (c
->name
, "stop"))
620 error ("Cannot execute this command while the target is running.");
622 /* Pass null arg rather than an empty one. */
625 /* Clear off trailing whitespace, except for set and complete command. */
627 && c
->type
!= set_cmd
628 && !is_complete_command (c
->function
.cfunc
))
630 p
= arg
+ strlen (arg
) - 1;
631 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
636 /* If this command has been pre-hooked, run the hook first. */
637 if ((c
->hook_pre
) && (!c
->hook_in
))
639 c
->hook_in
= 1; /* Prevent recursive hooking */
640 execute_user_command (c
->hook_pre
, (char *) 0);
641 c
->hook_in
= 0; /* Allow hook to work again once it is complete */
644 if (c
->flags
& DEPRECATED_WARN_USER
)
645 deprecated_cmd_warning (&line
);
647 if (c
->class == class_user
)
648 execute_user_command (c
, arg
);
649 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
650 do_setshow_command (arg
, from_tty
& caution
, c
);
651 else if (c
->function
.cfunc
== NO_FUNCTION
)
652 error ("That is not a command, just a help topic.");
653 else if (call_command_hook
)
654 call_command_hook (c
, arg
, from_tty
& caution
);
656 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
658 /* If this command has been post-hooked, run the hook last. */
659 if ((c
->hook_post
) && (!c
->hook_in
))
661 c
->hook_in
= 1; /* Prevent recursive hooking */
662 execute_user_command (c
->hook_post
, (char *) 0);
663 c
->hook_in
= 0; /* allow hook to work again once it is complete */
668 /* Tell the user if the language has changed (except first time). */
669 if (current_language
!= expected_language
)
671 if (language_mode
== language_mode_auto
)
673 language_info (1); /* Print what changed. */
678 /* Warn the user if the working language does not match the
679 language of the current frame. Only warn the user if we are
680 actually running the program, i.e. there is a stack. */
681 /* FIXME: This should be cacheing the frame and only running when
682 the frame changes. */
684 if (target_has_stack
)
686 flang
= get_frame_language ();
688 && flang
!= language_unknown
689 && flang
!= current_language
->la_language
)
691 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
697 /* Read commands from `instream' and execute them
698 until end of file or error reading instream. */
703 struct cleanup
*old_chain
;
705 int stdin_is_tty
= ISATTY (stdin
);
706 long time_at_cmd_start
;
708 long space_at_cmd_start
= 0;
710 extern int display_time
;
711 extern int display_space
;
713 while (instream
&& !feof (instream
))
715 if (window_hook
&& instream
== stdin
)
716 (*window_hook
) (instream
, get_prompt ());
719 if (instream
== stdin
&& stdin_is_tty
)
720 reinitialize_more_filter ();
721 old_chain
= make_cleanup (null_cleanup
, 0);
723 /* Get a command-line. This calls the readline package. */
724 command
= command_line_input (instream
== stdin
?
725 get_prompt () : (char *) NULL
,
726 instream
== stdin
, "prompt");
730 time_at_cmd_start
= get_run_time ();
735 extern char **environ
;
736 char *lim
= (char *) sbrk (0);
738 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
742 execute_command (command
, instream
== stdin
);
743 /* Do any commands attached to breakpoint we stopped at. */
744 bpstat_do_actions (&stop_bpstat
);
745 do_cleanups (old_chain
);
749 long cmd_time
= get_run_time () - time_at_cmd_start
;
751 printf_unfiltered ("Command execution time: %ld.%06ld\n",
752 cmd_time
/ 1000000, cmd_time
% 1000000);
758 extern char **environ
;
759 char *lim
= (char *) sbrk (0);
760 long space_now
= lim
- (char *) &environ
;
761 long space_diff
= space_now
- space_at_cmd_start
;
763 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
765 (space_diff
>= 0 ? '+' : '-'),
772 /* Read commands from `instream' and execute them until end of file or
773 error reading instream. This command loop doesnt care about any
774 such things as displaying time and space usage. If the user asks
775 for those, they won't work. */
777 simplified_command_loop (char *(*read_input_func
) (char *),
778 void (*execute_command_func
) (char *, int))
780 struct cleanup
*old_chain
;
782 int stdin_is_tty
= ISATTY (stdin
);
784 while (instream
&& !feof (instream
))
787 if (instream
== stdin
&& stdin_is_tty
)
788 reinitialize_more_filter ();
789 old_chain
= make_cleanup (null_cleanup
, 0);
791 /* Get a command-line. */
792 command
= (*read_input_func
) (instream
== stdin
?
793 get_prompt () : (char *) NULL
);
798 (*execute_command_func
) (command
, instream
== stdin
);
800 /* Do any commands attached to breakpoint we stopped at. */
801 bpstat_do_actions (&stop_bpstat
);
803 do_cleanups (old_chain
);
807 /* Commands call this if they do not want to be repeated by null lines. */
815 /* If we aren't reading from standard input, we are saving the last
816 thing read from stdin in line and don't want to delete it. Null lines
817 won't repeat here in any case. */
818 if (instream
== stdin
)
822 /* Read a line from the stream "instream" without command line editing.
824 It prints PROMPT_ARG once at the start.
825 Action is compatible with "readline", e.g. space for the result is
826 malloc'd and should be freed by the caller.
828 A NULL return means end of file. */
830 gdb_readline (char *prompt_arg
)
835 int result_size
= 80;
839 /* Don't use a _filtered function here. It causes the assumed
840 character position to be off, since the newline we read from
841 the user is not accounted for. */
842 fputs_unfiltered (prompt_arg
, gdb_stdout
);
843 /* OBSOLETE #ifdef MPW */
844 /* OBSOLETE Move to a new line so the entered line doesn't have a prompt */
845 /* OBSOLETE on the front of it. */
846 /* OBSOLETE fputs_unfiltered ("\n", gdb_stdout); */
847 /* OBSOLETE #endif *//* MPW */
848 gdb_flush (gdb_stdout
);
851 result
= (char *) xmalloc (result_size
);
855 /* Read from stdin if we are executing a user defined command.
856 This is the right thing for prompt_for_continue, at least. */
857 c
= fgetc (instream
? instream
: stdin
);
862 /* The last line does not end with a newline. Return it, and
863 if we are called again fgetc will still return EOF and
864 we'll return NULL then. */
871 #ifndef CRLF_SOURCE_FILES
875 if (input_index
> 0 && result
[input_index
- 1] == '\r')
881 result
[input_index
++] = c
;
882 while (input_index
>= result_size
)
885 result
= (char *) xrealloc (result
, result_size
);
889 result
[input_index
++] = '\0';
893 /* Variables which control command line editing and history
894 substitution. These variables are given default values at the end
896 static int command_editing_p
;
897 /* NOTE 1999-04-29: This variable will be static again, once we modify
898 gdb to use the event loop as the default command loop and we merge
899 event-top.c into this file, top.c */
900 /* static */ int history_expansion_p
;
901 static int write_history_p
;
902 static int history_size
;
903 static char *history_filename
;
910 #if STOP_SIGNAL == SIGTSTP
911 signal (SIGTSTP
, SIG_DFL
);
917 sigprocmask (SIG_SETMASK
, &zero
, 0);
919 #elif HAVE_SIGSETMASK
922 kill (getpid (), SIGTSTP
);
923 signal (SIGTSTP
, stop_sig
);
925 signal (STOP_SIGNAL
, stop_sig
);
927 printf_unfiltered ("%s", get_prompt ());
928 gdb_flush (gdb_stdout
);
930 /* Forget about any previous command -- null line now will do nothing. */
933 #endif /* STOP_SIGNAL */
935 /* Initialize signal handlers. */
937 float_handler (int signo
)
939 /* This message is based on ANSI C, section 4.7. Note that integer
940 divide by zero causes this, so "float" is a misnomer. */
941 signal (SIGFPE
, float_handler
);
942 error ("Erroneous arithmetic operation.");
946 do_nothing (int signo
)
948 /* Under System V the default disposition of a signal is reinstated after
949 the signal is caught and delivered to an application process. On such
950 systems one must restore the replacement signal handler if one wishes
951 to continue handling the signal in one's program. On BSD systems this
952 is not needed but it is harmless, and it simplifies the code to just do
953 it unconditionally. */
954 signal (signo
, do_nothing
);
960 signal (SIGINT
, request_quit
);
962 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
963 to the inferior and breakpoints will be ignored. */
965 signal (SIGTRAP
, SIG_DFL
);
968 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
969 passed to the inferior, which we don't want. It would be
970 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
971 on BSD4.3 systems using vfork, that can affect the
972 GDB process as well as the inferior (the signal handling tables
973 might be in memory, shared between the two). Since we establish
974 a handler for SIGQUIT, when we call exec it will set the signal
975 to SIG_DFL for us. */
976 signal (SIGQUIT
, do_nothing
);
978 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
979 signal (SIGHUP
, disconnect
);
981 signal (SIGFPE
, float_handler
);
983 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
984 signal (SIGWINCH
, SIGWINCH_HANDLER
);
988 /* Read one line from the command input stream `instream'
989 into the local static buffer `linebuffer' (whose current length
991 The buffer is made bigger as necessary.
992 Returns the address of the start of the line.
994 NULL is returned for end of file.
996 *If* the instream == stdin & stdin is a terminal, the line read
997 is copied into the file line saver (global var char *line,
998 length linesize) so that it can be duplicated.
1000 This routine either uses fancy command line editing or
1001 simple input as the user has requested. */
1004 command_line_input (char *prompt_arg
, int repeat
, char *annotation_suffix
)
1006 static char *linebuffer
= 0;
1007 static unsigned linelength
= 0;
1011 char *local_prompt
= prompt_arg
;
1015 /* The annotation suffix must be non-NULL. */
1016 if (annotation_suffix
== NULL
)
1017 annotation_suffix
= "";
1019 if (annotation_level
> 1 && instream
== stdin
)
1021 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
1022 + strlen (annotation_suffix
) + 40);
1023 if (prompt_arg
== NULL
)
1024 local_prompt
[0] = '\0';
1026 strcpy (local_prompt
, prompt_arg
);
1027 strcat (local_prompt
, "\n\032\032");
1028 strcat (local_prompt
, annotation_suffix
);
1029 strcat (local_prompt
, "\n");
1032 if (linebuffer
== 0)
1035 linebuffer
= (char *) xmalloc (linelength
);
1040 /* Control-C quits instantly if typed while in this loop
1041 since it should not wait until the user types a newline. */
1047 signal (STOP_SIGNAL
, handle_stop_sig
);
1049 signal (STOP_SIGNAL
, stop_sig
);
1055 /* Make sure that all output has been output. Some machines may let
1056 you get away with leaving out some of the gdb_flush, but not all. */
1058 gdb_flush (gdb_stdout
);
1059 gdb_flush (gdb_stderr
);
1061 if (source_file_name
!= NULL
)
1063 ++source_line_number
;
1064 sprintf (source_error
,
1065 "%s%s:%d: Error in sourced command file:\n",
1068 source_line_number
);
1069 error_pre_print
= source_error
;
1072 if (annotation_level
> 1 && instream
== stdin
)
1074 printf_unfiltered ("\n\032\032pre-");
1075 printf_unfiltered (annotation_suffix
);
1076 printf_unfiltered ("\n");
1079 /* Don't use fancy stuff if not talking to stdin. */
1080 if (readline_hook
&& instream
== NULL
)
1082 rl
= (*readline_hook
) (local_prompt
);
1084 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
1086 rl
= readline (local_prompt
);
1090 rl
= gdb_readline (local_prompt
);
1093 if (annotation_level
> 1 && instream
== stdin
)
1095 printf_unfiltered ("\n\032\032post-");
1096 printf_unfiltered (annotation_suffix
);
1097 printf_unfiltered ("\n");
1100 if (!rl
|| rl
== (char *) EOF
)
1105 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
1107 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
1108 nline
= (char *) xrealloc (linebuffer
, linelength
);
1109 p
+= nline
- linebuffer
;
1113 /* Copy line. Don't copy null at end. (Leaves line alone
1114 if this was just a newline) */
1118 xfree (rl
); /* Allocated in readline. */
1120 if (p
== linebuffer
|| *(p
- 1) != '\\')
1123 p
--; /* Put on top of '\'. */
1124 local_prompt
= (char *) 0;
1129 signal (STOP_SIGNAL
, SIG_DFL
);
1136 #define SERVER_COMMAND_LENGTH 7
1138 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
1139 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
1142 /* Note that we don't set `line'. Between this and the check in
1143 dont_repeat, this insures that repeating will still do the
1146 return linebuffer
+ SERVER_COMMAND_LENGTH
;
1149 /* Do history expansion if that is wished. */
1150 if (history_expansion_p
&& instream
== stdin
1151 && ISATTY (instream
))
1153 char *history_value
;
1156 *p
= '\0'; /* Insert null now. */
1157 expanded
= history_expand (linebuffer
, &history_value
);
1160 /* Print the changes. */
1161 printf_unfiltered ("%s\n", history_value
);
1163 /* If there was an error, call this function again. */
1166 xfree (history_value
);
1167 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
1169 if (strlen (history_value
) > linelength
)
1171 linelength
= strlen (history_value
) + 1;
1172 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1174 strcpy (linebuffer
, history_value
);
1175 p
= linebuffer
+ strlen (linebuffer
);
1176 xfree (history_value
);
1180 /* If we just got an empty line, and that is supposed
1181 to repeat the previous command, return the value in the
1183 if (repeat
&& p
== linebuffer
)
1185 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
1191 /* Add line to history if appropriate. */
1192 if (instream
== stdin
1193 && ISATTY (stdin
) && *linebuffer
)
1194 add_history (linebuffer
);
1196 /* Note: lines consisting solely of comments are added to the command
1197 history. This is useful when you type a command, and then
1198 realize you don't want to execute it quite yet. You can comment
1199 out the command and then later fetch it from the value history
1200 and remove the '#'. The kill ring is probably better, but some
1201 people are in the habit of commenting things out. */
1203 *p1
= '\0'; /* Found a comment. */
1205 /* Save into global buffer if appropriate. */
1208 if (linelength
> linesize
)
1210 line
= xrealloc (line
, linelength
);
1211 linesize
= linelength
;
1213 strcpy (line
, linebuffer
);
1220 /* Print the GDB banner. */
1222 print_gdb_version (struct ui_file
*stream
)
1224 /* From GNU coding standards, first line is meant to be easy for a
1225 program to parse, and is just canonical program name and version
1226 number, which starts after last space. */
1229 /* Print it console style until a format is defined */
1230 fprintf_filtered (stream
, "GNU gdb %s (MI_OUT)\n", version
);
1232 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
1235 /* Second line is a copyright notice. */
1237 fprintf_filtered (stream
, "Copyright 2001 Free Software Foundation, Inc.\n");
1239 /* Following the copyright is a brief statement that the program is
1240 free software, that users are free to copy and change it on
1241 certain conditions, that it is covered by the GNU GPL, and that
1242 there is no warranty. */
1244 fprintf_filtered (stream
, "\
1245 GDB is free software, covered by the GNU General Public License, and you are\n\
1246 welcome to change it and/or distribute copies of it under certain conditions.\n\
1247 Type \"show copying\" to see the conditions.\n\
1248 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
1250 /* After the required info we print the configuration information. */
1252 fprintf_filtered (stream
, "This GDB was configured as \"");
1253 if (!STREQ (host_name
, target_name
))
1255 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
1259 fprintf_filtered (stream
, "%s", host_name
);
1261 fprintf_filtered (stream
, "\".");
1264 /* get_prompt: access method for the GDB prompt string. */
1266 #define MAX_PROMPT_SIZE 256
1269 * int get_prompt_1 (char * buf);
1271 * Work-horse for get_prompt (called via catch_errors).
1272 * Argument is buffer to hold the formatted prompt.
1274 * Returns: 1 for success (use formatted prompt)
1275 * 0 for failure (use gdb_prompt_string).
1278 static int gdb_prompt_escape
;
1281 get_prompt_1 (void *data
)
1283 char *formatted_prompt
= data
;
1287 local_prompt
= PROMPT (0);
1289 local_prompt
= gdb_prompt_string
;
1292 if (gdb_prompt_escape
== 0)
1294 return 0; /* do no formatting */
1297 /* formatted prompt */
1299 char fmt
[40], *promptp
, *outp
, *tmp
;
1306 struct type
*arg_type
, *elt_type
;
1308 promptp
= local_prompt
;
1309 outp
= formatted_prompt
;
1311 while (*promptp
!= '\0')
1313 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
1315 if (*promptp
!= gdb_prompt_escape
)
1317 if (available
>= 1) /* overflow protect */
1318 *outp
++ = *promptp
++;
1322 /* GDB prompt string contains escape char. Parse for arg.
1323 Two consecutive escape chars followed by arg followed by
1324 a comma means to insert the arg using a default format.
1325 Otherwise a printf format string may be included between
1326 the two escape chars. eg:
1327 %%foo, insert foo using default format
1328 %2.2f%foo, insert foo using "%2.2f" format
1329 A mismatch between the format string and the data type
1330 of "foo" is an error (which we don't know how to protect
1333 fmt
[0] = '\0'; /* assume null format string */
1334 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
1336 promptp
+= 2; /* skip past two escape chars. */
1340 /* extract format string from between two esc chars */
1344 fmt
[i
++] = *promptp
++; /* copy format string */
1346 while (i
< sizeof (fmt
) - 1 &&
1347 *promptp
!= gdb_prompt_escape
&&
1350 if (*promptp
!= gdb_prompt_escape
)
1351 error ("Syntax error at prompt position %d",
1352 promptp
- local_prompt
);
1355 promptp
++; /* skip second escape char */
1356 fmt
[i
++] = '\0'; /* terminate the format string */
1360 arg_val
= parse_to_comma_and_eval (&promptp
);
1361 if (*promptp
== ',')
1362 promptp
++; /* skip past the comma */
1363 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
1364 switch (TYPE_CODE (arg_type
))
1366 case TYPE_CODE_ARRAY
:
1367 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
1368 if (TYPE_LENGTH (arg_type
) > 0 &&
1369 TYPE_LENGTH (elt_type
) == 1 &&
1370 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
1372 int len
= TYPE_LENGTH (arg_type
);
1374 if (VALUE_LAZY (arg_val
))
1375 value_fetch_lazy (arg_val
);
1376 tmp
= VALUE_CONTENTS (arg_val
);
1378 if (len
> available
)
1379 len
= available
; /* overflow protect */
1381 /* FIXME: how to protect GDB from crashing
1382 from bad user-supplied format string? */
1384 sprintf (outp
, fmt
, tmp
);
1386 strncpy (outp
, tmp
, len
);
1391 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
1392 addrval
= value_as_pointer (arg_val
);
1394 if (TYPE_LENGTH (elt_type
) == 1 &&
1395 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
1398 /* display it as a string */
1399 char *default_fmt
= "%s";
1403 /* Limiting the number of bytes that the following call
1404 will read protects us from sprintf overflow later. */
1405 i
= target_read_string (addrval
, /* src */
1407 available
, /* len */
1409 if (err
) /* read failed */
1410 error ("%s on target_read", safe_strerror (err
));
1412 tmp
[i
] = '\0'; /* force-terminate string */
1413 /* FIXME: how to protect GDB from crashing
1414 from bad user-supplied format string? */
1415 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1421 /* display it as a pointer */
1422 char *default_fmt
= "0x%x";
1424 /* FIXME: how to protect GDB from crashing
1425 from bad user-supplied format string? */
1426 if (available
>= 16 /*? */ ) /* overflow protect */
1427 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1433 char *default_fmt
= "%g";
1435 doubleval
= value_as_double (arg_val
);
1436 /* FIXME: how to protect GDB from crashing
1437 from bad user-supplied format string? */
1438 if (available
>= 16 /*? */ ) /* overflow protect */
1439 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1440 (double) doubleval
);
1445 char *default_fmt
= "%d";
1447 longval
= value_as_long (arg_val
);
1448 /* FIXME: how to protect GDB from crashing
1449 from bad user-supplied format string? */
1450 if (available
>= 16 /*? */ ) /* overflow protect */
1451 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
1455 case TYPE_CODE_BOOL
:
1457 /* no default format for bool */
1458 longval
= value_as_long (arg_val
);
1459 if (available
>= 8 /*? */ ) /* overflow protect */
1462 strcpy (outp
, "<true>");
1464 strcpy (outp
, "<false>");
1468 case TYPE_CODE_ENUM
:
1470 /* no default format for enum */
1471 longval
= value_as_long (arg_val
);
1472 len
= TYPE_NFIELDS (arg_type
);
1473 /* find enum name if possible */
1474 for (i
= 0; i
< len
; i
++)
1475 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
1476 break; /* match -- end loop */
1478 if (i
< len
) /* enum name found */
1480 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
1482 strncpy (outp
, name
, available
);
1483 /* in casel available < strlen (name), */
1484 outp
[available
] = '\0';
1488 if (available
>= 16 /*? */ ) /* overflow protect */
1489 sprintf (outp
, "%ld", (long) longval
);
1493 case TYPE_CODE_VOID
:
1495 break; /* void type -- no output */
1497 error ("bad data type at prompt position %d",
1498 promptp
- local_prompt
);
1501 outp
+= strlen (outp
);
1504 *outp
++ = '\0'; /* terminate prompt string */
1512 static char buf
[MAX_PROMPT_SIZE
];
1514 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
1517 return &buf
[0]; /* successful formatted prompt */
1521 /* Prompt could not be formatted. */
1525 return gdb_prompt_string
;
1530 set_prompt (char *s
)
1532 /* ??rehrauer: I don't know why this fails, since it looks as though
1533 assignments to prompt are wrapped in calls to savestring...
1538 PROMPT (0) = savestring (s
, strlen (s
));
1540 gdb_prompt_string
= savestring (s
, strlen (s
));
1544 /* If necessary, make the user confirm that we should quit. Return
1545 non-zero if we should quit, zero if we shouldn't. */
1550 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
1554 /* This is something of a hack. But there's no reliable way to
1555 see if a GUI is running. The `use_windows' variable doesn't
1558 s
= "A debugging session is active.\nDo you still want to close the debugger?";
1559 else if (attach_flag
)
1560 s
= "The program is running. Quit anyway (and detach it)? ";
1562 s
= "The program is running. Exit anyway? ";
1571 /* Quit without asking for confirmation. */
1574 quit_force (char *args
, int from_tty
)
1578 /* An optional expression may be used to cause gdb to terminate with the
1579 value of that expression. */
1582 value_ptr val
= parse_and_eval (args
);
1584 exit_code
= (int) value_as_long (val
);
1587 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
1590 target_detach (args
, from_tty
);
1595 /* UDI wants this, to kill the TIP. */
1598 /* Save the history information if it is appropriate to do so. */
1599 if (write_history_p
&& history_filename
)
1600 write_history (history_filename
);
1602 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
1607 /* Returns whether GDB is running on a terminal and whether the user
1608 desires that questions be asked of them on that terminal. */
1611 input_from_terminal_p (void)
1613 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
1618 dont_repeat_command (char *ignored
, int from_tty
)
1620 *line
= 0; /* Can't call dont_repeat here because we're not
1621 necessarily reading from stdin. */
1624 /* Functions to manipulate command line editing control variables. */
1626 /* Number of commands to print in each call to show_commands. */
1627 #define Hist_print 10
1629 show_commands (char *args
, int from_tty
)
1631 /* Index for history commands. Relative to history_base. */
1634 /* Number of the history entry which we are planning to display next.
1635 Relative to history_base. */
1638 /* The first command in the history which doesn't exist (i.e. one more
1639 than the number of the last command). Relative to history_base. */
1642 /* Print out some of the commands from the command history. */
1643 /* First determine the length of the history list. */
1644 hist_len
= history_size
;
1645 for (offset
= 0; offset
< history_size
; offset
++)
1647 if (!history_get (history_base
+ offset
))
1656 if (args
[0] == '+' && args
[1] == '\0')
1657 /* "info editing +" should print from the stored position. */
1660 /* "info editing <exp>" should print around command number <exp>. */
1661 num
= (parse_and_eval_long (args
) - history_base
) - Hist_print
/ 2;
1663 /* "show commands" means print the last Hist_print commands. */
1666 num
= hist_len
- Hist_print
;
1672 /* If there are at least Hist_print commands, we want to display the last
1673 Hist_print rather than, say, the last 6. */
1674 if (hist_len
- num
< Hist_print
)
1676 num
= hist_len
- Hist_print
;
1681 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
1683 printf_filtered ("%5d %s\n", history_base
+ offset
,
1684 (history_get (history_base
+ offset
))->line
);
1687 /* The next command we want to display is the next one that we haven't
1691 /* If the user repeats this command with return, it should do what
1692 "show commands +" does. This is unnecessary if arg is null,
1693 because "show commands +" is not useful after "show commands". */
1694 if (from_tty
&& args
)
1701 /* Called by do_setshow_command. */
1704 set_history_size_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
1706 if (history_size
== INT_MAX
)
1707 unstifle_history ();
1708 else if (history_size
>= 0)
1709 stifle_history (history_size
);
1712 history_size
= INT_MAX
;
1713 error ("History size must be non-negative");
1719 set_history (char *args
, int from_tty
)
1721 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
1722 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
1727 show_history (char *args
, int from_tty
)
1729 cmd_show_list (showhistlist
, from_tty
, "");
1732 int info_verbose
= 0; /* Default verbose msgs off */
1734 /* Called by do_setshow_command. An elaborate joke. */
1737 set_verbose (char *args
, int from_tty
, struct cmd_list_element
*c
)
1739 char *cmdname
= "verbose";
1740 struct cmd_list_element
*showcmd
;
1742 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
1746 c
->doc
= "Set verbose printing of informational messages.";
1747 showcmd
->doc
= "Show verbose printing of informational messages.";
1751 c
->doc
= "Set verbosity.";
1752 showcmd
->doc
= "Show verbosity.";
1756 /* Init the history buffer. Note that we are called after the init file(s)
1757 * have been read so that the user can change the history file via his
1758 * .gdbinit file (for instance). The GDBHISTFILE environment variable
1759 * overrides all of this.
1767 tmpenv
= getenv ("HISTSIZE");
1769 history_size
= atoi (tmpenv
);
1770 else if (!history_size
)
1773 stifle_history (history_size
);
1775 tmpenv
= getenv ("GDBHISTFILE");
1777 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
1778 else if (!history_filename
)
1780 /* We include the current directory so that if the user changes
1781 directories the file written will be the same as the one
1784 /* No leading dots in file names are allowed on MSDOS. */
1785 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
1787 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
1790 read_history (history_filename
);
1796 struct cmd_list_element
*c
;
1798 /* If we are running the asynchronous version,
1799 we initialize the prompts differently. */
1802 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
1806 /* initialize the prompt stack to a simple "(gdb) " prompt or to
1807 whatever the DEFAULT_PROMPT is. */
1808 the_prompts
.top
= 0;
1810 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
1812 /* Set things up for annotation_level > 1, if the user ever decides
1814 async_annotation_suffix
= "prompt";
1815 /* Set the variable associated with the setshow prompt command. */
1816 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
1818 /* If gdb was started with --annotate=2, this is equivalent to
1819 the user entering the command 'set annotate 2' at the gdb
1820 prompt, so we need to do extra processing. */
1821 if (annotation_level
> 1)
1822 set_async_annotation_level (NULL
, 0, NULL
);
1824 gdb_prompt_escape
= 0; /* default to none. */
1826 /* Set the important stuff up for command editing. */
1827 command_editing_p
= 1;
1828 history_expansion_p
= 0;
1829 write_history_p
= 0;
1831 /* Setup important stuff for command line editing. */
1832 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
1833 rl_completer_word_break_characters
=
1834 get_gdb_completer_word_break_characters ();
1835 rl_completer_quote_characters
= get_gdb_completer_quote_characters ();
1836 rl_readline_name
= "gdb";
1838 /* The set prompt command is different depending whether or not the
1839 async version is run. NOTE: this difference is going to
1840 disappear as we make the event loop be the default engine of
1845 (add_set_cmd ("prompt", class_support
, var_string
,
1846 (char *) &gdb_prompt_string
, "Set gdb's prompt",
1852 c
= add_set_cmd ("prompt", class_support
, var_string
,
1853 (char *) &new_async_prompt
, "Set gdb's prompt",
1855 add_show_from_set (c
, &showlist
);
1856 c
->function
.sfunc
= set_async_prompt
;
1860 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
1861 (char *) &gdb_prompt_escape
,
1862 "Set escape character for formatting of gdb's prompt",
1866 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
1867 Primarily used inside of user-defined commands that should not be repeated when\n\
1870 /* The set editing command is different depending whether or not the
1871 async version is run. NOTE: this difference is going to disappear
1872 as we make the event loop be the default engine of gdb. */
1876 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
1877 "Set editing of command lines as they are typed.\n\
1878 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1879 Without an argument, command line editing is enabled. To edit, use\n\
1880 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
1885 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
1886 "Set editing of command lines as they are typed.\n\
1887 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1888 Without an argument, command line editing is enabled. To edit, use\n\
1889 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
1891 add_show_from_set (c
, &showlist
);
1892 c
->function
.sfunc
= set_async_editing_command
;
1896 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
1897 "Set saving of the history record on exit.\n\
1898 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
1899 Without an argument, saving is enabled.", &sethistlist
),
1902 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
1903 "Set the size of the command history, \n\
1904 ie. the number of previous commands to keep a record of.", &sethistlist
);
1905 add_show_from_set (c
, &showhistlist
);
1906 c
->function
.sfunc
= set_history_size_command
;
1908 c
= add_set_cmd ("filename", no_class
, var_filename
,
1909 (char *) &history_filename
,
1910 "Set the filename in which to record the command history\n\
1911 (the list of previous commands of which a record is kept).", &sethistlist
);
1912 c
->completer
= filename_completer
;
1913 add_show_from_set (c
, &showhistlist
);
1916 (add_set_cmd ("confirm", class_support
, var_boolean
,
1918 "Set whether to confirm potentially dangerous operations.",
1922 /* The set annotate command is different depending whether or not
1923 the async version is run. NOTE: this difference is going to
1924 disappear as we make the event loop be the default engine of
1928 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
1929 (char *) &annotation_level
, "Set annotation_level.\n\
1930 0 == normal; 1 == fullname (for use when running under emacs)\n\
1931 2 == output annotated suitably for use by programs that control GDB.",
1933 c
= add_show_from_set (c
, &showlist
);
1937 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
1938 (char *) &annotation_level
, "Set annotation_level.\n\
1939 0 == normal; 1 == fullname (for use when running under emacs)\n\
1940 2 == output annotated suitably for use by programs that control GDB.",
1942 add_show_from_set (c
, &showlist
);
1943 c
->function
.sfunc
= set_async_annotation_level
;
1948 (add_set_cmd ("exec-done-display", class_support
, var_boolean
, (char *) &exec_done_display_p
,
1949 "Set notification of completion for asynchronous execution commands.\n\
1950 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist
),
1956 gdb_init (char *argv0
)
1958 if (pre_init_ui_hook
)
1959 pre_init_ui_hook ();
1961 /* Run the init function of each source file */
1963 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
1964 current_directory
= gdb_dirbuf
;
1967 /* Make sure we return to the original directory upon exit, come
1968 what may, since the OS doesn't do that for us. */
1969 make_final_cleanup (do_chdir_cleanup
, xstrdup (current_directory
));
1972 init_cmd_lists (); /* This needs to be done first */
1973 initialize_targets (); /* Setup target_terminal macros for utils.c */
1974 initialize_utils (); /* Make errors and warnings possible */
1975 initialize_all_files ();
1976 initialize_current_architecture ();
1978 init_main (); /* But that omits this file! Do it now */
1980 /* The signal handling mechanism is different depending whether or
1981 not the async version is run. NOTE: in the future we plan to make
1982 the event loop be the default engine of gdb, and this difference
1985 async_init_signals ();
1989 /* We need a default language for parsing expressions, so simple things like
1990 "set width 0" won't fail if no language is explicitly set in a config file
1991 or implicitly set by reading an executable during startup. */
1992 set_language (language_c
);
1993 expected_language
= current_language
; /* don't warn about the change. */
1996 /* Install the default UI */
1999 uiout
= cli_out_new (gdb_stdout
);
2001 /* All the interpreters should have had a look at things by now.
2002 Initialize the selected interpreter. */
2005 fprintf_unfiltered (gdb_stderr
, "Interpreter `%s' unrecognized.\n",
2013 init_ui_hook (argv0
);