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 that the disassembly flavor has changed */
449 void (*disassembly_flavor_hook
) PARAMS((char *args
, int from_tty
));
451 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
452 void (*memory_changed_hook
) PARAMS ((CORE_ADDR addr
, int len
));
454 /* Called when going to wait for the target. Usually allows the GUI to run
455 while waiting for target events. */
457 int (*target_wait_hook
) PARAMS ((int pid
, struct target_waitstatus
* status
));
459 /* Used by UI as a wrapper around command execution. May do various things
460 like enabling/disabling buttons, etc... */
462 void (*call_command_hook
) PARAMS ((struct cmd_list_element
* c
, char *cmd
,
465 /* Called after a `set' command has finished. Is only run if the
466 `set' command succeeded. */
468 void (*set_hook
) PARAMS ((struct cmd_list_element
*c
));
470 /* Called when the current thread changes. Argument is thread id. */
472 void (*context_hook
) PARAMS ((int id
));
474 /* Takes control from error (). Typically used to prevent longjmps out of the
475 middle of the GUI. Usually used in conjunction with a catch routine. */
477 NORETURN
void (*error_hook
)
478 PARAMS ((void)) ATTR_NORETURN
;
481 /* Where to go for return_to_top_level (RETURN_ERROR). */
482 SIGJMP_BUF error_return
;
483 /* Where to go for return_to_top_level (RETURN_QUIT). */
484 SIGJMP_BUF quit_return
;
486 /* Return for reason REASON. This generally gets back to the command
487 loop, but can be caught via catch_errors. */
490 return_to_top_level (reason
)
491 enum return_reason reason
;
496 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
497 I can think of a reason why that is vital, though). */
498 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
500 disable_current_display ();
501 do_cleanups (ALL_CLEANUPS
);
502 if (async_p
&& target_has_async
)
503 do_exec_cleanups (ALL_CLEANUPS
);
505 if (annotation_level
> 1)
516 (NORETURN
void) SIGLONGJMP
517 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
520 /* Call FUNC with arg ARGS, catching any errors. If there is no
521 error, return the value returned by FUNC. If there is an error,
522 print ERRSTRING, print the specific error message, then return
525 Must not be called with immediate_quit in effect (bad things might
526 happen, say we got a signal in the middle of a memcpy to quit_return).
527 This is an OK restriction; with very few exceptions immediate_quit can
528 be replaced by judicious use of QUIT.
530 MASK specifies what to catch; it is normally set to
531 RETURN_MASK_ALL, if for no other reason than that the code which
532 calls catch_errors might not be set up to deal with a quit which
533 isn't caught. But if the code can deal with it, it generally
534 should be RETURN_MASK_ERROR, unless for some reason it is more
535 useful to abort only the portion of the operation inside the
536 catch_errors. Note that quit should return to the command line
537 fairly quickly, even if some further processing is being done. */
540 catch_errors (func
, args
, errstring
, mask
)
541 catch_errors_ftype
*func
;
546 SIGJMP_BUF saved_error
;
547 SIGJMP_BUF saved_quit
;
550 struct cleanup
*saved_cleanup_chain
;
551 char *saved_error_pre_print
;
552 char *saved_quit_pre_print
;
554 saved_cleanup_chain
= save_cleanups ();
555 saved_error_pre_print
= error_pre_print
;
556 saved_quit_pre_print
= quit_pre_print
;
558 if (mask
& RETURN_MASK_ERROR
)
560 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (SIGJMP_BUF
));
561 error_pre_print
= errstring
;
563 if (mask
& RETURN_MASK_QUIT
)
565 memcpy (saved_quit
, quit_return
, sizeof (SIGJMP_BUF
));
566 quit_pre_print
= errstring
;
569 if (SIGSETJMP (tmp_jmp
) == 0)
571 if (mask
& RETURN_MASK_ERROR
)
572 memcpy (error_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
573 if (mask
& RETURN_MASK_QUIT
)
574 memcpy (quit_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
575 val
= (*func
) (args
);
580 restore_cleanups (saved_cleanup_chain
);
582 if (mask
& RETURN_MASK_ERROR
)
584 memcpy (error_return
, saved_error
, sizeof (SIGJMP_BUF
));
585 error_pre_print
= saved_error_pre_print
;
587 if (mask
& RETURN_MASK_QUIT
)
589 memcpy (quit_return
, saved_quit
, sizeof (SIGJMP_BUF
));
590 quit_pre_print
= saved_quit_pre_print
;
595 /* Handler for SIGHUP. */
602 catch_errors (quit_cover
, NULL
,
603 "Could not kill the program being debugged", RETURN_MASK_ALL
);
604 signal (SIGHUP
, SIG_DFL
);
605 kill (getpid (), SIGHUP
);
608 /* Just a little helper function for disconnect(). */
610 /* NOTE 1999-04-29: This function will be static again, once we modify
611 gdb to use the event loop as the default command loop and we merge
612 event-top.c into this file, top.c */
617 caution
= 0; /* Throw caution to the wind -- we're exiting.
618 This prevents asking the user dumb questions. */
619 quit_command ((char *) 0, 0);
622 #endif /* defined SIGHUP */
624 /* Line number we are currently in in a file which is being sourced. */
625 /* NOTE 1999-04-29: This variable will be static again, once we modify
626 gdb to use the event loop as the default command loop and we merge
627 event-top.c into this file, top.c */
628 /* static */ int source_line_number
;
630 /* Name of the file we are sourcing. */
631 /* NOTE 1999-04-29: This variable will be static again, once we modify
632 gdb to use the event loop as the default command loop and we merge
633 event-top.c into this file, top.c */
634 /* static */ char *source_file_name
;
636 /* Buffer containing the error_pre_print used by the source stuff.
638 /* NOTE 1999-04-29: This variable will be static again, once we modify
639 gdb to use the event loop as the default command loop and we merge
640 event-top.c into this file, top.c */
641 /* static */ char *source_error
;
642 static int source_error_allocated
;
644 /* Something to glom on to the start of error_pre_print if source_file_name
646 /* NOTE 1999-04-29: This variable will be static again, once we modify
647 gdb to use the event loop as the default command loop and we merge
648 event-top.c into this file, top.c */
649 /* static */ char *source_pre_error
;
651 /* Clean up on error during a "source" command (or execution of a
652 user-defined command). */
655 source_cleanup (stream
)
658 /* Restore the previous input stream. */
662 /* Read commands from STREAM. */
664 read_command_file (stream
)
667 struct cleanup
*cleanups
;
669 cleanups
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
672 do_cleanups (cleanups
);
675 extern void init_proc
PARAMS ((void));
677 void (*pre_init_ui_hook
) PARAMS ((void));
683 if (pre_init_ui_hook
)
686 /* Run the init function of each source file */
688 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
689 current_directory
= gdb_dirbuf
;
692 /* Make sure we return to the original directory upon exit, come
693 what may, since the OS doesn't do that for us. */
694 make_final_cleanup ((make_cleanup_func
) chdir
, strsave (current_directory
));
697 init_cmd_lists (); /* This needs to be done first */
698 initialize_targets (); /* Setup target_terminal macros for utils.c */
699 initialize_utils (); /* Make errors and warnings possible */
700 initialize_all_files ();
701 init_main (); /* But that omits this file! Do it now */
703 /* The signal handling mechanism is different depending whether or
704 not the async version is run. NOTE: in the future we plan to make
705 the event loop be the default engine of gdb, and this difference
708 async_init_signals ();
712 /* We need a default language for parsing expressions, so simple things like
713 "set width 0" won't fail if no language is explicitly set in a config file
714 or implicitly set by reading an executable during startup. */
715 set_language (language_c
);
716 expected_language
= current_language
; /* don't warn about the change. */
718 /* All the interpreters should have had a look at things by now.
719 Initialize the selected interpreter. */
721 init_ui_hook (argv0
);
724 /* Allocate, initialize a new command line structure for one of the
725 control commands (if/while). */
727 static struct command_line
*
728 build_command_line (type
, args
)
729 enum command_control_type type
;
732 struct command_line
*cmd
;
735 error ("if/while commands require arguments.\n");
737 cmd
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
739 cmd
->control_type
= type
;
743 = (struct command_line
**) xmalloc (sizeof (struct command_line
*)
745 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
746 cmd
->line
= savestring (args
, strlen (args
));
750 /* Build and return a new command structure for the control commands
751 such as "if" and "while". */
753 static struct command_line
*
754 get_command_line (type
, arg
)
755 enum command_control_type type
;
758 struct command_line
*cmd
;
759 struct cleanup
*old_chain
= NULL
;
761 /* Allocate and build a new command line structure. */
762 cmd
= build_command_line (type
, arg
);
764 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
, &cmd
);
766 /* Read in the body of this command. */
767 if (recurse_read_control_structure (cmd
) == invalid_control
)
769 warning ("error reading in control structure\n");
770 do_cleanups (old_chain
);
774 discard_cleanups (old_chain
);
778 /* Recursively print a command (including full control structures). */
780 print_command_line (cmd
, depth
, stream
)
781 struct command_line
*cmd
;
789 for (i
= 0; i
< depth
; i
++)
790 fputs_filtered (" ", stream
);
793 /* A simple command, print it and return. */
794 if (cmd
->control_type
== simple_control
)
796 fputs_filtered (cmd
->line
, stream
);
797 fputs_filtered ("\n", stream
);
801 /* loop_continue to jump to the start of a while loop, print it
803 if (cmd
->control_type
== continue_control
)
805 fputs_filtered ("loop_continue\n", stream
);
809 /* loop_break to break out of a while loop, print it and return. */
810 if (cmd
->control_type
== break_control
)
812 fputs_filtered ("loop_break\n", stream
);
816 /* A while command. Recursively print its subcommands before returning. */
817 if (cmd
->control_type
== while_control
)
819 struct command_line
*list
;
820 fputs_filtered ("while ", stream
);
821 fputs_filtered (cmd
->line
, stream
);
822 fputs_filtered ("\n", stream
);
823 list
= *cmd
->body_list
;
826 print_command_line (list
, depth
+ 1, stream
);
831 /* An if command. Recursively print both arms before returning. */
832 if (cmd
->control_type
== if_control
)
834 fputs_filtered ("if ", stream
);
835 fputs_filtered (cmd
->line
, stream
);
836 fputs_filtered ("\n", stream
);
838 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
840 /* Show the false arm if it exists. */
841 if (cmd
->body_count
== 2)
845 for (i
= 0; i
< depth
; i
++)
846 fputs_filtered (" ", stream
);
848 fputs_filtered ("else\n", stream
);
849 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
853 for (i
= 0; i
< depth
; i
++)
854 fputs_filtered (" ", stream
);
856 fputs_filtered ("end\n", stream
);
860 /* Execute the command in CMD. */
862 enum command_control_type
863 execute_control_command (cmd
)
864 struct command_line
*cmd
;
866 struct expression
*expr
;
867 struct command_line
*current
;
868 struct cleanup
*old_chain
= 0;
872 enum command_control_type ret
;
875 switch (cmd
->control_type
)
878 /* A simple command, execute it and return. */
879 new_line
= insert_args (cmd
->line
);
881 return invalid_control
;
882 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
884 execute_command (new_line
, 0);
885 ret
= cmd
->control_type
;
888 case continue_control
:
890 /* Return for "continue", and "break" so we can either
891 continue the loop at the top, or break out. */
892 ret
= cmd
->control_type
;
897 /* Parse the loop control expression for the while statement. */
898 new_line
= insert_args (cmd
->line
);
900 return invalid_control
;
901 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
903 expr
= parse_expression (new_line
);
904 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
906 ret
= simple_control
;
909 /* Keep iterating so long as the expression is true. */
916 /* Evaluate the expression. */
917 val_mark
= value_mark ();
918 val
= evaluate_expression (expr
);
919 cond_result
= value_true (val
);
920 value_free_to_mark (val_mark
);
922 /* If the value is false, then break out of the loop. */
926 /* Execute the body of the while statement. */
927 current
= *cmd
->body_list
;
930 ret
= execute_control_command (current
);
932 /* If we got an error, or a "break" command, then stop
934 if (ret
== invalid_control
|| ret
== break_control
)
940 /* If we got a "continue" command, then restart the loop
942 if (ret
== continue_control
)
945 /* Get the next statement. */
946 current
= current
->next
;
950 /* Reset RET so that we don't recurse the break all the way down. */
951 if (ret
== break_control
)
952 ret
= simple_control
;
959 new_line
= insert_args (cmd
->line
);
961 return invalid_control
;
962 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
964 /* Parse the conditional for the if statement. */
965 expr
= parse_expression (new_line
);
966 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
969 ret
= simple_control
;
971 /* Evaluate the conditional. */
972 val_mark
= value_mark ();
973 val
= evaluate_expression (expr
);
975 /* Choose which arm to take commands from based on the value of the
976 conditional expression. */
977 if (value_true (val
))
978 current
= *cmd
->body_list
;
979 else if (cmd
->body_count
== 2)
980 current
= *(cmd
->body_list
+ 1);
981 value_free_to_mark (val_mark
);
983 /* Execute commands in the given arm. */
986 ret
= execute_control_command (current
);
988 /* If we got an error, get out. */
989 if (ret
!= simple_control
)
992 /* Get the next statement in the body. */
993 current
= current
->next
;
1000 warning ("Invalid control type in command structure.");
1001 return invalid_control
;
1005 do_cleanups (old_chain
);
1010 /* "while" command support. Executes a body of statements while the
1011 loop condition is nonzero. */
1014 while_command (arg
, from_tty
)
1018 struct command_line
*command
= NULL
;
1021 command
= get_command_line (while_control
, arg
);
1023 if (command
== NULL
)
1026 execute_control_command (command
);
1027 free_command_lines (&command
);
1030 /* "if" command support. Execute either the true or false arm depending
1031 on the value of the if conditional. */
1034 if_command (arg
, from_tty
)
1038 struct command_line
*command
= NULL
;
1041 command
= get_command_line (if_control
, arg
);
1043 if (command
== NULL
)
1046 execute_control_command (command
);
1047 free_command_lines (&command
);
1054 struct user_args
*oargs
= user_args
;
1056 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1058 user_args
= user_args
->next
;
1062 /* Bind the incomming arguments for a user defined command to
1063 $arg0, $arg1 ... $argMAXUSERARGS. */
1065 static struct cleanup
*
1069 struct user_args
*args
;
1070 struct cleanup
*old_chain
;
1071 unsigned int arg_count
= 0;
1073 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
1074 memset (args
, 0, sizeof (struct user_args
));
1076 args
->next
= user_args
;
1079 old_chain
= make_cleanup ((make_cleanup_func
) arg_cleanup
, 0);
1091 if (arg_count
>= MAXUSERARGS
)
1093 error ("user defined function may only have %d arguments.\n",
1098 /* Strip whitespace. */
1099 while (*p
== ' ' || *p
== '\t')
1102 /* P now points to an argument. */
1104 user_args
->a
[arg_count
].arg
= p
;
1106 /* Get to the end of this argument. */
1109 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1115 else if (*p
== '\\')
1138 user_args
->a
[arg_count
].len
= p
- start_arg
;
1145 /* Given character string P, return a point to the first argument ($arg),
1146 or NULL if P contains no arguments. */
1152 while ((p
= strchr (p
, '$')))
1154 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1161 /* Insert the user defined arguments stored in user_arg into the $arg
1162 arguments found in line, with the updated copy being placed into nline. */
1168 char *p
, *save_line
, *new_line
;
1171 /* First we need to know how much memory to allocate for the new line. */
1174 while ((p
= locate_arg (line
)))
1179 if (i
>= user_args
->count
)
1181 error ("Missing argument %d in user function.\n", i
);
1184 len
+= user_args
->a
[i
].len
;
1188 /* Don't forget the tail. */
1189 len
+= strlen (line
);
1191 /* Allocate space for the new line and fill it in. */
1192 new_line
= (char *) xmalloc (len
+ 1);
1193 if (new_line
== NULL
)
1196 /* Restore pointer to beginning of old line. */
1199 /* Save pointer to beginning of new line. */
1200 save_line
= new_line
;
1202 while ((p
= locate_arg (line
)))
1206 memcpy (new_line
, line
, p
- line
);
1207 new_line
+= p
- line
;
1210 len
= user_args
->a
[i
].len
;
1213 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1218 /* Don't forget the tail. */
1219 strcpy (new_line
, line
);
1221 /* Return a pointer to the beginning of the new line. */
1226 execute_user_command (c
, args
)
1227 struct cmd_list_element
*c
;
1230 register struct command_line
*cmdlines
;
1231 struct cleanup
*old_chain
;
1232 enum command_control_type ret
;
1234 old_chain
= setup_user_args (args
);
1236 cmdlines
= c
->user_commands
;
1241 /* Set the instream to 0, indicating execution of a
1242 user-defined function. */
1243 old_chain
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
1244 instream
= (FILE *) 0;
1247 ret
= execute_control_command (cmdlines
);
1248 if (ret
!= simple_control
&& ret
!= break_control
)
1250 warning ("Error in control structure.\n");
1253 cmdlines
= cmdlines
->next
;
1255 do_cleanups (old_chain
);
1258 /* Execute the line P as a command.
1259 Pass FROM_TTY as second argument to the defining function. */
1262 execute_command (p
, from_tty
)
1266 register struct cmd_list_element
*c
;
1267 register enum language flang
;
1268 static int warned
= 0;
1269 /* FIXME: These should really be in an appropriate header file */
1270 extern void serial_log_command
PARAMS ((const char *));
1274 /* Force cleanup of any alloca areas if using C alloca instead of
1275 a builtin alloca. */
1278 /* This can happen when command_line_input hits end of file. */
1282 serial_log_command (p
);
1284 while (*p
== ' ' || *p
== '\t')
1290 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1292 /* If the target is running, we allow only a limited set of
1294 if (async_p
&& target_has_async
&& target_executing
)
1295 if (!strcmp (c
->name
, "help")
1296 && !strcmp (c
->name
, "pwd")
1297 && !strcmp (c
->name
, "show")
1298 && !strcmp (c
->name
, "stop"))
1299 error ("Cannot execute this command while the target is running.");
1301 /* Pass null arg rather than an empty one. */
1304 /* Clear off trailing whitespace, except for set and complete command. */
1305 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1307 p
= arg
+ strlen (arg
) - 1;
1308 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1313 /* If this command has been hooked, run the hook first. */
1315 execute_user_command (c
->hook
, (char *) 0);
1317 if (c
->class == class_user
)
1318 execute_user_command (c
, arg
);
1319 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1320 do_setshow_command (arg
, from_tty
& caution
, c
);
1321 else if (c
->function
.cfunc
== NO_FUNCTION
)
1322 error ("That is not a command, just a help topic.");
1323 else if (call_command_hook
)
1324 call_command_hook (c
, arg
, from_tty
& caution
);
1326 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1329 /* Tell the user if the language has changed (except first time). */
1330 if (current_language
!= expected_language
)
1332 if (language_mode
== language_mode_auto
)
1334 language_info (1); /* Print what changed. */
1339 /* Warn the user if the working language does not match the
1340 language of the current frame. Only warn the user if we are
1341 actually running the program, i.e. there is a stack. */
1342 /* FIXME: This should be cacheing the frame and only running when
1343 the frame changes. */
1345 if (target_has_stack
)
1347 flang
= get_frame_language ();
1349 && flang
!= language_unknown
1350 && flang
!= current_language
->la_language
)
1352 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1359 /* NOTE 1999-04-29: This function will be static again, once we modify
1360 gdb to use the event loop as the default command loop and we merge
1361 event-top.c into this file, top.c */
1363 command_loop_marker (foo
)
1368 /* Read commands from `instream' and execute them
1369 until end of file or error reading instream. */
1374 struct cleanup
*old_chain
;
1376 int stdin_is_tty
= ISATTY (stdin
);
1377 long time_at_cmd_start
;
1379 long space_at_cmd_start
= 0;
1381 extern int display_time
;
1382 extern int display_space
;
1384 while (instream
&& !feof (instream
))
1387 extern int insert_mode
;
1389 if (window_hook
&& instream
== stdin
)
1390 (*window_hook
) (instream
, get_prompt ());
1393 if (instream
== stdin
&& stdin_is_tty
)
1394 reinitialize_more_filter ();
1395 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1398 /* A bit of paranoia: I want to make sure the "insert_mode" global
1399 * is clear except when it is being used for command-line editing
1400 * (see tuiIO.c, utils.c); otherwise normal output will
1401 * get messed up in the TUI. So clear it before/after
1402 * the command-line-input call. - RT
1406 /* Get a command-line. This calls the readline package. */
1407 command
= command_line_input (instream
== stdin
?
1408 get_prompt () : (char *) NULL
,
1409 instream
== stdin
, "prompt");
1416 time_at_cmd_start
= get_run_time ();
1421 extern char **environ
;
1422 char *lim
= (char *) sbrk (0);
1424 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1428 execute_command (command
, instream
== stdin
);
1429 /* Do any commands attached to breakpoint we stopped at. */
1430 bpstat_do_actions (&stop_bpstat
);
1431 do_cleanups (old_chain
);
1435 long cmd_time
= get_run_time () - time_at_cmd_start
;
1437 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1438 cmd_time
/ 1000000, cmd_time
% 1000000);
1444 extern char **environ
;
1445 char *lim
= (char *) sbrk (0);
1446 long space_now
= lim
- (char *) &environ
;
1447 long space_diff
= space_now
- space_at_cmd_start
;
1449 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1451 (space_diff
>= 0 ? '+' : '-'),
1459 /* Commands call this if they do not want to be repeated by null lines. */
1467 /* If we aren't reading from standard input, we are saving the last
1468 thing read from stdin in line and don't want to delete it. Null lines
1469 won't repeat here in any case. */
1470 if (instream
== stdin
)
1474 /* Read a line from the stream "instream" without command line editing.
1476 It prints PROMPT_ARG once at the start.
1477 Action is compatible with "readline", e.g. space for the result is
1478 malloc'd and should be freed by the caller.
1480 A NULL return means end of file. */
1482 gdb_readline (prompt_arg
)
1487 int input_index
= 0;
1488 int result_size
= 80;
1492 /* Don't use a _filtered function here. It causes the assumed
1493 character position to be off, since the newline we read from
1494 the user is not accounted for. */
1495 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1497 /* Move to a new line so the entered line doesn't have a prompt
1498 on the front of it. */
1499 fputs_unfiltered ("\n", gdb_stdout
);
1501 gdb_flush (gdb_stdout
);
1504 result
= (char *) xmalloc (result_size
);
1508 /* Read from stdin if we are executing a user defined command.
1509 This is the right thing for prompt_for_continue, at least. */
1510 c
= fgetc (instream
? instream
: stdin
);
1514 if (input_index
> 0)
1515 /* The last line does not end with a newline. Return it, and
1516 if we are called again fgetc will still return EOF and
1517 we'll return NULL then. */
1524 #ifndef CRLF_SOURCE_FILES
1528 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1534 result
[input_index
++] = c
;
1535 while (input_index
>= result_size
)
1538 result
= (char *) xrealloc (result
, result_size
);
1542 result
[input_index
++] = '\0';
1546 /* Variables which control command line editing and history
1547 substitution. These variables are given default values at the end
1549 static int command_editing_p
;
1550 /* NOTE 1999-04-29: This variable will be static again, once we modify
1551 gdb to use the event loop as the default command loop and we merge
1552 event-top.c into this file, top.c */
1553 /* static */ int history_expansion_p
;
1554 static int write_history_p
;
1555 static int history_size
;
1556 static char *history_filename
;
1558 /* readline uses the word breaks for two things:
1559 (1) In figuring out where to point the TEXT parameter to the
1560 rl_completion_entry_function. Since we don't use TEXT for much,
1561 it doesn't matter a lot what the word breaks are for this purpose, but
1562 it does affect how much stuff M-? lists.
1563 (2) If one of the matches contains a word break character, readline
1564 will quote it. That's why we switch between
1565 gdb_completer_word_break_characters and
1566 gdb_completer_command_word_break_characters. I'm not sure when
1567 we need this behavior (perhaps for funky characters in C++ symbols?). */
1569 /* Variables which are necessary for fancy command line editing. */
1570 char *gdb_completer_word_break_characters
=
1571 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1573 /* When completing on command names, we remove '-' from the list of
1574 word break characters, since we use it in command names. If the
1575 readline library sees one in any of the current completion strings,
1576 it thinks that the string needs to be quoted and automatically supplies
1578 char *gdb_completer_command_word_break_characters
=
1579 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1581 /* Characters that can be used to quote completion strings. Note that we
1582 can't include '"' because the gdb C parser treats such quoted sequences
1584 char *gdb_completer_quote_characters
=
1587 /* Functions that are used as part of the fancy command line editing. */
1589 /* This can be used for functions which don't want to complete on symbols
1590 but don't want to complete on anything else either. */
1593 noop_completer (text
, prefix
)
1600 /* Complete on filenames. */
1602 filename_completer (text
, word
)
1606 /* From readline. */
1607 extern char *filename_completion_function
PARAMS ((char *, int));
1608 int subsequent_name
;
1610 int return_val_used
;
1611 int return_val_alloced
;
1613 return_val_used
= 0;
1614 /* Small for testing. */
1615 return_val_alloced
= 1;
1616 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1618 subsequent_name
= 0;
1622 p
= filename_completion_function (text
, subsequent_name
);
1623 if (return_val_used
>= return_val_alloced
)
1625 return_val_alloced
*= 2;
1627 (char **) xrealloc (return_val
,
1628 return_val_alloced
* sizeof (char *));
1632 return_val
[return_val_used
++] = p
;
1635 /* Like emacs, don't complete on old versions. Especially useful
1636 in the "source" command. */
1637 if (p
[strlen (p
) - 1] == '~')
1643 /* Return exactly p. */
1644 return_val
[return_val_used
++] = p
;
1645 else if (word
> text
)
1647 /* Return some portion of p. */
1648 q
= xmalloc (strlen (p
) + 5);
1649 strcpy (q
, p
+ (word
- text
));
1650 return_val
[return_val_used
++] = q
;
1655 /* Return some of TEXT plus p. */
1656 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1657 strncpy (q
, word
, text
- word
);
1658 q
[text
- word
] = '\0';
1660 return_val
[return_val_used
++] = q
;
1664 subsequent_name
= 1;
1667 /* There is no way to do this just long enough to affect quote inserting
1668 without also affecting the next completion. This should be fixed in
1670 /* Insure that readline does the right thing
1671 with respect to inserting quotes. */
1672 rl_completer_word_break_characters
= "";
1677 /* Here are some useful test cases for completion. FIXME: These should
1678 be put in the test suite. They should be tested with both M-? and TAB.
1680 "show output-" "radix"
1681 "show output" "-radix"
1682 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1683 "p " ambiguous (all symbols)
1684 "info t foo" no completions
1685 "info t " no completions
1686 "info t" ambiguous ("info target", "info terminal", etc.)
1687 "info ajksdlfk" no completions
1688 "info ajksdlfk " no completions
1690 "info " ambiguous (all info commands)
1691 "p \"a" no completions (string constant)
1692 "p 'a" ambiguous (all symbols starting with a)
1693 "p b-a" ambiguous (all symbols starting with a)
1694 "p b-" ambiguous (all symbols)
1695 "file Make" "file" (word break hard to screw up here)
1696 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1699 /* Generate completions one by one for the completer. Each time we are
1700 called return another potential completion to the caller.
1701 line_completion just completes on commands or passes the buck to the
1702 command's completer function, the stuff specific to symbol completion
1703 is in make_symbol_completion_list.
1705 TEXT is the caller's idea of the "word" we are looking at.
1707 MATCHES is the number of matches that have currently been collected from
1708 calling this completion function. When zero, then we need to initialize,
1709 otherwise the initialization has already taken place and we can just
1710 return the next potential completion string.
1712 LINE_BUFFER is available to be looked at; it contains the entire text
1713 of the line. POINT is the offset in that line of the cursor. You
1714 should pretend that the line ends at POINT.
1716 Returns NULL if there are no more completions, else a pointer to a string
1717 which is a possible completion, it is the caller's responsibility to
1721 line_completion_function (text
, matches
, line_buffer
, point
)
1727 static char **list
= (char **) NULL
; /* Cache of completions */
1728 static int index
; /* Next cached completion */
1729 char *output
= NULL
;
1730 char *tmp_command
, *p
;
1731 /* Pointer within tmp_command which corresponds to text. */
1733 struct cmd_list_element
*c
, *result_list
;
1737 /* The caller is beginning to accumulate a new set of completions, so
1738 we need to find all of them now, and cache them for returning one at
1739 a time on future calls. */
1743 /* Free the storage used by LIST, but not by the strings inside.
1744 This is because rl_complete_internal () frees the strings. */
1750 /* Choose the default set of word break characters to break completions.
1751 If we later find out that we are doing completions on command strings
1752 (as opposed to strings supplied by the individual command completer
1753 functions, which can be any string) then we will switch to the
1754 special word break set for command strings, which leaves out the
1755 '-' character used in some commands. */
1757 rl_completer_word_break_characters
=
1758 gdb_completer_word_break_characters
;
1760 /* Decide whether to complete on a list of gdb commands or on symbols. */
1761 tmp_command
= (char *) alloca (point
+ 1);
1764 strncpy (tmp_command
, line_buffer
, point
);
1765 tmp_command
[point
] = '\0';
1766 /* Since text always contains some number of characters leading up
1767 to point, we can find the equivalent position in tmp_command
1768 by subtracting that many characters from the end of tmp_command. */
1769 word
= tmp_command
+ point
- strlen (text
);
1773 /* An empty line we want to consider ambiguous; that is, it
1774 could be any command. */
1775 c
= (struct cmd_list_element
*) -1;
1780 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1783 /* Move p up to the next interesting thing. */
1784 while (*p
== ' ' || *p
== '\t')
1791 /* It is an unrecognized command. So there are no
1792 possible completions. */
1795 else if (c
== (struct cmd_list_element
*) -1)
1799 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1800 doesn't advance over that thing itself. Do so now. */
1802 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1804 if (q
!= tmp_command
+ point
)
1806 /* There is something beyond the ambiguous
1807 command, so there are no possible completions. For
1808 example, "info t " or "info t foo" does not complete
1809 to anything, because "info t" can be "info target" or
1815 /* We're trying to complete on the command which was ambiguous.
1816 This we can deal with. */
1819 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1824 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1826 /* Insure that readline does the right thing with respect to
1827 inserting quotes. */
1828 rl_completer_word_break_characters
=
1829 gdb_completer_command_word_break_characters
;
1834 /* We've recognized a full command. */
1836 if (p
== tmp_command
+ point
)
1838 /* There is no non-whitespace in the line beyond the command. */
1840 if (p
[-1] == ' ' || p
[-1] == '\t')
1842 /* The command is followed by whitespace; we need to complete
1843 on whatever comes after command. */
1846 /* It is a prefix command; what comes after it is
1847 a subcommand (e.g. "info "). */
1848 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1850 /* Insure that readline does the right thing
1851 with respect to inserting quotes. */
1852 rl_completer_word_break_characters
=
1853 gdb_completer_command_word_break_characters
;
1857 list
= complete_on_enum (c
->enums
, p
, word
);
1858 rl_completer_word_break_characters
=
1859 gdb_completer_command_word_break_characters
;
1863 /* It is a normal command; what comes after it is
1864 completed by the command's completer function. */
1865 list
= (*c
->completer
) (p
, word
);
1870 /* The command is not followed by whitespace; we need to
1871 complete on the command itself. e.g. "p" which is a
1872 command itself but also can complete to "print", "ptype"
1876 /* Find the command we are completing on. */
1878 while (q
> tmp_command
)
1880 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1886 list
= complete_on_cmdlist (result_list
, q
, word
);
1888 /* Insure that readline does the right thing
1889 with respect to inserting quotes. */
1890 rl_completer_word_break_characters
=
1891 gdb_completer_command_word_break_characters
;
1896 /* There is non-whitespace beyond the command. */
1898 if (c
->prefixlist
&& !c
->allow_unknown
)
1900 /* It is an unrecognized subcommand of a prefix command,
1901 e.g. "info adsfkdj". */
1906 list
= complete_on_enum (c
->enums
, p
, word
);
1910 /* It is a normal command. */
1911 list
= (*c
->completer
) (p
, word
);
1917 /* If we found a list of potential completions during initialization then
1918 dole them out one at a time. The vector of completions is NULL
1919 terminated, so after returning the last one, return NULL (and continue
1920 to do so) each time we are called after that, until a new list is
1925 output
= list
[index
];
1933 /* Can't do this because readline hasn't yet checked the word breaks
1934 for figuring out whether to insert a quote. */
1936 /* Make sure the word break characters are set back to normal for the
1937 next time that readline tries to complete something. */
1938 rl_completer_word_break_characters
=
1939 gdb_completer_word_break_characters
;
1945 /* Line completion interface function for readline. */
1948 readline_line_completion_function (text
, matches
)
1952 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
1955 /* Skip over a possibly quoted word (as defined by the quote characters
1956 and word break characters the completer uses). Returns pointer to the
1957 location after the "word". */
1963 char quote_char
= '\0';
1966 for (scan
= str
; *scan
!= '\0'; scan
++)
1968 if (quote_char
!= '\0')
1970 /* Ignore everything until the matching close quote char */
1971 if (*scan
== quote_char
)
1973 /* Found matching close quote. */
1978 else if (strchr (gdb_completer_quote_characters
, *scan
))
1980 /* Found start of a quoted string. */
1983 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1997 #if STOP_SIGNAL == SIGTSTP
1998 signal (SIGTSTP
, SIG_DFL
);
2000 kill (getpid (), SIGTSTP
);
2001 signal (SIGTSTP
, stop_sig
);
2003 signal (STOP_SIGNAL
, stop_sig
);
2005 printf_unfiltered ("%s", get_prompt ());
2006 gdb_flush (gdb_stdout
);
2008 /* Forget about any previous command -- null line now will do nothing. */
2011 #endif /* STOP_SIGNAL */
2013 /* Initialize signal handlers. */
2018 /* Under System V the default disposition of a signal is reinstated after
2019 the signal is caught and delivered to an application process. On such
2020 systems one must restore the replacement signal handler if one wishes
2021 to continue handling the signal in one's program. On BSD systems this
2022 is not needed but it is harmless, and it simplifies the code to just do
2023 it unconditionally. */
2024 signal (signo
, do_nothing
);
2030 signal (SIGINT
, request_quit
);
2032 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2033 to the inferior and breakpoints will be ignored. */
2035 signal (SIGTRAP
, SIG_DFL
);
2038 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2039 passed to the inferior, which we don't want. It would be
2040 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2041 on BSD4.3 systems using vfork, that can affect the
2042 GDB process as well as the inferior (the signal handling tables
2043 might be in memory, shared between the two). Since we establish
2044 a handler for SIGQUIT, when we call exec it will set the signal
2045 to SIG_DFL for us. */
2046 signal (SIGQUIT
, do_nothing
);
2048 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
2049 signal (SIGHUP
, disconnect
);
2051 signal (SIGFPE
, float_handler
);
2053 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2054 signal (SIGWINCH
, SIGWINCH_HANDLER
);
2058 /* Read one line from the command input stream `instream'
2059 into the local static buffer `linebuffer' (whose current length
2061 The buffer is made bigger as necessary.
2062 Returns the address of the start of the line.
2064 NULL is returned for end of file.
2066 *If* the instream == stdin & stdin is a terminal, the line read
2067 is copied into the file line saver (global var char *line,
2068 length linesize) so that it can be duplicated.
2070 This routine either uses fancy command line editing or
2071 simple input as the user has requested. */
2074 command_line_input (prompt_arg
, repeat
, annotation_suffix
)
2077 char *annotation_suffix
;
2079 static char *linebuffer
= 0;
2080 static unsigned linelength
= 0;
2084 char *local_prompt
= prompt_arg
;
2088 /* The annotation suffix must be non-NULL. */
2089 if (annotation_suffix
== NULL
)
2090 annotation_suffix
= "";
2092 if (annotation_level
> 1 && instream
== stdin
)
2094 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
2095 + strlen (annotation_suffix
) + 40);
2096 if (prompt_arg
== NULL
)
2097 local_prompt
[0] = '\0';
2099 strcpy (local_prompt
, prompt_arg
);
2100 strcat (local_prompt
, "\n\032\032");
2101 strcat (local_prompt
, annotation_suffix
);
2102 strcat (local_prompt
, "\n");
2105 if (linebuffer
== 0)
2108 linebuffer
= (char *) xmalloc (linelength
);
2113 /* Control-C quits instantly if typed while in this loop
2114 since it should not wait until the user types a newline. */
2120 signal (STOP_SIGNAL
, handle_stop_sig
);
2122 signal (STOP_SIGNAL
, stop_sig
);
2128 /* Make sure that all output has been output. Some machines may let
2129 you get away with leaving out some of the gdb_flush, but not all. */
2131 gdb_flush (gdb_stdout
);
2132 gdb_flush (gdb_stderr
);
2134 if (source_file_name
!= NULL
)
2136 ++source_line_number
;
2137 sprintf (source_error
,
2138 "%s%s:%d: Error in sourced command file:\n",
2141 source_line_number
);
2142 error_pre_print
= source_error
;
2145 if (annotation_level
> 1 && instream
== stdin
)
2147 printf_unfiltered ("\n\032\032pre-");
2148 printf_unfiltered (annotation_suffix
);
2149 printf_unfiltered ("\n");
2152 /* Don't use fancy stuff if not talking to stdin. */
2153 if (readline_hook
&& instream
== NULL
)
2155 rl
= (*readline_hook
) (local_prompt
);
2157 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2159 rl
= readline (local_prompt
);
2163 rl
= gdb_readline (local_prompt
);
2166 if (annotation_level
> 1 && instream
== stdin
)
2168 printf_unfiltered ("\n\032\032post-");
2169 printf_unfiltered (annotation_suffix
);
2170 printf_unfiltered ("\n");
2173 if (!rl
|| rl
== (char *) EOF
)
2178 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
2180 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
2181 nline
= (char *) xrealloc (linebuffer
, linelength
);
2182 p
+= nline
- linebuffer
;
2186 /* Copy line. Don't copy null at end. (Leaves line alone
2187 if this was just a newline) */
2191 free (rl
); /* Allocated in readline. */
2193 if (p
== linebuffer
|| *(p
- 1) != '\\')
2196 p
--; /* Put on top of '\'. */
2197 local_prompt
= (char *) 0;
2202 signal (STOP_SIGNAL
, SIG_DFL
);
2209 #define SERVER_COMMAND_LENGTH 7
2211 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2212 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2215 /* Note that we don't set `line'. Between this and the check in
2216 dont_repeat, this insures that repeating will still do the
2219 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2222 /* Do history expansion if that is wished. */
2223 if (history_expansion_p
&& instream
== stdin
2224 && ISATTY (instream
))
2226 char *history_value
;
2229 *p
= '\0'; /* Insert null now. */
2230 expanded
= history_expand (linebuffer
, &history_value
);
2233 /* Print the changes. */
2234 printf_unfiltered ("%s\n", history_value
);
2236 /* If there was an error, call this function again. */
2239 free (history_value
);
2240 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2242 if (strlen (history_value
) > linelength
)
2244 linelength
= strlen (history_value
) + 1;
2245 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2247 strcpy (linebuffer
, history_value
);
2248 p
= linebuffer
+ strlen (linebuffer
);
2249 free (history_value
);
2253 /* If we just got an empty line, and that is supposed
2254 to repeat the previous command, return the value in the
2256 if (repeat
&& p
== linebuffer
)
2258 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
2264 /* Add line to history if appropriate. */
2265 if (instream
== stdin
2266 && ISATTY (stdin
) && *linebuffer
)
2267 add_history (linebuffer
);
2269 /* Note: lines consisting solely of comments are added to the command
2270 history. This is useful when you type a command, and then
2271 realize you don't want to execute it quite yet. You can comment
2272 out the command and then later fetch it from the value history
2273 and remove the '#'. The kill ring is probably better, but some
2274 people are in the habit of commenting things out. */
2276 *p1
= '\0'; /* Found a comment. */
2278 /* Save into global buffer if appropriate. */
2281 if (linelength
> linesize
)
2283 line
= xrealloc (line
, linelength
);
2284 linesize
= linelength
;
2286 strcpy (line
, linebuffer
);
2294 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2295 code bodies. This is typically used when we encounter an "else"
2296 clause for an "if" command. */
2299 realloc_body_list (command
, new_length
)
2300 struct command_line
*command
;
2304 struct command_line
**body_list
;
2306 n
= command
->body_count
;
2308 /* Nothing to do? */
2309 if (new_length
<= n
)
2312 body_list
= (struct command_line
**)
2313 xmalloc (sizeof (struct command_line
*) * new_length
);
2315 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2317 free (command
->body_list
);
2318 command
->body_list
= body_list
;
2319 command
->body_count
= new_length
;
2322 /* Read one line from the input stream. If the command is an "else" or
2323 "end", return such an indication to the caller. */
2325 static enum misc_command_type
2326 read_next_line (command
)
2327 struct command_line
**command
;
2329 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2332 if (control_level
>= 254)
2333 error ("Control nesting too deep!\n");
2335 /* Set a prompt based on the nesting of the control commands. */
2336 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2338 for (i
= 0; i
< control_level
; i
++)
2339 control_prompt
[i
] = ' ';
2340 control_prompt
[i
] = '>';
2341 control_prompt
[i
+ 1] = '\0';
2342 prompt_ptr
= (char *) &control_prompt
[0];
2347 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2349 /* Not sure what to do here. */
2353 /* Strip leading and trailing whitespace. */
2354 while (*p
== ' ' || *p
== '\t')
2357 p1
= p
+ strlen (p
);
2358 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2361 /* Blanks and comments don't really do anything, but we need to
2362 distinguish them from else, end and other commands which can be
2364 if (p1
== p
|| p
[0] == '#')
2367 /* Is this the end of a simple, while, or if control structure? */
2368 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2371 /* Is the else clause of an if control structure? */
2372 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2373 return else_command
;
2375 /* Check for while, if, break, continue, etc and build a new command
2376 line structure for them. */
2377 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2378 *command
= build_command_line (while_control
, p
+ 6);
2379 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2380 *command
= build_command_line (if_control
, p
+ 3);
2381 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2383 *command
= (struct command_line
*)
2384 xmalloc (sizeof (struct command_line
));
2385 (*command
)->next
= NULL
;
2386 (*command
)->line
= NULL
;
2387 (*command
)->control_type
= break_control
;
2388 (*command
)->body_count
= 0;
2389 (*command
)->body_list
= NULL
;
2391 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2393 *command
= (struct command_line
*)
2394 xmalloc (sizeof (struct command_line
));
2395 (*command
)->next
= NULL
;
2396 (*command
)->line
= NULL
;
2397 (*command
)->control_type
= continue_control
;
2398 (*command
)->body_count
= 0;
2399 (*command
)->body_list
= NULL
;
2403 /* A normal command. */
2404 *command
= (struct command_line
*)
2405 xmalloc (sizeof (struct command_line
));
2406 (*command
)->next
= NULL
;
2407 (*command
)->line
= savestring (p
, p1
- p
);
2408 (*command
)->control_type
= simple_control
;
2409 (*command
)->body_count
= 0;
2410 (*command
)->body_list
= NULL
;
2413 /* Nothing special. */
2417 /* Recursively read in the control structures and create a command_line
2418 structure from them.
2420 The parent_control parameter is the control structure in which the
2421 following commands are nested. */
2423 static enum command_control_type
2424 recurse_read_control_structure (current_cmd
)
2425 struct command_line
*current_cmd
;
2427 int current_body
, i
;
2428 enum misc_command_type val
;
2429 enum command_control_type ret
;
2430 struct command_line
**body_ptr
, *child_tail
, *next
;
2435 /* Sanity checks. */
2436 if (current_cmd
->control_type
== simple_control
)
2438 error ("Recursed on a simple control type\n");
2439 return invalid_control
;
2442 if (current_body
> current_cmd
->body_count
)
2444 error ("Allocated body is smaller than this command type needs\n");
2445 return invalid_control
;
2448 /* Read lines from the input stream and build control structures. */
2454 val
= read_next_line (&next
);
2456 /* Just skip blanks and comments. */
2457 if (val
== nop_command
)
2460 if (val
== end_command
)
2462 if (current_cmd
->control_type
== while_control
2463 || current_cmd
->control_type
== if_control
)
2465 /* Success reading an entire control structure. */
2466 ret
= simple_control
;
2471 ret
= invalid_control
;
2476 /* Not the end of a control structure. */
2477 if (val
== else_command
)
2479 if (current_cmd
->control_type
== if_control
2480 && current_body
== 1)
2482 realloc_body_list (current_cmd
, 2);
2489 ret
= invalid_control
;
2496 child_tail
->next
= next
;
2500 body_ptr
= current_cmd
->body_list
;
2501 for (i
= 1; i
< current_body
; i
++)
2510 /* If the latest line is another control structure, then recurse
2512 if (next
->control_type
== while_control
2513 || next
->control_type
== if_control
)
2516 ret
= recurse_read_control_structure (next
);
2519 if (ret
!= simple_control
)
2529 /* Read lines from the input stream and accumulate them in a chain of
2530 struct command_line's, which is then returned. For input from a
2531 terminal, the special command "end" is used to mark the end of the
2532 input, and is not included in the returned chain of commands. */
2534 #define END_MESSAGE "End with a line saying just \"end\"."
2536 struct command_line
*
2537 read_command_lines (prompt_arg
, from_tty
)
2541 struct command_line
*head
, *tail
, *next
;
2542 struct cleanup
*old_chain
;
2543 enum command_control_type ret
;
2544 enum misc_command_type val
;
2547 if (readline_begin_hook
)
2549 /* Note - intentional to merge messages with no newline */
2550 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2552 else if (from_tty
&& input_from_terminal_p ())
2554 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2555 gdb_flush (gdb_stdout
);
2563 val
= read_next_line (&next
);
2565 /* Ignore blank lines or comments. */
2566 if (val
== nop_command
)
2569 if (val
== end_command
)
2571 ret
= simple_control
;
2575 if (val
!= ok_command
)
2577 ret
= invalid_control
;
2581 if (next
->control_type
== while_control
2582 || next
->control_type
== if_control
)
2585 ret
= recurse_read_control_structure (next
);
2588 if (ret
== invalid_control
)
2599 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
,
2609 if (ret
!= invalid_control
)
2611 discard_cleanups (old_chain
);
2614 do_cleanups (old_chain
);
2617 if (readline_end_hook
)
2619 (*readline_end_hook
) ();
2624 /* Free a chain of struct command_line's. */
2627 free_command_lines (lptr
)
2628 struct command_line
**lptr
;
2630 register struct command_line
*l
= *lptr
;
2631 register struct command_line
*next
;
2632 struct command_line
**blist
;
2637 if (l
->body_count
> 0)
2639 blist
= l
->body_list
;
2640 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2641 free_command_lines (blist
);
2650 /* Add an element to the list of info subcommands. */
2653 add_info (name
, fun
, doc
)
2655 void (*fun
) PARAMS ((char *, int));
2658 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2661 /* Add an alias to the list of info subcommands. */
2664 add_info_alias (name
, oldname
, abbrev_flag
)
2669 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2672 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2673 Therefore, its own definition is called only for "info" with no args. */
2677 info_command (arg
, from_tty
)
2681 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2682 help_list (infolist
, "info ", -1, gdb_stdout
);
2685 /* The "complete" command is used by Emacs to implement completion. */
2689 complete_command (arg
, from_tty
)
2701 argpoint
= strlen (arg
);
2703 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2705 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2707 printf_unfiltered ("%s\n", completion
);
2712 /* The "show" command with no arguments shows all the settings. */
2716 show_command (arg
, from_tty
)
2720 cmd_show_list (showlist
, from_tty
, "");
2723 /* Add an element to the list of commands. */
2726 add_com (name
, class, fun
, doc
)
2728 enum command_class
class;
2729 void (*fun
) PARAMS ((char *, int));
2732 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2735 /* Add an alias or abbreviation command to the list of commands. */
2738 add_com_alias (name
, oldname
, class, abbrev_flag
)
2741 enum command_class
class;
2744 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2751 error ("Argument required (%s).", why
);
2756 help_command (command
, from_tty
)
2758 int from_tty
; /* Ignored */
2760 help_cmd (command
, gdb_stdout
);
2764 validate_comname (comname
)
2770 error_no_arg ("name of command to define");
2775 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
2776 error ("Junk in argument list: \"%s\"", p
);
2781 /* This is just a placeholder in the command data structures. */
2783 user_defined_command (ignore
, from_tty
)
2790 define_command (comname
, from_tty
)
2794 register struct command_line
*cmds
;
2795 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2796 char *tem
= comname
;
2798 #define HOOK_STRING "hook-"
2801 validate_comname (comname
);
2803 /* Look it up, and verify that we got an exact match. */
2804 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2805 if (c
&& !STREQ (comname
, c
->name
))
2810 if (c
->class == class_user
|| c
->class == class_alias
)
2811 tem
= "Redefine command \"%s\"? ";
2813 tem
= "Really redefine built-in command \"%s\"? ";
2814 if (!query (tem
, c
->name
))
2815 error ("Command \"%s\" not redefined.", c
->name
);
2818 /* If this new command is a hook, then mark the command which it
2819 is hooking. Note that we allow hooking `help' commands, so that
2820 we can hook the `stop' pseudo-command. */
2822 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2824 /* Look up cmd it hooks, and verify that we got an exact match. */
2825 tem
= comname
+ HOOK_LEN
;
2826 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2827 if (hookc
&& !STREQ (comname
+ HOOK_LEN
, hookc
->name
))
2831 warning ("Your new `%s' command does not hook any existing command.",
2833 if (!query ("Proceed? "))
2834 error ("Not confirmed.");
2838 comname
= savestring (comname
, strlen (comname
));
2840 /* If the rest of the commands will be case insensitive, this one
2841 should behave in the same manner. */
2842 for (tem
= comname
; *tem
; tem
++)
2844 *tem
= tolower (*tem
);
2846 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
2847 cmds
= read_command_lines (tmpbuf
, from_tty
);
2849 if (c
&& c
->class == class_user
)
2850 free_command_lines (&c
->user_commands
);
2852 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2853 (c
&& c
->class == class_user
)
2854 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2855 newc
->user_commands
= cmds
;
2857 /* If this new command is a hook, then mark both commands as being
2861 hookc
->hook
= newc
; /* Target gets hooked. */
2862 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2867 document_command (comname
, from_tty
)
2871 struct command_line
*doclines
;
2872 register struct cmd_list_element
*c
;
2873 char *tem
= comname
;
2876 validate_comname (comname
);
2878 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2880 if (c
->class != class_user
)
2881 error ("Command \"%s\" is built-in.", comname
);
2883 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
2884 doclines
= read_command_lines (tmpbuf
, from_tty
);
2890 register struct command_line
*cl1
;
2891 register int len
= 0;
2893 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2894 len
+= strlen (cl1
->line
) + 1;
2896 c
->doc
= (char *) xmalloc (len
+ 1);
2899 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2901 strcat (c
->doc
, cl1
->line
);
2903 strcat (c
->doc
, "\n");
2907 free_command_lines (&doclines
);
2910 /* Print the GDB banner. */
2912 print_gdb_version (stream
)
2915 /* From GNU coding standards, first line is meant to be easy for a
2916 program to parse, and is just canonical program name and version
2917 number, which starts after last space. */
2919 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
2921 /* Second line is a copyright notice. */
2923 fprintf_filtered (stream
, "Copyright 1998 Free Software Foundation, Inc.\n");
2925 /* Following the copyright is a brief statement that the program is
2926 free software, that users are free to copy and change it on
2927 certain conditions, that it is covered by the GNU GPL, and that
2928 there is no warranty. */
2930 fprintf_filtered (stream
, "\
2931 GDB is free software, covered by the GNU General Public License, and you are\n\
2932 welcome to change it and/or distribute copies of it under certain conditions.\n\
2933 Type \"show copying\" to see the conditions.\n\
2934 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2936 /* After the required info we print the configuration information. */
2938 fprintf_filtered (stream
, "This GDB was configured as \"");
2939 if (!STREQ (host_name
, target_name
))
2941 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
2945 fprintf_filtered (stream
, "%s", host_name
);
2947 fprintf_filtered (stream
, "\".");
2952 show_version (args
, from_tty
)
2957 print_gdb_version (gdb_stdout
);
2958 printf_filtered ("\n");
2962 /* get_prompt: access method for the GDB prompt string. */
2964 #define MAX_PROMPT_SIZE 256
2967 * int get_prompt_1 (char * buf);
2969 * Work-horse for get_prompt (called via catch_errors).
2970 * Argument is buffer to hold the formatted prompt.
2972 * Returns: 1 for success (use formatted prompt)
2973 * 0 for failure (use gdb_prompt_string).
2976 static int gdb_prompt_escape
;
2979 get_prompt_1 (formatted_prompt
)
2980 char *formatted_prompt
;
2985 local_prompt
= PROMPT (0);
2987 local_prompt
= gdb_prompt_string
;
2990 if (gdb_prompt_escape
== 0)
2992 return 0; /* do no formatting */
2995 /* formatted prompt */
2997 char fmt
[40], *promptp
, *outp
, *tmp
;
3004 struct type
*arg_type
, *elt_type
;
3006 promptp
= local_prompt
;
3007 outp
= formatted_prompt
;
3009 while (*promptp
!= '\0')
3011 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
3013 if (*promptp
!= gdb_prompt_escape
)
3015 if (available
>= 1) /* overflow protect */
3016 *outp
++ = *promptp
++;
3020 /* GDB prompt string contains escape char. Parse for arg.
3021 Two consecutive escape chars followed by arg followed by
3022 a comma means to insert the arg using a default format.
3023 Otherwise a printf format string may be included between
3024 the two escape chars. eg:
3025 %%foo, insert foo using default format
3026 %2.2f%foo, insert foo using "%2.2f" format
3027 A mismatch between the format string and the data type
3028 of "foo" is an error (which we don't know how to protect
3031 fmt
[0] = '\0'; /* assume null format string */
3032 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
3034 promptp
+= 2; /* skip past two escape chars. */
3038 /* extract format string from between two esc chars */
3042 fmt
[i
++] = *promptp
++; /* copy format string */
3044 while (i
< sizeof (fmt
) - 1 &&
3045 *promptp
!= gdb_prompt_escape
&&
3048 if (*promptp
!= gdb_prompt_escape
)
3049 error ("Syntax error at prompt position %d",
3050 promptp
- local_prompt
);
3053 promptp
++; /* skip second escape char */
3054 fmt
[i
++] = '\0'; /* terminate the format string */
3058 arg_val
= parse_to_comma_and_eval (&promptp
);
3059 if (*promptp
== ',')
3060 promptp
++; /* skip past the comma */
3061 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
3062 switch (TYPE_CODE (arg_type
))
3064 case TYPE_CODE_ARRAY
:
3065 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3066 if (TYPE_LENGTH (arg_type
) > 0 &&
3067 TYPE_LENGTH (elt_type
) == 1 &&
3068 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
3070 int len
= TYPE_LENGTH (arg_type
);
3072 if (VALUE_LAZY (arg_val
))
3073 value_fetch_lazy (arg_val
);
3074 tmp
= VALUE_CONTENTS (arg_val
);
3076 if (len
> available
)
3077 len
= available
; /* overflow protect */
3079 /* FIXME: how to protect GDB from crashing
3080 from bad user-supplied format string? */
3082 sprintf (outp
, fmt
, tmp
);
3084 strncpy (outp
, tmp
, len
);
3089 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3090 addrval
= value_as_pointer (arg_val
);
3092 if (TYPE_LENGTH (elt_type
) == 1 &&
3093 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
3096 /* display it as a string */
3097 char *default_fmt
= "%s";
3101 /* Limiting the number of bytes that the following call
3102 will read protects us from sprintf overflow later. */
3103 i
= target_read_string (addrval
, /* src */
3105 available
, /* len */
3107 if (err
) /* read failed */
3108 error ("%s on target_read", safe_strerror (err
));
3110 tmp
[i
] = '\0'; /* force-terminate string */
3111 /* FIXME: how to protect GDB from crashing
3112 from bad user-supplied format string? */
3113 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3119 /* display it as a pointer */
3120 char *default_fmt
= "0x%x";
3122 /* FIXME: how to protect GDB from crashing
3123 from bad user-supplied format string? */
3124 if (available
>= 16 /*? */ ) /* overflow protect */
3125 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3131 char *default_fmt
= "%g";
3133 doubleval
= value_as_double (arg_val
);
3134 /* FIXME: how to protect GDB from crashing
3135 from bad user-supplied format string? */
3136 if (available
>= 16 /*? */ ) /* overflow protect */
3137 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3138 (double) doubleval
);
3143 char *default_fmt
= "%d";
3145 longval
= value_as_long (arg_val
);
3146 /* FIXME: how to protect GDB from crashing
3147 from bad user-supplied format string? */
3148 if (available
>= 16 /*? */ ) /* overflow protect */
3149 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3153 case TYPE_CODE_BOOL
:
3155 /* no default format for bool */
3156 longval
= value_as_long (arg_val
);
3157 if (available
>= 8 /*? */ ) /* overflow protect */
3160 strcpy (outp
, "<true>");
3162 strcpy (outp
, "<false>");
3166 case TYPE_CODE_ENUM
:
3168 /* no default format for enum */
3169 longval
= value_as_long (arg_val
);
3170 len
= TYPE_NFIELDS (arg_type
);
3171 /* find enum name if possible */
3172 for (i
= 0; i
< len
; i
++)
3173 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3174 break; /* match -- end loop */
3176 if (i
< len
) /* enum name found */
3178 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3180 strncpy (outp
, name
, available
);
3181 /* in casel available < strlen (name), */
3182 outp
[available
] = '\0';
3186 if (available
>= 16 /*? */ ) /* overflow protect */
3187 sprintf (outp
, "%d", (long) longval
);
3191 case TYPE_CODE_VOID
:
3193 break; /* void type -- no output */
3195 error ("bad data type at prompt position %d",
3196 promptp
- local_prompt
);
3199 outp
+= strlen (outp
);
3202 *outp
++ = '\0'; /* terminate prompt string */
3210 static char buf
[MAX_PROMPT_SIZE
];
3212 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3215 return &buf
[0]; /* successful formatted prompt */
3219 /* Prompt could not be formatted. */
3223 return gdb_prompt_string
;
3231 /* ??rehrauer: I don't know why this fails, since it looks as though
3232 assignments to prompt are wrapped in calls to savestring...
3237 PROMPT (0) = savestring (s
, strlen (s
));
3239 gdb_prompt_string
= savestring (s
, strlen (s
));
3243 /* If necessary, make the user confirm that we should quit. Return
3244 non-zero if we should quit, zero if we shouldn't. */
3249 if (inferior_pid
!= 0 && target_has_execution
)
3253 /* This is something of a hack. But there's no reliable way to
3254 see if a GUI is running. The `use_windows' variable doesn't
3257 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3258 else if (attach_flag
)
3259 s
= "The program is running. Quit anyway (and detach it)? ";
3261 s
= "The program is running. Exit anyway? ";
3270 /* Quit without asking for confirmation. */
3273 quit_force (args
, from_tty
)
3279 /* An optional expression may be used to cause gdb to terminate with the
3280 value of that expression. */
3283 value_ptr val
= parse_and_eval (args
);
3285 exit_code
= (int) value_as_long (val
);
3288 if (inferior_pid
!= 0 && target_has_execution
)
3291 target_detach (args
, from_tty
);
3296 /* UDI wants this, to kill the TIP. */
3299 /* Save the history information if it is appropriate to do so. */
3300 if (write_history_p
&& history_filename
)
3301 write_history (history_filename
);
3303 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3306 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3307 /* The above does not need to be inside a tuiDo(), since
3308 * it is not manipulating the curses screen, but rather,
3309 * it is tearing it down.
3318 /* Handle the quit command. */
3321 quit_command (args
, from_tty
)
3325 if (!quit_confirm ())
3326 error ("Not confirmed.");
3327 quit_force (args
, from_tty
);
3330 /* Returns whether GDB is running on a terminal and whether the user
3331 desires that questions be asked of them on that terminal. */
3334 input_from_terminal_p ()
3336 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3341 pwd_command (args
, from_tty
)
3346 error ("The \"pwd\" command does not take an argument: %s", args
);
3347 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3349 if (!STREQ (gdb_dirbuf
, current_directory
))
3350 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3351 current_directory
, gdb_dirbuf
);
3353 printf_unfiltered ("Working directory %s.\n", current_directory
);
3357 cd_command (dir
, from_tty
)
3362 /* Found something other than leading repetitions of "/..". */
3363 int found_real_path
;
3366 /* If the new directory is absolute, repeat is a no-op; if relative,
3367 repeat might be useful but is more likely to be a mistake. */
3371 error_no_arg ("new working directory");
3373 dir
= tilde_expand (dir
);
3374 make_cleanup (free
, dir
);
3376 if (chdir (dir
) < 0)
3377 perror_with_name (dir
);
3379 #if defined(_WIN32) || defined(__MSDOS__)
3380 /* There's too much mess with DOSish names like "d:", "d:.",
3381 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3382 simply get the canonicalized name of the current directory. */
3383 dir
= getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3387 if (SLASH_P (dir
[len
-1]))
3389 /* Remove the trailing slash unless this is a root directory
3390 (including a drive letter on non-Unix systems). */
3391 if (!(len
== 1) /* "/" */
3392 #if defined(_WIN32) || defined(__MSDOS__)
3393 && !(!SLASH_P (*dir
) && ROOTED_P (dir
) && len
<= 3) /* "d:/" */
3399 dir
= savestring (dir
, len
);
3401 current_directory
= dir
;
3404 if (SLASH_P (current_directory
[strlen (current_directory
) - 1]))
3405 current_directory
= concat (current_directory
, dir
, NULL
);
3407 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3411 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3413 found_real_path
= 0;
3414 for (p
= current_directory
; *p
;)
3416 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3418 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3419 && (p
[3] == 0 || SLASH_P (p
[3])))
3421 if (found_real_path
)
3423 /* Search backwards for the directory just before the "/.."
3424 and obliterate it and the "/..". */
3426 while (q
!= current_directory
&& !SLASH_P (q
[-1]))
3429 if (q
== current_directory
)
3430 /* current_directory is
3431 a relative pathname ("can't happen"--leave it alone). */
3435 strcpy (q
- 1, p
+ 3);
3440 /* We are dealing with leading repetitions of "/..", for example
3441 "/../..", which is the Mach super-root. */
3446 found_real_path
= 1;
3451 forget_cached_source_info ();
3454 pwd_command ((char *) 0, 1);
3457 struct source_cleanup_lines_args
3461 char *old_pre_error
;
3462 char *old_error_pre_print
;
3466 source_cleanup_lines (args
)
3469 struct source_cleanup_lines_args
*p
=
3470 (struct source_cleanup_lines_args
*) args
;
3471 source_line_number
= p
->old_line
;
3472 source_file_name
= p
->old_file
;
3473 source_pre_error
= p
->old_pre_error
;
3474 error_pre_print
= p
->old_error_pre_print
;
3479 source_command (args
, from_tty
)
3484 struct cleanup
*old_cleanups
;
3486 struct source_cleanup_lines_args old_lines
;
3491 error ("source command requires pathname of file to source.");
3494 file
= tilde_expand (file
);
3495 old_cleanups
= make_cleanup (free
, file
);
3497 stream
= fopen (file
, FOPEN_RT
);
3501 perror_with_name (file
);
3506 make_cleanup ((make_cleanup_func
) fclose
, stream
);
3508 old_lines
.old_line
= source_line_number
;
3509 old_lines
.old_file
= source_file_name
;
3510 old_lines
.old_pre_error
= source_pre_error
;
3511 old_lines
.old_error_pre_print
= error_pre_print
;
3512 make_cleanup (source_cleanup_lines
, &old_lines
);
3513 source_line_number
= 0;
3514 source_file_name
= file
;
3515 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3516 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3517 make_cleanup (free
, source_pre_error
);
3518 /* This will get set every time we read a line. So it won't stay "" for
3520 error_pre_print
= "";
3522 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3523 if (source_error_allocated
< needed_length
)
3525 source_error_allocated
*= 2;
3526 if (source_error_allocated
< needed_length
)
3527 source_error_allocated
= needed_length
;
3528 if (source_error
== NULL
)
3529 source_error
= xmalloc (source_error_allocated
);
3531 source_error
= xrealloc (source_error
, source_error_allocated
);
3534 read_command_file (stream
);
3536 do_cleanups (old_cleanups
);
3541 echo_command (text
, from_tty
)
3549 while ((c
= *p
++) != '\0')
3553 /* \ at end of argument is used after spaces
3554 so they won't be lost. */
3558 c
= parse_escape (&p
);
3560 printf_filtered ("%c", c
);
3563 printf_filtered ("%c", c
);
3566 /* Force this output to appear now. */
3568 gdb_flush (gdb_stdout
);
3573 dont_repeat_command (ignored
, from_tty
)
3577 *line
= 0; /* Can't call dont_repeat here because we're not
3578 necessarily reading from stdin. */
3581 /* Functions to manipulate command line editing control variables. */
3583 /* Number of commands to print in each call to show_commands. */
3584 #define Hist_print 10
3586 show_commands (args
, from_tty
)
3590 /* Index for history commands. Relative to history_base. */
3593 /* Number of the history entry which we are planning to display next.
3594 Relative to history_base. */
3597 /* The first command in the history which doesn't exist (i.e. one more
3598 than the number of the last command). Relative to history_base. */
3601 extern HIST_ENTRY
*history_get
PARAMS ((int));
3603 /* Print out some of the commands from the command history. */
3604 /* First determine the length of the history list. */
3605 hist_len
= history_size
;
3606 for (offset
= 0; offset
< history_size
; offset
++)
3608 if (!history_get (history_base
+ offset
))
3617 if (args
[0] == '+' && args
[1] == '\0')
3618 /* "info editing +" should print from the stored position. */
3621 /* "info editing <exp>" should print around command number <exp>. */
3622 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
3624 /* "show commands" means print the last Hist_print commands. */
3627 num
= hist_len
- Hist_print
;
3633 /* If there are at least Hist_print commands, we want to display the last
3634 Hist_print rather than, say, the last 6. */
3635 if (hist_len
- num
< Hist_print
)
3637 num
= hist_len
- Hist_print
;
3642 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3644 printf_filtered ("%5d %s\n", history_base
+ offset
,
3645 (history_get (history_base
+ offset
))->line
);
3648 /* The next command we want to display is the next one that we haven't
3652 /* If the user repeats this command with return, it should do what
3653 "show commands +" does. This is unnecessary if arg is null,
3654 because "show commands +" is not useful after "show commands". */
3655 if (from_tty
&& args
)
3662 /* Called by do_setshow_command. */
3665 set_history_size_command (args
, from_tty
, c
)
3668 struct cmd_list_element
*c
;
3670 if (history_size
== INT_MAX
)
3671 unstifle_history ();
3672 else if (history_size
>= 0)
3673 stifle_history (history_size
);
3676 history_size
= INT_MAX
;
3677 error ("History size must be non-negative");
3683 set_history (args
, from_tty
)
3687 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3688 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3693 show_history (args
, from_tty
)
3697 cmd_show_list (showhistlist
, from_tty
, "");
3700 int info_verbose
= 0; /* Default verbose msgs off */
3702 /* Called by do_setshow_command. An elaborate joke. */
3705 set_verbose (args
, from_tty
, c
)
3708 struct cmd_list_element
*c
;
3710 char *cmdname
= "verbose";
3711 struct cmd_list_element
*showcmd
;
3713 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3717 c
->doc
= "Set verbose printing of informational messages.";
3718 showcmd
->doc
= "Show verbose printing of informational messages.";
3722 c
->doc
= "Set verbosity.";
3723 showcmd
->doc
= "Show verbosity.";
3728 float_handler (signo
)
3731 /* This message is based on ANSI C, section 4.7. Note that integer
3732 divide by zero causes this, so "float" is a misnomer. */
3733 signal (SIGFPE
, float_handler
);
3734 error ("Erroneous arithmetic operation.");
3748 enablebreaklist
= NULL
;
3753 showhistlist
= NULL
;
3754 unsethistlist
= NULL
;
3755 maintenancelist
= NULL
;
3756 maintenanceinfolist
= NULL
;
3757 maintenanceprintlist
= NULL
;
3758 setprintlist
= NULL
;
3759 showprintlist
= NULL
;
3760 setchecklist
= NULL
;
3761 showchecklist
= NULL
;
3764 /* Init the history buffer. Note that we are called after the init file(s)
3765 * have been read so that the user can change the history file via his
3766 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3767 * overrides all of this.
3775 tmpenv
= getenv ("HISTSIZE");
3777 history_size
= atoi (tmpenv
);
3778 else if (!history_size
)
3781 stifle_history (history_size
);
3783 tmpenv
= getenv ("GDBHISTFILE");
3785 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
3786 else if (!history_filename
)
3788 /* We include the current directory so that if the user changes
3789 directories the file written will be the same as the one
3792 /* No leading dots in file names are allowed on MSDOS. */
3793 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
3795 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3798 read_history (history_filename
);
3804 struct cmd_list_element
*c
;
3806 /* If we are running the asynchronous version,
3807 we initialize the prompts differently. */
3810 #ifdef DEFAULT_PROMPT
3811 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3813 gdb_prompt_string
= savestring ("(gdb) ", 6);
3818 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3819 whatever the DEFAULT_PROMPT is. */
3820 the_prompts
.top
= 0;
3822 #ifdef DEFAULT_PROMPT
3823 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3825 PROMPT (0) = savestring ("(gdb) ", 6);
3828 /* Set things up for annotation_level > 1, if the user ever decides
3830 async_annotation_suffix
= "prompt";
3831 /* Set the variable associated with the setshow prompt command. */
3832 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
3834 gdb_prompt_escape
= 0; /* default to none. */
3836 /* Set the important stuff up for command editing. */
3837 command_editing_p
= 1;
3838 history_expansion_p
= 0;
3839 write_history_p
= 0;
3841 /* Setup important stuff for command line editing. */
3842 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3843 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3844 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3845 rl_readline_name
= "gdb";
3847 /* Define the classes of commands.
3848 They will appear in the help list in the reverse of this order. */
3850 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3851 "Maintenance commands.\n\
3852 Some gdb commands are provided just for use by gdb maintainers.\n\
3853 These commands are subject to frequent change, and may not be as\n\
3854 well documented as user commands.",
3856 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3857 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3858 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3859 The commands in this class are those defined by the user.\n\
3860 Use the \"define\" command to define a command.", &cmdlist
);
3861 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3863 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3864 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3865 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3866 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3867 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3868 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3869 counting from zero for the innermost (currently executing) frame.\n\n\
3870 At any time gdb identifies one frame as the \"selected\" frame.\n\
3871 Variable lookups are done with respect to the selected frame.\n\
3872 When the program being debugged stops, gdb selects the innermost frame.\n\
3873 The commands below can be used to select other frames by number or address.",
3875 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3877 add_com ("pwd", class_files
, pwd_command
,
3878 "Print working directory. This is used for your program as well.");
3879 c
= add_cmd ("cd", class_files
, cd_command
,
3880 "Set working directory to DIR for debugger and program being debugged.\n\
3881 The change does not take effect for the program being debugged\n\
3882 until the next time it is started.", &cmdlist
);
3883 c
->completer
= filename_completer
;
3885 /* The set prompt command is different depending whether or not the
3886 async version is run. NOTE: this difference is going to
3887 disappear as we make the event loop be the default engine of
3892 (add_set_cmd ("prompt", class_support
, var_string
,
3893 (char *) &gdb_prompt_string
, "Set gdb's prompt",
3899 c
= add_set_cmd ("prompt", class_support
, var_string
,
3900 (char *) &new_async_prompt
, "Set gdb's prompt",
3902 add_show_from_set (c
, &showlist
);
3903 c
->function
.sfunc
= set_async_prompt
;
3907 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
3908 (char *) &gdb_prompt_escape
,
3909 "Set escape character for formatting of gdb's prompt",
3913 add_com ("echo", class_support
, echo_command
,
3914 "Print a constant string. Give string as argument.\n\
3915 C escape sequences may be used in the argument.\n\
3916 No newline is added at the end of the argument;\n\
3917 use \"\\n\" if you want a newline to be printed.\n\
3918 Since leading and trailing whitespace are ignored in command arguments,\n\
3919 if you want to print some you must use \"\\\" before leading whitespace\n\
3920 to be printed or after trailing whitespace.");
3921 add_com ("document", class_support
, document_command
,
3922 "Document a user-defined command.\n\
3923 Give command name as argument. Give documentation on following lines.\n\
3924 End with a line of just \"end\".");
3925 add_com ("define", class_support
, define_command
,
3926 "Define a new command name. Command name is argument.\n\
3927 Definition appears on following lines, one command per line.\n\
3928 End with a line of just \"end\".\n\
3929 Use the \"document\" command to give documentation for the new command.\n\
3930 Commands defined in this way may have up to ten arguments.");
3933 c
= add_cmd ("source", class_support
, source_command
,
3934 "Read commands from a file named FILE.\n\
3935 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3936 when gdb is started.", &cmdlist
);
3938 /* Punt file name, we can't help it easily. */
3939 c
= add_cmd ("source", class_support
, source_command
,
3940 "Read commands from a file named FILE.\n\
3941 Note that the file \".gdbinit\" is read automatically in this way\n\
3942 when gdb is started.", &cmdlist
);
3944 c
->completer
= filename_completer
;
3946 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3947 add_com ("help", class_support
, help_command
, "Print list of commands.");
3948 add_com_alias ("q", "quit", class_support
, 1);
3949 add_com_alias ("h", "help", class_support
, 1);
3951 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
3952 Primarily used inside of user-defined commands that should not be repeated when\n\
3955 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *) &info_verbose
,
3958 add_show_from_set (c
, &showlist
);
3959 c
->function
.sfunc
= set_verbose
;
3960 set_verbose (NULL
, 0, c
);
3962 /* The set editing command is different depending whether or not the
3963 async version is run. NOTE: this difference is going to disappear
3964 as we make the event loop be the default engine of gdb. */
3968 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
3969 "Set editing of command lines as they are typed.\n\
3970 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3971 Without an argument, command line editing is enabled. To edit, use\n\
3972 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
3977 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
3978 "Set editing of command lines as they are typed.\n\
3979 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3980 Without an argument, command line editing is enabled. To edit, use\n\
3981 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
3983 add_show_from_set (c
, &showlist
);
3984 c
->function
.sfunc
= set_async_editing_command
;
3987 add_prefix_cmd ("history", class_support
, set_history
,
3988 "Generic command for setting command history parameters.",
3989 &sethistlist
, "set history ", 0, &setlist
);
3990 add_prefix_cmd ("history", class_support
, show_history
,
3991 "Generic command for showing command history parameters.",
3992 &showhistlist
, "show history ", 0, &showlist
);
3995 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *) &history_expansion_p
,
3996 "Set history expansion on command input.\n\
3997 Without an argument, history expansion is enabled.", &sethistlist
),
4001 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
4002 "Set saving of the history record on exit.\n\
4003 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
4004 Without an argument, saving is enabled.", &sethistlist
),
4007 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
4008 "Set the size of the command history, \n\
4009 ie. the number of previous commands to keep a record of.", &sethistlist
);
4010 add_show_from_set (c
, &showhistlist
);
4011 c
->function
.sfunc
= set_history_size_command
;
4014 (add_set_cmd ("filename", no_class
, var_filename
, (char *) &history_filename
,
4015 "Set the filename in which to record the command history\n\
4016 (the list of previous commands of which a record is kept).", &sethistlist
),
4020 (add_set_cmd ("confirm", class_support
, var_boolean
,
4022 "Set whether to confirm potentially dangerous operations.",
4026 add_prefix_cmd ("info", class_info
, info_command
,
4027 "Generic command for showing things about the program being debugged.",
4028 &infolist
, "info ", 0, &cmdlist
);
4029 add_com_alias ("i", "info", class_info
, 1);
4031 add_com ("complete", class_obscure
, complete_command
,
4032 "List the completions for the rest of the line as a command.");
4034 add_prefix_cmd ("show", class_info
, show_command
,
4035 "Generic command for showing things about the debugger.",
4036 &showlist
, "show ", 0, &cmdlist
);
4037 /* Another way to get at the same thing. */
4038 add_info ("set", show_command
, "Show all GDB settings.");
4040 add_cmd ("commands", no_class
, show_commands
,
4041 "Show the history of commands you typed.\n\
4042 You can supply a command number to start with, or a `+' to start after\n\
4043 the previous command number shown.",
4046 add_cmd ("version", no_class
, show_version
,
4047 "Show what version of GDB this is.", &showlist
);
4049 add_com ("while", class_support
, while_command
,
4050 "Execute nested commands WHILE the conditional expression is non zero.\n\
4051 The conditional expression must follow the word `while' and must in turn be\n\
4052 followed by a new line. The nested commands must be entered one per line,\n\
4053 and should be terminated by the word `end'.");
4055 add_com ("if", class_support
, if_command
,
4056 "Execute nested commands once IF the conditional expression is non zero.\n\
4057 The conditional expression must follow the word `if' and must in turn be\n\
4058 followed by a new line. The nested commands must be entered one per line,\n\
4059 and should be terminated by the word 'else' or `end'. If an else clause\n\
4060 is used, the same rules apply to its nested commands as to the first ones.");
4062 /* If target is open when baud changes, it doesn't take effect until the
4063 next open (I think, not sure). */
4064 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
4065 var_zinteger
, (char *) &baud_rate
,
4066 "Set baud rate for remote serial I/O.\n\
4067 This value is used to set the speed of the serial port when debugging\n\
4068 using remote targets.", &setlist
),
4072 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *) &remote_debug
,
4073 "Set debugging of remote protocol.\n\
4074 When enabled, each packet sent or received with the remote target\n\
4075 is displayed.", &setlist
),
4079 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *) &remote_timeout
,
4080 "Set timeout limit to wait for target to respond.\n\
4081 This value is used to set the time limit for gdb to wait for a response\n\
4082 from the target.", &setlist
),
4085 /* The set annotate command is different depending whether or not
4086 the async version is run. NOTE: this difference is going to
4087 disappear as we make the event loop be the default engine of
4091 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4092 (char *) &annotation_level
, "Set annotation_level.\n\
4093 0 == normal; 1 == fullname (for use when running under emacs)\n\
4094 2 == output annotated suitably for use by programs that control GDB.",
4096 c
= add_show_from_set (c
, &showlist
);
4100 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4101 (char *) &annotation_level
, "Set annotation_level.\n\
4102 0 == normal; 1 == fullname (for use when running under emacs)\n\
4103 2 == output annotated suitably for use by programs that control GDB.",
4105 add_show_from_set (c
, &showlist
);
4106 c
->function
.sfunc
= set_async_annotation_level
;