1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "call-cmds.h"
29 #include "breakpoint.h"
31 #include "expression.h"
34 #include "terminal.h" /* For job_control. */
38 /* readline include files */
39 #include <readline/readline.h>
40 #include <readline/history.h>
42 /* readline defines this. */
45 #include <sys/types.h>
50 #include "event-loop.h"
51 #include "gdb_string.h"
55 /* Prototypes for local functions */
57 static void dont_repeat_command
PARAMS ((char *, int));
59 static void source_cleanup_lines
PARAMS ((PTR
));
61 static void user_defined_command
PARAMS ((char *, int));
63 static void init_signals
PARAMS ((void));
66 static void stop_sig
PARAMS ((int));
69 static char *line_completion_function
PARAMS ((char *, int, char *, int));
71 static char *readline_line_completion_function
PARAMS ((char *, int));
73 /* NOTE 1999-04-29: this function will be static again, after we make the
74 event loop be the default command loop for gdb, and we merge
75 event-top.c into this file, top.c */
76 /* static */ void command_loop_marker
PARAMS ((int));
78 static void while_command
PARAMS ((char *, int));
80 static void if_command
PARAMS ((char *, int));
82 static struct command_line
*
83 build_command_line
PARAMS ((enum command_control_type
, char *));
85 static struct command_line
*
86 get_command_line
PARAMS ((enum command_control_type
, char *));
88 static void realloc_body_list
PARAMS ((struct command_line
*, int));
90 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
92 static enum command_control_type
93 recurse_read_control_structure
PARAMS ((struct command_line
*));
95 static struct cleanup
*setup_user_args
PARAMS ((char *));
97 static char *locate_arg
PARAMS ((char *));
99 static char *insert_args
PARAMS ((char *));
101 static void arg_cleanup
PARAMS ((void));
103 static void init_main
PARAMS ((void));
105 static void init_cmd_lists
PARAMS ((void));
107 static void float_handler
PARAMS ((int));
109 static void init_signals
PARAMS ((void));
111 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
113 static void show_history
PARAMS ((char *, int));
115 static void set_history
PARAMS ((char *, int));
117 static void set_history_size_command
PARAMS ((char *, int,
118 struct cmd_list_element
*));
120 static void show_commands
PARAMS ((char *, int));
122 static void echo_command
PARAMS ((char *, int));
124 static void pwd_command
PARAMS ((char *, int));
126 static void show_version
PARAMS ((char *, int));
128 static void document_command
PARAMS ((char *, int));
130 static void define_command
PARAMS ((char *, int));
132 static void validate_comname
PARAMS ((char *));
134 static void help_command
PARAMS ((char *, int));
136 static void show_command
PARAMS ((char *, int));
138 static void info_command
PARAMS ((char *, int));
140 static void complete_command
PARAMS ((char *, int));
142 static void do_nothing
PARAMS ((int));
145 /* NOTE 1999-04-29: This function will be static again, once we modify
146 gdb to use the event loop as the default command loop and we merge
147 event-top.c into this file, top.c */
148 /* static */ int quit_cover
PARAMS ((PTR
));
150 static void disconnect
PARAMS ((int));
153 static void source_cleanup
PARAMS ((FILE *));
155 /* If this definition isn't overridden by the header files, assume
156 that isatty and fileno exist on this system. */
158 #define ISATTY(FP) (isatty (fileno (FP)))
161 /* Initialization file name for gdb. This is overridden in some configs. */
163 #ifndef GDBINIT_FILENAME
164 #define GDBINIT_FILENAME ".gdbinit"
166 char gdbinit
[] = GDBINIT_FILENAME
;
168 int inhibit_gdbinit
= 0;
170 /* If nonzero, and GDB has been configured to be able to use windows,
171 attempt to open them upon startup. */
175 /* Version number of GDB, as a string. */
177 extern char *version
;
179 /* Canonical host name as a string. */
181 extern char *host_name
;
183 /* Canonical target name as a string. */
185 extern char *target_name
;
187 extern char lang_frame_mismatch_warn
[]; /* language.c */
189 /* Flag for whether we want all the "from_tty" gubbish printed. */
191 int caution
= 1; /* Default is yes, sigh. */
193 /* Define all cmd_list_elements. */
195 /* Chain containing all defined commands. */
197 struct cmd_list_element
*cmdlist
;
199 /* Chain containing all defined info subcommands. */
201 struct cmd_list_element
*infolist
;
203 /* Chain containing all defined enable subcommands. */
205 struct cmd_list_element
*enablelist
;
207 /* Chain containing all defined disable subcommands. */
209 struct cmd_list_element
*disablelist
;
211 /* Chain containing all defined toggle subcommands. */
213 struct cmd_list_element
*togglelist
;
215 /* Chain containing all defined stop subcommands. */
217 struct cmd_list_element
*stoplist
;
219 /* Chain containing all defined delete subcommands. */
221 struct cmd_list_element
*deletelist
;
223 /* Chain containing all defined "enable breakpoint" subcommands. */
225 struct cmd_list_element
*enablebreaklist
;
227 /* Chain containing all defined set subcommands */
229 struct cmd_list_element
*setlist
;
231 /* Chain containing all defined unset subcommands */
233 struct cmd_list_element
*unsetlist
;
235 /* Chain containing all defined show subcommands. */
237 struct cmd_list_element
*showlist
;
239 /* Chain containing all defined \"set history\". */
241 struct cmd_list_element
*sethistlist
;
243 /* Chain containing all defined \"show history\". */
245 struct cmd_list_element
*showhistlist
;
247 /* Chain containing all defined \"unset history\". */
249 struct cmd_list_element
*unsethistlist
;
251 /* Chain containing all defined maintenance subcommands. */
253 struct cmd_list_element
*maintenancelist
;
255 /* Chain containing all defined "maintenance info" subcommands. */
257 struct cmd_list_element
*maintenanceinfolist
;
259 /* Chain containing all defined "maintenance print" subcommands. */
261 struct cmd_list_element
*maintenanceprintlist
;
263 struct cmd_list_element
*setprintlist
;
265 struct cmd_list_element
*showprintlist
;
267 struct cmd_list_element
*setchecklist
;
269 struct cmd_list_element
*showchecklist
;
271 /* stdio stream that command input is being read from. Set to stdin normally.
272 Set by source_command to the file we are sourcing. Set to NULL if we are
273 executing a user-defined command or interacting via a GUI. */
277 /* Current working directory. */
279 char *current_directory
;
281 /* The directory name is actually stored here (usually). */
282 char gdb_dirbuf
[1024];
284 /* Function to call before reading a command, if nonzero.
285 The function receives two args: an input stream,
286 and a prompt string. */
288 void (*window_hook
) PARAMS ((FILE *, char *));
293 /* gdb prints this when reading a command interactively */
294 static char *gdb_prompt_string
; /* the global prompt string */
295 extern char *get_prompt
PARAMS ((void)); /* access function for prompt string */
297 /* Buffer used for reading command lines, and the size
298 allocated for it so far. */
303 /* Nonzero if the current command is modified by "server ". This
304 affects things like recording into the command history, comamnds
305 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
306 whatever) can issue its own commands and also send along commands
307 from the user, and have the user not notice that the user interface
308 is issuing commands too. */
311 /* Baud rate specified for talking to serial target systems. Default
312 is left as -1, so targets can choose their own defaults. */
313 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
314 or (unsigned int)-1. This is a Bad User Interface. */
318 /* Timeout limit for response from target. */
320 int remote_timeout
= 20; /* Set default to 20 */
322 /* Non-zero tells remote* modules to output debugging info. */
324 int remote_debug
= 0;
326 /* Non-zero means the target is running. Note: this is different from
327 saying that there is an active target and we are stopped at a
328 breakpoint, for instance. This is a real indicator whether the
329 target is off and running, which gdb is doing something else. */
330 int target_executing
= 0;
332 /* Level of control structure. */
333 static int control_level
;
335 /* Structure for arguments to user defined functions. */
336 #define MAXUSERARGS 10
339 struct user_args
*next
;
350 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
354 #define STOP_SIGNAL SIGTSTP
355 static void stop_sig
PARAMS ((int));
359 /* Some System V have job control but not sigsetmask(). */
360 #if !defined (HAVE_SIGSETMASK)
362 #define HAVE_SIGSETMASK 1
364 #define HAVE_SIGSETMASK 0
368 #if 0 == (HAVE_SIGSETMASK)
369 #define sigsetmask(n)
372 /* Hooks for alternate command interfaces. */
374 /* Called after most modules have been initialized, but before taking users
377 void (*init_ui_hook
) PARAMS ((char *argv0
));
379 /* This hook is called from within gdb's many mini-event loops which could
380 steal control from a real user interface's event loop. It returns
381 non-zero if the user is requesting a detach, zero otherwise. */
383 int (*ui_loop_hook
) PARAMS ((int));
385 /* Called instead of command_loop at top level. Can be invoked via
386 return_to_top_level. */
388 void (*command_loop_hook
) PARAMS ((void));
391 /* Called instead of fputs for all output. */
393 void (*fputs_unfiltered_hook
) PARAMS ((const char *linebuffer
, GDB_FILE
* stream
));
395 /* Called from print_frame_info to list the line we stopped in. */
397 void (*print_frame_info_listing_hook
) PARAMS ((struct symtab
* s
, int line
,
398 int stopline
, int noerror
));
399 /* Replaces most of query. */
401 int (*query_hook
) PARAMS ((const char *, va_list));
403 /* Replaces most of warning. */
405 void (*warning_hook
) PARAMS ((const char *, va_list));
407 /* Called from gdb_flush to flush output. */
409 void (*flush_hook
) PARAMS ((GDB_FILE
* stream
));
411 /* These three functions support getting lines of text from the user. They
412 are used in sequence. First readline_begin_hook is called with a text
413 string that might be (for example) a message for the user to type in a
414 sequence of commands to be executed at a breakpoint. If this function
415 calls back to a GUI, it might take this opportunity to pop up a text
416 interaction window with this message. Next, readline_hook is called
417 with a prompt that is emitted prior to collecting the user input.
418 It can be called multiple times. Finally, readline_end_hook is called
419 to notify the GUI that we are done with the interaction window and it
422 void (*readline_begin_hook
) PARAMS ((char *,...));
423 char *(*readline_hook
) PARAMS ((char *));
424 void (*readline_end_hook
) PARAMS ((void));
426 /* Called as appropriate to notify the interface of the specified breakpoint
429 void (*create_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
430 void (*delete_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
431 void (*modify_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
433 /* Called during long calculations to allow GUI to repair window damage, and to
434 check for stop buttons, etc... */
436 void (*interactive_hook
) PARAMS ((void));
438 /* Called when the registers have changed, as a hint to a GUI
439 to minimize window update. */
441 void (*registers_changed_hook
) PARAMS ((void));
443 /* Tell the GUI someone changed the register REGNO. -1 means
444 that the caller does not know which register changed or
445 that several registers have changed (see value_assign). */
446 void (*register_changed_hook
) PARAMS ((int regno
));
448 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
449 void (*memory_changed_hook
) PARAMS ((CORE_ADDR addr
, int len
));
451 /* Called when going to wait for the target. Usually allows the GUI to run
452 while waiting for target events. */
454 int (*target_wait_hook
) PARAMS ((int pid
, struct target_waitstatus
* status
));
456 /* Used by UI as a wrapper around command execution. May do various things
457 like enabling/disabling buttons, etc... */
459 void (*call_command_hook
) PARAMS ((struct cmd_list_element
* c
, char *cmd
,
462 /* Called after a `set' command has finished. Is only run if the
463 `set' command succeeded. */
465 void (*set_hook
) PARAMS ((struct cmd_list_element
*c
));
467 /* Called when the current thread changes. Argument is thread id. */
469 void (*context_hook
) PARAMS ((int id
));
471 /* Takes control from error (). Typically used to prevent longjmps out of the
472 middle of the GUI. Usually used in conjunction with a catch routine. */
474 NORETURN
void (*error_hook
)
475 PARAMS ((void)) ATTR_NORETURN
;
478 /* Where to go for return_to_top_level (RETURN_ERROR). */
479 SIGJMP_BUF error_return
;
480 /* Where to go for return_to_top_level (RETURN_QUIT). */
481 SIGJMP_BUF quit_return
;
483 /* Return for reason REASON. This generally gets back to the command
484 loop, but can be caught via catch_errors. */
487 return_to_top_level (reason
)
488 enum return_reason reason
;
493 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
494 I can think of a reason why that is vital, though). */
495 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
497 disable_current_display ();
498 do_cleanups (ALL_CLEANUPS
);
499 if (async_p
&& target_has_async
)
500 do_exec_cleanups (ALL_CLEANUPS
);
502 if (annotation_level
> 1)
513 (NORETURN
void) SIGLONGJMP
514 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
517 /* Call FUNC with arg ARGS, catching any errors. If there is no
518 error, return the value returned by FUNC. If there is an error,
519 print ERRSTRING, print the specific error message, then return
522 Must not be called with immediate_quit in effect (bad things might
523 happen, say we got a signal in the middle of a memcpy to quit_return).
524 This is an OK restriction; with very few exceptions immediate_quit can
525 be replaced by judicious use of QUIT.
527 MASK specifies what to catch; it is normally set to
528 RETURN_MASK_ALL, if for no other reason than that the code which
529 calls catch_errors might not be set up to deal with a quit which
530 isn't caught. But if the code can deal with it, it generally
531 should be RETURN_MASK_ERROR, unless for some reason it is more
532 useful to abort only the portion of the operation inside the
533 catch_errors. Note that quit should return to the command line
534 fairly quickly, even if some further processing is being done. */
537 catch_errors (func
, args
, errstring
, mask
)
538 catch_errors_ftype
*func
;
543 SIGJMP_BUF saved_error
;
544 SIGJMP_BUF saved_quit
;
547 struct cleanup
*saved_cleanup_chain
;
548 char *saved_error_pre_print
;
549 char *saved_quit_pre_print
;
551 saved_cleanup_chain
= save_cleanups ();
552 saved_error_pre_print
= error_pre_print
;
553 saved_quit_pre_print
= quit_pre_print
;
555 if (mask
& RETURN_MASK_ERROR
)
557 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (SIGJMP_BUF
));
558 error_pre_print
= errstring
;
560 if (mask
& RETURN_MASK_QUIT
)
562 memcpy (saved_quit
, quit_return
, sizeof (SIGJMP_BUF
));
563 quit_pre_print
= errstring
;
566 if (SIGSETJMP (tmp_jmp
) == 0)
568 if (mask
& RETURN_MASK_ERROR
)
569 memcpy (error_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
570 if (mask
& RETURN_MASK_QUIT
)
571 memcpy (quit_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
572 val
= (*func
) (args
);
577 restore_cleanups (saved_cleanup_chain
);
579 if (mask
& RETURN_MASK_ERROR
)
581 memcpy (error_return
, saved_error
, sizeof (SIGJMP_BUF
));
582 error_pre_print
= saved_error_pre_print
;
584 if (mask
& RETURN_MASK_QUIT
)
586 memcpy (quit_return
, saved_quit
, sizeof (SIGJMP_BUF
));
587 quit_pre_print
= saved_quit_pre_print
;
592 /* Handler for SIGHUP. */
599 catch_errors (quit_cover
, NULL
,
600 "Could not kill the program being debugged", RETURN_MASK_ALL
);
601 signal (SIGHUP
, SIG_DFL
);
602 kill (getpid (), SIGHUP
);
605 /* Just a little helper function for disconnect(). */
607 /* NOTE 1999-04-29: This function will be static again, once we modify
608 gdb to use the event loop as the default command loop and we merge
609 event-top.c into this file, top.c */
614 caution
= 0; /* Throw caution to the wind -- we're exiting.
615 This prevents asking the user dumb questions. */
616 quit_command ((char *) 0, 0);
619 #endif /* defined SIGHUP */
621 /* Line number we are currently in in a file which is being sourced. */
622 /* NOTE 1999-04-29: This variable will be static again, once we modify
623 gdb to use the event loop as the default command loop and we merge
624 event-top.c into this file, top.c */
625 /* static */ int source_line_number
;
627 /* Name of the file we are sourcing. */
628 /* NOTE 1999-04-29: This variable will be static again, once we modify
629 gdb to use the event loop as the default command loop and we merge
630 event-top.c into this file, top.c */
631 /* static */ char *source_file_name
;
633 /* Buffer containing the error_pre_print used by the source stuff.
635 /* NOTE 1999-04-29: This variable will be static again, once we modify
636 gdb to use the event loop as the default command loop and we merge
637 event-top.c into this file, top.c */
638 /* static */ char *source_error
;
639 static int source_error_allocated
;
641 /* Something to glom on to the start of error_pre_print if source_file_name
643 /* NOTE 1999-04-29: This variable will be static again, once we modify
644 gdb to use the event loop as the default command loop and we merge
645 event-top.c into this file, top.c */
646 /* static */ char *source_pre_error
;
648 /* Clean up on error during a "source" command (or execution of a
649 user-defined command). */
652 source_cleanup (stream
)
655 /* Restore the previous input stream. */
659 /* Read commands from STREAM. */
661 read_command_file (stream
)
664 struct cleanup
*cleanups
;
666 cleanups
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
669 do_cleanups (cleanups
);
672 extern void init_proc
PARAMS ((void));
674 void (*pre_init_ui_hook
) PARAMS ((void));
680 if (pre_init_ui_hook
)
683 /* Run the init function of each source file */
685 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
686 current_directory
= gdb_dirbuf
;
689 /* Make sure we return to the original directory upon exit, come
690 what may, since the OS doesn't do that for us. */
691 make_final_cleanup ((make_cleanup_func
) chdir
, strsave (current_directory
));
694 init_cmd_lists (); /* This needs to be done first */
695 initialize_targets (); /* Setup target_terminal macros for utils.c */
696 initialize_utils (); /* Make errors and warnings possible */
697 initialize_all_files ();
698 init_main (); /* But that omits this file! Do it now */
700 /* The signal handling mechanism is different depending whether or
701 not the async version is run. NOTE: in the future we plan to make
702 the event loop be the default engine of gdb, and this difference
705 async_init_signals ();
709 /* We need a default language for parsing expressions, so simple things like
710 "set width 0" won't fail if no language is explicitly set in a config file
711 or implicitly set by reading an executable during startup. */
712 set_language (language_c
);
713 expected_language
= current_language
; /* don't warn about the change. */
715 /* All the interpreters should have had a look at things by now.
716 Initialize the selected interpreter. */
718 init_ui_hook (argv0
);
721 /* Allocate, initialize a new command line structure for one of the
722 control commands (if/while). */
724 static struct command_line
*
725 build_command_line (type
, args
)
726 enum command_control_type type
;
729 struct command_line
*cmd
;
732 error ("if/while commands require arguments.\n");
734 cmd
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
736 cmd
->control_type
= type
;
740 = (struct command_line
**) xmalloc (sizeof (struct command_line
*)
742 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
743 cmd
->line
= savestring (args
, strlen (args
));
747 /* Build and return a new command structure for the control commands
748 such as "if" and "while". */
750 static struct command_line
*
751 get_command_line (type
, arg
)
752 enum command_control_type type
;
755 struct command_line
*cmd
;
756 struct cleanup
*old_chain
= NULL
;
758 /* Allocate and build a new command line structure. */
759 cmd
= build_command_line (type
, arg
);
761 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
, &cmd
);
763 /* Read in the body of this command. */
764 if (recurse_read_control_structure (cmd
) == invalid_control
)
766 warning ("error reading in control structure\n");
767 do_cleanups (old_chain
);
771 discard_cleanups (old_chain
);
775 /* Recursively print a command (including full control structures). */
777 print_command_line (cmd
, depth
, stream
)
778 struct command_line
*cmd
;
786 for (i
= 0; i
< depth
; i
++)
787 fputs_filtered (" ", stream
);
790 /* A simple command, print it and return. */
791 if (cmd
->control_type
== simple_control
)
793 fputs_filtered (cmd
->line
, stream
);
794 fputs_filtered ("\n", stream
);
798 /* loop_continue to jump to the start of a while loop, print it
800 if (cmd
->control_type
== continue_control
)
802 fputs_filtered ("loop_continue\n", stream
);
806 /* loop_break to break out of a while loop, print it and return. */
807 if (cmd
->control_type
== break_control
)
809 fputs_filtered ("loop_break\n", stream
);
813 /* A while command. Recursively print its subcommands before returning. */
814 if (cmd
->control_type
== while_control
)
816 struct command_line
*list
;
817 fputs_filtered ("while ", stream
);
818 fputs_filtered (cmd
->line
, stream
);
819 fputs_filtered ("\n", stream
);
820 list
= *cmd
->body_list
;
823 print_command_line (list
, depth
+ 1, stream
);
828 /* An if command. Recursively print both arms before returning. */
829 if (cmd
->control_type
== if_control
)
831 fputs_filtered ("if ", stream
);
832 fputs_filtered (cmd
->line
, stream
);
833 fputs_filtered ("\n", stream
);
835 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
837 /* Show the false arm if it exists. */
838 if (cmd
->body_count
== 2)
842 for (i
= 0; i
< depth
; i
++)
843 fputs_filtered (" ", stream
);
845 fputs_filtered ("else\n", stream
);
846 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
850 for (i
= 0; i
< depth
; i
++)
851 fputs_filtered (" ", stream
);
853 fputs_filtered ("end\n", stream
);
857 /* Execute the command in CMD. */
859 enum command_control_type
860 execute_control_command (cmd
)
861 struct command_line
*cmd
;
863 struct expression
*expr
;
864 struct command_line
*current
;
865 struct cleanup
*old_chain
= 0;
869 enum command_control_type ret
;
872 switch (cmd
->control_type
)
875 /* A simple command, execute it and return. */
876 new_line
= insert_args (cmd
->line
);
878 return invalid_control
;
879 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
881 execute_command (new_line
, 0);
882 ret
= cmd
->control_type
;
885 case continue_control
:
887 /* Return for "continue", and "break" so we can either
888 continue the loop at the top, or break out. */
889 ret
= cmd
->control_type
;
894 /* Parse the loop control expression for the while statement. */
895 new_line
= insert_args (cmd
->line
);
897 return invalid_control
;
898 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
900 expr
= parse_expression (new_line
);
901 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
903 ret
= simple_control
;
906 /* Keep iterating so long as the expression is true. */
913 /* Evaluate the expression. */
914 val_mark
= value_mark ();
915 val
= evaluate_expression (expr
);
916 cond_result
= value_true (val
);
917 value_free_to_mark (val_mark
);
919 /* If the value is false, then break out of the loop. */
923 /* Execute the body of the while statement. */
924 current
= *cmd
->body_list
;
927 ret
= execute_control_command (current
);
929 /* If we got an error, or a "break" command, then stop
931 if (ret
== invalid_control
|| ret
== break_control
)
937 /* If we got a "continue" command, then restart the loop
939 if (ret
== continue_control
)
942 /* Get the next statement. */
943 current
= current
->next
;
947 /* Reset RET so that we don't recurse the break all the way down. */
948 if (ret
== break_control
)
949 ret
= simple_control
;
956 new_line
= insert_args (cmd
->line
);
958 return invalid_control
;
959 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
961 /* Parse the conditional for the if statement. */
962 expr
= parse_expression (new_line
);
963 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
966 ret
= simple_control
;
968 /* Evaluate the conditional. */
969 val_mark
= value_mark ();
970 val
= evaluate_expression (expr
);
972 /* Choose which arm to take commands from based on the value of the
973 conditional expression. */
974 if (value_true (val
))
975 current
= *cmd
->body_list
;
976 else if (cmd
->body_count
== 2)
977 current
= *(cmd
->body_list
+ 1);
978 value_free_to_mark (val_mark
);
980 /* Execute commands in the given arm. */
983 ret
= execute_control_command (current
);
985 /* If we got an error, get out. */
986 if (ret
!= simple_control
)
989 /* Get the next statement in the body. */
990 current
= current
->next
;
997 warning ("Invalid control type in command structure.");
998 return invalid_control
;
1002 do_cleanups (old_chain
);
1007 /* "while" command support. Executes a body of statements while the
1008 loop condition is nonzero. */
1011 while_command (arg
, from_tty
)
1015 struct command_line
*command
= NULL
;
1018 command
= get_command_line (while_control
, arg
);
1020 if (command
== NULL
)
1023 execute_control_command (command
);
1024 free_command_lines (&command
);
1027 /* "if" command support. Execute either the true or false arm depending
1028 on the value of the if conditional. */
1031 if_command (arg
, from_tty
)
1035 struct command_line
*command
= NULL
;
1038 command
= get_command_line (if_control
, arg
);
1040 if (command
== NULL
)
1043 execute_control_command (command
);
1044 free_command_lines (&command
);
1051 struct user_args
*oargs
= user_args
;
1053 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1055 user_args
= user_args
->next
;
1059 /* Bind the incomming arguments for a user defined command to
1060 $arg0, $arg1 ... $argMAXUSERARGS. */
1062 static struct cleanup
*
1066 struct user_args
*args
;
1067 struct cleanup
*old_chain
;
1068 unsigned int arg_count
= 0;
1070 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
1071 memset (args
, 0, sizeof (struct user_args
));
1073 args
->next
= user_args
;
1076 old_chain
= make_cleanup ((make_cleanup_func
) arg_cleanup
, 0);
1088 if (arg_count
>= MAXUSERARGS
)
1090 error ("user defined function may only have %d arguments.\n",
1095 /* Strip whitespace. */
1096 while (*p
== ' ' || *p
== '\t')
1099 /* P now points to an argument. */
1101 user_args
->a
[arg_count
].arg
= p
;
1103 /* Get to the end of this argument. */
1106 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1112 else if (*p
== '\\')
1135 user_args
->a
[arg_count
].len
= p
- start_arg
;
1142 /* Given character string P, return a point to the first argument ($arg),
1143 or NULL if P contains no arguments. */
1149 while ((p
= strchr (p
, '$')))
1151 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1158 /* Insert the user defined arguments stored in user_arg into the $arg
1159 arguments found in line, with the updated copy being placed into nline. */
1165 char *p
, *save_line
, *new_line
;
1168 /* First we need to know how much memory to allocate for the new line. */
1171 while ((p
= locate_arg (line
)))
1176 if (i
>= user_args
->count
)
1178 error ("Missing argument %d in user function.\n", i
);
1181 len
+= user_args
->a
[i
].len
;
1185 /* Don't forget the tail. */
1186 len
+= strlen (line
);
1188 /* Allocate space for the new line and fill it in. */
1189 new_line
= (char *) xmalloc (len
+ 1);
1190 if (new_line
== NULL
)
1193 /* Restore pointer to beginning of old line. */
1196 /* Save pointer to beginning of new line. */
1197 save_line
= new_line
;
1199 while ((p
= locate_arg (line
)))
1203 memcpy (new_line
, line
, p
- line
);
1204 new_line
+= p
- line
;
1207 len
= user_args
->a
[i
].len
;
1210 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1215 /* Don't forget the tail. */
1216 strcpy (new_line
, line
);
1218 /* Return a pointer to the beginning of the new line. */
1223 execute_user_command (c
, args
)
1224 struct cmd_list_element
*c
;
1227 register struct command_line
*cmdlines
;
1228 struct cleanup
*old_chain
;
1229 enum command_control_type ret
;
1231 old_chain
= setup_user_args (args
);
1233 cmdlines
= c
->user_commands
;
1238 /* Set the instream to 0, indicating execution of a
1239 user-defined function. */
1240 old_chain
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
1241 instream
= (FILE *) 0;
1244 ret
= execute_control_command (cmdlines
);
1245 if (ret
!= simple_control
&& ret
!= break_control
)
1247 warning ("Error in control structure.\n");
1250 cmdlines
= cmdlines
->next
;
1252 do_cleanups (old_chain
);
1255 /* Execute the line P as a command.
1256 Pass FROM_TTY as second argument to the defining function. */
1259 execute_command (p
, from_tty
)
1263 register struct cmd_list_element
*c
;
1264 register enum language flang
;
1265 static int warned
= 0;
1266 /* FIXME: These should really be in an appropriate header file */
1267 extern void serial_log_command
PARAMS ((const char *));
1271 /* Force cleanup of any alloca areas if using C alloca instead of
1272 a builtin alloca. */
1275 /* This can happen when command_line_input hits end of file. */
1279 serial_log_command (p
);
1281 while (*p
== ' ' || *p
== '\t')
1287 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1289 /* If the target is running, we allow only a limited set of
1291 if (async_p
&& target_has_async
&& target_executing
)
1292 if (!strcmp (c
->name
, "help")
1293 && !strcmp (c
->name
, "pwd")
1294 && !strcmp (c
->name
, "show")
1295 && !strcmp (c
->name
, "stop"))
1296 error ("Cannot execute this command while the target is running.");
1298 /* Pass null arg rather than an empty one. */
1301 /* Clear off trailing whitespace, except for set and complete command. */
1302 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1304 p
= arg
+ strlen (arg
) - 1;
1305 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1310 /* If this command has been hooked, run the hook first. */
1312 execute_user_command (c
->hook
, (char *) 0);
1314 if (c
->class == class_user
)
1315 execute_user_command (c
, arg
);
1316 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1317 do_setshow_command (arg
, from_tty
& caution
, c
);
1318 else if (c
->function
.cfunc
== NO_FUNCTION
)
1319 error ("That is not a command, just a help topic.");
1320 else if (call_command_hook
)
1321 call_command_hook (c
, arg
, from_tty
& caution
);
1323 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1326 /* Tell the user if the language has changed (except first time). */
1327 if (current_language
!= expected_language
)
1329 if (language_mode
== language_mode_auto
)
1331 language_info (1); /* Print what changed. */
1336 /* Warn the user if the working language does not match the
1337 language of the current frame. Only warn the user if we are
1338 actually running the program, i.e. there is a stack. */
1339 /* FIXME: This should be cacheing the frame and only running when
1340 the frame changes. */
1342 if (target_has_stack
)
1344 flang
= get_frame_language ();
1346 && flang
!= language_unknown
1347 && flang
!= current_language
->la_language
)
1349 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1356 /* NOTE 1999-04-29: This function will be static again, once we modify
1357 gdb to use the event loop as the default command loop and we merge
1358 event-top.c into this file, top.c */
1360 command_loop_marker (foo
)
1365 /* Read commands from `instream' and execute them
1366 until end of file or error reading instream. */
1371 struct cleanup
*old_chain
;
1373 int stdin_is_tty
= ISATTY (stdin
);
1374 long time_at_cmd_start
;
1376 long space_at_cmd_start
= 0;
1378 extern int display_time
;
1379 extern int display_space
;
1381 while (instream
&& !feof (instream
))
1384 extern int insert_mode
;
1386 if (window_hook
&& instream
== stdin
)
1387 (*window_hook
) (instream
, get_prompt ());
1390 if (instream
== stdin
&& stdin_is_tty
)
1391 reinitialize_more_filter ();
1392 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1395 /* A bit of paranoia: I want to make sure the "insert_mode" global
1396 * is clear except when it is being used for command-line editing
1397 * (see tuiIO.c, utils.c); otherwise normal output will
1398 * get messed up in the TUI. So clear it before/after
1399 * the command-line-input call. - RT
1403 /* Get a command-line. This calls the readline package. */
1404 command
= command_line_input (instream
== stdin
?
1405 get_prompt () : (char *) NULL
,
1406 instream
== stdin
, "prompt");
1413 time_at_cmd_start
= get_run_time ();
1418 extern char **environ
;
1419 char *lim
= (char *) sbrk (0);
1421 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1425 execute_command (command
, instream
== stdin
);
1426 /* Do any commands attached to breakpoint we stopped at. */
1427 bpstat_do_actions (&stop_bpstat
);
1428 do_cleanups (old_chain
);
1432 long cmd_time
= get_run_time () - time_at_cmd_start
;
1434 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1435 cmd_time
/ 1000000, cmd_time
% 1000000);
1441 extern char **environ
;
1442 char *lim
= (char *) sbrk (0);
1443 long space_now
= lim
- (char *) &environ
;
1444 long space_diff
= space_now
- space_at_cmd_start
;
1446 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1448 (space_diff
>= 0 ? '+' : '-'),
1456 /* Commands call this if they do not want to be repeated by null lines. */
1464 /* If we aren't reading from standard input, we are saving the last
1465 thing read from stdin in line and don't want to delete it. Null lines
1466 won't repeat here in any case. */
1467 if (instream
== stdin
)
1471 /* Read a line from the stream "instream" without command line editing.
1473 It prints PROMPT_ARG once at the start.
1474 Action is compatible with "readline", e.g. space for the result is
1475 malloc'd and should be freed by the caller.
1477 A NULL return means end of file. */
1479 gdb_readline (prompt_arg
)
1484 int input_index
= 0;
1485 int result_size
= 80;
1489 /* Don't use a _filtered function here. It causes the assumed
1490 character position to be off, since the newline we read from
1491 the user is not accounted for. */
1492 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1494 /* Move to a new line so the entered line doesn't have a prompt
1495 on the front of it. */
1496 fputs_unfiltered ("\n", gdb_stdout
);
1498 gdb_flush (gdb_stdout
);
1501 result
= (char *) xmalloc (result_size
);
1505 /* Read from stdin if we are executing a user defined command.
1506 This is the right thing for prompt_for_continue, at least. */
1507 c
= fgetc (instream
? instream
: stdin
);
1511 if (input_index
> 0)
1512 /* The last line does not end with a newline. Return it, and
1513 if we are called again fgetc will still return EOF and
1514 we'll return NULL then. */
1521 #ifndef CRLF_SOURCE_FILES
1525 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1531 result
[input_index
++] = c
;
1532 while (input_index
>= result_size
)
1535 result
= (char *) xrealloc (result
, result_size
);
1539 result
[input_index
++] = '\0';
1543 /* Variables which control command line editing and history
1544 substitution. These variables are given default values at the end
1546 static int command_editing_p
;
1547 /* NOTE 1999-04-29: This variable will be static again, once we modify
1548 gdb to use the event loop as the default command loop and we merge
1549 event-top.c into this file, top.c */
1550 /* static */ int history_expansion_p
;
1551 static int write_history_p
;
1552 static int history_size
;
1553 static char *history_filename
;
1555 /* readline uses the word breaks for two things:
1556 (1) In figuring out where to point the TEXT parameter to the
1557 rl_completion_entry_function. Since we don't use TEXT for much,
1558 it doesn't matter a lot what the word breaks are for this purpose, but
1559 it does affect how much stuff M-? lists.
1560 (2) If one of the matches contains a word break character, readline
1561 will quote it. That's why we switch between
1562 gdb_completer_word_break_characters and
1563 gdb_completer_command_word_break_characters. I'm not sure when
1564 we need this behavior (perhaps for funky characters in C++ symbols?). */
1566 /* Variables which are necessary for fancy command line editing. */
1567 char *gdb_completer_word_break_characters
=
1568 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1570 /* When completing on command names, we remove '-' from the list of
1571 word break characters, since we use it in command names. If the
1572 readline library sees one in any of the current completion strings,
1573 it thinks that the string needs to be quoted and automatically supplies
1575 char *gdb_completer_command_word_break_characters
=
1576 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1578 /* Characters that can be used to quote completion strings. Note that we
1579 can't include '"' because the gdb C parser treats such quoted sequences
1581 char *gdb_completer_quote_characters
=
1584 /* Functions that are used as part of the fancy command line editing. */
1586 /* This can be used for functions which don't want to complete on symbols
1587 but don't want to complete on anything else either. */
1590 noop_completer (text
, prefix
)
1597 /* Complete on filenames. */
1599 filename_completer (text
, word
)
1603 /* From readline. */
1604 extern char *filename_completion_function
PARAMS ((char *, int));
1605 int subsequent_name
;
1607 int return_val_used
;
1608 int return_val_alloced
;
1610 return_val_used
= 0;
1611 /* Small for testing. */
1612 return_val_alloced
= 1;
1613 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1615 subsequent_name
= 0;
1619 p
= filename_completion_function (text
, subsequent_name
);
1620 if (return_val_used
>= return_val_alloced
)
1622 return_val_alloced
*= 2;
1624 (char **) xrealloc (return_val
,
1625 return_val_alloced
* sizeof (char *));
1629 return_val
[return_val_used
++] = p
;
1632 /* Like emacs, don't complete on old versions. Especially useful
1633 in the "source" command. */
1634 if (p
[strlen (p
) - 1] == '~')
1640 /* Return exactly p. */
1641 return_val
[return_val_used
++] = p
;
1642 else if (word
> text
)
1644 /* Return some portion of p. */
1645 q
= xmalloc (strlen (p
) + 5);
1646 strcpy (q
, p
+ (word
- text
));
1647 return_val
[return_val_used
++] = q
;
1652 /* Return some of TEXT plus p. */
1653 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1654 strncpy (q
, word
, text
- word
);
1655 q
[text
- word
] = '\0';
1657 return_val
[return_val_used
++] = q
;
1661 subsequent_name
= 1;
1664 /* There is no way to do this just long enough to affect quote inserting
1665 without also affecting the next completion. This should be fixed in
1667 /* Insure that readline does the right thing
1668 with respect to inserting quotes. */
1669 rl_completer_word_break_characters
= "";
1674 /* Here are some useful test cases for completion. FIXME: These should
1675 be put in the test suite. They should be tested with both M-? and TAB.
1677 "show output-" "radix"
1678 "show output" "-radix"
1679 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1680 "p " ambiguous (all symbols)
1681 "info t foo" no completions
1682 "info t " no completions
1683 "info t" ambiguous ("info target", "info terminal", etc.)
1684 "info ajksdlfk" no completions
1685 "info ajksdlfk " no completions
1687 "info " ambiguous (all info commands)
1688 "p \"a" no completions (string constant)
1689 "p 'a" ambiguous (all symbols starting with a)
1690 "p b-a" ambiguous (all symbols starting with a)
1691 "p b-" ambiguous (all symbols)
1692 "file Make" "file" (word break hard to screw up here)
1693 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1696 /* Generate completions one by one for the completer. Each time we are
1697 called return another potential completion to the caller.
1698 line_completion just completes on commands or passes the buck to the
1699 command's completer function, the stuff specific to symbol completion
1700 is in make_symbol_completion_list.
1702 TEXT is the caller's idea of the "word" we are looking at.
1704 MATCHES is the number of matches that have currently been collected from
1705 calling this completion function. When zero, then we need to initialize,
1706 otherwise the initialization has already taken place and we can just
1707 return the next potential completion string.
1709 LINE_BUFFER is available to be looked at; it contains the entire text
1710 of the line. POINT is the offset in that line of the cursor. You
1711 should pretend that the line ends at POINT.
1713 Returns NULL if there are no more completions, else a pointer to a string
1714 which is a possible completion, it is the caller's responsibility to
1718 line_completion_function (text
, matches
, line_buffer
, point
)
1724 static char **list
= (char **) NULL
; /* Cache of completions */
1725 static int index
; /* Next cached completion */
1726 char *output
= NULL
;
1727 char *tmp_command
, *p
;
1728 /* Pointer within tmp_command which corresponds to text. */
1730 struct cmd_list_element
*c
, *result_list
;
1734 /* The caller is beginning to accumulate a new set of completions, so
1735 we need to find all of them now, and cache them for returning one at
1736 a time on future calls. */
1740 /* Free the storage used by LIST, but not by the strings inside.
1741 This is because rl_complete_internal () frees the strings. */
1747 /* Choose the default set of word break characters to break completions.
1748 If we later find out that we are doing completions on command strings
1749 (as opposed to strings supplied by the individual command completer
1750 functions, which can be any string) then we will switch to the
1751 special word break set for command strings, which leaves out the
1752 '-' character used in some commands. */
1754 rl_completer_word_break_characters
=
1755 gdb_completer_word_break_characters
;
1757 /* Decide whether to complete on a list of gdb commands or on symbols. */
1758 tmp_command
= (char *) alloca (point
+ 1);
1761 strncpy (tmp_command
, line_buffer
, point
);
1762 tmp_command
[point
] = '\0';
1763 /* Since text always contains some number of characters leading up
1764 to point, we can find the equivalent position in tmp_command
1765 by subtracting that many characters from the end of tmp_command. */
1766 word
= tmp_command
+ point
- strlen (text
);
1770 /* An empty line we want to consider ambiguous; that is, it
1771 could be any command. */
1772 c
= (struct cmd_list_element
*) -1;
1777 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1780 /* Move p up to the next interesting thing. */
1781 while (*p
== ' ' || *p
== '\t')
1788 /* It is an unrecognized command. So there are no
1789 possible completions. */
1792 else if (c
== (struct cmd_list_element
*) -1)
1796 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1797 doesn't advance over that thing itself. Do so now. */
1799 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1801 if (q
!= tmp_command
+ point
)
1803 /* There is something beyond the ambiguous
1804 command, so there are no possible completions. For
1805 example, "info t " or "info t foo" does not complete
1806 to anything, because "info t" can be "info target" or
1812 /* We're trying to complete on the command which was ambiguous.
1813 This we can deal with. */
1816 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1821 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1823 /* Insure that readline does the right thing with respect to
1824 inserting quotes. */
1825 rl_completer_word_break_characters
=
1826 gdb_completer_command_word_break_characters
;
1831 /* We've recognized a full command. */
1833 if (p
== tmp_command
+ point
)
1835 /* There is no non-whitespace in the line beyond the command. */
1837 if (p
[-1] == ' ' || p
[-1] == '\t')
1839 /* The command is followed by whitespace; we need to complete
1840 on whatever comes after command. */
1843 /* It is a prefix command; what comes after it is
1844 a subcommand (e.g. "info "). */
1845 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1847 /* Insure that readline does the right thing
1848 with respect to inserting quotes. */
1849 rl_completer_word_break_characters
=
1850 gdb_completer_command_word_break_characters
;
1854 list
= complete_on_enum (c
->enums
, p
, word
);
1855 rl_completer_word_break_characters
=
1856 gdb_completer_command_word_break_characters
;
1860 /* It is a normal command; what comes after it is
1861 completed by the command's completer function. */
1862 list
= (*c
->completer
) (p
, word
);
1867 /* The command is not followed by whitespace; we need to
1868 complete on the command itself. e.g. "p" which is a
1869 command itself but also can complete to "print", "ptype"
1873 /* Find the command we are completing on. */
1875 while (q
> tmp_command
)
1877 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1883 list
= complete_on_cmdlist (result_list
, q
, word
);
1885 /* Insure that readline does the right thing
1886 with respect to inserting quotes. */
1887 rl_completer_word_break_characters
=
1888 gdb_completer_command_word_break_characters
;
1893 /* There is non-whitespace beyond the command. */
1895 if (c
->prefixlist
&& !c
->allow_unknown
)
1897 /* It is an unrecognized subcommand of a prefix command,
1898 e.g. "info adsfkdj". */
1903 list
= complete_on_enum (c
->enums
, p
, word
);
1907 /* It is a normal command. */
1908 list
= (*c
->completer
) (p
, word
);
1914 /* If we found a list of potential completions during initialization then
1915 dole them out one at a time. The vector of completions is NULL
1916 terminated, so after returning the last one, return NULL (and continue
1917 to do so) each time we are called after that, until a new list is
1922 output
= list
[index
];
1930 /* Can't do this because readline hasn't yet checked the word breaks
1931 for figuring out whether to insert a quote. */
1933 /* Make sure the word break characters are set back to normal for the
1934 next time that readline tries to complete something. */
1935 rl_completer_word_break_characters
=
1936 gdb_completer_word_break_characters
;
1942 /* Line completion interface function for readline. */
1945 readline_line_completion_function (text
, matches
)
1949 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
1952 /* Skip over a possibly quoted word (as defined by the quote characters
1953 and word break characters the completer uses). Returns pointer to the
1954 location after the "word". */
1960 char quote_char
= '\0';
1963 for (scan
= str
; *scan
!= '\0'; scan
++)
1965 if (quote_char
!= '\0')
1967 /* Ignore everything until the matching close quote char */
1968 if (*scan
== quote_char
)
1970 /* Found matching close quote. */
1975 else if (strchr (gdb_completer_quote_characters
, *scan
))
1977 /* Found start of a quoted string. */
1980 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1994 #if STOP_SIGNAL == SIGTSTP
1995 signal (SIGTSTP
, SIG_DFL
);
1997 kill (getpid (), SIGTSTP
);
1998 signal (SIGTSTP
, stop_sig
);
2000 signal (STOP_SIGNAL
, stop_sig
);
2002 printf_unfiltered ("%s", get_prompt ());
2003 gdb_flush (gdb_stdout
);
2005 /* Forget about any previous command -- null line now will do nothing. */
2008 #endif /* STOP_SIGNAL */
2010 /* Initialize signal handlers. */
2015 /* Under System V the default disposition of a signal is reinstated after
2016 the signal is caught and delivered to an application process. On such
2017 systems one must restore the replacement signal handler if one wishes
2018 to continue handling the signal in one's program. On BSD systems this
2019 is not needed but it is harmless, and it simplifies the code to just do
2020 it unconditionally. */
2021 signal (signo
, do_nothing
);
2027 signal (SIGINT
, request_quit
);
2029 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2030 to the inferior and breakpoints will be ignored. */
2032 signal (SIGTRAP
, SIG_DFL
);
2035 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2036 passed to the inferior, which we don't want. It would be
2037 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2038 on BSD4.3 systems using vfork, that can affect the
2039 GDB process as well as the inferior (the signal handling tables
2040 might be in memory, shared between the two). Since we establish
2041 a handler for SIGQUIT, when we call exec it will set the signal
2042 to SIG_DFL for us. */
2043 signal (SIGQUIT
, do_nothing
);
2045 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
2046 signal (SIGHUP
, disconnect
);
2048 signal (SIGFPE
, float_handler
);
2050 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2051 signal (SIGWINCH
, SIGWINCH_HANDLER
);
2055 /* Read one line from the command input stream `instream'
2056 into the local static buffer `linebuffer' (whose current length
2058 The buffer is made bigger as necessary.
2059 Returns the address of the start of the line.
2061 NULL is returned for end of file.
2063 *If* the instream == stdin & stdin is a terminal, the line read
2064 is copied into the file line saver (global var char *line,
2065 length linesize) so that it can be duplicated.
2067 This routine either uses fancy command line editing or
2068 simple input as the user has requested. */
2071 command_line_input (prompt_arg
, repeat
, annotation_suffix
)
2074 char *annotation_suffix
;
2076 static char *linebuffer
= 0;
2077 static unsigned linelength
= 0;
2081 char *local_prompt
= prompt_arg
;
2085 /* The annotation suffix must be non-NULL. */
2086 if (annotation_suffix
== NULL
)
2087 annotation_suffix
= "";
2089 if (annotation_level
> 1 && instream
== stdin
)
2091 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
2092 + strlen (annotation_suffix
) + 40);
2093 if (prompt_arg
== NULL
)
2094 local_prompt
[0] = '\0';
2096 strcpy (local_prompt
, prompt_arg
);
2097 strcat (local_prompt
, "\n\032\032");
2098 strcat (local_prompt
, annotation_suffix
);
2099 strcat (local_prompt
, "\n");
2102 if (linebuffer
== 0)
2105 linebuffer
= (char *) xmalloc (linelength
);
2110 /* Control-C quits instantly if typed while in this loop
2111 since it should not wait until the user types a newline. */
2117 signal (STOP_SIGNAL
, handle_stop_sig
);
2119 signal (STOP_SIGNAL
, stop_sig
);
2125 /* Make sure that all output has been output. Some machines may let
2126 you get away with leaving out some of the gdb_flush, but not all. */
2128 gdb_flush (gdb_stdout
);
2129 gdb_flush (gdb_stderr
);
2131 if (source_file_name
!= NULL
)
2133 ++source_line_number
;
2134 sprintf (source_error
,
2135 "%s%s:%d: Error in sourced command file:\n",
2138 source_line_number
);
2139 error_pre_print
= source_error
;
2142 if (annotation_level
> 1 && instream
== stdin
)
2144 printf_unfiltered ("\n\032\032pre-");
2145 printf_unfiltered (annotation_suffix
);
2146 printf_unfiltered ("\n");
2149 /* Don't use fancy stuff if not talking to stdin. */
2150 if (readline_hook
&& instream
== NULL
)
2152 rl
= (*readline_hook
) (local_prompt
);
2154 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2156 rl
= readline (local_prompt
);
2160 rl
= gdb_readline (local_prompt
);
2163 if (annotation_level
> 1 && instream
== stdin
)
2165 printf_unfiltered ("\n\032\032post-");
2166 printf_unfiltered (annotation_suffix
);
2167 printf_unfiltered ("\n");
2170 if (!rl
|| rl
== (char *) EOF
)
2175 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
2177 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
2178 nline
= (char *) xrealloc (linebuffer
, linelength
);
2179 p
+= nline
- linebuffer
;
2183 /* Copy line. Don't copy null at end. (Leaves line alone
2184 if this was just a newline) */
2188 free (rl
); /* Allocated in readline. */
2190 if (p
== linebuffer
|| *(p
- 1) != '\\')
2193 p
--; /* Put on top of '\'. */
2194 local_prompt
= (char *) 0;
2199 signal (STOP_SIGNAL
, SIG_DFL
);
2206 #define SERVER_COMMAND_LENGTH 7
2208 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2209 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2212 /* Note that we don't set `line'. Between this and the check in
2213 dont_repeat, this insures that repeating will still do the
2216 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2219 /* Do history expansion if that is wished. */
2220 if (history_expansion_p
&& instream
== stdin
2221 && ISATTY (instream
))
2223 char *history_value
;
2226 *p
= '\0'; /* Insert null now. */
2227 expanded
= history_expand (linebuffer
, &history_value
);
2230 /* Print the changes. */
2231 printf_unfiltered ("%s\n", history_value
);
2233 /* If there was an error, call this function again. */
2236 free (history_value
);
2237 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2239 if (strlen (history_value
) > linelength
)
2241 linelength
= strlen (history_value
) + 1;
2242 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2244 strcpy (linebuffer
, history_value
);
2245 p
= linebuffer
+ strlen (linebuffer
);
2246 free (history_value
);
2250 /* If we just got an empty line, and that is supposed
2251 to repeat the previous command, return the value in the
2253 if (repeat
&& p
== linebuffer
)
2255 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
2261 /* Add line to history if appropriate. */
2262 if (instream
== stdin
2263 && ISATTY (stdin
) && *linebuffer
)
2264 add_history (linebuffer
);
2266 /* Note: lines consisting solely of comments are added to the command
2267 history. This is useful when you type a command, and then
2268 realize you don't want to execute it quite yet. You can comment
2269 out the command and then later fetch it from the value history
2270 and remove the '#'. The kill ring is probably better, but some
2271 people are in the habit of commenting things out. */
2273 *p1
= '\0'; /* Found a comment. */
2275 /* Save into global buffer if appropriate. */
2278 if (linelength
> linesize
)
2280 line
= xrealloc (line
, linelength
);
2281 linesize
= linelength
;
2283 strcpy (line
, linebuffer
);
2291 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2292 code bodies. This is typically used when we encounter an "else"
2293 clause for an "if" command. */
2296 realloc_body_list (command
, new_length
)
2297 struct command_line
*command
;
2301 struct command_line
**body_list
;
2303 n
= command
->body_count
;
2305 /* Nothing to do? */
2306 if (new_length
<= n
)
2309 body_list
= (struct command_line
**)
2310 xmalloc (sizeof (struct command_line
*) * new_length
);
2312 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2314 free (command
->body_list
);
2315 command
->body_list
= body_list
;
2316 command
->body_count
= new_length
;
2319 /* Read one line from the input stream. If the command is an "else" or
2320 "end", return such an indication to the caller. */
2322 static enum misc_command_type
2323 read_next_line (command
)
2324 struct command_line
**command
;
2326 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2329 if (control_level
>= 254)
2330 error ("Control nesting too deep!\n");
2332 /* Set a prompt based on the nesting of the control commands. */
2333 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2335 for (i
= 0; i
< control_level
; i
++)
2336 control_prompt
[i
] = ' ';
2337 control_prompt
[i
] = '>';
2338 control_prompt
[i
+ 1] = '\0';
2339 prompt_ptr
= (char *) &control_prompt
[0];
2344 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2346 /* Not sure what to do here. */
2350 /* Strip leading and trailing whitespace. */
2351 while (*p
== ' ' || *p
== '\t')
2354 p1
= p
+ strlen (p
);
2355 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2358 /* Blanks and comments don't really do anything, but we need to
2359 distinguish them from else, end and other commands which can be
2361 if (p1
== p
|| p
[0] == '#')
2364 /* Is this the end of a simple, while, or if control structure? */
2365 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2368 /* Is the else clause of an if control structure? */
2369 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2370 return else_command
;
2372 /* Check for while, if, break, continue, etc and build a new command
2373 line structure for them. */
2374 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2375 *command
= build_command_line (while_control
, p
+ 6);
2376 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2377 *command
= build_command_line (if_control
, p
+ 3);
2378 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2380 *command
= (struct command_line
*)
2381 xmalloc (sizeof (struct command_line
));
2382 (*command
)->next
= NULL
;
2383 (*command
)->line
= NULL
;
2384 (*command
)->control_type
= break_control
;
2385 (*command
)->body_count
= 0;
2386 (*command
)->body_list
= NULL
;
2388 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2390 *command
= (struct command_line
*)
2391 xmalloc (sizeof (struct command_line
));
2392 (*command
)->next
= NULL
;
2393 (*command
)->line
= NULL
;
2394 (*command
)->control_type
= continue_control
;
2395 (*command
)->body_count
= 0;
2396 (*command
)->body_list
= NULL
;
2400 /* A normal command. */
2401 *command
= (struct command_line
*)
2402 xmalloc (sizeof (struct command_line
));
2403 (*command
)->next
= NULL
;
2404 (*command
)->line
= savestring (p
, p1
- p
);
2405 (*command
)->control_type
= simple_control
;
2406 (*command
)->body_count
= 0;
2407 (*command
)->body_list
= NULL
;
2410 /* Nothing special. */
2414 /* Recursively read in the control structures and create a command_line
2415 structure from them.
2417 The parent_control parameter is the control structure in which the
2418 following commands are nested. */
2420 static enum command_control_type
2421 recurse_read_control_structure (current_cmd
)
2422 struct command_line
*current_cmd
;
2424 int current_body
, i
;
2425 enum misc_command_type val
;
2426 enum command_control_type ret
;
2427 struct command_line
**body_ptr
, *child_tail
, *next
;
2432 /* Sanity checks. */
2433 if (current_cmd
->control_type
== simple_control
)
2435 error ("Recursed on a simple control type\n");
2436 return invalid_control
;
2439 if (current_body
> current_cmd
->body_count
)
2441 error ("Allocated body is smaller than this command type needs\n");
2442 return invalid_control
;
2445 /* Read lines from the input stream and build control structures. */
2451 val
= read_next_line (&next
);
2453 /* Just skip blanks and comments. */
2454 if (val
== nop_command
)
2457 if (val
== end_command
)
2459 if (current_cmd
->control_type
== while_control
2460 || current_cmd
->control_type
== if_control
)
2462 /* Success reading an entire control structure. */
2463 ret
= simple_control
;
2468 ret
= invalid_control
;
2473 /* Not the end of a control structure. */
2474 if (val
== else_command
)
2476 if (current_cmd
->control_type
== if_control
2477 && current_body
== 1)
2479 realloc_body_list (current_cmd
, 2);
2486 ret
= invalid_control
;
2493 child_tail
->next
= next
;
2497 body_ptr
= current_cmd
->body_list
;
2498 for (i
= 1; i
< current_body
; i
++)
2507 /* If the latest line is another control structure, then recurse
2509 if (next
->control_type
== while_control
2510 || next
->control_type
== if_control
)
2513 ret
= recurse_read_control_structure (next
);
2516 if (ret
!= simple_control
)
2526 /* Read lines from the input stream and accumulate them in a chain of
2527 struct command_line's, which is then returned. For input from a
2528 terminal, the special command "end" is used to mark the end of the
2529 input, and is not included in the returned chain of commands. */
2531 #define END_MESSAGE "End with a line saying just \"end\"."
2533 struct command_line
*
2534 read_command_lines (prompt_arg
, from_tty
)
2538 struct command_line
*head
, *tail
, *next
;
2539 struct cleanup
*old_chain
;
2540 enum command_control_type ret
;
2541 enum misc_command_type val
;
2544 if (readline_begin_hook
)
2546 /* Note - intentional to merge messages with no newline */
2547 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2549 else if (from_tty
&& input_from_terminal_p ())
2551 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2552 gdb_flush (gdb_stdout
);
2560 val
= read_next_line (&next
);
2562 /* Ignore blank lines or comments. */
2563 if (val
== nop_command
)
2566 if (val
== end_command
)
2568 ret
= simple_control
;
2572 if (val
!= ok_command
)
2574 ret
= invalid_control
;
2578 if (next
->control_type
== while_control
2579 || next
->control_type
== if_control
)
2582 ret
= recurse_read_control_structure (next
);
2585 if (ret
== invalid_control
)
2596 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
,
2606 if (ret
!= invalid_control
)
2608 discard_cleanups (old_chain
);
2611 do_cleanups (old_chain
);
2614 if (readline_end_hook
)
2616 (*readline_end_hook
) ();
2621 /* Free a chain of struct command_line's. */
2624 free_command_lines (lptr
)
2625 struct command_line
**lptr
;
2627 register struct command_line
*l
= *lptr
;
2628 register struct command_line
*next
;
2629 struct command_line
**blist
;
2634 if (l
->body_count
> 0)
2636 blist
= l
->body_list
;
2637 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2638 free_command_lines (blist
);
2647 /* Add an element to the list of info subcommands. */
2650 add_info (name
, fun
, doc
)
2652 void (*fun
) PARAMS ((char *, int));
2655 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2658 /* Add an alias to the list of info subcommands. */
2661 add_info_alias (name
, oldname
, abbrev_flag
)
2666 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2669 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2670 Therefore, its own definition is called only for "info" with no args. */
2674 info_command (arg
, from_tty
)
2678 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2679 help_list (infolist
, "info ", -1, gdb_stdout
);
2682 /* The "complete" command is used by Emacs to implement completion. */
2686 complete_command (arg
, from_tty
)
2698 argpoint
= strlen (arg
);
2700 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2702 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2704 printf_unfiltered ("%s\n", completion
);
2709 /* The "show" command with no arguments shows all the settings. */
2713 show_command (arg
, from_tty
)
2717 cmd_show_list (showlist
, from_tty
, "");
2720 /* Add an element to the list of commands. */
2723 add_com (name
, class, fun
, doc
)
2725 enum command_class
class;
2726 void (*fun
) PARAMS ((char *, int));
2729 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2732 /* Add an alias or abbreviation command to the list of commands. */
2735 add_com_alias (name
, oldname
, class, abbrev_flag
)
2738 enum command_class
class;
2741 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2748 error ("Argument required (%s).", why
);
2753 help_command (command
, from_tty
)
2755 int from_tty
; /* Ignored */
2757 help_cmd (command
, gdb_stdout
);
2761 validate_comname (comname
)
2767 error_no_arg ("name of command to define");
2772 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
2773 error ("Junk in argument list: \"%s\"", p
);
2778 /* This is just a placeholder in the command data structures. */
2780 user_defined_command (ignore
, from_tty
)
2787 define_command (comname
, from_tty
)
2791 register struct command_line
*cmds
;
2792 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2793 char *tem
= comname
;
2795 #define HOOK_STRING "hook-"
2798 validate_comname (comname
);
2800 /* Look it up, and verify that we got an exact match. */
2801 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2802 if (c
&& !STREQ (comname
, c
->name
))
2807 if (c
->class == class_user
|| c
->class == class_alias
)
2808 tem
= "Redefine command \"%s\"? ";
2810 tem
= "Really redefine built-in command \"%s\"? ";
2811 if (!query (tem
, c
->name
))
2812 error ("Command \"%s\" not redefined.", c
->name
);
2815 /* If this new command is a hook, then mark the command which it
2816 is hooking. Note that we allow hooking `help' commands, so that
2817 we can hook the `stop' pseudo-command. */
2819 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2821 /* Look up cmd it hooks, and verify that we got an exact match. */
2822 tem
= comname
+ HOOK_LEN
;
2823 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2824 if (hookc
&& !STREQ (comname
+ HOOK_LEN
, hookc
->name
))
2828 warning ("Your new `%s' command does not hook any existing command.",
2830 if (!query ("Proceed? "))
2831 error ("Not confirmed.");
2835 comname
= savestring (comname
, strlen (comname
));
2837 /* If the rest of the commands will be case insensitive, this one
2838 should behave in the same manner. */
2839 for (tem
= comname
; *tem
; tem
++)
2841 *tem
= tolower (*tem
);
2843 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
2844 cmds
= read_command_lines (tmpbuf
, from_tty
);
2846 if (c
&& c
->class == class_user
)
2847 free_command_lines (&c
->user_commands
);
2849 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2850 (c
&& c
->class == class_user
)
2851 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2852 newc
->user_commands
= cmds
;
2854 /* If this new command is a hook, then mark both commands as being
2858 hookc
->hook
= newc
; /* Target gets hooked. */
2859 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2864 document_command (comname
, from_tty
)
2868 struct command_line
*doclines
;
2869 register struct cmd_list_element
*c
;
2870 char *tem
= comname
;
2873 validate_comname (comname
);
2875 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2877 if (c
->class != class_user
)
2878 error ("Command \"%s\" is built-in.", comname
);
2880 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
2881 doclines
= read_command_lines (tmpbuf
, from_tty
);
2887 register struct command_line
*cl1
;
2888 register int len
= 0;
2890 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2891 len
+= strlen (cl1
->line
) + 1;
2893 c
->doc
= (char *) xmalloc (len
+ 1);
2896 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2898 strcat (c
->doc
, cl1
->line
);
2900 strcat (c
->doc
, "\n");
2904 free_command_lines (&doclines
);
2907 /* Print the GDB banner. */
2909 print_gdb_version (stream
)
2912 /* From GNU coding standards, first line is meant to be easy for a
2913 program to parse, and is just canonical program name and version
2914 number, which starts after last space. */
2916 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
2918 /* Second line is a copyright notice. */
2920 fprintf_filtered (stream
, "Copyright 1998 Free Software Foundation, Inc.\n");
2922 /* Following the copyright is a brief statement that the program is
2923 free software, that users are free to copy and change it on
2924 certain conditions, that it is covered by the GNU GPL, and that
2925 there is no warranty. */
2927 fprintf_filtered (stream
, "\
2928 GDB is free software, covered by the GNU General Public License, and you are\n\
2929 welcome to change it and/or distribute copies of it under certain conditions.\n\
2930 Type \"show copying\" to see the conditions.\n\
2931 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2933 /* After the required info we print the configuration information. */
2935 fprintf_filtered (stream
, "This GDB was configured as \"");
2936 if (!STREQ (host_name
, target_name
))
2938 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
2942 fprintf_filtered (stream
, "%s", host_name
);
2944 fprintf_filtered (stream
, "\".");
2949 show_version (args
, from_tty
)
2954 print_gdb_version (gdb_stdout
);
2955 printf_filtered ("\n");
2959 /* get_prompt: access method for the GDB prompt string. */
2961 #define MAX_PROMPT_SIZE 256
2964 * int get_prompt_1 (char * buf);
2966 * Work-horse for get_prompt (called via catch_errors).
2967 * Argument is buffer to hold the formatted prompt.
2969 * Returns: 1 for success (use formatted prompt)
2970 * 0 for failure (use gdb_prompt_string).
2973 static int gdb_prompt_escape
;
2976 get_prompt_1 (formatted_prompt
)
2977 char *formatted_prompt
;
2982 local_prompt
= PROMPT (0);
2984 local_prompt
= gdb_prompt_string
;
2987 if (gdb_prompt_escape
== 0)
2989 return 0; /* do no formatting */
2992 /* formatted prompt */
2994 char fmt
[40], *promptp
, *outp
, *tmp
;
3001 struct type
*arg_type
, *elt_type
;
3003 promptp
= local_prompt
;
3004 outp
= formatted_prompt
;
3006 while (*promptp
!= '\0')
3008 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
3010 if (*promptp
!= gdb_prompt_escape
)
3012 if (available
>= 1) /* overflow protect */
3013 *outp
++ = *promptp
++;
3017 /* GDB prompt string contains escape char. Parse for arg.
3018 Two consecutive escape chars followed by arg followed by
3019 a comma means to insert the arg using a default format.
3020 Otherwise a printf format string may be included between
3021 the two escape chars. eg:
3022 %%foo, insert foo using default format
3023 %2.2f%foo, insert foo using "%2.2f" format
3024 A mismatch between the format string and the data type
3025 of "foo" is an error (which we don't know how to protect
3028 fmt
[0] = '\0'; /* assume null format string */
3029 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
3031 promptp
+= 2; /* skip past two escape chars. */
3035 /* extract format string from between two esc chars */
3039 fmt
[i
++] = *promptp
++; /* copy format string */
3041 while (i
< sizeof (fmt
) - 1 &&
3042 *promptp
!= gdb_prompt_escape
&&
3045 if (*promptp
!= gdb_prompt_escape
)
3046 error ("Syntax error at prompt position %d",
3047 promptp
- local_prompt
);
3050 promptp
++; /* skip second escape char */
3051 fmt
[i
++] = '\0'; /* terminate the format string */
3055 arg_val
= parse_to_comma_and_eval (&promptp
);
3056 if (*promptp
== ',')
3057 promptp
++; /* skip past the comma */
3058 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
3059 switch (TYPE_CODE (arg_type
))
3061 case TYPE_CODE_ARRAY
:
3062 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3063 if (TYPE_LENGTH (arg_type
) > 0 &&
3064 TYPE_LENGTH (elt_type
) == 1 &&
3065 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
3067 int len
= TYPE_LENGTH (arg_type
);
3069 if (VALUE_LAZY (arg_val
))
3070 value_fetch_lazy (arg_val
);
3071 tmp
= VALUE_CONTENTS (arg_val
);
3073 if (len
> available
)
3074 len
= available
; /* overflow protect */
3076 /* FIXME: how to protect GDB from crashing
3077 from bad user-supplied format string? */
3079 sprintf (outp
, fmt
, tmp
);
3081 strncpy (outp
, tmp
, len
);
3086 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3087 addrval
= value_as_pointer (arg_val
);
3089 if (TYPE_LENGTH (elt_type
) == 1 &&
3090 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
3093 /* display it as a string */
3094 char *default_fmt
= "%s";
3098 /* Limiting the number of bytes that the following call
3099 will read protects us from sprintf overflow later. */
3100 i
= target_read_string (addrval
, /* src */
3102 available
, /* len */
3104 if (err
) /* read failed */
3105 error ("%s on target_read", safe_strerror (err
));
3107 tmp
[i
] = '\0'; /* force-terminate string */
3108 /* FIXME: how to protect GDB from crashing
3109 from bad user-supplied format string? */
3110 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3116 /* display it as a pointer */
3117 char *default_fmt
= "0x%x";
3119 /* FIXME: how to protect GDB from crashing
3120 from bad user-supplied format string? */
3121 if (available
>= 16 /*? */ ) /* overflow protect */
3122 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3128 char *default_fmt
= "%g";
3130 doubleval
= value_as_double (arg_val
);
3131 /* FIXME: how to protect GDB from crashing
3132 from bad user-supplied format string? */
3133 if (available
>= 16 /*? */ ) /* overflow protect */
3134 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3135 (double) doubleval
);
3140 char *default_fmt
= "%d";
3142 longval
= value_as_long (arg_val
);
3143 /* FIXME: how to protect GDB from crashing
3144 from bad user-supplied format string? */
3145 if (available
>= 16 /*? */ ) /* overflow protect */
3146 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3150 case TYPE_CODE_BOOL
:
3152 /* no default format for bool */
3153 longval
= value_as_long (arg_val
);
3154 if (available
>= 8 /*? */ ) /* overflow protect */
3157 strcpy (outp
, "<true>");
3159 strcpy (outp
, "<false>");
3163 case TYPE_CODE_ENUM
:
3165 /* no default format for enum */
3166 longval
= value_as_long (arg_val
);
3167 len
= TYPE_NFIELDS (arg_type
);
3168 /* find enum name if possible */
3169 for (i
= 0; i
< len
; i
++)
3170 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3171 break; /* match -- end loop */
3173 if (i
< len
) /* enum name found */
3175 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3177 strncpy (outp
, name
, available
);
3178 /* in casel available < strlen (name), */
3179 outp
[available
] = '\0';
3183 if (available
>= 16 /*? */ ) /* overflow protect */
3184 sprintf (outp
, "%d", (long) longval
);
3188 case TYPE_CODE_VOID
:
3190 break; /* void type -- no output */
3192 error ("bad data type at prompt position %d",
3193 promptp
- local_prompt
);
3196 outp
+= strlen (outp
);
3199 *outp
++ = '\0'; /* terminate prompt string */
3207 static char buf
[MAX_PROMPT_SIZE
];
3209 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3212 return &buf
[0]; /* successful formatted prompt */
3216 /* Prompt could not be formatted. */
3220 return gdb_prompt_string
;
3228 /* ??rehrauer: I don't know why this fails, since it looks as though
3229 assignments to prompt are wrapped in calls to savestring...
3234 PROMPT (0) = savestring (s
, strlen (s
));
3236 gdb_prompt_string
= savestring (s
, strlen (s
));
3240 /* If necessary, make the user confirm that we should quit. Return
3241 non-zero if we should quit, zero if we shouldn't. */
3246 if (inferior_pid
!= 0 && target_has_execution
)
3250 /* This is something of a hack. But there's no reliable way to
3251 see if a GUI is running. The `use_windows' variable doesn't
3254 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3255 else if (attach_flag
)
3256 s
= "The program is running. Quit anyway (and detach it)? ";
3258 s
= "The program is running. Exit anyway? ";
3267 /* Quit without asking for confirmation. */
3270 quit_force (args
, from_tty
)
3276 /* An optional expression may be used to cause gdb to terminate with the
3277 value of that expression. */
3280 value_ptr val
= parse_and_eval (args
);
3282 exit_code
= (int) value_as_long (val
);
3285 if (inferior_pid
!= 0 && target_has_execution
)
3288 target_detach (args
, from_tty
);
3293 /* UDI wants this, to kill the TIP. */
3296 /* Save the history information if it is appropriate to do so. */
3297 if (write_history_p
&& history_filename
)
3298 write_history (history_filename
);
3300 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3303 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3304 /* The above does not need to be inside a tuiDo(), since
3305 * it is not manipulating the curses screen, but rather,
3306 * it is tearing it down.
3315 /* Handle the quit command. */
3318 quit_command (args
, from_tty
)
3322 if (!quit_confirm ())
3323 error ("Not confirmed.");
3324 quit_force (args
, from_tty
);
3327 /* Returns whether GDB is running on a terminal and whether the user
3328 desires that questions be asked of them on that terminal. */
3331 input_from_terminal_p ()
3333 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3338 pwd_command (args
, from_tty
)
3343 error ("The \"pwd\" command does not take an argument: %s", args
);
3344 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3346 if (!STREQ (gdb_dirbuf
, current_directory
))
3347 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3348 current_directory
, gdb_dirbuf
);
3350 printf_unfiltered ("Working directory %s.\n", current_directory
);
3354 cd_command (dir
, from_tty
)
3359 /* Found something other than leading repetitions of "/..". */
3360 int found_real_path
;
3363 /* If the new directory is absolute, repeat is a no-op; if relative,
3364 repeat might be useful but is more likely to be a mistake. */
3368 error_no_arg ("new working directory");
3370 dir
= tilde_expand (dir
);
3371 make_cleanup (free
, dir
);
3373 if (chdir (dir
) < 0)
3374 perror_with_name (dir
);
3376 #if defined(_WIN32) || defined(__MSDOS__)
3377 /* There's too much mess with DOSish names like "d:", "d:.",
3378 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3379 simply get the canonicalized name of the current directory. */
3380 dir
= getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3384 if (SLASH_P (dir
[len
-1]))
3386 /* Remove the trailing slash unless this is a root directory
3387 (including a drive letter on non-Unix systems). */
3388 if (!(len
== 1) /* "/" */
3389 #if defined(_WIN32) || defined(__MSDOS__)
3390 && !(!SLASH_P (*dir
) && ROOTED_P (dir
) && len
<= 3) /* "d:/" */
3396 dir
= savestring (dir
, len
);
3398 current_directory
= dir
;
3401 if (SLASH_P (current_directory
[strlen (current_directory
) - 1]))
3402 current_directory
= concat (current_directory
, dir
, NULL
);
3404 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3408 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3410 found_real_path
= 0;
3411 for (p
= current_directory
; *p
;)
3413 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3415 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3416 && (p
[3] == 0 || SLASH_P (p
[3])))
3418 if (found_real_path
)
3420 /* Search backwards for the directory just before the "/.."
3421 and obliterate it and the "/..". */
3423 while (q
!= current_directory
&& !SLASH_P (q
[-1]))
3426 if (q
== current_directory
)
3427 /* current_directory is
3428 a relative pathname ("can't happen"--leave it alone). */
3432 strcpy (q
- 1, p
+ 3);
3437 /* We are dealing with leading repetitions of "/..", for example
3438 "/../..", which is the Mach super-root. */
3443 found_real_path
= 1;
3448 forget_cached_source_info ();
3451 pwd_command ((char *) 0, 1);
3454 struct source_cleanup_lines_args
3458 char *old_pre_error
;
3459 char *old_error_pre_print
;
3463 source_cleanup_lines (args
)
3466 struct source_cleanup_lines_args
*p
=
3467 (struct source_cleanup_lines_args
*) args
;
3468 source_line_number
= p
->old_line
;
3469 source_file_name
= p
->old_file
;
3470 source_pre_error
= p
->old_pre_error
;
3471 error_pre_print
= p
->old_error_pre_print
;
3476 source_command (args
, from_tty
)
3481 struct cleanup
*old_cleanups
;
3483 struct source_cleanup_lines_args old_lines
;
3488 error ("source command requires pathname of file to source.");
3491 file
= tilde_expand (file
);
3492 old_cleanups
= make_cleanup (free
, file
);
3494 stream
= fopen (file
, FOPEN_RT
);
3498 perror_with_name (file
);
3503 make_cleanup ((make_cleanup_func
) fclose
, stream
);
3505 old_lines
.old_line
= source_line_number
;
3506 old_lines
.old_file
= source_file_name
;
3507 old_lines
.old_pre_error
= source_pre_error
;
3508 old_lines
.old_error_pre_print
= error_pre_print
;
3509 make_cleanup (source_cleanup_lines
, &old_lines
);
3510 source_line_number
= 0;
3511 source_file_name
= file
;
3512 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3513 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3514 make_cleanup (free
, source_pre_error
);
3515 /* This will get set every time we read a line. So it won't stay "" for
3517 error_pre_print
= "";
3519 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3520 if (source_error_allocated
< needed_length
)
3522 source_error_allocated
*= 2;
3523 if (source_error_allocated
< needed_length
)
3524 source_error_allocated
= needed_length
;
3525 if (source_error
== NULL
)
3526 source_error
= xmalloc (source_error_allocated
);
3528 source_error
= xrealloc (source_error
, source_error_allocated
);
3531 read_command_file (stream
);
3533 do_cleanups (old_cleanups
);
3538 echo_command (text
, from_tty
)
3546 while ((c
= *p
++) != '\0')
3550 /* \ at end of argument is used after spaces
3551 so they won't be lost. */
3555 c
= parse_escape (&p
);
3557 printf_filtered ("%c", c
);
3560 printf_filtered ("%c", c
);
3563 /* Force this output to appear now. */
3565 gdb_flush (gdb_stdout
);
3570 dont_repeat_command (ignored
, from_tty
)
3574 *line
= 0; /* Can't call dont_repeat here because we're not
3575 necessarily reading from stdin. */
3578 /* Functions to manipulate command line editing control variables. */
3580 /* Number of commands to print in each call to show_commands. */
3581 #define Hist_print 10
3583 show_commands (args
, from_tty
)
3587 /* Index for history commands. Relative to history_base. */
3590 /* Number of the history entry which we are planning to display next.
3591 Relative to history_base. */
3594 /* The first command in the history which doesn't exist (i.e. one more
3595 than the number of the last command). Relative to history_base. */
3598 extern HIST_ENTRY
*history_get
PARAMS ((int));
3600 /* Print out some of the commands from the command history. */
3601 /* First determine the length of the history list. */
3602 hist_len
= history_size
;
3603 for (offset
= 0; offset
< history_size
; offset
++)
3605 if (!history_get (history_base
+ offset
))
3614 if (args
[0] == '+' && args
[1] == '\0')
3615 /* "info editing +" should print from the stored position. */
3618 /* "info editing <exp>" should print around command number <exp>. */
3619 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
3621 /* "show commands" means print the last Hist_print commands. */
3624 num
= hist_len
- Hist_print
;
3630 /* If there are at least Hist_print commands, we want to display the last
3631 Hist_print rather than, say, the last 6. */
3632 if (hist_len
- num
< Hist_print
)
3634 num
= hist_len
- Hist_print
;
3639 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3641 printf_filtered ("%5d %s\n", history_base
+ offset
,
3642 (history_get (history_base
+ offset
))->line
);
3645 /* The next command we want to display is the next one that we haven't
3649 /* If the user repeats this command with return, it should do what
3650 "show commands +" does. This is unnecessary if arg is null,
3651 because "show commands +" is not useful after "show commands". */
3652 if (from_tty
&& args
)
3659 /* Called by do_setshow_command. */
3662 set_history_size_command (args
, from_tty
, c
)
3665 struct cmd_list_element
*c
;
3667 if (history_size
== INT_MAX
)
3668 unstifle_history ();
3669 else if (history_size
>= 0)
3670 stifle_history (history_size
);
3673 history_size
= INT_MAX
;
3674 error ("History size must be non-negative");
3680 set_history (args
, from_tty
)
3684 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3685 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3690 show_history (args
, from_tty
)
3694 cmd_show_list (showhistlist
, from_tty
, "");
3697 int info_verbose
= 0; /* Default verbose msgs off */
3699 /* Called by do_setshow_command. An elaborate joke. */
3702 set_verbose (args
, from_tty
, c
)
3705 struct cmd_list_element
*c
;
3707 char *cmdname
= "verbose";
3708 struct cmd_list_element
*showcmd
;
3710 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3714 c
->doc
= "Set verbose printing of informational messages.";
3715 showcmd
->doc
= "Show verbose printing of informational messages.";
3719 c
->doc
= "Set verbosity.";
3720 showcmd
->doc
= "Show verbosity.";
3725 float_handler (signo
)
3728 /* This message is based on ANSI C, section 4.7. Note that integer
3729 divide by zero causes this, so "float" is a misnomer. */
3730 signal (SIGFPE
, float_handler
);
3731 error ("Erroneous arithmetic operation.");
3745 enablebreaklist
= NULL
;
3750 showhistlist
= NULL
;
3751 unsethistlist
= NULL
;
3752 maintenancelist
= NULL
;
3753 maintenanceinfolist
= NULL
;
3754 maintenanceprintlist
= NULL
;
3755 setprintlist
= NULL
;
3756 showprintlist
= NULL
;
3757 setchecklist
= NULL
;
3758 showchecklist
= NULL
;
3761 /* Init the history buffer. Note that we are called after the init file(s)
3762 * have been read so that the user can change the history file via his
3763 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3764 * overrides all of this.
3772 tmpenv
= getenv ("HISTSIZE");
3774 history_size
= atoi (tmpenv
);
3775 else if (!history_size
)
3778 stifle_history (history_size
);
3780 tmpenv
= getenv ("GDBHISTFILE");
3782 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
3783 else if (!history_filename
)
3785 /* We include the current directory so that if the user changes
3786 directories the file written will be the same as the one
3789 /* No leading dots in file names are allowed on MSDOS. */
3790 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
3792 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3795 read_history (history_filename
);
3801 struct cmd_list_element
*c
;
3803 /* If we are running the asynchronous version,
3804 we initialize the prompts differently. */
3807 #ifdef DEFAULT_PROMPT
3808 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3810 gdb_prompt_string
= savestring ("(gdb) ", 6);
3815 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3816 whatever the DEFAULT_PROMPT is. */
3817 the_prompts
.top
= 0;
3819 #ifdef DEFAULT_PROMPT
3820 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3822 PROMPT (0) = savestring ("(gdb) ", 6);
3825 /* Set things up for annotation_level > 1, if the user ever decides
3827 async_annotation_suffix
= "prompt";
3828 /* Set the variable associated with the setshow prompt command. */
3829 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
3831 gdb_prompt_escape
= 0; /* default to none. */
3833 /* Set the important stuff up for command editing. */
3834 command_editing_p
= 1;
3835 history_expansion_p
= 0;
3836 write_history_p
= 0;
3838 /* Setup important stuff for command line editing. */
3839 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3840 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3841 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3842 rl_readline_name
= "gdb";
3844 /* Define the classes of commands.
3845 They will appear in the help list in the reverse of this order. */
3847 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3848 "Maintenance commands.\n\
3849 Some gdb commands are provided just for use by gdb maintainers.\n\
3850 These commands are subject to frequent change, and may not be as\n\
3851 well documented as user commands.",
3853 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3854 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3855 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3856 The commands in this class are those defined by the user.\n\
3857 Use the \"define\" command to define a command.", &cmdlist
);
3858 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3860 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3861 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3862 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3863 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3864 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3865 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3866 counting from zero for the innermost (currently executing) frame.\n\n\
3867 At any time gdb identifies one frame as the \"selected\" frame.\n\
3868 Variable lookups are done with respect to the selected frame.\n\
3869 When the program being debugged stops, gdb selects the innermost frame.\n\
3870 The commands below can be used to select other frames by number or address.",
3872 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3874 add_com ("pwd", class_files
, pwd_command
,
3875 "Print working directory. This is used for your program as well.");
3876 c
= add_cmd ("cd", class_files
, cd_command
,
3877 "Set working directory to DIR for debugger and program being debugged.\n\
3878 The change does not take effect for the program being debugged\n\
3879 until the next time it is started.", &cmdlist
);
3880 c
->completer
= filename_completer
;
3882 /* The set prompt command is different depending whether or not the
3883 async version is run. NOTE: this difference is going to
3884 disappear as we make the event loop be the default engine of
3889 (add_set_cmd ("prompt", class_support
, var_string
,
3890 (char *) &gdb_prompt_string
, "Set gdb's prompt",
3896 c
= add_set_cmd ("prompt", class_support
, var_string
,
3897 (char *) &new_async_prompt
, "Set gdb's prompt",
3899 add_show_from_set (c
, &showlist
);
3900 c
->function
.sfunc
= set_async_prompt
;
3904 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
3905 (char *) &gdb_prompt_escape
,
3906 "Set escape character for formatting of gdb's prompt",
3910 add_com ("echo", class_support
, echo_command
,
3911 "Print a constant string. Give string as argument.\n\
3912 C escape sequences may be used in the argument.\n\
3913 No newline is added at the end of the argument;\n\
3914 use \"\\n\" if you want a newline to be printed.\n\
3915 Since leading and trailing whitespace are ignored in command arguments,\n\
3916 if you want to print some you must use \"\\\" before leading whitespace\n\
3917 to be printed or after trailing whitespace.");
3918 add_com ("document", class_support
, document_command
,
3919 "Document a user-defined command.\n\
3920 Give command name as argument. Give documentation on following lines.\n\
3921 End with a line of just \"end\".");
3922 add_com ("define", class_support
, define_command
,
3923 "Define a new command name. Command name is argument.\n\
3924 Definition appears on following lines, one command per line.\n\
3925 End with a line of just \"end\".\n\
3926 Use the \"document\" command to give documentation for the new command.\n\
3927 Commands defined in this way may have up to ten arguments.");
3930 c
= add_cmd ("source", class_support
, source_command
,
3931 "Read commands from a file named FILE.\n\
3932 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3933 when gdb is started.", &cmdlist
);
3935 /* Punt file name, we can't help it easily. */
3936 c
= add_cmd ("source", class_support
, source_command
,
3937 "Read commands from a file named FILE.\n\
3938 Note that the file \".gdbinit\" is read automatically in this way\n\
3939 when gdb is started.", &cmdlist
);
3941 c
->completer
= filename_completer
;
3943 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3944 add_com ("help", class_support
, help_command
, "Print list of commands.");
3945 add_com_alias ("q", "quit", class_support
, 1);
3946 add_com_alias ("h", "help", class_support
, 1);
3948 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
3949 Primarily used inside of user-defined commands that should not be repeated when\n\
3952 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *) &info_verbose
,
3955 add_show_from_set (c
, &showlist
);
3956 c
->function
.sfunc
= set_verbose
;
3957 set_verbose (NULL
, 0, c
);
3959 /* The set editing command is different depending whether or not the
3960 async version is run. NOTE: this difference is going to disappear
3961 as we make the event loop be the default engine of gdb. */
3965 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
3966 "Set editing of command lines as they are typed.\n\
3967 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3968 Without an argument, command line editing is enabled. To edit, use\n\
3969 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
3974 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
3975 "Set editing of command lines as they are typed.\n\
3976 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3977 Without an argument, command line editing is enabled. To edit, use\n\
3978 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
3980 add_show_from_set (c
, &showlist
);
3981 c
->function
.sfunc
= set_async_editing_command
;
3984 add_prefix_cmd ("history", class_support
, set_history
,
3985 "Generic command for setting command history parameters.",
3986 &sethistlist
, "set history ", 0, &setlist
);
3987 add_prefix_cmd ("history", class_support
, show_history
,
3988 "Generic command for showing command history parameters.",
3989 &showhistlist
, "show history ", 0, &showlist
);
3992 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *) &history_expansion_p
,
3993 "Set history expansion on command input.\n\
3994 Without an argument, history expansion is enabled.", &sethistlist
),
3998 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
3999 "Set saving of the history record on exit.\n\
4000 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
4001 Without an argument, saving is enabled.", &sethistlist
),
4004 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
4005 "Set the size of the command history, \n\
4006 ie. the number of previous commands to keep a record of.", &sethistlist
);
4007 add_show_from_set (c
, &showhistlist
);
4008 c
->function
.sfunc
= set_history_size_command
;
4011 (add_set_cmd ("filename", no_class
, var_filename
, (char *) &history_filename
,
4012 "Set the filename in which to record the command history\n\
4013 (the list of previous commands of which a record is kept).", &sethistlist
),
4017 (add_set_cmd ("confirm", class_support
, var_boolean
,
4019 "Set whether to confirm potentially dangerous operations.",
4023 add_prefix_cmd ("info", class_info
, info_command
,
4024 "Generic command for showing things about the program being debugged.",
4025 &infolist
, "info ", 0, &cmdlist
);
4026 add_com_alias ("i", "info", class_info
, 1);
4028 add_com ("complete", class_obscure
, complete_command
,
4029 "List the completions for the rest of the line as a command.");
4031 add_prefix_cmd ("show", class_info
, show_command
,
4032 "Generic command for showing things about the debugger.",
4033 &showlist
, "show ", 0, &cmdlist
);
4034 /* Another way to get at the same thing. */
4035 add_info ("set", show_command
, "Show all GDB settings.");
4037 add_cmd ("commands", no_class
, show_commands
,
4038 "Show the history of commands you typed.\n\
4039 You can supply a command number to start with, or a `+' to start after\n\
4040 the previous command number shown.",
4043 add_cmd ("version", no_class
, show_version
,
4044 "Show what version of GDB this is.", &showlist
);
4046 add_com ("while", class_support
, while_command
,
4047 "Execute nested commands WHILE the conditional expression is non zero.\n\
4048 The conditional expression must follow the word `while' and must in turn be\n\
4049 followed by a new line. The nested commands must be entered one per line,\n\
4050 and should be terminated by the word `end'.");
4052 add_com ("if", class_support
, if_command
,
4053 "Execute nested commands once IF the conditional expression is non zero.\n\
4054 The conditional expression must follow the word `if' and must in turn be\n\
4055 followed by a new line. The nested commands must be entered one per line,\n\
4056 and should be terminated by the word 'else' or `end'. If an else clause\n\
4057 is used, the same rules apply to its nested commands as to the first ones.");
4059 /* If target is open when baud changes, it doesn't take effect until the
4060 next open (I think, not sure). */
4061 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
4062 var_zinteger
, (char *) &baud_rate
,
4063 "Set baud rate for remote serial I/O.\n\
4064 This value is used to set the speed of the serial port when debugging\n\
4065 using remote targets.", &setlist
),
4069 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *) &remote_debug
,
4070 "Set debugging of remote protocol.\n\
4071 When enabled, each packet sent or received with the remote target\n\
4072 is displayed.", &setlist
),
4076 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *) &remote_timeout
,
4077 "Set timeout limit to wait for target to respond.\n\
4078 This value is used to set the time limit for gdb to wait for a response\n\
4079 from the target.", &setlist
),
4082 /* The set annotate command is different depending whether or not
4083 the async version is run. NOTE: this difference is going to
4084 disappear as we make the event loop be the default engine of
4088 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4089 (char *) &annotation_level
, "Set annotation_level.\n\
4090 0 == normal; 1 == fullname (for use when running under emacs)\n\
4091 2 == output annotated suitably for use by programs that control GDB.",
4093 c
= add_show_from_set (c
, &showlist
);
4097 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4098 (char *) &annotation_level
, "Set annotation_level.\n\
4099 0 == normal; 1 == fullname (for use when running under emacs)\n\
4100 2 == output annotated suitably for use by programs that control GDB.",
4102 add_show_from_set (c
, &showlist
);
4103 c
->function
.sfunc
= set_async_annotation_level
;