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, Boston, MA 02111-1307, USA. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
33 #include "terminal.h" /* For job_control. */
37 /* readline include files */
38 #include <readline/readline.h>
39 #include <readline/history.h>
41 /* readline defines this. */
44 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "gdb_string.h"
54 /* Prototypes for local functions */
56 static void dont_repeat_command
PARAMS ((char *, int));
58 static void source_cleanup_lines
PARAMS ((PTR
));
60 static void user_defined_command
PARAMS ((char *, int));
62 static void init_signals
PARAMS ((void));
65 static void stop_sig
PARAMS ((int));
68 static char * line_completion_function
PARAMS ((char *, int, char *, int));
70 static char * readline_line_completion_function
PARAMS ((char *, int));
72 /* NOTE 1999-04-29: this function will be static again, after we make the
73 event loop be the default command loop for gdb, and we merge
74 event-top.c into this file, top.c */
75 /* static */ void command_loop_marker
PARAMS ((int));
77 static void while_command
PARAMS ((char *, int));
79 static void if_command
PARAMS ((char *, int));
81 static struct command_line
*
82 build_command_line
PARAMS ((enum command_control_type
, char *));
84 static struct command_line
*
85 get_command_line
PARAMS ((enum command_control_type
, char *));
87 static void realloc_body_list
PARAMS ((struct command_line
*, int));
89 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
91 static enum command_control_type
92 recurse_read_control_structure
PARAMS ((struct command_line
*));
94 static struct cleanup
* setup_user_args
PARAMS ((char *));
96 static char * locate_arg
PARAMS ((char *));
98 static char * insert_args
PARAMS ((char *));
100 static void arg_cleanup
PARAMS ((void));
102 static void init_main
PARAMS ((void));
104 static void init_cmd_lists
PARAMS ((void));
106 static void float_handler
PARAMS ((int));
108 static void init_signals
PARAMS ((void));
110 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
112 static void show_history
PARAMS ((char *, int));
114 static void set_history
PARAMS ((char *, int));
116 static void set_history_size_command
PARAMS ((char *, int,
117 struct cmd_list_element
*));
119 static void show_commands
PARAMS ((char *, int));
121 static void echo_command
PARAMS ((char *, int));
123 static void pwd_command
PARAMS ((char *, int));
125 static void show_version
PARAMS ((char *, int));
127 static void document_command
PARAMS ((char *, int));
129 static void define_command
PARAMS ((char *, int));
131 static void validate_comname
PARAMS ((char *));
133 static void help_command
PARAMS ((char *, int));
135 static void show_command
PARAMS ((char *, int));
137 static void info_command
PARAMS ((char *, int));
139 static void complete_command
PARAMS ((char *, int));
141 static void do_nothing
PARAMS ((int));
144 /* NOTE 1999-04-29: This function will be static again, once we modify
145 gdb to use the event loop as the default command loop and we merge
146 event-top.c into this file, top.c */
147 /* static */ int quit_cover
PARAMS ((PTR
));
149 static void disconnect
PARAMS ((int));
152 static void source_cleanup
PARAMS ((FILE *));
154 /* If this definition isn't overridden by the header files, assume
155 that isatty and fileno exist on this system. */
157 #define ISATTY(FP) (isatty (fileno (FP)))
160 /* Initialization file name for gdb. This is overridden in some configs. */
162 #ifndef GDBINIT_FILENAME
163 #define GDBINIT_FILENAME ".gdbinit"
165 char gdbinit
[] = GDBINIT_FILENAME
;
167 int inhibit_gdbinit
= 0;
169 /* If nonzero, and GDB has been configured to be able to use windows,
170 attempt to open them upon startup. */
174 /* Version number of GDB, as a string. */
176 extern char *version
;
178 /* Canonical host name as a string. */
180 extern char *host_name
;
182 /* Canonical target name as a string. */
184 extern char *target_name
;
186 extern char lang_frame_mismatch_warn
[]; /* language.c */
188 /* Flag for whether we want all the "from_tty" gubbish printed. */
190 int caution
= 1; /* Default is yes, sigh. */
192 /* Define all cmd_list_elements. */
194 /* Chain containing all defined commands. */
196 struct cmd_list_element
*cmdlist
;
198 /* Chain containing all defined info subcommands. */
200 struct cmd_list_element
*infolist
;
202 /* Chain containing all defined enable subcommands. */
204 struct cmd_list_element
*enablelist
;
206 /* Chain containing all defined disable subcommands. */
208 struct cmd_list_element
*disablelist
;
210 /* Chain containing all defined toggle subcommands. */
212 struct cmd_list_element
*togglelist
;
214 /* Chain containing all defined stop subcommands. */
216 struct cmd_list_element
*stoplist
;
218 /* Chain containing all defined delete subcommands. */
220 struct cmd_list_element
*deletelist
;
222 /* Chain containing all defined "enable breakpoint" subcommands. */
224 struct cmd_list_element
*enablebreaklist
;
226 /* Chain containing all defined set subcommands */
228 struct cmd_list_element
*setlist
;
230 /* Chain containing all defined unset subcommands */
232 struct cmd_list_element
*unsetlist
;
234 /* Chain containing all defined show subcommands. */
236 struct cmd_list_element
*showlist
;
238 /* Chain containing all defined \"set history\". */
240 struct cmd_list_element
*sethistlist
;
242 /* Chain containing all defined \"show history\". */
244 struct cmd_list_element
*showhistlist
;
246 /* Chain containing all defined \"unset history\". */
248 struct cmd_list_element
*unsethistlist
;
250 /* Chain containing all defined maintenance subcommands. */
252 struct cmd_list_element
*maintenancelist
;
254 /* Chain containing all defined "maintenance info" subcommands. */
256 struct cmd_list_element
*maintenanceinfolist
;
258 /* Chain containing all defined "maintenance print" subcommands. */
260 struct cmd_list_element
*maintenanceprintlist
;
262 struct cmd_list_element
*setprintlist
;
264 struct cmd_list_element
*showprintlist
;
266 struct cmd_list_element
*setchecklist
;
268 struct cmd_list_element
*showchecklist
;
270 /* stdio stream that command input is being read from. Set to stdin normally.
271 Set by source_command to the file we are sourcing. Set to NULL if we are
272 executing a user-defined command or interacting via a GUI. */
276 /* Current working directory. */
278 char *current_directory
;
280 /* The directory name is actually stored here (usually). */
281 char gdb_dirbuf
[1024];
283 /* Function to call before reading a command, if nonzero.
284 The function receives two args: an input stream,
285 and a prompt string. */
287 void (*window_hook
) PARAMS ((FILE *, char *));
292 /* gdb prints this when reading a command interactively */
293 static char *gdb_prompt_string
; /* the global prompt string */
294 extern char *get_prompt
PARAMS((void)); /* access function for prompt string */
296 /* Buffer used for reading command lines, and the size
297 allocated for it so far. */
302 /* Nonzero if the current command is modified by "server ". This
303 affects things like recording into the command history, comamnds
304 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
305 whatever) can issue its own commands and also send along commands
306 from the user, and have the user not notice that the user interface
307 is issuing commands too. */
310 /* Baud rate specified for talking to serial target systems. Default
311 is left as -1, so targets can choose their own defaults. */
312 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
313 or (unsigned int)-1. This is a Bad User Interface. */
317 /* Timeout limit for response from target. */
319 int remote_timeout
= 20; /* Set default to 20 */
321 /* Non-zero tells remote* modules to output debugging info. */
323 int remote_debug
= 0;
325 /* Non-zero means the target is running. Note: this is different from
326 saying that there is an active target and we are stopped at a
327 breakpoint, for instance. This is a real indicator whether the
328 target is off and running, which gdb is doing something else. */
329 int target_executing
= 0;
331 /* Level of control structure. */
332 static int control_level
;
334 /* Structure for arguments to user defined functions. */
335 #define MAXUSERARGS 10
338 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 when the current thread changes. Argument is thread id. */
461 void (*context_hook
) PARAMS ((int id
));
463 /* Takes control from error (). Typically used to prevent longjmps out of the
464 middle of the GUI. Usually used in conjunction with a catch routine. */
466 NORETURN
void (*error_hook
) PARAMS ((void)) ATTR_NORETURN
;
469 /* Where to go for return_to_top_level (RETURN_ERROR). */
470 SIGJMP_BUF error_return
;
471 /* Where to go for return_to_top_level (RETURN_QUIT). */
472 SIGJMP_BUF quit_return
;
474 /* Return for reason REASON. This generally gets back to the command
475 loop, but can be caught via catch_errors. */
478 return_to_top_level (reason
)
479 enum return_reason reason
;
484 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
485 I can think of a reason why that is vital, though). */
486 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
488 disable_current_display ();
489 do_cleanups (ALL_CLEANUPS
);
490 if (async_p
&& target_has_async
)
491 do_exec_cleanups (ALL_CLEANUPS
);
493 if (annotation_level
> 1)
504 (NORETURN
void) SIGLONGJMP
505 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
508 /* Call FUNC with arg ARGS, catching any errors. If there is no
509 error, return the value returned by FUNC. If there is an error,
510 print ERRSTRING, print the specific error message, then return
513 Must not be called with immediate_quit in effect (bad things might
514 happen, say we got a signal in the middle of a memcpy to quit_return).
515 This is an OK restriction; with very few exceptions immediate_quit can
516 be replaced by judicious use of QUIT.
518 MASK specifies what to catch; it is normally set to
519 RETURN_MASK_ALL, if for no other reason than that the code which
520 calls catch_errors might not be set up to deal with a quit which
521 isn't caught. But if the code can deal with it, it generally
522 should be RETURN_MASK_ERROR, unless for some reason it is more
523 useful to abort only the portion of the operation inside the
524 catch_errors. Note that quit should return to the command line
525 fairly quickly, even if some further processing is being done. */
528 catch_errors (func
, args
, errstring
, mask
)
529 catch_errors_ftype
*func
;
534 SIGJMP_BUF saved_error
;
535 SIGJMP_BUF saved_quit
;
538 struct cleanup
*saved_cleanup_chain
;
539 char *saved_error_pre_print
;
540 char *saved_quit_pre_print
;
542 saved_cleanup_chain
= save_cleanups ();
543 saved_error_pre_print
= error_pre_print
;
544 saved_quit_pre_print
= quit_pre_print
;
546 if (mask
& RETURN_MASK_ERROR
)
548 memcpy ((char *)saved_error
, (char *)error_return
, sizeof (SIGJMP_BUF
));
549 error_pre_print
= errstring
;
551 if (mask
& RETURN_MASK_QUIT
)
553 memcpy (saved_quit
, quit_return
, sizeof (SIGJMP_BUF
));
554 quit_pre_print
= errstring
;
557 if (SIGSETJMP (tmp_jmp
) == 0)
559 if (mask
& RETURN_MASK_ERROR
)
560 memcpy (error_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
561 if (mask
& RETURN_MASK_QUIT
)
562 memcpy (quit_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
563 val
= (*func
) (args
);
568 restore_cleanups (saved_cleanup_chain
);
570 if (mask
& RETURN_MASK_ERROR
)
572 memcpy (error_return
, saved_error
, sizeof (SIGJMP_BUF
));
573 error_pre_print
= saved_error_pre_print
;
575 if (mask
& RETURN_MASK_QUIT
)
577 memcpy (quit_return
, saved_quit
, sizeof (SIGJMP_BUF
));
578 quit_pre_print
= saved_quit_pre_print
;
583 /* Handler for SIGHUP. */
590 catch_errors (quit_cover
, NULL
,
591 "Could not kill the program being debugged", RETURN_MASK_ALL
);
592 signal (SIGHUP
, SIG_DFL
);
593 kill (getpid (), SIGHUP
);
596 /* Just a little helper function for disconnect(). */
598 /* NOTE 1999-04-29: This function will be static again, once we modify
599 gdb to use the event loop as the default command loop and we merge
600 event-top.c into this file, top.c */
605 caution
= 0; /* Throw caution to the wind -- we're exiting.
606 This prevents asking the user dumb questions. */
607 quit_command((char *)0, 0);
610 #endif /* defined SIGHUP */
612 /* Line number we are currently in in a file which is being sourced. */
613 /* NOTE 1999-04-29: This variable will be static again, once we modify
614 gdb to use the event loop as the default command loop and we merge
615 event-top.c into this file, top.c */
616 /* static */ int source_line_number
;
618 /* Name of the file we are sourcing. */
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 */ char *source_file_name
;
624 /* Buffer containing the error_pre_print used by the source stuff.
626 /* NOTE 1999-04-29: This variable will be static again, once we modify
627 gdb to use the event loop as the default command loop and we merge
628 event-top.c into this file, top.c */
629 /* static */ char *source_error
;
630 static int source_error_allocated
;
632 /* Something to glom on to the start of error_pre_print if source_file_name
634 /* NOTE 1999-04-29: This variable will be static again, once we modify
635 gdb to use the event loop as the default command loop and we merge
636 event-top.c into this file, top.c */
637 /* static */ char *source_pre_error
;
639 /* Clean up on error during a "source" command (or execution of a
640 user-defined command). */
643 source_cleanup (stream
)
646 /* Restore the previous input stream. */
650 /* Read commands from STREAM. */
652 read_command_file (stream
)
655 struct cleanup
*cleanups
;
657 cleanups
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
660 do_cleanups (cleanups
);
663 extern void init_proc
PARAMS ((void));
665 void (*pre_init_ui_hook
) PARAMS ((void));
671 if (pre_init_ui_hook
)
674 /* Run the init function of each source file */
676 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
677 current_directory
= gdb_dirbuf
;
679 init_cmd_lists (); /* This needs to be done first */
680 initialize_targets (); /* Setup target_terminal macros for utils.c */
681 initialize_utils (); /* Make errors and warnings possible */
682 initialize_all_files ();
683 init_main (); /* But that omits this file! Do it now */
685 /* The signal handling mechanism is different depending whether or
686 not the async version is run. NOTE: in the future we plan to make
687 the event loop be the default engine of gdb, and this difference
690 async_init_signals ();
694 /* We need a default language for parsing expressions, so simple things like
695 "set width 0" won't fail if no language is explicitly set in a config file
696 or implicitly set by reading an executable during startup. */
697 set_language (language_c
);
698 expected_language
= current_language
; /* don't warn about the change. */
700 /* All the interpreters should have had a look at things by now.
701 Initialize the selected interpreter. */
703 init_ui_hook (argv0
);
706 /* Allocate, initialize a new command line structure for one of the
707 control commands (if/while). */
709 static struct command_line
*
710 build_command_line (type
, args
)
711 enum command_control_type type
;
714 struct command_line
*cmd
;
717 error ("if/while commands require arguments.\n");
719 cmd
= (struct command_line
*)xmalloc (sizeof (struct command_line
));
721 cmd
->control_type
= type
;
725 = (struct command_line
**)xmalloc (sizeof (struct command_line
*)
727 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
728 cmd
->line
= savestring (args
, strlen (args
));
732 /* Build and return a new command structure for the control commands
733 such as "if" and "while". */
735 static struct command_line
*
736 get_command_line (type
, arg
)
737 enum command_control_type type
;
740 struct command_line
*cmd
;
741 struct cleanup
*old_chain
= NULL
;
743 /* Allocate and build a new command line structure. */
744 cmd
= build_command_line (type
, arg
);
746 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
, &cmd
);
748 /* Read in the body of this command. */
749 if (recurse_read_control_structure (cmd
) == invalid_control
)
751 warning ("error reading in control structure\n");
752 do_cleanups (old_chain
);
756 discard_cleanups (old_chain
);
760 /* Recursively print a command (including full control structures). */
762 print_command_line (cmd
, depth
, stream
)
763 struct command_line
*cmd
;
771 for (i
= 0; i
< depth
; i
++)
772 fputs_filtered (" ", stream
);
775 /* A simple command, print it and return. */
776 if (cmd
->control_type
== simple_control
)
778 fputs_filtered (cmd
->line
, stream
);
779 fputs_filtered ("\n", stream
);
783 /* loop_continue to jump to the start of a while loop, print it
785 if (cmd
->control_type
== continue_control
)
787 fputs_filtered ("loop_continue\n", stream
);
791 /* loop_break to break out of a while loop, print it and return. */
792 if (cmd
->control_type
== break_control
)
794 fputs_filtered ("loop_break\n", stream
);
798 /* A while command. Recursively print its subcommands before returning. */
799 if (cmd
->control_type
== while_control
)
801 struct command_line
*list
;
802 fputs_filtered ("while ", stream
);
803 fputs_filtered (cmd
->line
, stream
);
804 fputs_filtered ("\n", stream
);
805 list
= *cmd
->body_list
;
808 print_command_line (list
, depth
+ 1, stream
);
813 /* An if command. Recursively print both arms before returning. */
814 if (cmd
->control_type
== if_control
)
816 fputs_filtered ("if ", stream
);
817 fputs_filtered (cmd
->line
, stream
);
818 fputs_filtered ("\n", stream
);
820 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
822 /* Show the false arm if it exists. */
823 if (cmd
->body_count
== 2)
827 for (i
= 0; i
< depth
; i
++)
828 fputs_filtered (" ", stream
);
830 fputs_filtered ("else\n", stream
);
831 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
835 for (i
= 0; i
< depth
; i
++)
836 fputs_filtered (" ", stream
);
838 fputs_filtered ("end\n", stream
);
842 /* Execute the command in CMD. */
844 enum command_control_type
845 execute_control_command (cmd
)
846 struct command_line
*cmd
;
848 struct expression
*expr
;
849 struct command_line
*current
;
850 struct cleanup
*old_chain
= 0;
854 enum command_control_type ret
;
857 switch (cmd
->control_type
)
860 /* A simple command, execute it and return. */
861 new_line
= insert_args (cmd
->line
);
863 return invalid_control
;
864 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
866 execute_command (new_line
, 0);
867 ret
= cmd
->control_type
;
870 case continue_control
:
872 /* Return for "continue", and "break" so we can either
873 continue the loop at the top, or break out. */
874 ret
= cmd
->control_type
;
879 /* Parse the loop control expression for the while statement. */
880 new_line
= insert_args (cmd
->line
);
882 return invalid_control
;
883 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
885 expr
= parse_expression (new_line
);
886 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
888 ret
= simple_control
;
891 /* Keep iterating so long as the expression is true. */
898 /* Evaluate the expression. */
899 val_mark
= value_mark ();
900 val
= evaluate_expression (expr
);
901 cond_result
= value_true (val
);
902 value_free_to_mark (val_mark
);
904 /* If the value is false, then break out of the loop. */
908 /* Execute the body of the while statement. */
909 current
= *cmd
->body_list
;
912 ret
= execute_control_command (current
);
914 /* If we got an error, or a "break" command, then stop
916 if (ret
== invalid_control
|| ret
== break_control
)
922 /* If we got a "continue" command, then restart the loop
924 if (ret
== continue_control
)
927 /* Get the next statement. */
928 current
= current
->next
;
932 /* Reset RET so that we don't recurse the break all the way down. */
933 if (ret
== break_control
)
934 ret
= simple_control
;
941 new_line
= insert_args (cmd
->line
);
943 return invalid_control
;
944 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
946 /* Parse the conditional for the if statement. */
947 expr
= parse_expression (new_line
);
948 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
951 ret
= simple_control
;
953 /* Evaluate the conditional. */
954 val_mark
= value_mark ();
955 val
= evaluate_expression (expr
);
957 /* Choose which arm to take commands from based on the value of the
958 conditional expression. */
959 if (value_true (val
))
960 current
= *cmd
->body_list
;
961 else if (cmd
->body_count
== 2)
962 current
= *(cmd
->body_list
+ 1);
963 value_free_to_mark (val_mark
);
965 /* Execute commands in the given arm. */
968 ret
= execute_control_command (current
);
970 /* If we got an error, get out. */
971 if (ret
!= simple_control
)
974 /* Get the next statement in the body. */
975 current
= current
->next
;
982 warning ("Invalid control type in command structure.");
983 return invalid_control
;
987 do_cleanups (old_chain
);
992 /* "while" command support. Executes a body of statements while the
993 loop condition is nonzero. */
996 while_command (arg
, from_tty
)
1000 struct command_line
*command
= NULL
;
1003 command
= get_command_line (while_control
, arg
);
1005 if (command
== NULL
)
1008 execute_control_command (command
);
1009 free_command_lines (&command
);
1012 /* "if" command support. Execute either the true or false arm depending
1013 on the value of the if conditional. */
1016 if_command (arg
, from_tty
)
1020 struct command_line
*command
= NULL
;
1023 command
= get_command_line (if_control
, arg
);
1025 if (command
== NULL
)
1028 execute_control_command (command
);
1029 free_command_lines (&command
);
1036 struct user_args
*oargs
= user_args
;
1038 fatal ("Internal error, arg_cleanup called with no user args.\n");
1040 user_args
= user_args
->next
;
1044 /* Bind the incomming arguments for a user defined command to
1045 $arg0, $arg1 ... $argMAXUSERARGS. */
1047 static struct cleanup
*
1051 struct user_args
*args
;
1052 struct cleanup
*old_chain
;
1053 unsigned int arg_count
= 0;
1055 args
= (struct user_args
*)xmalloc (sizeof (struct user_args
));
1056 memset (args
, 0, sizeof (struct user_args
));
1058 args
->next
= user_args
;
1061 old_chain
= make_cleanup ((make_cleanup_func
) arg_cleanup
, 0);
1073 if (arg_count
>= MAXUSERARGS
)
1075 error ("user defined function may only have %d arguments.\n",
1080 /* Strip whitespace. */
1081 while (*p
== ' ' || *p
== '\t')
1084 /* P now points to an argument. */
1086 user_args
->a
[arg_count
].arg
= p
;
1088 /* Get to the end of this argument. */
1091 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1097 else if (*p
== '\\')
1120 user_args
->a
[arg_count
].len
= p
- start_arg
;
1127 /* Given character string P, return a point to the first argument ($arg),
1128 or NULL if P contains no arguments. */
1134 while ((p
= strchr (p
, '$')))
1136 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1143 /* Insert the user defined arguments stored in user_arg into the $arg
1144 arguments found in line, with the updated copy being placed into nline. */
1150 char *p
, *save_line
, *new_line
;
1153 /* First we need to know how much memory to allocate for the new line. */
1156 while ((p
= locate_arg (line
)))
1161 if (i
>= user_args
->count
)
1163 error ("Missing argument %d in user function.\n", i
);
1166 len
+= user_args
->a
[i
].len
;
1170 /* Don't forget the tail. */
1171 len
+= strlen (line
);
1173 /* Allocate space for the new line and fill it in. */
1174 new_line
= (char *)xmalloc (len
+ 1);
1175 if (new_line
== NULL
)
1178 /* Restore pointer to beginning of old line. */
1181 /* Save pointer to beginning of new line. */
1182 save_line
= new_line
;
1184 while ((p
= locate_arg (line
)))
1188 memcpy (new_line
, line
, p
- line
);
1189 new_line
+= p
- line
;
1192 len
= user_args
->a
[i
].len
;
1195 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1200 /* Don't forget the tail. */
1201 strcpy (new_line
, line
);
1203 /* Return a pointer to the beginning of the new line. */
1208 execute_user_command (c
, args
)
1209 struct cmd_list_element
*c
;
1212 register struct command_line
*cmdlines
;
1213 struct cleanup
*old_chain
;
1214 enum command_control_type ret
;
1216 old_chain
= setup_user_args (args
);
1218 cmdlines
= c
->user_commands
;
1223 /* Set the instream to 0, indicating execution of a
1224 user-defined function. */
1225 old_chain
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
1226 instream
= (FILE *) 0;
1229 ret
= execute_control_command (cmdlines
);
1230 if (ret
!= simple_control
&& ret
!= break_control
)
1232 warning ("Error in control structure.\n");
1235 cmdlines
= cmdlines
->next
;
1237 do_cleanups (old_chain
);
1240 /* Execute the line P as a command.
1241 Pass FROM_TTY as second argument to the defining function. */
1244 execute_command (p
, from_tty
)
1248 register struct cmd_list_element
*c
;
1249 register enum language flang
;
1250 static int warned
= 0;
1251 /* FIXME: These should really be in an appropriate header file */
1252 extern void serial_log_command
PARAMS ((const char *));
1256 /* Force cleanup of any alloca areas if using C alloca instead of
1257 a builtin alloca. */
1260 /* This can happen when command_line_input hits end of file. */
1264 serial_log_command (p
);
1266 while (*p
== ' ' || *p
== '\t') p
++;
1271 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1273 /* If the target is running, we allow only a limited set of
1275 if (async_p
&& target_has_async
&& target_executing
)
1276 if (!strcmp (c
->name
, "help")
1277 && !strcmp (c
->name
, "pwd")
1278 && !strcmp (c
->name
, "show")
1279 && !strcmp (c
->name
, "stop"))
1280 error ("Cannot execute this command while the target is running.");
1282 /* Pass null arg rather than an empty one. */
1285 /* Clear off trailing whitespace, except for set and complete command. */
1286 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1288 p
= arg
+ strlen (arg
) - 1;
1289 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1294 /* If this command has been hooked, run the hook first. */
1296 execute_user_command (c
->hook
, (char *)0);
1298 if (c
->class == class_user
)
1299 execute_user_command (c
, arg
);
1300 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1301 do_setshow_command (arg
, from_tty
& caution
, c
);
1302 else if (c
->function
.cfunc
== NO_FUNCTION
)
1303 error ("That is not a command, just a help topic.");
1304 else if (call_command_hook
)
1305 call_command_hook (c
, arg
, from_tty
& caution
);
1307 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1310 /* Tell the user if the language has changed (except first time). */
1311 if (current_language
!= expected_language
)
1313 if (language_mode
== language_mode_auto
) {
1314 language_info (1); /* Print what changed. */
1319 /* Warn the user if the working language does not match the
1320 language of the current frame. Only warn the user if we are
1321 actually running the program, i.e. there is a stack. */
1322 /* FIXME: This should be cacheing the frame and only running when
1323 the frame changes. */
1325 if (target_has_stack
)
1327 flang
= get_frame_language ();
1329 && flang
!= language_unknown
1330 && flang
!= current_language
->la_language
)
1332 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1339 /* NOTE 1999-04-29: This function will be static again, once we modify
1340 gdb to use the event loop as the default command loop and we merge
1341 event-top.c into this file, top.c */
1343 command_loop_marker (foo
)
1348 /* Read commands from `instream' and execute them
1349 until end of file or error reading instream. */
1354 struct cleanup
*old_chain
;
1356 int stdin_is_tty
= ISATTY (stdin
);
1357 long time_at_cmd_start
;
1359 long space_at_cmd_start
= 0;
1361 extern int display_time
;
1362 extern int display_space
;
1364 while (instream
&& !feof (instream
))
1367 extern int insert_mode
;
1369 if (window_hook
&& instream
== stdin
)
1370 (*window_hook
) (instream
, get_prompt ());
1373 if (instream
== stdin
&& stdin_is_tty
)
1374 reinitialize_more_filter ();
1375 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1378 /* A bit of paranoia: I want to make sure the "insert_mode" global
1379 * is clear except when it is being used for command-line editing
1380 * (see tuiIO.c, utils.c); otherwise normal output will
1381 * get messed up in the TUI. So clear it before/after
1382 * the command-line-input call. - RT
1386 /* Get a command-line. This calls the readline package. */
1387 command
= command_line_input (instream
== stdin
?
1388 get_prompt () : (char *) NULL
,
1389 instream
== stdin
, "prompt");
1396 time_at_cmd_start
= get_run_time ();
1401 extern char **environ
;
1402 char *lim
= (char *) sbrk (0);
1404 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1408 execute_command (command
, instream
== stdin
);
1409 /* Do any commands attached to breakpoint we stopped at. */
1410 bpstat_do_actions (&stop_bpstat
);
1411 do_cleanups (old_chain
);
1415 long cmd_time
= get_run_time () - time_at_cmd_start
;
1417 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1418 cmd_time
/ 1000000, cmd_time
% 1000000);
1424 extern char **environ
;
1425 char *lim
= (char *) sbrk (0);
1426 long space_now
= lim
- (char *) &environ
;
1427 long space_diff
= space_now
- space_at_cmd_start
;
1429 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1431 (space_diff
>= 0 ? '+' : '-'),
1439 /* Commands call this if they do not want to be repeated by null lines. */
1447 /* If we aren't reading from standard input, we are saving the last
1448 thing read from stdin in line and don't want to delete it. Null lines
1449 won't repeat here in any case. */
1450 if (instream
== stdin
)
1454 /* Read a line from the stream "instream" without command line editing.
1456 It prints PROMPT_ARG once at the start.
1457 Action is compatible with "readline", e.g. space for the result is
1458 malloc'd and should be freed by the caller.
1460 A NULL return means end of file. */
1462 gdb_readline (prompt_arg
)
1467 int input_index
= 0;
1468 int result_size
= 80;
1472 /* Don't use a _filtered function here. It causes the assumed
1473 character position to be off, since the newline we read from
1474 the user is not accounted for. */
1475 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1477 /* Move to a new line so the entered line doesn't have a prompt
1478 on the front of it. */
1479 fputs_unfiltered ("\n", gdb_stdout
);
1481 gdb_flush (gdb_stdout
);
1484 result
= (char *) xmalloc (result_size
);
1488 /* Read from stdin if we are executing a user defined command.
1489 This is the right thing for prompt_for_continue, at least. */
1490 c
= fgetc (instream
? instream
: stdin
);
1494 if (input_index
> 0)
1495 /* The last line does not end with a newline. Return it, and
1496 if we are called again fgetc will still return EOF and
1497 we'll return NULL then. */
1504 #ifndef CRLF_SOURCE_FILES
1508 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1514 result
[input_index
++] = c
;
1515 while (input_index
>= result_size
)
1518 result
= (char *) xrealloc (result
, result_size
);
1522 result
[input_index
++] = '\0';
1526 /* Variables which control command line editing and history
1527 substitution. These variables are given default values at the end
1529 static int command_editing_p
;
1530 /* NOTE 1999-04-29: This variable will be static again, once we modify
1531 gdb to use the event loop as the default command loop and we merge
1532 event-top.c into this file, top.c */
1533 /* static */ int history_expansion_p
;
1534 static int write_history_p
;
1535 static int history_size
;
1536 static char *history_filename
;
1538 /* readline uses the word breaks for two things:
1539 (1) In figuring out where to point the TEXT parameter to the
1540 rl_completion_entry_function. Since we don't use TEXT for much,
1541 it doesn't matter a lot what the word breaks are for this purpose, but
1542 it does affect how much stuff M-? lists.
1543 (2) If one of the matches contains a word break character, readline
1544 will quote it. That's why we switch between
1545 gdb_completer_word_break_characters and
1546 gdb_completer_command_word_break_characters. I'm not sure when
1547 we need this behavior (perhaps for funky characters in C++ symbols?). */
1549 /* Variables which are necessary for fancy command line editing. */
1550 char *gdb_completer_word_break_characters
=
1551 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1553 /* When completing on command names, we remove '-' from the list of
1554 word break characters, since we use it in command names. If the
1555 readline library sees one in any of the current completion strings,
1556 it thinks that the string needs to be quoted and automatically supplies
1558 char *gdb_completer_command_word_break_characters
=
1559 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1561 /* Characters that can be used to quote completion strings. Note that we
1562 can't include '"' because the gdb C parser treats such quoted sequences
1564 char *gdb_completer_quote_characters
=
1567 /* Functions that are used as part of the fancy command line editing. */
1569 /* This can be used for functions which don't want to complete on symbols
1570 but don't want to complete on anything else either. */
1573 noop_completer (text
, prefix
)
1580 /* Complete on filenames. */
1582 filename_completer (text
, word
)
1586 /* From readline. */
1587 extern char *filename_completion_function
PARAMS ((char *, int));
1588 int subsequent_name
;
1590 int return_val_used
;
1591 int return_val_alloced
;
1593 return_val_used
= 0;
1594 /* Small for testing. */
1595 return_val_alloced
= 1;
1596 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1598 subsequent_name
= 0;
1602 p
= filename_completion_function (text
, subsequent_name
);
1603 if (return_val_used
>= return_val_alloced
)
1605 return_val_alloced
*= 2;
1607 (char **) xrealloc (return_val
,
1608 return_val_alloced
* sizeof (char *));
1612 return_val
[return_val_used
++] = p
;
1615 /* Like emacs, don't complete on old versions. Especially useful
1616 in the "source" command. */
1617 if (p
[strlen (p
) - 1] == '~')
1623 /* Return exactly p. */
1624 return_val
[return_val_used
++] = p
;
1625 else if (word
> text
)
1627 /* Return some portion of p. */
1628 q
= xmalloc (strlen (p
) + 5);
1629 strcpy (q
, p
+ (word
- text
));
1630 return_val
[return_val_used
++] = q
;
1635 /* Return some of TEXT plus p. */
1636 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1637 strncpy (q
, word
, text
- word
);
1638 q
[text
- word
] = '\0';
1640 return_val
[return_val_used
++] = q
;
1644 subsequent_name
= 1;
1647 /* There is no way to do this just long enough to affect quote inserting
1648 without also affecting the next completion. This should be fixed in
1650 /* Insure that readline does the right thing
1651 with respect to inserting quotes. */
1652 rl_completer_word_break_characters
= "";
1657 /* Here are some useful test cases for completion. FIXME: These should
1658 be put in the test suite. They should be tested with both M-? and TAB.
1660 "show output-" "radix"
1661 "show output" "-radix"
1662 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1663 "p " ambiguous (all symbols)
1664 "info t foo" no completions
1665 "info t " no completions
1666 "info t" ambiguous ("info target", "info terminal", etc.)
1667 "info ajksdlfk" no completions
1668 "info ajksdlfk " no completions
1670 "info " ambiguous (all info commands)
1671 "p \"a" no completions (string constant)
1672 "p 'a" ambiguous (all symbols starting with a)
1673 "p b-a" ambiguous (all symbols starting with a)
1674 "p b-" ambiguous (all symbols)
1675 "file Make" "file" (word break hard to screw up here)
1676 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1679 /* Generate completions one by one for the completer. Each time we are
1680 called return another potential completion to the caller.
1681 line_completion just completes on commands or passes the buck to the
1682 command's completer function, the stuff specific to symbol completion
1683 is in make_symbol_completion_list.
1685 TEXT is the caller's idea of the "word" we are looking at.
1687 MATCHES is the number of matches that have currently been collected from
1688 calling this completion function. When zero, then we need to initialize,
1689 otherwise the initialization has already taken place and we can just
1690 return the next potential completion string.
1692 LINE_BUFFER is available to be looked at; it contains the entire text
1693 of the line. POINT is the offset in that line of the cursor. You
1694 should pretend that the line ends at POINT.
1696 Returns NULL if there are no more completions, else a pointer to a string
1697 which is a possible completion, it is the caller's responsibility to
1701 line_completion_function (text
, matches
, line_buffer
, point
)
1707 static char **list
= (char **)NULL
; /* Cache of completions */
1708 static int index
; /* Next cached completion */
1709 char *output
= NULL
;
1710 char *tmp_command
, *p
;
1711 /* Pointer within tmp_command which corresponds to text. */
1713 struct cmd_list_element
*c
, *result_list
;
1717 /* The caller is beginning to accumulate a new set of completions, so
1718 we need to find all of them now, and cache them for returning one at
1719 a time on future calls. */
1723 /* Free the storage used by LIST, but not by the strings inside.
1724 This is because rl_complete_internal () frees the strings. */
1730 /* Choose the default set of word break characters to break completions.
1731 If we later find out that we are doing completions on command strings
1732 (as opposed to strings supplied by the individual command completer
1733 functions, which can be any string) then we will switch to the
1734 special word break set for command strings, which leaves out the
1735 '-' character used in some commands. */
1737 rl_completer_word_break_characters
=
1738 gdb_completer_word_break_characters
;
1740 /* Decide whether to complete on a list of gdb commands or on symbols. */
1741 tmp_command
= (char *) alloca (point
+ 1);
1744 strncpy (tmp_command
, line_buffer
, point
);
1745 tmp_command
[point
] = '\0';
1746 /* Since text always contains some number of characters leading up
1747 to point, we can find the equivalent position in tmp_command
1748 by subtracting that many characters from the end of tmp_command. */
1749 word
= tmp_command
+ point
- strlen (text
);
1753 /* An empty line we want to consider ambiguous; that is, it
1754 could be any command. */
1755 c
= (struct cmd_list_element
*) -1;
1760 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1763 /* Move p up to the next interesting thing. */
1764 while (*p
== ' ' || *p
== '\t')
1771 /* It is an unrecognized command. So there are no
1772 possible completions. */
1775 else if (c
== (struct cmd_list_element
*) -1)
1779 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1780 doesn't advance over that thing itself. Do so now. */
1782 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1784 if (q
!= tmp_command
+ point
)
1786 /* There is something beyond the ambiguous
1787 command, so there are no possible completions. For
1788 example, "info t " or "info t foo" does not complete
1789 to anything, because "info t" can be "info target" or
1795 /* We're trying to complete on the command which was ambiguous.
1796 This we can deal with. */
1799 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1804 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1806 /* Insure that readline does the right thing with respect to
1807 inserting quotes. */
1808 rl_completer_word_break_characters
=
1809 gdb_completer_command_word_break_characters
;
1814 /* We've recognized a full command. */
1816 if (p
== tmp_command
+ point
)
1818 /* There is no non-whitespace in the line beyond the command. */
1820 if (p
[-1] == ' ' || p
[-1] == '\t')
1822 /* The command is followed by whitespace; we need to complete
1823 on whatever comes after command. */
1826 /* It is a prefix command; what comes after it is
1827 a subcommand (e.g. "info "). */
1828 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1830 /* Insure that readline does the right thing
1831 with respect to inserting quotes. */
1832 rl_completer_word_break_characters
=
1833 gdb_completer_command_word_break_characters
;
1837 list
= complete_on_enum (c
->enums
, p
, word
);
1838 rl_completer_word_break_characters
=
1839 gdb_completer_command_word_break_characters
;
1843 /* It is a normal command; what comes after it is
1844 completed by the command's completer function. */
1845 list
= (*c
->completer
) (p
, word
);
1850 /* The command is not followed by whitespace; we need to
1851 complete on the command itself. e.g. "p" which is a
1852 command itself but also can complete to "print", "ptype"
1856 /* Find the command we are completing on. */
1858 while (q
> tmp_command
)
1860 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1866 list
= complete_on_cmdlist (result_list
, q
, word
);
1868 /* Insure that readline does the right thing
1869 with respect to inserting quotes. */
1870 rl_completer_word_break_characters
=
1871 gdb_completer_command_word_break_characters
;
1876 /* There is non-whitespace beyond the command. */
1878 if (c
->prefixlist
&& !c
->allow_unknown
)
1880 /* It is an unrecognized subcommand of a prefix command,
1881 e.g. "info adsfkdj". */
1886 list
= complete_on_enum (c
->enums
, p
, word
);
1890 /* It is a normal command. */
1891 list
= (*c
->completer
) (p
, word
);
1897 /* If we found a list of potential completions during initialization then
1898 dole them out one at a time. The vector of completions is NULL
1899 terminated, so after returning the last one, return NULL (and continue
1900 to do so) each time we are called after that, until a new list is
1905 output
= list
[index
];
1913 /* Can't do this because readline hasn't yet checked the word breaks
1914 for figuring out whether to insert a quote. */
1916 /* Make sure the word break characters are set back to normal for the
1917 next time that readline tries to complete something. */
1918 rl_completer_word_break_characters
=
1919 gdb_completer_word_break_characters
;
1925 /* Line completion interface function for readline. */
1928 readline_line_completion_function (text
, matches
)
1932 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
1935 /* Skip over a possibly quoted word (as defined by the quote characters
1936 and word break characters the completer uses). Returns pointer to the
1937 location after the "word". */
1943 char quote_char
= '\0';
1946 for (scan
= str
; *scan
!= '\0'; scan
++)
1948 if (quote_char
!= '\0')
1950 /* Ignore everything until the matching close quote char */
1951 if (*scan
== quote_char
)
1953 /* Found matching close quote. */
1958 else if (strchr (gdb_completer_quote_characters
, *scan
))
1960 /* Found start of a quoted string. */
1963 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1977 #if STOP_SIGNAL == SIGTSTP
1978 signal (SIGTSTP
, SIG_DFL
);
1980 kill (getpid (), SIGTSTP
);
1981 signal (SIGTSTP
, stop_sig
);
1983 signal (STOP_SIGNAL
, stop_sig
);
1985 printf_unfiltered ("%s", get_prompt ());
1986 gdb_flush (gdb_stdout
);
1988 /* Forget about any previous command -- null line now will do nothing. */
1991 #endif /* STOP_SIGNAL */
1993 /* Initialize signal handlers. */
1998 /* Under System V the default disposition of a signal is reinstated after
1999 the signal is caught and delivered to an application process. On such
2000 systems one must restore the replacement signal handler if one wishes
2001 to continue handling the signal in one's program. On BSD systems this
2002 is not needed but it is harmless, and it simplifies the code to just do
2003 it unconditionally. */
2004 signal (signo
, do_nothing
);
2010 signal (SIGINT
, request_quit
);
2012 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2013 to the inferior and breakpoints will be ignored. */
2015 signal (SIGTRAP
, SIG_DFL
);
2018 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2019 passed to the inferior, which we don't want. It would be
2020 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2021 on BSD4.3 systems using vfork, that can affect the
2022 GDB process as well as the inferior (the signal handling tables
2023 might be in memory, shared between the two). Since we establish
2024 a handler for SIGQUIT, when we call exec it will set the signal
2025 to SIG_DFL for us. */
2026 signal (SIGQUIT
, do_nothing
);
2028 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
2029 signal (SIGHUP
, disconnect
);
2031 signal (SIGFPE
, float_handler
);
2033 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2034 signal (SIGWINCH
, SIGWINCH_HANDLER
);
2038 /* Read one line from the command input stream `instream'
2039 into the local static buffer `linebuffer' (whose current length
2041 The buffer is made bigger as necessary.
2042 Returns the address of the start of the line.
2044 NULL is returned for end of file.
2046 *If* the instream == stdin & stdin is a terminal, the line read
2047 is copied into the file line saver (global var char *line,
2048 length linesize) so that it can be duplicated.
2050 This routine either uses fancy command line editing or
2051 simple input as the user has requested. */
2054 command_line_input (prompt_arg
, repeat
, annotation_suffix
)
2057 char *annotation_suffix
;
2059 static char *linebuffer
= 0;
2060 static unsigned linelength
= 0;
2064 char *local_prompt
= prompt_arg
;
2068 /* The annotation suffix must be non-NULL. */
2069 if (annotation_suffix
== NULL
)
2070 annotation_suffix
= "";
2072 if (annotation_level
> 1 && instream
== stdin
)
2074 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
2075 + strlen (annotation_suffix
) + 40);
2076 if (prompt_arg
== NULL
)
2077 local_prompt
[0] = '\0';
2079 strcpy (local_prompt
, prompt_arg
);
2080 strcat (local_prompt
, "\n\032\032");
2081 strcat (local_prompt
, annotation_suffix
);
2082 strcat (local_prompt
, "\n");
2085 if (linebuffer
== 0)
2088 linebuffer
= (char *) xmalloc (linelength
);
2093 /* Control-C quits instantly if typed while in this loop
2094 since it should not wait until the user types a newline. */
2100 signal (STOP_SIGNAL
, handle_stop_sig
);
2102 signal (STOP_SIGNAL
, stop_sig
);
2108 /* Make sure that all output has been output. Some machines may let
2109 you get away with leaving out some of the gdb_flush, but not all. */
2111 gdb_flush (gdb_stdout
);
2112 gdb_flush (gdb_stderr
);
2114 if (source_file_name
!= NULL
)
2116 ++source_line_number
;
2117 sprintf (source_error
,
2118 "%s%s:%d: Error in sourced command file:\n",
2121 source_line_number
);
2122 error_pre_print
= source_error
;
2125 if (annotation_level
> 1 && instream
== stdin
)
2127 printf_unfiltered ("\n\032\032pre-");
2128 printf_unfiltered (annotation_suffix
);
2129 printf_unfiltered ("\n");
2132 /* Don't use fancy stuff if not talking to stdin. */
2133 if (readline_hook
&& instream
== NULL
)
2135 rl
= (*readline_hook
) (local_prompt
);
2137 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2139 rl
= readline (local_prompt
);
2143 rl
= gdb_readline (local_prompt
);
2146 if (annotation_level
> 1 && instream
== stdin
)
2148 printf_unfiltered ("\n\032\032post-");
2149 printf_unfiltered (annotation_suffix
);
2150 printf_unfiltered ("\n");
2153 if (!rl
|| rl
== (char *) EOF
)
2158 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
2160 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
2161 nline
= (char *) xrealloc (linebuffer
, linelength
);
2162 p
+= nline
- linebuffer
;
2166 /* Copy line. Don't copy null at end. (Leaves line alone
2167 if this was just a newline) */
2171 free (rl
); /* Allocated in readline. */
2173 if (p
== linebuffer
|| *(p
- 1) != '\\')
2176 p
--; /* Put on top of '\'. */
2177 local_prompt
= (char *) 0;
2182 signal (STOP_SIGNAL
, SIG_DFL
);
2189 #define SERVER_COMMAND_LENGTH 7
2191 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2192 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2195 /* Note that we don't set `line'. Between this and the check in
2196 dont_repeat, this insures that repeating will still do the
2199 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2202 /* Do history expansion if that is wished. */
2203 if (history_expansion_p
&& instream
== stdin
2204 && ISATTY (instream
))
2206 char *history_value
;
2209 *p
= '\0'; /* Insert null now. */
2210 expanded
= history_expand (linebuffer
, &history_value
);
2213 /* Print the changes. */
2214 printf_unfiltered ("%s\n", history_value
);
2216 /* If there was an error, call this function again. */
2219 free (history_value
);
2220 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2222 if (strlen (history_value
) > linelength
)
2224 linelength
= strlen (history_value
) + 1;
2225 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2227 strcpy (linebuffer
, history_value
);
2228 p
= linebuffer
+ strlen(linebuffer
);
2229 free (history_value
);
2233 /* If we just got an empty line, and that is supposed
2234 to repeat the previous command, return the value in the
2236 if (repeat
&& p
== linebuffer
)
2238 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++) ;
2244 /* Add line to history if appropriate. */
2245 if (instream
== stdin
2246 && ISATTY (stdin
) && *linebuffer
)
2247 add_history (linebuffer
);
2249 /* Note: lines consisting solely of comments are added to the command
2250 history. This is useful when you type a command, and then
2251 realize you don't want to execute it quite yet. You can comment
2252 out the command and then later fetch it from the value history
2253 and remove the '#'. The kill ring is probably better, but some
2254 people are in the habit of commenting things out. */
2256 *p1
= '\0'; /* Found a comment. */
2258 /* Save into global buffer if appropriate. */
2261 if (linelength
> linesize
)
2263 line
= xrealloc (line
, linelength
);
2264 linesize
= linelength
;
2266 strcpy (line
, linebuffer
);
2274 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2275 code bodies. This is typically used when we encounter an "else"
2276 clause for an "if" command. */
2279 realloc_body_list (command
, new_length
)
2280 struct command_line
*command
;
2284 struct command_line
**body_list
;
2286 n
= command
->body_count
;
2288 /* Nothing to do? */
2289 if (new_length
<= n
)
2292 body_list
= (struct command_line
**)
2293 xmalloc (sizeof (struct command_line
*) * new_length
);
2295 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2297 free (command
->body_list
);
2298 command
->body_list
= body_list
;
2299 command
->body_count
= new_length
;
2302 /* Read one line from the input stream. If the command is an "else" or
2303 "end", return such an indication to the caller. */
2305 static enum misc_command_type
2306 read_next_line (command
)
2307 struct command_line
**command
;
2309 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2312 if (control_level
>= 254)
2313 error ("Control nesting too deep!\n");
2315 /* Set a prompt based on the nesting of the control commands. */
2316 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2318 for (i
= 0; i
< control_level
; i
++)
2319 control_prompt
[i
] = ' ';
2320 control_prompt
[i
] = '>';
2321 control_prompt
[i
+1] = '\0';
2322 prompt_ptr
= (char *)&control_prompt
[0];
2327 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2329 /* Not sure what to do here. */
2333 /* Strip leading and trailing whitespace. */
2334 while (*p
== ' ' || *p
== '\t')
2337 p1
= p
+ strlen (p
);
2338 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2341 /* Blanks and comments don't really do anything, but we need to
2342 distinguish them from else, end and other commands which can be
2344 if (p1
== p
|| p
[0] == '#')
2347 /* Is this the end of a simple, while, or if control structure? */
2348 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2351 /* Is the else clause of an if control structure? */
2352 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2353 return else_command
;
2355 /* Check for while, if, break, continue, etc and build a new command
2356 line structure for them. */
2357 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2358 *command
= build_command_line (while_control
, p
+ 6);
2359 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2360 *command
= build_command_line (if_control
, p
+ 3);
2361 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2363 *command
= (struct command_line
*)
2364 xmalloc (sizeof (struct command_line
));
2365 (*command
)->next
= NULL
;
2366 (*command
)->line
= NULL
;
2367 (*command
)->control_type
= break_control
;
2368 (*command
)->body_count
= 0;
2369 (*command
)->body_list
= NULL
;
2371 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2373 *command
= (struct command_line
*)
2374 xmalloc (sizeof (struct command_line
));
2375 (*command
)->next
= NULL
;
2376 (*command
)->line
= NULL
;
2377 (*command
)->control_type
= continue_control
;
2378 (*command
)->body_count
= 0;
2379 (*command
)->body_list
= NULL
;
2383 /* A normal command. */
2384 *command
= (struct command_line
*)
2385 xmalloc (sizeof (struct command_line
));
2386 (*command
)->next
= NULL
;
2387 (*command
)->line
= savestring (p
, p1
- p
);
2388 (*command
)->control_type
= simple_control
;
2389 (*command
)->body_count
= 0;
2390 (*command
)->body_list
= NULL
;
2393 /* Nothing special. */
2397 /* Recursively read in the control structures and create a command_line
2398 structure from them.
2400 The parent_control parameter is the control structure in which the
2401 following commands are nested. */
2403 static enum command_control_type
2404 recurse_read_control_structure (current_cmd
)
2405 struct command_line
*current_cmd
;
2407 int current_body
, i
;
2408 enum misc_command_type val
;
2409 enum command_control_type ret
;
2410 struct command_line
**body_ptr
, *child_tail
, *next
;
2415 /* Sanity checks. */
2416 if (current_cmd
->control_type
== simple_control
)
2418 error ("Recursed on a simple control type\n");
2419 return invalid_control
;
2422 if (current_body
> current_cmd
->body_count
)
2424 error ("Allocated body is smaller than this command type needs\n");
2425 return invalid_control
;
2428 /* Read lines from the input stream and build control structures. */
2434 val
= read_next_line (&next
);
2436 /* Just skip blanks and comments. */
2437 if (val
== nop_command
)
2440 if (val
== end_command
)
2442 if (current_cmd
->control_type
== while_control
2443 || current_cmd
->control_type
== if_control
)
2445 /* Success reading an entire control structure. */
2446 ret
= simple_control
;
2451 ret
= invalid_control
;
2456 /* Not the end of a control structure. */
2457 if (val
== else_command
)
2459 if (current_cmd
->control_type
== if_control
2460 && current_body
== 1)
2462 realloc_body_list (current_cmd
, 2);
2469 ret
= invalid_control
;
2476 child_tail
->next
= next
;
2480 body_ptr
= current_cmd
->body_list
;
2481 for (i
= 1; i
< current_body
; i
++)
2490 /* If the latest line is another control structure, then recurse
2492 if (next
->control_type
== while_control
2493 || next
->control_type
== if_control
)
2496 ret
= recurse_read_control_structure (next
);
2499 if (ret
!= simple_control
)
2509 /* Read lines from the input stream and accumulate them in a chain of
2510 struct command_line's, which is then returned. For input from a
2511 terminal, the special command "end" is used to mark the end of the
2512 input, and is not included in the returned chain of commands. */
2514 #define END_MESSAGE "End with a line saying just \"end\"."
2516 struct command_line
*
2517 read_command_lines (prompt_arg
, from_tty
)
2521 struct command_line
*head
, *tail
, *next
;
2522 struct cleanup
*old_chain
;
2523 enum command_control_type ret
;
2524 enum misc_command_type val
;
2527 if (readline_begin_hook
)
2529 /* Note - intentional to merge messages with no newline */
2530 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2532 else if (from_tty
&& input_from_terminal_p ())
2534 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2535 gdb_flush (gdb_stdout
);
2543 val
= read_next_line (&next
);
2545 /* Ignore blank lines or comments. */
2546 if (val
== nop_command
)
2549 if (val
== end_command
)
2551 ret
= simple_control
;
2555 if (val
!= ok_command
)
2557 ret
= invalid_control
;
2561 if (next
->control_type
== while_control
2562 || next
->control_type
== if_control
)
2565 ret
= recurse_read_control_structure (next
);
2568 if (ret
== invalid_control
)
2579 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
,
2589 if (ret
!= invalid_control
)
2591 discard_cleanups (old_chain
);
2594 do_cleanups (old_chain
);
2597 if (readline_end_hook
)
2599 (*readline_end_hook
) ();
2604 /* Free a chain of struct command_line's. */
2607 free_command_lines (lptr
)
2608 struct command_line
**lptr
;
2610 register struct command_line
*l
= *lptr
;
2611 register struct command_line
*next
;
2612 struct command_line
**blist
;
2617 if (l
->body_count
> 0)
2619 blist
= l
->body_list
;
2620 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2621 free_command_lines (blist
);
2630 /* Add an element to the list of info subcommands. */
2633 add_info (name
, fun
, doc
)
2635 void (*fun
) PARAMS ((char *, int));
2638 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2641 /* Add an alias to the list of info subcommands. */
2644 add_info_alias (name
, oldname
, abbrev_flag
)
2649 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2652 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2653 Therefore, its own definition is called only for "info" with no args. */
2657 info_command (arg
, from_tty
)
2661 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2662 help_list (infolist
, "info ", -1, gdb_stdout
);
2665 /* The "complete" command is used by Emacs to implement completion. */
2669 complete_command (arg
, from_tty
)
2681 argpoint
= strlen (arg
);
2683 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2685 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2687 printf_unfiltered ("%s\n", completion
);
2692 /* The "show" command with no arguments shows all the settings. */
2696 show_command (arg
, from_tty
)
2700 cmd_show_list (showlist
, from_tty
, "");
2703 /* Add an element to the list of commands. */
2706 add_com (name
, class, fun
, doc
)
2708 enum command_class
class;
2709 void (*fun
) PARAMS ((char *, int));
2712 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2715 /* Add an alias or abbreviation command to the list of commands. */
2718 add_com_alias (name
, oldname
, class, abbrev_flag
)
2721 enum command_class
class;
2724 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2731 error ("Argument required (%s).", why
);
2736 help_command (command
, from_tty
)
2738 int from_tty
; /* Ignored */
2740 help_cmd (command
, gdb_stdout
);
2744 validate_comname (comname
)
2750 error_no_arg ("name of command to define");
2755 if (!isalnum(*p
) && *p
!= '-' && *p
!= '_')
2756 error ("Junk in argument list: \"%s\"", p
);
2761 /* This is just a placeholder in the command data structures. */
2763 user_defined_command (ignore
, from_tty
)
2770 define_command (comname
, from_tty
)
2774 register struct command_line
*cmds
;
2775 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2776 char *tem
= comname
;
2778 #define HOOK_STRING "hook-"
2781 validate_comname (comname
);
2783 /* Look it up, and verify that we got an exact match. */
2784 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2785 if (c
&& !STREQ (comname
, c
->name
))
2790 if (c
->class == class_user
|| c
->class == class_alias
)
2791 tem
= "Redefine command \"%s\"? ";
2793 tem
= "Really redefine built-in command \"%s\"? ";
2794 if (!query (tem
, c
->name
))
2795 error ("Command \"%s\" not redefined.", c
->name
);
2798 /* If this new command is a hook, then mark the command which it
2799 is hooking. Note that we allow hooking `help' commands, so that
2800 we can hook the `stop' pseudo-command. */
2802 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2804 /* Look up cmd it hooks, and verify that we got an exact match. */
2805 tem
= comname
+HOOK_LEN
;
2806 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2807 if (hookc
&& !STREQ (comname
+HOOK_LEN
, hookc
->name
))
2811 warning ("Your new `%s' command does not hook any existing command.",
2813 if (!query ("Proceed? "))
2814 error ("Not confirmed.");
2818 comname
= savestring (comname
, strlen (comname
));
2820 /* If the rest of the commands will be case insensitive, this one
2821 should behave in the same manner. */
2822 for (tem
= comname
; *tem
; tem
++)
2823 if (isupper(*tem
)) *tem
= tolower(*tem
);
2825 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
2826 cmds
= read_command_lines (tmpbuf
, from_tty
);
2828 if (c
&& c
->class == class_user
)
2829 free_command_lines (&c
->user_commands
);
2831 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2832 (c
&& c
->class == class_user
)
2833 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2834 newc
->user_commands
= cmds
;
2836 /* If this new command is a hook, then mark both commands as being
2840 hookc
->hook
= newc
; /* Target gets hooked. */
2841 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2846 document_command (comname
, from_tty
)
2850 struct command_line
*doclines
;
2851 register struct cmd_list_element
*c
;
2852 char *tem
= comname
;
2855 validate_comname (comname
);
2857 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2859 if (c
->class != class_user
)
2860 error ("Command \"%s\" is built-in.", comname
);
2862 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
2863 doclines
= read_command_lines (tmpbuf
, from_tty
);
2865 if (c
->doc
) free (c
->doc
);
2868 register struct command_line
*cl1
;
2869 register int len
= 0;
2871 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2872 len
+= strlen (cl1
->line
) + 1;
2874 c
->doc
= (char *) xmalloc (len
+ 1);
2877 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2879 strcat (c
->doc
, cl1
->line
);
2881 strcat (c
->doc
, "\n");
2885 free_command_lines (&doclines
);
2888 /* Print the GDB banner. */
2890 print_gdb_version (stream
)
2893 /* From GNU coding standards, first line is meant to be easy for a
2894 program to parse, and is just canonical program name and version
2895 number, which starts after last space. */
2897 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
2899 /* Second line is a copyright notice. */
2901 fprintf_filtered (stream
, "Copyright 1998 Free Software Foundation, Inc.\n");
2903 /* Following the copyright is a brief statement that the program is
2904 free software, that users are free to copy and change it on
2905 certain conditions, that it is covered by the GNU GPL, and that
2906 there is no warranty. */
2908 fprintf_filtered (stream
, "\
2909 GDB is free software, covered by the GNU General Public License, and you are\n\
2910 welcome to change it and/or distribute copies of it under certain conditions.\n\
2911 Type \"show copying\" to see the conditions.\n\
2912 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2914 /* After the required info we print the configuration information. */
2916 fprintf_filtered (stream
, "This GDB was configured as \"");
2917 if (!STREQ (host_name
, target_name
))
2919 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
2923 fprintf_filtered (stream
, "%s", host_name
);
2925 fprintf_filtered (stream
, "\".");
2930 show_version (args
, from_tty
)
2935 print_gdb_version (gdb_stdout
);
2936 printf_filtered ("\n");
2940 /* get_prompt: access method for the GDB prompt string. */
2942 #define MAX_PROMPT_SIZE 256
2945 * int get_prompt_1 (char * buf);
2947 * Work-horse for get_prompt (called via catch_errors).
2948 * Argument is buffer to hold the formatted prompt.
2950 * Returns: 1 for success (use formatted prompt)
2951 * 0 for failure (use gdb_prompt_string).
2954 static int gdb_prompt_escape
;
2957 get_prompt_1 (formatted_prompt
)
2958 char *formatted_prompt
;
2963 local_prompt
= PROMPT (0);
2965 local_prompt
= gdb_prompt_string
;
2968 if (gdb_prompt_escape
== 0)
2970 return 0; /* do no formatting */
2972 else /* formatted prompt */
2974 char fmt
[40], *promptp
, *outp
, *tmp
;
2981 struct type
*arg_type
, *elt_type
;
2983 promptp
= local_prompt
;
2984 outp
= formatted_prompt
;
2986 while (*promptp
!= '\0')
2988 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
2990 if (*promptp
!= gdb_prompt_escape
)
2992 if (available
>= 1) /* overflow protect */
2993 *outp
++ = *promptp
++;
2997 /* GDB prompt string contains escape char. Parse for arg.
2998 Two consecutive escape chars followed by arg followed by
2999 a comma means to insert the arg using a default format.
3000 Otherwise a printf format string may be included between
3001 the two escape chars. eg:
3002 %%foo, insert foo using default format
3003 %2.2f%foo, insert foo using "%2.2f" format
3004 A mismatch between the format string and the data type
3005 of "foo" is an error (which we don't know how to protect
3008 fmt
[0] = '\0'; /* assume null format string */
3009 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
3011 promptp
+= 2; /* skip past two escape chars. */
3015 /* extract format string from between two esc chars */
3018 fmt
[i
++] = *promptp
++; /* copy format string */
3019 } while (i
< sizeof (fmt
) - 1 &&
3020 *promptp
!= gdb_prompt_escape
&&
3023 if (*promptp
!= gdb_prompt_escape
)
3024 error ("Syntax error at prompt position %d",
3025 promptp
- local_prompt
);
3028 promptp
++; /* skip second escape char */
3029 fmt
[i
++] = '\0'; /* terminate the format string */
3033 arg_val
= parse_to_comma_and_eval (&promptp
);
3034 if (*promptp
== ',')
3035 promptp
++; /* skip past the comma */
3036 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
3037 switch (TYPE_CODE (arg_type
))
3039 case TYPE_CODE_ARRAY
:
3040 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3041 if (TYPE_LENGTH (arg_type
) > 0 &&
3042 TYPE_LENGTH (elt_type
) == 1 &&
3043 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
3045 int len
= TYPE_LENGTH (arg_type
);
3047 if (VALUE_LAZY (arg_val
))
3048 value_fetch_lazy (arg_val
);
3049 tmp
= VALUE_CONTENTS (arg_val
);
3051 if (len
> available
)
3052 len
= available
; /* overflow protect */
3054 /* FIXME: how to protect GDB from crashing
3055 from bad user-supplied format string? */
3057 sprintf (outp
, fmt
, tmp
);
3059 strncpy (outp
, tmp
, len
);
3064 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3065 addrval
= value_as_pointer (arg_val
);
3067 if (TYPE_LENGTH (elt_type
) == 1 &&
3068 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
3071 /* display it as a string */
3072 char *default_fmt
= "%s";
3076 /* Limiting the number of bytes that the following call
3077 will read protects us from sprintf overflow later. */
3078 i
= target_read_string (addrval
, /* src */
3080 available
, /* len */
3082 if (err
) /* read failed */
3083 error ("%s on target_read", safe_strerror (err
));
3085 tmp
[i
] = '\0'; /* force-terminate string */
3086 /* FIXME: how to protect GDB from crashing
3087 from bad user-supplied format string? */
3088 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3094 /* display it as a pointer */
3095 char *default_fmt
= "0x%x";
3097 /* FIXME: how to protect GDB from crashing
3098 from bad user-supplied format string? */
3099 if (available
>= 16 /*?*/) /* overflow protect */
3100 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3106 char *default_fmt
= "%g";
3108 doubleval
= value_as_double (arg_val
);
3109 /* FIXME: how to protect GDB from crashing
3110 from bad user-supplied format string? */
3111 if (available
>= 16 /*?*/) /* overflow protect */
3112 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3113 (double) doubleval
);
3118 char *default_fmt
= "%d";
3120 longval
= value_as_long (arg_val
);
3121 /* FIXME: how to protect GDB from crashing
3122 from bad user-supplied format string? */
3123 if (available
>= 16 /*?*/) /* overflow protect */
3124 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3128 case TYPE_CODE_BOOL
:
3130 /* no default format for bool */
3131 longval
= value_as_long (arg_val
);
3132 if (available
>= 8 /*?*/) /* overflow protect */
3135 strcpy (outp
, "<true>");
3137 strcpy (outp
, "<false>");
3141 case TYPE_CODE_ENUM
:
3143 /* no default format for enum */
3144 longval
= value_as_long (arg_val
);
3145 len
= TYPE_NFIELDS (arg_type
);
3146 /* find enum name if possible */
3147 for (i
= 0; i
< len
; i
++)
3148 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3149 break; /* match -- end loop */
3151 if (i
< len
) /* enum name found */
3153 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3155 strncpy (outp
, name
, available
);
3156 /* in casel available < strlen (name), */
3157 outp
[available
] = '\0';
3161 if (available
>= 16 /*?*/) /* overflow protect */
3162 sprintf (outp
, "%d", (long) longval
);
3166 case TYPE_CODE_VOID
:
3168 break; /* void type -- no output */
3170 error ("bad data type at prompt position %d",
3171 promptp
- local_prompt
);
3174 outp
+= strlen (outp
);
3177 *outp
++ = '\0'; /* terminate prompt string */
3185 static char buf
[MAX_PROMPT_SIZE
];
3187 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3190 return &buf
[0]; /* successful formatted prompt */
3194 /* Prompt could not be formatted. */
3198 return gdb_prompt_string
;
3206 /* ??rehrauer: I don't know why this fails, since it looks as though
3207 assignments to prompt are wrapped in calls to savestring...
3212 PROMPT (0) = savestring (s
, strlen (s
));
3214 gdb_prompt_string
= savestring (s
, strlen (s
));
3218 /* If necessary, make the user confirm that we should quit. Return
3219 non-zero if we should quit, zero if we shouldn't. */
3224 if (inferior_pid
!= 0 && target_has_execution
)
3228 /* This is something of a hack. But there's no reliable way to
3229 see if a GUI is running. The `use_windows' variable doesn't
3232 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3233 else if (attach_flag
)
3234 s
= "The program is running. Quit anyway (and detach it)? ";
3236 s
= "The program is running. Exit anyway? ";
3245 /* Quit without asking for confirmation. */
3248 quit_force (args
, from_tty
)
3254 /* An optional expression may be used to cause gdb to terminate with the
3255 value of that expression. */
3258 value_ptr val
= parse_and_eval (args
);
3260 exit_code
= (int) value_as_long (val
);
3263 if (inferior_pid
!= 0 && target_has_execution
)
3266 target_detach (args
, from_tty
);
3271 /* UDI wants this, to kill the TIP. */
3274 /* Save the history information if it is appropriate to do so. */
3275 if (write_history_p
&& history_filename
)
3276 write_history (history_filename
);
3278 do_final_cleanups(ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3281 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3282 /* The above does not need to be inside a tuiDo(), since
3283 * it is not manipulating the curses screen, but rather,
3284 * it is tearing it down.
3293 /* Handle the quit command. */
3296 quit_command (args
, from_tty
)
3300 if (! quit_confirm ())
3301 error ("Not confirmed.");
3302 quit_force (args
, from_tty
);
3305 /* Returns whether GDB is running on a terminal and whether the user
3306 desires that questions be asked of them on that terminal. */
3309 input_from_terminal_p ()
3311 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3316 pwd_command (args
, from_tty
)
3320 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
3321 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3323 if (!STREQ (gdb_dirbuf
, current_directory
))
3324 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3325 current_directory
, gdb_dirbuf
);
3327 printf_unfiltered ("Working directory %s.\n", current_directory
);
3331 cd_command (dir
, from_tty
)
3336 /* Found something other than leading repetitions of "/..". */
3337 int found_real_path
;
3340 /* If the new directory is absolute, repeat is a no-op; if relative,
3341 repeat might be useful but is more likely to be a mistake. */
3345 error_no_arg ("new working directory");
3347 dir
= tilde_expand (dir
);
3348 make_cleanup (free
, dir
);
3350 if (chdir (dir
) < 0)
3351 perror_with_name (dir
);
3354 dir
= savestring (dir
, len
- (len
> 1 && SLASH_P(dir
[len
-1])));
3356 current_directory
= dir
;
3359 if (SLASH_P (current_directory
[0]) && current_directory
[1] == '\0')
3360 current_directory
= concat (current_directory
, dir
, NULL
);
3362 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3366 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3368 found_real_path
= 0;
3369 for (p
= current_directory
; *p
;)
3371 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3373 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3374 && (p
[3] == 0 || SLASH_P (p
[3])))
3376 if (found_real_path
)
3378 /* Search backwards for the directory just before the "/.."
3379 and obliterate it and the "/..". */
3381 while (q
!= current_directory
&& ! SLASH_P (q
[-1]))
3384 if (q
== current_directory
)
3385 /* current_directory is
3386 a relative pathname ("can't happen"--leave it alone). */
3390 strcpy (q
- 1, p
+ 3);
3395 /* We are dealing with leading repetitions of "/..", for example
3396 "/../..", which is the Mach super-root. */
3401 found_real_path
= 1;
3406 forget_cached_source_info ();
3409 pwd_command ((char *) 0, 1);
3412 struct source_cleanup_lines_args
{
3415 char *old_pre_error
;
3416 char *old_error_pre_print
;
3420 source_cleanup_lines (args
)
3423 struct source_cleanup_lines_args
*p
=
3424 (struct source_cleanup_lines_args
*)args
;
3425 source_line_number
= p
->old_line
;
3426 source_file_name
= p
->old_file
;
3427 source_pre_error
= p
->old_pre_error
;
3428 error_pre_print
= p
->old_error_pre_print
;
3433 source_command (args
, from_tty
)
3438 struct cleanup
*old_cleanups
;
3440 struct source_cleanup_lines_args old_lines
;
3445 error ("source command requires pathname of file to source.");
3448 file
= tilde_expand (file
);
3449 old_cleanups
= make_cleanup (free
, file
);
3451 stream
= fopen (file
, FOPEN_RT
);
3455 perror_with_name (file
);
3460 make_cleanup ((make_cleanup_func
) fclose
, stream
);
3462 old_lines
.old_line
= source_line_number
;
3463 old_lines
.old_file
= source_file_name
;
3464 old_lines
.old_pre_error
= source_pre_error
;
3465 old_lines
.old_error_pre_print
= error_pre_print
;
3466 make_cleanup (source_cleanup_lines
, &old_lines
);
3467 source_line_number
= 0;
3468 source_file_name
= file
;
3469 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3470 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3471 make_cleanup (free
, source_pre_error
);
3472 /* This will get set every time we read a line. So it won't stay "" for
3474 error_pre_print
= "";
3476 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3477 if (source_error_allocated
< needed_length
)
3479 source_error_allocated
*= 2;
3480 if (source_error_allocated
< needed_length
)
3481 source_error_allocated
= needed_length
;
3482 if (source_error
== NULL
)
3483 source_error
= xmalloc (source_error_allocated
);
3485 source_error
= xrealloc (source_error
, source_error_allocated
);
3488 read_command_file (stream
);
3490 do_cleanups (old_cleanups
);
3495 echo_command (text
, from_tty
)
3503 while ((c
= *p
++) != '\0')
3507 /* \ at end of argument is used after spaces
3508 so they won't be lost. */
3512 c
= parse_escape (&p
);
3514 printf_filtered ("%c", c
);
3517 printf_filtered ("%c", c
);
3520 /* Force this output to appear now. */
3522 gdb_flush (gdb_stdout
);
3527 dont_repeat_command (ignored
, from_tty
)
3531 *line
= 0; /* Can't call dont_repeat here because we're not
3532 necessarily reading from stdin. */
3535 /* Functions to manipulate command line editing control variables. */
3537 /* Number of commands to print in each call to show_commands. */
3538 #define Hist_print 10
3540 show_commands (args
, from_tty
)
3544 /* Index for history commands. Relative to history_base. */
3547 /* Number of the history entry which we are planning to display next.
3548 Relative to history_base. */
3551 /* The first command in the history which doesn't exist (i.e. one more
3552 than the number of the last command). Relative to history_base. */
3555 extern HIST_ENTRY
*history_get
PARAMS ((int));
3557 /* Print out some of the commands from the command history. */
3558 /* First determine the length of the history list. */
3559 hist_len
= history_size
;
3560 for (offset
= 0; offset
< history_size
; offset
++)
3562 if (!history_get (history_base
+ offset
))
3571 if (args
[0] == '+' && args
[1] == '\0')
3572 /* "info editing +" should print from the stored position. */
3575 /* "info editing <exp>" should print around command number <exp>. */
3576 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
3578 /* "show commands" means print the last Hist_print commands. */
3581 num
= hist_len
- Hist_print
;
3587 /* If there are at least Hist_print commands, we want to display the last
3588 Hist_print rather than, say, the last 6. */
3589 if (hist_len
- num
< Hist_print
)
3591 num
= hist_len
- Hist_print
;
3596 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3598 printf_filtered ("%5d %s\n", history_base
+ offset
,
3599 (history_get (history_base
+ offset
))->line
);
3602 /* The next command we want to display is the next one that we haven't
3606 /* If the user repeats this command with return, it should do what
3607 "show commands +" does. This is unnecessary if arg is null,
3608 because "show commands +" is not useful after "show commands". */
3609 if (from_tty
&& args
)
3616 /* Called by do_setshow_command. */
3619 set_history_size_command (args
, from_tty
, c
)
3622 struct cmd_list_element
*c
;
3624 if (history_size
== INT_MAX
)
3625 unstifle_history ();
3626 else if (history_size
>= 0)
3627 stifle_history (history_size
);
3630 history_size
= INT_MAX
;
3631 error ("History size must be non-negative");
3637 set_history (args
, from_tty
)
3641 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3642 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3647 show_history (args
, from_tty
)
3651 cmd_show_list (showhistlist
, from_tty
, "");
3654 int info_verbose
= 0; /* Default verbose msgs off */
3656 /* Called by do_setshow_command. An elaborate joke. */
3659 set_verbose (args
, from_tty
, c
)
3662 struct cmd_list_element
*c
;
3664 char *cmdname
= "verbose";
3665 struct cmd_list_element
*showcmd
;
3667 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3671 c
->doc
= "Set verbose printing of informational messages.";
3672 showcmd
->doc
= "Show verbose printing of informational messages.";
3676 c
->doc
= "Set verbosity.";
3677 showcmd
->doc
= "Show verbosity.";
3682 float_handler (signo
)
3685 /* This message is based on ANSI C, section 4.7. Note that integer
3686 divide by zero causes this, so "float" is a misnomer. */
3687 signal (SIGFPE
, float_handler
);
3688 error ("Erroneous arithmetic operation.");
3702 enablebreaklist
= NULL
;
3707 showhistlist
= NULL
;
3708 unsethistlist
= NULL
;
3709 maintenancelist
= NULL
;
3710 maintenanceinfolist
= NULL
;
3711 maintenanceprintlist
= NULL
;
3712 setprintlist
= NULL
;
3713 showprintlist
= NULL
;
3714 setchecklist
= NULL
;
3715 showchecklist
= NULL
;
3718 /* Init the history buffer. Note that we are called after the init file(s)
3719 * have been read so that the user can change the history file via his
3720 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3721 * overrides all of this.
3729 tmpenv
= getenv ("HISTSIZE");
3731 history_size
= atoi (tmpenv
);
3732 else if (!history_size
)
3735 stifle_history (history_size
);
3737 tmpenv
= getenv ("GDBHISTFILE");
3739 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
3740 else if (!history_filename
) {
3741 /* We include the current directory so that if the user changes
3742 directories the file written will be the same as the one
3744 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3746 read_history (history_filename
);
3752 struct cmd_list_element
*c
;
3754 /* If we are running the asynchronous version,
3755 we initialize the prompts differently. */
3758 #ifdef DEFAULT_PROMPT
3759 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
3761 gdb_prompt_string
= savestring ("(gdb) ", 6);
3766 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3767 whatever the DEFULAT_PROMPT is. */
3768 the_prompts
.top
= 0;
3770 #ifdef DEFAULT_PROMPT
3771 PROMPT(0) = savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
3773 PROMPT(0) = savestring ("(gdb) ", 6);
3776 /* Set things up for annotation_level > 1, if the user ever decides
3778 async_annotation_suffix
= "prompt";
3779 /* Set the variable associated with the setshow prompt command. */
3780 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
3782 gdb_prompt_escape
= 0; /* default to none. */
3784 /* Set the important stuff up for command editing. */
3785 command_editing_p
= 1;
3786 history_expansion_p
= 0;
3787 write_history_p
= 0;
3789 /* Setup important stuff for command line editing. */
3790 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3791 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3792 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3793 rl_readline_name
= "gdb";
3795 /* Define the classes of commands.
3796 They will appear in the help list in the reverse of this order. */
3798 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3799 "Maintenance commands.\n\
3800 Some gdb commands are provided just for use by gdb maintainers.\n\
3801 These commands are subject to frequent change, and may not be as\n\
3802 well documented as user commands.",
3804 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3805 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3806 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3807 The commands in this class are those defined by the user.\n\
3808 Use the \"define\" command to define a command.", &cmdlist
);
3809 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3811 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3812 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3813 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3814 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3815 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3816 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3817 counting from zero for the innermost (currently executing) frame.\n\n\
3818 At any time gdb identifies one frame as the \"selected\" frame.\n\
3819 Variable lookups are done with respect to the selected frame.\n\
3820 When the program being debugged stops, gdb selects the innermost frame.\n\
3821 The commands below can be used to select other frames by number or address.",
3823 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3825 add_com ("pwd", class_files
, pwd_command
,
3826 "Print working directory. This is used for your program as well.");
3827 c
= add_cmd ("cd", class_files
, cd_command
,
3828 "Set working directory to DIR for debugger and program being debugged.\n\
3829 The change does not take effect for the program being debugged\n\
3830 until the next time it is started.", &cmdlist
);
3831 c
->completer
= filename_completer
;
3833 /* The set prompt command is different depending whether or not the
3834 async version is run. NOTE: this difference is going to
3835 disappear as we make the event loop be the default engine of
3840 (add_set_cmd ("prompt", class_support
, var_string
,
3841 (char *) &gdb_prompt_string
, "Set gdb's prompt",
3847 c
= add_set_cmd ("prompt", class_support
, var_string
,
3848 (char *)&new_async_prompt
, "Set gdb's prompt",
3850 add_show_from_set (c
, &showlist
);
3851 c
->function
.sfunc
= set_async_prompt
;
3855 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
3856 (char *) &gdb_prompt_escape
,
3857 "Set escape character for formatting of gdb's prompt",
3861 add_com ("echo", class_support
, echo_command
,
3862 "Print a constant string. Give string as argument.\n\
3863 C escape sequences may be used in the argument.\n\
3864 No newline is added at the end of the argument;\n\
3865 use \"\\n\" if you want a newline to be printed.\n\
3866 Since leading and trailing whitespace are ignored in command arguments,\n\
3867 if you want to print some you must use \"\\\" before leading whitespace\n\
3868 to be printed or after trailing whitespace.");
3869 add_com ("document", class_support
, document_command
,
3870 "Document a user-defined command.\n\
3871 Give command name as argument. Give documentation on following lines.\n\
3872 End with a line of just \"end\".");
3873 add_com ("define", class_support
, define_command
,
3874 "Define a new command name. Command name is argument.\n\
3875 Definition appears on following lines, one command per line.\n\
3876 End with a line of just \"end\".\n\
3877 Use the \"document\" command to give documentation for the new command.\n\
3878 Commands defined in this way may have up to ten arguments.");
3881 c
= add_cmd ("source", class_support
, source_command
,
3882 "Read commands from a file named FILE.\n\
3883 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3884 when gdb is started.", &cmdlist
);
3886 /* Punt file name, we can't help it easily. */
3887 c
= add_cmd ("source", class_support
, source_command
,
3888 "Read commands from a file named FILE.\n\
3889 Note that the file \".gdbinit\" is read automatically in this way\n\
3890 when gdb is started.", &cmdlist
);
3892 c
->completer
= filename_completer
;
3894 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3895 add_com ("help", class_support
, help_command
, "Print list of commands.");
3896 add_com_alias ("q", "quit", class_support
, 1);
3897 add_com_alias ("h", "help", class_support
, 1);
3899 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
3900 Primarily used inside of user-defined commands that should not be repeated when\n\
3903 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
3906 add_show_from_set (c
, &showlist
);
3907 c
->function
.sfunc
= set_verbose
;
3908 set_verbose (NULL
, 0, c
);
3910 /* The set editing command is different depending whether or not the
3911 async version is run. NOTE: this difference is going to disappear
3912 as we make the event loop be the default engine of gdb. */
3916 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
3917 "Set editing of command lines as they are typed.\n\
3918 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3919 Without an argument, command line editing is enabled. To edit, use\n\
3920 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
3925 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *)&async_command_editing_p
,
3926 "Set editing of command lines as they are typed.\n\
3927 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3928 Without an argument, command line editing is enabled. To edit, use\n\
3929 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
3931 add_show_from_set (c
, &showlist
);
3932 c
->function
.sfunc
= set_async_editing_command
;
3935 add_prefix_cmd ("history", class_support
, set_history
,
3936 "Generic command for setting command history parameters.",
3937 &sethistlist
, "set history ", 0, &setlist
);
3938 add_prefix_cmd ("history", class_support
, show_history
,
3939 "Generic command for showing command history parameters.",
3940 &showhistlist
, "show history ", 0, &showlist
);
3943 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
3944 "Set history expansion on command input.\n\
3945 Without an argument, history expansion is enabled.", &sethistlist
),
3949 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
3950 "Set saving of the history record on exit.\n\
3951 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
3952 Without an argument, saving is enabled.", &sethistlist
),
3955 c
= add_set_cmd ("size", no_class
, var_integer
, (char *)&history_size
,
3956 "Set the size of the command history, \n\
3957 ie. the number of previous commands to keep a record of.", &sethistlist
);
3958 add_show_from_set (c
, &showhistlist
);
3959 c
->function
.sfunc
= set_history_size_command
;
3962 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
3963 "Set the filename in which to record the command history\n\
3964 (the list of previous commands of which a record is kept).", &sethistlist
),
3968 (add_set_cmd ("confirm", class_support
, var_boolean
,
3970 "Set whether to confirm potentially dangerous operations.",
3974 add_prefix_cmd ("info", class_info
, info_command
,
3975 "Generic command for showing things about the program being debugged.",
3976 &infolist
, "info ", 0, &cmdlist
);
3977 add_com_alias ("i", "info", class_info
, 1);
3979 add_com ("complete", class_obscure
, complete_command
,
3980 "List the completions for the rest of the line as a command.");
3982 add_prefix_cmd ("show", class_info
, show_command
,
3983 "Generic command for showing things about the debugger.",
3984 &showlist
, "show ", 0, &cmdlist
);
3985 /* Another way to get at the same thing. */
3986 add_info ("set", show_command
, "Show all GDB settings.");
3988 add_cmd ("commands", no_class
, show_commands
,
3989 "Show the history of commands you typed.\n\
3990 You can supply a command number to start with, or a `+' to start after\n\
3991 the previous command number shown.",
3994 add_cmd ("version", no_class
, show_version
,
3995 "Show what version of GDB this is.", &showlist
);
3997 add_com ("while", class_support
, while_command
,
3998 "Execute nested commands WHILE the conditional expression is non zero.\n\
3999 The conditional expression must follow the word `while' and must in turn be\n\
4000 followed by a new line. The nested commands must be entered one per line,\n\
4001 and should be terminated by the word `end'.");
4003 add_com ("if", class_support
, if_command
,
4004 "Execute nested commands once IF the conditional expression is non zero.\n\
4005 The conditional expression must follow the word `if' and must in turn be\n\
4006 followed by a new line. The nested commands must be entered one per line,\n\
4007 and should be terminated by the word 'else' or `end'. If an else clause\n\
4008 is used, the same rules apply to its nested commands as to the first ones.");
4010 /* If target is open when baud changes, it doesn't take effect until the
4011 next open (I think, not sure). */
4012 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
4013 var_zinteger
, (char *)&baud_rate
,
4014 "Set baud rate for remote serial I/O.\n\
4015 This value is used to set the speed of the serial port when debugging\n\
4016 using remote targets.", &setlist
),
4020 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *)&remote_debug
,
4021 "Set debugging of remote protocol.\n\
4022 When enabled, each packet sent or received with the remote target\n\
4023 is displayed.", &setlist
),
4027 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *)&remote_timeout
,
4028 "Set timeout limit to wait for target to respond.\n\
4029 This value is used to set the time limit for gdb to wait for a response\n\
4030 from the target.", &setlist
),
4033 /* The set annotate command is different depending whether or not
4034 the async version is run. NOTE: this difference is going to
4035 disappear as we make the event loop be the default engine of
4039 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4040 (char *)&annotation_level
, "Set annotation_level.\n\
4041 0 == normal; 1 == fullname (for use when running under emacs)\n\
4042 2 == output annotated suitably for use by programs that control GDB.",
4044 c
= add_show_from_set (c
, &showlist
);
4048 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4049 (char *)&annotation_level
, "Set annotation_level.\n\
4050 0 == normal; 1 == fullname (for use when running under emacs)\n\
4051 2 == output annotated suitably for use by programs that control GDB.",
4053 add_show_from_set (c
, &showlist
);
4054 c
->function
.sfunc
= set_async_annotation_level
;