1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
33 #include "terminal.h" /* For job_control. */
35 #include "completer.h"
39 /* readline include files */
40 #include <readline/readline.h>
41 #include <readline/history.h>
43 /* readline defines this. */
46 #include <sys/types.h>
50 #include "event-top.h"
51 #include "gdb_string.h"
59 /* Prototypes for local functions */
61 static void dont_repeat_command (char *, int);
63 static void source_cleanup_lines (PTR
);
65 static void user_defined_command (char *, int);
67 static void init_signals (void);
70 static void stop_sig (int);
73 static char *readline_line_completion_function (char *, int);
75 static void while_command (char *, int);
77 static void if_command (char *, int);
79 static struct command_line
*build_command_line (enum command_control_type
,
82 static struct command_line
*get_command_line (enum command_control_type
,
85 static void realloc_body_list (struct command_line
*, int);
87 static enum misc_command_type
read_next_line (struct command_line
**);
89 static enum command_control_type
90 recurse_read_control_structure (struct command_line
*);
92 static struct cleanup
*setup_user_args (char *);
94 static char *locate_arg (char *);
96 static char *insert_args (char *);
98 static void arg_cleanup (void *);
100 static void init_main (void);
102 static void init_cmd_lists (void);
104 static void float_handler (int);
106 static void init_signals (void);
108 static void set_verbose (char *, int, struct cmd_list_element
*);
110 static void show_history (char *, int);
112 static void set_history (char *, int);
114 static void set_history_size_command (char *, int, struct cmd_list_element
*);
116 static void show_commands (char *, int);
118 static void echo_command (char *, int);
120 static void pwd_command (char *, int);
122 static void show_version (char *, int);
124 static void document_command (char *, int);
126 static void define_command (char *, int);
128 static void validate_comname (char *);
130 static void help_command (char *, int);
132 static void show_command (char *, int);
134 static void info_command (char *, int);
136 static void complete_command (char *, int);
138 static void do_nothing (int);
140 static void show_debug (char *, int);
142 static void set_debug (char *, 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 (PTR
);
150 static void disconnect (int);
153 static void do_restore_instream_cleanup (void *stream
);
155 static struct cleanup
*make_cleanup_free_command_lines (struct command_line
**);
157 /* Default command line prompt. This is overriden in some configs. */
159 #ifndef DEFAULT_PROMPT
160 #define DEFAULT_PROMPT "(gdb) "
163 /* Initialization file name for gdb. This is overridden in some configs. */
165 #ifndef GDBINIT_FILENAME
166 #define GDBINIT_FILENAME ".gdbinit"
168 char gdbinit
[] = GDBINIT_FILENAME
;
170 int inhibit_gdbinit
= 0;
172 /* If nonzero, and GDB has been configured to be able to use windows,
173 attempt to open them upon startup. */
177 extern char lang_frame_mismatch_warn
[]; /* language.c */
179 /* Flag for whether we want all the "from_tty" gubbish printed. */
181 int caution
= 1; /* Default is yes, sigh. */
183 /* Define all cmd_list_elements. */
185 /* Chain containing all defined commands. */
187 struct cmd_list_element
*cmdlist
;
189 /* Chain containing all defined info subcommands. */
191 struct cmd_list_element
*infolist
;
193 /* Chain containing all defined enable subcommands. */
195 struct cmd_list_element
*enablelist
;
197 /* Chain containing all defined disable subcommands. */
199 struct cmd_list_element
*disablelist
;
201 /* Chain containing all defined toggle subcommands. */
203 struct cmd_list_element
*togglelist
;
205 /* Chain containing all defined stop subcommands. */
207 struct cmd_list_element
*stoplist
;
209 /* Chain containing all defined delete subcommands. */
211 struct cmd_list_element
*deletelist
;
213 /* Chain containing all defined "enable breakpoint" subcommands. */
215 struct cmd_list_element
*enablebreaklist
;
217 /* Chain containing all defined set subcommands */
219 struct cmd_list_element
*setlist
;
221 /* Chain containing all defined unset subcommands */
223 struct cmd_list_element
*unsetlist
;
225 /* Chain containing all defined show subcommands. */
227 struct cmd_list_element
*showlist
;
229 /* Chain containing all defined \"set history\". */
231 struct cmd_list_element
*sethistlist
;
233 /* Chain containing all defined \"show history\". */
235 struct cmd_list_element
*showhistlist
;
237 /* Chain containing all defined \"unset history\". */
239 struct cmd_list_element
*unsethistlist
;
241 /* Chain containing all defined maintenance subcommands. */
243 struct cmd_list_element
*maintenancelist
;
245 /* Chain containing all defined "maintenance info" subcommands. */
247 struct cmd_list_element
*maintenanceinfolist
;
249 /* Chain containing all defined "maintenance print" subcommands. */
251 struct cmd_list_element
*maintenanceprintlist
;
253 struct cmd_list_element
*setprintlist
;
255 struct cmd_list_element
*showprintlist
;
257 struct cmd_list_element
*setdebuglist
;
259 struct cmd_list_element
*showdebuglist
;
261 struct cmd_list_element
*setchecklist
;
263 struct cmd_list_element
*showchecklist
;
265 /* stdio stream that command input is being read from. Set to stdin normally.
266 Set by source_command to the file we are sourcing. Set to NULL if we are
267 executing a user-defined command or interacting via a GUI. */
271 /* Current working directory. */
273 char *current_directory
;
275 /* The directory name is actually stored here (usually). */
276 char gdb_dirbuf
[1024];
278 /* Function to call before reading a command, if nonzero.
279 The function receives two args: an input stream,
280 and a prompt string. */
282 void (*window_hook
) (FILE *, char *);
287 /* gdb prints this when reading a command interactively */
288 static char *gdb_prompt_string
; /* the global prompt string */
289 extern char *get_prompt (void); /* access function for prompt string */
291 /* Buffer used for reading command lines, and the size
292 allocated for it so far. */
297 /* Nonzero if the current command is modified by "server ". This
298 affects things like recording into the command history, commands
299 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
300 whatever) can issue its own commands and also send along commands
301 from the user, and have the user not notice that the user interface
302 is issuing commands too. */
305 /* Baud rate specified for talking to serial target systems. Default
306 is left as -1, so targets can choose their own defaults. */
307 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
308 or (unsigned int)-1. This is a Bad User Interface. */
312 /* Timeout limit for response from target. */
314 /* The default value has been changed many times over the years. It
315 was originally 5 seconds. But that was thought to be a long time
316 to sit and wait, so it was changed to 2 seconds. That was thought
317 to be plenty unless the connection was going through some terminal
318 server or multiplexer or other form of hairy serial connection.
320 In mid-1996, remote_timeout was moved from remote.c to top.c and
321 it began being used in other remote-* targets. It appears that the
322 default was changed to 20 seconds at that time, perhaps because the
323 Hitachi E7000 ICE didn't always respond in a timely manner.
325 But if 5 seconds is a long time to sit and wait for retransmissions,
326 20 seconds is far worse. This demonstrates the difficulty of using
327 a single variable for all protocol timeouts.
329 As remote.c is used much more than remote-e7000.c, it was changed
330 back to 2 seconds in 1999. */
332 int remote_timeout
= 2;
334 /* Non-zero tells remote* modules to output debugging info. */
336 int remote_debug
= 0;
338 /* Non-zero means the target is running. Note: this is different from
339 saying that there is an active target and we are stopped at a
340 breakpoint, for instance. This is a real indicator whether the
341 target is off and running, which gdb is doing something else. */
342 int target_executing
= 0;
344 /* Level of control structure. */
345 static int control_level
;
347 /* Structure for arguments to user defined functions. */
348 #define MAXUSERARGS 10
351 struct user_args
*next
;
362 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
366 #define STOP_SIGNAL SIGTSTP
367 static void stop_sig (int);
371 /* Some System V have job control but not sigsetmask(). */
372 #if !defined (HAVE_SIGSETMASK)
374 #define HAVE_SIGSETMASK 1
376 #define HAVE_SIGSETMASK 0
380 #if 0 == (HAVE_SIGSETMASK)
381 #define sigsetmask(n)
384 /* Hooks for alternate command interfaces. */
386 /* Called after most modules have been initialized, but before taking users
389 void (*init_ui_hook
) (char *argv0
);
391 /* This hook is called from within gdb's many mini-event loops which could
392 steal control from a real user interface's event loop. It returns
393 non-zero if the user is requesting a detach, zero otherwise. */
395 int (*ui_loop_hook
) (int);
397 /* Called instead of command_loop at top level. Can be invoked via
398 return_to_top_level. */
400 void (*command_loop_hook
) (void);
403 /* Called from print_frame_info to list the line we stopped in. */
405 void (*print_frame_info_listing_hook
) (struct symtab
* s
, int line
,
406 int stopline
, int noerror
);
407 /* Replaces most of query. */
409 int (*query_hook
) (const char *, va_list);
411 /* Replaces most of warning. */
413 void (*warning_hook
) (const char *, va_list);
415 /* These three functions support getting lines of text from the user. They
416 are used in sequence. First readline_begin_hook is called with a text
417 string that might be (for example) a message for the user to type in a
418 sequence of commands to be executed at a breakpoint. If this function
419 calls back to a GUI, it might take this opportunity to pop up a text
420 interaction window with this message. Next, readline_hook is called
421 with a prompt that is emitted prior to collecting the user input.
422 It can be called multiple times. Finally, readline_end_hook is called
423 to notify the GUI that we are done with the interaction window and it
426 void (*readline_begin_hook
) (char *, ...);
427 char *(*readline_hook
) (char *);
428 void (*readline_end_hook
) (void);
430 /* Called as appropriate to notify the interface of the specified breakpoint
433 void (*create_breakpoint_hook
) (struct breakpoint
* bpt
);
434 void (*delete_breakpoint_hook
) (struct breakpoint
* bpt
);
435 void (*modify_breakpoint_hook
) (struct breakpoint
* bpt
);
437 /* Called as appropriate to notify the interface that we have attached
438 to or detached from an already running process. */
440 void (*attach_hook
) (void);
441 void (*detach_hook
) (void);
443 /* Called during long calculations to allow GUI to repair window damage, and to
444 check for stop buttons, etc... */
446 void (*interactive_hook
) (void);
448 /* Called when the registers have changed, as a hint to a GUI
449 to minimize window update. */
451 void (*registers_changed_hook
) (void);
453 /* Tell the GUI someone changed the register REGNO. -1 means
454 that the caller does not know which register changed or
455 that several registers have changed (see value_assign). */
456 void (*register_changed_hook
) (int regno
);
458 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
459 void (*memory_changed_hook
) (CORE_ADDR addr
, int len
);
461 /* Called when going to wait for the target. Usually allows the GUI to run
462 while waiting for target events. */
464 int (*target_wait_hook
) (int pid
, struct target_waitstatus
* status
);
466 /* Used by UI as a wrapper around command execution. May do various things
467 like enabling/disabling buttons, etc... */
469 void (*call_command_hook
) (struct cmd_list_element
* c
, char *cmd
,
472 /* Called after a `set' command has finished. Is only run if the
473 `set' command succeeded. */
475 void (*set_hook
) (struct cmd_list_element
* c
);
477 /* Called when the current thread changes. Argument is thread id. */
479 void (*context_hook
) (int id
);
481 /* Takes control from error (). Typically used to prevent longjmps out of the
482 middle of the GUI. Usually used in conjunction with a catch routine. */
484 NORETURN
void (*error_hook
) (void) ATTR_NORETURN
;
487 /* One should use catch_errors rather than manipulating these
489 #if defined(HAVE_SIGSETJMP)
490 #define SIGJMP_BUF sigjmp_buf
491 #define SIGSETJMP(buf) sigsetjmp(buf, 1)
492 #define SIGLONGJMP(buf,val) siglongjmp(buf,val)
494 #define SIGJMP_BUF jmp_buf
495 #define SIGSETJMP(buf) setjmp(buf)
496 #define SIGLONGJMP(buf,val) longjmp(buf,val)
499 /* Where to go for return_to_top_level. */
500 static SIGJMP_BUF
*catch_return
;
502 /* Return for reason REASON to the nearest containing catch_errors(). */
505 return_to_top_level (enum return_reason reason
)
510 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
511 I can think of a reason why that is vital, though). */
512 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
514 disable_current_display ();
515 do_cleanups (ALL_CLEANUPS
);
516 if (event_loop_p
&& target_can_async_p () && !target_executing
)
517 do_exec_cleanups (ALL_CLEANUPS
);
518 if (event_loop_p
&& sync_execution
)
519 do_exec_error_cleanups (ALL_CLEANUPS
);
521 if (annotation_level
> 1)
532 /* Jump to the containing catch_errors() call, communicating REASON
533 to that call via setjmp's return value. Note that REASON can't
534 be zero, by definition in defs.h. */
536 (NORETURN
void) SIGLONGJMP (*catch_return
, (int) reason
);
539 /* Call FUNC with arg ARGS, catching any errors. If there is no
540 error, return the value returned by FUNC. If there is an error,
541 print ERRSTRING, print the specific error message, then return
544 Must not be called with immediate_quit in effect (bad things might
545 happen, say we got a signal in the middle of a memcpy to quit_return).
546 This is an OK restriction; with very few exceptions immediate_quit can
547 be replaced by judicious use of QUIT.
549 MASK specifies what to catch; it is normally set to
550 RETURN_MASK_ALL, if for no other reason than that the code which
551 calls catch_errors might not be set up to deal with a quit which
552 isn't caught. But if the code can deal with it, it generally
553 should be RETURN_MASK_ERROR, unless for some reason it is more
554 useful to abort only the portion of the operation inside the
555 catch_errors. Note that quit should return to the command line
556 fairly quickly, even if some further processing is being done. */
558 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
559 error() et.al. could maintain a set of flags that indicate the the
560 current state of each of the longjmp buffers. This would give the
561 longjmp code the chance to detect a longjmp botch (before it gets
562 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
563 code also randomly used a SET_TOP_LEVEL macro that directly
564 initialize the longjmp buffers. */
566 /* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code
567 be consolidated into a single file instead of being distributed
568 between utils.c and top.c? */
571 catch_errors (catch_errors_ftype
*func
, PTR args
, char *errstring
,
574 SIGJMP_BUF
*saved_catch
;
577 struct cleanup
*saved_cleanup_chain
;
578 char *saved_error_pre_print
;
579 char *saved_quit_pre_print
;
581 /* Return value from SIGSETJMP(): enum return_reason if error or
582 quit caught, 0 otherwise. */
585 /* Override error/quit messages during FUNC. */
587 saved_error_pre_print
= error_pre_print
;
588 saved_quit_pre_print
= quit_pre_print
;
590 if (mask
& RETURN_MASK_ERROR
)
591 error_pre_print
= errstring
;
592 if (mask
& RETURN_MASK_QUIT
)
593 quit_pre_print
= errstring
;
595 /* Prevent error/quit during FUNC from calling cleanups established
598 saved_cleanup_chain
= save_cleanups ();
600 /* Call FUNC, catching error/quit events. */
602 saved_catch
= catch_return
;
603 catch_return
= &catch;
604 caught
= SIGSETJMP (catch);
606 val
= (*func
) (args
);
609 catch_return
= saved_catch
;
611 /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
612 clean things up (restoring the cleanup chain) to the state they
613 were just prior to the call. Unfortunately, many FUNC's are not
614 that well behaved. This could be fixed by adding either a
615 do_cleanups call (to cover the problem) or an assertion check to
616 detect bad FUNCs code. */
618 /* Restore the cleanup chain and error/quit messages to their
621 restore_cleanups (saved_cleanup_chain
);
623 if (mask
& RETURN_MASK_QUIT
)
624 quit_pre_print
= saved_quit_pre_print
;
625 if (mask
& RETURN_MASK_ERROR
)
626 error_pre_print
= saved_error_pre_print
;
628 /* Return normally if no error/quit event occurred. */
633 /* If the caller didn't request that the event be caught, relay the
634 event to the next containing catch_errors(). */
636 if (!(mask
& RETURN_MASK (caught
)))
637 return_to_top_level (caught
);
639 /* Tell the caller that an event was caught.
641 FIXME: nsd/2000-02-22: When MASK is RETURN_MASK_ALL, the caller
642 can't tell what type of event occurred.
644 A possible fix is to add a new interface, catch_event(), that
645 returns enum return_reason after catching an error or a quit.
647 When returning normally, i.e. without catching an error or a
648 quit, catch_event() could return RETURN_NORMAL, which would be
649 added to enum return_reason. FUNC would return information
650 exclusively via ARGS.
652 Alternatively, normal catch_event() could return FUNC's return
653 value. The caller would need to be aware of potential overlap
654 with enum return_reason, which could be publicly restricted to
655 negative values to simplify return value processing in FUNC and
661 struct captured_command_args
663 catch_command_errors_ftype
*command
;
669 do_captured_command (void *data
)
671 struct captured_command_args
*context
= data
;
672 context
->command (context
->arg
, context
->from_tty
);
673 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
674 isn't needed. Instead an assertion check could be made that
675 simply confirmed that the called function correctly cleaned up
676 after itself. Unfortunately, old code (prior to 1999-11-04) in
677 main.c was calling SET_TOP_LEVEL(), calling the command function,
678 and then *always* calling do_cleanups(). For the moment we
679 remain ``bug compatible'' with that old code.. */
680 do_cleanups (ALL_CLEANUPS
);
685 catch_command_errors (catch_command_errors_ftype
* command
,
686 char *arg
, int from_tty
, return_mask mask
)
688 struct captured_command_args args
;
689 args
.command
= command
;
691 args
.from_tty
= from_tty
;
692 return catch_errors (do_captured_command
, &args
, "", mask
);
696 /* Handler for SIGHUP. */
700 disconnect (int signo
)
702 catch_errors (quit_cover
, NULL
,
703 "Could not kill the program being debugged", RETURN_MASK_ALL
);
704 signal (SIGHUP
, SIG_DFL
);
705 kill (getpid (), SIGHUP
);
708 /* Just a little helper function for disconnect(). */
710 /* NOTE 1999-04-29: This function will be static again, once we modify
711 gdb to use the event loop as the default command loop and we merge
712 event-top.c into this file, top.c */
716 caution
= 0; /* Throw caution to the wind -- we're exiting.
717 This prevents asking the user dumb questions. */
718 quit_command ((char *) 0, 0);
721 #endif /* defined SIGHUP */
723 /* Line number we are currently in in a file which is being sourced. */
724 /* NOTE 1999-04-29: This variable will be static again, once we modify
725 gdb to use the event loop as the default command loop and we merge
726 event-top.c into this file, top.c */
727 /* static */ int source_line_number
;
729 /* Name of the file we are sourcing. */
730 /* NOTE 1999-04-29: This variable will be static again, once we modify
731 gdb to use the event loop as the default command loop and we merge
732 event-top.c into this file, top.c */
733 /* static */ char *source_file_name
;
735 /* Buffer containing the error_pre_print used by the source stuff.
737 /* NOTE 1999-04-29: This variable will be static again, once we modify
738 gdb to use the event loop as the default command loop and we merge
739 event-top.c into this file, top.c */
740 /* static */ char *source_error
;
741 static int source_error_allocated
;
743 /* Something to glom on to the start of error_pre_print if source_file_name
745 /* NOTE 1999-04-29: This variable will be static again, once we modify
746 gdb to use the event loop as the default command loop and we merge
747 event-top.c into this file, top.c */
748 /* static */ char *source_pre_error
;
750 /* Clean up on error during a "source" command (or execution of a
751 user-defined command). */
754 do_restore_instream_cleanup (void *stream
)
756 /* Restore the previous input stream. */
760 /* Read commands from STREAM. */
762 read_command_file (FILE *stream
)
764 struct cleanup
*cleanups
;
766 cleanups
= make_cleanup (do_restore_instream_cleanup
, instream
);
769 do_cleanups (cleanups
);
772 extern void init_proc (void);
774 void (*pre_init_ui_hook
) (void);
778 do_chdir_cleanup (void *old_dir
)
786 gdb_init (char *argv0
)
788 if (pre_init_ui_hook
)
791 /* Run the init function of each source file */
793 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
794 current_directory
= gdb_dirbuf
;
797 /* Make sure we return to the original directory upon exit, come
798 what may, since the OS doesn't do that for us. */
799 make_final_cleanup (do_chdir_cleanup
, xstrdup (current_directory
));
802 init_cmd_lists (); /* This needs to be done first */
803 initialize_targets (); /* Setup target_terminal macros for utils.c */
804 initialize_utils (); /* Make errors and warnings possible */
805 initialize_all_files ();
806 initialize_current_architecture ();
807 init_main (); /* But that omits this file! Do it now */
809 /* The signal handling mechanism is different depending whether or
810 not the async version is run. NOTE: in the future we plan to make
811 the event loop be the default engine of gdb, and this difference
814 async_init_signals ();
818 /* We need a default language for parsing expressions, so simple things like
819 "set width 0" won't fail if no language is explicitly set in a config file
820 or implicitly set by reading an executable during startup. */
821 set_language (language_c
);
822 expected_language
= current_language
; /* don't warn about the change. */
825 /* Install the default UI */
826 uiout
= cli_out_new (gdb_stdout
);
830 /* All the interpreters should have had a look at things by now.
831 Initialize the selected interpreter. */
832 if (interpreter_p
&& !init_ui_hook
)
834 fprintf_unfiltered (gdb_stderr
, "Interpreter `%s' unrecognized.\n",
841 init_ui_hook (argv0
);
844 /* Allocate, initialize a new command line structure for one of the
845 control commands (if/while). */
847 static struct command_line
*
848 build_command_line (enum command_control_type type
, char *args
)
850 struct command_line
*cmd
;
853 error ("if/while commands require arguments.\n");
855 cmd
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
857 cmd
->control_type
= type
;
861 = (struct command_line
**) xmalloc (sizeof (struct command_line
*)
863 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
864 cmd
->line
= savestring (args
, strlen (args
));
868 /* Build and return a new command structure for the control commands
869 such as "if" and "while". */
871 static struct command_line
*
872 get_command_line (enum command_control_type type
, char *arg
)
874 struct command_line
*cmd
;
875 struct cleanup
*old_chain
= NULL
;
877 /* Allocate and build a new command line structure. */
878 cmd
= build_command_line (type
, arg
);
880 old_chain
= make_cleanup_free_command_lines (&cmd
);
882 /* Read in the body of this command. */
883 if (recurse_read_control_structure (cmd
) == invalid_control
)
885 warning ("error reading in control structure\n");
886 do_cleanups (old_chain
);
890 discard_cleanups (old_chain
);
894 /* Recursively print a command (including full control structures). */
897 print_command_lines (struct ui_out
*uiout
, struct command_line
*cmd
,
900 struct command_line
*list
;
907 ui_out_spaces (uiout
, 2 * depth
);
909 /* A simple command, print it and continue. */
910 if (list
->control_type
== simple_control
)
912 ui_out_field_string (uiout
, NULL
, list
->line
);
913 ui_out_text (uiout
, "\n");
918 /* loop_continue to jump to the start of a while loop, print it
920 if (list
->control_type
== continue_control
)
922 ui_out_field_string (uiout
, NULL
, "loop_continue");
923 ui_out_text (uiout
, "\n");
928 /* loop_break to break out of a while loop, print it and continue. */
929 if (list
->control_type
== break_control
)
931 ui_out_field_string (uiout
, NULL
, "loop_break");
932 ui_out_text (uiout
, "\n");
937 /* A while command. Recursively print its subcommands and continue. */
938 if (list
->control_type
== while_control
)
940 ui_out_text (uiout
, "while ");
941 ui_out_field_fmt (uiout
, NULL
, "while %s", list
->line
);
942 ui_out_text (uiout
, "\n");
943 print_command_lines (uiout
, *list
->body_list
, depth
+ 1);
944 ui_out_field_string (uiout
, NULL
, "end");
946 ui_out_spaces (uiout
, 2 * depth
);
947 ui_out_text (uiout
, "end\n");
952 /* An if command. Recursively print both arms before continueing. */
953 if (list
->control_type
== if_control
)
955 ui_out_text (uiout
, "if ");
956 ui_out_field_fmt (uiout
, NULL
, "if %s", list
->line
);
957 ui_out_text (uiout
, "\n");
959 print_command_lines (uiout
, list
->body_list
[0], depth
+ 1);
961 /* Show the false arm if it exists. */
962 if (list
->body_count
== 2)
965 ui_out_spaces (uiout
, 2 * depth
);
966 ui_out_field_string (uiout
, NULL
, "else");
967 ui_out_text (uiout
, "else\n");
968 print_command_lines (uiout
, list
->body_list
[1], depth
+ 1);
971 ui_out_field_string (uiout
, NULL
, "end");
973 ui_out_spaces (uiout
, 2 * depth
);
974 ui_out_text (uiout
, "end\n");
979 /* ignore illegal command type and try next */
985 print_command_line (struct command_line
*cmd
, unsigned int depth
,
986 struct ui_file
*stream
)
992 for (i
= 0; i
< depth
; i
++)
993 fputs_filtered (" ", stream
);
996 /* A simple command, print it and return. */
997 if (cmd
->control_type
== simple_control
)
999 fputs_filtered (cmd
->line
, stream
);
1000 fputs_filtered ("\n", stream
);
1004 /* loop_continue to jump to the start of a while loop, print it
1006 if (cmd
->control_type
== continue_control
)
1008 fputs_filtered ("loop_continue\n", stream
);
1012 /* loop_break to break out of a while loop, print it and return. */
1013 if (cmd
->control_type
== break_control
)
1015 fputs_filtered ("loop_break\n", stream
);
1019 /* A while command. Recursively print its subcommands before returning. */
1020 if (cmd
->control_type
== while_control
)
1022 struct command_line
*list
;
1023 fputs_filtered ("while ", stream
);
1024 fputs_filtered (cmd
->line
, stream
);
1025 fputs_filtered ("\n", stream
);
1026 list
= *cmd
->body_list
;
1029 print_command_line (list
, depth
+ 1, stream
);
1034 /* An if command. Recursively print both arms before returning. */
1035 if (cmd
->control_type
== if_control
)
1037 fputs_filtered ("if ", stream
);
1038 fputs_filtered (cmd
->line
, stream
);
1039 fputs_filtered ("\n", stream
);
1041 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
1043 /* Show the false arm if it exists. */
1044 if (cmd
->body_count
== 2)
1048 for (i
= 0; i
< depth
; i
++)
1049 fputs_filtered (" ", stream
);
1051 fputs_filtered ("else\n", stream
);
1052 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
1056 for (i
= 0; i
< depth
; i
++)
1057 fputs_filtered (" ", stream
);
1059 fputs_filtered ("end\n", stream
);
1064 /* Execute the command in CMD. */
1066 enum command_control_type
1067 execute_control_command (struct command_line
*cmd
)
1069 struct expression
*expr
;
1070 struct command_line
*current
;
1071 struct cleanup
*old_chain
= 0;
1075 enum command_control_type ret
;
1078 switch (cmd
->control_type
)
1080 case simple_control
:
1081 /* A simple command, execute it and return. */
1082 new_line
= insert_args (cmd
->line
);
1084 return invalid_control
;
1085 old_chain
= make_cleanup (free_current_contents
, &new_line
);
1086 execute_command (new_line
, 0);
1087 ret
= cmd
->control_type
;
1090 case continue_control
:
1092 /* Return for "continue", and "break" so we can either
1093 continue the loop at the top, or break out. */
1094 ret
= cmd
->control_type
;
1099 /* Parse the loop control expression for the while statement. */
1100 new_line
= insert_args (cmd
->line
);
1102 return invalid_control
;
1103 old_chain
= make_cleanup (free_current_contents
, &new_line
);
1104 expr
= parse_expression (new_line
);
1105 make_cleanup (free_current_contents
, &expr
);
1107 ret
= simple_control
;
1110 /* Keep iterating so long as the expression is true. */
1117 /* Evaluate the expression. */
1118 val_mark
= value_mark ();
1119 val
= evaluate_expression (expr
);
1120 cond_result
= value_true (val
);
1121 value_free_to_mark (val_mark
);
1123 /* If the value is false, then break out of the loop. */
1127 /* Execute the body of the while statement. */
1128 current
= *cmd
->body_list
;
1131 ret
= execute_control_command (current
);
1133 /* If we got an error, or a "break" command, then stop
1135 if (ret
== invalid_control
|| ret
== break_control
)
1141 /* If we got a "continue" command, then restart the loop
1143 if (ret
== continue_control
)
1146 /* Get the next statement. */
1147 current
= current
->next
;
1151 /* Reset RET so that we don't recurse the break all the way down. */
1152 if (ret
== break_control
)
1153 ret
= simple_control
;
1160 new_line
= insert_args (cmd
->line
);
1162 return invalid_control
;
1163 old_chain
= make_cleanup (free_current_contents
, &new_line
);
1164 /* Parse the conditional for the if statement. */
1165 expr
= parse_expression (new_line
);
1166 make_cleanup (free_current_contents
, &expr
);
1169 ret
= simple_control
;
1171 /* Evaluate the conditional. */
1172 val_mark
= value_mark ();
1173 val
= evaluate_expression (expr
);
1175 /* Choose which arm to take commands from based on the value of the
1176 conditional expression. */
1177 if (value_true (val
))
1178 current
= *cmd
->body_list
;
1179 else if (cmd
->body_count
== 2)
1180 current
= *(cmd
->body_list
+ 1);
1181 value_free_to_mark (val_mark
);
1183 /* Execute commands in the given arm. */
1186 ret
= execute_control_command (current
);
1188 /* If we got an error, get out. */
1189 if (ret
!= simple_control
)
1192 /* Get the next statement in the body. */
1193 current
= current
->next
;
1200 warning ("Invalid control type in command structure.");
1201 return invalid_control
;
1205 do_cleanups (old_chain
);
1210 /* "while" command support. Executes a body of statements while the
1211 loop condition is nonzero. */
1214 while_command (char *arg
, int from_tty
)
1216 struct command_line
*command
= NULL
;
1219 command
= get_command_line (while_control
, arg
);
1221 if (command
== NULL
)
1224 execute_control_command (command
);
1225 free_command_lines (&command
);
1228 /* "if" command support. Execute either the true or false arm depending
1229 on the value of the if conditional. */
1232 if_command (char *arg
, int from_tty
)
1234 struct command_line
*command
= NULL
;
1237 command
= get_command_line (if_control
, arg
);
1239 if (command
== NULL
)
1242 execute_control_command (command
);
1243 free_command_lines (&command
);
1248 arg_cleanup (void *ignore
)
1250 struct user_args
*oargs
= user_args
;
1252 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1254 user_args
= user_args
->next
;
1258 /* Bind the incomming arguments for a user defined command to
1259 $arg0, $arg1 ... $argMAXUSERARGS. */
1261 static struct cleanup
*
1262 setup_user_args (char *p
)
1264 struct user_args
*args
;
1265 struct cleanup
*old_chain
;
1266 unsigned int arg_count
= 0;
1268 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
1269 memset (args
, 0, sizeof (struct user_args
));
1271 args
->next
= user_args
;
1274 old_chain
= make_cleanup (arg_cleanup
, 0/*ignored*/);
1286 if (arg_count
>= MAXUSERARGS
)
1288 error ("user defined function may only have %d arguments.\n",
1293 /* Strip whitespace. */
1294 while (*p
== ' ' || *p
== '\t')
1297 /* P now points to an argument. */
1299 user_args
->a
[arg_count
].arg
= p
;
1301 /* Get to the end of this argument. */
1304 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1310 else if (*p
== '\\')
1333 user_args
->a
[arg_count
].len
= p
- start_arg
;
1340 /* Given character string P, return a point to the first argument ($arg),
1341 or NULL if P contains no arguments. */
1344 locate_arg (char *p
)
1346 while ((p
= strchr (p
, '$')))
1348 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1355 /* Insert the user defined arguments stored in user_arg into the $arg
1356 arguments found in line, with the updated copy being placed into nline. */
1359 insert_args (char *line
)
1361 char *p
, *save_line
, *new_line
;
1364 /* First we need to know how much memory to allocate for the new line. */
1367 while ((p
= locate_arg (line
)))
1372 if (i
>= user_args
->count
)
1374 error ("Missing argument %d in user function.\n", i
);
1377 len
+= user_args
->a
[i
].len
;
1381 /* Don't forget the tail. */
1382 len
+= strlen (line
);
1384 /* Allocate space for the new line and fill it in. */
1385 new_line
= (char *) xmalloc (len
+ 1);
1386 if (new_line
== NULL
)
1389 /* Restore pointer to beginning of old line. */
1392 /* Save pointer to beginning of new line. */
1393 save_line
= new_line
;
1395 while ((p
= locate_arg (line
)))
1399 memcpy (new_line
, line
, p
- line
);
1400 new_line
+= p
- line
;
1403 len
= user_args
->a
[i
].len
;
1406 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1411 /* Don't forget the tail. */
1412 strcpy (new_line
, line
);
1414 /* Return a pointer to the beginning of the new line. */
1419 execute_user_command (struct cmd_list_element
*c
, char *args
)
1421 register struct command_line
*cmdlines
;
1422 struct cleanup
*old_chain
;
1423 enum command_control_type ret
;
1425 old_chain
= setup_user_args (args
);
1427 cmdlines
= c
->user_commands
;
1432 /* Set the instream to 0, indicating execution of a
1433 user-defined function. */
1434 old_chain
= make_cleanup (do_restore_instream_cleanup
, instream
);
1435 instream
= (FILE *) 0;
1438 ret
= execute_control_command (cmdlines
);
1439 if (ret
!= simple_control
&& ret
!= break_control
)
1441 warning ("Error in control structure.\n");
1444 cmdlines
= cmdlines
->next
;
1446 do_cleanups (old_chain
);
1449 /* Execute the line P as a command.
1450 Pass FROM_TTY as second argument to the defining function. */
1453 execute_command (char *p
, int from_tty
)
1455 register struct cmd_list_element
*c
;
1456 register enum language flang
;
1457 static int warned
= 0;
1459 /* FIXME: These should really be in an appropriate header file */
1460 extern void serial_log_command (const char *);
1464 /* Force cleanup of any alloca areas if using C alloca instead of
1465 a builtin alloca. */
1468 /* This can happen when command_line_input hits end of file. */
1472 serial_log_command (p
);
1474 while (*p
== ' ' || *p
== '\t')
1481 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1483 /* If the target is running, we allow only a limited set of
1485 if (event_loop_p
&& target_can_async_p () && target_executing
)
1486 if (!strcmp (c
->name
, "help")
1487 && !strcmp (c
->name
, "pwd")
1488 && !strcmp (c
->name
, "show")
1489 && !strcmp (c
->name
, "stop"))
1490 error ("Cannot execute this command while the target is running.");
1492 /* Pass null arg rather than an empty one. */
1495 /* Clear off trailing whitespace, except for set and complete command. */
1496 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1498 p
= arg
+ strlen (arg
) - 1;
1499 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1504 /* If this command has been pre-hooked, run the hook first. */
1505 if ((c
->hook_pre
) && (!c
->hook_in
))
1507 c
->hook_in
= 1; /* Prevent recursive hooking */
1508 execute_user_command (c
->hook_pre
, (char *) 0);
1509 c
->hook_in
= 0; /* Allow hook to work again once it is complete */
1512 if (c
->flags
& DEPRECATED_WARN_USER
)
1513 deprecated_cmd_warning (&line
);
1515 if (c
->class == class_user
)
1516 execute_user_command (c
, arg
);
1517 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1518 do_setshow_command (arg
, from_tty
& caution
, c
);
1519 else if (c
->function
.cfunc
== NO_FUNCTION
)
1520 error ("That is not a command, just a help topic.");
1521 else if (call_command_hook
)
1522 call_command_hook (c
, arg
, from_tty
& caution
);
1524 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1526 /* If this command has been post-hooked, run the hook last. */
1527 if ((c
->hook_post
) && (!c
->hook_in
))
1529 c
->hook_in
= 1; /* Prevent recursive hooking */
1530 execute_user_command (c
->hook_post
, (char *) 0);
1531 c
->hook_in
= 0; /* allow hook to work again once it is complete */
1536 /* Tell the user if the language has changed (except first time). */
1537 if (current_language
!= expected_language
)
1539 if (language_mode
== language_mode_auto
)
1541 language_info (1); /* Print what changed. */
1546 /* Warn the user if the working language does not match the
1547 language of the current frame. Only warn the user if we are
1548 actually running the program, i.e. there is a stack. */
1549 /* FIXME: This should be cacheing the frame and only running when
1550 the frame changes. */
1552 if (target_has_stack
)
1554 flang
= get_frame_language ();
1556 && flang
!= language_unknown
1557 && flang
!= current_language
->la_language
)
1559 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1565 /* Read commands from `instream' and execute them
1566 until end of file or error reading instream. */
1571 struct cleanup
*old_chain
;
1573 int stdin_is_tty
= ISATTY (stdin
);
1574 long time_at_cmd_start
;
1576 long space_at_cmd_start
= 0;
1578 extern int display_time
;
1579 extern int display_space
;
1581 while (instream
&& !feof (instream
))
1584 extern int insert_mode
;
1586 if (window_hook
&& instream
== stdin
)
1587 (*window_hook
) (instream
, get_prompt ());
1590 if (instream
== stdin
&& stdin_is_tty
)
1591 reinitialize_more_filter ();
1592 old_chain
= make_cleanup (null_cleanup
, 0);
1595 /* A bit of paranoia: I want to make sure the "insert_mode" global
1596 * is clear except when it is being used for command-line editing
1597 * (see tuiIO.c, utils.c); otherwise normal output will
1598 * get messed up in the TUI. So clear it before/after
1599 * the command-line-input call. - RT
1603 /* Get a command-line. This calls the readline package. */
1604 command
= command_line_input (instream
== stdin
?
1605 get_prompt () : (char *) NULL
,
1606 instream
== stdin
, "prompt");
1613 time_at_cmd_start
= get_run_time ();
1618 extern char **environ
;
1619 char *lim
= (char *) sbrk (0);
1621 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1625 execute_command (command
, instream
== stdin
);
1626 /* Do any commands attached to breakpoint we stopped at. */
1627 bpstat_do_actions (&stop_bpstat
);
1628 do_cleanups (old_chain
);
1632 long cmd_time
= get_run_time () - time_at_cmd_start
;
1634 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1635 cmd_time
/ 1000000, cmd_time
% 1000000);
1641 extern char **environ
;
1642 char *lim
= (char *) sbrk (0);
1643 long space_now
= lim
- (char *) &environ
;
1644 long space_diff
= space_now
- space_at_cmd_start
;
1646 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1648 (space_diff
>= 0 ? '+' : '-'),
1655 /* Read commands from `instream' and execute them until end of file or
1656 error reading instream. This command loop doesnt care about any
1657 such things as displaying time and space usage. If the user asks
1658 for those, they won't work. */
1660 simplified_command_loop (char *(*read_input_func
) (char *),
1661 void (*execute_command_func
) (char *, int))
1663 struct cleanup
*old_chain
;
1665 int stdin_is_tty
= ISATTY (stdin
);
1667 while (instream
&& !feof (instream
))
1670 if (instream
== stdin
&& stdin_is_tty
)
1671 reinitialize_more_filter ();
1672 old_chain
= make_cleanup (null_cleanup
, 0);
1674 /* Get a command-line. */
1675 command
= (*read_input_func
) (instream
== stdin
?
1676 get_prompt () : (char *) NULL
);
1681 (*execute_command_func
) (command
, instream
== stdin
);
1683 /* Do any commands attached to breakpoint we stopped at. */
1684 bpstat_do_actions (&stop_bpstat
);
1686 do_cleanups (old_chain
);
1690 /* Commands call this if they do not want to be repeated by null lines. */
1698 /* If we aren't reading from standard input, we are saving the last
1699 thing read from stdin in line and don't want to delete it. Null lines
1700 won't repeat here in any case. */
1701 if (instream
== stdin
)
1705 /* Read a line from the stream "instream" without command line editing.
1707 It prints PROMPT_ARG once at the start.
1708 Action is compatible with "readline", e.g. space for the result is
1709 malloc'd and should be freed by the caller.
1711 A NULL return means end of file. */
1713 gdb_readline (char *prompt_arg
)
1717 int input_index
= 0;
1718 int result_size
= 80;
1722 /* Don't use a _filtered function here. It causes the assumed
1723 character position to be off, since the newline we read from
1724 the user is not accounted for. */
1725 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1727 /* Move to a new line so the entered line doesn't have a prompt
1728 on the front of it. */
1729 fputs_unfiltered ("\n", gdb_stdout
);
1731 gdb_flush (gdb_stdout
);
1734 result
= (char *) xmalloc (result_size
);
1738 /* Read from stdin if we are executing a user defined command.
1739 This is the right thing for prompt_for_continue, at least. */
1740 c
= fgetc (instream
? instream
: stdin
);
1744 if (input_index
> 0)
1745 /* The last line does not end with a newline. Return it, and
1746 if we are called again fgetc will still return EOF and
1747 we'll return NULL then. */
1754 #ifndef CRLF_SOURCE_FILES
1758 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1764 result
[input_index
++] = c
;
1765 while (input_index
>= result_size
)
1768 result
= (char *) xrealloc (result
, result_size
);
1772 result
[input_index
++] = '\0';
1776 /* Variables which control command line editing and history
1777 substitution. These variables are given default values at the end
1779 static int command_editing_p
;
1780 /* NOTE 1999-04-29: This variable will be static again, once we modify
1781 gdb to use the event loop as the default command loop and we merge
1782 event-top.c into this file, top.c */
1783 /* static */ int history_expansion_p
;
1784 static int write_history_p
;
1785 static int history_size
;
1786 static char *history_filename
;
1788 /* readline uses the word breaks for two things:
1789 (1) In figuring out where to point the TEXT parameter to the
1790 rl_completion_entry_function. Since we don't use TEXT for much,
1791 it doesn't matter a lot what the word breaks are for this purpose, but
1792 it does affect how much stuff M-? lists.
1793 (2) If one of the matches contains a word break character, readline
1794 will quote it. That's why we switch between
1795 gdb_completer_word_break_characters and
1796 gdb_completer_command_word_break_characters. I'm not sure when
1797 we need this behavior (perhaps for funky characters in C++ symbols?). */
1799 /* Variables which are necessary for fancy command line editing. */
1800 char *gdb_completer_word_break_characters
=
1801 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1803 /* When completing on command names, we remove '-' from the list of
1804 word break characters, since we use it in command names. If the
1805 readline library sees one in any of the current completion strings,
1806 it thinks that the string needs to be quoted and automatically supplies
1808 char *gdb_completer_command_word_break_characters
=
1809 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1811 /* When completing on file names, we remove from the list of word
1812 break characters any characters that are commonly used in file
1813 names, such as '-', '+', '~', etc. Otherwise, readline displays
1814 incorrect completion candidates. */
1815 char *gdb_completer_file_name_break_characters
= " \t\n*|\"';:?/><";
1817 /* Characters that can be used to quote completion strings. Note that we
1818 can't include '"' because the gdb C parser treats such quoted sequences
1820 char *gdb_completer_quote_characters
=
1823 /* Functions that are used as part of the fancy command line editing. */
1825 /* This can be used for functions which don't want to complete on symbols
1826 but don't want to complete on anything else either. */
1829 noop_completer (char *text
, char *prefix
)
1834 /* Line completion interface function for readline. */
1837 readline_line_completion_function (char *text
, int matches
)
1839 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
1845 stop_sig (int signo
)
1847 #if STOP_SIGNAL == SIGTSTP
1848 signal (SIGTSTP
, SIG_DFL
);
1850 kill (getpid (), SIGTSTP
);
1851 signal (SIGTSTP
, stop_sig
);
1853 signal (STOP_SIGNAL
, stop_sig
);
1855 printf_unfiltered ("%s", get_prompt ());
1856 gdb_flush (gdb_stdout
);
1858 /* Forget about any previous command -- null line now will do nothing. */
1861 #endif /* STOP_SIGNAL */
1863 /* Initialize signal handlers. */
1865 do_nothing (int signo
)
1867 /* Under System V the default disposition of a signal is reinstated after
1868 the signal is caught and delivered to an application process. On such
1869 systems one must restore the replacement signal handler if one wishes
1870 to continue handling the signal in one's program. On BSD systems this
1871 is not needed but it is harmless, and it simplifies the code to just do
1872 it unconditionally. */
1873 signal (signo
, do_nothing
);
1879 signal (SIGINT
, request_quit
);
1881 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
1882 to the inferior and breakpoints will be ignored. */
1884 signal (SIGTRAP
, SIG_DFL
);
1887 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1888 passed to the inferior, which we don't want. It would be
1889 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1890 on BSD4.3 systems using vfork, that can affect the
1891 GDB process as well as the inferior (the signal handling tables
1892 might be in memory, shared between the two). Since we establish
1893 a handler for SIGQUIT, when we call exec it will set the signal
1894 to SIG_DFL for us. */
1895 signal (SIGQUIT
, do_nothing
);
1897 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1898 signal (SIGHUP
, disconnect
);
1900 signal (SIGFPE
, float_handler
);
1902 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1903 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1907 /* Read one line from the command input stream `instream'
1908 into the local static buffer `linebuffer' (whose current length
1910 The buffer is made bigger as necessary.
1911 Returns the address of the start of the line.
1913 NULL is returned for end of file.
1915 *If* the instream == stdin & stdin is a terminal, the line read
1916 is copied into the file line saver (global var char *line,
1917 length linesize) so that it can be duplicated.
1919 This routine either uses fancy command line editing or
1920 simple input as the user has requested. */
1923 command_line_input (char *prompt_arg
, int repeat
, char *annotation_suffix
)
1925 static char *linebuffer
= 0;
1926 static unsigned linelength
= 0;
1930 char *local_prompt
= prompt_arg
;
1934 /* The annotation suffix must be non-NULL. */
1935 if (annotation_suffix
== NULL
)
1936 annotation_suffix
= "";
1938 if (annotation_level
> 1 && instream
== stdin
)
1940 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
1941 + strlen (annotation_suffix
) + 40);
1942 if (prompt_arg
== NULL
)
1943 local_prompt
[0] = '\0';
1945 strcpy (local_prompt
, prompt_arg
);
1946 strcat (local_prompt
, "\n\032\032");
1947 strcat (local_prompt
, annotation_suffix
);
1948 strcat (local_prompt
, "\n");
1951 if (linebuffer
== 0)
1954 linebuffer
= (char *) xmalloc (linelength
);
1959 /* Control-C quits instantly if typed while in this loop
1960 since it should not wait until the user types a newline. */
1966 signal (STOP_SIGNAL
, handle_stop_sig
);
1968 signal (STOP_SIGNAL
, stop_sig
);
1974 /* Make sure that all output has been output. Some machines may let
1975 you get away with leaving out some of the gdb_flush, but not all. */
1977 gdb_flush (gdb_stdout
);
1978 gdb_flush (gdb_stderr
);
1980 if (source_file_name
!= NULL
)
1982 ++source_line_number
;
1983 sprintf (source_error
,
1984 "%s%s:%d: Error in sourced command file:\n",
1987 source_line_number
);
1988 error_pre_print
= source_error
;
1991 if (annotation_level
> 1 && instream
== stdin
)
1993 printf_unfiltered ("\n\032\032pre-");
1994 printf_unfiltered (annotation_suffix
);
1995 printf_unfiltered ("\n");
1998 /* Don't use fancy stuff if not talking to stdin. */
1999 if (readline_hook
&& instream
== NULL
)
2001 rl
= (*readline_hook
) (local_prompt
);
2003 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2005 rl
= readline (local_prompt
);
2009 rl
= gdb_readline (local_prompt
);
2012 if (annotation_level
> 1 && instream
== stdin
)
2014 printf_unfiltered ("\n\032\032post-");
2015 printf_unfiltered (annotation_suffix
);
2016 printf_unfiltered ("\n");
2019 if (!rl
|| rl
== (char *) EOF
)
2024 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
2026 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
2027 nline
= (char *) xrealloc (linebuffer
, linelength
);
2028 p
+= nline
- linebuffer
;
2032 /* Copy line. Don't copy null at end. (Leaves line alone
2033 if this was just a newline) */
2037 free (rl
); /* Allocated in readline. */
2039 if (p
== linebuffer
|| *(p
- 1) != '\\')
2042 p
--; /* Put on top of '\'. */
2043 local_prompt
= (char *) 0;
2048 signal (STOP_SIGNAL
, SIG_DFL
);
2055 #define SERVER_COMMAND_LENGTH 7
2057 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2058 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2061 /* Note that we don't set `line'. Between this and the check in
2062 dont_repeat, this insures that repeating will still do the
2065 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2068 /* Do history expansion if that is wished. */
2069 if (history_expansion_p
&& instream
== stdin
2070 && ISATTY (instream
))
2072 char *history_value
;
2075 *p
= '\0'; /* Insert null now. */
2076 expanded
= history_expand (linebuffer
, &history_value
);
2079 /* Print the changes. */
2080 printf_unfiltered ("%s\n", history_value
);
2082 /* If there was an error, call this function again. */
2085 free (history_value
);
2086 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2088 if (strlen (history_value
) > linelength
)
2090 linelength
= strlen (history_value
) + 1;
2091 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2093 strcpy (linebuffer
, history_value
);
2094 p
= linebuffer
+ strlen (linebuffer
);
2095 free (history_value
);
2099 /* If we just got an empty line, and that is supposed
2100 to repeat the previous command, return the value in the
2102 if (repeat
&& p
== linebuffer
)
2104 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
2110 /* Add line to history if appropriate. */
2111 if (instream
== stdin
2112 && ISATTY (stdin
) && *linebuffer
)
2113 add_history (linebuffer
);
2115 /* Note: lines consisting solely of comments are added to the command
2116 history. This is useful when you type a command, and then
2117 realize you don't want to execute it quite yet. You can comment
2118 out the command and then later fetch it from the value history
2119 and remove the '#'. The kill ring is probably better, but some
2120 people are in the habit of commenting things out. */
2122 *p1
= '\0'; /* Found a comment. */
2124 /* Save into global buffer if appropriate. */
2127 if (linelength
> linesize
)
2129 line
= xrealloc (line
, linelength
);
2130 linesize
= linelength
;
2132 strcpy (line
, linebuffer
);
2140 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2141 code bodies. This is typically used when we encounter an "else"
2142 clause for an "if" command. */
2145 realloc_body_list (struct command_line
*command
, int new_length
)
2148 struct command_line
**body_list
;
2150 n
= command
->body_count
;
2152 /* Nothing to do? */
2153 if (new_length
<= n
)
2156 body_list
= (struct command_line
**)
2157 xmalloc (sizeof (struct command_line
*) * new_length
);
2159 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2161 free (command
->body_list
);
2162 command
->body_list
= body_list
;
2163 command
->body_count
= new_length
;
2166 /* Read one line from the input stream. If the command is an "else" or
2167 "end", return such an indication to the caller. */
2169 static enum misc_command_type
2170 read_next_line (struct command_line
**command
)
2172 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2175 if (control_level
>= 254)
2176 error ("Control nesting too deep!\n");
2178 /* Set a prompt based on the nesting of the control commands. */
2179 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2181 for (i
= 0; i
< control_level
; i
++)
2182 control_prompt
[i
] = ' ';
2183 control_prompt
[i
] = '>';
2184 control_prompt
[i
+ 1] = '\0';
2185 prompt_ptr
= (char *) &control_prompt
[0];
2190 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2192 /* Not sure what to do here. */
2196 /* Strip leading and trailing whitespace. */
2197 while (*p
== ' ' || *p
== '\t')
2200 p1
= p
+ strlen (p
);
2201 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2204 /* Blanks and comments don't really do anything, but we need to
2205 distinguish them from else, end and other commands which can be
2207 if (p1
== p
|| p
[0] == '#')
2210 /* Is this the end of a simple, while, or if control structure? */
2211 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2214 /* Is the else clause of an if control structure? */
2215 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2216 return else_command
;
2218 /* Check for while, if, break, continue, etc and build a new command
2219 line structure for them. */
2220 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2221 *command
= build_command_line (while_control
, p
+ 6);
2222 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2223 *command
= build_command_line (if_control
, p
+ 3);
2224 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2226 *command
= (struct command_line
*)
2227 xmalloc (sizeof (struct command_line
));
2228 (*command
)->next
= NULL
;
2229 (*command
)->line
= NULL
;
2230 (*command
)->control_type
= break_control
;
2231 (*command
)->body_count
= 0;
2232 (*command
)->body_list
= NULL
;
2234 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2236 *command
= (struct command_line
*)
2237 xmalloc (sizeof (struct command_line
));
2238 (*command
)->next
= NULL
;
2239 (*command
)->line
= NULL
;
2240 (*command
)->control_type
= continue_control
;
2241 (*command
)->body_count
= 0;
2242 (*command
)->body_list
= NULL
;
2246 /* A normal command. */
2247 *command
= (struct command_line
*)
2248 xmalloc (sizeof (struct command_line
));
2249 (*command
)->next
= NULL
;
2250 (*command
)->line
= savestring (p
, p1
- p
);
2251 (*command
)->control_type
= simple_control
;
2252 (*command
)->body_count
= 0;
2253 (*command
)->body_list
= NULL
;
2256 /* Nothing special. */
2260 /* Recursively read in the control structures and create a command_line
2261 structure from them.
2263 The parent_control parameter is the control structure in which the
2264 following commands are nested. */
2266 static enum command_control_type
2267 recurse_read_control_structure (struct command_line
*current_cmd
)
2269 int current_body
, i
;
2270 enum misc_command_type val
;
2271 enum command_control_type ret
;
2272 struct command_line
**body_ptr
, *child_tail
, *next
;
2277 /* Sanity checks. */
2278 if (current_cmd
->control_type
== simple_control
)
2280 error ("Recursed on a simple control type\n");
2281 return invalid_control
;
2284 if (current_body
> current_cmd
->body_count
)
2286 error ("Allocated body is smaller than this command type needs\n");
2287 return invalid_control
;
2290 /* Read lines from the input stream and build control structures. */
2296 val
= read_next_line (&next
);
2298 /* Just skip blanks and comments. */
2299 if (val
== nop_command
)
2302 if (val
== end_command
)
2304 if (current_cmd
->control_type
== while_control
2305 || current_cmd
->control_type
== if_control
)
2307 /* Success reading an entire control structure. */
2308 ret
= simple_control
;
2313 ret
= invalid_control
;
2318 /* Not the end of a control structure. */
2319 if (val
== else_command
)
2321 if (current_cmd
->control_type
== if_control
2322 && current_body
== 1)
2324 realloc_body_list (current_cmd
, 2);
2331 ret
= invalid_control
;
2338 child_tail
->next
= next
;
2342 body_ptr
= current_cmd
->body_list
;
2343 for (i
= 1; i
< current_body
; i
++)
2352 /* If the latest line is another control structure, then recurse
2354 if (next
->control_type
== while_control
2355 || next
->control_type
== if_control
)
2358 ret
= recurse_read_control_structure (next
);
2361 if (ret
!= simple_control
)
2371 /* Read lines from the input stream and accumulate them in a chain of
2372 struct command_line's, which is then returned. For input from a
2373 terminal, the special command "end" is used to mark the end of the
2374 input, and is not included in the returned chain of commands. */
2376 #define END_MESSAGE "End with a line saying just \"end\"."
2378 struct command_line
*
2379 read_command_lines (char *prompt_arg
, int from_tty
)
2381 struct command_line
*head
, *tail
, *next
;
2382 struct cleanup
*old_chain
;
2383 enum command_control_type ret
;
2384 enum misc_command_type val
;
2387 if (readline_begin_hook
)
2389 /* Note - intentional to merge messages with no newline */
2390 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2392 else if (from_tty
&& input_from_terminal_p ())
2394 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2395 gdb_flush (gdb_stdout
);
2403 val
= read_next_line (&next
);
2405 /* Ignore blank lines or comments. */
2406 if (val
== nop_command
)
2409 if (val
== end_command
)
2411 ret
= simple_control
;
2415 if (val
!= ok_command
)
2417 ret
= invalid_control
;
2421 if (next
->control_type
== while_control
2422 || next
->control_type
== if_control
)
2425 ret
= recurse_read_control_structure (next
);
2428 if (ret
== invalid_control
)
2439 old_chain
= make_cleanup_free_command_lines (&head
);
2448 if (ret
!= invalid_control
)
2450 discard_cleanups (old_chain
);
2453 do_cleanups (old_chain
);
2456 if (readline_end_hook
)
2458 (*readline_end_hook
) ();
2463 /* Free a chain of struct command_line's. */
2466 free_command_lines (struct command_line
**lptr
)
2468 register struct command_line
*l
= *lptr
;
2469 register struct command_line
*next
;
2470 struct command_line
**blist
;
2475 if (l
->body_count
> 0)
2477 blist
= l
->body_list
;
2478 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2479 free_command_lines (blist
);
2489 do_free_command_lines_cleanup (void *arg
)
2491 free_command_lines (arg
);
2494 static struct cleanup
*
2495 make_cleanup_free_command_lines (struct command_line
**arg
)
2497 return make_cleanup (do_free_command_lines_cleanup
, arg
);
2500 /* Add an element to the list of info subcommands. */
2502 struct cmd_list_element
*
2503 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
2505 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2508 /* Add an alias to the list of info subcommands. */
2510 struct cmd_list_element
*
2511 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
2513 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2516 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2517 Therefore, its own definition is called only for "info" with no args. */
2521 info_command (char *arg
, int from_tty
)
2523 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2524 help_list (infolist
, "info ", -1, gdb_stdout
);
2527 /* The "complete" command is used by Emacs to implement completion. */
2531 complete_command (char *arg
, int from_tty
)
2541 argpoint
= strlen (arg
);
2543 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2545 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2547 printf_unfiltered ("%s\n", completion
);
2552 /* The "show" command with no arguments shows all the settings. */
2556 show_command (char *arg
, int from_tty
)
2558 cmd_show_list (showlist
, from_tty
, "");
2561 /* Add an element to the list of commands. */
2563 struct cmd_list_element
*
2564 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
2567 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
2570 /* Add an alias or abbreviation command to the list of commands. */
2572 struct cmd_list_element
*
2573 add_com_alias (char *name
, char *oldname
, enum command_class
class,
2576 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2580 error_no_arg (char *why
)
2582 error ("Argument required (%s).", why
);
2585 /* Provide documentation on command or list given by COMMAND. FROM_TTY
2590 help_command (char *command
, int from_tty
)
2592 help_cmd (command
, gdb_stdout
);
2596 validate_comname (char *comname
)
2601 error_no_arg ("name of command to define");
2606 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
2607 error ("Junk in argument list: \"%s\"", p
);
2612 /* This is just a placeholder in the command data structures. */
2614 user_defined_command (char *ignore
, int from_tty
)
2619 define_command (char *comname
, int from_tty
)
2621 #define MAX_TMPBUF 128
2628 register struct command_line
*cmds
;
2629 register struct cmd_list_element
*c
, *newc
, *oldc
, *hookc
= 0;
2630 char *tem
= comname
;
2632 char tmpbuf
[MAX_TMPBUF
];
2633 int hook_type
= CMD_NO_HOOK
;
2634 int hook_name_size
= 0;
2636 #define HOOK_STRING "hook-"
2638 #define HOOK_POST_STRING "hookpost-"
2639 #define HOOK_POST_LEN 9
2641 validate_comname (comname
);
2643 /* Look it up, and verify that we got an exact match. */
2644 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2645 if (c
&& !STREQ (comname
, c
->name
))
2650 if (c
->class == class_user
|| c
->class == class_alias
)
2651 tem
= "Redefine command \"%s\"? ";
2653 tem
= "Really redefine built-in command \"%s\"? ";
2654 if (!query (tem
, c
->name
))
2655 error ("Command \"%s\" not redefined.", c
->name
);
2658 /* If this new command is a hook, then mark the command which it
2659 is hooking. Note that we allow hooking `help' commands, so that
2660 we can hook the `stop' pseudo-command. */
2662 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2664 hook_type
= CMD_PRE_HOOK
;
2665 hook_name_size
= HOOK_LEN
;
2667 else if (!strncmp (comname
, HOOK_POST_STRING
, HOOK_POST_LEN
))
2669 hook_type
= CMD_POST_HOOK
;
2670 hook_name_size
= HOOK_POST_LEN
;
2673 if (hook_type
!= CMD_NO_HOOK
)
2675 /* Look up cmd it hooks, and verify that we got an exact match. */
2676 tem
= comname
+ hook_name_size
;
2677 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2678 if (hookc
&& !STREQ (comname
+ hook_name_size
, hookc
->name
))
2682 warning ("Your new `%s' command does not hook any existing command.",
2684 if (!query ("Proceed? "))
2685 error ("Not confirmed.");
2689 comname
= savestring (comname
, strlen (comname
));
2691 /* If the rest of the commands will be case insensitive, this one
2692 should behave in the same manner. */
2693 for (tem
= comname
; *tem
; tem
++)
2695 *tem
= tolower (*tem
);
2697 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
2698 cmds
= read_command_lines (tmpbuf
, from_tty
);
2700 if (c
&& c
->class == class_user
)
2701 free_command_lines (&c
->user_commands
);
2703 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2704 (c
&& c
->class == class_user
)
2705 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2706 newc
->user_commands
= cmds
;
2708 /* If this new command is a hook, then mark both commands as being
2715 hookc
->hook_pre
= newc
; /* Target gets hooked. */
2716 newc
->hookee_pre
= hookc
; /* We are marked as hooking target cmd. */
2719 hookc
->hook_pre
= newc
; /* Target gets hooked. */
2720 newc
->hookee_pre
= hookc
; /* We are marked as hooking target cmd. */
2723 /* Should never come here as hookc would be 0. */
2729 document_command (char *comname
, int from_tty
)
2731 struct command_line
*doclines
;
2732 register struct cmd_list_element
*c
;
2733 char *tem
= comname
;
2736 validate_comname (comname
);
2738 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2740 if (c
->class != class_user
)
2741 error ("Command \"%s\" is built-in.", comname
);
2743 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
2744 doclines
= read_command_lines (tmpbuf
, from_tty
);
2750 register struct command_line
*cl1
;
2751 register int len
= 0;
2753 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2754 len
+= strlen (cl1
->line
) + 1;
2756 c
->doc
= (char *) xmalloc (len
+ 1);
2759 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2761 strcat (c
->doc
, cl1
->line
);
2763 strcat (c
->doc
, "\n");
2767 free_command_lines (&doclines
);
2770 /* Print the GDB banner. */
2772 print_gdb_version (struct ui_file
*stream
)
2774 /* From GNU coding standards, first line is meant to be easy for a
2775 program to parse, and is just canonical program name and version
2776 number, which starts after last space. */
2779 /* Print it console style until a format is defined */
2780 fprintf_filtered (stream
, "GNU gdb %s (UI_OUT)\n", version
);
2782 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
2785 /* Second line is a copyright notice. */
2787 fprintf_filtered (stream
, "Copyright 2000 Free Software Foundation, Inc.\n");
2789 /* Following the copyright is a brief statement that the program is
2790 free software, that users are free to copy and change it on
2791 certain conditions, that it is covered by the GNU GPL, and that
2792 there is no warranty. */
2794 fprintf_filtered (stream
, "\
2795 GDB is free software, covered by the GNU General Public License, and you are\n\
2796 welcome to change it and/or distribute copies of it under certain conditions.\n\
2797 Type \"show copying\" to see the conditions.\n\
2798 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2800 /* After the required info we print the configuration information. */
2802 fprintf_filtered (stream
, "This GDB was configured as \"");
2803 if (!STREQ (host_name
, target_name
))
2805 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
2809 fprintf_filtered (stream
, "%s", host_name
);
2811 fprintf_filtered (stream
, "\".");
2816 show_version (char *args
, int from_tty
)
2819 print_gdb_version (gdb_stdout
);
2820 printf_filtered ("\n");
2824 /* get_prompt: access method for the GDB prompt string. */
2826 #define MAX_PROMPT_SIZE 256
2829 * int get_prompt_1 (char * buf);
2831 * Work-horse for get_prompt (called via catch_errors).
2832 * Argument is buffer to hold the formatted prompt.
2834 * Returns: 1 for success (use formatted prompt)
2835 * 0 for failure (use gdb_prompt_string).
2838 static int gdb_prompt_escape
;
2841 get_prompt_1 (void *data
)
2843 char *formatted_prompt
= data
;
2847 local_prompt
= PROMPT (0);
2849 local_prompt
= gdb_prompt_string
;
2852 if (gdb_prompt_escape
== 0)
2854 return 0; /* do no formatting */
2857 /* formatted prompt */
2859 char fmt
[40], *promptp
, *outp
, *tmp
;
2866 struct type
*arg_type
, *elt_type
;
2868 promptp
= local_prompt
;
2869 outp
= formatted_prompt
;
2871 while (*promptp
!= '\0')
2873 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
2875 if (*promptp
!= gdb_prompt_escape
)
2877 if (available
>= 1) /* overflow protect */
2878 *outp
++ = *promptp
++;
2882 /* GDB prompt string contains escape char. Parse for arg.
2883 Two consecutive escape chars followed by arg followed by
2884 a comma means to insert the arg using a default format.
2885 Otherwise a printf format string may be included between
2886 the two escape chars. eg:
2887 %%foo, insert foo using default format
2888 %2.2f%foo, insert foo using "%2.2f" format
2889 A mismatch between the format string and the data type
2890 of "foo" is an error (which we don't know how to protect
2893 fmt
[0] = '\0'; /* assume null format string */
2894 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
2896 promptp
+= 2; /* skip past two escape chars. */
2900 /* extract format string from between two esc chars */
2904 fmt
[i
++] = *promptp
++; /* copy format string */
2906 while (i
< sizeof (fmt
) - 1 &&
2907 *promptp
!= gdb_prompt_escape
&&
2910 if (*promptp
!= gdb_prompt_escape
)
2911 error ("Syntax error at prompt position %d",
2912 promptp
- local_prompt
);
2915 promptp
++; /* skip second escape char */
2916 fmt
[i
++] = '\0'; /* terminate the format string */
2920 arg_val
= parse_to_comma_and_eval (&promptp
);
2921 if (*promptp
== ',')
2922 promptp
++; /* skip past the comma */
2923 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
2924 switch (TYPE_CODE (arg_type
))
2926 case TYPE_CODE_ARRAY
:
2927 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
2928 if (TYPE_LENGTH (arg_type
) > 0 &&
2929 TYPE_LENGTH (elt_type
) == 1 &&
2930 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
2932 int len
= TYPE_LENGTH (arg_type
);
2934 if (VALUE_LAZY (arg_val
))
2935 value_fetch_lazy (arg_val
);
2936 tmp
= VALUE_CONTENTS (arg_val
);
2938 if (len
> available
)
2939 len
= available
; /* overflow protect */
2941 /* FIXME: how to protect GDB from crashing
2942 from bad user-supplied format string? */
2944 sprintf (outp
, fmt
, tmp
);
2946 strncpy (outp
, tmp
, len
);
2951 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
2952 addrval
= value_as_pointer (arg_val
);
2954 if (TYPE_LENGTH (elt_type
) == 1 &&
2955 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
2958 /* display it as a string */
2959 char *default_fmt
= "%s";
2963 /* Limiting the number of bytes that the following call
2964 will read protects us from sprintf overflow later. */
2965 i
= target_read_string (addrval
, /* src */
2967 available
, /* len */
2969 if (err
) /* read failed */
2970 error ("%s on target_read", safe_strerror (err
));
2972 tmp
[i
] = '\0'; /* force-terminate string */
2973 /* FIXME: how to protect GDB from crashing
2974 from bad user-supplied format string? */
2975 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
2981 /* display it as a pointer */
2982 char *default_fmt
= "0x%x";
2984 /* FIXME: how to protect GDB from crashing
2985 from bad user-supplied format string? */
2986 if (available
>= 16 /*? */ ) /* overflow protect */
2987 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
2993 char *default_fmt
= "%g";
2995 doubleval
= value_as_double (arg_val
);
2996 /* FIXME: how to protect GDB from crashing
2997 from bad user-supplied format string? */
2998 if (available
>= 16 /*? */ ) /* overflow protect */
2999 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3000 (double) doubleval
);
3005 char *default_fmt
= "%d";
3007 longval
= value_as_long (arg_val
);
3008 /* FIXME: how to protect GDB from crashing
3009 from bad user-supplied format string? */
3010 if (available
>= 16 /*? */ ) /* overflow protect */
3011 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3015 case TYPE_CODE_BOOL
:
3017 /* no default format for bool */
3018 longval
= value_as_long (arg_val
);
3019 if (available
>= 8 /*? */ ) /* overflow protect */
3022 strcpy (outp
, "<true>");
3024 strcpy (outp
, "<false>");
3028 case TYPE_CODE_ENUM
:
3030 /* no default format for enum */
3031 longval
= value_as_long (arg_val
);
3032 len
= TYPE_NFIELDS (arg_type
);
3033 /* find enum name if possible */
3034 for (i
= 0; i
< len
; i
++)
3035 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3036 break; /* match -- end loop */
3038 if (i
< len
) /* enum name found */
3040 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3042 strncpy (outp
, name
, available
);
3043 /* in casel available < strlen (name), */
3044 outp
[available
] = '\0';
3048 if (available
>= 16 /*? */ ) /* overflow protect */
3049 sprintf (outp
, "%ld", (long) longval
);
3053 case TYPE_CODE_VOID
:
3055 break; /* void type -- no output */
3057 error ("bad data type at prompt position %d",
3058 promptp
- local_prompt
);
3061 outp
+= strlen (outp
);
3064 *outp
++ = '\0'; /* terminate prompt string */
3072 static char buf
[MAX_PROMPT_SIZE
];
3074 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3077 return &buf
[0]; /* successful formatted prompt */
3081 /* Prompt could not be formatted. */
3085 return gdb_prompt_string
;
3090 set_prompt (char *s
)
3092 /* ??rehrauer: I don't know why this fails, since it looks as though
3093 assignments to prompt are wrapped in calls to savestring...
3098 PROMPT (0) = savestring (s
, strlen (s
));
3100 gdb_prompt_string
= savestring (s
, strlen (s
));
3104 /* If necessary, make the user confirm that we should quit. Return
3105 non-zero if we should quit, zero if we shouldn't. */
3110 if (inferior_pid
!= 0 && target_has_execution
)
3114 /* This is something of a hack. But there's no reliable way to
3115 see if a GUI is running. The `use_windows' variable doesn't
3118 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3119 else if (attach_flag
)
3120 s
= "The program is running. Quit anyway (and detach it)? ";
3122 s
= "The program is running. Exit anyway? ";
3131 /* Quit without asking for confirmation. */
3134 quit_force (char *args
, int from_tty
)
3138 /* An optional expression may be used to cause gdb to terminate with the
3139 value of that expression. */
3142 value_ptr val
= parse_and_eval (args
);
3144 exit_code
= (int) value_as_long (val
);
3147 if (inferior_pid
!= 0 && target_has_execution
)
3150 target_detach (args
, from_tty
);
3155 /* UDI wants this, to kill the TIP. */
3158 /* Save the history information if it is appropriate to do so. */
3159 if (write_history_p
&& history_filename
)
3160 write_history (history_filename
);
3162 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3165 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3166 /* The above does not need to be inside a tuiDo(), since
3167 * it is not manipulating the curses screen, but rather,
3168 * it is tearing it down.
3177 /* Handle the quit command. */
3180 quit_command (char *args
, int from_tty
)
3182 if (!quit_confirm ())
3183 error ("Not confirmed.");
3184 quit_force (args
, from_tty
);
3187 /* Returns whether GDB is running on a terminal and whether the user
3188 desires that questions be asked of them on that terminal. */
3191 input_from_terminal_p (void)
3193 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3198 pwd_command (char *args
, int from_tty
)
3201 error ("The \"pwd\" command does not take an argument: %s", args
);
3202 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3204 if (!STREQ (gdb_dirbuf
, current_directory
))
3205 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3206 current_directory
, gdb_dirbuf
);
3208 printf_unfiltered ("Working directory %s.\n", current_directory
);
3212 cd_command (char *dir
, int from_tty
)
3215 /* Found something other than leading repetitions of "/..". */
3216 int found_real_path
;
3219 /* If the new directory is absolute, repeat is a no-op; if relative,
3220 repeat might be useful but is more likely to be a mistake. */
3224 error_no_arg ("new working directory");
3226 dir
= tilde_expand (dir
);
3227 make_cleanup (free
, dir
);
3229 if (chdir (dir
) < 0)
3230 perror_with_name (dir
);
3232 #if defined(_WIN32) || defined(__MSDOS__)
3233 /* There's too much mess with DOSish names like "d:", "d:.",
3234 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3235 simply get the canonicalized name of the current directory. */
3236 dir
= getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3240 if (SLASH_P (dir
[len
- 1]))
3242 /* Remove the trailing slash unless this is a root directory
3243 (including a drive letter on non-Unix systems). */
3244 if (!(len
== 1) /* "/" */
3245 #if defined(_WIN32) || defined(__MSDOS__)
3246 && !(!SLASH_P (*dir
) && ROOTED_P (dir
) && len
<= 3) /* "d:/" */
3252 dir
= savestring (dir
, len
);
3254 current_directory
= dir
;
3257 if (SLASH_P (current_directory
[strlen (current_directory
) - 1]))
3258 current_directory
= concat (current_directory
, dir
, NULL
);
3260 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3264 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3266 found_real_path
= 0;
3267 for (p
= current_directory
; *p
;)
3269 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3271 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3272 && (p
[3] == 0 || SLASH_P (p
[3])))
3274 if (found_real_path
)
3276 /* Search backwards for the directory just before the "/.."
3277 and obliterate it and the "/..". */
3279 while (q
!= current_directory
&& !SLASH_P (q
[-1]))
3282 if (q
== current_directory
)
3283 /* current_directory is
3284 a relative pathname ("can't happen"--leave it alone). */
3288 strcpy (q
- 1, p
+ 3);
3293 /* We are dealing with leading repetitions of "/..", for example
3294 "/../..", which is the Mach super-root. */
3299 found_real_path
= 1;
3304 forget_cached_source_info ();
3307 pwd_command ((char *) 0, 1);
3310 struct source_cleanup_lines_args
3314 char *old_pre_error
;
3315 char *old_error_pre_print
;
3319 source_cleanup_lines (PTR args
)
3321 struct source_cleanup_lines_args
*p
=
3322 (struct source_cleanup_lines_args
*) args
;
3323 source_line_number
= p
->old_line
;
3324 source_file_name
= p
->old_file
;
3325 source_pre_error
= p
->old_pre_error
;
3326 error_pre_print
= p
->old_error_pre_print
;
3331 do_fclose_cleanup (void *stream
)
3337 source_command (char *args
, int from_tty
)
3340 struct cleanup
*old_cleanups
;
3342 struct source_cleanup_lines_args old_lines
;
3347 error ("source command requires pathname of file to source.");
3350 file
= tilde_expand (file
);
3351 old_cleanups
= make_cleanup (free
, file
);
3353 stream
= fopen (file
, FOPEN_RT
);
3357 perror_with_name (file
);
3362 make_cleanup (do_fclose_cleanup
, stream
);
3364 old_lines
.old_line
= source_line_number
;
3365 old_lines
.old_file
= source_file_name
;
3366 old_lines
.old_pre_error
= source_pre_error
;
3367 old_lines
.old_error_pre_print
= error_pre_print
;
3368 make_cleanup (source_cleanup_lines
, &old_lines
);
3369 source_line_number
= 0;
3370 source_file_name
= file
;
3371 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3372 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3373 make_cleanup (free
, source_pre_error
);
3374 /* This will get set every time we read a line. So it won't stay "" for
3376 error_pre_print
= "";
3378 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3379 if (source_error_allocated
< needed_length
)
3381 source_error_allocated
*= 2;
3382 if (source_error_allocated
< needed_length
)
3383 source_error_allocated
= needed_length
;
3384 if (source_error
== NULL
)
3385 source_error
= xmalloc (source_error_allocated
);
3387 source_error
= xrealloc (source_error
, source_error_allocated
);
3390 read_command_file (stream
);
3392 do_cleanups (old_cleanups
);
3397 echo_command (char *text
, int from_tty
)
3403 while ((c
= *p
++) != '\0')
3407 /* \ at end of argument is used after spaces
3408 so they won't be lost. */
3412 c
= parse_escape (&p
);
3414 printf_filtered ("%c", c
);
3417 printf_filtered ("%c", c
);
3420 /* Force this output to appear now. */
3422 gdb_flush (gdb_stdout
);
3427 dont_repeat_command (char *ignored
, int from_tty
)
3429 *line
= 0; /* Can't call dont_repeat here because we're not
3430 necessarily reading from stdin. */
3433 /* Functions to manipulate command line editing control variables. */
3435 /* Number of commands to print in each call to show_commands. */
3436 #define Hist_print 10
3438 show_commands (char *args
, int from_tty
)
3440 /* Index for history commands. Relative to history_base. */
3443 /* Number of the history entry which we are planning to display next.
3444 Relative to history_base. */
3447 /* The first command in the history which doesn't exist (i.e. one more
3448 than the number of the last command). Relative to history_base. */
3451 extern HIST_ENTRY
*history_get (int);
3453 /* Print out some of the commands from the command history. */
3454 /* First determine the length of the history list. */
3455 hist_len
= history_size
;
3456 for (offset
= 0; offset
< history_size
; offset
++)
3458 if (!history_get (history_base
+ offset
))
3467 if (args
[0] == '+' && args
[1] == '\0')
3468 /* "info editing +" should print from the stored position. */
3471 /* "info editing <exp>" should print around command number <exp>. */
3472 num
= (parse_and_eval_long (args
) - history_base
) - Hist_print
/ 2;
3474 /* "show commands" means print the last Hist_print commands. */
3477 num
= hist_len
- Hist_print
;
3483 /* If there are at least Hist_print commands, we want to display the last
3484 Hist_print rather than, say, the last 6. */
3485 if (hist_len
- num
< Hist_print
)
3487 num
= hist_len
- Hist_print
;
3492 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3494 printf_filtered ("%5d %s\n", history_base
+ offset
,
3495 (history_get (history_base
+ offset
))->line
);
3498 /* The next command we want to display is the next one that we haven't
3502 /* If the user repeats this command with return, it should do what
3503 "show commands +" does. This is unnecessary if arg is null,
3504 because "show commands +" is not useful after "show commands". */
3505 if (from_tty
&& args
)
3512 /* Called by do_setshow_command. */
3515 set_history_size_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
3517 if (history_size
== INT_MAX
)
3518 unstifle_history ();
3519 else if (history_size
>= 0)
3520 stifle_history (history_size
);
3523 history_size
= INT_MAX
;
3524 error ("History size must be non-negative");
3530 set_history (char *args
, int from_tty
)
3532 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3533 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3538 show_history (char *args
, int from_tty
)
3540 cmd_show_list (showhistlist
, from_tty
, "");
3543 int info_verbose
= 0; /* Default verbose msgs off */
3545 /* Called by do_setshow_command. An elaborate joke. */
3548 set_verbose (char *args
, int from_tty
, struct cmd_list_element
*c
)
3550 char *cmdname
= "verbose";
3551 struct cmd_list_element
*showcmd
;
3553 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3557 c
->doc
= "Set verbose printing of informational messages.";
3558 showcmd
->doc
= "Show verbose printing of informational messages.";
3562 c
->doc
= "Set verbosity.";
3563 showcmd
->doc
= "Show verbosity.";
3568 float_handler (int signo
)
3570 /* This message is based on ANSI C, section 4.7. Note that integer
3571 divide by zero causes this, so "float" is a misnomer. */
3572 signal (SIGFPE
, float_handler
);
3573 error ("Erroneous arithmetic operation.");
3577 set_debug (char *arg
, int from_tty
)
3579 printf_unfiltered ("\"set debug\" must be followed by the name of a print subcommand.\n");
3580 help_list (setdebuglist
, "set debug ", -1, gdb_stdout
);
3584 show_debug (char *args
, int from_tty
)
3586 cmd_show_list (showdebuglist
, from_tty
, "");
3590 init_cmd_lists (void)
3599 enablebreaklist
= NULL
;
3604 showhistlist
= NULL
;
3605 unsethistlist
= NULL
;
3606 maintenancelist
= NULL
;
3607 maintenanceinfolist
= NULL
;
3608 maintenanceprintlist
= NULL
;
3609 setprintlist
= NULL
;
3610 showprintlist
= NULL
;
3611 setchecklist
= NULL
;
3612 showchecklist
= NULL
;
3615 /* Init the history buffer. Note that we are called after the init file(s)
3616 * have been read so that the user can change the history file via his
3617 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3618 * overrides all of this.
3626 tmpenv
= getenv ("HISTSIZE");
3628 history_size
= atoi (tmpenv
);
3629 else if (!history_size
)
3632 stifle_history (history_size
);
3634 tmpenv
= getenv ("GDBHISTFILE");
3636 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
3637 else if (!history_filename
)
3639 /* We include the current directory so that if the user changes
3640 directories the file written will be the same as the one
3643 /* No leading dots in file names are allowed on MSDOS. */
3644 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
3646 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3649 read_history (history_filename
);
3655 struct cmd_list_element
*c
;
3657 /* If we are running the asynchronous version,
3658 we initialize the prompts differently. */
3661 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3665 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3666 whatever the DEFAULT_PROMPT is. */
3667 the_prompts
.top
= 0;
3669 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3671 /* Set things up for annotation_level > 1, if the user ever decides
3673 async_annotation_suffix
= "prompt";
3674 /* Set the variable associated with the setshow prompt command. */
3675 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
3677 gdb_prompt_escape
= 0; /* default to none. */
3679 /* Set the important stuff up for command editing. */
3680 command_editing_p
= 1;
3681 history_expansion_p
= 0;
3682 write_history_p
= 0;
3684 /* Setup important stuff for command line editing. */
3685 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3686 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3687 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3688 rl_readline_name
= "gdb";
3690 /* Define the classes of commands.
3691 They will appear in the help list in the reverse of this order. */
3693 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3694 "Maintenance commands.\n\
3695 Some gdb commands are provided just for use by gdb maintainers.\n\
3696 These commands are subject to frequent change, and may not be as\n\
3697 well documented as user commands.",
3699 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3700 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3701 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3702 The commands in this class are those defined by the user.\n\
3703 Use the \"define\" command to define a command.", &cmdlist
);
3704 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3706 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3707 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3708 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3709 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3710 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3711 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3712 counting from zero for the innermost (currently executing) frame.\n\n\
3713 At any time gdb identifies one frame as the \"selected\" frame.\n\
3714 Variable lookups are done with respect to the selected frame.\n\
3715 When the program being debugged stops, gdb selects the innermost frame.\n\
3716 The commands below can be used to select other frames by number or address.",
3718 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3720 add_com ("pwd", class_files
, pwd_command
,
3721 "Print working directory. This is used for your program as well.");
3722 c
= add_cmd ("cd", class_files
, cd_command
,
3723 "Set working directory to DIR for debugger and program being debugged.\n\
3724 The change does not take effect for the program being debugged\n\
3725 until the next time it is started.", &cmdlist
);
3726 c
->completer
= filename_completer
;
3728 /* The set prompt command is different depending whether or not the
3729 async version is run. NOTE: this difference is going to
3730 disappear as we make the event loop be the default engine of
3735 (add_set_cmd ("prompt", class_support
, var_string
,
3736 (char *) &gdb_prompt_string
, "Set gdb's prompt",
3742 c
= add_set_cmd ("prompt", class_support
, var_string
,
3743 (char *) &new_async_prompt
, "Set gdb's prompt",
3745 add_show_from_set (c
, &showlist
);
3746 c
->function
.sfunc
= set_async_prompt
;
3750 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
3751 (char *) &gdb_prompt_escape
,
3752 "Set escape character for formatting of gdb's prompt",
3756 add_com ("echo", class_support
, echo_command
,
3757 "Print a constant string. Give string as argument.\n\
3758 C escape sequences may be used in the argument.\n\
3759 No newline is added at the end of the argument;\n\
3760 use \"\\n\" if you want a newline to be printed.\n\
3761 Since leading and trailing whitespace are ignored in command arguments,\n\
3762 if you want to print some you must use \"\\\" before leading whitespace\n\
3763 to be printed or after trailing whitespace.");
3764 add_com ("document", class_support
, document_command
,
3765 "Document a user-defined command.\n\
3766 Give command name as argument. Give documentation on following lines.\n\
3767 End with a line of just \"end\".");
3768 add_com ("define", class_support
, define_command
,
3769 "Define a new command name. Command name is argument.\n\
3770 Definition appears on following lines, one command per line.\n\
3771 End with a line of just \"end\".\n\
3772 Use the \"document\" command to give documentation for the new command.\n\
3773 Commands defined in this way may have up to ten arguments.");
3776 c
= add_cmd ("source", class_support
, source_command
,
3777 "Read commands from a file named FILE.\n\
3778 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3779 when gdb is started.", &cmdlist
);
3781 /* Punt file name, we can't help it easily. */
3782 c
= add_cmd ("source", class_support
, source_command
,
3783 "Read commands from a file named FILE.\n\
3784 Note that the file \".gdbinit\" is read automatically in this way\n\
3785 when gdb is started.", &cmdlist
);
3787 c
->completer
= filename_completer
;
3789 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3790 add_com ("help", class_support
, help_command
, "Print list of commands.");
3791 add_com_alias ("q", "quit", class_support
, 1);
3792 add_com_alias ("h", "help", class_support
, 1);
3794 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
3795 Primarily used inside of user-defined commands that should not be repeated when\n\
3798 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *) &info_verbose
,
3801 add_show_from_set (c
, &showlist
);
3802 c
->function
.sfunc
= set_verbose
;
3803 set_verbose (NULL
, 0, c
);
3805 /* The set editing command is different depending whether or not the
3806 async version is run. NOTE: this difference is going to disappear
3807 as we make the event loop be the default engine of gdb. */
3811 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
3812 "Set editing of command lines as they are typed.\n\
3813 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3814 Without an argument, command line editing is enabled. To edit, use\n\
3815 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
3820 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
3821 "Set editing of command lines as they are typed.\n\
3822 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3823 Without an argument, command line editing is enabled. To edit, use\n\
3824 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
3826 add_show_from_set (c
, &showlist
);
3827 c
->function
.sfunc
= set_async_editing_command
;
3830 add_prefix_cmd ("history", class_support
, set_history
,
3831 "Generic command for setting command history parameters.",
3832 &sethistlist
, "set history ", 0, &setlist
);
3833 add_prefix_cmd ("history", class_support
, show_history
,
3834 "Generic command for showing command history parameters.",
3835 &showhistlist
, "show history ", 0, &showlist
);
3838 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *) &history_expansion_p
,
3839 "Set history expansion on command input.\n\
3840 Without an argument, history expansion is enabled.", &sethistlist
),
3844 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
3845 "Set saving of the history record on exit.\n\
3846 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
3847 Without an argument, saving is enabled.", &sethistlist
),
3850 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
3851 "Set the size of the command history, \n\
3852 ie. the number of previous commands to keep a record of.", &sethistlist
);
3853 add_show_from_set (c
, &showhistlist
);
3854 c
->function
.sfunc
= set_history_size_command
;
3857 (add_set_cmd ("filename", no_class
, var_filename
, (char *) &history_filename
,
3858 "Set the filename in which to record the command history\n\
3859 (the list of previous commands of which a record is kept).", &sethistlist
),
3863 (add_set_cmd ("confirm", class_support
, var_boolean
,
3865 "Set whether to confirm potentially dangerous operations.",
3869 add_prefix_cmd ("info", class_info
, info_command
,
3870 "Generic command for showing things about the program being debugged.",
3871 &infolist
, "info ", 0, &cmdlist
);
3872 add_com_alias ("i", "info", class_info
, 1);
3874 add_com ("complete", class_obscure
, complete_command
,
3875 "List the completions for the rest of the line as a command.");
3877 add_prefix_cmd ("show", class_info
, show_command
,
3878 "Generic command for showing things about the debugger.",
3879 &showlist
, "show ", 0, &cmdlist
);
3880 /* Another way to get at the same thing. */
3881 add_info ("set", show_command
, "Show all GDB settings.");
3883 add_cmd ("commands", no_class
, show_commands
,
3884 "Show the history of commands you typed.\n\
3885 You can supply a command number to start with, or a `+' to start after\n\
3886 the previous command number shown.",
3889 add_cmd ("version", no_class
, show_version
,
3890 "Show what version of GDB this is.", &showlist
);
3892 add_com ("while", class_support
, while_command
,
3893 "Execute nested commands WHILE the conditional expression is non zero.\n\
3894 The conditional expression must follow the word `while' and must in turn be\n\
3895 followed by a new line. The nested commands must be entered one per line,\n\
3896 and should be terminated by the word `end'.");
3898 add_com ("if", class_support
, if_command
,
3899 "Execute nested commands once IF the conditional expression is non zero.\n\
3900 The conditional expression must follow the word `if' and must in turn be\n\
3901 followed by a new line. The nested commands must be entered one per line,\n\
3902 and should be terminated by the word 'else' or `end'. If an else clause\n\
3903 is used, the same rules apply to its nested commands as to the first ones.");
3905 /* If target is open when baud changes, it doesn't take effect until the
3906 next open (I think, not sure). */
3907 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
3908 var_zinteger
, (char *) &baud_rate
,
3909 "Set baud rate for remote serial I/O.\n\
3910 This value is used to set the speed of the serial port when debugging\n\
3911 using remote targets.", &setlist
),
3914 c
= add_set_cmd ("remotedebug", no_class
, var_zinteger
,
3915 (char *) &remote_debug
,
3916 "Set debugging of remote protocol.\n\
3917 When enabled, each packet sent or received with the remote target\n\
3918 is displayed.", &setlist
);
3919 deprecate_cmd (c
, "set debug remote");
3920 deprecate_cmd (add_show_from_set (c
, &showlist
), "show debug remote");
3922 add_show_from_set (add_set_cmd ("remote", no_class
, var_zinteger
,
3923 (char *) &remote_debug
,
3924 "Set debugging of remote protocol.\n\
3925 When enabled, each packet sent or received with the remote target\n\
3926 is displayed.", &setdebuglist
),
3930 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *) &remote_timeout
,
3931 "Set timeout limit to wait for target to respond.\n\
3932 This value is used to set the time limit for gdb to wait for a response\n\
3933 from the target.", &setlist
),
3936 /* The set annotate command is different depending whether or not
3937 the async version is run. NOTE: this difference is going to
3938 disappear as we make the event loop be the default engine of
3942 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
3943 (char *) &annotation_level
, "Set annotation_level.\n\
3944 0 == normal; 1 == fullname (for use when running under emacs)\n\
3945 2 == output annotated suitably for use by programs that control GDB.",
3947 c
= add_show_from_set (c
, &showlist
);
3951 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
3952 (char *) &annotation_level
, "Set annotation_level.\n\
3953 0 == normal; 1 == fullname (for use when running under emacs)\n\
3954 2 == output annotated suitably for use by programs that control GDB.",
3956 add_show_from_set (c
, &showlist
);
3957 c
->function
.sfunc
= set_async_annotation_level
;
3962 (add_set_cmd ("exec-done-display", class_support
, var_boolean
, (char *) &exec_done_display_p
,
3963 "Set notification of completion for asynchronous execution commands.\n\
3964 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist
),
3967 add_prefix_cmd ("debug", no_class
, set_debug
,
3968 "Generic command for setting gdb debugging flags",
3969 &setdebuglist
, "set debug ", 0, &setlist
);
3971 add_prefix_cmd ("debug", no_class
, show_debug
,
3972 "Generic command for showing gdb debugging flags",
3973 &showdebuglist
, "show debug ", 0, &showlist
);