1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "call-cmds.h"
29 #include "breakpoint.h"
31 #include "expression.h"
34 #include "terminal.h" /* For job_control. */
39 /* readline include files */
40 #include <readline/readline.h>
41 #include <readline/history.h>
43 /* readline defines this. */
46 #include <sys/types.h>
50 #include "event-top.h"
51 #include "gdb_string.h"
55 /* Prototypes for local functions */
57 static void dont_repeat_command
PARAMS ((char *, int));
59 static void source_cleanup_lines
PARAMS ((PTR
));
61 static void user_defined_command
PARAMS ((char *, int));
63 static void init_signals
PARAMS ((void));
66 static void stop_sig
PARAMS ((int));
69 static char *line_completion_function
PARAMS ((char *, int, char *, int));
71 static char *readline_line_completion_function
PARAMS ((char *, int));
73 /* NOTE 1999-04-29: this function will be static again, after we make the
74 event loop be the default command loop for gdb, and we merge
75 event-top.c into this file, top.c */
76 /* static */ void command_loop_marker
PARAMS ((int));
78 static void while_command
PARAMS ((char *, int));
80 static void if_command
PARAMS ((char *, int));
82 static struct command_line
*
83 build_command_line
PARAMS ((enum command_control_type
, char *));
85 static struct command_line
*
86 get_command_line
PARAMS ((enum command_control_type
, char *));
88 static void realloc_body_list
PARAMS ((struct command_line
*, int));
90 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
92 static enum command_control_type
93 recurse_read_control_structure
PARAMS ((struct command_line
*));
95 static struct cleanup
*setup_user_args
PARAMS ((char *));
97 static char *locate_arg
PARAMS ((char *));
99 static char *insert_args
PARAMS ((char *));
101 static void arg_cleanup
PARAMS ((void));
103 static void init_main
PARAMS ((void));
105 static void init_cmd_lists
PARAMS ((void));
107 static void float_handler
PARAMS ((int));
109 static void init_signals
PARAMS ((void));
111 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
113 static void show_history
PARAMS ((char *, int));
115 static void set_history
PARAMS ((char *, int));
117 static void set_history_size_command
PARAMS ((char *, int,
118 struct cmd_list_element
*));
120 static void show_commands
PARAMS ((char *, int));
122 static void echo_command
PARAMS ((char *, int));
124 static void pwd_command
PARAMS ((char *, int));
126 static void show_version
PARAMS ((char *, int));
128 static void document_command
PARAMS ((char *, int));
130 static void define_command
PARAMS ((char *, int));
132 static void validate_comname
PARAMS ((char *));
134 static void help_command
PARAMS ((char *, int));
136 static void show_command
PARAMS ((char *, int));
138 static void info_command
PARAMS ((char *, int));
140 static void complete_command
PARAMS ((char *, int));
142 static void do_nothing
PARAMS ((int));
145 /* NOTE 1999-04-29: This function will be static again, once we modify
146 gdb to use the event loop as the default command loop and we merge
147 event-top.c into this file, top.c */
148 /* static */ int quit_cover
PARAMS ((PTR
));
150 static void disconnect
PARAMS ((int));
153 static void source_cleanup
PARAMS ((FILE *));
155 /* Default command line prompt. This is overriden in some configs. */
157 #ifndef DEFAULT_PROMPT
158 #define DEFAULT_PROMPT "(gdb) "
161 /* Initialization file name for gdb. This is overridden in some configs. */
163 #ifndef GDBINIT_FILENAME
164 #define GDBINIT_FILENAME ".gdbinit"
166 char gdbinit
[] = GDBINIT_FILENAME
;
168 int inhibit_gdbinit
= 0;
170 /* If nonzero, and GDB has been configured to be able to use windows,
171 attempt to open them upon startup. */
175 extern char lang_frame_mismatch_warn
[]; /* language.c */
177 /* Flag for whether we want all the "from_tty" gubbish printed. */
179 int caution
= 1; /* Default is yes, sigh. */
181 /* Define all cmd_list_elements. */
183 /* Chain containing all defined commands. */
185 struct cmd_list_element
*cmdlist
;
187 /* Chain containing all defined info subcommands. */
189 struct cmd_list_element
*infolist
;
191 /* Chain containing all defined enable subcommands. */
193 struct cmd_list_element
*enablelist
;
195 /* Chain containing all defined disable subcommands. */
197 struct cmd_list_element
*disablelist
;
199 /* Chain containing all defined toggle subcommands. */
201 struct cmd_list_element
*togglelist
;
203 /* Chain containing all defined stop subcommands. */
205 struct cmd_list_element
*stoplist
;
207 /* Chain containing all defined delete subcommands. */
209 struct cmd_list_element
*deletelist
;
211 /* Chain containing all defined "enable breakpoint" subcommands. */
213 struct cmd_list_element
*enablebreaklist
;
215 /* Chain containing all defined set subcommands */
217 struct cmd_list_element
*setlist
;
219 /* Chain containing all defined unset subcommands */
221 struct cmd_list_element
*unsetlist
;
223 /* Chain containing all defined show subcommands. */
225 struct cmd_list_element
*showlist
;
227 /* Chain containing all defined \"set history\". */
229 struct cmd_list_element
*sethistlist
;
231 /* Chain containing all defined \"show history\". */
233 struct cmd_list_element
*showhistlist
;
235 /* Chain containing all defined \"unset history\". */
237 struct cmd_list_element
*unsethistlist
;
239 /* Chain containing all defined maintenance subcommands. */
241 struct cmd_list_element
*maintenancelist
;
243 /* Chain containing all defined "maintenance info" subcommands. */
245 struct cmd_list_element
*maintenanceinfolist
;
247 /* Chain containing all defined "maintenance print" subcommands. */
249 struct cmd_list_element
*maintenanceprintlist
;
251 struct cmd_list_element
*setprintlist
;
253 struct cmd_list_element
*showprintlist
;
255 struct cmd_list_element
*setchecklist
;
257 struct cmd_list_element
*showchecklist
;
259 /* stdio stream that command input is being read from. Set to stdin normally.
260 Set by source_command to the file we are sourcing. Set to NULL if we are
261 executing a user-defined command or interacting via a GUI. */
265 /* Current working directory. */
267 char *current_directory
;
269 /* The directory name is actually stored here (usually). */
270 char gdb_dirbuf
[1024];
272 /* Function to call before reading a command, if nonzero.
273 The function receives two args: an input stream,
274 and a prompt string. */
276 void (*window_hook
) PARAMS ((FILE *, char *));
281 /* gdb prints this when reading a command interactively */
282 static char *gdb_prompt_string
; /* the global prompt string */
283 extern char *get_prompt
PARAMS ((void)); /* access function for prompt string */
285 /* Buffer used for reading command lines, and the size
286 allocated for it so far. */
291 /* Nonzero if the current command is modified by "server ". This
292 affects things like recording into the command history, commands
293 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
294 whatever) can issue its own commands and also send along commands
295 from the user, and have the user not notice that the user interface
296 is issuing commands too. */
299 /* Baud rate specified for talking to serial target systems. Default
300 is left as -1, so targets can choose their own defaults. */
301 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
302 or (unsigned int)-1. This is a Bad User Interface. */
306 /* Timeout limit for response from target. */
308 int remote_timeout
= 20; /* Set default to 20 */
310 /* Non-zero tells remote* modules to output debugging info. */
312 int remote_debug
= 0;
314 /* Non-zero means the target is running. Note: this is different from
315 saying that there is an active target and we are stopped at a
316 breakpoint, for instance. This is a real indicator whether the
317 target is off and running, which gdb is doing something else. */
318 int target_executing
= 0;
320 /* Level of control structure. */
321 static int control_level
;
323 /* Structure for arguments to user defined functions. */
324 #define MAXUSERARGS 10
327 struct user_args
*next
;
338 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
342 #define STOP_SIGNAL SIGTSTP
343 static void stop_sig
PARAMS ((int));
347 /* Some System V have job control but not sigsetmask(). */
348 #if !defined (HAVE_SIGSETMASK)
350 #define HAVE_SIGSETMASK 1
352 #define HAVE_SIGSETMASK 0
356 #if 0 == (HAVE_SIGSETMASK)
357 #define sigsetmask(n)
360 /* Hooks for alternate command interfaces. */
362 /* Called after most modules have been initialized, but before taking users
365 void (*init_ui_hook
) PARAMS ((char *argv0
));
367 /* This hook is called from within gdb's many mini-event loops which could
368 steal control from a real user interface's event loop. It returns
369 non-zero if the user is requesting a detach, zero otherwise. */
371 int (*ui_loop_hook
) PARAMS ((int));
373 /* Called instead of command_loop at top level. Can be invoked via
374 return_to_top_level. */
376 void (*command_loop_hook
) PARAMS ((void));
379 /* Called from print_frame_info to list the line we stopped in. */
381 void (*print_frame_info_listing_hook
) PARAMS ((struct symtab
* s
, int line
,
382 int stopline
, int noerror
));
383 /* Replaces most of query. */
385 int (*query_hook
) PARAMS ((const char *, va_list));
387 /* Replaces most of warning. */
389 void (*warning_hook
) PARAMS ((const char *, va_list));
391 /* These three functions support getting lines of text from the user. They
392 are used in sequence. First readline_begin_hook is called with a text
393 string that might be (for example) a message for the user to type in a
394 sequence of commands to be executed at a breakpoint. If this function
395 calls back to a GUI, it might take this opportunity to pop up a text
396 interaction window with this message. Next, readline_hook is called
397 with a prompt that is emitted prior to collecting the user input.
398 It can be called multiple times. Finally, readline_end_hook is called
399 to notify the GUI that we are done with the interaction window and it
402 void (*readline_begin_hook
) PARAMS ((char *,...));
403 char *(*readline_hook
) PARAMS ((char *));
404 void (*readline_end_hook
) PARAMS ((void));
406 /* Called as appropriate to notify the interface of the specified breakpoint
409 void (*create_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
410 void (*delete_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
411 void (*modify_breakpoint_hook
) PARAMS ((struct breakpoint
* bpt
));
413 /* Called as appropriate to notify the interface that we have attached
414 to or detached from an already running process. */
416 void (*attach_hook
) PARAMS ((void));
417 void (*detach_hook
) PARAMS ((void));
419 /* Called during long calculations to allow GUI to repair window damage, and to
420 check for stop buttons, etc... */
422 void (*interactive_hook
) PARAMS ((void));
424 /* Called when the registers have changed, as a hint to a GUI
425 to minimize window update. */
427 void (*registers_changed_hook
) PARAMS ((void));
429 /* Tell the GUI someone changed the register REGNO. -1 means
430 that the caller does not know which register changed or
431 that several registers have changed (see value_assign). */
432 void (*register_changed_hook
) PARAMS ((int regno
));
434 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
435 void (*memory_changed_hook
) PARAMS ((CORE_ADDR addr
, int len
));
437 /* Called when going to wait for the target. Usually allows the GUI to run
438 while waiting for target events. */
440 int (*target_wait_hook
) PARAMS ((int pid
, struct target_waitstatus
* status
));
442 /* Used by UI as a wrapper around command execution. May do various things
443 like enabling/disabling buttons, etc... */
445 void (*call_command_hook
) PARAMS ((struct cmd_list_element
* c
, char *cmd
,
448 /* Called after a `set' command has finished. Is only run if the
449 `set' command succeeded. */
451 void (*set_hook
) PARAMS ((struct cmd_list_element
*c
));
453 /* Called when the current thread changes. Argument is thread id. */
455 void (*context_hook
) PARAMS ((int id
));
457 /* Takes control from error (). Typically used to prevent longjmps out of the
458 middle of the GUI. Usually used in conjunction with a catch routine. */
460 NORETURN
void (*error_hook
)
461 PARAMS ((void)) ATTR_NORETURN
;
464 /* Generally one should use catch_errors rather than manipulating these
465 directly. The exception is main(). */
466 #if defined(HAVE_SIGSETJMP)
467 #define SIGJMP_BUF sigjmp_buf
468 #define SIGSETJMP(buf) sigsetjmp(buf, 1)
469 #define SIGLONGJMP(buf,val) siglongjmp(buf,val)
471 #define SIGJMP_BUF jmp_buf
472 #define SIGSETJMP(buf) setjmp(buf)
473 #define SIGLONGJMP(buf,val) longjmp(buf,val)
476 /* Where to go for return_to_top_level (RETURN_ERROR). */
477 static SIGJMP_BUF error_return
;
478 /* Where to go for return_to_top_level (RETURN_QUIT). */
479 static SIGJMP_BUF quit_return
;
481 /* Return for reason REASON. This generally gets back to the command
482 loop, but can be caught via catch_errors. */
485 return_to_top_level (reason
)
486 enum return_reason reason
;
491 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
492 I can think of a reason why that is vital, though). */
493 bpstat_clear_actions (stop_bpstat
); /* Clear queued breakpoint commands */
495 disable_current_display ();
496 do_cleanups (ALL_CLEANUPS
);
497 if (event_loop_p
&& target_can_async_p () && !target_executing
)
498 do_exec_cleanups (ALL_CLEANUPS
);
499 if (event_loop_p
&& sync_execution
)
500 do_exec_error_cleanups (ALL_CLEANUPS
);
502 if (annotation_level
> 1)
513 (NORETURN
void) SIGLONGJMP
514 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
517 /* Call FUNC with arg ARGS, catching any errors. If there is no
518 error, return the value returned by FUNC. If there is an error,
519 print ERRSTRING, print the specific error message, then return
522 Must not be called with immediate_quit in effect (bad things might
523 happen, say we got a signal in the middle of a memcpy to quit_return).
524 This is an OK restriction; with very few exceptions immediate_quit can
525 be replaced by judicious use of QUIT.
527 MASK specifies what to catch; it is normally set to
528 RETURN_MASK_ALL, if for no other reason than that the code which
529 calls catch_errors might not be set up to deal with a quit which
530 isn't caught. But if the code can deal with it, it generally
531 should be RETURN_MASK_ERROR, unless for some reason it is more
532 useful to abort only the portion of the operation inside the
533 catch_errors. Note that quit should return to the command line
534 fairly quickly, even if some further processing is being done. */
536 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
537 error() et.al. could maintain a set of flags that indicate the the
538 current state of each of the longjmp buffers. This would give the
539 longjmp code the chance to detect a longjmp botch (before it gets
540 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
541 code also randomly used a SET_TOP_LEVEL macro that directly
542 initialize the longjmp buffers. */
544 /* MAYBE: cagney/1999-11-05: Since the SET_TOP_LEVEL macro has been
545 eliminated it is now possible to use the stack to directly store
546 each longjmp buffer. The global code would just need to update a
547 pointer (onto the stack - ulgh!?) indicating the current longjmp
548 buffers. It would certainly improve the performance of the longjmp
549 code since the memcpy's would be eliminated. */
551 /* MAYBE: cagney/1999-11-05: Should the catch_erros and cleanups code
552 be consolidated into a single file instead of being distributed
553 between utils.c and top.c? */
556 catch_errors (func
, args
, errstring
, mask
)
557 catch_errors_ftype
*func
;
562 SIGJMP_BUF saved_error
;
563 SIGJMP_BUF saved_quit
;
566 struct cleanup
*saved_cleanup_chain
;
567 char *saved_error_pre_print
;
568 char *saved_quit_pre_print
;
570 saved_cleanup_chain
= save_cleanups ();
571 saved_error_pre_print
= error_pre_print
;
572 saved_quit_pre_print
= quit_pre_print
;
574 if (mask
& RETURN_MASK_ERROR
)
576 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (SIGJMP_BUF
));
577 error_pre_print
= errstring
;
579 if (mask
& RETURN_MASK_QUIT
)
581 memcpy (saved_quit
, quit_return
, sizeof (SIGJMP_BUF
));
582 quit_pre_print
= errstring
;
585 if (SIGSETJMP (tmp_jmp
) == 0)
587 if (mask
& RETURN_MASK_ERROR
)
588 memcpy (error_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
589 if (mask
& RETURN_MASK_QUIT
)
590 memcpy (quit_return
, tmp_jmp
, sizeof (SIGJMP_BUF
));
591 val
= (*func
) (args
);
592 /* FIXME: cagney/1999-11-05: A correct FUNC implementaton will
593 clean things up (restoring the cleanup chain) to the state
594 they were just prior to the call. Technically, this means
595 that the below restore_cleanups call is redundant.
596 Unfortunatly, many FUNC's are not that well behaved.
597 restore_cleanups should either be replaced with a do_cleanups
598 call (to cover the problem) or an assertion check to detect
604 restore_cleanups (saved_cleanup_chain
);
606 if (mask
& RETURN_MASK_ERROR
)
608 memcpy (error_return
, saved_error
, sizeof (SIGJMP_BUF
));
609 error_pre_print
= saved_error_pre_print
;
611 if (mask
& RETURN_MASK_QUIT
)
613 memcpy (quit_return
, saved_quit
, sizeof (SIGJMP_BUF
));
614 quit_pre_print
= saved_quit_pre_print
;
619 struct captured_command_args
621 catch_command_errors_ftype
*command
;
627 do_captured_command (void *data
)
629 struct captured_command_args
*context
= data
;
630 context
->command (context
->arg
, context
->from_tty
);
631 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
632 isn't needed. Instead an assertion check could be made that
633 simply confirmed that the called function correctly cleaned up
634 after its self. Unfortunatly, old code (prior to 1999-11-04) in
635 main.c was calling SET_TOP_LEVEL(), calling the command function,
636 and then *always* calling do_cleanups(). For the moment we
637 remain ``bug compatible'' with that old code.. */
638 do_cleanups (ALL_CLEANUPS
);
643 catch_command_errors (catch_command_errors_ftype
*command
,
644 char *arg
, int from_tty
, return_mask mask
)
646 struct captured_command_args args
;
647 args
.command
= command
;
649 args
.from_tty
= from_tty
;
650 return catch_errors (do_captured_command
, &args
, "", mask
);
654 /* Handler for SIGHUP. */
661 catch_errors (quit_cover
, NULL
,
662 "Could not kill the program being debugged", RETURN_MASK_ALL
);
663 signal (SIGHUP
, SIG_DFL
);
664 kill (getpid (), SIGHUP
);
667 /* Just a little helper function for disconnect(). */
669 /* NOTE 1999-04-29: This function will be static again, once we modify
670 gdb to use the event loop as the default command loop and we merge
671 event-top.c into this file, top.c */
676 caution
= 0; /* Throw caution to the wind -- we're exiting.
677 This prevents asking the user dumb questions. */
678 quit_command ((char *) 0, 0);
681 #endif /* defined SIGHUP */
683 /* Line number we are currently in in a file which is being sourced. */
684 /* NOTE 1999-04-29: This variable will be static again, once we modify
685 gdb to use the event loop as the default command loop and we merge
686 event-top.c into this file, top.c */
687 /* static */ int source_line_number
;
689 /* Name of the file we are sourcing. */
690 /* NOTE 1999-04-29: This variable will be static again, once we modify
691 gdb to use the event loop as the default command loop and we merge
692 event-top.c into this file, top.c */
693 /* static */ char *source_file_name
;
695 /* Buffer containing the error_pre_print used by the source stuff.
697 /* NOTE 1999-04-29: This variable will be static again, once we modify
698 gdb to use the event loop as the default command loop and we merge
699 event-top.c into this file, top.c */
700 /* static */ char *source_error
;
701 static int source_error_allocated
;
703 /* Something to glom on to the start of error_pre_print if source_file_name
705 /* NOTE 1999-04-29: This variable will be static again, once we modify
706 gdb to use the event loop as the default command loop and we merge
707 event-top.c into this file, top.c */
708 /* static */ char *source_pre_error
;
710 /* Clean up on error during a "source" command (or execution of a
711 user-defined command). */
714 source_cleanup (stream
)
717 /* Restore the previous input stream. */
721 /* Read commands from STREAM. */
723 read_command_file (stream
)
726 struct cleanup
*cleanups
;
728 cleanups
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
731 do_cleanups (cleanups
);
734 extern void init_proc
PARAMS ((void));
736 void (*pre_init_ui_hook
) PARAMS ((void));
742 if (pre_init_ui_hook
)
745 /* Run the init function of each source file */
747 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
748 current_directory
= gdb_dirbuf
;
751 /* Make sure we return to the original directory upon exit, come
752 what may, since the OS doesn't do that for us. */
753 make_final_cleanup ((make_cleanup_func
) chdir
, strsave (current_directory
));
756 init_cmd_lists (); /* This needs to be done first */
757 initialize_targets (); /* Setup target_terminal macros for utils.c */
758 initialize_utils (); /* Make errors and warnings possible */
759 initialize_all_files ();
760 initialize_current_architecture ();
761 init_main (); /* But that omits this file! Do it now */
763 /* The signal handling mechanism is different depending whether or
764 not the async version is run. NOTE: in the future we plan to make
765 the event loop be the default engine of gdb, and this difference
768 async_init_signals ();
772 /* We need a default language for parsing expressions, so simple things like
773 "set width 0" won't fail if no language is explicitly set in a config file
774 or implicitly set by reading an executable during startup. */
775 set_language (language_c
);
776 expected_language
= current_language
; /* don't warn about the change. */
778 /* All the interpreters should have had a look at things by now.
779 Initialize the selected interpreter. */
781 init_ui_hook (argv0
);
784 /* Allocate, initialize a new command line structure for one of the
785 control commands (if/while). */
787 static struct command_line
*
788 build_command_line (type
, args
)
789 enum command_control_type type
;
792 struct command_line
*cmd
;
795 error ("if/while commands require arguments.\n");
797 cmd
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
799 cmd
->control_type
= type
;
803 = (struct command_line
**) xmalloc (sizeof (struct command_line
*)
805 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
806 cmd
->line
= savestring (args
, strlen (args
));
810 /* Build and return a new command structure for the control commands
811 such as "if" and "while". */
813 static struct command_line
*
814 get_command_line (type
, arg
)
815 enum command_control_type type
;
818 struct command_line
*cmd
;
819 struct cleanup
*old_chain
= NULL
;
821 /* Allocate and build a new command line structure. */
822 cmd
= build_command_line (type
, arg
);
824 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
, &cmd
);
826 /* Read in the body of this command. */
827 if (recurse_read_control_structure (cmd
) == invalid_control
)
829 warning ("error reading in control structure\n");
830 do_cleanups (old_chain
);
834 discard_cleanups (old_chain
);
838 /* Recursively print a command (including full control structures). */
840 print_command_line (cmd
, depth
, stream
)
841 struct command_line
*cmd
;
849 for (i
= 0; i
< depth
; i
++)
850 fputs_filtered (" ", stream
);
853 /* A simple command, print it and return. */
854 if (cmd
->control_type
== simple_control
)
856 fputs_filtered (cmd
->line
, stream
);
857 fputs_filtered ("\n", stream
);
861 /* loop_continue to jump to the start of a while loop, print it
863 if (cmd
->control_type
== continue_control
)
865 fputs_filtered ("loop_continue\n", stream
);
869 /* loop_break to break out of a while loop, print it and return. */
870 if (cmd
->control_type
== break_control
)
872 fputs_filtered ("loop_break\n", stream
);
876 /* A while command. Recursively print its subcommands before returning. */
877 if (cmd
->control_type
== while_control
)
879 struct command_line
*list
;
880 fputs_filtered ("while ", stream
);
881 fputs_filtered (cmd
->line
, stream
);
882 fputs_filtered ("\n", stream
);
883 list
= *cmd
->body_list
;
886 print_command_line (list
, depth
+ 1, stream
);
891 /* An if command. Recursively print both arms before returning. */
892 if (cmd
->control_type
== if_control
)
894 fputs_filtered ("if ", stream
);
895 fputs_filtered (cmd
->line
, stream
);
896 fputs_filtered ("\n", stream
);
898 print_command_line (cmd
->body_list
[0], depth
+ 1, stream
);
900 /* Show the false arm if it exists. */
901 if (cmd
->body_count
== 2)
905 for (i
= 0; i
< depth
; i
++)
906 fputs_filtered (" ", stream
);
908 fputs_filtered ("else\n", stream
);
909 print_command_line (cmd
->body_list
[1], depth
+ 1, stream
);
913 for (i
= 0; i
< depth
; i
++)
914 fputs_filtered (" ", stream
);
916 fputs_filtered ("end\n", stream
);
920 /* Execute the command in CMD. */
922 enum command_control_type
923 execute_control_command (cmd
)
924 struct command_line
*cmd
;
926 struct expression
*expr
;
927 struct command_line
*current
;
928 struct cleanup
*old_chain
= 0;
932 enum command_control_type ret
;
935 switch (cmd
->control_type
)
938 /* A simple command, execute it and return. */
939 new_line
= insert_args (cmd
->line
);
941 return invalid_control
;
942 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
944 execute_command (new_line
, 0);
945 ret
= cmd
->control_type
;
948 case continue_control
:
950 /* Return for "continue", and "break" so we can either
951 continue the loop at the top, or break out. */
952 ret
= cmd
->control_type
;
957 /* Parse the loop control expression for the while statement. */
958 new_line
= insert_args (cmd
->line
);
960 return invalid_control
;
961 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
963 expr
= parse_expression (new_line
);
964 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
966 ret
= simple_control
;
969 /* Keep iterating so long as the expression is true. */
976 /* Evaluate the expression. */
977 val_mark
= value_mark ();
978 val
= evaluate_expression (expr
);
979 cond_result
= value_true (val
);
980 value_free_to_mark (val_mark
);
982 /* If the value is false, then break out of the loop. */
986 /* Execute the body of the while statement. */
987 current
= *cmd
->body_list
;
990 ret
= execute_control_command (current
);
992 /* If we got an error, or a "break" command, then stop
994 if (ret
== invalid_control
|| ret
== break_control
)
1000 /* If we got a "continue" command, then restart the loop
1002 if (ret
== continue_control
)
1005 /* Get the next statement. */
1006 current
= current
->next
;
1010 /* Reset RET so that we don't recurse the break all the way down. */
1011 if (ret
== break_control
)
1012 ret
= simple_control
;
1019 new_line
= insert_args (cmd
->line
);
1021 return invalid_control
;
1022 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1024 /* Parse the conditional for the if statement. */
1025 expr
= parse_expression (new_line
);
1026 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
1029 ret
= simple_control
;
1031 /* Evaluate the conditional. */
1032 val_mark
= value_mark ();
1033 val
= evaluate_expression (expr
);
1035 /* Choose which arm to take commands from based on the value of the
1036 conditional expression. */
1037 if (value_true (val
))
1038 current
= *cmd
->body_list
;
1039 else if (cmd
->body_count
== 2)
1040 current
= *(cmd
->body_list
+ 1);
1041 value_free_to_mark (val_mark
);
1043 /* Execute commands in the given arm. */
1046 ret
= execute_control_command (current
);
1048 /* If we got an error, get out. */
1049 if (ret
!= simple_control
)
1052 /* Get the next statement in the body. */
1053 current
= current
->next
;
1060 warning ("Invalid control type in command structure.");
1061 return invalid_control
;
1065 do_cleanups (old_chain
);
1070 /* "while" command support. Executes a body of statements while the
1071 loop condition is nonzero. */
1074 while_command (arg
, from_tty
)
1078 struct command_line
*command
= NULL
;
1081 command
= get_command_line (while_control
, arg
);
1083 if (command
== NULL
)
1086 execute_control_command (command
);
1087 free_command_lines (&command
);
1090 /* "if" command support. Execute either the true or false arm depending
1091 on the value of the if conditional. */
1094 if_command (arg
, from_tty
)
1098 struct command_line
*command
= NULL
;
1101 command
= get_command_line (if_control
, arg
);
1103 if (command
== NULL
)
1106 execute_control_command (command
);
1107 free_command_lines (&command
);
1114 struct user_args
*oargs
= user_args
;
1116 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1118 user_args
= user_args
->next
;
1122 /* Bind the incomming arguments for a user defined command to
1123 $arg0, $arg1 ... $argMAXUSERARGS. */
1125 static struct cleanup
*
1129 struct user_args
*args
;
1130 struct cleanup
*old_chain
;
1131 unsigned int arg_count
= 0;
1133 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
1134 memset (args
, 0, sizeof (struct user_args
));
1136 args
->next
= user_args
;
1139 old_chain
= make_cleanup ((make_cleanup_func
) arg_cleanup
, 0);
1151 if (arg_count
>= MAXUSERARGS
)
1153 error ("user defined function may only have %d arguments.\n",
1158 /* Strip whitespace. */
1159 while (*p
== ' ' || *p
== '\t')
1162 /* P now points to an argument. */
1164 user_args
->a
[arg_count
].arg
= p
;
1166 /* Get to the end of this argument. */
1169 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
1175 else if (*p
== '\\')
1198 user_args
->a
[arg_count
].len
= p
- start_arg
;
1205 /* Given character string P, return a point to the first argument ($arg),
1206 or NULL if P contains no arguments. */
1212 while ((p
= strchr (p
, '$')))
1214 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
1221 /* Insert the user defined arguments stored in user_arg into the $arg
1222 arguments found in line, with the updated copy being placed into nline. */
1228 char *p
, *save_line
, *new_line
;
1231 /* First we need to know how much memory to allocate for the new line. */
1234 while ((p
= locate_arg (line
)))
1239 if (i
>= user_args
->count
)
1241 error ("Missing argument %d in user function.\n", i
);
1244 len
+= user_args
->a
[i
].len
;
1248 /* Don't forget the tail. */
1249 len
+= strlen (line
);
1251 /* Allocate space for the new line and fill it in. */
1252 new_line
= (char *) xmalloc (len
+ 1);
1253 if (new_line
== NULL
)
1256 /* Restore pointer to beginning of old line. */
1259 /* Save pointer to beginning of new line. */
1260 save_line
= new_line
;
1262 while ((p
= locate_arg (line
)))
1266 memcpy (new_line
, line
, p
- line
);
1267 new_line
+= p
- line
;
1270 len
= user_args
->a
[i
].len
;
1273 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
1278 /* Don't forget the tail. */
1279 strcpy (new_line
, line
);
1281 /* Return a pointer to the beginning of the new line. */
1286 execute_user_command (c
, args
)
1287 struct cmd_list_element
*c
;
1290 register struct command_line
*cmdlines
;
1291 struct cleanup
*old_chain
;
1292 enum command_control_type ret
;
1294 old_chain
= setup_user_args (args
);
1296 cmdlines
= c
->user_commands
;
1301 /* Set the instream to 0, indicating execution of a
1302 user-defined function. */
1303 old_chain
= make_cleanup ((make_cleanup_func
) source_cleanup
, instream
);
1304 instream
= (FILE *) 0;
1307 ret
= execute_control_command (cmdlines
);
1308 if (ret
!= simple_control
&& ret
!= break_control
)
1310 warning ("Error in control structure.\n");
1313 cmdlines
= cmdlines
->next
;
1315 do_cleanups (old_chain
);
1318 /* Execute the line P as a command.
1319 Pass FROM_TTY as second argument to the defining function. */
1322 execute_command (p
, from_tty
)
1326 register struct cmd_list_element
*c
;
1327 register enum language flang
;
1328 static int warned
= 0;
1329 /* FIXME: These should really be in an appropriate header file */
1330 extern void serial_log_command
PARAMS ((const char *));
1334 /* Force cleanup of any alloca areas if using C alloca instead of
1335 a builtin alloca. */
1338 /* This can happen when command_line_input hits end of file. */
1342 serial_log_command (p
);
1344 while (*p
== ' ' || *p
== '\t')
1350 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1352 /* If the target is running, we allow only a limited set of
1354 if (event_loop_p
&& target_can_async_p () && target_executing
)
1355 if (!strcmp (c
->name
, "help")
1356 && !strcmp (c
->name
, "pwd")
1357 && !strcmp (c
->name
, "show")
1358 && !strcmp (c
->name
, "stop"))
1359 error ("Cannot execute this command while the target is running.");
1361 /* Pass null arg rather than an empty one. */
1364 /* Clear off trailing whitespace, except for set and complete command. */
1365 if (arg
&& c
->type
!= set_cmd
&& c
->function
.cfunc
!= complete_command
)
1367 p
= arg
+ strlen (arg
) - 1;
1368 while (p
>= arg
&& (*p
== ' ' || *p
== '\t'))
1373 /* If this command has been hooked, run the hook first. */
1375 execute_user_command (c
->hook
, (char *) 0);
1377 if (c
->class == class_user
)
1378 execute_user_command (c
, arg
);
1379 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1380 do_setshow_command (arg
, from_tty
& caution
, c
);
1381 else if (c
->function
.cfunc
== NO_FUNCTION
)
1382 error ("That is not a command, just a help topic.");
1383 else if (call_command_hook
)
1384 call_command_hook (c
, arg
, from_tty
& caution
);
1386 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1389 /* Tell the user if the language has changed (except first time). */
1390 if (current_language
!= expected_language
)
1392 if (language_mode
== language_mode_auto
)
1394 language_info (1); /* Print what changed. */
1399 /* Warn the user if the working language does not match the
1400 language of the current frame. Only warn the user if we are
1401 actually running the program, i.e. there is a stack. */
1402 /* FIXME: This should be cacheing the frame and only running when
1403 the frame changes. */
1405 if (target_has_stack
)
1407 flang
= get_frame_language ();
1409 && flang
!= language_unknown
1410 && flang
!= current_language
->la_language
)
1412 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1419 /* NOTE 1999-04-29: This function will be static again, once we modify
1420 gdb to use the event loop as the default command loop and we merge
1421 event-top.c into this file, top.c */
1423 command_loop_marker (foo
)
1428 /* Read commands from `instream' and execute them
1429 until end of file or error reading instream. */
1434 struct cleanup
*old_chain
;
1436 int stdin_is_tty
= ISATTY (stdin
);
1437 long time_at_cmd_start
;
1439 long space_at_cmd_start
= 0;
1441 extern int display_time
;
1442 extern int display_space
;
1444 while (instream
&& !feof (instream
))
1447 extern int insert_mode
;
1449 if (window_hook
&& instream
== stdin
)
1450 (*window_hook
) (instream
, get_prompt ());
1453 if (instream
== stdin
&& stdin_is_tty
)
1454 reinitialize_more_filter ();
1455 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
1458 /* A bit of paranoia: I want to make sure the "insert_mode" global
1459 * is clear except when it is being used for command-line editing
1460 * (see tuiIO.c, utils.c); otherwise normal output will
1461 * get messed up in the TUI. So clear it before/after
1462 * the command-line-input call. - RT
1466 /* Get a command-line. This calls the readline package. */
1467 command
= command_line_input (instream
== stdin
?
1468 get_prompt () : (char *) NULL
,
1469 instream
== stdin
, "prompt");
1476 time_at_cmd_start
= get_run_time ();
1481 extern char **environ
;
1482 char *lim
= (char *) sbrk (0);
1484 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
1488 execute_command (command
, instream
== stdin
);
1489 /* Do any commands attached to breakpoint we stopped at. */
1490 bpstat_do_actions (&stop_bpstat
);
1491 do_cleanups (old_chain
);
1495 long cmd_time
= get_run_time () - time_at_cmd_start
;
1497 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1498 cmd_time
/ 1000000, cmd_time
% 1000000);
1504 extern char **environ
;
1505 char *lim
= (char *) sbrk (0);
1506 long space_now
= lim
- (char *) &environ
;
1507 long space_diff
= space_now
- space_at_cmd_start
;
1509 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1511 (space_diff
>= 0 ? '+' : '-'),
1519 /* Commands call this if they do not want to be repeated by null lines. */
1527 /* If we aren't reading from standard input, we are saving the last
1528 thing read from stdin in line and don't want to delete it. Null lines
1529 won't repeat here in any case. */
1530 if (instream
== stdin
)
1534 /* Read a line from the stream "instream" without command line editing.
1536 It prints PROMPT_ARG once at the start.
1537 Action is compatible with "readline", e.g. space for the result is
1538 malloc'd and should be freed by the caller.
1540 A NULL return means end of file. */
1542 gdb_readline (prompt_arg
)
1547 int input_index
= 0;
1548 int result_size
= 80;
1552 /* Don't use a _filtered function here. It causes the assumed
1553 character position to be off, since the newline we read from
1554 the user is not accounted for. */
1555 fputs_unfiltered (prompt_arg
, gdb_stdout
);
1557 /* Move to a new line so the entered line doesn't have a prompt
1558 on the front of it. */
1559 fputs_unfiltered ("\n", gdb_stdout
);
1561 gdb_flush (gdb_stdout
);
1564 result
= (char *) xmalloc (result_size
);
1568 /* Read from stdin if we are executing a user defined command.
1569 This is the right thing for prompt_for_continue, at least. */
1570 c
= fgetc (instream
? instream
: stdin
);
1574 if (input_index
> 0)
1575 /* The last line does not end with a newline. Return it, and
1576 if we are called again fgetc will still return EOF and
1577 we'll return NULL then. */
1584 #ifndef CRLF_SOURCE_FILES
1588 if (input_index
> 0 && result
[input_index
- 1] == '\r')
1594 result
[input_index
++] = c
;
1595 while (input_index
>= result_size
)
1598 result
= (char *) xrealloc (result
, result_size
);
1602 result
[input_index
++] = '\0';
1606 /* Variables which control command line editing and history
1607 substitution. These variables are given default values at the end
1609 static int command_editing_p
;
1610 /* NOTE 1999-04-29: This variable will be static again, once we modify
1611 gdb to use the event loop as the default command loop and we merge
1612 event-top.c into this file, top.c */
1613 /* static */ int history_expansion_p
;
1614 static int write_history_p
;
1615 static int history_size
;
1616 static char *history_filename
;
1618 /* readline uses the word breaks for two things:
1619 (1) In figuring out where to point the TEXT parameter to the
1620 rl_completion_entry_function. Since we don't use TEXT for much,
1621 it doesn't matter a lot what the word breaks are for this purpose, but
1622 it does affect how much stuff M-? lists.
1623 (2) If one of the matches contains a word break character, readline
1624 will quote it. That's why we switch between
1625 gdb_completer_word_break_characters and
1626 gdb_completer_command_word_break_characters. I'm not sure when
1627 we need this behavior (perhaps for funky characters in C++ symbols?). */
1629 /* Variables which are necessary for fancy command line editing. */
1630 char *gdb_completer_word_break_characters
=
1631 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1633 /* When completing on command names, we remove '-' from the list of
1634 word break characters, since we use it in command names. If the
1635 readline library sees one in any of the current completion strings,
1636 it thinks that the string needs to be quoted and automatically supplies
1638 char *gdb_completer_command_word_break_characters
=
1639 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1641 /* Characters that can be used to quote completion strings. Note that we
1642 can't include '"' because the gdb C parser treats such quoted sequences
1644 char *gdb_completer_quote_characters
=
1647 /* Functions that are used as part of the fancy command line editing. */
1649 /* This can be used for functions which don't want to complete on symbols
1650 but don't want to complete on anything else either. */
1653 noop_completer (text
, prefix
)
1660 /* Complete on filenames. */
1662 filename_completer (text
, word
)
1666 /* From readline. */
1667 extern char *filename_completion_function
PARAMS ((char *, int));
1668 int subsequent_name
;
1670 int return_val_used
;
1671 int return_val_alloced
;
1673 return_val_used
= 0;
1674 /* Small for testing. */
1675 return_val_alloced
= 1;
1676 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1678 subsequent_name
= 0;
1682 p
= filename_completion_function (text
, subsequent_name
);
1683 if (return_val_used
>= return_val_alloced
)
1685 return_val_alloced
*= 2;
1687 (char **) xrealloc (return_val
,
1688 return_val_alloced
* sizeof (char *));
1692 return_val
[return_val_used
++] = p
;
1695 /* Like emacs, don't complete on old versions. Especially useful
1696 in the "source" command. */
1697 if (p
[strlen (p
) - 1] == '~')
1703 /* Return exactly p. */
1704 return_val
[return_val_used
++] = p
;
1705 else if (word
> text
)
1707 /* Return some portion of p. */
1708 q
= xmalloc (strlen (p
) + 5);
1709 strcpy (q
, p
+ (word
- text
));
1710 return_val
[return_val_used
++] = q
;
1715 /* Return some of TEXT plus p. */
1716 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1717 strncpy (q
, word
, text
- word
);
1718 q
[text
- word
] = '\0';
1720 return_val
[return_val_used
++] = q
;
1724 subsequent_name
= 1;
1727 /* There is no way to do this just long enough to affect quote inserting
1728 without also affecting the next completion. This should be fixed in
1730 /* Insure that readline does the right thing
1731 with respect to inserting quotes. */
1732 rl_completer_word_break_characters
= "";
1737 /* Here are some useful test cases for completion. FIXME: These should
1738 be put in the test suite. They should be tested with both M-? and TAB.
1740 "show output-" "radix"
1741 "show output" "-radix"
1742 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1743 "p " ambiguous (all symbols)
1744 "info t foo" no completions
1745 "info t " no completions
1746 "info t" ambiguous ("info target", "info terminal", etc.)
1747 "info ajksdlfk" no completions
1748 "info ajksdlfk " no completions
1750 "info " ambiguous (all info commands)
1751 "p \"a" no completions (string constant)
1752 "p 'a" ambiguous (all symbols starting with a)
1753 "p b-a" ambiguous (all symbols starting with a)
1754 "p b-" ambiguous (all symbols)
1755 "file Make" "file" (word break hard to screw up here)
1756 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1759 /* Generate completions one by one for the completer. Each time we are
1760 called return another potential completion to the caller.
1761 line_completion just completes on commands or passes the buck to the
1762 command's completer function, the stuff specific to symbol completion
1763 is in make_symbol_completion_list.
1765 TEXT is the caller's idea of the "word" we are looking at.
1767 MATCHES is the number of matches that have currently been collected from
1768 calling this completion function. When zero, then we need to initialize,
1769 otherwise the initialization has already taken place and we can just
1770 return the next potential completion string.
1772 LINE_BUFFER is available to be looked at; it contains the entire text
1773 of the line. POINT is the offset in that line of the cursor. You
1774 should pretend that the line ends at POINT.
1776 Returns NULL if there are no more completions, else a pointer to a string
1777 which is a possible completion, it is the caller's responsibility to
1781 line_completion_function (text
, matches
, line_buffer
, point
)
1787 static char **list
= (char **) NULL
; /* Cache of completions */
1788 static int index
; /* Next cached completion */
1789 char *output
= NULL
;
1790 char *tmp_command
, *p
;
1791 /* Pointer within tmp_command which corresponds to text. */
1793 struct cmd_list_element
*c
, *result_list
;
1797 /* The caller is beginning to accumulate a new set of completions, so
1798 we need to find all of them now, and cache them for returning one at
1799 a time on future calls. */
1803 /* Free the storage used by LIST, but not by the strings inside.
1804 This is because rl_complete_internal () frees the strings. */
1810 /* Choose the default set of word break characters to break completions.
1811 If we later find out that we are doing completions on command strings
1812 (as opposed to strings supplied by the individual command completer
1813 functions, which can be any string) then we will switch to the
1814 special word break set for command strings, which leaves out the
1815 '-' character used in some commands. */
1817 rl_completer_word_break_characters
=
1818 gdb_completer_word_break_characters
;
1820 /* Decide whether to complete on a list of gdb commands or on symbols. */
1821 tmp_command
= (char *) alloca (point
+ 1);
1824 strncpy (tmp_command
, line_buffer
, point
);
1825 tmp_command
[point
] = '\0';
1826 /* Since text always contains some number of characters leading up
1827 to point, we can find the equivalent position in tmp_command
1828 by subtracting that many characters from the end of tmp_command. */
1829 word
= tmp_command
+ point
- strlen (text
);
1833 /* An empty line we want to consider ambiguous; that is, it
1834 could be any command. */
1835 c
= (struct cmd_list_element
*) -1;
1840 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1843 /* Move p up to the next interesting thing. */
1844 while (*p
== ' ' || *p
== '\t')
1851 /* It is an unrecognized command. So there are no
1852 possible completions. */
1855 else if (c
== (struct cmd_list_element
*) -1)
1859 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1860 doesn't advance over that thing itself. Do so now. */
1862 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1864 if (q
!= tmp_command
+ point
)
1866 /* There is something beyond the ambiguous
1867 command, so there are no possible completions. For
1868 example, "info t " or "info t foo" does not complete
1869 to anything, because "info t" can be "info target" or
1875 /* We're trying to complete on the command which was ambiguous.
1876 This we can deal with. */
1879 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1884 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1886 /* Insure that readline does the right thing with respect to
1887 inserting quotes. */
1888 rl_completer_word_break_characters
=
1889 gdb_completer_command_word_break_characters
;
1894 /* We've recognized a full command. */
1896 if (p
== tmp_command
+ point
)
1898 /* There is no non-whitespace in the line beyond the command. */
1900 if (p
[-1] == ' ' || p
[-1] == '\t')
1902 /* The command is followed by whitespace; we need to complete
1903 on whatever comes after command. */
1906 /* It is a prefix command; what comes after it is
1907 a subcommand (e.g. "info "). */
1908 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1910 /* Insure that readline does the right thing
1911 with respect to inserting quotes. */
1912 rl_completer_word_break_characters
=
1913 gdb_completer_command_word_break_characters
;
1917 list
= complete_on_enum (c
->enums
, p
, word
);
1918 rl_completer_word_break_characters
=
1919 gdb_completer_command_word_break_characters
;
1923 /* It is a normal command; what comes after it is
1924 completed by the command's completer function. */
1925 list
= (*c
->completer
) (p
, word
);
1930 /* The command is not followed by whitespace; we need to
1931 complete on the command itself. e.g. "p" which is a
1932 command itself but also can complete to "print", "ptype"
1936 /* Find the command we are completing on. */
1938 while (q
> tmp_command
)
1940 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1946 list
= complete_on_cmdlist (result_list
, q
, word
);
1948 /* Insure that readline does the right thing
1949 with respect to inserting quotes. */
1950 rl_completer_word_break_characters
=
1951 gdb_completer_command_word_break_characters
;
1956 /* There is non-whitespace beyond the command. */
1958 if (c
->prefixlist
&& !c
->allow_unknown
)
1960 /* It is an unrecognized subcommand of a prefix command,
1961 e.g. "info adsfkdj". */
1966 list
= complete_on_enum (c
->enums
, p
, word
);
1970 /* It is a normal command. */
1971 list
= (*c
->completer
) (p
, word
);
1977 /* If we found a list of potential completions during initialization then
1978 dole them out one at a time. The vector of completions is NULL
1979 terminated, so after returning the last one, return NULL (and continue
1980 to do so) each time we are called after that, until a new list is
1985 output
= list
[index
];
1993 /* Can't do this because readline hasn't yet checked the word breaks
1994 for figuring out whether to insert a quote. */
1996 /* Make sure the word break characters are set back to normal for the
1997 next time that readline tries to complete something. */
1998 rl_completer_word_break_characters
=
1999 gdb_completer_word_break_characters
;
2005 /* Line completion interface function for readline. */
2008 readline_line_completion_function (text
, matches
)
2012 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
2015 /* Skip over a possibly quoted word (as defined by the quote characters
2016 and word break characters the completer uses). Returns pointer to the
2017 location after the "word". */
2023 char quote_char
= '\0';
2026 for (scan
= str
; *scan
!= '\0'; scan
++)
2028 if (quote_char
!= '\0')
2030 /* Ignore everything until the matching close quote char */
2031 if (*scan
== quote_char
)
2033 /* Found matching close quote. */
2038 else if (strchr (gdb_completer_quote_characters
, *scan
))
2040 /* Found start of a quoted string. */
2043 else if (strchr (gdb_completer_word_break_characters
, *scan
))
2057 #if STOP_SIGNAL == SIGTSTP
2058 signal (SIGTSTP
, SIG_DFL
);
2060 kill (getpid (), SIGTSTP
);
2061 signal (SIGTSTP
, stop_sig
);
2063 signal (STOP_SIGNAL
, stop_sig
);
2065 printf_unfiltered ("%s", get_prompt ());
2066 gdb_flush (gdb_stdout
);
2068 /* Forget about any previous command -- null line now will do nothing. */
2071 #endif /* STOP_SIGNAL */
2073 /* Initialize signal handlers. */
2078 /* Under System V the default disposition of a signal is reinstated after
2079 the signal is caught and delivered to an application process. On such
2080 systems one must restore the replacement signal handler if one wishes
2081 to continue handling the signal in one's program. On BSD systems this
2082 is not needed but it is harmless, and it simplifies the code to just do
2083 it unconditionally. */
2084 signal (signo
, do_nothing
);
2090 signal (SIGINT
, request_quit
);
2092 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2093 to the inferior and breakpoints will be ignored. */
2095 signal (SIGTRAP
, SIG_DFL
);
2098 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2099 passed to the inferior, which we don't want. It would be
2100 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2101 on BSD4.3 systems using vfork, that can affect the
2102 GDB process as well as the inferior (the signal handling tables
2103 might be in memory, shared between the two). Since we establish
2104 a handler for SIGQUIT, when we call exec it will set the signal
2105 to SIG_DFL for us. */
2106 signal (SIGQUIT
, do_nothing
);
2108 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
2109 signal (SIGHUP
, disconnect
);
2111 signal (SIGFPE
, float_handler
);
2113 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2114 signal (SIGWINCH
, SIGWINCH_HANDLER
);
2118 /* Read one line from the command input stream `instream'
2119 into the local static buffer `linebuffer' (whose current length
2121 The buffer is made bigger as necessary.
2122 Returns the address of the start of the line.
2124 NULL is returned for end of file.
2126 *If* the instream == stdin & stdin is a terminal, the line read
2127 is copied into the file line saver (global var char *line,
2128 length linesize) so that it can be duplicated.
2130 This routine either uses fancy command line editing or
2131 simple input as the user has requested. */
2134 command_line_input (prompt_arg
, repeat
, annotation_suffix
)
2137 char *annotation_suffix
;
2139 static char *linebuffer
= 0;
2140 static unsigned linelength
= 0;
2144 char *local_prompt
= prompt_arg
;
2148 /* The annotation suffix must be non-NULL. */
2149 if (annotation_suffix
== NULL
)
2150 annotation_suffix
= "";
2152 if (annotation_level
> 1 && instream
== stdin
)
2154 local_prompt
= alloca ((prompt_arg
== NULL
? 0 : strlen (prompt_arg
))
2155 + strlen (annotation_suffix
) + 40);
2156 if (prompt_arg
== NULL
)
2157 local_prompt
[0] = '\0';
2159 strcpy (local_prompt
, prompt_arg
);
2160 strcat (local_prompt
, "\n\032\032");
2161 strcat (local_prompt
, annotation_suffix
);
2162 strcat (local_prompt
, "\n");
2165 if (linebuffer
== 0)
2168 linebuffer
= (char *) xmalloc (linelength
);
2173 /* Control-C quits instantly if typed while in this loop
2174 since it should not wait until the user types a newline. */
2180 signal (STOP_SIGNAL
, handle_stop_sig
);
2182 signal (STOP_SIGNAL
, stop_sig
);
2188 /* Make sure that all output has been output. Some machines may let
2189 you get away with leaving out some of the gdb_flush, but not all. */
2191 gdb_flush (gdb_stdout
);
2192 gdb_flush (gdb_stderr
);
2194 if (source_file_name
!= NULL
)
2196 ++source_line_number
;
2197 sprintf (source_error
,
2198 "%s%s:%d: Error in sourced command file:\n",
2201 source_line_number
);
2202 error_pre_print
= source_error
;
2205 if (annotation_level
> 1 && instream
== stdin
)
2207 printf_unfiltered ("\n\032\032pre-");
2208 printf_unfiltered (annotation_suffix
);
2209 printf_unfiltered ("\n");
2212 /* Don't use fancy stuff if not talking to stdin. */
2213 if (readline_hook
&& instream
== NULL
)
2215 rl
= (*readline_hook
) (local_prompt
);
2217 else if (command_editing_p
&& instream
== stdin
&& ISATTY (instream
))
2219 rl
= readline (local_prompt
);
2223 rl
= gdb_readline (local_prompt
);
2226 if (annotation_level
> 1 && instream
== stdin
)
2228 printf_unfiltered ("\n\032\032post-");
2229 printf_unfiltered (annotation_suffix
);
2230 printf_unfiltered ("\n");
2233 if (!rl
|| rl
== (char *) EOF
)
2238 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
2240 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
2241 nline
= (char *) xrealloc (linebuffer
, linelength
);
2242 p
+= nline
- linebuffer
;
2246 /* Copy line. Don't copy null at end. (Leaves line alone
2247 if this was just a newline) */
2251 free (rl
); /* Allocated in readline. */
2253 if (p
== linebuffer
|| *(p
- 1) != '\\')
2256 p
--; /* Put on top of '\'. */
2257 local_prompt
= (char *) 0;
2262 signal (STOP_SIGNAL
, SIG_DFL
);
2269 #define SERVER_COMMAND_LENGTH 7
2271 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
2272 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
2275 /* Note that we don't set `line'. Between this and the check in
2276 dont_repeat, this insures that repeating will still do the
2279 return linebuffer
+ SERVER_COMMAND_LENGTH
;
2282 /* Do history expansion if that is wished. */
2283 if (history_expansion_p
&& instream
== stdin
2284 && ISATTY (instream
))
2286 char *history_value
;
2289 *p
= '\0'; /* Insert null now. */
2290 expanded
= history_expand (linebuffer
, &history_value
);
2293 /* Print the changes. */
2294 printf_unfiltered ("%s\n", history_value
);
2296 /* If there was an error, call this function again. */
2299 free (history_value
);
2300 return command_line_input (prompt_arg
, repeat
, annotation_suffix
);
2302 if (strlen (history_value
) > linelength
)
2304 linelength
= strlen (history_value
) + 1;
2305 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
2307 strcpy (linebuffer
, history_value
);
2308 p
= linebuffer
+ strlen (linebuffer
);
2309 free (history_value
);
2313 /* If we just got an empty line, and that is supposed
2314 to repeat the previous command, return the value in the
2316 if (repeat
&& p
== linebuffer
)
2318 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
2324 /* Add line to history if appropriate. */
2325 if (instream
== stdin
2326 && ISATTY (stdin
) && *linebuffer
)
2327 add_history (linebuffer
);
2329 /* Note: lines consisting solely of comments are added to the command
2330 history. This is useful when you type a command, and then
2331 realize you don't want to execute it quite yet. You can comment
2332 out the command and then later fetch it from the value history
2333 and remove the '#'. The kill ring is probably better, but some
2334 people are in the habit of commenting things out. */
2336 *p1
= '\0'; /* Found a comment. */
2338 /* Save into global buffer if appropriate. */
2341 if (linelength
> linesize
)
2343 line
= xrealloc (line
, linelength
);
2344 linesize
= linelength
;
2346 strcpy (line
, linebuffer
);
2354 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2355 code bodies. This is typically used when we encounter an "else"
2356 clause for an "if" command. */
2359 realloc_body_list (command
, new_length
)
2360 struct command_line
*command
;
2364 struct command_line
**body_list
;
2366 n
= command
->body_count
;
2368 /* Nothing to do? */
2369 if (new_length
<= n
)
2372 body_list
= (struct command_line
**)
2373 xmalloc (sizeof (struct command_line
*) * new_length
);
2375 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
2377 free (command
->body_list
);
2378 command
->body_list
= body_list
;
2379 command
->body_count
= new_length
;
2382 /* Read one line from the input stream. If the command is an "else" or
2383 "end", return such an indication to the caller. */
2385 static enum misc_command_type
2386 read_next_line (command
)
2387 struct command_line
**command
;
2389 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
2392 if (control_level
>= 254)
2393 error ("Control nesting too deep!\n");
2395 /* Set a prompt based on the nesting of the control commands. */
2396 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
2398 for (i
= 0; i
< control_level
; i
++)
2399 control_prompt
[i
] = ' ';
2400 control_prompt
[i
] = '>';
2401 control_prompt
[i
+ 1] = '\0';
2402 prompt_ptr
= (char *) &control_prompt
[0];
2407 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
2409 /* Not sure what to do here. */
2413 /* Strip leading and trailing whitespace. */
2414 while (*p
== ' ' || *p
== '\t')
2417 p1
= p
+ strlen (p
);
2418 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
2421 /* Blanks and comments don't really do anything, but we need to
2422 distinguish them from else, end and other commands which can be
2424 if (p1
== p
|| p
[0] == '#')
2427 /* Is this the end of a simple, while, or if control structure? */
2428 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2431 /* Is the else clause of an if control structure? */
2432 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
2433 return else_command
;
2435 /* Check for while, if, break, continue, etc and build a new command
2436 line structure for them. */
2437 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
2438 *command
= build_command_line (while_control
, p
+ 6);
2439 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
2440 *command
= build_command_line (if_control
, p
+ 3);
2441 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
2443 *command
= (struct command_line
*)
2444 xmalloc (sizeof (struct command_line
));
2445 (*command
)->next
= NULL
;
2446 (*command
)->line
= NULL
;
2447 (*command
)->control_type
= break_control
;
2448 (*command
)->body_count
= 0;
2449 (*command
)->body_list
= NULL
;
2451 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
2453 *command
= (struct command_line
*)
2454 xmalloc (sizeof (struct command_line
));
2455 (*command
)->next
= NULL
;
2456 (*command
)->line
= NULL
;
2457 (*command
)->control_type
= continue_control
;
2458 (*command
)->body_count
= 0;
2459 (*command
)->body_list
= NULL
;
2463 /* A normal command. */
2464 *command
= (struct command_line
*)
2465 xmalloc (sizeof (struct command_line
));
2466 (*command
)->next
= NULL
;
2467 (*command
)->line
= savestring (p
, p1
- p
);
2468 (*command
)->control_type
= simple_control
;
2469 (*command
)->body_count
= 0;
2470 (*command
)->body_list
= NULL
;
2473 /* Nothing special. */
2477 /* Recursively read in the control structures and create a command_line
2478 structure from them.
2480 The parent_control parameter is the control structure in which the
2481 following commands are nested. */
2483 static enum command_control_type
2484 recurse_read_control_structure (current_cmd
)
2485 struct command_line
*current_cmd
;
2487 int current_body
, i
;
2488 enum misc_command_type val
;
2489 enum command_control_type ret
;
2490 struct command_line
**body_ptr
, *child_tail
, *next
;
2495 /* Sanity checks. */
2496 if (current_cmd
->control_type
== simple_control
)
2498 error ("Recursed on a simple control type\n");
2499 return invalid_control
;
2502 if (current_body
> current_cmd
->body_count
)
2504 error ("Allocated body is smaller than this command type needs\n");
2505 return invalid_control
;
2508 /* Read lines from the input stream and build control structures. */
2514 val
= read_next_line (&next
);
2516 /* Just skip blanks and comments. */
2517 if (val
== nop_command
)
2520 if (val
== end_command
)
2522 if (current_cmd
->control_type
== while_control
2523 || current_cmd
->control_type
== if_control
)
2525 /* Success reading an entire control structure. */
2526 ret
= simple_control
;
2531 ret
= invalid_control
;
2536 /* Not the end of a control structure. */
2537 if (val
== else_command
)
2539 if (current_cmd
->control_type
== if_control
2540 && current_body
== 1)
2542 realloc_body_list (current_cmd
, 2);
2549 ret
= invalid_control
;
2556 child_tail
->next
= next
;
2560 body_ptr
= current_cmd
->body_list
;
2561 for (i
= 1; i
< current_body
; i
++)
2570 /* If the latest line is another control structure, then recurse
2572 if (next
->control_type
== while_control
2573 || next
->control_type
== if_control
)
2576 ret
= recurse_read_control_structure (next
);
2579 if (ret
!= simple_control
)
2589 /* Read lines from the input stream and accumulate them in a chain of
2590 struct command_line's, which is then returned. For input from a
2591 terminal, the special command "end" is used to mark the end of the
2592 input, and is not included in the returned chain of commands. */
2594 #define END_MESSAGE "End with a line saying just \"end\"."
2596 struct command_line
*
2597 read_command_lines (prompt_arg
, from_tty
)
2601 struct command_line
*head
, *tail
, *next
;
2602 struct cleanup
*old_chain
;
2603 enum command_control_type ret
;
2604 enum misc_command_type val
;
2607 if (readline_begin_hook
)
2609 /* Note - intentional to merge messages with no newline */
2610 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
2612 else if (from_tty
&& input_from_terminal_p ())
2614 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
2615 gdb_flush (gdb_stdout
);
2623 val
= read_next_line (&next
);
2625 /* Ignore blank lines or comments. */
2626 if (val
== nop_command
)
2629 if (val
== end_command
)
2631 ret
= simple_control
;
2635 if (val
!= ok_command
)
2637 ret
= invalid_control
;
2641 if (next
->control_type
== while_control
2642 || next
->control_type
== if_control
)
2645 ret
= recurse_read_control_structure (next
);
2648 if (ret
== invalid_control
)
2659 old_chain
= make_cleanup ((make_cleanup_func
) free_command_lines
,
2669 if (ret
!= invalid_control
)
2671 discard_cleanups (old_chain
);
2674 do_cleanups (old_chain
);
2677 if (readline_end_hook
)
2679 (*readline_end_hook
) ();
2684 /* Free a chain of struct command_line's. */
2687 free_command_lines (lptr
)
2688 struct command_line
**lptr
;
2690 register struct command_line
*l
= *lptr
;
2691 register struct command_line
*next
;
2692 struct command_line
**blist
;
2697 if (l
->body_count
> 0)
2699 blist
= l
->body_list
;
2700 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2701 free_command_lines (blist
);
2710 /* Add an element to the list of info subcommands. */
2713 add_info (name
, fun
, doc
)
2715 void (*fun
) PARAMS ((char *, int));
2718 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2721 /* Add an alias to the list of info subcommands. */
2724 add_info_alias (name
, oldname
, abbrev_flag
)
2729 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2732 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2733 Therefore, its own definition is called only for "info" with no args. */
2737 info_command (arg
, from_tty
)
2741 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2742 help_list (infolist
, "info ", -1, gdb_stdout
);
2745 /* The "complete" command is used by Emacs to implement completion. */
2749 complete_command (arg
, from_tty
)
2761 argpoint
= strlen (arg
);
2763 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2765 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2767 printf_unfiltered ("%s\n", completion
);
2772 /* The "show" command with no arguments shows all the settings. */
2776 show_command (arg
, from_tty
)
2780 cmd_show_list (showlist
, from_tty
, "");
2783 /* Add an element to the list of commands. */
2786 add_com (name
, class, fun
, doc
)
2788 enum command_class
class;
2789 void (*fun
) PARAMS ((char *, int));
2792 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2795 /* Add an alias or abbreviation command to the list of commands. */
2798 add_com_alias (name
, oldname
, class, abbrev_flag
)
2801 enum command_class
class;
2804 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2811 error ("Argument required (%s).", why
);
2816 help_command (command
, from_tty
)
2818 int from_tty
; /* Ignored */
2820 help_cmd (command
, gdb_stdout
);
2824 validate_comname (comname
)
2830 error_no_arg ("name of command to define");
2835 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
2836 error ("Junk in argument list: \"%s\"", p
);
2841 /* This is just a placeholder in the command data structures. */
2843 user_defined_command (ignore
, from_tty
)
2850 define_command (comname
, from_tty
)
2854 register struct command_line
*cmds
;
2855 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2856 char *tem
= comname
;
2858 #define HOOK_STRING "hook-"
2861 validate_comname (comname
);
2863 /* Look it up, and verify that we got an exact match. */
2864 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2865 if (c
&& !STREQ (comname
, c
->name
))
2870 if (c
->class == class_user
|| c
->class == class_alias
)
2871 tem
= "Redefine command \"%s\"? ";
2873 tem
= "Really redefine built-in command \"%s\"? ";
2874 if (!query (tem
, c
->name
))
2875 error ("Command \"%s\" not redefined.", c
->name
);
2878 /* If this new command is a hook, then mark the command which it
2879 is hooking. Note that we allow hooking `help' commands, so that
2880 we can hook the `stop' pseudo-command. */
2882 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2884 /* Look up cmd it hooks, and verify that we got an exact match. */
2885 tem
= comname
+ HOOK_LEN
;
2886 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2887 if (hookc
&& !STREQ (comname
+ HOOK_LEN
, hookc
->name
))
2891 warning ("Your new `%s' command does not hook any existing command.",
2893 if (!query ("Proceed? "))
2894 error ("Not confirmed.");
2898 comname
= savestring (comname
, strlen (comname
));
2900 /* If the rest of the commands will be case insensitive, this one
2901 should behave in the same manner. */
2902 for (tem
= comname
; *tem
; tem
++)
2904 *tem
= tolower (*tem
);
2906 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
2907 cmds
= read_command_lines (tmpbuf
, from_tty
);
2909 if (c
&& c
->class == class_user
)
2910 free_command_lines (&c
->user_commands
);
2912 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2913 (c
&& c
->class == class_user
)
2914 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2915 newc
->user_commands
= cmds
;
2917 /* If this new command is a hook, then mark both commands as being
2921 hookc
->hook
= newc
; /* Target gets hooked. */
2922 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2927 document_command (comname
, from_tty
)
2931 struct command_line
*doclines
;
2932 register struct cmd_list_element
*c
;
2933 char *tem
= comname
;
2936 validate_comname (comname
);
2938 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2940 if (c
->class != class_user
)
2941 error ("Command \"%s\" is built-in.", comname
);
2943 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
2944 doclines
= read_command_lines (tmpbuf
, from_tty
);
2950 register struct command_line
*cl1
;
2951 register int len
= 0;
2953 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2954 len
+= strlen (cl1
->line
) + 1;
2956 c
->doc
= (char *) xmalloc (len
+ 1);
2959 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2961 strcat (c
->doc
, cl1
->line
);
2963 strcat (c
->doc
, "\n");
2967 free_command_lines (&doclines
);
2970 /* Print the GDB banner. */
2972 print_gdb_version (stream
)
2975 /* From GNU coding standards, first line is meant to be easy for a
2976 program to parse, and is just canonical program name and version
2977 number, which starts after last space. */
2979 fprintf_filtered (stream
, "GNU gdb %s\n", version
);
2981 /* Second line is a copyright notice. */
2983 fprintf_filtered (stream
, "Copyright 1998 Free Software Foundation, Inc.\n");
2985 /* Following the copyright is a brief statement that the program is
2986 free software, that users are free to copy and change it on
2987 certain conditions, that it is covered by the GNU GPL, and that
2988 there is no warranty. */
2990 fprintf_filtered (stream
, "\
2991 GDB is free software, covered by the GNU General Public License, and you are\n\
2992 welcome to change it and/or distribute copies of it under certain conditions.\n\
2993 Type \"show copying\" to see the conditions.\n\
2994 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2996 /* After the required info we print the configuration information. */
2998 fprintf_filtered (stream
, "This GDB was configured as \"");
2999 if (!STREQ (host_name
, target_name
))
3001 fprintf_filtered (stream
, "--host=%s --target=%s", host_name
, target_name
);
3005 fprintf_filtered (stream
, "%s", host_name
);
3007 fprintf_filtered (stream
, "\".");
3012 show_version (args
, from_tty
)
3017 print_gdb_version (gdb_stdout
);
3018 printf_filtered ("\n");
3022 /* get_prompt: access method for the GDB prompt string. */
3024 #define MAX_PROMPT_SIZE 256
3027 * int get_prompt_1 (char * buf);
3029 * Work-horse for get_prompt (called via catch_errors).
3030 * Argument is buffer to hold the formatted prompt.
3032 * Returns: 1 for success (use formatted prompt)
3033 * 0 for failure (use gdb_prompt_string).
3036 static int gdb_prompt_escape
;
3039 get_prompt_1 (formatted_prompt
)
3040 char *formatted_prompt
;
3045 local_prompt
= PROMPT (0);
3047 local_prompt
= gdb_prompt_string
;
3050 if (gdb_prompt_escape
== 0)
3052 return 0; /* do no formatting */
3055 /* formatted prompt */
3057 char fmt
[40], *promptp
, *outp
, *tmp
;
3064 struct type
*arg_type
, *elt_type
;
3066 promptp
= local_prompt
;
3067 outp
= formatted_prompt
;
3069 while (*promptp
!= '\0')
3071 int available
= MAX_PROMPT_SIZE
- (outp
- formatted_prompt
) - 1;
3073 if (*promptp
!= gdb_prompt_escape
)
3075 if (available
>= 1) /* overflow protect */
3076 *outp
++ = *promptp
++;
3080 /* GDB prompt string contains escape char. Parse for arg.
3081 Two consecutive escape chars followed by arg followed by
3082 a comma means to insert the arg using a default format.
3083 Otherwise a printf format string may be included between
3084 the two escape chars. eg:
3085 %%foo, insert foo using default format
3086 %2.2f%foo, insert foo using "%2.2f" format
3087 A mismatch between the format string and the data type
3088 of "foo" is an error (which we don't know how to protect
3091 fmt
[0] = '\0'; /* assume null format string */
3092 if (promptp
[1] == gdb_prompt_escape
) /* double esc char */
3094 promptp
+= 2; /* skip past two escape chars. */
3098 /* extract format string from between two esc chars */
3102 fmt
[i
++] = *promptp
++; /* copy format string */
3104 while (i
< sizeof (fmt
) - 1 &&
3105 *promptp
!= gdb_prompt_escape
&&
3108 if (*promptp
!= gdb_prompt_escape
)
3109 error ("Syntax error at prompt position %d",
3110 promptp
- local_prompt
);
3113 promptp
++; /* skip second escape char */
3114 fmt
[i
++] = '\0'; /* terminate the format string */
3118 arg_val
= parse_to_comma_and_eval (&promptp
);
3119 if (*promptp
== ',')
3120 promptp
++; /* skip past the comma */
3121 arg_type
= check_typedef (VALUE_TYPE (arg_val
));
3122 switch (TYPE_CODE (arg_type
))
3124 case TYPE_CODE_ARRAY
:
3125 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3126 if (TYPE_LENGTH (arg_type
) > 0 &&
3127 TYPE_LENGTH (elt_type
) == 1 &&
3128 TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
3130 int len
= TYPE_LENGTH (arg_type
);
3132 if (VALUE_LAZY (arg_val
))
3133 value_fetch_lazy (arg_val
);
3134 tmp
= VALUE_CONTENTS (arg_val
);
3136 if (len
> available
)
3137 len
= available
; /* overflow protect */
3139 /* FIXME: how to protect GDB from crashing
3140 from bad user-supplied format string? */
3142 sprintf (outp
, fmt
, tmp
);
3144 strncpy (outp
, tmp
, len
);
3149 elt_type
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
3150 addrval
= value_as_pointer (arg_val
);
3152 if (TYPE_LENGTH (elt_type
) == 1 &&
3153 TYPE_CODE (elt_type
) == TYPE_CODE_INT
&&
3156 /* display it as a string */
3157 char *default_fmt
= "%s";
3161 /* Limiting the number of bytes that the following call
3162 will read protects us from sprintf overflow later. */
3163 i
= target_read_string (addrval
, /* src */
3165 available
, /* len */
3167 if (err
) /* read failed */
3168 error ("%s on target_read", safe_strerror (err
));
3170 tmp
[i
] = '\0'; /* force-terminate string */
3171 /* FIXME: how to protect GDB from crashing
3172 from bad user-supplied format string? */
3173 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3179 /* display it as a pointer */
3180 char *default_fmt
= "0x%x";
3182 /* FIXME: how to protect GDB from crashing
3183 from bad user-supplied format string? */
3184 if (available
>= 16 /*? */ ) /* overflow protect */
3185 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3191 char *default_fmt
= "%g";
3193 doubleval
= value_as_double (arg_val
);
3194 /* FIXME: how to protect GDB from crashing
3195 from bad user-supplied format string? */
3196 if (available
>= 16 /*? */ ) /* overflow protect */
3197 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3198 (double) doubleval
);
3203 char *default_fmt
= "%d";
3205 longval
= value_as_long (arg_val
);
3206 /* FIXME: how to protect GDB from crashing
3207 from bad user-supplied format string? */
3208 if (available
>= 16 /*? */ ) /* overflow protect */
3209 sprintf (outp
, fmt
[0] == 0 ? default_fmt
: fmt
,
3213 case TYPE_CODE_BOOL
:
3215 /* no default format for bool */
3216 longval
= value_as_long (arg_val
);
3217 if (available
>= 8 /*? */ ) /* overflow protect */
3220 strcpy (outp
, "<true>");
3222 strcpy (outp
, "<false>");
3226 case TYPE_CODE_ENUM
:
3228 /* no default format for enum */
3229 longval
= value_as_long (arg_val
);
3230 len
= TYPE_NFIELDS (arg_type
);
3231 /* find enum name if possible */
3232 for (i
= 0; i
< len
; i
++)
3233 if (TYPE_FIELD_BITPOS (arg_type
, i
) == longval
)
3234 break; /* match -- end loop */
3236 if (i
< len
) /* enum name found */
3238 char *name
= TYPE_FIELD_NAME (arg_type
, i
);
3240 strncpy (outp
, name
, available
);
3241 /* in casel available < strlen (name), */
3242 outp
[available
] = '\0';
3246 if (available
>= 16 /*? */ ) /* overflow protect */
3247 sprintf (outp
, "%ld", (long) longval
);
3251 case TYPE_CODE_VOID
:
3253 break; /* void type -- no output */
3255 error ("bad data type at prompt position %d",
3256 promptp
- local_prompt
);
3259 outp
+= strlen (outp
);
3262 *outp
++ = '\0'; /* terminate prompt string */
3270 static char buf
[MAX_PROMPT_SIZE
];
3272 if (catch_errors (get_prompt_1
, buf
, "bad formatted prompt: ",
3275 return &buf
[0]; /* successful formatted prompt */
3279 /* Prompt could not be formatted. */
3283 return gdb_prompt_string
;
3291 /* ??rehrauer: I don't know why this fails, since it looks as though
3292 assignments to prompt are wrapped in calls to savestring...
3297 PROMPT (0) = savestring (s
, strlen (s
));
3299 gdb_prompt_string
= savestring (s
, strlen (s
));
3303 /* If necessary, make the user confirm that we should quit. Return
3304 non-zero if we should quit, zero if we shouldn't. */
3309 if (inferior_pid
!= 0 && target_has_execution
)
3313 /* This is something of a hack. But there's no reliable way to
3314 see if a GUI is running. The `use_windows' variable doesn't
3317 s
= "A debugging session is active.\nDo you still want to close the debugger?";
3318 else if (attach_flag
)
3319 s
= "The program is running. Quit anyway (and detach it)? ";
3321 s
= "The program is running. Exit anyway? ";
3330 /* Quit without asking for confirmation. */
3333 quit_force (args
, from_tty
)
3339 /* An optional expression may be used to cause gdb to terminate with the
3340 value of that expression. */
3343 value_ptr val
= parse_and_eval (args
);
3345 exit_code
= (int) value_as_long (val
);
3348 if (inferior_pid
!= 0 && target_has_execution
)
3351 target_detach (args
, from_tty
);
3356 /* UDI wants this, to kill the TIP. */
3359 /* Save the history information if it is appropriate to do so. */
3360 if (write_history_p
&& history_filename
)
3361 write_history (history_filename
);
3363 do_final_cleanups (ALL_CLEANUPS
); /* Do any final cleanups before exiting */
3366 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3367 /* The above does not need to be inside a tuiDo(), since
3368 * it is not manipulating the curses screen, but rather,
3369 * it is tearing it down.
3378 /* Handle the quit command. */
3381 quit_command (args
, from_tty
)
3385 if (!quit_confirm ())
3386 error ("Not confirmed.");
3387 quit_force (args
, from_tty
);
3390 /* Returns whether GDB is running on a terminal and whether the user
3391 desires that questions be asked of them on that terminal. */
3394 input_from_terminal_p ()
3396 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
3401 pwd_command (args
, from_tty
)
3406 error ("The \"pwd\" command does not take an argument: %s", args
);
3407 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3409 if (!STREQ (gdb_dirbuf
, current_directory
))
3410 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3411 current_directory
, gdb_dirbuf
);
3413 printf_unfiltered ("Working directory %s.\n", current_directory
);
3417 cd_command (dir
, from_tty
)
3422 /* Found something other than leading repetitions of "/..". */
3423 int found_real_path
;
3426 /* If the new directory is absolute, repeat is a no-op; if relative,
3427 repeat might be useful but is more likely to be a mistake. */
3431 error_no_arg ("new working directory");
3433 dir
= tilde_expand (dir
);
3434 make_cleanup (free
, dir
);
3436 if (chdir (dir
) < 0)
3437 perror_with_name (dir
);
3439 #if defined(_WIN32) || defined(__MSDOS__)
3440 /* There's too much mess with DOSish names like "d:", "d:.",
3441 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3442 simply get the canonicalized name of the current directory. */
3443 dir
= getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
3447 if (SLASH_P (dir
[len
-1]))
3449 /* Remove the trailing slash unless this is a root directory
3450 (including a drive letter on non-Unix systems). */
3451 if (!(len
== 1) /* "/" */
3452 #if defined(_WIN32) || defined(__MSDOS__)
3453 && !(!SLASH_P (*dir
) && ROOTED_P (dir
) && len
<= 3) /* "d:/" */
3459 dir
= savestring (dir
, len
);
3461 current_directory
= dir
;
3464 if (SLASH_P (current_directory
[strlen (current_directory
) - 1]))
3465 current_directory
= concat (current_directory
, dir
, NULL
);
3467 current_directory
= concat (current_directory
, SLASH_STRING
, dir
, NULL
);
3471 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3473 found_real_path
= 0;
3474 for (p
= current_directory
; *p
;)
3476 if (SLASH_P (p
[0]) && p
[1] == '.' && (p
[2] == 0 || SLASH_P (p
[2])))
3478 else if (SLASH_P (p
[0]) && p
[1] == '.' && p
[2] == '.'
3479 && (p
[3] == 0 || SLASH_P (p
[3])))
3481 if (found_real_path
)
3483 /* Search backwards for the directory just before the "/.."
3484 and obliterate it and the "/..". */
3486 while (q
!= current_directory
&& !SLASH_P (q
[-1]))
3489 if (q
== current_directory
)
3490 /* current_directory is
3491 a relative pathname ("can't happen"--leave it alone). */
3495 strcpy (q
- 1, p
+ 3);
3500 /* We are dealing with leading repetitions of "/..", for example
3501 "/../..", which is the Mach super-root. */
3506 found_real_path
= 1;
3511 forget_cached_source_info ();
3514 pwd_command ((char *) 0, 1);
3517 struct source_cleanup_lines_args
3521 char *old_pre_error
;
3522 char *old_error_pre_print
;
3526 source_cleanup_lines (args
)
3529 struct source_cleanup_lines_args
*p
=
3530 (struct source_cleanup_lines_args
*) args
;
3531 source_line_number
= p
->old_line
;
3532 source_file_name
= p
->old_file
;
3533 source_pre_error
= p
->old_pre_error
;
3534 error_pre_print
= p
->old_error_pre_print
;
3539 source_command (args
, from_tty
)
3544 struct cleanup
*old_cleanups
;
3546 struct source_cleanup_lines_args old_lines
;
3551 error ("source command requires pathname of file to source.");
3554 file
= tilde_expand (file
);
3555 old_cleanups
= make_cleanup (free
, file
);
3557 stream
= fopen (file
, FOPEN_RT
);
3561 perror_with_name (file
);
3566 make_cleanup ((make_cleanup_func
) fclose
, stream
);
3568 old_lines
.old_line
= source_line_number
;
3569 old_lines
.old_file
= source_file_name
;
3570 old_lines
.old_pre_error
= source_pre_error
;
3571 old_lines
.old_error_pre_print
= error_pre_print
;
3572 make_cleanup (source_cleanup_lines
, &old_lines
);
3573 source_line_number
= 0;
3574 source_file_name
= file
;
3575 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
3576 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
3577 make_cleanup (free
, source_pre_error
);
3578 /* This will get set every time we read a line. So it won't stay "" for
3580 error_pre_print
= "";
3582 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
3583 if (source_error_allocated
< needed_length
)
3585 source_error_allocated
*= 2;
3586 if (source_error_allocated
< needed_length
)
3587 source_error_allocated
= needed_length
;
3588 if (source_error
== NULL
)
3589 source_error
= xmalloc (source_error_allocated
);
3591 source_error
= xrealloc (source_error
, source_error_allocated
);
3594 read_command_file (stream
);
3596 do_cleanups (old_cleanups
);
3601 echo_command (text
, from_tty
)
3609 while ((c
= *p
++) != '\0')
3613 /* \ at end of argument is used after spaces
3614 so they won't be lost. */
3618 c
= parse_escape (&p
);
3620 printf_filtered ("%c", c
);
3623 printf_filtered ("%c", c
);
3626 /* Force this output to appear now. */
3628 gdb_flush (gdb_stdout
);
3633 dont_repeat_command (ignored
, from_tty
)
3637 *line
= 0; /* Can't call dont_repeat here because we're not
3638 necessarily reading from stdin. */
3641 /* Functions to manipulate command line editing control variables. */
3643 /* Number of commands to print in each call to show_commands. */
3644 #define Hist_print 10
3646 show_commands (args
, from_tty
)
3650 /* Index for history commands. Relative to history_base. */
3653 /* Number of the history entry which we are planning to display next.
3654 Relative to history_base. */
3657 /* The first command in the history which doesn't exist (i.e. one more
3658 than the number of the last command). Relative to history_base. */
3661 extern HIST_ENTRY
*history_get
PARAMS ((int));
3663 /* Print out some of the commands from the command history. */
3664 /* First determine the length of the history list. */
3665 hist_len
= history_size
;
3666 for (offset
= 0; offset
< history_size
; offset
++)
3668 if (!history_get (history_base
+ offset
))
3677 if (args
[0] == '+' && args
[1] == '\0')
3678 /* "info editing +" should print from the stored position. */
3681 /* "info editing <exp>" should print around command number <exp>. */
3682 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
3684 /* "show commands" means print the last Hist_print commands. */
3687 num
= hist_len
- Hist_print
;
3693 /* If there are at least Hist_print commands, we want to display the last
3694 Hist_print rather than, say, the last 6. */
3695 if (hist_len
- num
< Hist_print
)
3697 num
= hist_len
- Hist_print
;
3702 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
3704 printf_filtered ("%5d %s\n", history_base
+ offset
,
3705 (history_get (history_base
+ offset
))->line
);
3708 /* The next command we want to display is the next one that we haven't
3712 /* If the user repeats this command with return, it should do what
3713 "show commands +" does. This is unnecessary if arg is null,
3714 because "show commands +" is not useful after "show commands". */
3715 if (from_tty
&& args
)
3722 /* Called by do_setshow_command. */
3725 set_history_size_command (args
, from_tty
, c
)
3728 struct cmd_list_element
*c
;
3730 if (history_size
== INT_MAX
)
3731 unstifle_history ();
3732 else if (history_size
>= 0)
3733 stifle_history (history_size
);
3736 history_size
= INT_MAX
;
3737 error ("History size must be non-negative");
3743 set_history (args
, from_tty
)
3747 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3748 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
3753 show_history (args
, from_tty
)
3757 cmd_show_list (showhistlist
, from_tty
, "");
3760 int info_verbose
= 0; /* Default verbose msgs off */
3762 /* Called by do_setshow_command. An elaborate joke. */
3765 set_verbose (args
, from_tty
, c
)
3768 struct cmd_list_element
*c
;
3770 char *cmdname
= "verbose";
3771 struct cmd_list_element
*showcmd
;
3773 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
3777 c
->doc
= "Set verbose printing of informational messages.";
3778 showcmd
->doc
= "Show verbose printing of informational messages.";
3782 c
->doc
= "Set verbosity.";
3783 showcmd
->doc
= "Show verbosity.";
3788 float_handler (signo
)
3791 /* This message is based on ANSI C, section 4.7. Note that integer
3792 divide by zero causes this, so "float" is a misnomer. */
3793 signal (SIGFPE
, float_handler
);
3794 error ("Erroneous arithmetic operation.");
3808 enablebreaklist
= NULL
;
3813 showhistlist
= NULL
;
3814 unsethistlist
= NULL
;
3815 maintenancelist
= NULL
;
3816 maintenanceinfolist
= NULL
;
3817 maintenanceprintlist
= NULL
;
3818 setprintlist
= NULL
;
3819 showprintlist
= NULL
;
3820 setchecklist
= NULL
;
3821 showchecklist
= NULL
;
3824 /* Init the history buffer. Note that we are called after the init file(s)
3825 * have been read so that the user can change the history file via his
3826 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3827 * overrides all of this.
3835 tmpenv
= getenv ("HISTSIZE");
3837 history_size
= atoi (tmpenv
);
3838 else if (!history_size
)
3841 stifle_history (history_size
);
3843 tmpenv
= getenv ("GDBHISTFILE");
3845 history_filename
= savestring (tmpenv
, strlen (tmpenv
));
3846 else if (!history_filename
)
3848 /* We include the current directory so that if the user changes
3849 directories the file written will be the same as the one
3852 /* No leading dots in file names are allowed on MSDOS. */
3853 history_filename
= concat (current_directory
, "/_gdb_history", NULL
);
3855 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3858 read_history (history_filename
);
3864 struct cmd_list_element
*c
;
3866 /* If we are running the asynchronous version,
3867 we initialize the prompts differently. */
3870 gdb_prompt_string
= savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3874 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3875 whatever the DEFAULT_PROMPT is. */
3876 the_prompts
.top
= 0;
3878 PROMPT (0) = savestring (DEFAULT_PROMPT
, strlen (DEFAULT_PROMPT
));
3880 /* Set things up for annotation_level > 1, if the user ever decides
3882 async_annotation_suffix
= "prompt";
3883 /* Set the variable associated with the setshow prompt command. */
3884 new_async_prompt
= savestring (PROMPT (0), strlen (PROMPT (0)));
3886 gdb_prompt_escape
= 0; /* default to none. */
3888 /* Set the important stuff up for command editing. */
3889 command_editing_p
= 1;
3890 history_expansion_p
= 0;
3891 write_history_p
= 0;
3893 /* Setup important stuff for command line editing. */
3894 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3895 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3896 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3897 rl_readline_name
= "gdb";
3899 /* Define the classes of commands.
3900 They will appear in the help list in the reverse of this order. */
3902 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3903 "Maintenance commands.\n\
3904 Some gdb commands are provided just for use by gdb maintainers.\n\
3905 These commands are subject to frequent change, and may not be as\n\
3906 well documented as user commands.",
3908 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3909 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3910 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3911 The commands in this class are those defined by the user.\n\
3912 Use the \"define\" command to define a command.", &cmdlist
);
3913 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3915 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3916 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3917 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3918 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3919 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3920 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3921 counting from zero for the innermost (currently executing) frame.\n\n\
3922 At any time gdb identifies one frame as the \"selected\" frame.\n\
3923 Variable lookups are done with respect to the selected frame.\n\
3924 When the program being debugged stops, gdb selects the innermost frame.\n\
3925 The commands below can be used to select other frames by number or address.",
3927 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3929 add_com ("pwd", class_files
, pwd_command
,
3930 "Print working directory. This is used for your program as well.");
3931 c
= add_cmd ("cd", class_files
, cd_command
,
3932 "Set working directory to DIR for debugger and program being debugged.\n\
3933 The change does not take effect for the program being debugged\n\
3934 until the next time it is started.", &cmdlist
);
3935 c
->completer
= filename_completer
;
3937 /* The set prompt command is different depending whether or not the
3938 async version is run. NOTE: this difference is going to
3939 disappear as we make the event loop be the default engine of
3944 (add_set_cmd ("prompt", class_support
, var_string
,
3945 (char *) &gdb_prompt_string
, "Set gdb's prompt",
3951 c
= add_set_cmd ("prompt", class_support
, var_string
,
3952 (char *) &new_async_prompt
, "Set gdb's prompt",
3954 add_show_from_set (c
, &showlist
);
3955 c
->function
.sfunc
= set_async_prompt
;
3959 (add_set_cmd ("prompt-escape-char", class_support
, var_zinteger
,
3960 (char *) &gdb_prompt_escape
,
3961 "Set escape character for formatting of gdb's prompt",
3965 add_com ("echo", class_support
, echo_command
,
3966 "Print a constant string. Give string as argument.\n\
3967 C escape sequences may be used in the argument.\n\
3968 No newline is added at the end of the argument;\n\
3969 use \"\\n\" if you want a newline to be printed.\n\
3970 Since leading and trailing whitespace are ignored in command arguments,\n\
3971 if you want to print some you must use \"\\\" before leading whitespace\n\
3972 to be printed or after trailing whitespace.");
3973 add_com ("document", class_support
, document_command
,
3974 "Document a user-defined command.\n\
3975 Give command name as argument. Give documentation on following lines.\n\
3976 End with a line of just \"end\".");
3977 add_com ("define", class_support
, define_command
,
3978 "Define a new command name. Command name is argument.\n\
3979 Definition appears on following lines, one command per line.\n\
3980 End with a line of just \"end\".\n\
3981 Use the \"document\" command to give documentation for the new command.\n\
3982 Commands defined in this way may have up to ten arguments.");
3985 c
= add_cmd ("source", class_support
, source_command
,
3986 "Read commands from a file named FILE.\n\
3987 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3988 when gdb is started.", &cmdlist
);
3990 /* Punt file name, we can't help it easily. */
3991 c
= add_cmd ("source", class_support
, source_command
,
3992 "Read commands from a file named FILE.\n\
3993 Note that the file \".gdbinit\" is read automatically in this way\n\
3994 when gdb is started.", &cmdlist
);
3996 c
->completer
= filename_completer
;
3998 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3999 add_com ("help", class_support
, help_command
, "Print list of commands.");
4000 add_com_alias ("q", "quit", class_support
, 1);
4001 add_com_alias ("h", "help", class_support
, 1);
4003 add_com ("dont-repeat", class_support
, dont_repeat_command
, "Don't repeat this command.\n\
4004 Primarily used inside of user-defined commands that should not be repeated when\n\
4007 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *) &info_verbose
,
4010 add_show_from_set (c
, &showlist
);
4011 c
->function
.sfunc
= set_verbose
;
4012 set_verbose (NULL
, 0, c
);
4014 /* The set editing command is different depending whether or not the
4015 async version is run. NOTE: this difference is going to disappear
4016 as we make the event loop be the default engine of gdb. */
4020 (add_set_cmd ("editing", class_support
, var_boolean
, (char *) &command_editing_p
,
4021 "Set editing of command lines as they are typed.\n\
4022 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4023 Without an argument, command line editing is enabled. To edit, use\n\
4024 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
4029 c
= add_set_cmd ("editing", class_support
, var_boolean
, (char *) &async_command_editing_p
,
4030 "Set editing of command lines as they are typed.\n\
4031 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4032 Without an argument, command line editing is enabled. To edit, use\n\
4033 EMACS-like or VI-like commands like control-P or ESC.", &setlist
);
4035 add_show_from_set (c
, &showlist
);
4036 c
->function
.sfunc
= set_async_editing_command
;
4039 add_prefix_cmd ("history", class_support
, set_history
,
4040 "Generic command for setting command history parameters.",
4041 &sethistlist
, "set history ", 0, &setlist
);
4042 add_prefix_cmd ("history", class_support
, show_history
,
4043 "Generic command for showing command history parameters.",
4044 &showhistlist
, "show history ", 0, &showlist
);
4047 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *) &history_expansion_p
,
4048 "Set history expansion on command input.\n\
4049 Without an argument, history expansion is enabled.", &sethistlist
),
4053 (add_set_cmd ("save", no_class
, var_boolean
, (char *) &write_history_p
,
4054 "Set saving of the history record on exit.\n\
4055 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
4056 Without an argument, saving is enabled.", &sethistlist
),
4059 c
= add_set_cmd ("size", no_class
, var_integer
, (char *) &history_size
,
4060 "Set the size of the command history, \n\
4061 ie. the number of previous commands to keep a record of.", &sethistlist
);
4062 add_show_from_set (c
, &showhistlist
);
4063 c
->function
.sfunc
= set_history_size_command
;
4066 (add_set_cmd ("filename", no_class
, var_filename
, (char *) &history_filename
,
4067 "Set the filename in which to record the command history\n\
4068 (the list of previous commands of which a record is kept).", &sethistlist
),
4072 (add_set_cmd ("confirm", class_support
, var_boolean
,
4074 "Set whether to confirm potentially dangerous operations.",
4078 add_prefix_cmd ("info", class_info
, info_command
,
4079 "Generic command for showing things about the program being debugged.",
4080 &infolist
, "info ", 0, &cmdlist
);
4081 add_com_alias ("i", "info", class_info
, 1);
4083 add_com ("complete", class_obscure
, complete_command
,
4084 "List the completions for the rest of the line as a command.");
4086 add_prefix_cmd ("show", class_info
, show_command
,
4087 "Generic command for showing things about the debugger.",
4088 &showlist
, "show ", 0, &cmdlist
);
4089 /* Another way to get at the same thing. */
4090 add_info ("set", show_command
, "Show all GDB settings.");
4092 add_cmd ("commands", no_class
, show_commands
,
4093 "Show the history of commands you typed.\n\
4094 You can supply a command number to start with, or a `+' to start after\n\
4095 the previous command number shown.",
4098 add_cmd ("version", no_class
, show_version
,
4099 "Show what version of GDB this is.", &showlist
);
4101 add_com ("while", class_support
, while_command
,
4102 "Execute nested commands WHILE the conditional expression is non zero.\n\
4103 The conditional expression must follow the word `while' and must in turn be\n\
4104 followed by a new line. The nested commands must be entered one per line,\n\
4105 and should be terminated by the word `end'.");
4107 add_com ("if", class_support
, if_command
,
4108 "Execute nested commands once IF the conditional expression is non zero.\n\
4109 The conditional expression must follow the word `if' and must in turn be\n\
4110 followed by a new line. The nested commands must be entered one per line,\n\
4111 and should be terminated by the word 'else' or `end'. If an else clause\n\
4112 is used, the same rules apply to its nested commands as to the first ones.");
4114 /* If target is open when baud changes, it doesn't take effect until the
4115 next open (I think, not sure). */
4116 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
4117 var_zinteger
, (char *) &baud_rate
,
4118 "Set baud rate for remote serial I/O.\n\
4119 This value is used to set the speed of the serial port when debugging\n\
4120 using remote targets.", &setlist
),
4124 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *) &remote_debug
,
4125 "Set debugging of remote protocol.\n\
4126 When enabled, each packet sent or received with the remote target\n\
4127 is displayed.", &setlist
),
4131 add_set_cmd ("remotetimeout", no_class
, var_integer
, (char *) &remote_timeout
,
4132 "Set timeout limit to wait for target to respond.\n\
4133 This value is used to set the time limit for gdb to wait for a response\n\
4134 from the target.", &setlist
),
4137 /* The set annotate command is different depending whether or not
4138 the async version is run. NOTE: this difference is going to
4139 disappear as we make the event loop be the default engine of
4143 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4144 (char *) &annotation_level
, "Set annotation_level.\n\
4145 0 == normal; 1 == fullname (for use when running under emacs)\n\
4146 2 == output annotated suitably for use by programs that control GDB.",
4148 c
= add_show_from_set (c
, &showlist
);
4152 c
= add_set_cmd ("annotate", class_obscure
, var_zinteger
,
4153 (char *) &annotation_level
, "Set annotation_level.\n\
4154 0 == normal; 1 == fullname (for use when running under emacs)\n\
4155 2 == output annotated suitably for use by programs that control GDB.",
4157 add_show_from_set (c
, &showlist
);
4158 c
->function
.sfunc
= set_async_annotation_level
;
4163 (add_set_cmd ("exec-done-display", class_support
, var_boolean
, (char *) &exec_done_display_p
,
4164 "Set notification of completion for asynchronous execution commands.\n\
4165 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist
),