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
PARAMS ((char *, char *));
40 static void show_user
PARAMS ((char *, int));
42 static void show_user_1 (struct cmd_list_element
*, struct ui_file
*);
44 static void make_command
PARAMS ((char *, int));
46 static void shell_escape
PARAMS ((char *, int));
48 static int parse_binary_operation
PARAMS ((char *));
50 static void print_doc_line (struct ui_file
*, char *);
52 static struct cmd_list_element
*find_cmd
PARAMS ((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 void apropos_command (char *, int);
62 void _initialize_command
PARAMS ((void));
64 /* Add element named NAME.
65 CLASS is the top level category into which commands are broken down
67 FUN should be the function to execute the command;
68 it will get a character string as argument, with leading
69 and trailing blanks already eliminated.
71 DOC is a documentation string for the command.
72 Its first line should be a complete sentence.
73 It should start with ? for a command that is an abbreviation
74 or with * for a command that most users don't need to know about.
76 Add this command to command list *LIST.
78 Returns a pointer to the added command (not necessarily the head
81 struct cmd_list_element
*
82 add_cmd (name
, class, fun
, doc
, list
)
84 enum command_class
class;
85 void (*fun
) PARAMS ((char *, int));
87 struct cmd_list_element
**list
;
89 register struct cmd_list_element
*c
90 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
91 struct cmd_list_element
*p
;
93 delete_cmd (name
, list
);
95 if (*list
== NULL
|| STRCMP ((*list
)->name
, name
) >= 0)
103 while (p
->next
&& STRCMP (p
->next
->name
, name
) <= 0)
113 c
->function
.cfunc
= fun
;
116 c
->replacement
= NULL
;
118 c
->prefixlist
= NULL
;
119 c
->prefixname
= NULL
;
120 c
->allow_unknown
= 0;
122 c
->completer
= make_symbol_completion_list
;
123 c
->type
= not_set_cmd
;
125 c
->var_type
= var_boolean
;
127 c
->user_commands
= NULL
;
129 c
->cmd_pointer
= NULL
;
135 /* Deprecates a command CMD.
136 REPLACEMENT is the name of the command which should be used in place
137 of this command, or NULL if no such command exists.
139 This function does not check to see if command REPLACEMENT exists
140 since gdb may not have gotten around to adding REPLACEMENT when this
143 Returns a pointer to the deprecated command. */
145 struct cmd_list_element
*
146 deprecate_cmd (cmd
, replacement
)
147 struct cmd_list_element
*cmd
;
150 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
152 if (replacement
!= NULL
)
153 cmd
->replacement
= replacement
;
155 cmd
->replacement
= NULL
;
161 /* Same as above, except that the abbrev_flag is set. */
163 #if 0 /* Currently unused */
165 struct cmd_list_element
*
166 add_abbrev_cmd (name
, class, fun
, doc
, list
)
168 enum command_class
class;
169 void (*fun
) PARAMS ((char *, int));
171 struct cmd_list_element
**list
;
173 register struct cmd_list_element
*c
174 = add_cmd (name
, class, fun
, doc
, list
);
182 struct cmd_list_element
*
183 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
186 enum command_class
class;
188 struct cmd_list_element
**list
;
190 /* Must do this since lookup_cmd tries to side-effect its first arg */
192 register struct cmd_list_element
*old
;
193 register struct cmd_list_element
*c
;
194 copied_name
= (char *) alloca (strlen (oldname
) + 1);
195 strcpy (copied_name
, oldname
);
196 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
200 delete_cmd (name
, list
);
204 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
205 c
->prefixlist
= old
->prefixlist
;
206 c
->prefixname
= old
->prefixname
;
207 c
->allow_unknown
= old
->allow_unknown
;
208 c
->abbrev_flag
= abbrev_flag
;
209 c
->cmd_pointer
= old
;
213 /* Like add_cmd but adds an element for a command prefix:
214 a name that should be followed by a subcommand to be looked up
215 in another command list. PREFIXLIST should be the address
216 of the variable containing that list. */
218 struct cmd_list_element
*
219 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
222 enum command_class
class;
223 void (*fun
) PARAMS ((char *, int));
225 struct cmd_list_element
**prefixlist
;
228 struct cmd_list_element
**list
;
230 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
231 c
->prefixlist
= prefixlist
;
232 c
->prefixname
= prefixname
;
233 c
->allow_unknown
= allow_unknown
;
237 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
239 struct cmd_list_element
*
240 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
243 enum command_class
class;
244 void (*fun
) PARAMS ((char *, int));
246 struct cmd_list_element
**prefixlist
;
249 struct cmd_list_element
**list
;
251 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
252 c
->prefixlist
= prefixlist
;
253 c
->prefixname
= prefixname
;
254 c
->allow_unknown
= allow_unknown
;
259 /* This is an empty "cfunc". */
261 not_just_help_class_command (args
, from_tty
)
267 /* This is an empty "sfunc". */
268 static void empty_sfunc
PARAMS ((char *, int, struct cmd_list_element
*));
271 empty_sfunc (args
, from_tty
, c
)
274 struct cmd_list_element
*c
;
278 /* Add element named NAME to command list LIST (the list for set
279 or some sublist thereof).
280 CLASS is as in add_cmd.
281 VAR_TYPE is the kind of thing we are setting.
282 VAR is address of the variable being controlled by this command.
283 DOC is the documentation string. */
285 struct cmd_list_element
*
286 add_set_cmd (name
, class, var_type
, var
, doc
, list
)
288 enum command_class
class;
292 struct cmd_list_element
**list
;
294 struct cmd_list_element
*c
295 = add_cmd (name
, class, NO_FUNCTION
, doc
, list
);
298 c
->var_type
= var_type
;
300 /* This needs to be something besides NO_FUNCTION so that this isn't
301 treated as a help class. */
302 c
->function
.sfunc
= empty_sfunc
;
306 /* Add element named NAME to command list LIST (the list for set
307 or some sublist thereof).
308 CLASS is as in add_cmd.
309 ENUMLIST is a list of strings which may follow NAME.
310 VAR is address of the variable which will contain the matching string
312 DOC is the documentation string. */
314 struct cmd_list_element
*
315 add_set_enum_cmd (name
, class, enumlist
, var
, doc
, list
)
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",
613 struct ui_file
*stream
;
615 struct cmd_list_element
*c
;
616 extern struct cmd_list_element
*cmdlist
;
618 for (c
= cmdlist
; c
; c
= c
->next
)
622 /* If this is a prefix command, print it's subcommands */
624 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 0, stream
);
626 /* If this is a class name, print all of the commands in the class */
627 else if (c
->function
.cfunc
== NULL
)
628 help_cmd_list (cmdlist
, c
->class, "", 0, stream
);
632 /* Print only the first line of STR on STREAM. */
634 print_doc_line (stream
, str
)
635 struct ui_file
*stream
;
638 static char *line_buffer
= 0;
639 static int line_size
;
645 line_buffer
= (char *) xmalloc (line_size
);
649 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
651 if (p
- str
> line_size
- 1)
653 line_size
= p
- str
+ 1;
654 free ((PTR
) line_buffer
);
655 line_buffer
= (char *) xmalloc (line_size
);
657 strncpy (line_buffer
, str
, p
- str
);
658 line_buffer
[p
- str
] = '\0';
659 if (islower (line_buffer
[0]))
660 line_buffer
[0] = toupper (line_buffer
[0]);
662 ui_out_text (uiout
, line_buffer
);
664 fputs_filtered (line_buffer
, stream
);
669 * Implement a help command on command list LIST.
670 * RECURSE should be non-zero if this should be done recursively on
671 * all sublists of LIST.
672 * PREFIX is the prefix to print before each command name.
673 * STREAM is the stream upon which the output should be written.
675 * A non-negative class number to list only commands in that
677 * ALL_COMMANDS to list all commands in list.
678 * ALL_CLASSES to list all classes in list.
680 * Note that RECURSE will be active on *all* sublists, not just the
681 * ones selected by the criteria above (ie. the selection mechanism
682 * is at the low level, not the high-level).
685 help_cmd_list (list
, class, prefix
, recurse
, stream
)
686 struct cmd_list_element
*list
;
687 enum command_class
class;
690 struct ui_file
*stream
;
692 register struct cmd_list_element
*c
;
694 for (c
= list
; c
; c
= c
->next
)
696 if (c
->abbrev_flag
== 0 &&
697 (class == all_commands
698 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
699 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
701 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
702 print_doc_line (stream
, c
->doc
);
703 fputs_filtered ("\n", stream
);
706 && c
->prefixlist
!= 0
707 && c
->abbrev_flag
== 0)
708 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
713 /* Search the input clist for 'command'. Return the command if
714 found (or NULL if not), and return the number of commands
717 static struct cmd_list_element
*
718 find_cmd (command
, len
, clist
, ignore_help_classes
, nfound
)
721 struct cmd_list_element
*clist
;
722 int ignore_help_classes
;
725 struct cmd_list_element
*found
, *c
;
727 found
= (struct cmd_list_element
*) NULL
;
729 for (c
= clist
; c
; c
= c
->next
)
730 if (!strncmp (command
, c
->name
, len
)
731 && (!ignore_help_classes
|| c
->function
.cfunc
))
735 if (c
->name
[len
] == '\0')
744 /* This routine takes a line of TEXT and a CLIST in which to start the
745 lookup. When it returns it will have incremented the text pointer past
746 the section of text it matched, set *RESULT_LIST to point to the list in
747 which the last word was matched, and will return a pointer to the cmd
748 list element which the text matches. It will return NULL if no match at
749 all was possible. It will return -1 (cast appropriately, ick) if ambigous
750 matches are possible; in this case *RESULT_LIST will be set to point to
751 the list in which there are ambiguous choices (and *TEXT will be set to
752 the ambiguous text string).
754 If the located command was an abbreviation, this routine returns the base
755 command of the abbreviation.
757 It does no error reporting whatsoever; control will always return
758 to the superior routine.
760 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
761 at the prefix_command (ie. the best match) *or* (special case) will be NULL
762 if no prefix command was ever found. For example, in the case of "info a",
763 "info" matches without ambiguity, but "a" could be "args" or "address", so
764 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
765 RESULT_LIST should not be interpeted as a pointer to the beginning of a
766 list; it simply points to a specific command. In the case of an ambiguous
767 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
768 "info t" can be "info types" or "info target"; upon return *TEXT has been
769 advanced past "info ").
771 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
772 affect the operation).
774 This routine does *not* modify the text pointed to by TEXT.
776 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
777 are actually help classes rather than commands (i.e. the function field of
778 the struct cmd_list_element is NULL). */
780 struct cmd_list_element
*
781 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
783 struct cmd_list_element
*clist
, **result_list
;
784 int ignore_help_classes
;
787 int len
, tmp
, nfound
;
788 struct cmd_list_element
*found
, *c
;
791 while (**text
== ' ' || **text
== '\t')
794 /* Treating underscores as part of command words is important
795 so that "set args_foo()" doesn't get interpreted as
796 "set args _foo()". */
798 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
800 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
801 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
805 /* If nothing but whitespace, return 0. */
811 /* *text and p now bracket the first command word to lookup (and
812 it's length is len). We copy this into a local temporary */
815 command
= (char *) alloca (len
+ 1);
816 for (tmp
= 0; tmp
< len
; tmp
++)
818 char x
= (*text
)[tmp
];
826 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
829 ** We didn't find the command in the entered case, so lower case it
832 if (!found
|| nfound
== 0)
834 for (tmp
= 0; tmp
< len
; tmp
++)
836 char x
= command
[tmp
];
837 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
839 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
842 /* If nothing matches, we have a simple failure. */
848 if (result_list
!= NULL
)
849 /* Will be modified in calling routine
850 if we know what the prefix command is. */
852 return (struct cmd_list_element
*) -1; /* Ambiguous. */
855 /* We've matched something on this list. Move text pointer forward. */
859 if (found
->cmd_pointer
)
861 /* We drop the alias (abbreviation) in favor of the command it is
862 pointing to. If the alias is deprecated, though, we need to
863 warn the user about it before we drop it. Note that while we
864 are warning about the alias, we may also warn about the command
865 itself and we will adjust the appropriate DEPRECATED_WARN_USER
868 if (found
->flags
& DEPRECATED_WARN_USER
)
869 deprecated_cmd_warning (&line
);
870 found
= found
->cmd_pointer
;
872 /* If we found a prefix command, keep looking. */
874 if (found
->prefixlist
)
876 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
877 ignore_help_classes
);
880 /* Didn't find anything; this is as far as we got. */
881 if (result_list
!= NULL
)
882 *result_list
= clist
;
885 else if (c
== (struct cmd_list_element
*) -1)
887 /* We've gotten this far properly, but the next step
888 is ambiguous. We need to set the result list to the best
889 we've found (if an inferior hasn't already set it). */
890 if (result_list
!= NULL
)
892 /* This used to say *result_list = *found->prefixlist
893 If that was correct, need to modify the documentation
894 at the top of this function to clarify what is supposed
896 *result_list
= found
;
907 if (result_list
!= NULL
)
908 *result_list
= clist
;
913 /* All this hair to move the space to the front of cmdtype */
916 undef_cmd_error (cmdtype
, q
)
919 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
923 strlen (cmdtype
) - 1,
927 /* Look up the contents of *LINE as a command in the command list LIST.
928 LIST is a chain of struct cmd_list_element's.
929 If it is found, return the struct cmd_list_element for that command
930 and update *LINE to point after the command name, at the first argument.
931 If not found, call error if ALLOW_UNKNOWN is zero
932 otherwise (or if error returns) return zero.
933 Call error if specified command is ambiguous,
934 unless ALLOW_UNKNOWN is negative.
935 CMDTYPE precedes the word "command" in the error message.
937 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
938 elements which are actually help classes rather than commands (i.e.
939 the function field of the struct cmd_list_element is 0). */
941 struct cmd_list_element
*
942 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
944 struct cmd_list_element
*list
;
947 int ignore_help_classes
;
949 struct cmd_list_element
*last_list
= 0;
950 struct cmd_list_element
*c
=
951 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
953 /* This is wrong for complete_command. */
954 char *ptr
= (*line
) + strlen (*line
) - 1;
956 /* Clear off trailing whitespace. */
957 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
967 error ("Lack of needed %scommand", cmdtype
);
972 while (isalnum (*p
) || *p
== '-')
975 q
= (char *) alloca (p
- *line
+ 1);
976 strncpy (q
, *line
, p
- *line
);
978 undef_cmd_error (cmdtype
, q
);
984 else if (c
== (struct cmd_list_element
*) -1)
986 /* Ambigous. Local values should be off prefixlist or called
988 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
990 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
991 struct cmd_list_element
*local_list
=
992 (last_list
? *(last_list
->prefixlist
) : list
);
994 if (local_allow_unknown
< 0)
997 return last_list
; /* Found something. */
999 return 0; /* Found nothing. */
1003 /* Report as error. */
1008 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1009 && (*line
)[amb_len
] != '\t');
1014 for (c
= local_list
; c
; c
= c
->next
)
1015 if (!strncmp (*line
, c
->name
, amb_len
))
1017 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1019 if (strlen (ambbuf
))
1020 strcat (ambbuf
, ", ");
1021 strcat (ambbuf
, c
->name
);
1025 strcat (ambbuf
, "..");
1029 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
1031 return 0; /* lint */
1036 /* We've got something. It may still not be what the caller
1037 wants (if this command *needs* a subcommand). */
1038 while (**line
== ' ' || **line
== '\t')
1041 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1042 undef_cmd_error (c
->prefixname
, *line
);
1044 /* Seems to be what he wants. Return it. */
1050 /* We are here presumably because an alias or command in *TEXT is
1051 deprecated and a warning message should be generated. This function
1052 decodes *TEXT and potentially generates a warning message as outlined
1055 Example for 'set endian big' which has a fictitious alias 'seb'.
1057 If alias wasn't used in *TEXT, and the command is deprecated:
1058 "warning: 'set endian big' is deprecated."
1060 If alias was used, and only the alias is deprecated:
1061 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1063 If alias was used and command is deprecated (regardless of whether the
1064 alias itself is deprecated:
1066 "warning: 'set endian big' (seb) is deprecated."
1068 After the message has been sent, clear the appropriate flags in the
1069 command and/or the alias so the user is no longer bothered.
1073 deprecated_cmd_warning (char **text
)
1075 struct cmd_list_element
*alias
= NULL
;
1076 struct cmd_list_element
*prefix_cmd
= NULL
;
1077 struct cmd_list_element
*cmd
= NULL
;
1078 struct cmd_list_element
*c
;
1081 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1082 /* return if text doesn't evaluate to a command */
1085 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1086 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1087 /* return if nothing is deprecated */
1090 printf_filtered ("Warning:");
1092 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1093 printf_filtered (" '%s', an alias for the", alias
->name
);
1095 printf_filtered (" command '");
1098 printf_filtered ("%s", prefix_cmd
->prefixname
);
1100 printf_filtered ("%s", cmd
->name
);
1102 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1103 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1105 printf_filtered ("' is deprecated.\n");
1108 /* if it is only the alias that is deprecated, we want to indicate the
1109 new alias, otherwise we'll indicate the new command */
1111 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1113 if (alias
->replacement
)
1114 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1116 printf_filtered ("No alternative known.\n\n");
1120 if (cmd
->replacement
)
1121 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1123 printf_filtered ("No alternative known.\n\n");
1126 /* We've warned you, now we'll keep quiet */
1128 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1130 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1135 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1136 Return 1 on success, 0 on failure.
1138 If LINE refers to an alias, *alias will point to that alias.
1140 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1141 command) set *prefix_cmd.
1143 Set *cmd to point to the command LINE indicates.
1145 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1146 exist, they are NULL when we return.
1150 lookup_cmd_composition (char *text
,
1151 struct cmd_list_element
**alias
,
1152 struct cmd_list_element
**prefix_cmd
,
1153 struct cmd_list_element
**cmd
)
1156 int len
, tmp
, nfound
;
1157 struct cmd_list_element
*cur_list
;
1158 struct cmd_list_element
*prev_cmd
;
1167 /* Go through as many command lists as we need to
1168 to find the command TEXT refers to. */
1172 while (*text
== ' ' || *text
== '\t')
1175 /* Treating underscores as part of command words is important
1176 so that "set args_foo()" doesn't get interpreted as
1177 "set args _foo()". */
1179 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1181 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
1182 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
1186 /* If nothing but whitespace, return. */
1192 /* text and p now bracket the first command word to lookup (and
1193 it's length is len). We copy this into a local temporary */
1195 command
= (char *) alloca (len
+ 1);
1196 for (tmp
= 0; tmp
< len
; tmp
++)
1201 command
[len
] = '\0';
1206 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1208 /* We didn't find the command in the entered case, so lower case it
1211 if (!*cmd
|| nfound
== 0)
1213 for (tmp
= 0; tmp
< len
; tmp
++)
1215 char x
= command
[tmp
];
1216 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1218 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1221 if (*cmd
== (struct cmd_list_element
*) -1)
1223 return 0; /* ambiguous */
1227 return 0; /* nothing found */
1230 if ((*cmd
)->cmd_pointer
)
1232 /* cmd was actually an alias, we note that an alias was used
1233 (by assigning *alais) and we set *cmd.
1236 *cmd
= (*cmd
)->cmd_pointer
;
1238 *prefix_cmd
= prev_cmd
;
1240 if ((*cmd
)->prefixlist
)
1241 cur_list
= *(*cmd
)->prefixlist
;
1253 /* Look up the contents of *LINE as a command in the command list LIST.
1254 LIST is a chain of struct cmd_list_element's.
1255 If it is found, return the struct cmd_list_element for that command
1256 and update *LINE to point after the command name, at the first argument.
1257 If not found, call error if ALLOW_UNKNOWN is zero
1258 otherwise (or if error returns) return zero.
1259 Call error if specified command is ambiguous,
1260 unless ALLOW_UNKNOWN is negative.
1261 CMDTYPE precedes the word "command" in the error message. */
1263 struct cmd_list_element
*
1264 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
1266 struct cmd_list_element
*list
;
1271 register struct cmd_list_element
*c
, *found
;
1274 char *processed_cmd
;
1277 /* Skip leading whitespace. */
1279 while (**line
== ' ' || **line
== '\t')
1282 /* Clear out trailing whitespace. */
1284 p
= *line
+ strlen (*line
);
1285 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1289 /* Find end of command name. */
1292 while (*p
== '-' || isalnum (*p
))
1295 /* Look up the command name.
1296 If exact match, keep that.
1297 Otherwise, take command abbreviated, if unique. Note that (in my
1298 opinion) a null string does *not* indicate ambiguity; simply the
1299 end of the argument. */
1304 error ("Lack of needed %scommand", cmdtype
);
1308 /* Copy over to a local buffer, converting to lowercase on the way.
1309 This is in case the command being parsed is a subcommand which
1310 doesn't match anything, and that's ok. We want the original
1311 untouched for the routine of the original command. */
1313 processed_cmd
= (char *) alloca (p
- *line
+ 1);
1314 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
1316 char x
= (*line
)[cmd_len
];
1318 processed_cmd
[cmd_len
] = tolower (x
);
1320 processed_cmd
[cmd_len
] = x
;
1322 processed_cmd
[cmd_len
] = '\0';
1324 /* Check all possibilities in the current command list. */
1327 for (c
= list
; c
; c
= c
->next
)
1329 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1333 if (c
->name
[cmd_len
] == 0)
1341 /* Report error for undefined command name. */
1345 if (nfound
> 1 && allow_unknown
>= 0)
1348 for (c
= list
; c
; c
= c
->next
)
1349 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1351 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
1353 if (strlen (ambbuf
))
1354 strcat (ambbuf
, ", ");
1355 strcat (ambbuf
, c
->name
);
1359 strcat (ambbuf
, "..");
1363 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
1364 processed_cmd
, ambbuf
);
1366 else if (!allow_unknown
)
1367 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
1371 /* Skip whitespace before the argument. */
1373 while (*p
== ' ' || *p
== '\t')
1377 if (found
->prefixlist
&& *p
)
1379 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
1380 found
->allow_unknown
);
1389 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1391 /* Return a vector of char pointers which point to the different
1392 possible completions in LIST of TEXT.
1394 WORD points in the same buffer as TEXT, and completions should be
1395 returned relative to this position. For example, suppose TEXT is "foo"
1396 and we want to complete to "foobar". If WORD is "oo", return
1397 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1400 complete_on_cmdlist (list
, text
, word
)
1401 struct cmd_list_element
*list
;
1405 struct cmd_list_element
*ptr
;
1407 int sizeof_matchlist
;
1409 int textlen
= strlen (text
);
1411 sizeof_matchlist
= 10;
1412 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1415 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1416 if (!strncmp (ptr
->name
, text
, textlen
)
1417 && !ptr
->abbrev_flag
1418 && (ptr
->function
.cfunc
1419 || ptr
->prefixlist
))
1421 if (matches
== sizeof_matchlist
)
1423 sizeof_matchlist
*= 2;
1424 matchlist
= (char **) xrealloc ((char *) matchlist
,
1426 * sizeof (char *)));
1429 matchlist
[matches
] = (char *)
1430 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1432 strcpy (matchlist
[matches
], ptr
->name
);
1433 else if (word
> text
)
1435 /* Return some portion of ptr->name. */
1436 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1440 /* Return some of text plus ptr->name. */
1441 strncpy (matchlist
[matches
], word
, text
- word
);
1442 matchlist
[matches
][text
- word
] = '\0';
1443 strcat (matchlist
[matches
], ptr
->name
);
1450 free ((PTR
) matchlist
);
1455 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1456 * sizeof (char *)));
1457 matchlist
[matches
] = (char *) 0;
1463 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1465 /* Return a vector of char pointers which point to the different
1466 possible completions in CMD of TEXT.
1468 WORD points in the same buffer as TEXT, and completions should be
1469 returned relative to this position. For example, suppose TEXT is "foo"
1470 and we want to complete to "foobar". If WORD is "oo", return
1471 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1474 complete_on_enum (enumlist
, text
, word
)
1480 int sizeof_matchlist
;
1482 int textlen
= strlen (text
);
1486 sizeof_matchlist
= 10;
1487 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1490 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1491 if (strncmp (name
, text
, textlen
) == 0)
1493 if (matches
== sizeof_matchlist
)
1495 sizeof_matchlist
*= 2;
1496 matchlist
= (char **) xrealloc ((char *) matchlist
,
1498 * sizeof (char *)));
1501 matchlist
[matches
] = (char *)
1502 xmalloc (strlen (word
) + strlen (name
) + 1);
1504 strcpy (matchlist
[matches
], name
);
1505 else if (word
> text
)
1507 /* Return some portion of name. */
1508 strcpy (matchlist
[matches
], name
+ (word
- text
));
1512 /* Return some of text plus name. */
1513 strncpy (matchlist
[matches
], word
, text
- word
);
1514 matchlist
[matches
][text
- word
] = '\0';
1515 strcat (matchlist
[matches
], name
);
1522 free ((PTR
) matchlist
);
1527 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1528 * sizeof (char *)));
1529 matchlist
[matches
] = (char *) 0;
1536 parse_binary_operation (arg
)
1544 length
= strlen (arg
);
1546 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
1549 if (!strncmp (arg
, "on", length
)
1550 || !strncmp (arg
, "1", length
)
1551 || !strncmp (arg
, "yes", length
))
1553 else if (!strncmp (arg
, "off", length
)
1554 || !strncmp (arg
, "0", length
)
1555 || !strncmp (arg
, "no", length
))
1559 error ("\"on\" or \"off\" expected.");
1564 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1565 of the argument, and FROM_TTY is nonzero if this command is being entered
1566 directly by the user (i.e. these are just like any other
1567 command). C is the command list element for the command. */
1569 do_setshow_command (arg
, from_tty
, c
)
1572 struct cmd_list_element
*c
;
1574 if (c
->type
== set_cmd
)
1576 switch (c
->var_type
)
1587 new = (char *) xmalloc (strlen (arg
) + 2);
1590 while ((ch
= *p
++) != '\000')
1594 /* \ at end of argument is used after spaces
1595 so they won't be lost. */
1596 /* This is obsolete now that we no longer strip
1597 trailing whitespace and actually, the backslash
1598 didn't get here in my test, readline or
1599 something did something funky with a backslash
1600 right before a newline. */
1603 ch
= parse_escape (&p
);
1605 break; /* C loses */
1613 if (*(p
- 1) != '\\')
1617 new = (char *) xrealloc (new, q
- new);
1618 if (*(char **) c
->var
!= NULL
)
1619 free (*(char **) c
->var
);
1620 *(char **) c
->var
= new;
1623 case var_string_noescape
:
1626 if (*(char **) c
->var
!= NULL
)
1627 free (*(char **) c
->var
);
1628 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1632 error_no_arg ("filename to set it to.");
1633 if (*(char **) c
->var
!= NULL
)
1634 free (*(char **) c
->var
);
1635 *(char **) c
->var
= tilde_expand (arg
);
1638 *(int *) c
->var
= parse_binary_operation (arg
);
1642 error_no_arg ("integer to set it to.");
1643 *(unsigned int *) c
->var
= parse_and_eval_address (arg
);
1644 if (*(unsigned int *) c
->var
== 0)
1645 *(unsigned int *) c
->var
= UINT_MAX
;
1651 error_no_arg ("integer to set it to.");
1652 val
= parse_and_eval_address (arg
);
1654 *(int *) c
->var
= INT_MAX
;
1655 else if (val
>= INT_MAX
)
1656 error ("integer %u out of range", val
);
1658 *(int *) c
->var
= val
;
1663 error_no_arg ("integer to set it to.");
1664 *(int *) c
->var
= parse_and_eval_address (arg
);
1674 /* if no argument was supplied, print an informative error message */
1678 strcpy (msg
, "Requires an argument. Valid arguments are ");
1679 for (i
= 0; c
->enums
[i
]; i
++)
1683 strcat (msg
, c
->enums
[i
]);
1689 p
= strchr (arg
, ' ');
1697 for (i
= 0; c
->enums
[i
]; i
++)
1698 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
1700 match
= c
->enums
[i
];
1705 error ("Undefined item: \"%s\".", arg
);
1708 error ("Ambiguous item \"%s\".", arg
);
1710 *(char **) c
->var
= match
;
1714 error ("gdb internal error: bad var_type in do_setshow_command");
1717 else if (c
->type
== show_cmd
)
1720 struct cleanup
*old_chain
;
1721 struct ui_stream
*stb
;
1724 stb
= ui_out_stream_new (uiout
);
1725 old_chain
= make_cleanup ((make_cleanup_func
) ui_out_stream_delete
, stb
);
1728 /* Print doc minus "show" at start. */
1729 print_doc_line (gdb_stdout
, c
->doc
+ 5);
1732 ui_out_text (uiout
, " is ");
1733 ui_out_wrap_hint (uiout
, " ");
1735 switch (c
->var_type
)
1741 if (*(unsigned char **) c
->var
)
1742 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
1746 case var_string_noescape
:
1749 if (*(char **) c
->var
)
1750 fputs_filtered (*(char **) c
->var
, stb
->stream
);
1754 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
1757 if (*(unsigned int *) c
->var
== UINT_MAX
)
1759 fputs_filtered ("unlimited", stb
->stream
);
1762 /* else fall through */
1764 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
1767 if (*(int *) c
->var
== INT_MAX
)
1769 fputs_filtered ("unlimited", stb
->stream
);
1772 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
1776 error ("gdb internal error: bad var_type in do_setshow_command");
1779 ui_out_text (uiout
, "\"");
1780 ui_out_field_stream (uiout
, "value", stb
);
1782 ui_out_text (uiout
, "\"");
1783 ui_out_text (uiout
, ".\n");
1784 do_cleanups (old_chain
);
1786 fputs_filtered (" is ", gdb_stdout
);
1788 switch (c
->var_type
)
1792 fputs_filtered ("\"", gdb_stdout
);
1793 if (*(unsigned char **) c
->var
)
1794 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
1795 fputs_filtered ("\"", gdb_stdout
);
1798 case var_string_noescape
:
1801 fputs_filtered ("\"", gdb_stdout
);
1802 if (*(char **) c
->var
)
1803 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
1804 fputs_filtered ("\"", gdb_stdout
);
1807 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
1810 if (*(unsigned int *) c
->var
== UINT_MAX
)
1812 fputs_filtered ("unlimited", gdb_stdout
);
1815 /* else fall through */
1817 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
1820 if (*(int *) c
->var
== INT_MAX
)
1822 fputs_filtered ("unlimited", gdb_stdout
);
1825 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
1829 error ("gdb internal error: bad var_type in do_setshow_command");
1831 fputs_filtered (".\n", gdb_stdout
);
1835 error ("gdb internal error: bad cmd_type in do_setshow_command");
1836 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1837 if (c
->type
== set_cmd
&& set_hook
)
1841 /* Show all the settings in a list of show commands. */
1844 cmd_show_list (list
, from_tty
, prefix
)
1845 struct cmd_list_element
*list
;
1850 ui_out_list_begin (uiout
, "showlist");
1852 for (; list
!= NULL
; list
= list
->next
)
1854 /* If we find a prefix, run its list, prefixing our output by its
1855 prefix (with "show " skipped). */
1857 if (list
->prefixlist
&& !list
->abbrev_flag
)
1859 ui_out_list_begin (uiout
, "optionlist");
1860 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
1861 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1862 ui_out_list_end (uiout
);
1864 if (list
->type
== show_cmd
)
1866 ui_out_list_begin (uiout
, "option");
1867 ui_out_text (uiout
, prefix
);
1868 ui_out_field_string (uiout
, "name", list
->name
);
1869 ui_out_text (uiout
, ": ");
1870 do_setshow_command ((char *) NULL
, from_tty
, list
);
1871 ui_out_list_end (uiout
);
1874 if (list
->prefixlist
&& !list
->abbrev_flag
)
1875 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1876 if (list
->type
== show_cmd
)
1878 fputs_filtered (prefix
, gdb_stdout
);
1879 fputs_filtered (list
->name
, gdb_stdout
);
1880 fputs_filtered (": ", gdb_stdout
);
1881 do_setshow_command ((char *) NULL
, from_tty
, list
);
1886 ui_out_list_end (uiout
);
1892 shell_escape (arg
, from_tty
)
1897 /* If ARG is NULL, they want an inferior shell, but `system' just
1898 reports if the shell is available when passed a NULL arg. */
1899 int rc
= system (arg
? arg
: "");
1902 arg
= "inferior shell";
1906 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", arg
,
1907 safe_strerror (errno
));
1908 gdb_flush (gdb_stderr
);
1912 fprintf_unfiltered (gdb_stderr
, "%s exited with status %d\n", arg
, rc
);
1913 gdb_flush (gdb_stderr
);
1916 /* Make sure to return to the directory GDB thinks it is, in case the
1917 shell command we just ran changed it. */
1918 chdir (current_directory
);
1920 #else /* Can fork. */
1921 int rc
, status
, pid
;
1922 char *p
, *user_shell
;
1924 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1925 user_shell
= "/bin/sh";
1927 /* Get the name of the shell for arg0 */
1928 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1931 p
++; /* Get past '/' */
1933 if ((pid
= fork ()) == 0)
1936 execl (user_shell
, p
, 0);
1938 execl (user_shell
, p
, "-c", arg
, 0);
1940 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", user_shell
,
1941 safe_strerror (errno
));
1942 gdb_flush (gdb_stderr
);
1947 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1950 error ("Fork failed");
1951 #endif /* Can fork. */
1955 make_command (arg
, from_tty
)
1965 p
= xmalloc (sizeof ("make ") + strlen (arg
));
1966 strcpy (p
, "make ");
1967 strcpy (p
+ sizeof ("make ") - 1, arg
);
1970 shell_escape (p
, from_tty
);
1974 show_user_1 (c
, stream
)
1975 struct cmd_list_element
*c
;
1976 struct ui_file
*stream
;
1978 register struct command_line
*cmdlines
;
1980 cmdlines
= c
->user_commands
;
1983 fputs_filtered ("User command ", stream
);
1984 fputs_filtered (c
->name
, stream
);
1985 fputs_filtered (":\n", stream
);
1988 print_command_lines (uiout
, cmdlines
, 1);
1989 fputs_filtered ("\n", stream
);
1993 print_command_line (cmdlines
, 4, stream
);
1994 cmdlines
= cmdlines
->next
;
1996 fputs_filtered ("\n", stream
);
2002 show_user (args
, from_tty
)
2006 struct cmd_list_element
*c
;
2007 extern struct cmd_list_element
*cmdlist
;
2011 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
2012 if (c
->class != class_user
)
2013 error ("Not a user command.");
2014 show_user_1 (c
, gdb_stdout
);
2018 for (c
= cmdlist
; c
; c
= c
->next
)
2020 if (c
->class == class_user
)
2021 show_user_1 (c
, gdb_stdout
);
2027 _initialize_command ()
2029 add_com ("shell", class_support
, shell_escape
,
2030 "Execute the rest of the line as a shell command. \n\
2031 With no arguments, run an inferior shell.");
2033 /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
2034 be a really useful feature. Unfortunatly, the below wont do
2035 this. Instead it adds support for the form ``(gdb) ! ls''
2036 (i.e. the space is required). If the ``!'' command below is
2037 added the complains about no ``!'' command would be replaced by
2038 complains about how the ``!'' command is broken :-) */
2040 add_com_alias ("!", "shell", class_support
, 0);
2042 add_com ("make", class_support
, make_command
,
2043 "Run the ``make'' program using the rest of the line as arguments.");
2044 add_cmd ("user", no_class
, show_user
,
2045 "Show definitions of user defined commands.\n\
2046 Argument is the name of the user defined command.\n\
2047 With no argument, show definitions of all user defined commands.", &showlist
);
2048 add_com ("apropos", class_support
, apropos_command
, "Search for commands matching a REGEXP");