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 static void help_all (struct ui_file
*stream
);
62 void apropos_command (char *, int);
64 void _initialize_command
PARAMS ((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
PARAMS ((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 (name
, class, var_type
, var
, doc
, list
)
290 enum command_class
class;
294 struct cmd_list_element
**list
;
296 struct cmd_list_element
*c
297 = add_cmd (name
, class, NO_FUNCTION
, doc
, list
);
300 c
->var_type
= var_type
;
302 /* This needs to be something besides NO_FUNCTION so that this isn't
303 treated as a help class. */
304 c
->function
.sfunc
= empty_sfunc
;
308 /* Add element named NAME to command list LIST (the list for set
309 or some sublist thereof).
310 CLASS is as in add_cmd.
311 ENUMLIST is a list of strings which may follow NAME.
312 VAR is address of the variable which will contain the matching string
314 DOC is the documentation string. */
316 struct cmd_list_element
*
317 add_set_enum_cmd (name
, class, enumlist
, var
, doc
, list
)
319 enum command_class
class;
323 struct cmd_list_element
**list
;
325 struct cmd_list_element
*c
326 = add_set_cmd (name
, class, var_enum
, var
, doc
, list
);
332 /* Where SETCMD has already been added, add the corresponding show
333 command to LIST and return a pointer to the added command (not
334 necessarily the head of LIST). */
335 struct cmd_list_element
*
336 add_show_from_set (setcmd
, list
)
337 struct cmd_list_element
*setcmd
;
338 struct cmd_list_element
**list
;
340 struct cmd_list_element
*showcmd
=
341 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
342 struct cmd_list_element
*p
;
344 memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
345 delete_cmd (showcmd
->name
, list
);
346 showcmd
->type
= show_cmd
;
348 /* Replace "set " at start of docstring with "show ". */
349 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
350 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
351 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
353 fprintf_unfiltered (gdb_stderr
, "GDB internal error: Bad docstring for set command\n");
355 if (*list
== NULL
|| STRCMP ((*list
)->name
, showcmd
->name
) >= 0)
357 showcmd
->next
= *list
;
363 while (p
->next
&& STRCMP (p
->next
->name
, showcmd
->name
) <= 0)
367 showcmd
->next
= p
->next
;
374 /* Remove the command named NAME from the command list. */
377 delete_cmd (name
, list
)
379 struct cmd_list_element
**list
;
381 register struct cmd_list_element
*c
;
382 struct cmd_list_element
*p
;
384 while (*list
&& STREQ ((*list
)->name
, name
))
387 (*list
)->hookee
->hook
= 0; /* Hook slips out of its mouth */
394 for (c
= *list
; c
->next
;)
396 if (STREQ (c
->next
->name
, name
))
399 c
->next
->hookee
->hook
= 0; /* hooked cmd gets away. */
401 free ((PTR
) c
->next
);
408 /* Recursively walk the commandlist structures, and print out the
409 documentation of commands that match our regex in either their
410 name, or their documentation.
413 apropos_cmd_helper (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
414 struct re_pattern_buffer
*regex
, char *prefix
)
416 register struct cmd_list_element
*c
;
417 int returnvalue
=1; /*Needed to avoid double printing*/
418 /* Walk through the commands */
419 for (c
=commandlist
;c
;c
=c
->next
)
423 /* Try to match against the name*/
424 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
425 if (returnvalue
>= 0)
427 /* Stolen from help_cmd_list. We don't directly use
428 * help_cmd_list because it doesn't let us print out
431 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
432 print_doc_line (stream
, c
->doc
);
433 fputs_filtered ("\n", stream
);
434 returnvalue
=0; /*Set this so we don't print it again.*/
437 if (c
->doc
!= NULL
&& returnvalue
!= 0)
439 /* Try to match against documentation */
440 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
442 /* Stolen from help_cmd_list. We don't directly use
443 * help_cmd_list because it doesn't let us print out
446 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
447 print_doc_line (stream
, c
->doc
);
448 fputs_filtered ("\n", stream
);
451 /* Check if this command has subcommands */
452 if (c
->prefixlist
!= NULL
)
454 /* Recursively call ourselves on the subcommand list,
455 passing the right prefix in.
457 apropos_cmd_helper(stream
,*c
->prefixlist
,regex
,c
->prefixname
);
461 /* Search through names of commands and documentations for a certain
465 apropos_command (char *searchstr
, int from_tty
)
467 extern struct cmd_list_element
*cmdlist
; /*This is the main command list*/
469 char *pattern_fastmap
;
470 char errorbuffer
[512];
471 pattern_fastmap
=calloc(256,sizeof(char));
472 if (searchstr
== NULL
)
473 error("REGEXP string is empty");
475 if (regcomp(&pattern
,searchstr
,REG_ICASE
) == 0)
477 pattern
.fastmap
=pattern_fastmap
;
478 re_compile_fastmap(&pattern
);
479 apropos_cmd_helper(gdb_stdout
,cmdlist
,&pattern
,"");
483 regerror(regcomp(&pattern
,searchstr
,REG_ICASE
),NULL
,errorbuffer
,512);
484 error("Error in regular expression:%s",errorbuffer
);
486 free(pattern_fastmap
);
490 /* This command really has to deal with two things:
491 * 1) I want documentation on *this string* (usually called by
492 * "help commandname").
493 * 2) I want documentation on *this list* (usually called by
494 * giving a command that requires subcommands. Also called by saying
497 * I am going to split this into two seperate comamnds, help_cmd and
502 help_cmd (command
, stream
)
504 struct ui_file
*stream
;
506 struct cmd_list_element
*c
;
507 extern struct cmd_list_element
*cmdlist
;
511 help_list (cmdlist
, "", all_classes
, stream
);
515 if (strcmp (command
, "all") == 0)
521 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
526 /* There are three cases here.
527 If c->prefixlist is nonzero, we have a prefix command.
528 Print its documentation, then list its subcommands.
530 If c->function is nonzero, we really have a command.
531 Print its documentation and return.
533 If c->function is zero, we have a class name.
534 Print its documentation (as if it were a command)
535 and then set class to the number of this class
536 so that the commands in the class will be listed. */
538 fputs_filtered (c
->doc
, stream
);
539 fputs_filtered ("\n", stream
);
541 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
543 fprintf_filtered (stream
, "\n");
545 /* If this is a prefix command, print it's subcommands */
547 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
549 /* If this is a class name, print all of the commands in the class */
550 if (c
->function
.cfunc
== NULL
)
551 help_list (cmdlist
, "", c
->class, stream
);
554 fprintf_filtered (stream
, "\nThis command has a hook defined: %s\n",
559 * Get a specific kind of help on a command list.
562 * CMDTYPE is the prefix to use in the title string.
563 * CLASS is the class with which to list the nodes of this list (see
564 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
565 * everything, ALL_CLASSES for just classes, and non-negative for only things
566 * in a specific class.
567 * and STREAM is the output stream on which to print things.
568 * If you call this routine with a class >= 0, it recurses.
571 help_list (list
, cmdtype
, class, stream
)
572 struct cmd_list_element
*list
;
574 enum command_class
class;
575 struct ui_file
*stream
;
578 char *cmdtype1
, *cmdtype2
;
580 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
581 len
= strlen (cmdtype
);
582 cmdtype1
= (char *) alloca (len
+ 1);
584 cmdtype2
= (char *) alloca (len
+ 4);
589 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
591 strncpy (cmdtype2
, cmdtype
, len
- 1);
592 strcpy (cmdtype2
+ len
- 1, " sub");
595 if (class == all_classes
)
596 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
598 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
600 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
602 if (class == all_classes
)
603 fprintf_filtered (stream
, "\n\
604 Type \"help%s\" followed by a class name for a list of commands in that class.",
607 fprintf_filtered (stream
, "\n\
608 Type \"help%s\" followed by %scommand name for full documentation.\n\
609 Command name abbreviations are allowed if unambiguous.\n",
614 help_all (struct ui_file
*stream
)
616 struct cmd_list_element
*c
;
617 extern struct cmd_list_element
*cmdlist
;
619 for (c
= cmdlist
; c
; c
= c
->next
)
623 /* If this is a prefix command, print it's subcommands */
625 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 0, stream
);
627 /* If this is a class name, print all of the commands in the class */
628 else if (c
->function
.cfunc
== NULL
)
629 help_cmd_list (cmdlist
, c
->class, "", 0, stream
);
633 /* Print only the first line of STR on STREAM. */
635 print_doc_line (stream
, str
)
636 struct ui_file
*stream
;
639 static char *line_buffer
= 0;
640 static int line_size
;
646 line_buffer
= (char *) xmalloc (line_size
);
650 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
652 if (p
- str
> line_size
- 1)
654 line_size
= p
- str
+ 1;
655 free ((PTR
) line_buffer
);
656 line_buffer
= (char *) xmalloc (line_size
);
658 strncpy (line_buffer
, str
, p
- str
);
659 line_buffer
[p
- str
] = '\0';
660 if (islower (line_buffer
[0]))
661 line_buffer
[0] = toupper (line_buffer
[0]);
663 ui_out_text (uiout
, line_buffer
);
665 fputs_filtered (line_buffer
, stream
);
670 * Implement a help command on command list LIST.
671 * RECURSE should be non-zero if this should be done recursively on
672 * all sublists of LIST.
673 * PREFIX is the prefix to print before each command name.
674 * STREAM is the stream upon which the output should be written.
676 * A non-negative class number to list only commands in that
678 * ALL_COMMANDS to list all commands in list.
679 * ALL_CLASSES to list all classes in list.
681 * Note that RECURSE will be active on *all* sublists, not just the
682 * ones selected by the criteria above (ie. the selection mechanism
683 * is at the low level, not the high-level).
686 help_cmd_list (list
, class, prefix
, recurse
, stream
)
687 struct cmd_list_element
*list
;
688 enum command_class
class;
691 struct ui_file
*stream
;
693 register struct cmd_list_element
*c
;
695 for (c
= list
; c
; c
= c
->next
)
697 if (c
->abbrev_flag
== 0 &&
698 (class == all_commands
699 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
700 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
702 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
703 print_doc_line (stream
, c
->doc
);
704 fputs_filtered ("\n", stream
);
707 && c
->prefixlist
!= 0
708 && c
->abbrev_flag
== 0)
709 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
714 /* Search the input clist for 'command'. Return the command if
715 found (or NULL if not), and return the number of commands
718 static struct cmd_list_element
*
719 find_cmd (command
, len
, clist
, ignore_help_classes
, nfound
)
722 struct cmd_list_element
*clist
;
723 int ignore_help_classes
;
726 struct cmd_list_element
*found
, *c
;
728 found
= (struct cmd_list_element
*) NULL
;
730 for (c
= clist
; c
; c
= c
->next
)
731 if (!strncmp (command
, c
->name
, len
)
732 && (!ignore_help_classes
|| c
->function
.cfunc
))
736 if (c
->name
[len
] == '\0')
745 /* This routine takes a line of TEXT and a CLIST in which to start the
746 lookup. When it returns it will have incremented the text pointer past
747 the section of text it matched, set *RESULT_LIST to point to the list in
748 which the last word was matched, and will return a pointer to the cmd
749 list element which the text matches. It will return NULL if no match at
750 all was possible. It will return -1 (cast appropriately, ick) if ambigous
751 matches are possible; in this case *RESULT_LIST will be set to point to
752 the list in which there are ambiguous choices (and *TEXT will be set to
753 the ambiguous text string).
755 If the located command was an abbreviation, this routine returns the base
756 command of the abbreviation.
758 It does no error reporting whatsoever; control will always return
759 to the superior routine.
761 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
762 at the prefix_command (ie. the best match) *or* (special case) will be NULL
763 if no prefix command was ever found. For example, in the case of "info a",
764 "info" matches without ambiguity, but "a" could be "args" or "address", so
765 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
766 RESULT_LIST should not be interpeted as a pointer to the beginning of a
767 list; it simply points to a specific command. In the case of an ambiguous
768 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
769 "info t" can be "info types" or "info target"; upon return *TEXT has been
770 advanced past "info ").
772 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
773 affect the operation).
775 This routine does *not* modify the text pointed to by TEXT.
777 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
778 are actually help classes rather than commands (i.e. the function field of
779 the struct cmd_list_element is NULL). */
781 struct cmd_list_element
*
782 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
784 struct cmd_list_element
*clist
, **result_list
;
785 int ignore_help_classes
;
788 int len
, tmp
, nfound
;
789 struct cmd_list_element
*found
, *c
;
792 while (**text
== ' ' || **text
== '\t')
795 /* Treating underscores as part of command words is important
796 so that "set args_foo()" doesn't get interpreted as
797 "set args _foo()". */
799 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
801 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
802 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
806 /* If nothing but whitespace, return 0. */
812 /* *text and p now bracket the first command word to lookup (and
813 it's length is len). We copy this into a local temporary */
816 command
= (char *) alloca (len
+ 1);
817 for (tmp
= 0; tmp
< len
; tmp
++)
819 char x
= (*text
)[tmp
];
827 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
830 ** We didn't find the command in the entered case, so lower case it
833 if (!found
|| nfound
== 0)
835 for (tmp
= 0; tmp
< len
; tmp
++)
837 char x
= command
[tmp
];
838 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
840 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
843 /* If nothing matches, we have a simple failure. */
849 if (result_list
!= NULL
)
850 /* Will be modified in calling routine
851 if we know what the prefix command is. */
853 return (struct cmd_list_element
*) -1; /* Ambiguous. */
856 /* We've matched something on this list. Move text pointer forward. */
860 if (found
->cmd_pointer
)
862 /* We drop the alias (abbreviation) in favor of the command it is
863 pointing to. If the alias is deprecated, though, we need to
864 warn the user about it before we drop it. Note that while we
865 are warning about the alias, we may also warn about the command
866 itself and we will adjust the appropriate DEPRECATED_WARN_USER
869 if (found
->flags
& DEPRECATED_WARN_USER
)
870 deprecated_cmd_warning (&line
);
871 found
= found
->cmd_pointer
;
873 /* If we found a prefix command, keep looking. */
875 if (found
->prefixlist
)
877 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
878 ignore_help_classes
);
881 /* Didn't find anything; this is as far as we got. */
882 if (result_list
!= NULL
)
883 *result_list
= clist
;
886 else if (c
== (struct cmd_list_element
*) -1)
888 /* We've gotten this far properly, but the next step
889 is ambiguous. We need to set the result list to the best
890 we've found (if an inferior hasn't already set it). */
891 if (result_list
!= NULL
)
893 /* This used to say *result_list = *found->prefixlist
894 If that was correct, need to modify the documentation
895 at the top of this function to clarify what is supposed
897 *result_list
= found
;
908 if (result_list
!= NULL
)
909 *result_list
= clist
;
914 /* All this hair to move the space to the front of cmdtype */
917 undef_cmd_error (cmdtype
, q
)
920 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
924 strlen (cmdtype
) - 1,
928 /* Look up the contents of *LINE as a command in the command list LIST.
929 LIST is a chain of struct cmd_list_element's.
930 If it is found, return the struct cmd_list_element for that command
931 and update *LINE to point after the command name, at the first argument.
932 If not found, call error if ALLOW_UNKNOWN is zero
933 otherwise (or if error returns) return zero.
934 Call error if specified command is ambiguous,
935 unless ALLOW_UNKNOWN is negative.
936 CMDTYPE precedes the word "command" in the error message.
938 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
939 elements which are actually help classes rather than commands (i.e.
940 the function field of the struct cmd_list_element is 0). */
942 struct cmd_list_element
*
943 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
945 struct cmd_list_element
*list
;
948 int ignore_help_classes
;
950 struct cmd_list_element
*last_list
= 0;
951 struct cmd_list_element
*c
=
952 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
954 /* This is wrong for complete_command. */
955 char *ptr
= (*line
) + strlen (*line
) - 1;
957 /* Clear off trailing whitespace. */
958 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
968 error ("Lack of needed %scommand", cmdtype
);
973 while (isalnum (*p
) || *p
== '-')
976 q
= (char *) alloca (p
- *line
+ 1);
977 strncpy (q
, *line
, p
- *line
);
979 undef_cmd_error (cmdtype
, q
);
985 else if (c
== (struct cmd_list_element
*) -1)
987 /* Ambigous. Local values should be off prefixlist or called
989 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
991 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
992 struct cmd_list_element
*local_list
=
993 (last_list
? *(last_list
->prefixlist
) : list
);
995 if (local_allow_unknown
< 0)
998 return last_list
; /* Found something. */
1000 return 0; /* Found nothing. */
1004 /* Report as error. */
1009 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1010 && (*line
)[amb_len
] != '\t');
1015 for (c
= local_list
; c
; c
= c
->next
)
1016 if (!strncmp (*line
, c
->name
, amb_len
))
1018 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1020 if (strlen (ambbuf
))
1021 strcat (ambbuf
, ", ");
1022 strcat (ambbuf
, c
->name
);
1026 strcat (ambbuf
, "..");
1030 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
1032 return 0; /* lint */
1037 /* We've got something. It may still not be what the caller
1038 wants (if this command *needs* a subcommand). */
1039 while (**line
== ' ' || **line
== '\t')
1042 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1043 undef_cmd_error (c
->prefixname
, *line
);
1045 /* Seems to be what he wants. Return it. */
1051 /* We are here presumably because an alias or command in *TEXT is
1052 deprecated and a warning message should be generated. This function
1053 decodes *TEXT and potentially generates a warning message as outlined
1056 Example for 'set endian big' which has a fictitious alias 'seb'.
1058 If alias wasn't used in *TEXT, and the command is deprecated:
1059 "warning: 'set endian big' is deprecated."
1061 If alias was used, and only the alias is deprecated:
1062 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1064 If alias was used and command is deprecated (regardless of whether the
1065 alias itself is deprecated:
1067 "warning: 'set endian big' (seb) is deprecated."
1069 After the message has been sent, clear the appropriate flags in the
1070 command and/or the alias so the user is no longer bothered.
1074 deprecated_cmd_warning (char **text
)
1076 struct cmd_list_element
*alias
= NULL
;
1077 struct cmd_list_element
*prefix_cmd
= NULL
;
1078 struct cmd_list_element
*cmd
= NULL
;
1079 struct cmd_list_element
*c
;
1082 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1083 /* return if text doesn't evaluate to a command */
1086 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1087 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1088 /* return if nothing is deprecated */
1091 printf_filtered ("Warning:");
1093 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1094 printf_filtered (" '%s', an alias for the", alias
->name
);
1096 printf_filtered (" command '");
1099 printf_filtered ("%s", prefix_cmd
->prefixname
);
1101 printf_filtered ("%s", cmd
->name
);
1103 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1104 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1106 printf_filtered ("' is deprecated.\n");
1109 /* if it is only the alias that is deprecated, we want to indicate the
1110 new alias, otherwise we'll indicate the new command */
1112 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1114 if (alias
->replacement
)
1115 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1117 printf_filtered ("No alternative known.\n\n");
1121 if (cmd
->replacement
)
1122 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1124 printf_filtered ("No alternative known.\n\n");
1127 /* We've warned you, now we'll keep quiet */
1129 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1131 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1136 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1137 Return 1 on success, 0 on failure.
1139 If LINE refers to an alias, *alias will point to that alias.
1141 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1142 command) set *prefix_cmd.
1144 Set *cmd to point to the command LINE indicates.
1146 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1147 exist, they are NULL when we return.
1151 lookup_cmd_composition (char *text
,
1152 struct cmd_list_element
**alias
,
1153 struct cmd_list_element
**prefix_cmd
,
1154 struct cmd_list_element
**cmd
)
1157 int len
, tmp
, nfound
;
1158 struct cmd_list_element
*cur_list
;
1159 struct cmd_list_element
*prev_cmd
;
1168 /* Go through as many command lists as we need to
1169 to find the command TEXT refers to. */
1173 while (*text
== ' ' || *text
== '\t')
1176 /* Treating underscores as part of command words is important
1177 so that "set args_foo()" doesn't get interpreted as
1178 "set args _foo()". */
1180 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1182 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
1183 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
1187 /* If nothing but whitespace, return. */
1193 /* text and p now bracket the first command word to lookup (and
1194 it's length is len). We copy this into a local temporary */
1196 command
= (char *) alloca (len
+ 1);
1197 for (tmp
= 0; tmp
< len
; tmp
++)
1202 command
[len
] = '\0';
1207 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1209 /* We didn't find the command in the entered case, so lower case it
1212 if (!*cmd
|| nfound
== 0)
1214 for (tmp
= 0; tmp
< len
; tmp
++)
1216 char x
= command
[tmp
];
1217 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1219 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1222 if (*cmd
== (struct cmd_list_element
*) -1)
1224 return 0; /* ambiguous */
1228 return 0; /* nothing found */
1231 if ((*cmd
)->cmd_pointer
)
1233 /* cmd was actually an alias, we note that an alias was used
1234 (by assigning *alais) and we set *cmd.
1237 *cmd
= (*cmd
)->cmd_pointer
;
1239 *prefix_cmd
= prev_cmd
;
1241 if ((*cmd
)->prefixlist
)
1242 cur_list
= *(*cmd
)->prefixlist
;
1254 /* Look up the contents of *LINE as a command in the command list LIST.
1255 LIST is a chain of struct cmd_list_element's.
1256 If it is found, return the struct cmd_list_element for that command
1257 and update *LINE to point after the command name, at the first argument.
1258 If not found, call error if ALLOW_UNKNOWN is zero
1259 otherwise (or if error returns) return zero.
1260 Call error if specified command is ambiguous,
1261 unless ALLOW_UNKNOWN is negative.
1262 CMDTYPE precedes the word "command" in the error message. */
1264 struct cmd_list_element
*
1265 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
1267 struct cmd_list_element
*list
;
1272 register struct cmd_list_element
*c
, *found
;
1275 char *processed_cmd
;
1278 /* Skip leading whitespace. */
1280 while (**line
== ' ' || **line
== '\t')
1283 /* Clear out trailing whitespace. */
1285 p
= *line
+ strlen (*line
);
1286 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1290 /* Find end of command name. */
1293 while (*p
== '-' || isalnum (*p
))
1296 /* Look up the command name.
1297 If exact match, keep that.
1298 Otherwise, take command abbreviated, if unique. Note that (in my
1299 opinion) a null string does *not* indicate ambiguity; simply the
1300 end of the argument. */
1305 error ("Lack of needed %scommand", cmdtype
);
1309 /* Copy over to a local buffer, converting to lowercase on the way.
1310 This is in case the command being parsed is a subcommand which
1311 doesn't match anything, and that's ok. We want the original
1312 untouched for the routine of the original command. */
1314 processed_cmd
= (char *) alloca (p
- *line
+ 1);
1315 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
1317 char x
= (*line
)[cmd_len
];
1319 processed_cmd
[cmd_len
] = tolower (x
);
1321 processed_cmd
[cmd_len
] = x
;
1323 processed_cmd
[cmd_len
] = '\0';
1325 /* Check all possibilities in the current command list. */
1328 for (c
= list
; c
; c
= c
->next
)
1330 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1334 if (c
->name
[cmd_len
] == 0)
1342 /* Report error for undefined command name. */
1346 if (nfound
> 1 && allow_unknown
>= 0)
1349 for (c
= list
; c
; c
= c
->next
)
1350 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1352 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
1354 if (strlen (ambbuf
))
1355 strcat (ambbuf
, ", ");
1356 strcat (ambbuf
, c
->name
);
1360 strcat (ambbuf
, "..");
1364 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
1365 processed_cmd
, ambbuf
);
1367 else if (!allow_unknown
)
1368 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
1372 /* Skip whitespace before the argument. */
1374 while (*p
== ' ' || *p
== '\t')
1378 if (found
->prefixlist
&& *p
)
1380 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
1381 found
->allow_unknown
);
1390 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1392 /* Return a vector of char pointers which point to the different
1393 possible completions in LIST of TEXT.
1395 WORD points in the same buffer as TEXT, and completions should be
1396 returned relative to this position. For example, suppose TEXT is "foo"
1397 and we want to complete to "foobar". If WORD is "oo", return
1398 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1401 complete_on_cmdlist (list
, text
, word
)
1402 struct cmd_list_element
*list
;
1406 struct cmd_list_element
*ptr
;
1408 int sizeof_matchlist
;
1410 int textlen
= strlen (text
);
1412 sizeof_matchlist
= 10;
1413 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1416 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1417 if (!strncmp (ptr
->name
, text
, textlen
)
1418 && !ptr
->abbrev_flag
1419 && (ptr
->function
.cfunc
1420 || ptr
->prefixlist
))
1422 if (matches
== sizeof_matchlist
)
1424 sizeof_matchlist
*= 2;
1425 matchlist
= (char **) xrealloc ((char *) matchlist
,
1427 * sizeof (char *)));
1430 matchlist
[matches
] = (char *)
1431 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1433 strcpy (matchlist
[matches
], ptr
->name
);
1434 else if (word
> text
)
1436 /* Return some portion of ptr->name. */
1437 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1441 /* Return some of text plus ptr->name. */
1442 strncpy (matchlist
[matches
], word
, text
- word
);
1443 matchlist
[matches
][text
- word
] = '\0';
1444 strcat (matchlist
[matches
], ptr
->name
);
1451 free ((PTR
) matchlist
);
1456 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1457 * sizeof (char *)));
1458 matchlist
[matches
] = (char *) 0;
1464 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1466 /* Return a vector of char pointers which point to the different
1467 possible completions in CMD of TEXT.
1469 WORD points in the same buffer as TEXT, and completions should be
1470 returned relative to this position. For example, suppose TEXT is "foo"
1471 and we want to complete to "foobar". If WORD is "oo", return
1472 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1475 complete_on_enum (enumlist
, text
, word
)
1481 int sizeof_matchlist
;
1483 int textlen
= strlen (text
);
1487 sizeof_matchlist
= 10;
1488 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1491 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1492 if (strncmp (name
, text
, textlen
) == 0)
1494 if (matches
== sizeof_matchlist
)
1496 sizeof_matchlist
*= 2;
1497 matchlist
= (char **) xrealloc ((char *) matchlist
,
1499 * sizeof (char *)));
1502 matchlist
[matches
] = (char *)
1503 xmalloc (strlen (word
) + strlen (name
) + 1);
1505 strcpy (matchlist
[matches
], name
);
1506 else if (word
> text
)
1508 /* Return some portion of name. */
1509 strcpy (matchlist
[matches
], name
+ (word
- text
));
1513 /* Return some of text plus name. */
1514 strncpy (matchlist
[matches
], word
, text
- word
);
1515 matchlist
[matches
][text
- word
] = '\0';
1516 strcat (matchlist
[matches
], name
);
1523 free ((PTR
) matchlist
);
1528 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1529 * sizeof (char *)));
1530 matchlist
[matches
] = (char *) 0;
1537 parse_binary_operation (arg
)
1545 length
= strlen (arg
);
1547 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
1550 if (!strncmp (arg
, "on", length
)
1551 || !strncmp (arg
, "1", length
)
1552 || !strncmp (arg
, "yes", length
))
1554 else if (!strncmp (arg
, "off", length
)
1555 || !strncmp (arg
, "0", length
)
1556 || !strncmp (arg
, "no", length
))
1560 error ("\"on\" or \"off\" expected.");
1565 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1566 of the argument, and FROM_TTY is nonzero if this command is being entered
1567 directly by the user (i.e. these are just like any other
1568 command). C is the command list element for the command. */
1570 do_setshow_command (arg
, from_tty
, c
)
1573 struct cmd_list_element
*c
;
1575 if (c
->type
== set_cmd
)
1577 switch (c
->var_type
)
1588 new = (char *) xmalloc (strlen (arg
) + 2);
1591 while ((ch
= *p
++) != '\000')
1595 /* \ at end of argument is used after spaces
1596 so they won't be lost. */
1597 /* This is obsolete now that we no longer strip
1598 trailing whitespace and actually, the backslash
1599 didn't get here in my test, readline or
1600 something did something funky with a backslash
1601 right before a newline. */
1604 ch
= parse_escape (&p
);
1606 break; /* C loses */
1614 if (*(p
- 1) != '\\')
1618 new = (char *) xrealloc (new, q
- new);
1619 if (*(char **) c
->var
!= NULL
)
1620 free (*(char **) c
->var
);
1621 *(char **) c
->var
= new;
1624 case var_string_noescape
:
1627 if (*(char **) c
->var
!= NULL
)
1628 free (*(char **) c
->var
);
1629 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1633 error_no_arg ("filename to set it to.");
1634 if (*(char **) c
->var
!= NULL
)
1635 free (*(char **) c
->var
);
1636 *(char **) c
->var
= tilde_expand (arg
);
1639 *(int *) c
->var
= parse_binary_operation (arg
);
1643 error_no_arg ("integer to set it to.");
1644 *(unsigned int *) c
->var
= parse_and_eval_address (arg
);
1645 if (*(unsigned int *) c
->var
== 0)
1646 *(unsigned int *) c
->var
= UINT_MAX
;
1652 error_no_arg ("integer to set it to.");
1653 val
= parse_and_eval_address (arg
);
1655 *(int *) c
->var
= INT_MAX
;
1656 else if (val
>= INT_MAX
)
1657 error ("integer %u out of range", val
);
1659 *(int *) c
->var
= val
;
1664 error_no_arg ("integer to set it to.");
1665 *(int *) c
->var
= parse_and_eval_address (arg
);
1675 /* if no argument was supplied, print an informative error message */
1679 strcpy (msg
, "Requires an argument. Valid arguments are ");
1680 for (i
= 0; c
->enums
[i
]; i
++)
1684 strcat (msg
, c
->enums
[i
]);
1690 p
= strchr (arg
, ' ');
1698 for (i
= 0; c
->enums
[i
]; i
++)
1699 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
1701 match
= c
->enums
[i
];
1706 error ("Undefined item: \"%s\".", arg
);
1709 error ("Ambiguous item \"%s\".", arg
);
1711 *(char **) c
->var
= match
;
1715 error ("gdb internal error: bad var_type in do_setshow_command");
1718 else if (c
->type
== show_cmd
)
1721 struct cleanup
*old_chain
;
1722 struct ui_stream
*stb
;
1725 stb
= ui_out_stream_new (uiout
);
1726 old_chain
= make_cleanup ((make_cleanup_func
) ui_out_stream_delete
, stb
);
1729 /* Print doc minus "show" at start. */
1730 print_doc_line (gdb_stdout
, c
->doc
+ 5);
1733 ui_out_text (uiout
, " is ");
1734 ui_out_wrap_hint (uiout
, " ");
1736 switch (c
->var_type
)
1742 if (*(unsigned char **) c
->var
)
1743 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
1747 case var_string_noescape
:
1750 if (*(char **) c
->var
)
1751 fputs_filtered (*(char **) c
->var
, stb
->stream
);
1755 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
1758 if (*(unsigned int *) c
->var
== UINT_MAX
)
1760 fputs_filtered ("unlimited", stb
->stream
);
1763 /* else fall through */
1765 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
1768 if (*(int *) c
->var
== INT_MAX
)
1770 fputs_filtered ("unlimited", stb
->stream
);
1773 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
1777 error ("gdb internal error: bad var_type in do_setshow_command");
1780 ui_out_text (uiout
, "\"");
1781 ui_out_field_stream (uiout
, "value", stb
);
1783 ui_out_text (uiout
, "\"");
1784 ui_out_text (uiout
, ".\n");
1785 do_cleanups (old_chain
);
1787 fputs_filtered (" is ", gdb_stdout
);
1789 switch (c
->var_type
)
1793 fputs_filtered ("\"", gdb_stdout
);
1794 if (*(unsigned char **) c
->var
)
1795 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
1796 fputs_filtered ("\"", gdb_stdout
);
1799 case var_string_noescape
:
1802 fputs_filtered ("\"", gdb_stdout
);
1803 if (*(char **) c
->var
)
1804 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
1805 fputs_filtered ("\"", gdb_stdout
);
1808 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
1811 if (*(unsigned int *) c
->var
== UINT_MAX
)
1813 fputs_filtered ("unlimited", gdb_stdout
);
1816 /* else fall through */
1818 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
1821 if (*(int *) c
->var
== INT_MAX
)
1823 fputs_filtered ("unlimited", gdb_stdout
);
1826 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
1830 error ("gdb internal error: bad var_type in do_setshow_command");
1832 fputs_filtered (".\n", gdb_stdout
);
1836 error ("gdb internal error: bad cmd_type in do_setshow_command");
1837 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1838 if (c
->type
== set_cmd
&& set_hook
)
1842 /* Show all the settings in a list of show commands. */
1845 cmd_show_list (list
, from_tty
, prefix
)
1846 struct cmd_list_element
*list
;
1851 ui_out_list_begin (uiout
, "showlist");
1853 for (; list
!= NULL
; list
= list
->next
)
1855 /* If we find a prefix, run its list, prefixing our output by its
1856 prefix (with "show " skipped). */
1858 if (list
->prefixlist
&& !list
->abbrev_flag
)
1860 ui_out_list_begin (uiout
, "optionlist");
1861 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
1862 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1863 ui_out_list_end (uiout
);
1865 if (list
->type
== show_cmd
)
1867 ui_out_list_begin (uiout
, "option");
1868 ui_out_text (uiout
, prefix
);
1869 ui_out_field_string (uiout
, "name", list
->name
);
1870 ui_out_text (uiout
, ": ");
1871 do_setshow_command ((char *) NULL
, from_tty
, list
);
1872 ui_out_list_end (uiout
);
1875 if (list
->prefixlist
&& !list
->abbrev_flag
)
1876 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1877 if (list
->type
== show_cmd
)
1879 fputs_filtered (prefix
, gdb_stdout
);
1880 fputs_filtered (list
->name
, gdb_stdout
);
1881 fputs_filtered (": ", gdb_stdout
);
1882 do_setshow_command ((char *) NULL
, from_tty
, list
);
1887 ui_out_list_end (uiout
);
1893 shell_escape (arg
, from_tty
)
1898 /* If ARG is NULL, they want an inferior shell, but `system' just
1899 reports if the shell is available when passed a NULL arg. */
1900 int rc
= system (arg
? arg
: "");
1903 arg
= "inferior shell";
1907 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", arg
,
1908 safe_strerror (errno
));
1909 gdb_flush (gdb_stderr
);
1913 fprintf_unfiltered (gdb_stderr
, "%s exited with status %d\n", arg
, rc
);
1914 gdb_flush (gdb_stderr
);
1917 /* Make sure to return to the directory GDB thinks it is, in case the
1918 shell command we just ran changed it. */
1919 chdir (current_directory
);
1921 #else /* Can fork. */
1922 int rc
, status
, pid
;
1923 char *p
, *user_shell
;
1925 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1926 user_shell
= "/bin/sh";
1928 /* Get the name of the shell for arg0 */
1929 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1932 p
++; /* Get past '/' */
1934 if ((pid
= fork ()) == 0)
1937 execl (user_shell
, p
, 0);
1939 execl (user_shell
, p
, "-c", arg
, 0);
1941 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", user_shell
,
1942 safe_strerror (errno
));
1943 gdb_flush (gdb_stderr
);
1948 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1951 error ("Fork failed");
1952 #endif /* Can fork. */
1956 make_command (arg
, from_tty
)
1966 p
= xmalloc (sizeof ("make ") + strlen (arg
));
1967 strcpy (p
, "make ");
1968 strcpy (p
+ sizeof ("make ") - 1, arg
);
1971 shell_escape (p
, from_tty
);
1975 show_user_1 (c
, stream
)
1976 struct cmd_list_element
*c
;
1977 struct ui_file
*stream
;
1979 register struct command_line
*cmdlines
;
1981 cmdlines
= c
->user_commands
;
1984 fputs_filtered ("User command ", stream
);
1985 fputs_filtered (c
->name
, stream
);
1986 fputs_filtered (":\n", stream
);
1989 print_command_lines (uiout
, cmdlines
, 1);
1990 fputs_filtered ("\n", stream
);
1994 print_command_line (cmdlines
, 4, stream
);
1995 cmdlines
= cmdlines
->next
;
1997 fputs_filtered ("\n", stream
);
2003 show_user (args
, from_tty
)
2007 struct cmd_list_element
*c
;
2008 extern struct cmd_list_element
*cmdlist
;
2012 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
2013 if (c
->class != class_user
)
2014 error ("Not a user command.");
2015 show_user_1 (c
, gdb_stdout
);
2019 for (c
= cmdlist
; c
; c
= c
->next
)
2021 if (c
->class == class_user
)
2022 show_user_1 (c
, gdb_stdout
);
2028 _initialize_command ()
2030 add_com ("shell", class_support
, shell_escape
,
2031 "Execute the rest of the line as a shell command. \n\
2032 With no arguments, run an inferior shell.");
2034 /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
2035 be a really useful feature. Unfortunatly, the below wont do
2036 this. Instead it adds support for the form ``(gdb) ! ls''
2037 (i.e. the space is required). If the ``!'' command below is
2038 added the complains about no ``!'' command would be replaced by
2039 complains about how the ``!'' command is broken :-) */
2041 add_com_alias ("!", "shell", class_support
, 0);
2043 add_com ("make", class_support
, make_command
,
2044 "Run the ``make'' program using the rest of the line as arguments.");
2045 add_cmd ("user", no_class
, show_user
,
2046 "Show definitions of user defined commands.\n\
2047 Argument is the name of the user defined command.\n\
2048 With no argument, show definitions of all user defined commands.", &showlist
);
2049 add_com ("apropos", class_support
, apropos_command
, "Search for commands matching a REGEXP");