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. */
38 /* readline include files */
39 #include <readline/readline.h>
40 #include <readline/history.h>
42 /* readline defines this. */
45 #include <sys/types.h>
49 #include "event-top.h"
50 #include "gdb_string.h"
58 /* Prototypes for local functions */
60 static void dont_repeat_command
PARAMS ((char *, int));
62 static void source_cleanup_lines
PARAMS ((PTR
));
64 static void user_defined_command
PARAMS ((char *, int));
66 static void init_signals
PARAMS ((void));
69 static void stop_sig
PARAMS ((int));
72 static char *line_completion_function
PARAMS ((char *, int, char *, int));
74 static char *readline_line_completion_function
PARAMS ((char *, int));
76 /* NOTE 1999-04-29: this function will be static again, after we make the
77 event loop be the default command loop for gdb, and we merge
78 event-top.c into this file, top.c */
79 /* static */ void command_loop_marker
PARAMS ((int));
81 static void while_command
PARAMS ((char *, int));
83 static void if_command
PARAMS ((char *, int));
85 static struct command_line
*
86 build_command_line
PARAMS ((enum command_control_type
, char *));
88 static struct command_line
*
89 get_command_line
PARAMS ((enum command_control_type
, char *));
91 static void realloc_body_list
PARAMS ((struct command_line
*, int));
93 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
95 static enum command_control_type
96 recurse_read_control_structure
PARAMS ((struct command_line
*));
98 static struct cleanup
*setup_user_args
PARAMS ((char *));
100 static char *locate_arg
PARAMS ((char *));
102 static char *insert_args
PARAMS ((char *));
104 static void arg_cleanup
PARAMS ((void));
106 static void init_main
PARAMS ((void));
108 static void init_cmd_lists
PARAMS ((void));
110 static void float_handler
PARAMS ((int));
112 static void init_signals
PARAMS ((void));
114 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
116 static void show_history
PARAMS ((char *, int));
118 static void set_history
PARAMS ((char *, int));
120 static void set_history_size_command
PARAMS ((char *, int,
121 struct cmd_list_element
*));
123 static void show_commands
PARAMS ((char *, int));
125 static void echo_command
PARAMS ((char *, int));
127 static void pwd_command
PARAMS ((char *, int));
129 static void show_version
PARAMS ((char *, int));
131 static void document_command
PARAMS ((char *, int));
133 static void define_command
PARAMS ((char *, int));
135 static void validate_comname
PARAMS ((char *));
137 static void help_command
PARAMS ((char *, int));
139 static void show_command
PARAMS ((char *, int));
141 static void info_command
PARAMS ((char *, int));
143 static void complete_command
PARAMS ((char *, int));
145 static void do_nothing
PARAMS ((int));
147 static void show_debug
PARAMS ((char *, int));
149 static void set_debug
PARAMS ((char *, int));
152 /* NOTE 1999-04-29: This function will be static again, once we modify
153 gdb to use the event loop as the default command loop and we merge
154 event-top.c into this file, top.c */
155 /* static */ int quit_cover
PARAMS ((PTR
));
157 static void disconnect
PARAMS ((int));
160 static void source_cleanup
PARAMS ((FILE *));
162 /* Default command line prompt. This is overriden in some configs. */
164 #ifndef DEFAULT_PROMPT
165 #define DEFAULT_PROMPT "(gdb) "
168 /* Initialization file name for gdb. This is overridden in some configs. */
170 #ifndef GDBINIT_FILENAME
171 #define GDBINIT_FILENAME ".gdbinit"
173 char gdbinit
[] = GDBINIT_FILENAME
;
175 int inhibit_gdbinit
= 0;
177 /* If nonzero, and GDB has been configured to be able to use windows,
178 attempt to open them upon startup. */
182 extern char lang_frame_mismatch_warn
[]; /* language.c */
184 /* Flag for whether we want all the "from_tty" gubbish printed. */
186 int caution
= 1; /* Default is yes, sigh. */
188 /* Define all cmd_list_elements. */
190 /* Chain containing all defined commands. */
192 struct cmd_list_element
*cmdlist
;
194 /* Chain containing all defined info subcommands. */
196 struct cmd_list_element
*infolist
;
198 /* Chain containing all defined enable subcommands. */
200 struct cmd_list_element
*enablelist
;
202 /* Chain containing all defined disable subcommands. */
204 struct cmd_list_element
*disablelist
;
206 /* Chain containing all defined toggle subcommands. */
208 struct cmd_list_element
*togglelist
;
210 /* Chain containing all defined stop subcommands. */
212 struct cmd_list_element
*stoplist
;
214 /* Chain containing all defined delete subcommands. */
216 struct cmd_list_element
*deletelist
;
218 /* Chain containing all defined "enable breakpoint" subcommands. */
220 struct cmd_list_element
*enablebreaklist
;
222 /* Chain containing all defined set subcommands */
224 struct cmd_list_element
*setlist
;
226 /* Chain containing all defined unset subcommands */
228 struct cmd_list_element
*unsetlist
;
230 /* Chain containing all defined show subcommands. */
232 struct cmd_list_element
*showlist
;
234 /* Chain containing all defined \"set history\". */
236 struct cmd_list_element
*sethistlist
;
238 /* Chain containing all defined \"show history\". */
240 struct cmd_list_element
*showhistlist
;
242 /* Chain containing all defined \"unset history\". */
244 struct cmd_list_element
*unsethistlist
;
246 /* Chain containing all defined maintenance subcommands. */
248 struct cmd_list_element
*maintenancelist
;
250 /* Chain containing all defined "maintenance info" subcommands. */
252 struct cmd_list_element
*maintenanceinfolist
;
254 /* Chain containing all defined "maintenance print" subcommands. */
256 struct cmd_list_element
*maintenanceprintlist
;
258 struct cmd_list_element
*setprintlist
;
260 struct cmd_list_element
*showprintlist
;
262 struct cmd_list_element
*setdebuglist
;
264 struct cmd_list_element
*showdebuglist
;
266 struct cmd_list_element
*setchecklist
;
268 struct cmd_list_element
*showchecklist
;
270 /* stdio stream that command input is being read from. Set to stdin normally.
271 Set by source_command to the file we are sourcing. Set to NULL if we are
272 executing a user-defined command or interacting via a GUI. */
276 /* Current working directory. */
278 char *current_directory
;
280 /* The directory name is actually stored here (usually). */
281 char gdb_dirbuf
[1024];
283 /* Function to call before reading a command, if nonzero.
284 The function receives two args: an input stream,
285 and a prompt string. */
287 void (*window_hook
) PARAMS ((FILE *, char *));
292 /* gdb prints this when reading a command interactively */
293 static char *gdb_prompt_string
; /* the global prompt string */
294 extern char *get_prompt
PARAMS ((void)); /* access function for prompt string */
296 /* Buffer used for reading command lines, and the size
297 allocated for it so far. */
302 /* Nonzero if the current command is modified by "server ". This
303 affects things like recording into the command history, commands
304 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
305 whatever) can issue its own commands and also send along commands
306 from the user, and have the user not notice that the user interface
307 is issuing commands too. */
310 /* Baud rate specified for talking to serial target systems. Default
311 is left as -1, so targets can choose their own defaults. */
312 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
313 or (unsigned int)-1. This is a Bad User Interface. */
317 /* Timeout limit for response from target. */
319 /* The default value has been changed many times over the years. It
320 was originally 5 seconds. But that was thought to be a long time
321 to sit and wait, so it was changed to 2 seconds. That was thought
322 to be plenty unless the connection was going through some terminal
323 server or multiplexer or other form of hairy serial connection.
325 In mid-1996, remote_timeout was moved from remote.c to top.c and
326 it began being used in other remote-* targets. It appears that the
327 default was changed to 20 seconds at that time, perhaps because the
328 Hitachi E7000 ICE didn't always respond in a timely manner.
330 But if 5 seconds is a long time to sit and wait for retransmissions,
331 20 seconds is far worse. This demonstrates the difficulty of using
332 a single variable for all protocol timeouts.
334 As remote.c is used much more than remote-e7000.c, it was changed
335 back to 2 seconds in 1999. */
337 int remote_timeout
= 2;
339 /* Non-zero tells remote* modules to output debugging info. */
341 int remote_debug
= 0;
343 /* Non-zero means the target is running. Note: this is different from
344 saying that there is an active target and we are stopped at a
345 breakpoint, for instance. This is a real indicator whether the
346 target is off and running, which gdb is doing something else. */
347 int target_executing
= 0;
349 /* Level of control structure. */
350 static int control_level
;
352 /* Structure for arguments to user defined functions. */
353 #define MAXUSERARGS 10
356 struct user_args
*next
;
367 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
371 #define STOP_SIGNAL SIGTSTP
372 static void stop_sig
PARAMS ((int));
376 /* Some System V have job control but not sigsetmask(). */
377 #if !defined (HAVE_SIGSETMASK)
379 #define HAVE_SIGSETMASK 1
381 #define HAVE_SIGSETMASK 0
385 #if 0 == (HAVE_SIGSETMASK)
386 #define sigsetmask(n)
389 /* Hooks for alternate command interfaces. */
391 /* Called after most modules have been initialized, but before taking users
394 void (*init_ui_hook
) PARAMS ((char *argv0
));
396 /* This hook is called from within gdb's many mini-event loops which could
397 steal control from a real user interface's event loop. It returns
398 non-zero if the user is requesting a detach, zero otherwise. */
400 int (*ui_loop_hook
) PARAMS ((int));
402 /* Called instead of command_loop at top level. Can be invoked via
403 return_to_top_level. */
405 void (*command_loop_hook
) PARAMS ((void));
408 /* Called from print_frame_info to list the line we stopped in. */
410 void (*print_frame_info_listing_hook
) PARAMS ((struct symtab
* s
, int line
,
411 int stopline
, int noerror
));
412 /* Replaces most of query. */
414 int (*query_hook
) PARAMS ((const char *, va_list));
416 /* Replaces most of warning. */
418 void (*warning_hook
) PARAMS ((const char *, va_list));
420 /* These three functions support getting lines of text from the user. They
421 are used in sequence. First readline_begin_hook is called with a text
422 string that might be (for example) a message for the user to type in a
423 sequence of commands to be executed at a breakpoint. If this function
424 calls back to a GUI, it might take this opportunity to pop up a text
425 interaction window with this message. Next, readline_hook is called
426 with a prompt that is emitted prior to collecting the user input.
427 It can be called multiple times. Finally, readline_end_hook is called
428 to notify the GUI that we are done with the interaction window and it
431 void (*readline_begin_hook
) PARAMS ((char *,...));
432 char *(*readline_hook
) PARAMS ((char *));
433 void (*readline_end_hook
) PARAMS ((void));
435 /* Called as appropriate to notify the interface of the specified breakpoint
438 void (*create_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
439 void (*delete_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
440 void (*modify_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
442 /* Called as appropriate to notify the interface that we have attached
443 to or detached from an already running process. */
445 void (*attach_hook
) PARAMS ((void));
446 void (*detach_hook
) PARAMS ((void));
448 /* Called during long calculations to allow GUI to repair window damage, and to
449 check for stop buttons, etc... */
451 void (*interactive_hook
) PARAMS ((void));
453 /* Called when the registers have changed, as a hint to a GUI
454 to minimize window update. */
456 void (*registers_changed_hook
) PARAMS ((void));
458 /* Tell the GUI someone changed the register REGNO. -1 means
459 that the caller does not know which register changed or
460 that several registers have changed (see value_assign). */
461 void (*register_changed_hook
) PARAMS ((int regno
));
463 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
464 void (*memory_changed_hook
) PARAMS ((CORE_ADDR addr
, int len
));
466 /* Called when going to wait for the target. Usually allows the GUI to run
467 while waiting for target events. */
469 int (*target_wait_hook
) PARAMS ((int pid
, struct target_waitstatus
* status
));
471 /* Used by UI as a wrapper around command execution. May do various things
472 like enabling/disabling buttons, etc... */
474 void (*call_command_hook
) PARAMS ((struct cmd_list_element
* c
, char *cmd
,
477 /* Called after a `set' command has finished. Is only run if the
478 `set' command succeeded. */
480 void (*set_hook
) (struct cmd_list_element
* c
);
482 /* Called when the current thread changes. Argument is thread id. */
484 void (*context_hook
) PARAMS ((int id
));
486 /* Takes control from error (). Typically used to prevent longjmps out of the
487 middle of the GUI. Usually used in conjunction with a catch routine. */
489 NORETURN
void (*error_hook
) (void) ATTR_NORETURN
;
492 /* One should use catch_errors rather than manipulating these
494 #if defined(HAVE_SIGSETJMP)
495 #define SIGJMP_BUF sigjmp_buf
496 #define SIGSETJMP(buf) sigsetjmp(buf, 1)
497 #define SIGLONGJMP(buf,val) siglongjmp(buf,val)
499 #define SIGJMP_BUF jmp_buf
500 #define SIGSETJMP(buf) setjmp(buf)
501 #define SIGLONGJMP(buf,val) longjmp(buf,val)
504 /* Where to go for return_to_top_level. */
505 static SIGJMP_BUF
*catch_return
;
507 /* Return for reason REASON to the nearest containing catch_errors(). */
510 return_to_top_level (reason
)
511 enum return_reason reason
;
516 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
517 I can think of a reason why that is vital, though). */
518 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
520 disable_current_display ();
521 do_cleanups (ALL_CLEANUPS
);
522 if (event_loop_p
&& target_can_async_p () && !target_executing
)
523 do_exec_cleanups (ALL_CLEANUPS
);
524 if (event_loop_p
&& sync_execution
)
525 do_exec_error_cleanups (ALL_CLEANUPS
);
527 if (annotation_level
> 1)
538 /* Jump to the containing catch_errors() call, communicating REASON
539 to that call via setjmp's return value. Note that REASON can't
540 be zero, by definition in defs.h. */
542 (NORETURN
void) SIGLONGJMP (*catch_return
, (int) reason
);
545 /* Call FUNC with arg ARGS, catching any errors. If there is no
546 error, return the value returned by FUNC. If there is an error,
547 print ERRSTRING, print the specific error message, then return
550 Must not be called with immediate_quit in effect (bad things might
551 happen, say we got a signal in the middle of a memcpy to quit_return).
552 This is an OK restriction; with very few exceptions immediate_quit can
553 be replaced by judicious use of QUIT.
555 MASK specifies what to catch; it is normally set to
556 RETURN_MASK_ALL, if for no other reason than that the code which
557 calls catch_errors might not be set up to deal with a quit which
558 isn't caught. But if the code can deal with it, it generally
559 should be RETURN_MASK_ERROR, unless for some reason it is more
560 useful to abort only the portion of the operation inside the
561 catch_errors. Note that quit should return to the command line
562 fairly quickly, even if some further processing is being done. */
564 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
565 error() et.al. could maintain a set of flags that indicate the the
566 current state of each of the longjmp buffers. This would give the
567 longjmp code the chance to detect a longjmp botch (before it gets
568 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
569 code also randomly used a SET_TOP_LEVEL macro that directly
570 initialize the longjmp buffers. */
572 /* MAYBE: cagney/1999-11-05: Should the catch_erros and cleanups code
573 be consolidated into a single file instead of being distributed
574 between utils.c and top.c? */
577 catch_errors (func
, args
, errstring
, mask
)
578 catch_errors_ftype
*func
;
583 SIGJMP_BUF
*saved_catch
;
586 struct cleanup
*saved_cleanup_chain
;
587 char *saved_error_pre_print
;
588 char *saved_quit_pre_print
;
590 /* Return value from SIGSETJMP(): enum return_reason if error or
591 quit caught, 0 otherwise. */
594 /* Override error/quit messages during FUNC. */
596 saved_error_pre_print
= error_pre_print
;
597 saved_quit_pre_print
= quit_pre_print
;
599 if (mask
& RETURN_MASK_ERROR
)
600 error_pre_print
= errstring
;
601 if (mask
& RETURN_MASK_QUIT
)
602 quit_pre_print
= errstring
;
604 /* Prevent error/quit during FUNC from calling cleanups established
607 saved_cleanup_chain
= save_cleanups ();
609 /* Call FUNC, catching error/quit events. */
611 saved_catch
= catch_return
;
612 catch_return
= &catch;
613 caught
= SIGSETJMP (catch);
615 val
= (*func
) (args
);
616 catch_return
= saved_catch
;
618 /* FIXME: cagney/1999-11-05: A correct FUNC implementaton will
619 clean things up (restoring the cleanup chain) to the state they
620 were just prior to the call. Unfortunatly, many FUNC's are not
621 that well behaved. This could be fixed by adding either a
622 do_cleanups call (to cover the problem) or an assertion check to
623 detect bad FUNCs code. */
625 /* Restore the cleanup chain and error/quit messages to their
628 restore_cleanups (saved_cleanup_chain
);
630 if (mask
& RETURN_MASK_QUIT
)
631 quit_pre_print
= saved_quit_pre_print
;
632 if (mask
& RETURN_MASK_ERROR
)
633 error_pre_print
= saved_error_pre_print
;
635 /* Return normally if no error/quit event occurred. */
640 /* If the caller didn't request that the event be caught, relay the
641 event to the next containing catch_errors(). */
643 if (!(mask
& RETURN_MASK (caught
)))
644 return_to_top_level (caught
);
646 /* Tell the caller that an event was caught.
648 FIXME: nsd/2000-02-22: When MASK is RETURN_MASK_ALL, the caller
649 can't tell what type of event occurred.
651 A possible fix is to add a new interface, catch_event(), that
652 returns enum return_reason after catching an error or a quit.
654 When returning normally, i.e. without catching an error or a
655 quit, catch_event() could return RETURN_NORMAL, which would be
656 added to enum return_reason. FUNC would return information
657 exclusively via ARGS.
659 Alternatively, normal catch_event() could return FUNC's return
660 value. The caller would need to be aware of potential overlap
661 with enum return_reason, which could be publicly restricted to
662 negative values to simplify return value processing in FUNC and
668 struct captured_command_args
670 catch_command_errors_ftype
*command
;
676 do_captured_command (void *data
)
678 struct captured_command_args
*context
= data
;
679 context
->command (context
->arg
, context
->from_tty
);
680 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
681 isn't needed. Instead an assertion check could be made that
682 simply confirmed that the called function correctly cleaned up
683 after its self. Unfortunatly, old code (prior to 1999-11-04) in
684 main.c was calling SET_TOP_LEVEL(), calling the command function,
685 and then *always* calling do_cleanups(). For the moment we
686 remain ``bug compatible'' with that old code.. */
687 do_cleanups (ALL_CLEANUPS
);
692 catch_command_errors (catch_command_errors_ftype
* command
,
693 char *arg
, int from_tty
, return_mask mask
)
695 struct captured_command_args args
;
696 args
.command
= command
;
698 args
.from_tty
= from_tty
;
699 return catch_errors (do_captured_command
, &args
, "", mask
);
703 /* Handler for SIGHUP. */
710 catch_errors (quit_cover
, NULL
,
711 "Could not kill the program being debugged", RETURN_MASK_ALL
);
712 signal (SIGHUP
, SIG_DFL
);
713 kill (getpid (), SIGHUP
);
716 /* Just a little helper function for disconnect(). */
718 /* NOTE 1999-04-29: This function will be static again, once we modify
719 gdb to use the event loop as the default command loop and we merge
720 event-top.c into this file, top.c */
725 caution
= 0; /* Throw caution to the wind -- we're exiting.
726 This prevents asking the user dumb questions. */
727 quit_command ((char *) 0, 0);
730 #endif /* defined SIGHUP */
732 /* Line number we are currently in in a file which is being sourced. */
733 /* NOTE 1999-04-29: This variable will be static again, once we modify
734 gdb to use the event loop as the default command loop and we merge
735 event-top.c into this file, top.c */
736 /* static */ int source_line_number
;
738 /* Name of the file we are sourcing. */
739 /* NOTE 1999-04-29: This variable will be static again, once we modify
740 gdb to use the event loop as the default command loop and we merge
741 event-top.c into this file, top.c */
742 /* static */ char *source_file_name
;
744 /* Buffer containing the error_pre_print used by the source stuff.
746 /* NOTE 1999-04-29: This variable will be static again, once we modify
747 gdb to use the event loop as the default command loop and we merge
748 event-top.c into this file, top.c */
749 /* static */ char *source_error
;
750 static int source_error_allocated
;
752 /* Something to glom on to the start of error_pre_print if source_file_name
754 /* NOTE 1999-04-29: This variable will be static again, once we modify
755 gdb to use the event loop as the default command loop and we merge
756 event-top.c into this file, top.c */
757 /* static */ char *source_pre_error
;
759 /* Clean up on error during a "source" command (or execution of a
760 user-defined command). */
763 source_cleanup (stream
)
766 /* Restore the previous input stream. */
770 /* Read commands from STREAM. */
772 read_command_file (stream
)
775 struct cleanup
*cleanups
;
777 cleanups
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
780 do_cleanups (cleanups
);
783 extern void init_proc
PARAMS ((void));
785 void (*pre_init_ui_hook
) PARAMS ((void));
791 if (pre_init_ui_hook
)
794 /* Run the init function of each source file */
796 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
797 current_directory
= gdb_dirbuf
;
800 /* Make sure we return to the original directory upon exit, come
801 what may, since the OS doesn't do that for us. */
802 make_final_cleanup ((make_cleanup_func
) chdir
, strsave (current_directory
));
805 init_cmd_lists (); /* This needs to be done first */
806 initialize_targets (); /* Setup target_terminal macros for utils.c */
807 initialize_utils (); /* Make errors and warnings possible */
808 initialize_all_files ();
809 initialize_current_architecture ();
810 init_main (); /* But that omits this file! Do it now */
812 /* The signal handling mechanism is different depending whether or
813 not the async version is run. NOTE: in the future we plan to make
814 the event loop be the default engine of gdb, and this difference
817 async_init_signals ();
821 /* We need a default language for parsing expressions, so simple things like
822 "set width 0" won't fail if no language is explicitly set in a config file
823 or implicitly set by reading an executable during startup. */
824 set_language (language_c
);
825 expected_language
= current_language
; /* don't warn about the change. */
828 /* Install the default UI */
829 uiout
= cli_out_new (gdb_stdout
);
833 /* All the interpreters should have had a look at things by now.
834 Initialize the selected interpreter. */
835 if (interpreter_p
&& !init_ui_hook
)
837 fprintf_unfiltered (gdb_stderr
, "Interpreter `%s' unrecognized.\n",
844 init_ui_hook (argv0
);
847 /* Allocate, initialize a new command line structure for one of the
848 control commands (if/while). */
850 static struct command_line
*
851 build_command_line (type
, args
)
852 enum command_control_type type
;
855 struct command_line
*cmd
;
858 error ("if/while commands require arguments.\n");
860 cmd
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
862 cmd
->control_type
= type
;
866 = (struct command_line
**) xmalloc (sizeof (struct command_line
*)
868 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
869 cmd
->line
= savestring (args
, strlen (args
));
873 /* Build and return a new command structure for the control commands
874 such as "if" and "while". */
876 static struct command_line
*
877 get_command_line (type
, arg
)
878 enum command_control_type type
;
881 struct command_line
*cmd
;
882 struct cleanup
*old_chain
= NULL
;
884 /* Allocate and build a new command line structure. */
885 cmd
= build_command_line (type
, arg
);
887 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
, &cmd
);
889 /* Read in the body of this command. */
890 if (recurse_read_control_structure (cmd
) == invalid_control
)
892 warning ("error reading in control structure\n");
893 do_cleanups (old_chain
);
897 discard_cleanups (old_chain
);
901 /* Recursively print a command (including full control structures). */
904 print_command_lines (uiout
, cmd
, depth
)
905 struct ui_out
*uiout
;
906 struct command_line
*cmd
;
909 struct command_line
*list
;
916 ui_out_spaces (uiout
, 2 * depth
);
918 /* A simple command, print it and continue. */
919 if (list
->control_type
== simple_control
)
921 ui_out_field_string (uiout
, NULL
, list
->line
);
922 ui_out_text (uiout
, "\n");
927 /* loop_continue to jump to the start of a while loop, print it
929 if (list
->control_type
== continue_control
)
931 ui_out_field_string (uiout
, NULL
, "loop_continue");
932 ui_out_text (uiout
, "\n");
937 /* loop_break to break out of a while loop, print it and continue. */
938 if (list
->control_type
== break_control
)
940 ui_out_field_string (uiout
, NULL
, "loop_break");
941 ui_out_text (uiout
, "\n");
946 /* A while command. Recursively print its subcommands and continue. */
947 if (list
->control_type
== while_control
)
949 ui_out_text (uiout
, "while ");
950 ui_out_field_fmt (uiout
, NULL
, "while %s", list
->line
);
951 ui_out_text (uiout
, "\n");
952 print_command_lines (uiout
, *list
->body_list
, depth
+ 1);
953 ui_out_field_string (uiout
, NULL
, "end");
955 ui_out_spaces (uiout
, 2 * depth
);
956 ui_out_text (uiout
, "end\n");
961 /* An if command. Recursively print both arms before continueing. */
962 if (list
->control_type
== if_control
)
964 ui_out_text (uiout
, "if ");
965 ui_out_field_fmt (uiout
, NULL
, "if %s", list
->line
);
966 ui_out_text (uiout
, "\n");
968 print_command_lines (uiout
, list
->body_list
[0], depth
+ 1);
970 /* Show the false arm if it exists. */
971 if (list
->body_count
== 2)
974 ui_out_spaces (uiout
, 2 * depth
);
975 ui_out_field_string (uiout
, NULL
, "else");
976 ui_out_text (uiout
, "else\n");
977 print_command_lines (uiout
, list
->body_list
[1], depth
+ 1);
980 ui_out_field_string (uiout
, NULL
, "end");
982 ui_out_spaces (uiout
, 2 * depth
);
983 ui_out_text (uiout
, "end\n");
988 /* ignore illegal command type and try next */
994 print_command_line (cmd
, depth
, stream
)
995 struct command_line
*cmd
;
997 struct ui_file
*stream
;
1003 for (i
= 0; i
< depth
; i
++)
1004 fputs_filtered (" ", stream
);
1007 /* A simple command, print it and return. */
1008 if (cmd
->control_type
== simple_control
)
1010 fputs_filtered (cmd
->line
, stream
);
1011 fputs_filtered ("\n", stream
);
1015 /* loop_continue to jump to the start of a while loop, print it
1017 if (cmd
->control_type
== continue_control
)
1019 fputs_filtered ("loop_continue\n", stream
);
1023 /* loop_break to break out of a while loop, print it and return. */
1024 if (cmd
->control_type
== break_control
)
1026 fputs_filtered ("loop_break\n", stream
);
1030 /* A while command. Recursively print its subcommands before returning. */
1031 if (cmd
->control_type
== while_control
)
1033 struct command_line
*list
;
1034 fputs_filtered ("while ", stream
);
1035 fputs_filtered (cmd
->line
, stream
);
1036 fputs_filtered ("\n", stream
);
1037 list
= *cmd
->body_list
;
1040 print_command_line (list
, depth
+ 1, stream
);
1045 /* An if command. Recursively print both arms before returning. */
1046 if (cmd
->control_type
== if_control
)
1048 fputs_filtered ("if ", stream
);
1049 fputs_filtered (cmd
->line
, stream
);
1050 fputs_filtered ("\n", stream
);
1052 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
1054 /* Show the false arm if it exists. */
1055 if (cmd
->body_count
== 2)
1059 for (i
= 0; i
< depth
; i
++)
1060 fputs_filtered (" ", stream
);
1062 fputs_filtered ("else\n", stream
);
1063 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
1067 for (i
= 0; i
< depth
; i
++)
1068 fputs_filtered (" ", stream
);
1070 fputs_filtered ("end\n", stream
);
1075 /* Execute the command in CMD. */
1077 enum command_control_type
1078 execute_control_command (cmd
)
1079 struct command_line
*cmd
;
1081 struct expression
*expr
;
1082 struct command_line
*current
;
1083 struct cleanup
*old_chain
= 0;
1087 enum command_control_type ret
;
1090 switch (cmd
->control_type
)
1092 case simple_control
:
1093 /* A simple command, execute it and return. */
1094 new_line
= insert_args (cmd
->line
);
1096 return invalid_control
;
1097 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1099 execute_command (new_line
, 0);
1100 ret
= cmd
->control_type
;
1103 case continue_control
:
1105 /* Return for "continue", and "break" so we can either
1106 continue the loop at the top, or break out. */
1107 ret
= cmd
->control_type
;
1112 /* Parse the loop control expression for the while statement. */
1113 new_line
= insert_args (cmd
->line
);
1115 return invalid_control
;
1116 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1118 expr
= parse_expression (new_line
);
1119 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
1121 ret
= simple_control
;
1124 /* Keep iterating so long as the expression is true. */
1131 /* Evaluate the expression. */
1132 val_mark
= value_mark ();
1133 val
= evaluate_expression (expr
);
1134 cond_result
= value_true (val
);
1135 value_free_to_mark (val_mark
);
1137 /* If the value is false, then break out of the loop. */
1141 /* Execute the body of the while statement. */
1142 current
= *cmd
->body_list
;
1145 ret
= execute_control_command (current
);
1147 /* If we got an error, or a "break" command, then stop
1149 if (ret
== invalid_control
|| ret
== break_control
)
1155 /* If we got a "continue" command, then restart the loop
1157 if (ret
== continue_control
)
1160 /* Get the next statement. */
1161 current
= current
->next
;
1165 /* Reset RET so that we don't recurse the break all the way down. */
1166 if (ret
== break_control
)
1167 ret
= simple_control
;
1174 new_line
= insert_args (cmd
->line
);
1176 return invalid_control
;
1177 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1179 /* Parse the conditional for the if statement. */
1180 expr
= parse_expression (new_line
);
1181 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
1184 ret
= simple_control
;
1186 /* Evaluate the conditional. */
1187 val_mark
= value_mark ();
1188 val
= evaluate_expression (expr
);
1190 /* Choose which arm to take commands from based on the value of the
1191 conditional expression. */
1192 if (value_true (val
))
1193 current
= *cmd
->body_list
;
1194 else if (cmd
->body_count
== 2)
1195 current
= *(cmd
->body_list
+ 1);
1196 value_free_to_mark (val_mark
);
1198 /* Execute commands in the given arm. */
1201 ret
= execute_control_command (current
);
1203 /* If we got an error, get out. */
1204 if (ret
!= simple_control
)
1207 /* Get the next statement in the body. */
1208 current
= current
->next
;
1215 warning ("Invalid control type in command structure.");
1216 return invalid_control
;
1220 do_cleanups (old_chain
);
1225 /* "while" command support. Executes a body of statements while the
1226 loop condition is nonzero. */
1229 while_command (arg
, from_tty
)
1233 struct command_line
*command
= NULL
;
1236 command
= get_command_line (while_control
, arg
);
1238 if (command
== NULL
)
1241 execute_control_command (command
);
1242 free_command_lines (&command
);
1245 /* "if" command support. Execute either the true or false arm depending
1246 on the value of the if conditional. */
1249 if_command (arg
, from_tty
)
1253 struct command_line
*command
= NULL
;
1256 command
= get_command_line (if_control
, arg
);
1258 if (command
== NULL
)
1261 execute_control_command (command
);
1262 free_command_lines (&command
);
1269 struct user_args
*oargs
= user_args
;
1271 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1273 user_args
= user_args
->next
;
1277 /* Bind the incomming arguments for a user defined command to
1278 $arg0, $arg1 ... $argMAXUSERARGS. */
1280 static struct cleanup
*
1284 struct user_args
*args
;
1285 struct cleanup
*old_chain
;
1286 unsigned int arg_count
= 0;
1288 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
1289 memset (args
, 0, sizeof (struct user_args
));
1291 args
->next
= user_args
;
1294 old_chain
= make_cleanup ((make_cleanup_func
) arg_cleanup
, 0);
1306 if (arg_count
>= MAXUSERARGS
)
1308 error ("user defined function may only have %d arguments.\n",
1313 /* Strip whitespace. */
1314 while (*p
== ' ' || *p
== '\t')
1317 /* P now points to an argument. */
1319 user_args
->a
[arg_count
].arg
= p
;
1321 /* Get to the end of this argument. */
1324 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1330 else if (*p
== '\\')
1353 user_args
->a
[arg_count
].len
= p
- start_arg
;
1360 /* Given character string P, return a point to the first argument ($arg),
1361 or NULL if P contains no arguments. */
1367 while ((p
= strchr (p
, '$')))
1369 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1376 /* Insert the user defined arguments stored in user_arg into the $arg
1377 arguments found in line, with the updated copy being placed into nline. */
1383 char *p
, *save_line
, *new_line
;
1386 /* First we need to know how much memory to allocate for the new line. */
1389 while ((p
= locate_arg (line
)))
1394 if (i
>= user_args
->count
)
1396 error ("Missing argument %d in user function.\n", i
);
1399 len
+= user_args
->a
[i
].len
;
1403 /* Don't forget the tail. */
1404 len
+= strlen (line
);
1406 /* Allocate space for the new line and fill it in. */
1407 new_line
= (char *) xmalloc (len
+ 1);
1408 if (new_line
== NULL
)
1411 /* Restore pointer to beginning of old line. */
1414 /* Save pointer to beginning of new line. */
1415 save_line
= new_line
;
1417 while ((p
= locate_arg (line
)))
1421 memcpy (new_line
, line
, p
- line
);
1422 new_line
+= p
- line
;
1425 len
= user_args
->a
[i
].len
;
1428 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1433 /* Don't forget the tail. */
1434 strcpy (new_line
, line
);
1436 /* Return a pointer to the beginning of the new line. */
1441 execute_user_command (c
, args
)
1442 struct cmd_list_element
*c
;
1445 register struct command_line
*cmdlines
;
1446 struct cleanup
*old_chain
;
1447 enum command_control_type ret
;
1449 old_chain
= setup_user_args (args
);
1451 cmdlines
= c
->user_commands
;
1456 /* Set the instream to 0, indicating execution of a
1457 user-defined function. */
1458 old_chain
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
1459 instream
= (FILE *) 0;
1462 ret
= execute_control_command (cmdlines
);
1463 if (ret
!= simple_control
&& ret
!= break_control
)
1465 warning ("Error in control structure.\n");
1468 cmdlines
= cmdlines
->next
;
1470 do_cleanups (old_chain
);
1473 /* Execute the line P as a command.
1474 Pass FROM_TTY as second argument to the defining function. */
1477 execute_command (p
, from_tty
)
1481 register struct cmd_list_element
*c
;
1482 register enum language flang
;
1483 static int warned
= 0;
1485 /* FIXME: These should really be in an appropriate header file */
1486 extern void serial_log_command
PARAMS ((const char *));
1490 /* Force cleanup of any alloca areas if using C alloca instead of
1491 a builtin alloca. */
1494 /* This can happen when command_line_input hits end of file. */
1498 serial_log_command (p
);
1500 while (*p
== ' ' || *p
== '\t')
1507 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1509 /* If the target is running, we allow only a limited set of
1511 if (event_loop_p
&& target_can_async_p () && target_executing
)
1512 if (!strcmp (c
->name
, "help")
1513 && !strcmp (c
->name
, "pwd")
1514 && !strcmp (c
->name
, "show")
1515 && !strcmp (c
->name
, "stop"))
1516 error ("Cannot execute this command while the target is running.");
1518 /* Pass null arg rather than an empty one. */
1521 /* Clear off trailing whitespace, except for set and complete command. */
1522 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1524 p
= arg
+ strlen (arg
) - 1;
1525 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1530 /* If this command has been hooked, run the hook first. */
1532 execute_user_command (c
->hook
, (char *) 0);
1534 if (c
->flags
& DEPRECATED_WARN_USER
)
1535 deprecated_cmd_warning (&line
);
1537 if (c
->class == class_user
)
1538 execute_user_command (c
, arg
);
1539 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1540 do_setshow_command (arg
, from_tty
& caution
, c
);
1541 else if (c
->function
.cfunc
== NO_FUNCTION
)
1542 error ("That is not a command, just a help topic.");
1543 else if (call_command_hook
)
1544 call_command_hook (c
, arg
, from_tty
& caution
);
1546 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1549 /* Tell the user if the language has changed (except first time). */
1550 if (current_language
!= expected_language
)
1552 if (language_mode
== language_mode_auto
)
1554 language_info (1); /* Print what changed. */
1559 /* Warn the user if the working language does not match the
1560 language of the current frame. Only warn the user if we are
1561 actually running the program, i.e. there is a stack. */
1562 /* FIXME: This should be cacheing the frame and only running when
1563 the frame changes. */
1565 if (target_has_stack
)
1567 flang
= get_frame_language ();
1569 && flang
!= language_unknown
1570 && flang
!= current_language
->la_language
)
1572 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1579 /* NOTE 1999-04-29: This function will be static again, once we modify
1580 gdb to use the event loop as the default command loop and we merge
1581 event-top.c into this file, top.c */
1583 command_loop_marker (foo
)
1588 /* Read commands from `instream' and execute them
1589 until end of file or error reading instream. */
1594 struct cleanup
*old_chain
;
1596 int stdin_is_tty
= ISATTY (stdin
);
1597 long time_at_cmd_start
;
1599 long space_at_cmd_start
= 0;
1601 extern int display_time
;
1602 extern int display_space
;
1604 while (instream
&& !feof (instream
))
1607 extern int insert_mode
;
1609 if (window_hook
&& instream
== stdin
)
1610 (*window_hook
) (instream
, get_prompt ());
1613 if (instream
== stdin
&& stdin_is_tty
)
1614 reinitialize_more_filter ();
1615 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1618 /* A bit of paranoia: I want to make sure the "insert_mode" global
1619 * is clear except when it is being used for command-line editing
1620 * (see tuiIO.c, utils.c); otherwise normal output will
1621 * get messed up in the TUI. So clear it before/after
1622 * the command-line-input call. - RT
1626 /* Get a command-line. This calls the readline package. */
1627 command
= command_line_input (instream
== stdin
?
1628 get_prompt () : (char *) NULL
,
1629 instream
== stdin
, "prompt");
1636 time_at_cmd_start
= get_run_time ();
1641 extern char **environ
;
1642 char *lim
= (char *) sbrk (0);
1644 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1648 execute_command (command
, instream
== stdin
);
1649 /* Do any commands attached to breakpoint we stopped at. */
1650 bpstat_do_actions (&stop_bpstat
);
1651 do_cleanups (old_chain
);
1655 long cmd_time
= get_run_time () - time_at_cmd_start
;
1657 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1658 cmd_time
/ 1000000, cmd_time
% 1000000);
1664 extern char **environ
;
1665 char *lim
= (char *) sbrk (0);
1666 long space_now
= lim
- (char *) &environ
;
1667 long space_diff
= space_now
- space_at_cmd_start
;
1669 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1671 (space_diff
>= 0 ? '+' : '-'),
1678 /* Read commands from `instream' and execute them until end of file or
1679 error reading instream. This command loop doesnt care about any
1680 such things as displaying time and space usage. If the user asks
1681 for those, they won't work. */
1683 simplified_command_loop (read_input_func
, execute_command_func
)
1684 char *(*read_input_func
) (char *);
1685 void (*execute_command_func
) (char *, int);
1687 struct cleanup
*old_chain
;
1689 int stdin_is_tty
= ISATTY (stdin
);
1691 while (instream
&& !feof (instream
))
1694 if (instream
== stdin
&& stdin_is_tty
)
1695 reinitialize_more_filter ();
1696 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1698 /* Get a command-line. */
1699 command
= (*read_input_func
) (instream
== stdin
?
1700 get_prompt () : (char *) NULL
);
1705 (*execute_command_func
) (command
, instream
== stdin
);
1707 /* Do any commands attached to breakpoint we stopped at. */
1708 bpstat_do_actions (&stop_bpstat
);
1710 do_cleanups (old_chain
);
1714 /* Commands call this if they do not want to be repeated by null lines. */
1722 /* If we aren't reading from standard input, we are saving the last
1723 thing read from stdin in line and don't want to delete it. Null lines
1724 won't repeat here in any case. */
1725 if (instream
== stdin
)
1729 /* Read a line from the stream "instream" without command line editing.
1731 It prints PROMPT_ARG once at the start.
1732 Action is compatible with "readline", e.g. space for the result is
1733 malloc'd and should be freed by the caller.
1735 A NULL return means end of file. */
1737 gdb_readline (prompt_arg
)
1742 int input_index
= 0;
1743 int result_size
= 80;
1747 /* Don't use a _filtered function here. It causes the assumed
1748 character position to be off, since the newline we read from
1749 the user is not accounted for. */
1750 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1752 /* Move to a new line so the entered line doesn't have a prompt
1753 on the front of it. */
1754 fputs_unfiltered ("\n", gdb_stdout
);
1756 gdb_flush (gdb_stdout
);
1759 result
= (char *) xmalloc (result_size
);
1763 /* Read from stdin if we are executing a user defined command.
1764 This is the right thing for prompt_for_continue, at least. */
1765 c
= fgetc (instream
? instream
: stdin
);
1769 if (input_index
> 0)
1770 /* The last line does not end with a newline. Return it, and
1771 if we are called again fgetc will still return EOF and
1772 we'll return NULL then. */
1779 #ifndef CRLF_SOURCE_FILES
1783 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1789 result
[input_index
++] = c
;
1790 while (input_index
>= result_size
)
1793 result
= (char *) xrealloc (result
, result_size
);
1797 result
[input_index
++] = '\0';
1801 /* Variables which control command line editing and history
1802 substitution. These variables are given default values at the end
1804 static int command_editing_p
;
1805 /* NOTE 1999-04-29: This variable will be static again, once we modify
1806 gdb to use the event loop as the default command loop and we merge
1807 event-top.c into this file, top.c */
1808 /* static */ int history_expansion_p
;
1809 static int write_history_p
;
1810 static int history_size
;
1811 static char *history_filename
;
1813 /* readline uses the word breaks for two things:
1814 (1) In figuring out where to point the TEXT parameter to the
1815 rl_completion_entry_function. Since we don't use TEXT for much,
1816 it doesn't matter a lot what the word breaks are for this purpose, but
1817 it does affect how much stuff M-? lists.
1818 (2) If one of the matches contains a word break character, readline
1819 will quote it. That's why we switch between
1820 gdb_completer_word_break_characters and
1821 gdb_completer_command_word_break_characters. I'm not sure when
1822 we need this behavior (perhaps for funky characters in C++ symbols?). */
1824 /* Variables which are necessary for fancy command line editing. */
1825 char *gdb_completer_word_break_characters
=
1826 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1828 /* When completing on command names, we remove '-' from the list of
1829 word break characters, since we use it in command names. If the
1830 readline library sees one in any of the current completion strings,
1831 it thinks that the string needs to be quoted and automatically supplies
1833 char *gdb_completer_command_word_break_characters
=
1834 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1836 /* Characters that can be used to quote completion strings. Note that we
1837 can't include '"' because the gdb C parser treats such quoted sequences
1839 char *gdb_completer_quote_characters
=
1842 /* Functions that are used as part of the fancy command line editing. */
1844 /* This can be used for functions which don't want to complete on symbols
1845 but don't want to complete on anything else either. */
1848 noop_completer (text
, prefix
)
1855 /* Complete on filenames. */
1857 filename_completer (text
, word
)
1861 /* From readline. */
1862 extern char *filename_completion_function
PARAMS ((char *, int));
1863 int subsequent_name
;
1865 int return_val_used
;
1866 int return_val_alloced
;
1868 return_val_used
= 0;
1869 /* Small for testing. */
1870 return_val_alloced
= 1;
1871 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1873 subsequent_name
= 0;
1877 p
= filename_completion_function (text
, subsequent_name
);
1878 if (return_val_used
>= return_val_alloced
)
1880 return_val_alloced
*= 2;
1882 (char **) xrealloc (return_val
,
1883 return_val_alloced
* sizeof (char *));
1887 return_val
[return_val_used
++] = p
;
1890 /* Like emacs, don't complete on old versions. Especially useful
1891 in the "source" command. */
1892 if (p
[strlen (p
) - 1] == '~')
1898 /* Return exactly p. */
1899 return_val
[return_val_used
++] = p
;
1900 else if (word
> text
)
1902 /* Return some portion of p. */
1903 q
= xmalloc (strlen (p
) + 5);
1904 strcpy (q
, p
+ (word
- text
));
1905 return_val
[return_val_used
++] = q
;
1910 /* Return some of TEXT plus p. */
1911 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1912 strncpy (q
, word
, text
- word
);
1913 q
[text
- word
] = '\0';
1915 return_val
[return_val_used
++] = q
;
1919 subsequent_name
= 1;
1922 /* There is no way to do this just long enough to affect quote inserting
1923 without also affecting the next completion. This should be fixed in
1925 /* Insure that readline does the right thing
1926 with respect to inserting quotes. */
1927 rl_completer_word_break_characters
= "";
1932 /* Here are some useful test cases for completion. FIXME: These should
1933 be put in the test suite. They should be tested with both M-? and TAB.
1935 "show output-" "radix"
1936 "show output" "-radix"
1937 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1938 "p " ambiguous (all symbols)
1939 "info t foo" no completions
1940 "info t " no completions
1941 "info t" ambiguous ("info target", "info terminal", etc.)
1942 "info ajksdlfk" no completions
1943 "info ajksdlfk " no completions
1945 "info " ambiguous (all info commands)
1946 "p \"a" no completions (string constant)
1947 "p 'a" ambiguous (all symbols starting with a)
1948 "p b-a" ambiguous (all symbols starting with a)
1949 "p b-" ambiguous (all symbols)
1950 "file Make" "file" (word break hard to screw up here)
1951 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1954 /* Generate completions one by one for the completer. Each time we are
1955 called return another potential completion to the caller.
1956 line_completion just completes on commands or passes the buck to the
1957 command's completer function, the stuff specific to symbol completion
1958 is in make_symbol_completion_list.
1960 TEXT is the caller's idea of the "word" we are looking at.
1962 MATCHES is the number of matches that have currently been collected from
1963 calling this completion function. When zero, then we need to initialize,
1964 otherwise the initialization has already taken place and we can just
1965 return the next potential completion string.
1967 LINE_BUFFER is available to be looked at; it contains the entire text
1968 of the line. POINT is the offset in that line of the cursor. You
1969 should pretend that the line ends at POINT.
1971 Returns NULL if there are no more completions, else a pointer to a string
1972 which is a possible completion, it is the caller's responsibility to
1976 line_completion_function (text
, matches
, line_buffer
, point
)
1982 static char **list
= (char **) NULL
; /* Cache of completions */
1983 static int index
; /* Next cached completion */
1984 char *output
= NULL
;
1985 char *tmp_command
, *p
;
1986 /* Pointer within tmp_command which corresponds to text. */
1988 struct cmd_list_element
*c
, *result_list
;
1992 /* The caller is beginning to accumulate a new set of completions, so
1993 we need to find all of them now, and cache them for returning one at
1994 a time on future calls. */
1998 /* Free the storage used by LIST, but not by the strings inside.
1999 This is because rl_complete_internal () frees the strings. */
2005 /* Choose the default set of word break characters to break completions.
2006 If we later find out that we are doing completions on command strings
2007 (as opposed to strings supplied by the individual command completer
2008 functions, which can be any string) then we will switch to the
2009 special word break set for command strings, which leaves out the
2010 '-' character used in some commands. */
2012 rl_completer_word_break_characters
=
2013 gdb_completer_word_break_characters
;
2015 /* Decide whether to complete on a list of gdb commands or on symbols. */
2016 tmp_command
= (char *) alloca (point
+ 1);
2019 strncpy (tmp_command
, line_buffer
, point
);
2020 tmp_command
[point
] = '\0';
2021 /* Since text always contains some number of characters leading up
2022 to point, we can find the equivalent position in tmp_command
2023 by subtracting that many characters from the end of tmp_command. */
2024 word
= tmp_command
+ point
- strlen (text
);
2028 /* An empty line we want to consider ambiguous; that is, it
2029 could be any command. */
2030 c
= (struct cmd_list_element
*) -1;
2035 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
2038 /* Move p up to the next interesting thing. */
2039 while (*p
== ' ' || *p
== '\t')
2046 /* It is an unrecognized command. So there are no
2047 possible completions. */
2050 else if (c
== (struct cmd_list_element
*) -1)
2054 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
2055 doesn't advance over that thing itself. Do so now. */
2057 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
2059 if (q
!= tmp_command
+ point
)
2061 /* There is something beyond the ambiguous
2062 command, so there are no possible completions. For
2063 example, "info t " or "info t foo" does not complete
2064 to anything, because "info t" can be "info target" or
2070 /* We're trying to complete on the command which was ambiguous.
2071 This we can deal with. */
2074 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
2079 list
= complete_on_cmdlist (cmdlist
, p
, word
);
2081 /* Insure that readline does the right thing with respect to
2082 inserting quotes. */
2083 rl_completer_word_break_characters
=
2084 gdb_completer_command_word_break_characters
;
2089 /* We've recognized a full command. */
2091 if (p
== tmp_command
+ point
)
2093 /* There is no non-whitespace in the line beyond the command. */
2095 if (p
[-1] == ' ' || p
[-1] == '\t')
2097 /* The command is followed by whitespace; we need to complete
2098 on whatever comes after command. */
2101 /* It is a prefix command; what comes after it is
2102 a subcommand (e.g. "info "). */
2103 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
2105 /* Insure that readline does the right thing
2106 with respect to inserting quotes. */
2107 rl_completer_word_break_characters
=
2108 gdb_completer_command_word_break_characters
;
2112 list
= complete_on_enum (c
->enums
, p
, word
);
2113 rl_completer_word_break_characters
=
2114 gdb_completer_command_word_break_characters
;
2118 /* It is a normal command; what comes after it is
2119 completed by the command's completer function. */
2120 list
= (*c
->completer
) (p
, word
);
2125 /* The command is not followed by whitespace; we need to
2126 complete on the command itself. e.g. "p" which is a
2127 command itself but also can complete to "print", "ptype"
2131 /* Find the command we are completing on. */
2133 while (q
> tmp_command
)
2135 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
2141 list
= complete_on_cmdlist (result_list
, q
, word
);
2143 /* Insure that readline does the right thing
2144 with respect to inserting quotes. */
2145 rl_completer_word_break_characters
=
2146 gdb_completer_command_word_break_characters
;
2151 /* There is non-whitespace beyond the command. */
2153 if (c
->prefixlist
&& !c
->allow_unknown
)
2155 /* It is an unrecognized subcommand of a prefix command,
2156 e.g. "info adsfkdj". */
2161 list
= complete_on_enum (c
->enums
, p
, word
);
2165 /* It is a normal command. */
2166 list
= (*c
->completer
) (p
, word
);
2172 /* If we found a list of potential completions during initialization then
2173 dole them out one at a time. The vector of completions is NULL
2174 terminated, so after returning the last one, return NULL (and continue
2175 to do so) each time we are called after that, until a new list is
2180 output
= list
[index
];
2188 /* Can't do this because readline hasn't yet checked the word breaks
2189 for figuring out whether to insert a quote. */
2191 /* Make sure the word break characters are set back to normal for the
2192 next time that readline tries to complete something. */
2193 rl_completer_word_break_characters
=
2194 gdb_completer_word_break_characters
;
2200 /* Line completion interface function for readline. */
2203 readline_line_completion_function (text
, matches
)
2207 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
2210 /* Skip over a possibly quoted word (as defined by the quote characters
2211 and word break characters the completer uses). Returns pointer to the
2212 location after the "word". */
2218 char quote_char
= '\0';
2221 for (scan
= str
; *scan
!= '\0'; scan
++)
2223 if (quote_char
!= '\0')
2225 /* Ignore everything until the matching close quote char */
2226 if (*scan
== quote_char
)
2228 /* Found matching close quote. */
2233 else if (strchr (gdb_completer_quote_characters
, *scan
))
2235 /* Found start of a quoted string. */
2238 else if (strchr (gdb_completer_word_break_characters
, *scan
))
2252 #if STOP_SIGNAL == SIGTSTP
2253 signal (SIGTSTP
, SIG_DFL
);
2255 kill (getpid (), SIGTSTP
);
2256 signal (SIGTSTP
, stop_sig
);
2258 signal (STOP_SIGNAL
, stop_sig
);
2260 printf_unfiltered ("%s", get_prompt ());
2261 gdb_flush (gdb_stdout
);
2263 /* Forget about any previous command -- null line now will do nothing. */
2266 #endif /* STOP_SIGNAL */
2268 /* Initialize signal handlers. */
2273 /* Under System V the default disposition of a signal is reinstated after
2274 the signal is caught and delivered to an application process. On such
2275 systems one must restore the replacement signal handler if one wishes
2276 to continue handling the signal in one's program. On BSD systems this
2277 is not needed but it is harmless, and it simplifies the code to just do
2278 it unconditionally. */
2279 signal (signo
, do_nothing
);
2285 signal (SIGINT
, request_quit
);
2287 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2288 to the inferior and breakpoints will be ignored. */
2290 signal (SIGTRAP
, SIG_DFL
);
2293 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2294 passed to the inferior, which we don't want. It would be
2295 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2296 on BSD4.3 systems using vfork, that can affect the
2297 GDB process as well as the inferior (the signal handling tables
2298 might be in memory, shared between the two). Since we establish
2299 a handler for SIGQUIT, when we call exec it will set the signal
2300 to SIG_DFL for us. */
2301 signal (SIGQUIT
, do_nothing
);
2303 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
2304 signal (SIGHUP
, disconnect
);
2306 signal (SIGFPE
, float_handler
);
2308 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2309 signal (SIGWINCH
, SIGWINCH_HANDLER
);
2313 /* Read one line from the command input stream `instream'
2314 into the local static buffer `linebuffer' (whose current length
2316 The buffer is made bigger as necessary.
2317 Returns the address of the start of the line.
2319 NULL is returned for end of file.
2321 *If* the instream == stdin & stdin is a terminal, the line read
2322 is copied into the file line saver (global var char *line,
2323 length linesize) so that it can be duplicated.
2325 This routine either uses fancy command line editing or
2326 simple input as the user has requested. */
2329 command_line_input (prompt_arg
, repeat
, annotation_suffix
)
2332 char *annotation_suffix
;
2334 static char *linebuffer
= 0;
2335 static unsigned linelength
= 0;
2339 char *local_prompt
= prompt_arg
;
2343 /* The annotation suffix must be non-NULL. */
2344 if (annotation_suffix
== NULL
)
2345 annotation_suffix
= "";
2347 if (annotation_level
> 1 && instream
== stdin
)
2349 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
2350 + strlen (annotation_suffix
) + 40);
2351 if (prompt_arg
== NULL
)
2352 local_prompt
[0] = '\0';
2354 strcpy (local_prompt
, prompt_arg
);
2355 strcat (local_prompt
, "\n\032\032");
2356 strcat (local_prompt
, annotation_suffix
);
2357 strcat (local_prompt
, "\n");
2360 if (linebuffer
== 0)
2363 linebuffer
= (char *) xmalloc (linelength
);
2368 /* Control-C quits instantly if typed while in this loop
2369 since it should not wait until the user types a newline. */
2375 signal (STOP_SIGNAL
, handle_stop_sig
);
2377 signal (STOP_SIGNAL
, stop_sig
);
2383 /* Make sure that all output has been output. Some machines may let
2384 you get away with leaving out some of the gdb_flush, but not all. */
2386 gdb_flush (gdb_stdout
);
2387 gdb_flush (gdb_stderr
);
2389 if (source_file_name
!= NULL
)
2391 ++source_line_number
;
2392 sprintf (source_error
,
2393 "%s%s:%d: Error in sourced command file:\n",
2396 source_line_number
);
2397 error_pre_print
= source_error
;
2400 if (annotation_level
> 1 && instream
== stdin
)
2402 printf_unfiltered ("\n\032\032pre-");
2403 printf_unfiltered (annotation_suffix
);
2404 printf_unfiltered ("\n");
2407 /* Don't use fancy stuff if not talking to stdin. */
2408 if (readline_hook
&& instream
== NULL
)
2410 rl
= (*readline_hook
) (local_prompt
);
2412 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2414 rl
= readline (local_prompt
);
2418 rl
= gdb_readline (local_prompt
);
2421 if (annotation_level
> 1 && instream
== stdin
)
2423 printf_unfiltered ("\n\032\032post-");
2424 printf_unfiltered (annotation_suffix
);
2425 printf_unfiltered ("\n");
2428 if (!rl
|| rl
== (char *) EOF
)
2433 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
2435 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
2436 nline
= (char *) xrealloc (linebuffer
, linelength
);
2437 p
+= nline
- linebuffer
;
2441 /* Copy line. Don't copy null at end. (Leaves line alone
2442 if this was just a newline) */
2446 free (rl
); /* Allocated in readline. */
2448 if (p
== linebuffer
|| *(p
- 1) != '\\')
2451 p
--; /* Put on top of '\'. */
2452 local_prompt
= (char *) 0;
2457 signal (STOP_SIGNAL
, SIG_DFL
);
2464 #define SERVER_COMMAND_LENGTH 7
2466 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2467 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2470 /* Note that we don't set `line'. Between this and the check in
2471 dont_repeat, this insures that repeating will still do the
2474 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2477 /* Do history expansion if that is wished. */
2478 if (history_expansion_p
&& instream
== stdin
2479 && ISATTY (instream
))
2481 char *history_value
;
2484 *p
= '\0'; /* Insert null now. */
2485 expanded
= history_expand (linebuffer
, &history_value
);
2488 /* Print the changes. */
2489 printf_unfiltered ("%s\n", history_value
);
2491 /* If there was an error, call this function again. */
2494 free (history_value
);
2495 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2497 if (strlen (history_value
) > linelength
)
2499 linelength
= strlen (history_value
) + 1;
2500 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2502 strcpy (linebuffer
, history_value
);
2503 p
= linebuffer
+ strlen (linebuffer
);
2504 free (history_value
);
2508 /* If we just got an empty line, and that is supposed
2509 to repeat the previous command, return the value in the
2511 if (repeat
&& p
== linebuffer
)
2513 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
2519 /* Add line to history if appropriate. */
2520 if (instream
== stdin
2521 && ISATTY (stdin
) && *linebuffer
)
2522 add_history (linebuffer
);
2524 /* Note: lines consisting solely of comments are added to the command
2525 history. This is useful when you type a command, and then
2526 realize you don't want to execute it quite yet. You can comment
2527 out the command and then later fetch it from the value history
2528 and remove the '#'. The kill ring is probably better, but some
2529 people are in the habit of commenting things out. */
2531 *p1
= '\0'; /* Found a comment. */
2533 /* Save into global buffer if appropriate. */
2536 if (linelength
> linesize
)
2538 line
= xrealloc (line
, linelength
);
2539 linesize
= linelength
;
2541 strcpy (line
, linebuffer
);
2549 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2550 code bodies. This is typically used when we encounter an "else"
2551 clause for an "if" command. */
2554 realloc_body_list (command
, new_length
)
2555 struct command_line
*command
;
2559 struct command_line
**body_list
;
2561 n
= command
->body_count
;
2563 /* Nothing to do? */
2564 if (new_length
<= n
)
2567 body_list
= (struct command_line
**)
2568 xmalloc (sizeof (struct command_line
*) * new_length
);
2570 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2572 free (command
->body_list
);
2573 command
->body_list
= body_list
;
2574 command
->body_count
= new_length
;
2577 /* Read one line from the input stream. If the command is an "else" or
2578 "end", return such an indication to the caller. */
2580 static enum misc_command_type
2581 read_next_line (command
)
2582 struct command_line
**command
;
2584 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2587 if (control_level
>= 254)
2588 error ("Control nesting too deep!\n");
2590 /* Set a prompt based on the nesting of the control commands. */
2591 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2593 for (i
= 0; i
< control_level
; i
++)
2594 control_prompt
[i
] = ' ';
2595 control_prompt
[i
] = '>';
2596 control_prompt
[i
+ 1] = '\0';
2597 prompt_ptr
= (char *) &control_prompt
[0];
2602 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2604 /* Not sure what to do here. */
2608 /* Strip leading and trailing whitespace. */
2609 while (*p
== ' ' || *p
== '\t')
2612 p1
= p
+ strlen (p
);
2613 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2616 /* Blanks and comments don't really do anything, but we need to
2617 distinguish them from else, end and other commands which can be
2619 if (p1
== p
|| p
[0] == '#')
2622 /* Is this the end of a simple, while, or if control structure? */
2623 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2626 /* Is the else clause of an if control structure? */
2627 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2628 return else_command
;
2630 /* Check for while, if, break, continue, etc and build a new command
2631 line structure for them. */
2632 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2633 *command
= build_command_line (while_control
, p
+ 6);
2634 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2635 *command
= build_command_line (if_control
, p
+ 3);
2636 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2638 *command
= (struct command_line
*)
2639 xmalloc (sizeof (struct command_line
));
2640 (*command
)->next
= NULL
;
2641 (*command
)->line
= NULL
;
2642 (*command
)->control_type
= break_control
;
2643 (*command
)->body_count
= 0;
2644 (*command
)->body_list
= NULL
;
2646 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2648 *command
= (struct command_line
*)
2649 xmalloc (sizeof (struct command_line
));
2650 (*command
)->next
= NULL
;
2651 (*command
)->line
= NULL
;
2652 (*command
)->control_type
= continue_control
;
2653 (*command
)->body_count
= 0;
2654 (*command
)->body_list
= NULL
;
2658 /* A normal command. */
2659 *command
= (struct command_line
*)
2660 xmalloc (sizeof (struct command_line
));
2661 (*command
)->next
= NULL
;
2662 (*command
)->line
= savestring (p
, p1
- p
);
2663 (*command
)->control_type
= simple_control
;
2664 (*command
)->body_count
= 0;
2665 (*command
)->body_list
= NULL
;
2668 /* Nothing special. */
2672 /* Recursively read in the control structures and create a command_line
2673 structure from them.
2675 The parent_control parameter is the control structure in which the
2676 following commands are nested. */
2678 static enum command_control_type
2679 recurse_read_control_structure (current_cmd
)
2680 struct command_line
*current_cmd
;
2682 int current_body
, i
;
2683 enum misc_command_type val
;
2684 enum command_control_type ret
;
2685 struct command_line
**body_ptr
, *child_tail
, *next
;
2690 /* Sanity checks. */
2691 if (current_cmd
->control_type
== simple_control
)
2693 error ("Recursed on a simple control type\n");
2694 return invalid_control
;
2697 if (current_body
> current_cmd
->body_count
)
2699 error ("Allocated body is smaller than this command type needs\n");
2700 return invalid_control
;
2703 /* Read lines from the input stream and build control structures. */
2709 val
= read_next_line (&next
);
2711 /* Just skip blanks and comments. */
2712 if (val
== nop_command
)
2715 if (val
== end_command
)
2717 if (current_cmd
->control_type
== while_control
2718 || current_cmd
->control_type
== if_control
)
2720 /* Success reading an entire control structure. */
2721 ret
= simple_control
;
2726 ret
= invalid_control
;
2731 /* Not the end of a control structure. */
2732 if (val
== else_command
)
2734 if (current_cmd
->control_type
== if_control
2735 && current_body
== 1)
2737 realloc_body_list (current_cmd
, 2);
2744 ret
= invalid_control
;
2751 child_tail
->next
= next
;
2755 body_ptr
= current_cmd
->body_list
;
2756 for (i
= 1; i
< current_body
; i
++)
2765 /* If the latest line is another control structure, then recurse
2767 if (next
->control_type
== while_control
2768 || next
->control_type
== if_control
)
2771 ret
= recurse_read_control_structure (next
);
2774 if (ret
!= simple_control
)
2784 /* Read lines from the input stream and accumulate them in a chain of
2785 struct command_line's, which is then returned. For input from a
2786 terminal, the special command "end" is used to mark the end of the
2787 input, and is not included in the returned chain of commands. */
2789 #define END_MESSAGE "End with a line saying just \"end\"."
2791 struct command_line
*
2792 read_command_lines (prompt_arg
, from_tty
)
2796 struct command_line
*head
, *tail
, *next
;
2797 struct cleanup
*old_chain
;
2798 enum command_control_type ret
;
2799 enum misc_command_type val
;
2802 if (readline_begin_hook
)
2804 /* Note - intentional to merge messages with no newline */
2805 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2807 else if (from_tty
&& input_from_terminal_p ())
2809 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2810 gdb_flush (gdb_stdout
);
2818 val
= read_next_line (&next
);
2820 /* Ignore blank lines or comments. */
2821 if (val
== nop_command
)
2824 if (val
== end_command
)
2826 ret
= simple_control
;
2830 if (val
!= ok_command
)
2832 ret
= invalid_control
;
2836 if (next
->control_type
== while_control
2837 || next
->control_type
== if_control
)
2840 ret
= recurse_read_control_structure (next
);
2843 if (ret
== invalid_control
)
2854 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
,
2864 if (ret
!= invalid_control
)
2866 discard_cleanups (old_chain
);
2869 do_cleanups (old_chain
);
2872 if (readline_end_hook
)
2874 (*readline_end_hook
) ();
2879 /* Free a chain of struct command_line's. */
2882 free_command_lines (lptr
)
2883 struct command_line
**lptr
;
2885 register struct command_line
*l
= *lptr
;
2886 register struct command_line
*next
;
2887 struct command_line
**blist
;
2892 if (l
->body_count
> 0)
2894 blist
= l
->body_list
;
2895 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2896 free_command_lines (blist
);
2905 /* Add an element to the list of info subcommands. */
2907 struct cmd_list_element
*
2908 add_info (name
, fun
, doc
)
2910 void (*fun
) PARAMS ((char *, int));
2913 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2916 /* Add an alias to the list of info subcommands. */
2918 struct cmd_list_element
*
2919 add_info_alias (name
, oldname
, abbrev_flag
)
2924 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2927 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2928 Therefore, its own definition is called only for "info" with no args. */
2932 info_command (arg
, from_tty
)
2936 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2937 help_list (infolist
, "info ", -1, gdb_stdout
);
2940 /* The "complete" command is used by Emacs to implement completion. */
2944 complete_command (arg
, from_tty
)
2956 argpoint
= strlen (arg
);
2958 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2960 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2962 printf_unfiltered ("%s\n", completion
);
2967 /* The "show" command with no arguments shows all the settings. */
2971 show_command (arg
, from_tty
)
2975 cmd_show_list (showlist
, from_tty
, "");
2978 /* Add an element to the list of commands. */
2980 struct cmd_list_element
*
2981 add_com (name
, class, fun
, doc
)
2983 enum command_class
class;
2984 void (*fun
) PARAMS ((char *, int));
2987 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
2990 /* Add an alias or abbreviation command to the list of commands. */
2992 struct cmd_list_element
*
2993 add_com_alias (name
, oldname
, class, abbrev_flag
)
2996 enum command_class
class;
2999 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
3006 error ("Argument required (%s).", why
);
3011 help_command (command
, from_tty
)
3013 int from_tty
; /* Ignored */
3015 help_cmd (command
, gdb_stdout
);
3019 validate_comname (comname
)
3025 error_no_arg ("name of command to define");
3030 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
3031 error ("Junk in argument list: \"%s\"", p
);
3036 /* This is just a placeholder in the command data structures. */
3038 user_defined_command (ignore
, from_tty
)
3045 define_command (comname
, from_tty
)
3049 register struct command_line
*cmds
;
3050 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
3051 char *tem
= comname
;
3053 #define HOOK_STRING "hook-"
3056 validate_comname (comname
);
3058 /* Look it up, and verify that we got an exact match. */
3059 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
3060 if (c
&& !STREQ (comname
, c
->name
))
3065 if (c
->class == class_user
|| c
->class == class_alias
)
3066 tem
= "Redefine command \"%s\"? ";
3068 tem
= "Really redefine built-in command \"%s\"? ";
3069 if (!query (tem
, c
->name
))
3070 error ("Command \"%s\" not redefined.", c
->name
);
3073 /* If this new command is a hook, then mark the command which it
3074 is hooking. Note that we allow hooking `help' commands, so that
3075 we can hook the `stop' pseudo-command. */
3077 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
3079 /* Look up cmd it hooks, and verify that we got an exact match. */
3080 tem
= comname
+ HOOK_LEN
;
3081 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
3082 if (hookc
&& !STREQ (comname
+ HOOK_LEN
, hookc
->name
))
3086 warning ("Your new `%s' command does not hook any existing command.",
3088 if (!query ("Proceed? "))
3089 error ("Not confirmed.");
3093 comname
= savestring (comname
, strlen (comname
));
3095 /* If the rest of the commands will be case insensitive, this one
3096 should behave in the same manner. */
3097 for (tem
= comname
; *tem
; tem
++)
3099 *tem
= tolower (*tem
);
3101 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
3102 cmds
= read_command_lines (tmpbuf
, from_tty
);
3104 if (c
&& c
->class == class_user
)
3105 free_command_lines (&c
->user_commands
);
3107 newc
= add_cmd (comname
, class_user
, user_defined_command
,
3108 (c
&& c
->class == class_user
)
3109 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
3110 newc
->user_commands
= cmds
;
3112 /* If this new command is a hook, then mark both commands as being
3116 hookc
->hook
= newc
; /* Target gets hooked. */
3117 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
3122 document_command (comname
, from_tty
)
3126 struct command_line
*doclines
;
3127 register struct cmd_list_element
*c
;
3128 char *tem
= comname
;
3131 validate_comname (comname
);
3133 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
3135 if (c
->class != class_user
)
3136 error ("Command \"%s\" is built-in.", comname
);
3138 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
3139 doclines
= read_command_lines (tmpbuf
, from_tty
);
3145 register struct command_line
*cl1
;
3146 register int len
= 0;
3148 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
3149 len
+= strlen (cl1
->line
) + 1;
3151 c
->doc
= (char *) xmalloc (len
+ 1);
3154 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
3156 strcat (c
->doc
, cl1
->line
);
3158 strcat (c
->doc
, "\n");
3162 free_command_lines (&doclines
);
3165 /* Print the GDB banner. */
3167 print_gdb_version (stream
)
3168 struct ui_file
*stream
;
3170 /* From GNU coding standards, first line is meant to be easy for a
3171 program to parse, and is just canonical program name and version
3172 number, which starts after last space. */
3175 /* Print it console style until a format is defined */
3176 fprintf_filtered (stream
, "GNU gdb %s (UI_OUT)\n", version
);
3178 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
3181 /* Second line is a copyright notice. */
3183 fprintf_filtered (stream
, "Copyright 2000 Free Software Foundation, Inc.\n");
3185 /* Following the copyright is a brief statement that the program is
3186 free software, that users are free to copy and change it on
3187 certain conditions, that it is covered by the GNU GPL, and that
3188 there is no warranty. */
3190 fprintf_filtered (stream
, "\
3191 GDB is free software, covered by the GNU General Public License, and you are\n\
3192 welcome to change it and/or distribute copies of it under certain conditions.\n\
3193 Type \"show copying\" to see the conditions.\n\
3194 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
3196 /* After the required info we print the configuration information. */
3198 fprintf_filtered (stream
, "This GDB was configured as \"");
3199 if (!STREQ (host_name
, target_name
))
3201 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
3205 fprintf_filtered (stream
, "%s", host_name
);
3207 fprintf_filtered (stream
, "\".");
3212 show_version (args
, from_tty
)
3217 print_gdb_version (gdb_stdout
);
3218 printf_filtered ("\n");
3222 /* get_prompt: access method for the GDB prompt string. */
3224 #define MAX_PROMPT_SIZE 256
3227 * int get_prompt_1 (char * buf);
3229 * Work-horse for get_prompt (called via catch_errors).
3230 * Argument is buffer to hold the formatted prompt.
3232 * Returns: 1 for success (use formatted prompt)
3233 * 0 for failure (use gdb_prompt_string).
3236 static int gdb_prompt_escape
;
3239 get_prompt_1 (formatted_prompt
)
3240 char *formatted_prompt
;
3245 local_prompt
= PROMPT (0);
3247 local_prompt
= gdb_prompt_string
;
3250 if (gdb_prompt_escape
== 0)
3252 return 0; /* do no formatting */
3255 /* formatted prompt */
3257 char fmt
[40], *promptp
, *outp
, *tmp
;
3264 struct type
*arg_type
, *elt_type
;
3266 promptp
= local_prompt
;
3267 outp
= formatted_prompt
;
3269 while (*promptp
!= '\0')
3271 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
3273 if (*promptp
!= gdb_prompt_escape
)
3275 if (available
>= 1) /* overflow protect */
3276 *outp
++ = *promptp
++;
3280 /* GDB prompt string contains escape char. Parse for arg.
3281 Two consecutive escape chars followed by arg followed by
3282 a comma means to insert the arg using a default format.
3283 Otherwise a printf format string may be included between
3284 the two escape chars. eg:
3285 %%foo, insert foo using default format
3286 %2.2f%foo, insert foo using "%2.2f" format
3287 A mismatch between the format string and the data type
3288 of "foo" is an error (which we don't know how to protect
3291 fmt
[0] = '\0'; /* assume null format string */
3292 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
3294 promptp
+= 2; /* skip past two escape chars. */
3298 /* extract format string from between two esc chars */
3302 fmt
[i
++] = *promptp
++; /* copy format string */
3304 while (i
< sizeof (fmt
) - 1 &&
3305 *promptp
!= gdb_prompt_escape
&&
3308 if (*promptp
!= gdb_prompt_escape
)
3309 error ("Syntax error at prompt position %d",
3310 promptp
- local_prompt
);
3313 promptp
++; /* skip second escape char */
3314 fmt
[i
++] = '\0'; /* terminate the format string */
3318 arg_val
= parse_to_comma_and_eval (&promptp
);
3319 if (*promptp
== ',')
3320 promptp
++; /* skip past the comma */
3321 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
3322 switch (TYPE_CODE (arg_type
))
3324 case TYPE_CODE_ARRAY
:
3325 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3326 if (TYPE_LENGTH (arg_type
) > 0 &&
3327 TYPE_LENGTH (elt_type
) == 1 &&
3328 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
3330 int len
= TYPE_LENGTH (arg_type
);
3332 if (VALUE_LAZY (arg_val
))
3333 value_fetch_lazy (arg_val
);
3334 tmp
= VALUE_CONTENTS (arg_val
);
3336 if (len
> available
)
3337 len
= available
; /* overflow protect */
3339 /* FIXME: how to protect GDB from crashing
3340 from bad user-supplied format string? */
3342 sprintf (outp
, fmt
, tmp
);
3344 strncpy (outp
, tmp
, len
);
3349 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3350 addrval
= value_as_pointer (arg_val
);
3352 if (TYPE_LENGTH (elt_type
) == 1 &&
3353 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
3356 /* display it as a string */
3357 char *default_fmt
= "%s";
3361 /* Limiting the number of bytes that the following call
3362 will read protects us from sprintf overflow later. */
3363 i
= target_read_string (addrval
, /* src */
3365 available
, /* len */
3367 if (err
) /* read failed */
3368 error ("%s on target_read", safe_strerror (err
));
3370 tmp
[i
] = '\0'; /* force-terminate string */
3371 /* FIXME: how to protect GDB from crashing
3372 from bad user-supplied format string? */
3373 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3379 /* display it as a pointer */
3380 char *default_fmt
= "0x%x";
3382 /* FIXME: how to protect GDB from crashing
3383 from bad user-supplied format string? */
3384 if (available
>= 16 /*? */ ) /* overflow protect */
3385 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3391 char *default_fmt
= "%g";
3393 doubleval
= value_as_double (arg_val
);
3394 /* FIXME: how to protect GDB from crashing
3395 from bad user-supplied format string? */
3396 if (available
>= 16 /*? */ ) /* overflow protect */
3397 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3398 (double) doubleval
);
3403 char *default_fmt
= "%d";
3405 longval
= value_as_long (arg_val
);
3406 /* FIXME: how to protect GDB from crashing
3407 from bad user-supplied format string? */
3408 if (available
>= 16 /*? */ ) /* overflow protect */
3409 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3413 case TYPE_CODE_BOOL
:
3415 /* no default format for bool */
3416 longval
= value_as_long (arg_val
);
3417 if (available
>= 8 /*? */ ) /* overflow protect */
3420 strcpy (outp
, "<true>");
3422 strcpy (outp
, "<false>");
3426 case TYPE_CODE_ENUM
:
3428 /* no default format for enum */
3429 longval
= value_as_long (arg_val
);
3430 len
= TYPE_NFIELDS (arg_type
);
3431 /* find enum name if possible */
3432 for (i
= 0; i
< len
; i
++)
3433 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3434 break; /* match -- end loop */
3436 if (i
< len
) /* enum name found */
3438 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3440 strncpy (outp
, name
, available
);
3441 /* in casel available < strlen (name), */
3442 outp
[available
] = '\0';
3446 if (available
>= 16 /*? */ ) /* overflow protect */
3447 sprintf (outp
, "%ld", (long) longval
);
3451 case TYPE_CODE_VOID
:
3453 break; /* void type -- no output */
3455 error ("bad data type at prompt position %d",
3456 promptp
- local_prompt
);
3459 outp
+= strlen (outp
);
3462 *outp
++ = '\0'; /* terminate prompt string */
3470 static char buf
[MAX_PROMPT_SIZE
];
3472 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3475 return &buf
[0]; /* successful formatted prompt */
3479 /* Prompt could not be formatted. */
3483 return gdb_prompt_string
;
3491 /* ??rehrauer: I don't know why this fails, since it looks as though
3492 assignments to prompt are wrapped in calls to savestring...
3497 PROMPT (0) = savestring (s
, strlen (s
));
3499 gdb_prompt_string
= savestring (s
, strlen (s
));
3503 /* If necessary, make the user confirm that we should quit. Return
3504 non-zero if we should quit, zero if we shouldn't. */
3509 if (inferior_pid
!= 0 && target_has_execution
)
3513 /* This is something of a hack. But there's no reliable way to
3514 see if a GUI is running. The `use_windows' variable doesn't
3517 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3518 else if (attach_flag
)
3519 s
= "The program is running. Quit anyway (and detach it)? ";
3521 s
= "The program is running. Exit anyway? ";
3530 /* Quit without asking for confirmation. */
3533 quit_force (args
, from_tty
)
3539 /* An optional expression may be used to cause gdb to terminate with the
3540 value of that expression. */
3543 value_ptr val
= parse_and_eval (args
);
3545 exit_code
= (int) value_as_long (val
);
3548 if (inferior_pid
!= 0 && target_has_execution
)
3551 target_detach (args
, from_tty
);
3556 /* UDI wants this, to kill the TIP. */
3559 /* Save the history information if it is appropriate to do so. */
3560 if (write_history_p
&& history_filename
)
3561 write_history (history_filename
);
3563 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3566 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3567 /* The above does not need to be inside a tuiDo(), since
3568 * it is not manipulating the curses screen, but rather,
3569 * it is tearing it down.
3578 /* Handle the quit command. */
3581 quit_command (args
, from_tty
)
3585 if (!quit_confirm ())
3586 error ("Not confirmed.");
3587 quit_force (args
, from_tty
);
3590 /* Returns whether GDB is running on a terminal and whether the user
3591 desires that questions be asked of them on that terminal. */
3594 input_from_terminal_p ()
3596 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3601 pwd_command (args
, from_tty
)
3606 error ("The \"pwd\" command does not take an argument: %s", args
);
3607 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3609 if (!STREQ (gdb_dirbuf
, current_directory
))
3610 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3611 current_directory
, gdb_dirbuf
);
3613 printf_unfiltered ("Working directory %s.\n", current_directory
);
3617 cd_command (dir
, from_tty
)
3622 /* Found something other than leading repetitions of "/..". */
3623 int found_real_path
;
3626 /* If the new directory is absolute, repeat is a no-op; if relative,
3627 repeat might be useful but is more likely to be a mistake. */
3631 error_no_arg ("new working directory");
3633 dir
= tilde_expand (dir
);
3634 make_cleanup (free
, dir
);
3636 if (chdir (dir
) < 0)
3637 perror_with_name (dir
);
3639 #if defined(_WIN32) || defined(__MSDOS__)
3640 /* There's too much mess with DOSish names like "d:", "d:.",
3641 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3642 simply get the canonicalized name of the current directory. */
3643 dir
= getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3647 if (SLASH_P (dir
[len
- 1]))
3649 /* Remove the trailing slash unless this is a root directory
3650 (including a drive letter on non-Unix systems). */
3651 if (!(len
== 1) /* "/" */
3652 #if defined(_WIN32) || defined(__MSDOS__)
3653 && !(!SLASH_P (*dir
) && ROOTED_P (dir
) && len
<= 3) /* "d:/" */
3659 dir
= savestring (dir
, len
);
3661 current_directory
= dir
;
3664 if (SLASH_P (current_directory
[strlen (current_directory
) - 1]))
3665 current_directory
= concat (current_directory
, dir
, NULL
);
3667 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3671 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3673 found_real_path
= 0;
3674 for (p
= current_directory
; *p
;)
3676 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3678 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3679 && (p
[3] == 0 || SLASH_P (p
[3])))
3681 if (found_real_path
)
3683 /* Search backwards for the directory just before the "/.."
3684 and obliterate it and the "/..". */
3686 while (q
!= current_directory
&& !SLASH_P (q
[-1]))
3689 if (q
== current_directory
)
3690 /* current_directory is
3691 a relative pathname ("can't happen"--leave it alone). */
3695 strcpy (q
- 1, p
+ 3);
3700 /* We are dealing with leading repetitions of "/..", for example
3701 "/../..", which is the Mach super-root. */
3706 found_real_path
= 1;
3711 forget_cached_source_info ();
3714 pwd_command ((char *) 0, 1);
3717 struct source_cleanup_lines_args
3721 char *old_pre_error
;
3722 char *old_error_pre_print
;
3726 source_cleanup_lines (args
)
3729 struct source_cleanup_lines_args
*p
=
3730 (struct source_cleanup_lines_args
*) args
;
3731 source_line_number
= p
->old_line
;
3732 source_file_name
= p
->old_file
;
3733 source_pre_error
= p
->old_pre_error
;
3734 error_pre_print
= p
->old_error_pre_print
;
3739 source_command (args
, from_tty
)
3744 struct cleanup
*old_cleanups
;
3746 struct source_cleanup_lines_args old_lines
;
3751 error ("source command requires pathname of file to source.");
3754 file
= tilde_expand (file
);
3755 old_cleanups
= make_cleanup (free
, file
);
3757 stream
= fopen (file
, FOPEN_RT
);
3761 perror_with_name (file
);
3766 make_cleanup ((make_cleanup_func
) fclose
, stream
);
3768 old_lines
.old_line
= source_line_number
;
3769 old_lines
.old_file
= source_file_name
;
3770 old_lines
.old_pre_error
= source_pre_error
;
3771 old_lines
.old_error_pre_print
= error_pre_print
;
3772 make_cleanup (source_cleanup_lines
, &old_lines
);
3773 source_line_number
= 0;
3774 source_file_name
= file
;
3775 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3776 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3777 make_cleanup (free
, source_pre_error
);
3778 /* This will get set every time we read a line. So it won't stay "" for
3780 error_pre_print
= "";
3782 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3783 if (source_error_allocated
< needed_length
)
3785 source_error_allocated
*= 2;
3786 if (source_error_allocated
< needed_length
)
3787 source_error_allocated
= needed_length
;
3788 if (source_error
== NULL
)
3789 source_error
= xmalloc (source_error_allocated
);
3791 source_error
= xrealloc (source_error
, source_error_allocated
);
3794 read_command_file (stream
);
3796 do_cleanups (old_cleanups
);
3801 echo_command (text
, from_tty
)
3809 while ((c
= *p
++) != '\0')
3813 /* \ at end of argument is used after spaces
3814 so they won't be lost. */
3818 c
= parse_escape (&p
);
3820 printf_filtered ("%c", c
);
3823 printf_filtered ("%c", c
);
3826 /* Force this output to appear now. */
3828 gdb_flush (gdb_stdout
);
3833 dont_repeat_command (ignored
, from_tty
)
3837 *line
= 0; /* Can't call dont_repeat here because we're not
3838 necessarily reading from stdin. */
3841 /* Functions to manipulate command line editing control variables. */
3843 /* Number of commands to print in each call to show_commands. */
3844 #define Hist_print 10
3846 show_commands (args
, from_tty
)
3850 /* Index for history commands. Relative to history_base. */
3853 /* Number of the history entry which we are planning to display next.
3854 Relative to history_base. */
3857 /* The first command in the history which doesn't exist (i.e. one more
3858 than the number of the last command). Relative to history_base. */
3861 extern HIST_ENTRY
*history_get
PARAMS ((int));
3863 /* Print out some of the commands from the command history. */
3864 /* First determine the length of the history list. */
3865 hist_len
= history_size
;
3866 for (offset
= 0; offset
< history_size
; offset
++)
3868 if (!history_get (history_base
+ offset
))
3877 if (args
[0] == '+' && args
[1] == '\0')
3878 /* "info editing +" should print from the stored position. */
3881 /* "info editing <exp>" should print around command number <exp>. */
3882 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
3884 /* "show commands" means print the last Hist_print commands. */
3887 num
= hist_len
- Hist_print
;
3893 /* If there are at least Hist_print commands, we want to display the last
3894 Hist_print rather than, say, the last 6. */
3895 if (hist_len
- num
< Hist_print
)
3897 num
= hist_len
- Hist_print
;
3902 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3904 printf_filtered ("%5d %s\n", history_base
+ offset
,
3905 (history_get (history_base
+ offset
))->line
);
3908 /* The next command we want to display is the next one that we haven't
3912 /* If the user repeats this command with return, it should do what
3913 "show commands +" does. This is unnecessary if arg is null,
3914 because "show commands +" is not useful after "show commands". */
3915 if (from_tty
&& args
)
3922 /* Called by do_setshow_command. */
3925 set_history_size_command (args
, from_tty
, c
)
3928 struct cmd_list_element
*c
;
3930 if (history_size
== INT_MAX
)
3931 unstifle_history ();
3932 else if (history_size
>= 0)
3933 stifle_history (history_size
);
3936 history_size
= INT_MAX
;
3937 error ("History size must be non-negative");
3943 set_history (args
, from_tty
)
3947 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3948 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3953 show_history (args
, from_tty
)
3957 cmd_show_list (showhistlist
, from_tty
, "");
3960 int info_verbose
= 0; /* Default verbose msgs off */
3962 /* Called by do_setshow_command. An elaborate joke. */
3965 set_verbose (args
, from_tty
, c
)
3968 struct cmd_list_element
*c
;
3970 char *cmdname
= "verbose";
3971 struct cmd_list_element
*showcmd
;
3973 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3977 c
->doc
= "Set verbose printing of informational messages.";
3978 showcmd
->doc
= "Show verbose printing of informational messages.";
3982 c
->doc
= "Set verbosity.";
3983 showcmd
->doc
= "Show verbosity.";
3988 float_handler (signo
)
3991 /* This message is based on ANSI C, section 4.7. Note that integer
3992 divide by zero causes this, so "float" is a misnomer. */
3993 signal (SIGFPE
, float_handler
);
3994 error ("Erroneous arithmetic operation.");
3998 set_debug (arg
, from_tty
)
4002 printf_unfiltered ("\"set debug\" must be followed by the name of a print subcommand.\n");
4003 help_list (setdebuglist
, "set debug ", -1, gdb_stdout
);
4007 show_debug (args
, from_tty
)
4011 cmd_show_list (showdebuglist
, from_tty
, "");
4024 enablebreaklist
= NULL
;
4029 showhistlist
= NULL
;
4030 unsethistlist
= NULL
;
4031 maintenancelist
= NULL
;
4032 maintenanceinfolist
= NULL
;
4033 maintenanceprintlist
= NULL
;
4034 setprintlist
= NULL
;
4035 showprintlist
= NULL
;
4036 setchecklist
= NULL
;
4037 showchecklist
= NULL
;
4040 /* Init the history buffer. Note that we are called after the init file(s)
4041 * have been read so that the user can change the history file via his
4042 * .gdbinit file (for instance). The GDBHISTFILE environment variable
4043 * overrides all of this.
4051 tmpenv
= getenv ("HISTSIZE");
4053 history_size
= atoi (tmpenv
);
4054 else if (!history_size
)
4057 stifle_history (history_size
);
4059 tmpenv
= getenv ("GDBHISTFILE");
4061 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
4062 else if (!history_filename
)
4064 /* We include the current directory so that if the user changes
4065 directories the file written will be the same as the one
4068 /* No leading dots in file names are allowed on MSDOS. */
4069 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
4071 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
4074 read_history (history_filename
);
4080 struct cmd_list_element
*c
;
4082 /* If we are running the asynchronous version,
4083 we initialize the prompts differently. */
4086 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
4090 /* initialize the prompt stack to a simple "(gdb) " prompt or to
4091 whatever the DEFAULT_PROMPT is. */
4092 the_prompts
.top
= 0;
4094 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
4096 /* Set things up for annotation_level > 1, if the user ever decides
4098 async_annotation_suffix
= "prompt";
4099 /* Set the variable associated with the setshow prompt command. */
4100 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
4102 gdb_prompt_escape
= 0; /* default to none. */
4104 /* Set the important stuff up for command editing. */
4105 command_editing_p
= 1;
4106 history_expansion_p
= 0;
4107 write_history_p
= 0;
4109 /* Setup important stuff for command line editing. */
4110 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
4111 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
4112 rl_completer_quote_characters
= gdb_completer_quote_characters
;
4113 rl_readline_name
= "gdb";
4115 /* Define the classes of commands.
4116 They will appear in the help list in the reverse of this order. */
4118 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
4119 "Maintenance commands.\n\
4120 Some gdb commands are provided just for use by gdb maintainers.\n\
4121 These commands are subject to frequent change, and may not be as\n\
4122 well documented as user commands.",
4124 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
4125 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
4126 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
4127 The commands in this class are those defined by the user.\n\
4128 Use the \"define\" command to define a command.", &cmdlist
);
4129 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
4131 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
4132 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
4133 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
4134 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
4135 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
4136 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
4137 counting from zero for the innermost (currently executing) frame.\n\n\
4138 At any time gdb identifies one frame as the \"selected\" frame.\n\
4139 Variable lookups are done with respect to the selected frame.\n\
4140 When the program being debugged stops, gdb selects the innermost frame.\n\
4141 The commands below can be used to select other frames by number or address.",
4143 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
4145 add_com ("pwd", class_files
, pwd_command
,
4146 "Print working directory. This is used for your program as well.");
4147 c
= add_cmd ("cd", class_files
, cd_command
,
4148 "Set working directory to DIR for debugger and program being debugged.\n\
4149 The change does not take effect for the program being debugged\n\
4150 until the next time it is started.", &cmdlist
);
4151 c
->completer
= filename_completer
;
4153 /* The set prompt command is different depending whether or not the
4154 async version is run. NOTE: this difference is going to
4155 disappear as we make the event loop be the default engine of
4160 (add_set_cmd ("prompt", class_support
, var_string
,
4161 (char *) &gdb_prompt_string
, "Set gdb's prompt",
4167 c
= add_set_cmd ("prompt", class_support
, var_string
,
4168 (char *) &new_async_prompt
, "Set gdb's prompt",
4170 add_show_from_set (c
, &showlist
);
4171 c
->function
.sfunc
= set_async_prompt
;
4175 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
4176 (char *) &gdb_prompt_escape
,
4177 "Set escape character for formatting of gdb's prompt",
4181 add_com ("echo", class_support
, echo_command
,
4182 "Print a constant string. Give string as argument.\n\
4183 C escape sequences may be used in the argument.\n\
4184 No newline is added at the end of the argument;\n\
4185 use \"\\n\" if you want a newline to be printed.\n\
4186 Since leading and trailing whitespace are ignored in command arguments,\n\
4187 if you want to print some you must use \"\\\" before leading whitespace\n\
4188 to be printed or after trailing whitespace.");
4189 add_com ("document", class_support
, document_command
,
4190 "Document a user-defined command.\n\
4191 Give command name as argument. Give documentation on following lines.\n\
4192 End with a line of just \"end\".");
4193 add_com ("define", class_support
, define_command
,
4194 "Define a new command name. Command name is argument.\n\
4195 Definition appears on following lines, one command per line.\n\
4196 End with a line of just \"end\".\n\
4197 Use the \"document\" command to give documentation for the new command.\n\
4198 Commands defined in this way may have up to ten arguments.");
4201 c
= add_cmd ("source", class_support
, source_command
,
4202 "Read commands from a file named FILE.\n\
4203 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
4204 when gdb is started.", &cmdlist
);
4206 /* Punt file name, we can't help it easily. */
4207 c
= add_cmd ("source", class_support
, source_command
,
4208 "Read commands from a file named FILE.\n\
4209 Note that the file \".gdbinit\" is read automatically in this way\n\
4210 when gdb is started.", &cmdlist
);
4212 c
->completer
= filename_completer
;
4214 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
4215 add_com ("help", class_support
, help_command
, "Print list of commands.");
4216 add_com_alias ("q", "quit", class_support
, 1);
4217 add_com_alias ("h", "help", class_support
, 1);
4219 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
4220 Primarily used inside of user-defined commands that should not be repeated when\n\
4223 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *) &info_verbose
,
4226 add_show_from_set (c
, &showlist
);
4227 c
->function
.sfunc
= set_verbose
;
4228 set_verbose (NULL
, 0, c
);
4230 /* The set editing command is different depending whether or not the
4231 async version is run. NOTE: this difference is going to disappear
4232 as we make the event loop be the default engine of gdb. */
4236 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
4237 "Set editing of command lines as they are typed.\n\
4238 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4239 Without an argument, command line editing is enabled. To edit, use\n\
4240 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
4245 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
4246 "Set editing of command lines as they are typed.\n\
4247 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4248 Without an argument, command line editing is enabled. To edit, use\n\
4249 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
4251 add_show_from_set (c
, &showlist
);
4252 c
->function
.sfunc
= set_async_editing_command
;
4255 add_prefix_cmd ("history", class_support
, set_history
,
4256 "Generic command for setting command history parameters.",
4257 &sethistlist
, "set history ", 0, &setlist
);
4258 add_prefix_cmd ("history", class_support
, show_history
,
4259 "Generic command for showing command history parameters.",
4260 &showhistlist
, "show history ", 0, &showlist
);
4263 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *) &history_expansion_p
,
4264 "Set history expansion on command input.\n\
4265 Without an argument, history expansion is enabled.", &sethistlist
),
4269 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
4270 "Set saving of the history record on exit.\n\
4271 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
4272 Without an argument, saving is enabled.", &sethistlist
),
4275 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
4276 "Set the size of the command history, \n\
4277 ie. the number of previous commands to keep a record of.", &sethistlist
);
4278 add_show_from_set (c
, &showhistlist
);
4279 c
->function
.sfunc
= set_history_size_command
;
4282 (add_set_cmd ("filename", no_class
, var_filename
, (char *) &history_filename
,
4283 "Set the filename in which to record the command history\n\
4284 (the list of previous commands of which a record is kept).", &sethistlist
),
4288 (add_set_cmd ("confirm", class_support
, var_boolean
,
4290 "Set whether to confirm potentially dangerous operations.",
4294 add_prefix_cmd ("info", class_info
, info_command
,
4295 "Generic command for showing things about the program being debugged.",
4296 &infolist
, "info ", 0, &cmdlist
);
4297 add_com_alias ("i", "info", class_info
, 1);
4299 add_com ("complete", class_obscure
, complete_command
,
4300 "List the completions for the rest of the line as a command.");
4302 add_prefix_cmd ("show", class_info
, show_command
,
4303 "Generic command for showing things about the debugger.",
4304 &showlist
, "show ", 0, &cmdlist
);
4305 /* Another way to get at the same thing. */
4306 add_info ("set", show_command
, "Show all GDB settings.");
4308 add_cmd ("commands", no_class
, show_commands
,
4309 "Show the history of commands you typed.\n\
4310 You can supply a command number to start with, or a `+' to start after\n\
4311 the previous command number shown.",
4314 add_cmd ("version", no_class
, show_version
,
4315 "Show what version of GDB this is.", &showlist
);
4317 add_com ("while", class_support
, while_command
,
4318 "Execute nested commands WHILE the conditional expression is non zero.\n\
4319 The conditional expression must follow the word `while' and must in turn be\n\
4320 followed by a new line. The nested commands must be entered one per line,\n\
4321 and should be terminated by the word `end'.");
4323 add_com ("if", class_support
, if_command
,
4324 "Execute nested commands once IF the conditional expression is non zero.\n\
4325 The conditional expression must follow the word `if' and must in turn be\n\
4326 followed by a new line. The nested commands must be entered one per line,\n\
4327 and should be terminated by the word 'else' or `end'. If an else clause\n\
4328 is used, the same rules apply to its nested commands as to the first ones.");
4330 /* If target is open when baud changes, it doesn't take effect until the
4331 next open (I think, not sure). */
4332 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
4333 var_zinteger
, (char *) &baud_rate
,
4334 "Set baud rate for remote serial I/O.\n\
4335 This value is used to set the speed of the serial port when debugging\n\
4336 using remote targets.", &setlist
),
4339 c
= add_set_cmd ("remotedebug", no_class
, var_zinteger
,
4340 (char *) &remote_debug
,
4341 "Set debugging of remote protocol.\n\
4342 When enabled, each packet sent or received with the remote target\n\
4343 is displayed.", &setlist
);
4344 deprecate_cmd (c
, "set debug remote");
4345 deprecate_cmd (add_show_from_set (c
, &showlist
), "show debug remote");
4347 add_show_from_set (add_set_cmd ("remote", no_class
, var_zinteger
,
4348 (char *) &remote_debug
,
4349 "Set debugging of remote protocol.\n\
4350 When enabled, each packet sent or received with the remote target\n\
4351 is displayed.", &setdebuglist
),
4355 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *) &remote_timeout
,
4356 "Set timeout limit to wait for target to respond.\n\
4357 This value is used to set the time limit for gdb to wait for a response\n\
4358 from the target.", &setlist
),
4361 /* The set annotate command is different depending whether or not
4362 the async version is run. NOTE: this difference is going to
4363 disappear as we make the event loop be the default engine of
4367 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4368 (char *) &annotation_level
, "Set annotation_level.\n\
4369 0 == normal; 1 == fullname (for use when running under emacs)\n\
4370 2 == output annotated suitably for use by programs that control GDB.",
4372 c
= add_show_from_set (c
, &showlist
);
4376 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4377 (char *) &annotation_level
, "Set annotation_level.\n\
4378 0 == normal; 1 == fullname (for use when running under emacs)\n\
4379 2 == output annotated suitably for use by programs that control GDB.",
4381 add_show_from_set (c
, &showlist
);
4382 c
->function
.sfunc
= set_async_annotation_level
;
4387 (add_set_cmd ("exec-done-display", class_support
, var_boolean
, (char *) &exec_done_display_p
,
4388 "Set notification of completion for asynchronous execution commands.\n\
4389 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist
),
4392 add_prefix_cmd ("debug", no_class
, set_debug
,
4393 "Generic command for setting gdb debugging flags",
4394 &setdebuglist
, "set debug ", 0, &setlist
);
4396 add_prefix_cmd ("debug", no_class
, show_debug
,
4397 "Generic command for showing gdb debugging flags",
4398 &showdebuglist
, "show debug ", 0, &showlist
);