1 /* Handle lists of commands, their decoding and documentation, for GDB.
2 Copyright 1986, 1989, 1990, 1991, 1998, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "gnu-regex.h"
31 /* FIXME: this should be auto-configured! */
36 /* Prototypes for local functions */
38 static void undef_cmd_error (char *, char *);
40 static void show_user (char *, int);
42 static void show_user_1 (struct cmd_list_element
*, struct ui_file
*);
44 static void make_command (char *, int);
46 static void shell_escape (char *, int);
48 static int parse_binary_operation (char *);
50 static void print_doc_line (struct ui_file
*, char *);
52 static struct cmd_list_element
*find_cmd (char *command
,
54 struct cmd_list_element
*clist
,
55 int ignore_help_classes
,
57 static void apropos_cmd_helper (struct ui_file
*, struct cmd_list_element
*,
58 struct re_pattern_buffer
*, char *);
60 static void help_all (struct ui_file
*stream
);
62 void apropos_command (char *, int);
64 void _initialize_command (void);
66 /* Add element named NAME.
67 CLASS is the top level category into which commands are broken down
69 FUN should be the function to execute the command;
70 it will get a character string as argument, with leading
71 and trailing blanks already eliminated.
73 DOC is a documentation string for the command.
74 Its first line should be a complete sentence.
75 It should start with ? for a command that is an abbreviation
76 or with * for a command that most users don't need to know about.
78 Add this command to command list *LIST.
80 Returns a pointer to the added command (not necessarily the head
83 struct cmd_list_element
*
84 add_cmd (name
, class, fun
, doc
, list
)
86 enum command_class
class;
87 void (*fun
) PARAMS ((char *, int));
89 struct cmd_list_element
**list
;
91 register struct cmd_list_element
*c
92 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
93 struct cmd_list_element
*p
;
95 delete_cmd (name
, list
);
97 if (*list
== NULL
|| STRCMP ((*list
)->name
, name
) >= 0)
105 while (p
->next
&& STRCMP (p
->next
->name
, name
) <= 0)
115 c
->function
.cfunc
= fun
;
118 c
->replacement
= NULL
;
120 c
->prefixlist
= NULL
;
121 c
->prefixname
= NULL
;
122 c
->allow_unknown
= 0;
124 c
->completer
= make_symbol_completion_list
;
125 c
->type
= not_set_cmd
;
127 c
->var_type
= var_boolean
;
129 c
->user_commands
= NULL
;
131 c
->cmd_pointer
= NULL
;
137 /* Deprecates a command CMD.
138 REPLACEMENT is the name of the command which should be used in place
139 of this command, or NULL if no such command exists.
141 This function does not check to see if command REPLACEMENT exists
142 since gdb may not have gotten around to adding REPLACEMENT when this
145 Returns a pointer to the deprecated command. */
147 struct cmd_list_element
*
148 deprecate_cmd (cmd
, replacement
)
149 struct cmd_list_element
*cmd
;
152 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
154 if (replacement
!= NULL
)
155 cmd
->replacement
= replacement
;
157 cmd
->replacement
= NULL
;
163 /* Same as above, except that the abbrev_flag is set. */
165 #if 0 /* Currently unused */
167 struct cmd_list_element
*
168 add_abbrev_cmd (name
, class, fun
, doc
, list
)
170 enum command_class
class;
171 void (*fun
) PARAMS ((char *, int));
173 struct cmd_list_element
**list
;
175 register struct cmd_list_element
*c
176 = add_cmd (name
, class, fun
, doc
, list
);
184 struct cmd_list_element
*
185 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
188 enum command_class
class;
190 struct cmd_list_element
**list
;
192 /* Must do this since lookup_cmd tries to side-effect its first arg */
194 register struct cmd_list_element
*old
;
195 register struct cmd_list_element
*c
;
196 copied_name
= (char *) alloca (strlen (oldname
) + 1);
197 strcpy (copied_name
, oldname
);
198 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
202 delete_cmd (name
, list
);
206 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
207 c
->prefixlist
= old
->prefixlist
;
208 c
->prefixname
= old
->prefixname
;
209 c
->allow_unknown
= old
->allow_unknown
;
210 c
->abbrev_flag
= abbrev_flag
;
211 c
->cmd_pointer
= old
;
215 /* Like add_cmd but adds an element for a command prefix:
216 a name that should be followed by a subcommand to be looked up
217 in another command list. PREFIXLIST should be the address
218 of the variable containing that list. */
220 struct cmd_list_element
*
221 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
224 enum command_class
class;
225 void (*fun
) PARAMS ((char *, int));
227 struct cmd_list_element
**prefixlist
;
230 struct cmd_list_element
**list
;
232 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
233 c
->prefixlist
= prefixlist
;
234 c
->prefixname
= prefixname
;
235 c
->allow_unknown
= allow_unknown
;
239 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
241 struct cmd_list_element
*
242 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
245 enum command_class
class;
246 void (*fun
) PARAMS ((char *, int));
248 struct cmd_list_element
**prefixlist
;
251 struct cmd_list_element
**list
;
253 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
254 c
->prefixlist
= prefixlist
;
255 c
->prefixname
= prefixname
;
256 c
->allow_unknown
= allow_unknown
;
261 /* This is an empty "cfunc". */
263 not_just_help_class_command (args
, from_tty
)
269 /* This is an empty "sfunc". */
270 static void empty_sfunc (char *, int, struct cmd_list_element
*);
273 empty_sfunc (args
, from_tty
, c
)
276 struct cmd_list_element
*c
;
280 /* Add element named NAME to command list LIST (the list for set
281 or some sublist thereof).
282 CLASS is as in add_cmd.
283 VAR_TYPE is the kind of thing we are setting.
284 VAR is address of the variable being controlled by this command.
285 DOC is the documentation string. */
287 struct cmd_list_element
*
288 add_set_cmd (char *name
,
289 enum command_class
class,
293 struct cmd_list_element
**list
)
295 struct cmd_list_element
*c
296 = add_cmd (name
, class, NO_FUNCTION
, doc
, list
);
299 c
->var_type
= var_type
;
301 /* This needs to be something besides NO_FUNCTION so that this isn't
302 treated as a help class. */
303 c
->function
.sfunc
= empty_sfunc
;
307 /* Add element named NAME to command list LIST (the list for set
308 or some sublist thereof).
309 CLASS is as in add_cmd.
310 ENUMLIST is a list of strings which may follow NAME.
311 VAR is address of the variable which will contain the matching string
313 DOC is the documentation string. */
315 struct cmd_list_element
*
316 add_set_enum_cmd (char *name
,
317 enum command_class
class,
321 struct cmd_list_element
**list
)
323 struct cmd_list_element
*c
324 = add_set_cmd (name
, class, var_enum
, var
, doc
, list
);
330 /* Where SETCMD has already been added, add the corresponding show
331 command to LIST and return a pointer to the added command (not
332 necessarily the head of LIST). */
333 struct cmd_list_element
*
334 add_show_from_set (setcmd
, list
)
335 struct cmd_list_element
*setcmd
;
336 struct cmd_list_element
**list
;
338 struct cmd_list_element
*showcmd
=
339 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
340 struct cmd_list_element
*p
;
342 memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
343 delete_cmd (showcmd
->name
, list
);
344 showcmd
->type
= show_cmd
;
346 /* Replace "set " at start of docstring with "show ". */
347 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
348 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
349 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
351 fprintf_unfiltered (gdb_stderr
, "GDB internal error: Bad docstring for set command\n");
353 if (*list
== NULL
|| STRCMP ((*list
)->name
, showcmd
->name
) >= 0)
355 showcmd
->next
= *list
;
361 while (p
->next
&& STRCMP (p
->next
->name
, showcmd
->name
) <= 0)
365 showcmd
->next
= p
->next
;
372 /* Remove the command named NAME from the command list. */
375 delete_cmd (name
, list
)
377 struct cmd_list_element
**list
;
379 register struct cmd_list_element
*c
;
380 struct cmd_list_element
*p
;
382 while (*list
&& STREQ ((*list
)->name
, name
))
385 (*list
)->hookee
->hook
= 0; /* Hook slips out of its mouth */
392 for (c
= *list
; c
->next
;)
394 if (STREQ (c
->next
->name
, name
))
397 c
->next
->hookee
->hook
= 0; /* hooked cmd gets away. */
399 free ((PTR
) c
->next
);
406 /* Recursively walk the commandlist structures, and print out the
407 documentation of commands that match our regex in either their
408 name, or their documentation.
411 apropos_cmd_helper (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
412 struct re_pattern_buffer
*regex
, char *prefix
)
414 register struct cmd_list_element
*c
;
415 int returnvalue
=1; /*Needed to avoid double printing*/
416 /* Walk through the commands */
417 for (c
=commandlist
;c
;c
=c
->next
)
421 /* Try to match against the name*/
422 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
423 if (returnvalue
>= 0)
425 /* Stolen from help_cmd_list. We don't directly use
426 * help_cmd_list because it doesn't let us print out
429 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
430 print_doc_line (stream
, c
->doc
);
431 fputs_filtered ("\n", stream
);
432 returnvalue
=0; /*Set this so we don't print it again.*/
435 if (c
->doc
!= NULL
&& returnvalue
!= 0)
437 /* Try to match against documentation */
438 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
440 /* Stolen from help_cmd_list. We don't directly use
441 * help_cmd_list because it doesn't let us print out
444 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
445 print_doc_line (stream
, c
->doc
);
446 fputs_filtered ("\n", stream
);
449 /* Check if this command has subcommands */
450 if (c
->prefixlist
!= NULL
)
452 /* Recursively call ourselves on the subcommand list,
453 passing the right prefix in.
455 apropos_cmd_helper(stream
,*c
->prefixlist
,regex
,c
->prefixname
);
459 /* Search through names of commands and documentations for a certain
463 apropos_command (char *searchstr
, int from_tty
)
465 extern struct cmd_list_element
*cmdlist
; /*This is the main command list*/
467 char *pattern_fastmap
;
468 char errorbuffer
[512];
469 pattern_fastmap
=calloc(256,sizeof(char));
470 if (searchstr
== NULL
)
471 error("REGEXP string is empty");
473 if (regcomp(&pattern
,searchstr
,REG_ICASE
) == 0)
475 pattern
.fastmap
=pattern_fastmap
;
476 re_compile_fastmap(&pattern
);
477 apropos_cmd_helper(gdb_stdout
,cmdlist
,&pattern
,"");
481 regerror(regcomp(&pattern
,searchstr
,REG_ICASE
),NULL
,errorbuffer
,512);
482 error("Error in regular expression:%s",errorbuffer
);
484 free(pattern_fastmap
);
488 /* This command really has to deal with two things:
489 * 1) I want documentation on *this string* (usually called by
490 * "help commandname").
491 * 2) I want documentation on *this list* (usually called by
492 * giving a command that requires subcommands. Also called by saying
495 * I am going to split this into two seperate comamnds, help_cmd and
500 help_cmd (command
, stream
)
502 struct ui_file
*stream
;
504 struct cmd_list_element
*c
;
505 extern struct cmd_list_element
*cmdlist
;
509 help_list (cmdlist
, "", all_classes
, stream
);
513 if (strcmp (command
, "all") == 0)
519 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
524 /* There are three cases here.
525 If c->prefixlist is nonzero, we have a prefix command.
526 Print its documentation, then list its subcommands.
528 If c->function is nonzero, we really have a command.
529 Print its documentation and return.
531 If c->function is zero, we have a class name.
532 Print its documentation (as if it were a command)
533 and then set class to the number of this class
534 so that the commands in the class will be listed. */
536 fputs_filtered (c
->doc
, stream
);
537 fputs_filtered ("\n", stream
);
539 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
541 fprintf_filtered (stream
, "\n");
543 /* If this is a prefix command, print it's subcommands */
545 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
547 /* If this is a class name, print all of the commands in the class */
548 if (c
->function
.cfunc
== NULL
)
549 help_list (cmdlist
, "", c
->class, stream
);
552 fprintf_filtered (stream
, "\nThis command has a hook defined: %s\n",
557 * Get a specific kind of help on a command list.
560 * CMDTYPE is the prefix to use in the title string.
561 * CLASS is the class with which to list the nodes of this list (see
562 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
563 * everything, ALL_CLASSES for just classes, and non-negative for only things
564 * in a specific class.
565 * and STREAM is the output stream on which to print things.
566 * If you call this routine with a class >= 0, it recurses.
569 help_list (list
, cmdtype
, class, stream
)
570 struct cmd_list_element
*list
;
572 enum command_class
class;
573 struct ui_file
*stream
;
576 char *cmdtype1
, *cmdtype2
;
578 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
579 len
= strlen (cmdtype
);
580 cmdtype1
= (char *) alloca (len
+ 1);
582 cmdtype2
= (char *) alloca (len
+ 4);
587 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
589 strncpy (cmdtype2
, cmdtype
, len
- 1);
590 strcpy (cmdtype2
+ len
- 1, " sub");
593 if (class == all_classes
)
594 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
596 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
598 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
600 if (class == all_classes
)
601 fprintf_filtered (stream
, "\n\
602 Type \"help%s\" followed by a class name for a list of commands in that class.",
605 fprintf_filtered (stream
, "\n\
606 Type \"help%s\" followed by %scommand name for full documentation.\n\
607 Command name abbreviations are allowed if unambiguous.\n",
612 help_all (struct ui_file
*stream
)
614 struct cmd_list_element
*c
;
615 extern struct cmd_list_element
*cmdlist
;
617 for (c
= cmdlist
; c
; c
= c
->next
)
621 /* If this is a prefix command, print it's subcommands */
623 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 0, stream
);
625 /* If this is a class name, print all of the commands in the class */
626 else if (c
->function
.cfunc
== NULL
)
627 help_cmd_list (cmdlist
, c
->class, "", 0, stream
);
631 /* Print only the first line of STR on STREAM. */
633 print_doc_line (stream
, str
)
634 struct ui_file
*stream
;
637 static char *line_buffer
= 0;
638 static int line_size
;
644 line_buffer
= (char *) xmalloc (line_size
);
648 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
650 if (p
- str
> line_size
- 1)
652 line_size
= p
- str
+ 1;
653 free ((PTR
) line_buffer
);
654 line_buffer
= (char *) xmalloc (line_size
);
656 strncpy (line_buffer
, str
, p
- str
);
657 line_buffer
[p
- str
] = '\0';
658 if (islower (line_buffer
[0]))
659 line_buffer
[0] = toupper (line_buffer
[0]);
661 ui_out_text (uiout
, line_buffer
);
663 fputs_filtered (line_buffer
, stream
);
668 * Implement a help command on command list LIST.
669 * RECURSE should be non-zero if this should be done recursively on
670 * all sublists of LIST.
671 * PREFIX is the prefix to print before each command name.
672 * STREAM is the stream upon which the output should be written.
674 * A non-negative class number to list only commands in that
676 * ALL_COMMANDS to list all commands in list.
677 * ALL_CLASSES to list all classes in list.
679 * Note that RECURSE will be active on *all* sublists, not just the
680 * ones selected by the criteria above (ie. the selection mechanism
681 * is at the low level, not the high-level).
684 help_cmd_list (list
, class, prefix
, recurse
, stream
)
685 struct cmd_list_element
*list
;
686 enum command_class
class;
689 struct ui_file
*stream
;
691 register struct cmd_list_element
*c
;
693 for (c
= list
; c
; c
= c
->next
)
695 if (c
->abbrev_flag
== 0 &&
696 (class == all_commands
697 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
698 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
700 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
701 print_doc_line (stream
, c
->doc
);
702 fputs_filtered ("\n", stream
);
705 && c
->prefixlist
!= 0
706 && c
->abbrev_flag
== 0)
707 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
712 /* Search the input clist for 'command'. Return the command if
713 found (or NULL if not), and return the number of commands
716 static struct cmd_list_element
*
717 find_cmd (command
, len
, clist
, ignore_help_classes
, nfound
)
720 struct cmd_list_element
*clist
;
721 int ignore_help_classes
;
724 struct cmd_list_element
*found
, *c
;
726 found
= (struct cmd_list_element
*) NULL
;
728 for (c
= clist
; c
; c
= c
->next
)
729 if (!strncmp (command
, c
->name
, len
)
730 && (!ignore_help_classes
|| c
->function
.cfunc
))
734 if (c
->name
[len
] == '\0')
743 /* This routine takes a line of TEXT and a CLIST in which to start the
744 lookup. When it returns it will have incremented the text pointer past
745 the section of text it matched, set *RESULT_LIST to point to the list in
746 which the last word was matched, and will return a pointer to the cmd
747 list element which the text matches. It will return NULL if no match at
748 all was possible. It will return -1 (cast appropriately, ick) if ambigous
749 matches are possible; in this case *RESULT_LIST will be set to point to
750 the list in which there are ambiguous choices (and *TEXT will be set to
751 the ambiguous text string).
753 If the located command was an abbreviation, this routine returns the base
754 command of the abbreviation.
756 It does no error reporting whatsoever; control will always return
757 to the superior routine.
759 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
760 at the prefix_command (ie. the best match) *or* (special case) will be NULL
761 if no prefix command was ever found. For example, in the case of "info a",
762 "info" matches without ambiguity, but "a" could be "args" or "address", so
763 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
764 RESULT_LIST should not be interpeted as a pointer to the beginning of a
765 list; it simply points to a specific command. In the case of an ambiguous
766 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
767 "info t" can be "info types" or "info target"; upon return *TEXT has been
768 advanced past "info ").
770 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
771 affect the operation).
773 This routine does *not* modify the text pointed to by TEXT.
775 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
776 are actually help classes rather than commands (i.e. the function field of
777 the struct cmd_list_element is NULL). */
779 struct cmd_list_element
*
780 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
782 struct cmd_list_element
*clist
, **result_list
;
783 int ignore_help_classes
;
786 int len
, tmp
, nfound
;
787 struct cmd_list_element
*found
, *c
;
790 while (**text
== ' ' || **text
== '\t')
793 /* Treating underscores as part of command words is important
794 so that "set args_foo()" doesn't get interpreted as
795 "set args _foo()". */
797 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
799 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
800 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
804 /* If nothing but whitespace, return 0. */
810 /* *text and p now bracket the first command word to lookup (and
811 it's length is len). We copy this into a local temporary */
814 command
= (char *) alloca (len
+ 1);
815 for (tmp
= 0; tmp
< len
; tmp
++)
817 char x
= (*text
)[tmp
];
825 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
828 ** We didn't find the command in the entered case, so lower case it
831 if (!found
|| nfound
== 0)
833 for (tmp
= 0; tmp
< len
; tmp
++)
835 char x
= command
[tmp
];
836 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
838 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
841 /* If nothing matches, we have a simple failure. */
847 if (result_list
!= NULL
)
848 /* Will be modified in calling routine
849 if we know what the prefix command is. */
851 return (struct cmd_list_element
*) -1; /* Ambiguous. */
854 /* We've matched something on this list. Move text pointer forward. */
858 if (found
->cmd_pointer
)
860 /* We drop the alias (abbreviation) in favor of the command it is
861 pointing to. If the alias is deprecated, though, we need to
862 warn the user about it before we drop it. Note that while we
863 are warning about the alias, we may also warn about the command
864 itself and we will adjust the appropriate DEPRECATED_WARN_USER
867 if (found
->flags
& DEPRECATED_WARN_USER
)
868 deprecated_cmd_warning (&line
);
869 found
= found
->cmd_pointer
;
871 /* If we found a prefix command, keep looking. */
873 if (found
->prefixlist
)
875 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
876 ignore_help_classes
);
879 /* Didn't find anything; this is as far as we got. */
880 if (result_list
!= NULL
)
881 *result_list
= clist
;
884 else if (c
== (struct cmd_list_element
*) -1)
886 /* We've gotten this far properly, but the next step
887 is ambiguous. We need to set the result list to the best
888 we've found (if an inferior hasn't already set it). */
889 if (result_list
!= NULL
)
891 /* This used to say *result_list = *found->prefixlist
892 If that was correct, need to modify the documentation
893 at the top of this function to clarify what is supposed
895 *result_list
= found
;
906 if (result_list
!= NULL
)
907 *result_list
= clist
;
912 /* All this hair to move the space to the front of cmdtype */
915 undef_cmd_error (cmdtype
, q
)
918 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
922 strlen (cmdtype
) - 1,
926 /* Look up the contents of *LINE as a command in the command list LIST.
927 LIST is a chain of struct cmd_list_element's.
928 If it is found, return the struct cmd_list_element for that command
929 and update *LINE to point after the command name, at the first argument.
930 If not found, call error if ALLOW_UNKNOWN is zero
931 otherwise (or if error returns) return zero.
932 Call error if specified command is ambiguous,
933 unless ALLOW_UNKNOWN is negative.
934 CMDTYPE precedes the word "command" in the error message.
936 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
937 elements which are actually help classes rather than commands (i.e.
938 the function field of the struct cmd_list_element is 0). */
940 struct cmd_list_element
*
941 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
943 struct cmd_list_element
*list
;
946 int ignore_help_classes
;
948 struct cmd_list_element
*last_list
= 0;
949 struct cmd_list_element
*c
=
950 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
952 /* This is wrong for complete_command. */
953 char *ptr
= (*line
) + strlen (*line
) - 1;
955 /* Clear off trailing whitespace. */
956 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
966 error ("Lack of needed %scommand", cmdtype
);
971 while (isalnum (*p
) || *p
== '-')
974 q
= (char *) alloca (p
- *line
+ 1);
975 strncpy (q
, *line
, p
- *line
);
977 undef_cmd_error (cmdtype
, q
);
983 else if (c
== (struct cmd_list_element
*) -1)
985 /* Ambigous. Local values should be off prefixlist or called
987 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
989 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
990 struct cmd_list_element
*local_list
=
991 (last_list
? *(last_list
->prefixlist
) : list
);
993 if (local_allow_unknown
< 0)
996 return last_list
; /* Found something. */
998 return 0; /* Found nothing. */
1002 /* Report as error. */
1007 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1008 && (*line
)[amb_len
] != '\t');
1013 for (c
= local_list
; c
; c
= c
->next
)
1014 if (!strncmp (*line
, c
->name
, amb_len
))
1016 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1018 if (strlen (ambbuf
))
1019 strcat (ambbuf
, ", ");
1020 strcat (ambbuf
, c
->name
);
1024 strcat (ambbuf
, "..");
1028 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
1030 return 0; /* lint */
1035 /* We've got something. It may still not be what the caller
1036 wants (if this command *needs* a subcommand). */
1037 while (**line
== ' ' || **line
== '\t')
1040 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1041 undef_cmd_error (c
->prefixname
, *line
);
1043 /* Seems to be what he wants. Return it. */
1049 /* We are here presumably because an alias or command in *TEXT is
1050 deprecated and a warning message should be generated. This function
1051 decodes *TEXT and potentially generates a warning message as outlined
1054 Example for 'set endian big' which has a fictitious alias 'seb'.
1056 If alias wasn't used in *TEXT, and the command is deprecated:
1057 "warning: 'set endian big' is deprecated."
1059 If alias was used, and only the alias is deprecated:
1060 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1062 If alias was used and command is deprecated (regardless of whether the
1063 alias itself is deprecated:
1065 "warning: 'set endian big' (seb) is deprecated."
1067 After the message has been sent, clear the appropriate flags in the
1068 command and/or the alias so the user is no longer bothered.
1072 deprecated_cmd_warning (char **text
)
1074 struct cmd_list_element
*alias
= NULL
;
1075 struct cmd_list_element
*prefix_cmd
= NULL
;
1076 struct cmd_list_element
*cmd
= NULL
;
1077 struct cmd_list_element
*c
;
1080 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1081 /* return if text doesn't evaluate to a command */
1084 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1085 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1086 /* return if nothing is deprecated */
1089 printf_filtered ("Warning:");
1091 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1092 printf_filtered (" '%s', an alias for the", alias
->name
);
1094 printf_filtered (" command '");
1097 printf_filtered ("%s", prefix_cmd
->prefixname
);
1099 printf_filtered ("%s", cmd
->name
);
1101 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1102 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1104 printf_filtered ("' is deprecated.\n");
1107 /* if it is only the alias that is deprecated, we want to indicate the
1108 new alias, otherwise we'll indicate the new command */
1110 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1112 if (alias
->replacement
)
1113 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1115 printf_filtered ("No alternative known.\n\n");
1119 if (cmd
->replacement
)
1120 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1122 printf_filtered ("No alternative known.\n\n");
1125 /* We've warned you, now we'll keep quiet */
1127 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1129 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1134 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1135 Return 1 on success, 0 on failure.
1137 If LINE refers to an alias, *alias will point to that alias.
1139 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1140 command) set *prefix_cmd.
1142 Set *cmd to point to the command LINE indicates.
1144 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1145 exist, they are NULL when we return.
1149 lookup_cmd_composition (char *text
,
1150 struct cmd_list_element
**alias
,
1151 struct cmd_list_element
**prefix_cmd
,
1152 struct cmd_list_element
**cmd
)
1155 int len
, tmp
, nfound
;
1156 struct cmd_list_element
*cur_list
;
1157 struct cmd_list_element
*prev_cmd
;
1166 /* Go through as many command lists as we need to
1167 to find the command TEXT refers to. */
1171 while (*text
== ' ' || *text
== '\t')
1174 /* Treating underscores as part of command words is important
1175 so that "set args_foo()" doesn't get interpreted as
1176 "set args _foo()". */
1178 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1180 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
1181 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
1185 /* If nothing but whitespace, return. */
1191 /* text and p now bracket the first command word to lookup (and
1192 it's length is len). We copy this into a local temporary */
1194 command
= (char *) alloca (len
+ 1);
1195 for (tmp
= 0; tmp
< len
; tmp
++)
1200 command
[len
] = '\0';
1205 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1207 /* We didn't find the command in the entered case, so lower case it
1210 if (!*cmd
|| nfound
== 0)
1212 for (tmp
= 0; tmp
< len
; tmp
++)
1214 char x
= command
[tmp
];
1215 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1217 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1220 if (*cmd
== (struct cmd_list_element
*) -1)
1222 return 0; /* ambiguous */
1226 return 0; /* nothing found */
1229 if ((*cmd
)->cmd_pointer
)
1231 /* cmd was actually an alias, we note that an alias was used
1232 (by assigning *alais) and we set *cmd.
1235 *cmd
= (*cmd
)->cmd_pointer
;
1237 *prefix_cmd
= prev_cmd
;
1239 if ((*cmd
)->prefixlist
)
1240 cur_list
= *(*cmd
)->prefixlist
;
1252 /* Look up the contents of *LINE as a command in the command list LIST.
1253 LIST is a chain of struct cmd_list_element's.
1254 If it is found, return the struct cmd_list_element for that command
1255 and update *LINE to point after the command name, at the first argument.
1256 If not found, call error if ALLOW_UNKNOWN is zero
1257 otherwise (or if error returns) return zero.
1258 Call error if specified command is ambiguous,
1259 unless ALLOW_UNKNOWN is negative.
1260 CMDTYPE precedes the word "command" in the error message. */
1262 struct cmd_list_element
*
1263 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
1265 struct cmd_list_element
*list
;
1270 register struct cmd_list_element
*c
, *found
;
1273 char *processed_cmd
;
1276 /* Skip leading whitespace. */
1278 while (**line
== ' ' || **line
== '\t')
1281 /* Clear out trailing whitespace. */
1283 p
= *line
+ strlen (*line
);
1284 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1288 /* Find end of command name. */
1291 while (*p
== '-' || isalnum (*p
))
1294 /* Look up the command name.
1295 If exact match, keep that.
1296 Otherwise, take command abbreviated, if unique. Note that (in my
1297 opinion) a null string does *not* indicate ambiguity; simply the
1298 end of the argument. */
1303 error ("Lack of needed %scommand", cmdtype
);
1307 /* Copy over to a local buffer, converting to lowercase on the way.
1308 This is in case the command being parsed is a subcommand which
1309 doesn't match anything, and that's ok. We want the original
1310 untouched for the routine of the original command. */
1312 processed_cmd
= (char *) alloca (p
- *line
+ 1);
1313 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
1315 char x
= (*line
)[cmd_len
];
1317 processed_cmd
[cmd_len
] = tolower (x
);
1319 processed_cmd
[cmd_len
] = x
;
1321 processed_cmd
[cmd_len
] = '\0';
1323 /* Check all possibilities in the current command list. */
1326 for (c
= list
; c
; c
= c
->next
)
1328 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1332 if (c
->name
[cmd_len
] == 0)
1340 /* Report error for undefined command name. */
1344 if (nfound
> 1 && allow_unknown
>= 0)
1347 for (c
= list
; c
; c
= c
->next
)
1348 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1350 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
1352 if (strlen (ambbuf
))
1353 strcat (ambbuf
, ", ");
1354 strcat (ambbuf
, c
->name
);
1358 strcat (ambbuf
, "..");
1362 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
1363 processed_cmd
, ambbuf
);
1365 else if (!allow_unknown
)
1366 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
1370 /* Skip whitespace before the argument. */
1372 while (*p
== ' ' || *p
== '\t')
1376 if (found
->prefixlist
&& *p
)
1378 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
1379 found
->allow_unknown
);
1388 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1390 /* Return a vector of char pointers which point to the different
1391 possible completions in LIST of TEXT.
1393 WORD points in the same buffer as TEXT, and completions should be
1394 returned relative to this position. For example, suppose TEXT is "foo"
1395 and we want to complete to "foobar". If WORD is "oo", return
1396 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1399 complete_on_cmdlist (list
, text
, word
)
1400 struct cmd_list_element
*list
;
1404 struct cmd_list_element
*ptr
;
1406 int sizeof_matchlist
;
1408 int textlen
= strlen (text
);
1410 sizeof_matchlist
= 10;
1411 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1414 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1415 if (!strncmp (ptr
->name
, text
, textlen
)
1416 && !ptr
->abbrev_flag
1417 && (ptr
->function
.cfunc
1418 || ptr
->prefixlist
))
1420 if (matches
== sizeof_matchlist
)
1422 sizeof_matchlist
*= 2;
1423 matchlist
= (char **) xrealloc ((char *) matchlist
,
1425 * sizeof (char *)));
1428 matchlist
[matches
] = (char *)
1429 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1431 strcpy (matchlist
[matches
], ptr
->name
);
1432 else if (word
> text
)
1434 /* Return some portion of ptr->name. */
1435 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1439 /* Return some of text plus ptr->name. */
1440 strncpy (matchlist
[matches
], word
, text
- word
);
1441 matchlist
[matches
][text
- word
] = '\0';
1442 strcat (matchlist
[matches
], ptr
->name
);
1449 free ((PTR
) matchlist
);
1454 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1455 * sizeof (char *)));
1456 matchlist
[matches
] = (char *) 0;
1462 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1464 /* Return a vector of char pointers which point to the different
1465 possible completions in CMD of TEXT.
1467 WORD points in the same buffer as TEXT, and completions should be
1468 returned relative to this position. For example, suppose TEXT is "foo"
1469 and we want to complete to "foobar". If WORD is "oo", return
1470 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1473 complete_on_enum (enumlist
, text
, word
)
1479 int sizeof_matchlist
;
1481 int textlen
= strlen (text
);
1485 sizeof_matchlist
= 10;
1486 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1489 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1490 if (strncmp (name
, text
, textlen
) == 0)
1492 if (matches
== sizeof_matchlist
)
1494 sizeof_matchlist
*= 2;
1495 matchlist
= (char **) xrealloc ((char *) matchlist
,
1497 * sizeof (char *)));
1500 matchlist
[matches
] = (char *)
1501 xmalloc (strlen (word
) + strlen (name
) + 1);
1503 strcpy (matchlist
[matches
], name
);
1504 else if (word
> text
)
1506 /* Return some portion of name. */
1507 strcpy (matchlist
[matches
], name
+ (word
- text
));
1511 /* Return some of text plus name. */
1512 strncpy (matchlist
[matches
], word
, text
- word
);
1513 matchlist
[matches
][text
- word
] = '\0';
1514 strcat (matchlist
[matches
], name
);
1521 free ((PTR
) matchlist
);
1526 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1527 * sizeof (char *)));
1528 matchlist
[matches
] = (char *) 0;
1535 parse_binary_operation (arg
)
1543 length
= strlen (arg
);
1545 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
1548 if (!strncmp (arg
, "on", length
)
1549 || !strncmp (arg
, "1", length
)
1550 || !strncmp (arg
, "yes", length
))
1552 else if (!strncmp (arg
, "off", length
)
1553 || !strncmp (arg
, "0", length
)
1554 || !strncmp (arg
, "no", length
))
1558 error ("\"on\" or \"off\" expected.");
1563 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1564 of the argument, and FROM_TTY is nonzero if this command is being entered
1565 directly by the user (i.e. these are just like any other
1566 command). C is the command list element for the command. */
1568 do_setshow_command (arg
, from_tty
, c
)
1571 struct cmd_list_element
*c
;
1573 if (c
->type
== set_cmd
)
1575 switch (c
->var_type
)
1586 new = (char *) xmalloc (strlen (arg
) + 2);
1589 while ((ch
= *p
++) != '\000')
1593 /* \ at end of argument is used after spaces
1594 so they won't be lost. */
1595 /* This is obsolete now that we no longer strip
1596 trailing whitespace and actually, the backslash
1597 didn't get here in my test, readline or
1598 something did something funky with a backslash
1599 right before a newline. */
1602 ch
= parse_escape (&p
);
1604 break; /* C loses */
1612 if (*(p
- 1) != '\\')
1616 new = (char *) xrealloc (new, q
- new);
1617 if (*(char **) c
->var
!= NULL
)
1618 free (*(char **) c
->var
);
1619 *(char **) c
->var
= new;
1622 case var_string_noescape
:
1625 if (*(char **) c
->var
!= NULL
)
1626 free (*(char **) c
->var
);
1627 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1631 error_no_arg ("filename to set it to.");
1632 if (*(char **) c
->var
!= NULL
)
1633 free (*(char **) c
->var
);
1634 *(char **) c
->var
= tilde_expand (arg
);
1637 *(int *) c
->var
= parse_binary_operation (arg
);
1641 error_no_arg ("integer to set it to.");
1642 *(unsigned int *) c
->var
= parse_and_eval_address (arg
);
1643 if (*(unsigned int *) c
->var
== 0)
1644 *(unsigned int *) c
->var
= UINT_MAX
;
1650 error_no_arg ("integer to set it to.");
1651 val
= parse_and_eval_address (arg
);
1653 *(int *) c
->var
= INT_MAX
;
1654 else if (val
>= INT_MAX
)
1655 error ("integer %u out of range", val
);
1657 *(int *) c
->var
= val
;
1662 error_no_arg ("integer to set it to.");
1663 *(int *) c
->var
= parse_and_eval_address (arg
);
1673 /* if no argument was supplied, print an informative error message */
1677 strcpy (msg
, "Requires an argument. Valid arguments are ");
1678 for (i
= 0; c
->enums
[i
]; i
++)
1682 strcat (msg
, c
->enums
[i
]);
1688 p
= strchr (arg
, ' ');
1696 for (i
= 0; c
->enums
[i
]; i
++)
1697 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
1699 match
= c
->enums
[i
];
1704 error ("Undefined item: \"%s\".", arg
);
1707 error ("Ambiguous item \"%s\".", arg
);
1709 *(char **) c
->var
= match
;
1713 error ("gdb internal error: bad var_type in do_setshow_command");
1716 else if (c
->type
== show_cmd
)
1719 struct cleanup
*old_chain
;
1720 struct ui_stream
*stb
;
1723 stb
= ui_out_stream_new (uiout
);
1724 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1727 /* Print doc minus "show" at start. */
1728 print_doc_line (gdb_stdout
, c
->doc
+ 5);
1731 ui_out_text (uiout
, " is ");
1732 ui_out_wrap_hint (uiout
, " ");
1734 switch (c
->var_type
)
1740 if (*(unsigned char **) c
->var
)
1741 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
1745 case var_string_noescape
:
1748 if (*(char **) c
->var
)
1749 fputs_filtered (*(char **) c
->var
, stb
->stream
);
1753 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
1756 if (*(unsigned int *) c
->var
== UINT_MAX
)
1758 fputs_filtered ("unlimited", stb
->stream
);
1761 /* else fall through */
1763 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
1766 if (*(int *) c
->var
== INT_MAX
)
1768 fputs_filtered ("unlimited", stb
->stream
);
1771 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
1775 error ("gdb internal error: bad var_type in do_setshow_command");
1778 ui_out_text (uiout
, "\"");
1779 ui_out_field_stream (uiout
, "value", stb
);
1781 ui_out_text (uiout
, "\"");
1782 ui_out_text (uiout
, ".\n");
1783 do_cleanups (old_chain
);
1785 fputs_filtered (" is ", gdb_stdout
);
1787 switch (c
->var_type
)
1791 fputs_filtered ("\"", gdb_stdout
);
1792 if (*(unsigned char **) c
->var
)
1793 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
1794 fputs_filtered ("\"", gdb_stdout
);
1797 case var_string_noescape
:
1800 fputs_filtered ("\"", gdb_stdout
);
1801 if (*(char **) c
->var
)
1802 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
1803 fputs_filtered ("\"", gdb_stdout
);
1806 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
1809 if (*(unsigned int *) c
->var
== UINT_MAX
)
1811 fputs_filtered ("unlimited", gdb_stdout
);
1814 /* else fall through */
1816 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
1819 if (*(int *) c
->var
== INT_MAX
)
1821 fputs_filtered ("unlimited", gdb_stdout
);
1824 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
1828 error ("gdb internal error: bad var_type in do_setshow_command");
1830 fputs_filtered (".\n", gdb_stdout
);
1834 error ("gdb internal error: bad cmd_type in do_setshow_command");
1835 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1836 if (c
->type
== set_cmd
&& set_hook
)
1840 /* Show all the settings in a list of show commands. */
1843 cmd_show_list (list
, from_tty
, prefix
)
1844 struct cmd_list_element
*list
;
1849 ui_out_list_begin (uiout
, "showlist");
1851 for (; list
!= NULL
; list
= list
->next
)
1853 /* If we find a prefix, run its list, prefixing our output by its
1854 prefix (with "show " skipped). */
1856 if (list
->prefixlist
&& !list
->abbrev_flag
)
1858 ui_out_list_begin (uiout
, "optionlist");
1859 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
1860 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1861 ui_out_list_end (uiout
);
1863 if (list
->type
== show_cmd
)
1865 ui_out_list_begin (uiout
, "option");
1866 ui_out_text (uiout
, prefix
);
1867 ui_out_field_string (uiout
, "name", list
->name
);
1868 ui_out_text (uiout
, ": ");
1869 do_setshow_command ((char *) NULL
, from_tty
, list
);
1870 ui_out_list_end (uiout
);
1873 if (list
->prefixlist
&& !list
->abbrev_flag
)
1874 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1875 if (list
->type
== show_cmd
)
1877 fputs_filtered (prefix
, gdb_stdout
);
1878 fputs_filtered (list
->name
, gdb_stdout
);
1879 fputs_filtered (": ", gdb_stdout
);
1880 do_setshow_command ((char *) NULL
, from_tty
, list
);
1885 ui_out_list_end (uiout
);
1891 shell_escape (arg
, from_tty
)
1896 /* If ARG is NULL, they want an inferior shell, but `system' just
1897 reports if the shell is available when passed a NULL arg. */
1898 int rc
= system (arg
? arg
: "");
1901 arg
= "inferior shell";
1905 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", arg
,
1906 safe_strerror (errno
));
1907 gdb_flush (gdb_stderr
);
1911 fprintf_unfiltered (gdb_stderr
, "%s exited with status %d\n", arg
, rc
);
1912 gdb_flush (gdb_stderr
);
1915 /* Make sure to return to the directory GDB thinks it is, in case the
1916 shell command we just ran changed it. */
1917 chdir (current_directory
);
1919 #else /* Can fork. */
1920 int rc
, status
, pid
;
1921 char *p
, *user_shell
;
1923 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1924 user_shell
= "/bin/sh";
1926 /* Get the name of the shell for arg0 */
1927 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1930 p
++; /* Get past '/' */
1932 if ((pid
= fork ()) == 0)
1935 execl (user_shell
, p
, 0);
1937 execl (user_shell
, p
, "-c", arg
, 0);
1939 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", user_shell
,
1940 safe_strerror (errno
));
1941 gdb_flush (gdb_stderr
);
1946 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1949 error ("Fork failed");
1950 #endif /* Can fork. */
1954 make_command (arg
, from_tty
)
1964 p
= xmalloc (sizeof ("make ") + strlen (arg
));
1965 strcpy (p
, "make ");
1966 strcpy (p
+ sizeof ("make ") - 1, arg
);
1969 shell_escape (p
, from_tty
);
1973 show_user_1 (c
, stream
)
1974 struct cmd_list_element
*c
;
1975 struct ui_file
*stream
;
1977 register struct command_line
*cmdlines
;
1979 cmdlines
= c
->user_commands
;
1982 fputs_filtered ("User command ", stream
);
1983 fputs_filtered (c
->name
, stream
);
1984 fputs_filtered (":\n", stream
);
1987 print_command_lines (uiout
, cmdlines
, 1);
1988 fputs_filtered ("\n", stream
);
1992 print_command_line (cmdlines
, 4, stream
);
1993 cmdlines
= cmdlines
->next
;
1995 fputs_filtered ("\n", stream
);
2001 show_user (args
, from_tty
)
2005 struct cmd_list_element
*c
;
2006 extern struct cmd_list_element
*cmdlist
;
2010 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
2011 if (c
->class != class_user
)
2012 error ("Not a user command.");
2013 show_user_1 (c
, gdb_stdout
);
2017 for (c
= cmdlist
; c
; c
= c
->next
)
2019 if (c
->class == class_user
)
2020 show_user_1 (c
, gdb_stdout
);
2026 _initialize_command ()
2028 add_com ("shell", class_support
, shell_escape
,
2029 "Execute the rest of the line as a shell command. \n\
2030 With no arguments, run an inferior shell.");
2032 /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
2033 be a really useful feature. Unfortunatly, the below wont do
2034 this. Instead it adds support for the form ``(gdb) ! ls''
2035 (i.e. the space is required). If the ``!'' command below is
2036 added the complains about no ``!'' command would be replaced by
2037 complains about how the ``!'' command is broken :-) */
2039 add_com_alias ("!", "shell", class_support
, 0);
2041 add_com ("make", class_support
, make_command
,
2042 "Run the ``make'' program using the rest of the line as arguments.");
2043 add_cmd ("user", no_class
, show_user
,
2044 "Show definitions of user defined commands.\n\
2045 Argument is the name of the user defined command.\n\
2046 With no argument, show definitions of all user defined commands.", &showlist
);
2047 add_com ("apropos", class_support
, apropos_command
, "Search for commands matching a REGEXP");