1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 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. */
38 /* readline include files */
39 #include <readline/readline.h>
40 #include <readline/history.h>
42 /* readline defines this. */
45 #include <sys/types.h>
47 #include "event-loop.h"
48 #include "gdb_string.h"
52 /* Prototypes for local functions */
54 static void dont_repeat_command
PARAMS ((char *, int));
56 static void source_cleanup_lines
PARAMS ((PTR
));
58 static void user_defined_command
PARAMS ((char *, int));
60 static void init_signals
PARAMS ((void));
63 static void stop_sig
PARAMS ((int));
66 static char *line_completion_function
PARAMS ((char *, int, char *, int));
68 static char *readline_line_completion_function
PARAMS ((char *, int));
70 /* NOTE 1999-04-29: this function will be static again, after we make the
71 event loop be the default command loop for gdb, and we merge
72 event-top.c into this file, top.c */
73 /* static */ void command_loop_marker
PARAMS ((int));
75 static void while_command
PARAMS ((char *, int));
77 static void if_command
PARAMS ((char *, int));
79 static struct command_line
*
80 build_command_line
PARAMS ((enum command_control_type
, char *));
82 static struct command_line
*
83 get_command_line
PARAMS ((enum command_control_type
, char *));
85 static void realloc_body_list
PARAMS ((struct command_line
*, int));
87 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
89 static enum command_control_type
90 recurse_read_control_structure
PARAMS ((struct command_line
*));
92 static struct cleanup
*setup_user_args
PARAMS ((char *));
94 static char *locate_arg
PARAMS ((char *));
96 static char *insert_args
PARAMS ((char *));
98 static void arg_cleanup
PARAMS ((void));
100 static void init_main
PARAMS ((void));
102 static void init_cmd_lists
PARAMS ((void));
104 static void float_handler
PARAMS ((int));
106 static void init_signals
PARAMS ((void));
108 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
110 static void show_history
PARAMS ((char *, int));
112 static void set_history
PARAMS ((char *, int));
114 static void set_history_size_command
PARAMS ((char *, int,
115 struct cmd_list_element
*));
117 static void show_commands
PARAMS ((char *, int));
119 static void echo_command
PARAMS ((char *, int));
121 static void pwd_command
PARAMS ((char *, int));
123 static void show_version
PARAMS ((char *, int));
125 static void document_command
PARAMS ((char *, int));
127 static void define_command
PARAMS ((char *, int));
129 static void validate_comname
PARAMS ((char *));
131 static void help_command
PARAMS ((char *, int));
133 static void show_command
PARAMS ((char *, int));
135 static void info_command
PARAMS ((char *, int));
137 static void complete_command
PARAMS ((char *, int));
139 static void do_nothing
PARAMS ((int));
142 /* NOTE 1999-04-29: This function will be static again, once we modify
143 gdb to use the event loop as the default command loop and we merge
144 event-top.c into this file, top.c */
145 /* static */ int quit_cover
PARAMS ((PTR
));
147 static void disconnect
PARAMS ((int));
150 static void source_cleanup
PARAMS ((FILE *));
152 /* Default command line prompt. This is overriden in some configs. */
154 #ifndef DEFAULT_PROMPT
155 #define DEFAULT_PROMPT "(gdb) "
158 /* Initialization file name for gdb. This is overridden in some configs. */
160 #ifndef GDBINIT_FILENAME
161 #define GDBINIT_FILENAME ".gdbinit"
163 char gdbinit
[] = GDBINIT_FILENAME
;
165 int inhibit_gdbinit
= 0;
167 /* If nonzero, and GDB has been configured to be able to use windows,
168 attempt to open them upon startup. */
172 /* Version number of GDB, as a string. */
174 extern char *version
;
176 /* Canonical host name as a string. */
178 extern char *host_name
;
180 /* Canonical target name as a string. */
182 extern char *target_name
;
184 extern char lang_frame_mismatch_warn
[]; /* language.c */
186 /* Flag for whether we want all the "from_tty" gubbish printed. */
188 int caution
= 1; /* Default is yes, sigh. */
190 /* Define all cmd_list_elements. */
192 /* Chain containing all defined commands. */
194 struct cmd_list_element
*cmdlist
;
196 /* Chain containing all defined info subcommands. */
198 struct cmd_list_element
*infolist
;
200 /* Chain containing all defined enable subcommands. */
202 struct cmd_list_element
*enablelist
;
204 /* Chain containing all defined disable subcommands. */
206 struct cmd_list_element
*disablelist
;
208 /* Chain containing all defined toggle subcommands. */
210 struct cmd_list_element
*togglelist
;
212 /* Chain containing all defined stop subcommands. */
214 struct cmd_list_element
*stoplist
;
216 /* Chain containing all defined delete subcommands. */
218 struct cmd_list_element
*deletelist
;
220 /* Chain containing all defined "enable breakpoint" subcommands. */
222 struct cmd_list_element
*enablebreaklist
;
224 /* Chain containing all defined set subcommands */
226 struct cmd_list_element
*setlist
;
228 /* Chain containing all defined unset subcommands */
230 struct cmd_list_element
*unsetlist
;
232 /* Chain containing all defined show subcommands. */
234 struct cmd_list_element
*showlist
;
236 /* Chain containing all defined \"set history\". */
238 struct cmd_list_element
*sethistlist
;
240 /* Chain containing all defined \"show history\". */
242 struct cmd_list_element
*showhistlist
;
244 /* Chain containing all defined \"unset history\". */
246 struct cmd_list_element
*unsethistlist
;
248 /* Chain containing all defined maintenance subcommands. */
250 struct cmd_list_element
*maintenancelist
;
252 /* Chain containing all defined "maintenance info" subcommands. */
254 struct cmd_list_element
*maintenanceinfolist
;
256 /* Chain containing all defined "maintenance print" subcommands. */
258 struct cmd_list_element
*maintenanceprintlist
;
260 struct cmd_list_element
*setprintlist
;
262 struct cmd_list_element
*showprintlist
;
264 struct cmd_list_element
*setchecklist
;
266 struct cmd_list_element
*showchecklist
;
268 /* stdio stream that command input is being read from. Set to stdin normally.
269 Set by source_command to the file we are sourcing. Set to NULL if we are
270 executing a user-defined command or interacting via a GUI. */
274 /* Current working directory. */
276 char *current_directory
;
278 /* The directory name is actually stored here (usually). */
279 char gdb_dirbuf
[1024];
281 /* Function to call before reading a command, if nonzero.
282 The function receives two args: an input stream,
283 and a prompt string. */
285 void (*window_hook
) PARAMS ((FILE *, char *));
290 /* gdb prints this when reading a command interactively */
291 static char *gdb_prompt_string
; /* the global prompt string */
292 extern char *get_prompt
PARAMS ((void)); /* access function for prompt string */
294 /* Buffer used for reading command lines, and the size
295 allocated for it so far. */
300 /* Nonzero if the current command is modified by "server ". This
301 affects things like recording into the command history, comamnds
302 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
303 whatever) can issue its own commands and also send along commands
304 from the user, and have the user not notice that the user interface
305 is issuing commands too. */
308 /* Baud rate specified for talking to serial target systems. Default
309 is left as -1, so targets can choose their own defaults. */
310 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
311 or (unsigned int)-1. This is a Bad User Interface. */
315 /* Timeout limit for response from target. */
317 int remote_timeout
= 20; /* Set default to 20 */
319 /* Non-zero tells remote* modules to output debugging info. */
321 int remote_debug
= 0;
323 /* Non-zero means the target is running. Note: this is different from
324 saying that there is an active target and we are stopped at a
325 breakpoint, for instance. This is a real indicator whether the
326 target is off and running, which gdb is doing something else. */
327 int target_executing
= 0;
329 /* Level of control structure. */
330 static int control_level
;
332 /* Structure for arguments to user defined functions. */
333 #define MAXUSERARGS 10
336 struct user_args
*next
;
347 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
351 #define STOP_SIGNAL SIGTSTP
352 static void stop_sig
PARAMS ((int));
356 /* Some System V have job control but not sigsetmask(). */
357 #if !defined (HAVE_SIGSETMASK)
359 #define HAVE_SIGSETMASK 1
361 #define HAVE_SIGSETMASK 0
365 #if 0 == (HAVE_SIGSETMASK)
366 #define sigsetmask(n)
369 /* Hooks for alternate command interfaces. */
371 /* Called after most modules have been initialized, but before taking users
374 void (*init_ui_hook
) PARAMS ((char *argv0
));
376 /* This hook is called from within gdb's many mini-event loops which could
377 steal control from a real user interface's event loop. It returns
378 non-zero if the user is requesting a detach, zero otherwise. */
380 int (*ui_loop_hook
) PARAMS ((int));
382 /* Called instead of command_loop at top level. Can be invoked via
383 return_to_top_level. */
385 void (*command_loop_hook
) PARAMS ((void));
388 /* Called instead of fputs for all output. */
390 void (*fputs_unfiltered_hook
) PARAMS ((const char *linebuffer
, GDB_FILE
* stream
));
392 /* Called from print_frame_info to list the line we stopped in. */
394 void (*print_frame_info_listing_hook
) PARAMS ((struct symtab
* s
, int line
,
395 int stopline
, int noerror
));
396 /* Replaces most of query. */
398 int (*query_hook
) PARAMS ((const char *, va_list));
400 /* Replaces most of warning. */
402 void (*warning_hook
) PARAMS ((const char *, va_list));
404 /* Called from gdb_flush to flush output. */
406 void (*flush_hook
) PARAMS ((GDB_FILE
* stream
));
408 /* These three functions support getting lines of text from the user. They
409 are used in sequence. First readline_begin_hook is called with a text
410 string that might be (for example) a message for the user to type in a
411 sequence of commands to be executed at a breakpoint. If this function
412 calls back to a GUI, it might take this opportunity to pop up a text
413 interaction window with this message. Next, readline_hook is called
414 with a prompt that is emitted prior to collecting the user input.
415 It can be called multiple times. Finally, readline_end_hook is called
416 to notify the GUI that we are done with the interaction window and it
419 void (*readline_begin_hook
) PARAMS ((char *,...));
420 char *(*readline_hook
) PARAMS ((char *));
421 void (*readline_end_hook
) PARAMS ((void));
423 /* Called as appropriate to notify the interface of the specified breakpoint
426 void (*create_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
427 void (*delete_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
428 void (*modify_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
430 /* Called during long calculations to allow GUI to repair window damage, and to
431 check for stop buttons, etc... */
433 void (*interactive_hook
) PARAMS ((void));
435 /* Called when the registers have changed, as a hint to a GUI
436 to minimize window update. */
438 void (*registers_changed_hook
) PARAMS ((void));
440 /* Tell the GUI someone changed the register REGNO. -1 means
441 that the caller does not know which register changed or
442 that several registers have changed (see value_assign). */
443 void (*register_changed_hook
) PARAMS ((int regno
));
445 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
446 void (*memory_changed_hook
) PARAMS ((CORE_ADDR addr
, int len
));
448 /* Called when going to wait for the target. Usually allows the GUI to run
449 while waiting for target events. */
451 int (*target_wait_hook
) PARAMS ((int pid
, struct target_waitstatus
* status
));
453 /* Used by UI as a wrapper around command execution. May do various things
454 like enabling/disabling buttons, etc... */
456 void (*call_command_hook
) PARAMS ((struct cmd_list_element
* c
, char *cmd
,
459 /* Called after a `set' command has finished. Is only run if the
460 `set' command succeeded. */
462 void (*set_hook
) PARAMS ((struct cmd_list_element
*c
));
464 /* Called when the current thread changes. Argument is thread id. */
466 void (*context_hook
) PARAMS ((int id
));
468 /* Takes control from error (). Typically used to prevent longjmps out of the
469 middle of the GUI. Usually used in conjunction with a catch routine. */
471 NORETURN
void (*error_hook
)
472 PARAMS ((void)) ATTR_NORETURN
;
475 /* Where to go for return_to_top_level (RETURN_ERROR). */
476 SIGJMP_BUF error_return
;
477 /* Where to go for return_to_top_level (RETURN_QUIT). */
478 SIGJMP_BUF quit_return
;
480 /* Return for reason REASON. This generally gets back to the command
481 loop, but can be caught via catch_errors. */
484 return_to_top_level (reason
)
485 enum return_reason reason
;
490 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
491 I can think of a reason why that is vital, though). */
492 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
494 disable_current_display ();
495 do_cleanups (ALL_CLEANUPS
);
496 if (async_p
&& target_has_async
)
497 do_exec_cleanups (ALL_CLEANUPS
);
499 if (annotation_level
> 1)
510 (NORETURN
void) SIGLONGJMP
511 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
514 /* Call FUNC with arg ARGS, catching any errors. If there is no
515 error, return the value returned by FUNC. If there is an error,
516 print ERRSTRING, print the specific error message, then return
519 Must not be called with immediate_quit in effect (bad things might
520 happen, say we got a signal in the middle of a memcpy to quit_return).
521 This is an OK restriction; with very few exceptions immediate_quit can
522 be replaced by judicious use of QUIT.
524 MASK specifies what to catch; it is normally set to
525 RETURN_MASK_ALL, if for no other reason than that the code which
526 calls catch_errors might not be set up to deal with a quit which
527 isn't caught. But if the code can deal with it, it generally
528 should be RETURN_MASK_ERROR, unless for some reason it is more
529 useful to abort only the portion of the operation inside the
530 catch_errors. Note that quit should return to the command line
531 fairly quickly, even if some further processing is being done. */
534 catch_errors (func
, args
, errstring
, mask
)
535 catch_errors_ftype
*func
;
540 SIGJMP_BUF saved_error
;
541 SIGJMP_BUF saved_quit
;
544 struct cleanup
*saved_cleanup_chain
;
545 char *saved_error_pre_print
;
546 char *saved_quit_pre_print
;
548 saved_cleanup_chain
= save_cleanups ();
549 saved_error_pre_print
= error_pre_print
;
550 saved_quit_pre_print
= quit_pre_print
;
552 if (mask
& RETURN_MASK_ERROR
)
554 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (SIGJMP_BUF
));
555 error_pre_print
= errstring
;
557 if (mask
& RETURN_MASK_QUIT
)
559 memcpy (saved_quit
, quit_return
, sizeof (SIGJMP_BUF
));
560 quit_pre_print
= errstring
;
563 if (SIGSETJMP (tmp_jmp
) == 0)
565 if (mask
& RETURN_MASK_ERROR
)
566 memcpy (error_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
567 if (mask
& RETURN_MASK_QUIT
)
568 memcpy (quit_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
569 val
= (*func
) (args
);
574 restore_cleanups (saved_cleanup_chain
);
576 if (mask
& RETURN_MASK_ERROR
)
578 memcpy (error_return
, saved_error
, sizeof (SIGJMP_BUF
));
579 error_pre_print
= saved_error_pre_print
;
581 if (mask
& RETURN_MASK_QUIT
)
583 memcpy (quit_return
, saved_quit
, sizeof (SIGJMP_BUF
));
584 quit_pre_print
= saved_quit_pre_print
;
589 /* Handler for SIGHUP. */
596 catch_errors (quit_cover
, NULL
,
597 "Could not kill the program being debugged", RETURN_MASK_ALL
);
598 signal (SIGHUP
, SIG_DFL
);
599 kill (getpid (), SIGHUP
);
602 /* Just a little helper function for disconnect(). */
604 /* NOTE 1999-04-29: This function will be static again, once we modify
605 gdb to use the event loop as the default command loop and we merge
606 event-top.c into this file, top.c */
611 caution
= 0; /* Throw caution to the wind -- we're exiting.
612 This prevents asking the user dumb questions. */
613 quit_command ((char *) 0, 0);
616 #endif /* defined SIGHUP */
618 /* Line number we are currently in in a file which is being sourced. */
619 /* NOTE 1999-04-29: This variable will be static again, once we modify
620 gdb to use the event loop as the default command loop and we merge
621 event-top.c into this file, top.c */
622 /* static */ int source_line_number
;
624 /* Name of the file we are sourcing. */
625 /* NOTE 1999-04-29: This variable will be static again, once we modify
626 gdb to use the event loop as the default command loop and we merge
627 event-top.c into this file, top.c */
628 /* static */ char *source_file_name
;
630 /* Buffer containing the error_pre_print used by the source stuff.
632 /* NOTE 1999-04-29: This variable will be static again, once we modify
633 gdb to use the event loop as the default command loop and we merge
634 event-top.c into this file, top.c */
635 /* static */ char *source_error
;
636 static int source_error_allocated
;
638 /* Something to glom on to the start of error_pre_print if source_file_name
640 /* NOTE 1999-04-29: This variable will be static again, once we modify
641 gdb to use the event loop as the default command loop and we merge
642 event-top.c into this file, top.c */
643 /* static */ char *source_pre_error
;
645 /* Clean up on error during a "source" command (or execution of a
646 user-defined command). */
649 source_cleanup (stream
)
652 /* Restore the previous input stream. */
656 /* Read commands from STREAM. */
658 read_command_file (stream
)
661 struct cleanup
*cleanups
;
663 cleanups
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
666 do_cleanups (cleanups
);
669 extern void init_proc
PARAMS ((void));
671 void (*pre_init_ui_hook
) PARAMS ((void));
677 if (pre_init_ui_hook
)
680 /* Run the init function of each source file */
682 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
683 current_directory
= gdb_dirbuf
;
686 /* Make sure we return to the original directory upon exit, come
687 what may, since the OS doesn't do that for us. */
688 make_final_cleanup ((make_cleanup_func
) chdir
, strsave (current_directory
));
691 init_cmd_lists (); /* This needs to be done first */
692 initialize_targets (); /* Setup target_terminal macros for utils.c */
693 initialize_utils (); /* Make errors and warnings possible */
694 initialize_all_files ();
695 init_main (); /* But that omits this file! Do it now */
697 /* The signal handling mechanism is different depending whether or
698 not the async version is run. NOTE: in the future we plan to make
699 the event loop be the default engine of gdb, and this difference
702 async_init_signals ();
706 /* We need a default language for parsing expressions, so simple things like
707 "set width 0" won't fail if no language is explicitly set in a config file
708 or implicitly set by reading an executable during startup. */
709 set_language (language_c
);
710 expected_language
= current_language
; /* don't warn about the change. */
712 /* All the interpreters should have had a look at things by now.
713 Initialize the selected interpreter. */
715 init_ui_hook (argv0
);
718 /* Allocate, initialize a new command line structure for one of the
719 control commands (if/while). */
721 static struct command_line
*
722 build_command_line (type
, args
)
723 enum command_control_type type
;
726 struct command_line
*cmd
;
729 error ("if/while commands require arguments.\n");
731 cmd
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
733 cmd
->control_type
= type
;
737 = (struct command_line
**) xmalloc (sizeof (struct command_line
*)
739 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
740 cmd
->line
= savestring (args
, strlen (args
));
744 /* Build and return a new command structure for the control commands
745 such as "if" and "while". */
747 static struct command_line
*
748 get_command_line (type
, arg
)
749 enum command_control_type type
;
752 struct command_line
*cmd
;
753 struct cleanup
*old_chain
= NULL
;
755 /* Allocate and build a new command line structure. */
756 cmd
= build_command_line (type
, arg
);
758 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
, &cmd
);
760 /* Read in the body of this command. */
761 if (recurse_read_control_structure (cmd
) == invalid_control
)
763 warning ("error reading in control structure\n");
764 do_cleanups (old_chain
);
768 discard_cleanups (old_chain
);
772 /* Recursively print a command (including full control structures). */
774 print_command_line (cmd
, depth
, stream
)
775 struct command_line
*cmd
;
783 for (i
= 0; i
< depth
; i
++)
784 fputs_filtered (" ", stream
);
787 /* A simple command, print it and return. */
788 if (cmd
->control_type
== simple_control
)
790 fputs_filtered (cmd
->line
, stream
);
791 fputs_filtered ("\n", stream
);
795 /* loop_continue to jump to the start of a while loop, print it
797 if (cmd
->control_type
== continue_control
)
799 fputs_filtered ("loop_continue\n", stream
);
803 /* loop_break to break out of a while loop, print it and return. */
804 if (cmd
->control_type
== break_control
)
806 fputs_filtered ("loop_break\n", stream
);
810 /* A while command. Recursively print its subcommands before returning. */
811 if (cmd
->control_type
== while_control
)
813 struct command_line
*list
;
814 fputs_filtered ("while ", stream
);
815 fputs_filtered (cmd
->line
, stream
);
816 fputs_filtered ("\n", stream
);
817 list
= *cmd
->body_list
;
820 print_command_line (list
, depth
+ 1, stream
);
825 /* An if command. Recursively print both arms before returning. */
826 if (cmd
->control_type
== if_control
)
828 fputs_filtered ("if ", stream
);
829 fputs_filtered (cmd
->line
, stream
);
830 fputs_filtered ("\n", stream
);
832 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
834 /* Show the false arm if it exists. */
835 if (cmd
->body_count
== 2)
839 for (i
= 0; i
< depth
; i
++)
840 fputs_filtered (" ", stream
);
842 fputs_filtered ("else\n", stream
);
843 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
847 for (i
= 0; i
< depth
; i
++)
848 fputs_filtered (" ", stream
);
850 fputs_filtered ("end\n", stream
);
854 /* Execute the command in CMD. */
856 enum command_control_type
857 execute_control_command (cmd
)
858 struct command_line
*cmd
;
860 struct expression
*expr
;
861 struct command_line
*current
;
862 struct cleanup
*old_chain
= 0;
866 enum command_control_type ret
;
869 switch (cmd
->control_type
)
872 /* A simple command, execute it and return. */
873 new_line
= insert_args (cmd
->line
);
875 return invalid_control
;
876 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
878 execute_command (new_line
, 0);
879 ret
= cmd
->control_type
;
882 case continue_control
:
884 /* Return for "continue", and "break" so we can either
885 continue the loop at the top, or break out. */
886 ret
= cmd
->control_type
;
891 /* Parse the loop control expression for the while statement. */
892 new_line
= insert_args (cmd
->line
);
894 return invalid_control
;
895 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
897 expr
= parse_expression (new_line
);
898 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
900 ret
= simple_control
;
903 /* Keep iterating so long as the expression is true. */
910 /* Evaluate the expression. */
911 val_mark
= value_mark ();
912 val
= evaluate_expression (expr
);
913 cond_result
= value_true (val
);
914 value_free_to_mark (val_mark
);
916 /* If the value is false, then break out of the loop. */
920 /* Execute the body of the while statement. */
921 current
= *cmd
->body_list
;
924 ret
= execute_control_command (current
);
926 /* If we got an error, or a "break" command, then stop
928 if (ret
== invalid_control
|| ret
== break_control
)
934 /* If we got a "continue" command, then restart the loop
936 if (ret
== continue_control
)
939 /* Get the next statement. */
940 current
= current
->next
;
944 /* Reset RET so that we don't recurse the break all the way down. */
945 if (ret
== break_control
)
946 ret
= simple_control
;
953 new_line
= insert_args (cmd
->line
);
955 return invalid_control
;
956 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
958 /* Parse the conditional for the if statement. */
959 expr
= parse_expression (new_line
);
960 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
963 ret
= simple_control
;
965 /* Evaluate the conditional. */
966 val_mark
= value_mark ();
967 val
= evaluate_expression (expr
);
969 /* Choose which arm to take commands from based on the value of the
970 conditional expression. */
971 if (value_true (val
))
972 current
= *cmd
->body_list
;
973 else if (cmd
->body_count
== 2)
974 current
= *(cmd
->body_list
+ 1);
975 value_free_to_mark (val_mark
);
977 /* Execute commands in the given arm. */
980 ret
= execute_control_command (current
);
982 /* If we got an error, get out. */
983 if (ret
!= simple_control
)
986 /* Get the next statement in the body. */
987 current
= current
->next
;
994 warning ("Invalid control type in command structure.");
995 return invalid_control
;
999 do_cleanups (old_chain
);
1004 /* "while" command support. Executes a body of statements while the
1005 loop condition is nonzero. */
1008 while_command (arg
, from_tty
)
1012 struct command_line
*command
= NULL
;
1015 command
= get_command_line (while_control
, arg
);
1017 if (command
== NULL
)
1020 execute_control_command (command
);
1021 free_command_lines (&command
);
1024 /* "if" command support. Execute either the true or false arm depending
1025 on the value of the if conditional. */
1028 if_command (arg
, from_tty
)
1032 struct command_line
*command
= NULL
;
1035 command
= get_command_line (if_control
, arg
);
1037 if (command
== NULL
)
1040 execute_control_command (command
);
1041 free_command_lines (&command
);
1048 struct user_args
*oargs
= user_args
;
1050 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1052 user_args
= user_args
->next
;
1056 /* Bind the incomming arguments for a user defined command to
1057 $arg0, $arg1 ... $argMAXUSERARGS. */
1059 static struct cleanup
*
1063 struct user_args
*args
;
1064 struct cleanup
*old_chain
;
1065 unsigned int arg_count
= 0;
1067 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
1068 memset (args
, 0, sizeof (struct user_args
));
1070 args
->next
= user_args
;
1073 old_chain
= make_cleanup ((make_cleanup_func
) arg_cleanup
, 0);
1085 if (arg_count
>= MAXUSERARGS
)
1087 error ("user defined function may only have %d arguments.\n",
1092 /* Strip whitespace. */
1093 while (*p
== ' ' || *p
== '\t')
1096 /* P now points to an argument. */
1098 user_args
->a
[arg_count
].arg
= p
;
1100 /* Get to the end of this argument. */
1103 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1109 else if (*p
== '\\')
1132 user_args
->a
[arg_count
].len
= p
- start_arg
;
1139 /* Given character string P, return a point to the first argument ($arg),
1140 or NULL if P contains no arguments. */
1146 while ((p
= strchr (p
, '$')))
1148 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1155 /* Insert the user defined arguments stored in user_arg into the $arg
1156 arguments found in line, with the updated copy being placed into nline. */
1162 char *p
, *save_line
, *new_line
;
1165 /* First we need to know how much memory to allocate for the new line. */
1168 while ((p
= locate_arg (line
)))
1173 if (i
>= user_args
->count
)
1175 error ("Missing argument %d in user function.\n", i
);
1178 len
+= user_args
->a
[i
].len
;
1182 /* Don't forget the tail. */
1183 len
+= strlen (line
);
1185 /* Allocate space for the new line and fill it in. */
1186 new_line
= (char *) xmalloc (len
+ 1);
1187 if (new_line
== NULL
)
1190 /* Restore pointer to beginning of old line. */
1193 /* Save pointer to beginning of new line. */
1194 save_line
= new_line
;
1196 while ((p
= locate_arg (line
)))
1200 memcpy (new_line
, line
, p
- line
);
1201 new_line
+= p
- line
;
1204 len
= user_args
->a
[i
].len
;
1207 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1212 /* Don't forget the tail. */
1213 strcpy (new_line
, line
);
1215 /* Return a pointer to the beginning of the new line. */
1220 execute_user_command (c
, args
)
1221 struct cmd_list_element
*c
;
1224 register struct command_line
*cmdlines
;
1225 struct cleanup
*old_chain
;
1226 enum command_control_type ret
;
1228 old_chain
= setup_user_args (args
);
1230 cmdlines
= c
->user_commands
;
1235 /* Set the instream to 0, indicating execution of a
1236 user-defined function. */
1237 old_chain
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
1238 instream
= (FILE *) 0;
1241 ret
= execute_control_command (cmdlines
);
1242 if (ret
!= simple_control
&& ret
!= break_control
)
1244 warning ("Error in control structure.\n");
1247 cmdlines
= cmdlines
->next
;
1249 do_cleanups (old_chain
);
1252 /* Execute the line P as a command.
1253 Pass FROM_TTY as second argument to the defining function. */
1256 execute_command (p
, from_tty
)
1260 register struct cmd_list_element
*c
;
1261 register enum language flang
;
1262 static int warned
= 0;
1263 /* FIXME: These should really be in an appropriate header file */
1264 extern void serial_log_command
PARAMS ((const char *));
1268 /* Force cleanup of any alloca areas if using C alloca instead of
1269 a builtin alloca. */
1272 /* This can happen when command_line_input hits end of file. */
1276 serial_log_command (p
);
1278 while (*p
== ' ' || *p
== '\t')
1284 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1286 /* If the target is running, we allow only a limited set of
1288 if (async_p
&& target_has_async
&& target_executing
)
1289 if (!strcmp (c
->name
, "help")
1290 && !strcmp (c
->name
, "pwd")
1291 && !strcmp (c
->name
, "show")
1292 && !strcmp (c
->name
, "stop"))
1293 error ("Cannot execute this command while the target is running.");
1295 /* Pass null arg rather than an empty one. */
1298 /* Clear off trailing whitespace, except for set and complete command. */
1299 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1301 p
= arg
+ strlen (arg
) - 1;
1302 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1307 /* If this command has been hooked, run the hook first. */
1309 execute_user_command (c
->hook
, (char *) 0);
1311 if (c
->class == class_user
)
1312 execute_user_command (c
, arg
);
1313 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1314 do_setshow_command (arg
, from_tty
& caution
, c
);
1315 else if (c
->function
.cfunc
== NO_FUNCTION
)
1316 error ("That is not a command, just a help topic.");
1317 else if (call_command_hook
)
1318 call_command_hook (c
, arg
, from_tty
& caution
);
1320 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1323 /* Tell the user if the language has changed (except first time). */
1324 if (current_language
!= expected_language
)
1326 if (language_mode
== language_mode_auto
)
1328 language_info (1); /* Print what changed. */
1333 /* Warn the user if the working language does not match the
1334 language of the current frame. Only warn the user if we are
1335 actually running the program, i.e. there is a stack. */
1336 /* FIXME: This should be cacheing the frame and only running when
1337 the frame changes. */
1339 if (target_has_stack
)
1341 flang
= get_frame_language ();
1343 && flang
!= language_unknown
1344 && flang
!= current_language
->la_language
)
1346 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1353 /* NOTE 1999-04-29: This function will be static again, once we modify
1354 gdb to use the event loop as the default command loop and we merge
1355 event-top.c into this file, top.c */
1357 command_loop_marker (foo
)
1362 /* Read commands from `instream' and execute them
1363 until end of file or error reading instream. */
1368 struct cleanup
*old_chain
;
1370 int stdin_is_tty
= ISATTY (stdin
);
1371 long time_at_cmd_start
;
1373 long space_at_cmd_start
= 0;
1375 extern int display_time
;
1376 extern int display_space
;
1378 while (instream
&& !feof (instream
))
1381 extern int insert_mode
;
1383 if (window_hook
&& instream
== stdin
)
1384 (*window_hook
) (instream
, get_prompt ());
1387 if (instream
== stdin
&& stdin_is_tty
)
1388 reinitialize_more_filter ();
1389 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1392 /* A bit of paranoia: I want to make sure the "insert_mode" global
1393 * is clear except when it is being used for command-line editing
1394 * (see tuiIO.c, utils.c); otherwise normal output will
1395 * get messed up in the TUI. So clear it before/after
1396 * the command-line-input call. - RT
1400 /* Get a command-line. This calls the readline package. */
1401 command
= command_line_input (instream
== stdin
?
1402 get_prompt () : (char *) NULL
,
1403 instream
== stdin
, "prompt");
1410 time_at_cmd_start
= get_run_time ();
1415 extern char **environ
;
1416 char *lim
= (char *) sbrk (0);
1418 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1422 execute_command (command
, instream
== stdin
);
1423 /* Do any commands attached to breakpoint we stopped at. */
1424 bpstat_do_actions (&stop_bpstat
);
1425 do_cleanups (old_chain
);
1429 long cmd_time
= get_run_time () - time_at_cmd_start
;
1431 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1432 cmd_time
/ 1000000, cmd_time
% 1000000);
1438 extern char **environ
;
1439 char *lim
= (char *) sbrk (0);
1440 long space_now
= lim
- (char *) &environ
;
1441 long space_diff
= space_now
- space_at_cmd_start
;
1443 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1445 (space_diff
>= 0 ? '+' : '-'),
1453 /* Commands call this if they do not want to be repeated by null lines. */
1461 /* If we aren't reading from standard input, we are saving the last
1462 thing read from stdin in line and don't want to delete it. Null lines
1463 won't repeat here in any case. */
1464 if (instream
== stdin
)
1468 /* Read a line from the stream "instream" without command line editing.
1470 It prints PROMPT_ARG once at the start.
1471 Action is compatible with "readline", e.g. space for the result is
1472 malloc'd and should be freed by the caller.
1474 A NULL return means end of file. */
1476 gdb_readline (prompt_arg
)
1481 int input_index
= 0;
1482 int result_size
= 80;
1486 /* Don't use a _filtered function here. It causes the assumed
1487 character position to be off, since the newline we read from
1488 the user is not accounted for. */
1489 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1491 /* Move to a new line so the entered line doesn't have a prompt
1492 on the front of it. */
1493 fputs_unfiltered ("\n", gdb_stdout
);
1495 gdb_flush (gdb_stdout
);
1498 result
= (char *) xmalloc (result_size
);
1502 /* Read from stdin if we are executing a user defined command.
1503 This is the right thing for prompt_for_continue, at least. */
1504 c
= fgetc (instream
? instream
: stdin
);
1508 if (input_index
> 0)
1509 /* The last line does not end with a newline. Return it, and
1510 if we are called again fgetc will still return EOF and
1511 we'll return NULL then. */
1518 #ifndef CRLF_SOURCE_FILES
1522 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1528 result
[input_index
++] = c
;
1529 while (input_index
>= result_size
)
1532 result
= (char *) xrealloc (result
, result_size
);
1536 result
[input_index
++] = '\0';
1540 /* Variables which control command line editing and history
1541 substitution. These variables are given default values at the end
1543 static int command_editing_p
;
1544 /* NOTE 1999-04-29: This variable will be static again, once we modify
1545 gdb to use the event loop as the default command loop and we merge
1546 event-top.c into this file, top.c */
1547 /* static */ int history_expansion_p
;
1548 static int write_history_p
;
1549 static int history_size
;
1550 static char *history_filename
;
1552 /* readline uses the word breaks for two things:
1553 (1) In figuring out where to point the TEXT parameter to the
1554 rl_completion_entry_function. Since we don't use TEXT for much,
1555 it doesn't matter a lot what the word breaks are for this purpose, but
1556 it does affect how much stuff M-? lists.
1557 (2) If one of the matches contains a word break character, readline
1558 will quote it. That's why we switch between
1559 gdb_completer_word_break_characters and
1560 gdb_completer_command_word_break_characters. I'm not sure when
1561 we need this behavior (perhaps for funky characters in C++ symbols?). */
1563 /* Variables which are necessary for fancy command line editing. */
1564 char *gdb_completer_word_break_characters
=
1565 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1567 /* When completing on command names, we remove '-' from the list of
1568 word break characters, since we use it in command names. If the
1569 readline library sees one in any of the current completion strings,
1570 it thinks that the string needs to be quoted and automatically supplies
1572 char *gdb_completer_command_word_break_characters
=
1573 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1575 /* Characters that can be used to quote completion strings. Note that we
1576 can't include '"' because the gdb C parser treats such quoted sequences
1578 char *gdb_completer_quote_characters
=
1581 /* Functions that are used as part of the fancy command line editing. */
1583 /* This can be used for functions which don't want to complete on symbols
1584 but don't want to complete on anything else either. */
1587 noop_completer (text
, prefix
)
1594 /* Complete on filenames. */
1596 filename_completer (text
, word
)
1600 /* From readline. */
1601 extern char *filename_completion_function
PARAMS ((char *, int));
1602 int subsequent_name
;
1604 int return_val_used
;
1605 int return_val_alloced
;
1607 return_val_used
= 0;
1608 /* Small for testing. */
1609 return_val_alloced
= 1;
1610 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1612 subsequent_name
= 0;
1616 p
= filename_completion_function (text
, subsequent_name
);
1617 if (return_val_used
>= return_val_alloced
)
1619 return_val_alloced
*= 2;
1621 (char **) xrealloc (return_val
,
1622 return_val_alloced
* sizeof (char *));
1626 return_val
[return_val_used
++] = p
;
1629 /* Like emacs, don't complete on old versions. Especially useful
1630 in the "source" command. */
1631 if (p
[strlen (p
) - 1] == '~')
1637 /* Return exactly p. */
1638 return_val
[return_val_used
++] = p
;
1639 else if (word
> text
)
1641 /* Return some portion of p. */
1642 q
= xmalloc (strlen (p
) + 5);
1643 strcpy (q
, p
+ (word
- text
));
1644 return_val
[return_val_used
++] = q
;
1649 /* Return some of TEXT plus p. */
1650 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1651 strncpy (q
, word
, text
- word
);
1652 q
[text
- word
] = '\0';
1654 return_val
[return_val_used
++] = q
;
1658 subsequent_name
= 1;
1661 /* There is no way to do this just long enough to affect quote inserting
1662 without also affecting the next completion. This should be fixed in
1664 /* Insure that readline does the right thing
1665 with respect to inserting quotes. */
1666 rl_completer_word_break_characters
= "";
1671 /* Here are some useful test cases for completion. FIXME: These should
1672 be put in the test suite. They should be tested with both M-? and TAB.
1674 "show output-" "radix"
1675 "show output" "-radix"
1676 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1677 "p " ambiguous (all symbols)
1678 "info t foo" no completions
1679 "info t " no completions
1680 "info t" ambiguous ("info target", "info terminal", etc.)
1681 "info ajksdlfk" no completions
1682 "info ajksdlfk " no completions
1684 "info " ambiguous (all info commands)
1685 "p \"a" no completions (string constant)
1686 "p 'a" ambiguous (all symbols starting with a)
1687 "p b-a" ambiguous (all symbols starting with a)
1688 "p b-" ambiguous (all symbols)
1689 "file Make" "file" (word break hard to screw up here)
1690 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1693 /* Generate completions one by one for the completer. Each time we are
1694 called return another potential completion to the caller.
1695 line_completion just completes on commands or passes the buck to the
1696 command's completer function, the stuff specific to symbol completion
1697 is in make_symbol_completion_list.
1699 TEXT is the caller's idea of the "word" we are looking at.
1701 MATCHES is the number of matches that have currently been collected from
1702 calling this completion function. When zero, then we need to initialize,
1703 otherwise the initialization has already taken place and we can just
1704 return the next potential completion string.
1706 LINE_BUFFER is available to be looked at; it contains the entire text
1707 of the line. POINT is the offset in that line of the cursor. You
1708 should pretend that the line ends at POINT.
1710 Returns NULL if there are no more completions, else a pointer to a string
1711 which is a possible completion, it is the caller's responsibility to
1715 line_completion_function (text
, matches
, line_buffer
, point
)
1721 static char **list
= (char **) NULL
; /* Cache of completions */
1722 static int index
; /* Next cached completion */
1723 char *output
= NULL
;
1724 char *tmp_command
, *p
;
1725 /* Pointer within tmp_command which corresponds to text. */
1727 struct cmd_list_element
*c
, *result_list
;
1731 /* The caller is beginning to accumulate a new set of completions, so
1732 we need to find all of them now, and cache them for returning one at
1733 a time on future calls. */
1737 /* Free the storage used by LIST, but not by the strings inside.
1738 This is because rl_complete_internal () frees the strings. */
1744 /* Choose the default set of word break characters to break completions.
1745 If we later find out that we are doing completions on command strings
1746 (as opposed to strings supplied by the individual command completer
1747 functions, which can be any string) then we will switch to the
1748 special word break set for command strings, which leaves out the
1749 '-' character used in some commands. */
1751 rl_completer_word_break_characters
=
1752 gdb_completer_word_break_characters
;
1754 /* Decide whether to complete on a list of gdb commands or on symbols. */
1755 tmp_command
= (char *) alloca (point
+ 1);
1758 strncpy (tmp_command
, line_buffer
, point
);
1759 tmp_command
[point
] = '\0';
1760 /* Since text always contains some number of characters leading up
1761 to point, we can find the equivalent position in tmp_command
1762 by subtracting that many characters from the end of tmp_command. */
1763 word
= tmp_command
+ point
- strlen (text
);
1767 /* An empty line we want to consider ambiguous; that is, it
1768 could be any command. */
1769 c
= (struct cmd_list_element
*) -1;
1774 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1777 /* Move p up to the next interesting thing. */
1778 while (*p
== ' ' || *p
== '\t')
1785 /* It is an unrecognized command. So there are no
1786 possible completions. */
1789 else if (c
== (struct cmd_list_element
*) -1)
1793 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1794 doesn't advance over that thing itself. Do so now. */
1796 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1798 if (q
!= tmp_command
+ point
)
1800 /* There is something beyond the ambiguous
1801 command, so there are no possible completions. For
1802 example, "info t " or "info t foo" does not complete
1803 to anything, because "info t" can be "info target" or
1809 /* We're trying to complete on the command which was ambiguous.
1810 This we can deal with. */
1813 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1818 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1820 /* Insure that readline does the right thing with respect to
1821 inserting quotes. */
1822 rl_completer_word_break_characters
=
1823 gdb_completer_command_word_break_characters
;
1828 /* We've recognized a full command. */
1830 if (p
== tmp_command
+ point
)
1832 /* There is no non-whitespace in the line beyond the command. */
1834 if (p
[-1] == ' ' || p
[-1] == '\t')
1836 /* The command is followed by whitespace; we need to complete
1837 on whatever comes after command. */
1840 /* It is a prefix command; what comes after it is
1841 a subcommand (e.g. "info "). */
1842 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1844 /* Insure that readline does the right thing
1845 with respect to inserting quotes. */
1846 rl_completer_word_break_characters
=
1847 gdb_completer_command_word_break_characters
;
1851 list
= complete_on_enum (c
->enums
, p
, word
);
1852 rl_completer_word_break_characters
=
1853 gdb_completer_command_word_break_characters
;
1857 /* It is a normal command; what comes after it is
1858 completed by the command's completer function. */
1859 list
= (*c
->completer
) (p
, word
);
1864 /* The command is not followed by whitespace; we need to
1865 complete on the command itself. e.g. "p" which is a
1866 command itself but also can complete to "print", "ptype"
1870 /* Find the command we are completing on. */
1872 while (q
> tmp_command
)
1874 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1880 list
= complete_on_cmdlist (result_list
, q
, word
);
1882 /* Insure that readline does the right thing
1883 with respect to inserting quotes. */
1884 rl_completer_word_break_characters
=
1885 gdb_completer_command_word_break_characters
;
1890 /* There is non-whitespace beyond the command. */
1892 if (c
->prefixlist
&& !c
->allow_unknown
)
1894 /* It is an unrecognized subcommand of a prefix command,
1895 e.g. "info adsfkdj". */
1900 list
= complete_on_enum (c
->enums
, p
, word
);
1904 /* It is a normal command. */
1905 list
= (*c
->completer
) (p
, word
);
1911 /* If we found a list of potential completions during initialization then
1912 dole them out one at a time. The vector of completions is NULL
1913 terminated, so after returning the last one, return NULL (and continue
1914 to do so) each time we are called after that, until a new list is
1919 output
= list
[index
];
1927 /* Can't do this because readline hasn't yet checked the word breaks
1928 for figuring out whether to insert a quote. */
1930 /* Make sure the word break characters are set back to normal for the
1931 next time that readline tries to complete something. */
1932 rl_completer_word_break_characters
=
1933 gdb_completer_word_break_characters
;
1939 /* Line completion interface function for readline. */
1942 readline_line_completion_function (text
, matches
)
1946 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
1949 /* Skip over a possibly quoted word (as defined by the quote characters
1950 and word break characters the completer uses). Returns pointer to the
1951 location after the "word". */
1957 char quote_char
= '\0';
1960 for (scan
= str
; *scan
!= '\0'; scan
++)
1962 if (quote_char
!= '\0')
1964 /* Ignore everything until the matching close quote char */
1965 if (*scan
== quote_char
)
1967 /* Found matching close quote. */
1972 else if (strchr (gdb_completer_quote_characters
, *scan
))
1974 /* Found start of a quoted string. */
1977 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1991 #if STOP_SIGNAL == SIGTSTP
1992 signal (SIGTSTP
, SIG_DFL
);
1994 kill (getpid (), SIGTSTP
);
1995 signal (SIGTSTP
, stop_sig
);
1997 signal (STOP_SIGNAL
, stop_sig
);
1999 printf_unfiltered ("%s", get_prompt ());
2000 gdb_flush (gdb_stdout
);
2002 /* Forget about any previous command -- null line now will do nothing. */
2005 #endif /* STOP_SIGNAL */
2007 /* Initialize signal handlers. */
2012 /* Under System V the default disposition of a signal is reinstated after
2013 the signal is caught and delivered to an application process. On such
2014 systems one must restore the replacement signal handler if one wishes
2015 to continue handling the signal in one's program. On BSD systems this
2016 is not needed but it is harmless, and it simplifies the code to just do
2017 it unconditionally. */
2018 signal (signo
, do_nothing
);
2024 signal (SIGINT
, request_quit
);
2026 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2027 to the inferior and breakpoints will be ignored. */
2029 signal (SIGTRAP
, SIG_DFL
);
2032 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2033 passed to the inferior, which we don't want. It would be
2034 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2035 on BSD4.3 systems using vfork, that can affect the
2036 GDB process as well as the inferior (the signal handling tables
2037 might be in memory, shared between the two). Since we establish
2038 a handler for SIGQUIT, when we call exec it will set the signal
2039 to SIG_DFL for us. */
2040 signal (SIGQUIT
, do_nothing
);
2042 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
2043 signal (SIGHUP
, disconnect
);
2045 signal (SIGFPE
, float_handler
);
2047 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2048 signal (SIGWINCH
, SIGWINCH_HANDLER
);
2052 /* Read one line from the command input stream `instream'
2053 into the local static buffer `linebuffer' (whose current length
2055 The buffer is made bigger as necessary.
2056 Returns the address of the start of the line.
2058 NULL is returned for end of file.
2060 *If* the instream == stdin & stdin is a terminal, the line read
2061 is copied into the file line saver (global var char *line,
2062 length linesize) so that it can be duplicated.
2064 This routine either uses fancy command line editing or
2065 simple input as the user has requested. */
2068 command_line_input (prompt_arg
, repeat
, annotation_suffix
)
2071 char *annotation_suffix
;
2073 static char *linebuffer
= 0;
2074 static unsigned linelength
= 0;
2078 char *local_prompt
= prompt_arg
;
2082 /* The annotation suffix must be non-NULL. */
2083 if (annotation_suffix
== NULL
)
2084 annotation_suffix
= "";
2086 if (annotation_level
> 1 && instream
== stdin
)
2088 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
2089 + strlen (annotation_suffix
) + 40);
2090 if (prompt_arg
== NULL
)
2091 local_prompt
[0] = '\0';
2093 strcpy (local_prompt
, prompt_arg
);
2094 strcat (local_prompt
, "\n\032\032");
2095 strcat (local_prompt
, annotation_suffix
);
2096 strcat (local_prompt
, "\n");
2099 if (linebuffer
== 0)
2102 linebuffer
= (char *) xmalloc (linelength
);
2107 /* Control-C quits instantly if typed while in this loop
2108 since it should not wait until the user types a newline. */
2114 signal (STOP_SIGNAL
, handle_stop_sig
);
2116 signal (STOP_SIGNAL
, stop_sig
);
2122 /* Make sure that all output has been output. Some machines may let
2123 you get away with leaving out some of the gdb_flush, but not all. */
2125 gdb_flush (gdb_stdout
);
2126 gdb_flush (gdb_stderr
);
2128 if (source_file_name
!= NULL
)
2130 ++source_line_number
;
2131 sprintf (source_error
,
2132 "%s%s:%d: Error in sourced command file:\n",
2135 source_line_number
);
2136 error_pre_print
= source_error
;
2139 if (annotation_level
> 1 && instream
== stdin
)
2141 printf_unfiltered ("\n\032\032pre-");
2142 printf_unfiltered (annotation_suffix
);
2143 printf_unfiltered ("\n");
2146 /* Don't use fancy stuff if not talking to stdin. */
2147 if (readline_hook
&& instream
== NULL
)
2149 rl
= (*readline_hook
) (local_prompt
);
2151 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2153 rl
= readline (local_prompt
);
2157 rl
= gdb_readline (local_prompt
);
2160 if (annotation_level
> 1 && instream
== stdin
)
2162 printf_unfiltered ("\n\032\032post-");
2163 printf_unfiltered (annotation_suffix
);
2164 printf_unfiltered ("\n");
2167 if (!rl
|| rl
== (char *) EOF
)
2172 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
2174 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
2175 nline
= (char *) xrealloc (linebuffer
, linelength
);
2176 p
+= nline
- linebuffer
;
2180 /* Copy line. Don't copy null at end. (Leaves line alone
2181 if this was just a newline) */
2185 free (rl
); /* Allocated in readline. */
2187 if (p
== linebuffer
|| *(p
- 1) != '\\')
2190 p
--; /* Put on top of '\'. */
2191 local_prompt
= (char *) 0;
2196 signal (STOP_SIGNAL
, SIG_DFL
);
2203 #define SERVER_COMMAND_LENGTH 7
2205 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2206 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2209 /* Note that we don't set `line'. Between this and the check in
2210 dont_repeat, this insures that repeating will still do the
2213 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2216 /* Do history expansion if that is wished. */
2217 if (history_expansion_p
&& instream
== stdin
2218 && ISATTY (instream
))
2220 char *history_value
;
2223 *p
= '\0'; /* Insert null now. */
2224 expanded
= history_expand (linebuffer
, &history_value
);
2227 /* Print the changes. */
2228 printf_unfiltered ("%s\n", history_value
);
2230 /* If there was an error, call this function again. */
2233 free (history_value
);
2234 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2236 if (strlen (history_value
) > linelength
)
2238 linelength
= strlen (history_value
) + 1;
2239 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2241 strcpy (linebuffer
, history_value
);
2242 p
= linebuffer
+ strlen (linebuffer
);
2243 free (history_value
);
2247 /* If we just got an empty line, and that is supposed
2248 to repeat the previous command, return the value in the
2250 if (repeat
&& p
== linebuffer
)
2252 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
2258 /* Add line to history if appropriate. */
2259 if (instream
== stdin
2260 && ISATTY (stdin
) && *linebuffer
)
2261 add_history (linebuffer
);
2263 /* Note: lines consisting solely of comments are added to the command
2264 history. This is useful when you type a command, and then
2265 realize you don't want to execute it quite yet. You can comment
2266 out the command and then later fetch it from the value history
2267 and remove the '#'. The kill ring is probably better, but some
2268 people are in the habit of commenting things out. */
2270 *p1
= '\0'; /* Found a comment. */
2272 /* Save into global buffer if appropriate. */
2275 if (linelength
> linesize
)
2277 line
= xrealloc (line
, linelength
);
2278 linesize
= linelength
;
2280 strcpy (line
, linebuffer
);
2288 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2289 code bodies. This is typically used when we encounter an "else"
2290 clause for an "if" command. */
2293 realloc_body_list (command
, new_length
)
2294 struct command_line
*command
;
2298 struct command_line
**body_list
;
2300 n
= command
->body_count
;
2302 /* Nothing to do? */
2303 if (new_length
<= n
)
2306 body_list
= (struct command_line
**)
2307 xmalloc (sizeof (struct command_line
*) * new_length
);
2309 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2311 free (command
->body_list
);
2312 command
->body_list
= body_list
;
2313 command
->body_count
= new_length
;
2316 /* Read one line from the input stream. If the command is an "else" or
2317 "end", return such an indication to the caller. */
2319 static enum misc_command_type
2320 read_next_line (command
)
2321 struct command_line
**command
;
2323 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2326 if (control_level
>= 254)
2327 error ("Control nesting too deep!\n");
2329 /* Set a prompt based on the nesting of the control commands. */
2330 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2332 for (i
= 0; i
< control_level
; i
++)
2333 control_prompt
[i
] = ' ';
2334 control_prompt
[i
] = '>';
2335 control_prompt
[i
+ 1] = '\0';
2336 prompt_ptr
= (char *) &control_prompt
[0];
2341 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2343 /* Not sure what to do here. */
2347 /* Strip leading and trailing whitespace. */
2348 while (*p
== ' ' || *p
== '\t')
2351 p1
= p
+ strlen (p
);
2352 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2355 /* Blanks and comments don't really do anything, but we need to
2356 distinguish them from else, end and other commands which can be
2358 if (p1
== p
|| p
[0] == '#')
2361 /* Is this the end of a simple, while, or if control structure? */
2362 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2365 /* Is the else clause of an if control structure? */
2366 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2367 return else_command
;
2369 /* Check for while, if, break, continue, etc and build a new command
2370 line structure for them. */
2371 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2372 *command
= build_command_line (while_control
, p
+ 6);
2373 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2374 *command
= build_command_line (if_control
, p
+ 3);
2375 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2377 *command
= (struct command_line
*)
2378 xmalloc (sizeof (struct command_line
));
2379 (*command
)->next
= NULL
;
2380 (*command
)->line
= NULL
;
2381 (*command
)->control_type
= break_control
;
2382 (*command
)->body_count
= 0;
2383 (*command
)->body_list
= NULL
;
2385 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2387 *command
= (struct command_line
*)
2388 xmalloc (sizeof (struct command_line
));
2389 (*command
)->next
= NULL
;
2390 (*command
)->line
= NULL
;
2391 (*command
)->control_type
= continue_control
;
2392 (*command
)->body_count
= 0;
2393 (*command
)->body_list
= NULL
;
2397 /* A normal command. */
2398 *command
= (struct command_line
*)
2399 xmalloc (sizeof (struct command_line
));
2400 (*command
)->next
= NULL
;
2401 (*command
)->line
= savestring (p
, p1
- p
);
2402 (*command
)->control_type
= simple_control
;
2403 (*command
)->body_count
= 0;
2404 (*command
)->body_list
= NULL
;
2407 /* Nothing special. */
2411 /* Recursively read in the control structures and create a command_line
2412 structure from them.
2414 The parent_control parameter is the control structure in which the
2415 following commands are nested. */
2417 static enum command_control_type
2418 recurse_read_control_structure (current_cmd
)
2419 struct command_line
*current_cmd
;
2421 int current_body
, i
;
2422 enum misc_command_type val
;
2423 enum command_control_type ret
;
2424 struct command_line
**body_ptr
, *child_tail
, *next
;
2429 /* Sanity checks. */
2430 if (current_cmd
->control_type
== simple_control
)
2432 error ("Recursed on a simple control type\n");
2433 return invalid_control
;
2436 if (current_body
> current_cmd
->body_count
)
2438 error ("Allocated body is smaller than this command type needs\n");
2439 return invalid_control
;
2442 /* Read lines from the input stream and build control structures. */
2448 val
= read_next_line (&next
);
2450 /* Just skip blanks and comments. */
2451 if (val
== nop_command
)
2454 if (val
== end_command
)
2456 if (current_cmd
->control_type
== while_control
2457 || current_cmd
->control_type
== if_control
)
2459 /* Success reading an entire control structure. */
2460 ret
= simple_control
;
2465 ret
= invalid_control
;
2470 /* Not the end of a control structure. */
2471 if (val
== else_command
)
2473 if (current_cmd
->control_type
== if_control
2474 && current_body
== 1)
2476 realloc_body_list (current_cmd
, 2);
2483 ret
= invalid_control
;
2490 child_tail
->next
= next
;
2494 body_ptr
= current_cmd
->body_list
;
2495 for (i
= 1; i
< current_body
; i
++)
2504 /* If the latest line is another control structure, then recurse
2506 if (next
->control_type
== while_control
2507 || next
->control_type
== if_control
)
2510 ret
= recurse_read_control_structure (next
);
2513 if (ret
!= simple_control
)
2523 /* Read lines from the input stream and accumulate them in a chain of
2524 struct command_line's, which is then returned. For input from a
2525 terminal, the special command "end" is used to mark the end of the
2526 input, and is not included in the returned chain of commands. */
2528 #define END_MESSAGE "End with a line saying just \"end\"."
2530 struct command_line
*
2531 read_command_lines (prompt_arg
, from_tty
)
2535 struct command_line
*head
, *tail
, *next
;
2536 struct cleanup
*old_chain
;
2537 enum command_control_type ret
;
2538 enum misc_command_type val
;
2541 if (readline_begin_hook
)
2543 /* Note - intentional to merge messages with no newline */
2544 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2546 else if (from_tty
&& input_from_terminal_p ())
2548 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2549 gdb_flush (gdb_stdout
);
2557 val
= read_next_line (&next
);
2559 /* Ignore blank lines or comments. */
2560 if (val
== nop_command
)
2563 if (val
== end_command
)
2565 ret
= simple_control
;
2569 if (val
!= ok_command
)
2571 ret
= invalid_control
;
2575 if (next
->control_type
== while_control
2576 || next
->control_type
== if_control
)
2579 ret
= recurse_read_control_structure (next
);
2582 if (ret
== invalid_control
)
2593 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
,
2603 if (ret
!= invalid_control
)
2605 discard_cleanups (old_chain
);
2608 do_cleanups (old_chain
);
2611 if (readline_end_hook
)
2613 (*readline_end_hook
) ();
2618 /* Free a chain of struct command_line's. */
2621 free_command_lines (lptr
)
2622 struct command_line
**lptr
;
2624 register struct command_line
*l
= *lptr
;
2625 register struct command_line
*next
;
2626 struct command_line
**blist
;
2631 if (l
->body_count
> 0)
2633 blist
= l
->body_list
;
2634 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2635 free_command_lines (blist
);
2644 /* Add an element to the list of info subcommands. */
2647 add_info (name
, fun
, doc
)
2649 void (*fun
) PARAMS ((char *, int));
2652 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2655 /* Add an alias to the list of info subcommands. */
2658 add_info_alias (name
, oldname
, abbrev_flag
)
2663 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2666 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2667 Therefore, its own definition is called only for "info" with no args. */
2671 info_command (arg
, from_tty
)
2675 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2676 help_list (infolist
, "info ", -1, gdb_stdout
);
2679 /* The "complete" command is used by Emacs to implement completion. */
2683 complete_command (arg
, from_tty
)
2695 argpoint
= strlen (arg
);
2697 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2699 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2701 printf_unfiltered ("%s\n", completion
);
2706 /* The "show" command with no arguments shows all the settings. */
2710 show_command (arg
, from_tty
)
2714 cmd_show_list (showlist
, from_tty
, "");
2717 /* Add an element to the list of commands. */
2720 add_com (name
, class, fun
, doc
)
2722 enum command_class
class;
2723 void (*fun
) PARAMS ((char *, int));
2726 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2729 /* Add an alias or abbreviation command to the list of commands. */
2732 add_com_alias (name
, oldname
, class, abbrev_flag
)
2735 enum command_class
class;
2738 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2745 error ("Argument required (%s).", why
);
2750 help_command (command
, from_tty
)
2752 int from_tty
; /* Ignored */
2754 help_cmd (command
, gdb_stdout
);
2758 validate_comname (comname
)
2764 error_no_arg ("name of command to define");
2769 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
2770 error ("Junk in argument list: \"%s\"", p
);
2775 /* This is just a placeholder in the command data structures. */
2777 user_defined_command (ignore
, from_tty
)
2784 define_command (comname
, from_tty
)
2788 register struct command_line
*cmds
;
2789 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2790 char *tem
= comname
;
2792 #define HOOK_STRING "hook-"
2795 validate_comname (comname
);
2797 /* Look it up, and verify that we got an exact match. */
2798 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2799 if (c
&& !STREQ (comname
, c
->name
))
2804 if (c
->class == class_user
|| c
->class == class_alias
)
2805 tem
= "Redefine command \"%s\"? ";
2807 tem
= "Really redefine built-in command \"%s\"? ";
2808 if (!query (tem
, c
->name
))
2809 error ("Command \"%s\" not redefined.", c
->name
);
2812 /* If this new command is a hook, then mark the command which it
2813 is hooking. Note that we allow hooking `help' commands, so that
2814 we can hook the `stop' pseudo-command. */
2816 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2818 /* Look up cmd it hooks, and verify that we got an exact match. */
2819 tem
= comname
+ HOOK_LEN
;
2820 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2821 if (hookc
&& !STREQ (comname
+ HOOK_LEN
, hookc
->name
))
2825 warning ("Your new `%s' command does not hook any existing command.",
2827 if (!query ("Proceed? "))
2828 error ("Not confirmed.");
2832 comname
= savestring (comname
, strlen (comname
));
2834 /* If the rest of the commands will be case insensitive, this one
2835 should behave in the same manner. */
2836 for (tem
= comname
; *tem
; tem
++)
2838 *tem
= tolower (*tem
);
2840 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
2841 cmds
= read_command_lines (tmpbuf
, from_tty
);
2843 if (c
&& c
->class == class_user
)
2844 free_command_lines (&c
->user_commands
);
2846 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2847 (c
&& c
->class == class_user
)
2848 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2849 newc
->user_commands
= cmds
;
2851 /* If this new command is a hook, then mark both commands as being
2855 hookc
->hook
= newc
; /* Target gets hooked. */
2856 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2861 document_command (comname
, from_tty
)
2865 struct command_line
*doclines
;
2866 register struct cmd_list_element
*c
;
2867 char *tem
= comname
;
2870 validate_comname (comname
);
2872 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2874 if (c
->class != class_user
)
2875 error ("Command \"%s\" is built-in.", comname
);
2877 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
2878 doclines
= read_command_lines (tmpbuf
, from_tty
);
2884 register struct command_line
*cl1
;
2885 register int len
= 0;
2887 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2888 len
+= strlen (cl1
->line
) + 1;
2890 c
->doc
= (char *) xmalloc (len
+ 1);
2893 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2895 strcat (c
->doc
, cl1
->line
);
2897 strcat (c
->doc
, "\n");
2901 free_command_lines (&doclines
);
2904 /* Print the GDB banner. */
2906 print_gdb_version (stream
)
2909 /* From GNU coding standards, first line is meant to be easy for a
2910 program to parse, and is just canonical program name and version
2911 number, which starts after last space. */
2913 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
2915 /* Second line is a copyright notice. */
2917 fprintf_filtered (stream
, "Copyright 1998 Free Software Foundation, Inc.\n");
2919 /* Following the copyright is a brief statement that the program is
2920 free software, that users are free to copy and change it on
2921 certain conditions, that it is covered by the GNU GPL, and that
2922 there is no warranty. */
2924 fprintf_filtered (stream
, "\
2925 GDB is free software, covered by the GNU General Public License, and you are\n\
2926 welcome to change it and/or distribute copies of it under certain conditions.\n\
2927 Type \"show copying\" to see the conditions.\n\
2928 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2930 /* After the required info we print the configuration information. */
2932 fprintf_filtered (stream
, "This GDB was configured as \"");
2933 if (!STREQ (host_name
, target_name
))
2935 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
2939 fprintf_filtered (stream
, "%s", host_name
);
2941 fprintf_filtered (stream
, "\".");
2946 show_version (args
, from_tty
)
2951 print_gdb_version (gdb_stdout
);
2952 printf_filtered ("\n");
2956 /* get_prompt: access method for the GDB prompt string. */
2958 #define MAX_PROMPT_SIZE 256
2961 * int get_prompt_1 (char * buf);
2963 * Work-horse for get_prompt (called via catch_errors).
2964 * Argument is buffer to hold the formatted prompt.
2966 * Returns: 1 for success (use formatted prompt)
2967 * 0 for failure (use gdb_prompt_string).
2970 static int gdb_prompt_escape
;
2973 get_prompt_1 (formatted_prompt
)
2974 char *formatted_prompt
;
2979 local_prompt
= PROMPT (0);
2981 local_prompt
= gdb_prompt_string
;
2984 if (gdb_prompt_escape
== 0)
2986 return 0; /* do no formatting */
2989 /* formatted prompt */
2991 char fmt
[40], *promptp
, *outp
, *tmp
;
2998 struct type
*arg_type
, *elt_type
;
3000 promptp
= local_prompt
;
3001 outp
= formatted_prompt
;
3003 while (*promptp
!= '\0')
3005 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
3007 if (*promptp
!= gdb_prompt_escape
)
3009 if (available
>= 1) /* overflow protect */
3010 *outp
++ = *promptp
++;
3014 /* GDB prompt string contains escape char. Parse for arg.
3015 Two consecutive escape chars followed by arg followed by
3016 a comma means to insert the arg using a default format.
3017 Otherwise a printf format string may be included between
3018 the two escape chars. eg:
3019 %%foo, insert foo using default format
3020 %2.2f%foo, insert foo using "%2.2f" format
3021 A mismatch between the format string and the data type
3022 of "foo" is an error (which we don't know how to protect
3025 fmt
[0] = '\0'; /* assume null format string */
3026 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
3028 promptp
+= 2; /* skip past two escape chars. */
3032 /* extract format string from between two esc chars */
3036 fmt
[i
++] = *promptp
++; /* copy format string */
3038 while (i
< sizeof (fmt
) - 1 &&
3039 *promptp
!= gdb_prompt_escape
&&
3042 if (*promptp
!= gdb_prompt_escape
)
3043 error ("Syntax error at prompt position %d",
3044 promptp
- local_prompt
);
3047 promptp
++; /* skip second escape char */
3048 fmt
[i
++] = '\0'; /* terminate the format string */
3052 arg_val
= parse_to_comma_and_eval (&promptp
);
3053 if (*promptp
== ',')
3054 promptp
++; /* skip past the comma */
3055 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
3056 switch (TYPE_CODE (arg_type
))
3058 case TYPE_CODE_ARRAY
:
3059 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3060 if (TYPE_LENGTH (arg_type
) > 0 &&
3061 TYPE_LENGTH (elt_type
) == 1 &&
3062 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
3064 int len
= TYPE_LENGTH (arg_type
);
3066 if (VALUE_LAZY (arg_val
))
3067 value_fetch_lazy (arg_val
);
3068 tmp
= VALUE_CONTENTS (arg_val
);
3070 if (len
> available
)
3071 len
= available
; /* overflow protect */
3073 /* FIXME: how to protect GDB from crashing
3074 from bad user-supplied format string? */
3076 sprintf (outp
, fmt
, tmp
);
3078 strncpy (outp
, tmp
, len
);
3083 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3084 addrval
= value_as_pointer (arg_val
);
3086 if (TYPE_LENGTH (elt_type
) == 1 &&
3087 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
3090 /* display it as a string */
3091 char *default_fmt
= "%s";
3095 /* Limiting the number of bytes that the following call
3096 will read protects us from sprintf overflow later. */
3097 i
= target_read_string (addrval
, /* src */
3099 available
, /* len */
3101 if (err
) /* read failed */
3102 error ("%s on target_read", safe_strerror (err
));
3104 tmp
[i
] = '\0'; /* force-terminate string */
3105 /* FIXME: how to protect GDB from crashing
3106 from bad user-supplied format string? */
3107 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3113 /* display it as a pointer */
3114 char *default_fmt
= "0x%x";
3116 /* FIXME: how to protect GDB from crashing
3117 from bad user-supplied format string? */
3118 if (available
>= 16 /*? */ ) /* overflow protect */
3119 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3125 char *default_fmt
= "%g";
3127 doubleval
= value_as_double (arg_val
);
3128 /* FIXME: how to protect GDB from crashing
3129 from bad user-supplied format string? */
3130 if (available
>= 16 /*? */ ) /* overflow protect */
3131 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3132 (double) doubleval
);
3137 char *default_fmt
= "%d";
3139 longval
= value_as_long (arg_val
);
3140 /* FIXME: how to protect GDB from crashing
3141 from bad user-supplied format string? */
3142 if (available
>= 16 /*? */ ) /* overflow protect */
3143 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3147 case TYPE_CODE_BOOL
:
3149 /* no default format for bool */
3150 longval
= value_as_long (arg_val
);
3151 if (available
>= 8 /*? */ ) /* overflow protect */
3154 strcpy (outp
, "<true>");
3156 strcpy (outp
, "<false>");
3160 case TYPE_CODE_ENUM
:
3162 /* no default format for enum */
3163 longval
= value_as_long (arg_val
);
3164 len
= TYPE_NFIELDS (arg_type
);
3165 /* find enum name if possible */
3166 for (i
= 0; i
< len
; i
++)
3167 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3168 break; /* match -- end loop */
3170 if (i
< len
) /* enum name found */
3172 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3174 strncpy (outp
, name
, available
);
3175 /* in casel available < strlen (name), */
3176 outp
[available
] = '\0';
3180 if (available
>= 16 /*? */ ) /* overflow protect */
3181 sprintf (outp
, "%d", (long) longval
);
3185 case TYPE_CODE_VOID
:
3187 break; /* void type -- no output */
3189 error ("bad data type at prompt position %d",
3190 promptp
- local_prompt
);
3193 outp
+= strlen (outp
);
3196 *outp
++ = '\0'; /* terminate prompt string */
3204 static char buf
[MAX_PROMPT_SIZE
];
3206 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3209 return &buf
[0]; /* successful formatted prompt */
3213 /* Prompt could not be formatted. */
3217 return gdb_prompt_string
;
3225 /* ??rehrauer: I don't know why this fails, since it looks as though
3226 assignments to prompt are wrapped in calls to savestring...
3231 PROMPT (0) = savestring (s
, strlen (s
));
3233 gdb_prompt_string
= savestring (s
, strlen (s
));
3237 /* If necessary, make the user confirm that we should quit. Return
3238 non-zero if we should quit, zero if we shouldn't. */
3243 if (inferior_pid
!= 0 && target_has_execution
)
3247 /* This is something of a hack. But there's no reliable way to
3248 see if a GUI is running. The `use_windows' variable doesn't
3251 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3252 else if (attach_flag
)
3253 s
= "The program is running. Quit anyway (and detach it)? ";
3255 s
= "The program is running. Exit anyway? ";
3264 /* Quit without asking for confirmation. */
3267 quit_force (args
, from_tty
)
3273 /* An optional expression may be used to cause gdb to terminate with the
3274 value of that expression. */
3277 value_ptr val
= parse_and_eval (args
);
3279 exit_code
= (int) value_as_long (val
);
3282 if (inferior_pid
!= 0 && target_has_execution
)
3285 target_detach (args
, from_tty
);
3290 /* UDI wants this, to kill the TIP. */
3293 /* Save the history information if it is appropriate to do so. */
3294 if (write_history_p
&& history_filename
)
3295 write_history (history_filename
);
3297 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3300 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3301 /* The above does not need to be inside a tuiDo(), since
3302 * it is not manipulating the curses screen, but rather,
3303 * it is tearing it down.
3312 /* Handle the quit command. */
3315 quit_command (args
, from_tty
)
3319 if (!quit_confirm ())
3320 error ("Not confirmed.");
3321 quit_force (args
, from_tty
);
3324 /* Returns whether GDB is running on a terminal and whether the user
3325 desires that questions be asked of them on that terminal. */
3328 input_from_terminal_p ()
3330 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3335 pwd_command (args
, from_tty
)
3340 error ("The \"pwd\" command does not take an argument: %s", args
);
3341 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3343 if (!STREQ (gdb_dirbuf
, current_directory
))
3344 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3345 current_directory
, gdb_dirbuf
);
3347 printf_unfiltered ("Working directory %s.\n", current_directory
);
3351 cd_command (dir
, from_tty
)
3356 /* Found something other than leading repetitions of "/..". */
3357 int found_real_path
;
3360 /* If the new directory is absolute, repeat is a no-op; if relative,
3361 repeat might be useful but is more likely to be a mistake. */
3365 error_no_arg ("new working directory");
3367 dir
= tilde_expand (dir
);
3368 make_cleanup (free
, dir
);
3370 if (chdir (dir
) < 0)
3371 perror_with_name (dir
);
3373 #if defined(_WIN32) || defined(__MSDOS__)
3374 /* There's too much mess with DOSish names like "d:", "d:.",
3375 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3376 simply get the canonicalized name of the current directory. */
3377 dir
= getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3381 if (SLASH_P (dir
[len
-1]))
3383 /* Remove the trailing slash unless this is a root directory
3384 (including a drive letter on non-Unix systems). */
3385 if (!(len
== 1) /* "/" */
3386 #if defined(_WIN32) || defined(__MSDOS__)
3387 && !(!SLASH_P (*dir
) && ROOTED_P (dir
) && len
<= 3) /* "d:/" */
3393 dir
= savestring (dir
, len
);
3395 current_directory
= dir
;
3398 if (SLASH_P (current_directory
[strlen (current_directory
) - 1]))
3399 current_directory
= concat (current_directory
, dir
, NULL
);
3401 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3405 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3407 found_real_path
= 0;
3408 for (p
= current_directory
; *p
;)
3410 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3412 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3413 && (p
[3] == 0 || SLASH_P (p
[3])))
3415 if (found_real_path
)
3417 /* Search backwards for the directory just before the "/.."
3418 and obliterate it and the "/..". */
3420 while (q
!= current_directory
&& !SLASH_P (q
[-1]))
3423 if (q
== current_directory
)
3424 /* current_directory is
3425 a relative pathname ("can't happen"--leave it alone). */
3429 strcpy (q
- 1, p
+ 3);
3434 /* We are dealing with leading repetitions of "/..", for example
3435 "/../..", which is the Mach super-root. */
3440 found_real_path
= 1;
3445 forget_cached_source_info ();
3448 pwd_command ((char *) 0, 1);
3451 struct source_cleanup_lines_args
3455 char *old_pre_error
;
3456 char *old_error_pre_print
;
3460 source_cleanup_lines (args
)
3463 struct source_cleanup_lines_args
*p
=
3464 (struct source_cleanup_lines_args
*) args
;
3465 source_line_number
= p
->old_line
;
3466 source_file_name
= p
->old_file
;
3467 source_pre_error
= p
->old_pre_error
;
3468 error_pre_print
= p
->old_error_pre_print
;
3473 source_command (args
, from_tty
)
3478 struct cleanup
*old_cleanups
;
3480 struct source_cleanup_lines_args old_lines
;
3485 error ("source command requires pathname of file to source.");
3488 file
= tilde_expand (file
);
3489 old_cleanups
= make_cleanup (free
, file
);
3491 stream
= fopen (file
, FOPEN_RT
);
3495 perror_with_name (file
);
3500 make_cleanup ((make_cleanup_func
) fclose
, stream
);
3502 old_lines
.old_line
= source_line_number
;
3503 old_lines
.old_file
= source_file_name
;
3504 old_lines
.old_pre_error
= source_pre_error
;
3505 old_lines
.old_error_pre_print
= error_pre_print
;
3506 make_cleanup (source_cleanup_lines
, &old_lines
);
3507 source_line_number
= 0;
3508 source_file_name
= file
;
3509 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3510 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3511 make_cleanup (free
, source_pre_error
);
3512 /* This will get set every time we read a line. So it won't stay "" for
3514 error_pre_print
= "";
3516 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3517 if (source_error_allocated
< needed_length
)
3519 source_error_allocated
*= 2;
3520 if (source_error_allocated
< needed_length
)
3521 source_error_allocated
= needed_length
;
3522 if (source_error
== NULL
)
3523 source_error
= xmalloc (source_error_allocated
);
3525 source_error
= xrealloc (source_error
, source_error_allocated
);
3528 read_command_file (stream
);
3530 do_cleanups (old_cleanups
);
3535 echo_command (text
, from_tty
)
3543 while ((c
= *p
++) != '\0')
3547 /* \ at end of argument is used after spaces
3548 so they won't be lost. */
3552 c
= parse_escape (&p
);
3554 printf_filtered ("%c", c
);
3557 printf_filtered ("%c", c
);
3560 /* Force this output to appear now. */
3562 gdb_flush (gdb_stdout
);
3567 dont_repeat_command (ignored
, from_tty
)
3571 *line
= 0; /* Can't call dont_repeat here because we're not
3572 necessarily reading from stdin. */
3575 /* Functions to manipulate command line editing control variables. */
3577 /* Number of commands to print in each call to show_commands. */
3578 #define Hist_print 10
3580 show_commands (args
, from_tty
)
3584 /* Index for history commands. Relative to history_base. */
3587 /* Number of the history entry which we are planning to display next.
3588 Relative to history_base. */
3591 /* The first command in the history which doesn't exist (i.e. one more
3592 than the number of the last command). Relative to history_base. */
3595 extern HIST_ENTRY
*history_get
PARAMS ((int));
3597 /* Print out some of the commands from the command history. */
3598 /* First determine the length of the history list. */
3599 hist_len
= history_size
;
3600 for (offset
= 0; offset
< history_size
; offset
++)
3602 if (!history_get (history_base
+ offset
))
3611 if (args
[0] == '+' && args
[1] == '\0')
3612 /* "info editing +" should print from the stored position. */
3615 /* "info editing <exp>" should print around command number <exp>. */
3616 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
3618 /* "show commands" means print the last Hist_print commands. */
3621 num
= hist_len
- Hist_print
;
3627 /* If there are at least Hist_print commands, we want to display the last
3628 Hist_print rather than, say, the last 6. */
3629 if (hist_len
- num
< Hist_print
)
3631 num
= hist_len
- Hist_print
;
3636 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3638 printf_filtered ("%5d %s\n", history_base
+ offset
,
3639 (history_get (history_base
+ offset
))->line
);
3642 /* The next command we want to display is the next one that we haven't
3646 /* If the user repeats this command with return, it should do what
3647 "show commands +" does. This is unnecessary if arg is null,
3648 because "show commands +" is not useful after "show commands". */
3649 if (from_tty
&& args
)
3656 /* Called by do_setshow_command. */
3659 set_history_size_command (args
, from_tty
, c
)
3662 struct cmd_list_element
*c
;
3664 if (history_size
== INT_MAX
)
3665 unstifle_history ();
3666 else if (history_size
>= 0)
3667 stifle_history (history_size
);
3670 history_size
= INT_MAX
;
3671 error ("History size must be non-negative");
3677 set_history (args
, from_tty
)
3681 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3682 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3687 show_history (args
, from_tty
)
3691 cmd_show_list (showhistlist
, from_tty
, "");
3694 int info_verbose
= 0; /* Default verbose msgs off */
3696 /* Called by do_setshow_command. An elaborate joke. */
3699 set_verbose (args
, from_tty
, c
)
3702 struct cmd_list_element
*c
;
3704 char *cmdname
= "verbose";
3705 struct cmd_list_element
*showcmd
;
3707 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3711 c
->doc
= "Set verbose printing of informational messages.";
3712 showcmd
->doc
= "Show verbose printing of informational messages.";
3716 c
->doc
= "Set verbosity.";
3717 showcmd
->doc
= "Show verbosity.";
3722 float_handler (signo
)
3725 /* This message is based on ANSI C, section 4.7. Note that integer
3726 divide by zero causes this, so "float" is a misnomer. */
3727 signal (SIGFPE
, float_handler
);
3728 error ("Erroneous arithmetic operation.");
3742 enablebreaklist
= NULL
;
3747 showhistlist
= NULL
;
3748 unsethistlist
= NULL
;
3749 maintenancelist
= NULL
;
3750 maintenanceinfolist
= NULL
;
3751 maintenanceprintlist
= NULL
;
3752 setprintlist
= NULL
;
3753 showprintlist
= NULL
;
3754 setchecklist
= NULL
;
3755 showchecklist
= NULL
;
3758 /* Init the history buffer. Note that we are called after the init file(s)
3759 * have been read so that the user can change the history file via his
3760 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3761 * overrides all of this.
3769 tmpenv
= getenv ("HISTSIZE");
3771 history_size
= atoi (tmpenv
);
3772 else if (!history_size
)
3775 stifle_history (history_size
);
3777 tmpenv
= getenv ("GDBHISTFILE");
3779 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
3780 else if (!history_filename
)
3782 /* We include the current directory so that if the user changes
3783 directories the file written will be the same as the one
3786 /* No leading dots in file names are allowed on MSDOS. */
3787 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
3789 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3792 read_history (history_filename
);
3798 struct cmd_list_element
*c
;
3800 /* If we are running the asynchronous version,
3801 we initialize the prompts differently. */
3804 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3808 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3809 whatever the DEFAULT_PROMPT is. */
3810 the_prompts
.top
= 0;
3812 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3814 /* Set things up for annotation_level > 1, if the user ever decides
3816 async_annotation_suffix
= "prompt";
3817 /* Set the variable associated with the setshow prompt command. */
3818 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
3820 gdb_prompt_escape
= 0; /* default to none. */
3822 /* Set the important stuff up for command editing. */
3823 command_editing_p
= 1;
3824 history_expansion_p
= 0;
3825 write_history_p
= 0;
3827 /* Setup important stuff for command line editing. */
3828 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3829 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3830 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3831 rl_readline_name
= "gdb";
3833 /* Define the classes of commands.
3834 They will appear in the help list in the reverse of this order. */
3836 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3837 "Maintenance commands.\n\
3838 Some gdb commands are provided just for use by gdb maintainers.\n\
3839 These commands are subject to frequent change, and may not be as\n\
3840 well documented as user commands.",
3842 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3843 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3844 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3845 The commands in this class are those defined by the user.\n\
3846 Use the \"define\" command to define a command.", &cmdlist
);
3847 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3849 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3850 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3851 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3852 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3853 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3854 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3855 counting from zero for the innermost (currently executing) frame.\n\n\
3856 At any time gdb identifies one frame as the \"selected\" frame.\n\
3857 Variable lookups are done with respect to the selected frame.\n\
3858 When the program being debugged stops, gdb selects the innermost frame.\n\
3859 The commands below can be used to select other frames by number or address.",
3861 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3863 add_com ("pwd", class_files
, pwd_command
,
3864 "Print working directory. This is used for your program as well.");
3865 c
= add_cmd ("cd", class_files
, cd_command
,
3866 "Set working directory to DIR for debugger and program being debugged.\n\
3867 The change does not take effect for the program being debugged\n\
3868 until the next time it is started.", &cmdlist
);
3869 c
->completer
= filename_completer
;
3871 /* The set prompt command is different depending whether or not the
3872 async version is run. NOTE: this difference is going to
3873 disappear as we make the event loop be the default engine of
3878 (add_set_cmd ("prompt", class_support
, var_string
,
3879 (char *) &gdb_prompt_string
, "Set gdb's prompt",
3885 c
= add_set_cmd ("prompt", class_support
, var_string
,
3886 (char *) &new_async_prompt
, "Set gdb's prompt",
3888 add_show_from_set (c
, &showlist
);
3889 c
->function
.sfunc
= set_async_prompt
;
3893 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
3894 (char *) &gdb_prompt_escape
,
3895 "Set escape character for formatting of gdb's prompt",
3899 add_com ("echo", class_support
, echo_command
,
3900 "Print a constant string. Give string as argument.\n\
3901 C escape sequences may be used in the argument.\n\
3902 No newline is added at the end of the argument;\n\
3903 use \"\\n\" if you want a newline to be printed.\n\
3904 Since leading and trailing whitespace are ignored in command arguments,\n\
3905 if you want to print some you must use \"\\\" before leading whitespace\n\
3906 to be printed or after trailing whitespace.");
3907 add_com ("document", class_support
, document_command
,
3908 "Document a user-defined command.\n\
3909 Give command name as argument. Give documentation on following lines.\n\
3910 End with a line of just \"end\".");
3911 add_com ("define", class_support
, define_command
,
3912 "Define a new command name. Command name is argument.\n\
3913 Definition appears on following lines, one command per line.\n\
3914 End with a line of just \"end\".\n\
3915 Use the \"document\" command to give documentation for the new command.\n\
3916 Commands defined in this way may have up to ten arguments.");
3919 c
= add_cmd ("source", class_support
, source_command
,
3920 "Read commands from a file named FILE.\n\
3921 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3922 when gdb is started.", &cmdlist
);
3924 /* Punt file name, we can't help it easily. */
3925 c
= add_cmd ("source", class_support
, source_command
,
3926 "Read commands from a file named FILE.\n\
3927 Note that the file \".gdbinit\" is read automatically in this way\n\
3928 when gdb is started.", &cmdlist
);
3930 c
->completer
= filename_completer
;
3932 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3933 add_com ("help", class_support
, help_command
, "Print list of commands.");
3934 add_com_alias ("q", "quit", class_support
, 1);
3935 add_com_alias ("h", "help", class_support
, 1);
3937 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
3938 Primarily used inside of user-defined commands that should not be repeated when\n\
3941 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *) &info_verbose
,
3944 add_show_from_set (c
, &showlist
);
3945 c
->function
.sfunc
= set_verbose
;
3946 set_verbose (NULL
, 0, c
);
3948 /* The set editing command is different depending whether or not the
3949 async version is run. NOTE: this difference is going to disappear
3950 as we make the event loop be the default engine of gdb. */
3954 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
3955 "Set editing of command lines as they are typed.\n\
3956 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3957 Without an argument, command line editing is enabled. To edit, use\n\
3958 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
3963 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
3964 "Set editing of command lines as they are typed.\n\
3965 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3966 Without an argument, command line editing is enabled. To edit, use\n\
3967 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
3969 add_show_from_set (c
, &showlist
);
3970 c
->function
.sfunc
= set_async_editing_command
;
3973 add_prefix_cmd ("history", class_support
, set_history
,
3974 "Generic command for setting command history parameters.",
3975 &sethistlist
, "set history ", 0, &setlist
);
3976 add_prefix_cmd ("history", class_support
, show_history
,
3977 "Generic command for showing command history parameters.",
3978 &showhistlist
, "show history ", 0, &showlist
);
3981 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *) &history_expansion_p
,
3982 "Set history expansion on command input.\n\
3983 Without an argument, history expansion is enabled.", &sethistlist
),
3987 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
3988 "Set saving of the history record on exit.\n\
3989 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
3990 Without an argument, saving is enabled.", &sethistlist
),
3993 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
3994 "Set the size of the command history, \n\
3995 ie. the number of previous commands to keep a record of.", &sethistlist
);
3996 add_show_from_set (c
, &showhistlist
);
3997 c
->function
.sfunc
= set_history_size_command
;
4000 (add_set_cmd ("filename", no_class
, var_filename
, (char *) &history_filename
,
4001 "Set the filename in which to record the command history\n\
4002 (the list of previous commands of which a record is kept).", &sethistlist
),
4006 (add_set_cmd ("confirm", class_support
, var_boolean
,
4008 "Set whether to confirm potentially dangerous operations.",
4012 add_prefix_cmd ("info", class_info
, info_command
,
4013 "Generic command for showing things about the program being debugged.",
4014 &infolist
, "info ", 0, &cmdlist
);
4015 add_com_alias ("i", "info", class_info
, 1);
4017 add_com ("complete", class_obscure
, complete_command
,
4018 "List the completions for the rest of the line as a command.");
4020 add_prefix_cmd ("show", class_info
, show_command
,
4021 "Generic command for showing things about the debugger.",
4022 &showlist
, "show ", 0, &cmdlist
);
4023 /* Another way to get at the same thing. */
4024 add_info ("set", show_command
, "Show all GDB settings.");
4026 add_cmd ("commands", no_class
, show_commands
,
4027 "Show the history of commands you typed.\n\
4028 You can supply a command number to start with, or a `+' to start after\n\
4029 the previous command number shown.",
4032 add_cmd ("version", no_class
, show_version
,
4033 "Show what version of GDB this is.", &showlist
);
4035 add_com ("while", class_support
, while_command
,
4036 "Execute nested commands WHILE the conditional expression is non zero.\n\
4037 The conditional expression must follow the word `while' and must in turn be\n\
4038 followed by a new line. The nested commands must be entered one per line,\n\
4039 and should be terminated by the word `end'.");
4041 add_com ("if", class_support
, if_command
,
4042 "Execute nested commands once IF the conditional expression is non zero.\n\
4043 The conditional expression must follow the word `if' and must in turn be\n\
4044 followed by a new line. The nested commands must be entered one per line,\n\
4045 and should be terminated by the word 'else' or `end'. If an else clause\n\
4046 is used, the same rules apply to its nested commands as to the first ones.");
4048 /* If target is open when baud changes, it doesn't take effect until the
4049 next open (I think, not sure). */
4050 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
4051 var_zinteger
, (char *) &baud_rate
,
4052 "Set baud rate for remote serial I/O.\n\
4053 This value is used to set the speed of the serial port when debugging\n\
4054 using remote targets.", &setlist
),
4058 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *) &remote_debug
,
4059 "Set debugging of remote protocol.\n\
4060 When enabled, each packet sent or received with the remote target\n\
4061 is displayed.", &setlist
),
4065 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *) &remote_timeout
,
4066 "Set timeout limit to wait for target to respond.\n\
4067 This value is used to set the time limit for gdb to wait for a response\n\
4068 from the target.", &setlist
),
4071 /* The set annotate command is different depending whether or not
4072 the async version is run. NOTE: this difference is going to
4073 disappear as we make the event loop be the default engine of
4077 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4078 (char *) &annotation_level
, "Set annotation_level.\n\
4079 0 == normal; 1 == fullname (for use when running under emacs)\n\
4080 2 == output annotated suitably for use by programs that control GDB.",
4082 c
= add_show_from_set (c
, &showlist
);
4086 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4087 (char *) &annotation_level
, "Set annotation_level.\n\
4088 0 == normal; 1 == fullname (for use when running under emacs)\n\
4089 2 == output annotated suitably for use by programs that control GDB.",
4091 add_show_from_set (c
, &showlist
);
4092 c
->function
.sfunc
= set_async_annotation_level
;
4097 (add_set_cmd ("exec-done-display", class_support
, var_boolean
, (char *) &exec_done_display_p
,
4098 "Set notification of completion for asynchronous execution commands.\n\
4099 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist
),