1 /* Handle lists of commands, their decoding and documentation, for GDB.
2 Copyright 1986, 1989, 1990, 1991, 1998, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "gnu-regex.h"
31 /* FIXME: this should be auto-configured! */
36 /* Prototypes for local functions */
38 static void undef_cmd_error (char *, char *);
40 static void show_user (char *, int);
42 static void show_user_1 (struct cmd_list_element
*, struct ui_file
*);
44 static void make_command (char *, int);
46 static void shell_escape (char *, int);
48 static int parse_binary_operation (char *);
50 static void print_doc_line (struct ui_file
*, char *);
52 static struct cmd_list_element
*find_cmd (char *command
,
54 struct cmd_list_element
*clist
,
55 int ignore_help_classes
,
57 static void apropos_cmd_helper (struct ui_file
*, struct cmd_list_element
*,
58 struct re_pattern_buffer
*, char *);
60 static void help_all (struct ui_file
*stream
);
62 void apropos_command (char *, int);
64 void _initialize_command (void);
66 /* Add element named NAME.
67 CLASS is the top level category into which commands are broken down
69 FUN should be the function to execute the command;
70 it will get a character string as argument, with leading
71 and trailing blanks already eliminated.
73 DOC is a documentation string for the command.
74 Its first line should be a complete sentence.
75 It should start with ? for a command that is an abbreviation
76 or with * for a command that most users don't need to know about.
78 Add this command to command list *LIST.
80 Returns a pointer to the added command (not necessarily the head
83 struct cmd_list_element
*
84 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
85 char *doc
, struct cmd_list_element
**list
)
87 register struct cmd_list_element
*c
88 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
89 struct cmd_list_element
*p
;
91 delete_cmd (name
, list
);
93 if (*list
== NULL
|| STRCMP ((*list
)->name
, name
) >= 0)
101 while (p
->next
&& STRCMP (p
->next
->name
, name
) <= 0)
111 c
->function
.cfunc
= fun
;
114 c
->replacement
= NULL
;
116 c
->prefixlist
= NULL
;
117 c
->prefixname
= NULL
;
118 c
->allow_unknown
= 0;
120 c
->completer
= make_symbol_completion_list
;
121 c
->type
= not_set_cmd
;
123 c
->var_type
= var_boolean
;
125 c
->user_commands
= NULL
;
127 c
->cmd_pointer
= NULL
;
133 /* Deprecates a command CMD.
134 REPLACEMENT is the name of the command which should be used in place
135 of this command, or NULL if no such command exists.
137 This function does not check to see if command REPLACEMENT exists
138 since gdb may not have gotten around to adding REPLACEMENT when this
141 Returns a pointer to the deprecated command. */
143 struct cmd_list_element
*
144 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
146 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
148 if (replacement
!= NULL
)
149 cmd
->replacement
= replacement
;
151 cmd
->replacement
= NULL
;
157 /* Same as above, except that the abbrev_flag is set. */
159 #if 0 /* Currently unused */
161 struct cmd_list_element
*
162 add_abbrev_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
163 char *doc
, struct cmd_list_element
**list
)
165 register struct cmd_list_element
*c
166 = add_cmd (name
, class, fun
, doc
, list
);
174 struct cmd_list_element
*
175 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
176 int abbrev_flag
, struct cmd_list_element
**list
)
178 /* Must do this since lookup_cmd tries to side-effect its first arg */
180 register struct cmd_list_element
*old
;
181 register struct cmd_list_element
*c
;
182 copied_name
= (char *) alloca (strlen (oldname
) + 1);
183 strcpy (copied_name
, oldname
);
184 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
188 delete_cmd (name
, list
);
192 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
193 c
->prefixlist
= old
->prefixlist
;
194 c
->prefixname
= old
->prefixname
;
195 c
->allow_unknown
= old
->allow_unknown
;
196 c
->abbrev_flag
= abbrev_flag
;
197 c
->cmd_pointer
= old
;
201 /* Like add_cmd but adds an element for a command prefix:
202 a name that should be followed by a subcommand to be looked up
203 in another command list. PREFIXLIST should be the address
204 of the variable containing that list. */
206 struct cmd_list_element
*
207 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
208 char *doc
, struct cmd_list_element
**prefixlist
,
209 char *prefixname
, int allow_unknown
,
210 struct cmd_list_element
**list
)
212 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
213 c
->prefixlist
= prefixlist
;
214 c
->prefixname
= prefixname
;
215 c
->allow_unknown
= allow_unknown
;
219 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
221 struct cmd_list_element
*
222 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
223 void (*fun
) (char *, int), char *doc
,
224 struct cmd_list_element
**prefixlist
, char *prefixname
,
225 int allow_unknown
, struct cmd_list_element
**list
)
227 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
228 c
->prefixlist
= prefixlist
;
229 c
->prefixname
= prefixname
;
230 c
->allow_unknown
= allow_unknown
;
235 /* This is an empty "cfunc". */
237 not_just_help_class_command (char *args
, int from_tty
)
241 /* This is an empty "sfunc". */
242 static void empty_sfunc (char *, int, struct cmd_list_element
*);
245 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
249 /* Add element named NAME to command list LIST (the list for set
250 or some sublist thereof).
251 CLASS is as in add_cmd.
252 VAR_TYPE is the kind of thing we are setting.
253 VAR is address of the variable being controlled by this command.
254 DOC is the documentation string. */
256 struct cmd_list_element
*
257 add_set_cmd (char *name
,
258 enum command_class
class,
262 struct cmd_list_element
**list
)
264 struct cmd_list_element
*c
265 = add_cmd (name
, class, NO_FUNCTION
, doc
, list
);
268 c
->var_type
= var_type
;
270 /* This needs to be something besides NO_FUNCTION so that this isn't
271 treated as a help class. */
272 c
->function
.sfunc
= empty_sfunc
;
276 /* Add element named NAME to command list LIST (the list for set
277 or some sublist thereof).
278 CLASS is as in add_cmd.
279 ENUMLIST is a list of strings which may follow NAME.
280 VAR is address of the variable which will contain the matching string
282 DOC is the documentation string. */
284 struct cmd_list_element
*
285 add_set_enum_cmd (char *name
,
286 enum command_class
class,
287 const char *enumlist
[],
290 struct cmd_list_element
**list
)
292 struct cmd_list_element
*c
293 = add_set_cmd (name
, class, var_enum
, var
, doc
, list
);
299 /* Add element named NAME to command list LIST (the list for set
300 or some sublist thereof).
301 CLASS is as in add_cmd.
302 VAR is address of the variable which will contain the value.
303 DOC is the documentation string. */
304 struct cmd_list_element
*
305 add_set_auto_boolean_cmd (char *name
,
306 enum command_class
class,
307 enum cmd_auto_boolean
*var
,
309 struct cmd_list_element
**list
)
311 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
312 struct cmd_list_element
*c
;
313 c
= add_set_cmd (name
, class, var_auto_boolean
, var
, doc
, list
);
314 c
->enums
= auto_boolean_enums
;
318 /* Where SETCMD has already been added, add the corresponding show
319 command to LIST and return a pointer to the added command (not
320 necessarily the head of LIST). */
321 struct cmd_list_element
*
322 add_show_from_set (struct cmd_list_element
*setcmd
,
323 struct cmd_list_element
**list
)
325 struct cmd_list_element
*showcmd
=
326 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
327 struct cmd_list_element
*p
;
329 memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
330 delete_cmd (showcmd
->name
, list
);
331 showcmd
->type
= show_cmd
;
333 /* Replace "set " at start of docstring with "show ". */
334 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
335 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
336 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
338 fprintf_unfiltered (gdb_stderr
, "GDB internal error: Bad docstring for set command\n");
340 if (*list
== NULL
|| STRCMP ((*list
)->name
, showcmd
->name
) >= 0)
342 showcmd
->next
= *list
;
348 while (p
->next
&& STRCMP (p
->next
->name
, showcmd
->name
) <= 0)
352 showcmd
->next
= p
->next
;
359 /* Remove the command named NAME from the command list. */
362 delete_cmd (char *name
, struct cmd_list_element
**list
)
364 register struct cmd_list_element
*c
;
365 struct cmd_list_element
*p
;
367 while (*list
&& STREQ ((*list
)->name
, name
))
370 (*list
)->hookee
->hook
= 0; /* Hook slips out of its mouth */
377 for (c
= *list
; c
->next
;)
379 if (STREQ (c
->next
->name
, name
))
382 c
->next
->hookee
->hook
= 0; /* hooked cmd gets away. */
384 free ((PTR
) c
->next
);
391 /* Recursively walk the commandlist structures, and print out the
392 documentation of commands that match our regex in either their
393 name, or their documentation.
396 apropos_cmd_helper (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
397 struct re_pattern_buffer
*regex
, char *prefix
)
399 register struct cmd_list_element
*c
;
400 int returnvalue
=1; /*Needed to avoid double printing*/
401 /* Walk through the commands */
402 for (c
=commandlist
;c
;c
=c
->next
)
406 /* Try to match against the name*/
407 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
408 if (returnvalue
>= 0)
410 /* Stolen from help_cmd_list. We don't directly use
411 * help_cmd_list because it doesn't let us print out
414 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
415 print_doc_line (stream
, c
->doc
);
416 fputs_filtered ("\n", stream
);
417 returnvalue
=0; /*Set this so we don't print it again.*/
420 if (c
->doc
!= NULL
&& returnvalue
!= 0)
422 /* Try to match against documentation */
423 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=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
);
434 /* Check if this command has subcommands */
435 if (c
->prefixlist
!= NULL
)
437 /* Recursively call ourselves on the subcommand list,
438 passing the right prefix in.
440 apropos_cmd_helper(stream
,*c
->prefixlist
,regex
,c
->prefixname
);
444 /* Search through names of commands and documentations for a certain
448 apropos_command (char *searchstr
, int from_tty
)
450 extern struct cmd_list_element
*cmdlist
; /*This is the main command list*/
452 char *pattern_fastmap
;
453 char errorbuffer
[512];
454 pattern_fastmap
=calloc(256,sizeof(char));
455 if (searchstr
== NULL
)
456 error("REGEXP string is empty");
458 if (regcomp(&pattern
,searchstr
,REG_ICASE
) == 0)
460 pattern
.fastmap
=pattern_fastmap
;
461 re_compile_fastmap(&pattern
);
462 apropos_cmd_helper(gdb_stdout
,cmdlist
,&pattern
,"");
466 regerror(regcomp(&pattern
,searchstr
,REG_ICASE
),NULL
,errorbuffer
,512);
467 error("Error in regular expression:%s",errorbuffer
);
469 free(pattern_fastmap
);
473 /* This command really has to deal with two things:
474 * 1) I want documentation on *this string* (usually called by
475 * "help commandname").
476 * 2) I want documentation on *this list* (usually called by
477 * giving a command that requires subcommands. Also called by saying
480 * I am going to split this into two seperate comamnds, help_cmd and
485 help_cmd (char *command
, struct ui_file
*stream
)
487 struct cmd_list_element
*c
;
488 extern struct cmd_list_element
*cmdlist
;
492 help_list (cmdlist
, "", all_classes
, stream
);
496 if (strcmp (command
, "all") == 0)
502 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
507 /* There are three cases here.
508 If c->prefixlist is nonzero, we have a prefix command.
509 Print its documentation, then list its subcommands.
511 If c->function is nonzero, we really have a command.
512 Print its documentation and return.
514 If c->function is zero, we have a class name.
515 Print its documentation (as if it were a command)
516 and then set class to the number of this class
517 so that the commands in the class will be listed. */
519 fputs_filtered (c
->doc
, stream
);
520 fputs_filtered ("\n", stream
);
522 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
524 fprintf_filtered (stream
, "\n");
526 /* If this is a prefix command, print it's subcommands */
528 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
530 /* If this is a class name, print all of the commands in the class */
531 if (c
->function
.cfunc
== NULL
)
532 help_list (cmdlist
, "", c
->class, stream
);
535 fprintf_filtered (stream
, "\nThis command has a hook defined: %s\n",
540 * Get a specific kind of help on a command list.
543 * CMDTYPE is the prefix to use in the title string.
544 * CLASS is the class with which to list the nodes of this list (see
545 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
546 * everything, ALL_CLASSES for just classes, and non-negative for only things
547 * in a specific class.
548 * and STREAM is the output stream on which to print things.
549 * If you call this routine with a class >= 0, it recurses.
552 help_list (struct cmd_list_element
*list
, char *cmdtype
,
553 enum command_class
class, struct ui_file
*stream
)
556 char *cmdtype1
, *cmdtype2
;
558 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
559 len
= strlen (cmdtype
);
560 cmdtype1
= (char *) alloca (len
+ 1);
562 cmdtype2
= (char *) alloca (len
+ 4);
567 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
569 strncpy (cmdtype2
, cmdtype
, len
- 1);
570 strcpy (cmdtype2
+ len
- 1, " sub");
573 if (class == all_classes
)
574 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
576 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
578 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
580 if (class == all_classes
)
581 fprintf_filtered (stream
, "\n\
582 Type \"help%s\" followed by a class name for a list of commands in that class.",
585 fprintf_filtered (stream
, "\n\
586 Type \"help%s\" followed by %scommand name for full documentation.\n\
587 Command name abbreviations are allowed if unambiguous.\n",
592 help_all (struct ui_file
*stream
)
594 struct cmd_list_element
*c
;
595 extern struct cmd_list_element
*cmdlist
;
597 for (c
= cmdlist
; c
; c
= c
->next
)
601 /* If this is a prefix command, print it's subcommands */
603 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 0, stream
);
605 /* If this is a class name, print all of the commands in the class */
606 else if (c
->function
.cfunc
== NULL
)
607 help_cmd_list (cmdlist
, c
->class, "", 0, stream
);
611 /* Print only the first line of STR on STREAM. */
613 print_doc_line (struct ui_file
*stream
, char *str
)
615 static char *line_buffer
= 0;
616 static int line_size
;
622 line_buffer
= (char *) xmalloc (line_size
);
626 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
628 if (p
- str
> line_size
- 1)
630 line_size
= p
- str
+ 1;
631 free ((PTR
) line_buffer
);
632 line_buffer
= (char *) xmalloc (line_size
);
634 strncpy (line_buffer
, str
, p
- str
);
635 line_buffer
[p
- str
] = '\0';
636 if (islower (line_buffer
[0]))
637 line_buffer
[0] = toupper (line_buffer
[0]);
639 ui_out_text (uiout
, line_buffer
);
641 fputs_filtered (line_buffer
, stream
);
646 * Implement a help command on command list LIST.
647 * RECURSE should be non-zero if this should be done recursively on
648 * all sublists of LIST.
649 * PREFIX is the prefix to print before each command name.
650 * STREAM is the stream upon which the output should be written.
652 * A non-negative class number to list only commands in that
654 * ALL_COMMANDS to list all commands in list.
655 * ALL_CLASSES to list all classes in list.
657 * Note that RECURSE will be active on *all* sublists, not just the
658 * ones selected by the criteria above (ie. the selection mechanism
659 * is at the low level, not the high-level).
662 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
663 char *prefix
, int recurse
, struct ui_file
*stream
)
665 register struct cmd_list_element
*c
;
667 for (c
= list
; c
; c
= c
->next
)
669 if (c
->abbrev_flag
== 0 &&
670 (class == all_commands
671 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
672 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
674 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
675 print_doc_line (stream
, c
->doc
);
676 fputs_filtered ("\n", stream
);
679 && c
->prefixlist
!= 0
680 && c
->abbrev_flag
== 0)
681 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
686 /* Search the input clist for 'command'. Return the command if
687 found (or NULL if not), and return the number of commands
690 static struct cmd_list_element
*
691 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
692 int ignore_help_classes
, int *nfound
)
694 struct cmd_list_element
*found
, *c
;
696 found
= (struct cmd_list_element
*) NULL
;
698 for (c
= clist
; c
; c
= c
->next
)
699 if (!strncmp (command
, c
->name
, len
)
700 && (!ignore_help_classes
|| c
->function
.cfunc
))
704 if (c
->name
[len
] == '\0')
713 /* This routine takes a line of TEXT and a CLIST in which to start the
714 lookup. When it returns it will have incremented the text pointer past
715 the section of text it matched, set *RESULT_LIST to point to the list in
716 which the last word was matched, and will return a pointer to the cmd
717 list element which the text matches. It will return NULL if no match at
718 all was possible. It will return -1 (cast appropriately, ick) if ambigous
719 matches are possible; in this case *RESULT_LIST will be set to point to
720 the list in which there are ambiguous choices (and *TEXT will be set to
721 the ambiguous text string).
723 If the located command was an abbreviation, this routine returns the base
724 command of the abbreviation.
726 It does no error reporting whatsoever; control will always return
727 to the superior routine.
729 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
730 at the prefix_command (ie. the best match) *or* (special case) will be NULL
731 if no prefix command was ever found. For example, in the case of "info a",
732 "info" matches without ambiguity, but "a" could be "args" or "address", so
733 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
734 RESULT_LIST should not be interpeted as a pointer to the beginning of a
735 list; it simply points to a specific command. In the case of an ambiguous
736 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
737 "info t" can be "info types" or "info target"; upon return *TEXT has been
738 advanced past "info ").
740 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
741 affect the operation).
743 This routine does *not* modify the text pointed to by TEXT.
745 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
746 are actually help classes rather than commands (i.e. the function field of
747 the struct cmd_list_element is NULL). */
749 struct cmd_list_element
*
750 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
751 struct cmd_list_element
**result_list
, int ignore_help_classes
)
754 int len
, tmp
, nfound
;
755 struct cmd_list_element
*found
, *c
;
758 while (**text
== ' ' || **text
== '\t')
761 /* Treating underscores as part of command words is important
762 so that "set args_foo()" doesn't get interpreted as
763 "set args _foo()". */
765 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
767 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
768 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
772 /* If nothing but whitespace, return 0. */
778 /* *text and p now bracket the first command word to lookup (and
779 it's length is len). We copy this into a local temporary */
782 command
= (char *) alloca (len
+ 1);
783 for (tmp
= 0; tmp
< len
; tmp
++)
785 char x
= (*text
)[tmp
];
793 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
796 ** We didn't find the command in the entered case, so lower case it
799 if (!found
|| nfound
== 0)
801 for (tmp
= 0; tmp
< len
; tmp
++)
803 char x
= command
[tmp
];
804 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
806 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
809 /* If nothing matches, we have a simple failure. */
815 if (result_list
!= NULL
)
816 /* Will be modified in calling routine
817 if we know what the prefix command is. */
819 return (struct cmd_list_element
*) -1; /* Ambiguous. */
822 /* We've matched something on this list. Move text pointer forward. */
826 if (found
->cmd_pointer
)
828 /* We drop the alias (abbreviation) in favor of the command it is
829 pointing to. If the alias is deprecated, though, we need to
830 warn the user about it before we drop it. Note that while we
831 are warning about the alias, we may also warn about the command
832 itself and we will adjust the appropriate DEPRECATED_WARN_USER
835 if (found
->flags
& DEPRECATED_WARN_USER
)
836 deprecated_cmd_warning (&line
);
837 found
= found
->cmd_pointer
;
839 /* If we found a prefix command, keep looking. */
841 if (found
->prefixlist
)
843 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
844 ignore_help_classes
);
847 /* Didn't find anything; this is as far as we got. */
848 if (result_list
!= NULL
)
849 *result_list
= clist
;
852 else if (c
== (struct cmd_list_element
*) -1)
854 /* We've gotten this far properly, but the next step
855 is ambiguous. We need to set the result list to the best
856 we've found (if an inferior hasn't already set it). */
857 if (result_list
!= NULL
)
859 /* This used to say *result_list = *found->prefixlist
860 If that was correct, need to modify the documentation
861 at the top of this function to clarify what is supposed
863 *result_list
= found
;
874 if (result_list
!= NULL
)
875 *result_list
= clist
;
880 /* All this hair to move the space to the front of cmdtype */
883 undef_cmd_error (char *cmdtype
, char *q
)
885 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
889 strlen (cmdtype
) - 1,
893 /* Look up the contents of *LINE as a command in the command list LIST.
894 LIST is a chain of struct cmd_list_element's.
895 If it is found, return the struct cmd_list_element for that command
896 and update *LINE to point after the command name, at the first argument.
897 If not found, call error if ALLOW_UNKNOWN is zero
898 otherwise (or if error returns) return zero.
899 Call error if specified command is ambiguous,
900 unless ALLOW_UNKNOWN is negative.
901 CMDTYPE precedes the word "command" in the error message.
903 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
904 elements which are actually help classes rather than commands (i.e.
905 the function field of the struct cmd_list_element is 0). */
907 struct cmd_list_element
*
908 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
909 int allow_unknown
, int ignore_help_classes
)
911 struct cmd_list_element
*last_list
= 0;
912 struct cmd_list_element
*c
=
913 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
915 /* This is wrong for complete_command. */
916 char *ptr
= (*line
) + strlen (*line
) - 1;
918 /* Clear off trailing whitespace. */
919 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
929 error ("Lack of needed %scommand", cmdtype
);
934 while (isalnum (*p
) || *p
== '-')
937 q
= (char *) alloca (p
- *line
+ 1);
938 strncpy (q
, *line
, p
- *line
);
940 undef_cmd_error (cmdtype
, q
);
946 else if (c
== (struct cmd_list_element
*) -1)
948 /* Ambigous. Local values should be off prefixlist or called
950 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
952 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
953 struct cmd_list_element
*local_list
=
954 (last_list
? *(last_list
->prefixlist
) : list
);
956 if (local_allow_unknown
< 0)
959 return last_list
; /* Found something. */
961 return 0; /* Found nothing. */
965 /* Report as error. */
970 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
971 && (*line
)[amb_len
] != '\t');
976 for (c
= local_list
; c
; c
= c
->next
)
977 if (!strncmp (*line
, c
->name
, amb_len
))
979 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
982 strcat (ambbuf
, ", ");
983 strcat (ambbuf
, c
->name
);
987 strcat (ambbuf
, "..");
991 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
998 /* We've got something. It may still not be what the caller
999 wants (if this command *needs* a subcommand). */
1000 while (**line
== ' ' || **line
== '\t')
1003 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1004 undef_cmd_error (c
->prefixname
, *line
);
1006 /* Seems to be what he wants. Return it. */
1012 /* We are here presumably because an alias or command in *TEXT is
1013 deprecated and a warning message should be generated. This function
1014 decodes *TEXT and potentially generates a warning message as outlined
1017 Example for 'set endian big' which has a fictitious alias 'seb'.
1019 If alias wasn't used in *TEXT, and the command is deprecated:
1020 "warning: 'set endian big' is deprecated."
1022 If alias was used, and only the alias is deprecated:
1023 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1025 If alias was used and command is deprecated (regardless of whether the
1026 alias itself is deprecated:
1028 "warning: 'set endian big' (seb) is deprecated."
1030 After the message has been sent, clear the appropriate flags in the
1031 command and/or the alias so the user is no longer bothered.
1035 deprecated_cmd_warning (char **text
)
1037 struct cmd_list_element
*alias
= NULL
;
1038 struct cmd_list_element
*prefix_cmd
= NULL
;
1039 struct cmd_list_element
*cmd
= NULL
;
1040 struct cmd_list_element
*c
;
1043 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1044 /* return if text doesn't evaluate to a command */
1047 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1048 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1049 /* return if nothing is deprecated */
1052 printf_filtered ("Warning:");
1054 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1055 printf_filtered (" '%s', an alias for the", alias
->name
);
1057 printf_filtered (" command '");
1060 printf_filtered ("%s", prefix_cmd
->prefixname
);
1062 printf_filtered ("%s", cmd
->name
);
1064 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1065 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1067 printf_filtered ("' is deprecated.\n");
1070 /* if it is only the alias that is deprecated, we want to indicate the
1071 new alias, otherwise we'll indicate the new command */
1073 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1075 if (alias
->replacement
)
1076 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1078 printf_filtered ("No alternative known.\n\n");
1082 if (cmd
->replacement
)
1083 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1085 printf_filtered ("No alternative known.\n\n");
1088 /* We've warned you, now we'll keep quiet */
1090 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1092 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1097 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1098 Return 1 on success, 0 on failure.
1100 If LINE refers to an alias, *alias will point to that alias.
1102 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1103 command) set *prefix_cmd.
1105 Set *cmd to point to the command LINE indicates.
1107 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1108 exist, they are NULL when we return.
1112 lookup_cmd_composition (char *text
,
1113 struct cmd_list_element
**alias
,
1114 struct cmd_list_element
**prefix_cmd
,
1115 struct cmd_list_element
**cmd
)
1118 int len
, tmp
, nfound
;
1119 struct cmd_list_element
*cur_list
;
1120 struct cmd_list_element
*prev_cmd
;
1129 /* Go through as many command lists as we need to
1130 to find the command TEXT refers to. */
1134 while (*text
== ' ' || *text
== '\t')
1137 /* Treating underscores as part of command words is important
1138 so that "set args_foo()" doesn't get interpreted as
1139 "set args _foo()". */
1141 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1143 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
1144 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
1148 /* If nothing but whitespace, return. */
1154 /* text and p now bracket the first command word to lookup (and
1155 it's length is len). We copy this into a local temporary */
1157 command
= (char *) alloca (len
+ 1);
1158 for (tmp
= 0; tmp
< len
; tmp
++)
1163 command
[len
] = '\0';
1168 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1170 /* We didn't find the command in the entered case, so lower case it
1173 if (!*cmd
|| nfound
== 0)
1175 for (tmp
= 0; tmp
< len
; tmp
++)
1177 char x
= command
[tmp
];
1178 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1180 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1183 if (*cmd
== (struct cmd_list_element
*) -1)
1185 return 0; /* ambiguous */
1189 return 0; /* nothing found */
1192 if ((*cmd
)->cmd_pointer
)
1194 /* cmd was actually an alias, we note that an alias was used
1195 (by assigning *alais) and we set *cmd.
1198 *cmd
= (*cmd
)->cmd_pointer
;
1200 *prefix_cmd
= prev_cmd
;
1202 if ((*cmd
)->prefixlist
)
1203 cur_list
= *(*cmd
)->prefixlist
;
1215 /* Look up the contents of *LINE as a command in the command list LIST.
1216 LIST is a chain of struct cmd_list_element's.
1217 If it is found, return the struct cmd_list_element for that command
1218 and update *LINE to point after the command name, at the first argument.
1219 If not found, call error if ALLOW_UNKNOWN is zero
1220 otherwise (or if error returns) return zero.
1221 Call error if specified command is ambiguous,
1222 unless ALLOW_UNKNOWN is negative.
1223 CMDTYPE precedes the word "command" in the error message. */
1225 struct cmd_list_element
*
1226 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1230 register struct cmd_list_element
*c
, *found
;
1233 char *processed_cmd
;
1236 /* Skip leading whitespace. */
1238 while (**line
== ' ' || **line
== '\t')
1241 /* Clear out trailing whitespace. */
1243 p
= *line
+ strlen (*line
);
1244 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1248 /* Find end of command name. */
1251 while (*p
== '-' || isalnum (*p
))
1254 /* Look up the command name.
1255 If exact match, keep that.
1256 Otherwise, take command abbreviated, if unique. Note that (in my
1257 opinion) a null string does *not* indicate ambiguity; simply the
1258 end of the argument. */
1263 error ("Lack of needed %scommand", cmdtype
);
1267 /* Copy over to a local buffer, converting to lowercase on the way.
1268 This is in case the command being parsed is a subcommand which
1269 doesn't match anything, and that's ok. We want the original
1270 untouched for the routine of the original command. */
1272 processed_cmd
= (char *) alloca (p
- *line
+ 1);
1273 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
1275 char x
= (*line
)[cmd_len
];
1277 processed_cmd
[cmd_len
] = tolower (x
);
1279 processed_cmd
[cmd_len
] = x
;
1281 processed_cmd
[cmd_len
] = '\0';
1283 /* Check all possibilities in the current command list. */
1286 for (c
= list
; c
; c
= c
->next
)
1288 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1292 if (c
->name
[cmd_len
] == 0)
1300 /* Report error for undefined command name. */
1304 if (nfound
> 1 && allow_unknown
>= 0)
1307 for (c
= list
; c
; c
= c
->next
)
1308 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1310 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
1312 if (strlen (ambbuf
))
1313 strcat (ambbuf
, ", ");
1314 strcat (ambbuf
, c
->name
);
1318 strcat (ambbuf
, "..");
1322 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
1323 processed_cmd
, ambbuf
);
1325 else if (!allow_unknown
)
1326 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
1330 /* Skip whitespace before the argument. */
1332 while (*p
== ' ' || *p
== '\t')
1336 if (found
->prefixlist
&& *p
)
1338 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
1339 found
->allow_unknown
);
1348 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1350 /* Return a vector of char pointers which point to the different
1351 possible completions in LIST of TEXT.
1353 WORD points in the same buffer as TEXT, and completions should be
1354 returned relative to this position. For example, suppose TEXT is "foo"
1355 and we want to complete to "foobar". If WORD is "oo", return
1356 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1359 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1361 struct cmd_list_element
*ptr
;
1363 int sizeof_matchlist
;
1365 int textlen
= strlen (text
);
1367 sizeof_matchlist
= 10;
1368 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1371 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1372 if (!strncmp (ptr
->name
, text
, textlen
)
1373 && !ptr
->abbrev_flag
1374 && (ptr
->function
.cfunc
1375 || ptr
->prefixlist
))
1377 if (matches
== sizeof_matchlist
)
1379 sizeof_matchlist
*= 2;
1380 matchlist
= (char **) xrealloc ((char *) matchlist
,
1382 * sizeof (char *)));
1385 matchlist
[matches
] = (char *)
1386 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1388 strcpy (matchlist
[matches
], ptr
->name
);
1389 else if (word
> text
)
1391 /* Return some portion of ptr->name. */
1392 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1396 /* Return some of text plus ptr->name. */
1397 strncpy (matchlist
[matches
], word
, text
- word
);
1398 matchlist
[matches
][text
- word
] = '\0';
1399 strcat (matchlist
[matches
], ptr
->name
);
1406 free ((PTR
) matchlist
);
1411 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1412 * sizeof (char *)));
1413 matchlist
[matches
] = (char *) 0;
1419 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1421 /* Return a vector of char pointers which point to the different
1422 possible completions in CMD of TEXT.
1424 WORD points in the same buffer as TEXT, and completions should be
1425 returned relative to this position. For example, suppose TEXT is "foo"
1426 and we want to complete to "foobar". If WORD is "oo", return
1427 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1430 complete_on_enum (const char *enumlist
[],
1435 int sizeof_matchlist
;
1437 int textlen
= strlen (text
);
1441 sizeof_matchlist
= 10;
1442 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1445 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1446 if (strncmp (name
, text
, textlen
) == 0)
1448 if (matches
== sizeof_matchlist
)
1450 sizeof_matchlist
*= 2;
1451 matchlist
= (char **) xrealloc ((char *) matchlist
,
1453 * sizeof (char *)));
1456 matchlist
[matches
] = (char *)
1457 xmalloc (strlen (word
) + strlen (name
) + 1);
1459 strcpy (matchlist
[matches
], name
);
1460 else if (word
> text
)
1462 /* Return some portion of name. */
1463 strcpy (matchlist
[matches
], name
+ (word
- text
));
1467 /* Return some of text plus name. */
1468 strncpy (matchlist
[matches
], word
, text
- word
);
1469 matchlist
[matches
][text
- word
] = '\0';
1470 strcat (matchlist
[matches
], name
);
1477 free ((PTR
) matchlist
);
1482 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1483 * sizeof (char *)));
1484 matchlist
[matches
] = (char *) 0;
1490 static enum cmd_auto_boolean
1491 parse_auto_binary_operation (const char *arg
)
1493 if (arg
!= NULL
&& *arg
!= '\0')
1495 int length
= strlen (arg
);
1496 while (isspace (arg
[length
- 1]) && length
> 0)
1498 if (strncmp (arg
, "on", length
) == 0
1499 || strncmp (arg
, "1", length
) == 0
1500 || strncmp (arg
, "yes", length
) == 0
1501 || strncmp (arg
, "enable", length
) == 0)
1502 return CMD_AUTO_BOOLEAN_TRUE
;
1503 else if (strncmp (arg
, "off", length
) == 0
1504 || strncmp (arg
, "0", length
) == 0
1505 || strncmp (arg
, "no", length
) == 0
1506 || strncmp (arg
, "disable", length
) == 0)
1507 return CMD_AUTO_BOOLEAN_FALSE
;
1508 else if (strncmp (arg
, "auto", length
) == 0
1509 || (strncmp (arg
, "-1", length
) == 0 && length
> 1))
1510 return CMD_AUTO_BOOLEAN_AUTO
;
1512 error ("\"on\", \"off\" or \"auto\" expected.");
1513 return CMD_AUTO_BOOLEAN_AUTO
; /* pacify GCC */
1517 parse_binary_operation (char *arg
)
1524 length
= strlen (arg
);
1526 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
1529 if (strncmp (arg
, "on", length
) == 0
1530 || strncmp (arg
, "1", length
) == 0
1531 || strncmp (arg
, "yes", length
) == 0
1532 || strncmp (arg
, "enable", length
) == 0)
1534 else if (strncmp (arg
, "off", length
) == 0
1535 || strncmp (arg
, "0", length
) == 0
1536 || strncmp (arg
, "no", length
) == 0
1537 || strncmp (arg
, "disable", length
) == 0)
1541 error ("\"on\" or \"off\" expected.");
1546 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1547 of the argument, and FROM_TTY is nonzero if this command is being entered
1548 directly by the user (i.e. these are just like any other
1549 command). C is the command list element for the command. */
1551 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
1553 if (c
->type
== set_cmd
)
1555 switch (c
->var_type
)
1566 new = (char *) xmalloc (strlen (arg
) + 2);
1569 while ((ch
= *p
++) != '\000')
1573 /* \ at end of argument is used after spaces
1574 so they won't be lost. */
1575 /* This is obsolete now that we no longer strip
1576 trailing whitespace and actually, the backslash
1577 didn't get here in my test, readline or
1578 something did something funky with a backslash
1579 right before a newline. */
1582 ch
= parse_escape (&p
);
1584 break; /* C loses */
1592 if (*(p
- 1) != '\\')
1596 new = (char *) xrealloc (new, q
- new);
1597 if (*(char **) c
->var
!= NULL
)
1598 free (*(char **) c
->var
);
1599 *(char **) c
->var
= new;
1602 case var_string_noescape
:
1605 if (*(char **) c
->var
!= NULL
)
1606 free (*(char **) c
->var
);
1607 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1611 error_no_arg ("filename to set it to.");
1612 if (*(char **) c
->var
!= NULL
)
1613 free (*(char **) c
->var
);
1614 *(char **) c
->var
= tilde_expand (arg
);
1617 *(int *) c
->var
= parse_binary_operation (arg
);
1619 case var_auto_boolean
:
1620 *(enum cmd_auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
1624 error_no_arg ("integer to set it to.");
1625 *(unsigned int *) c
->var
= parse_and_eval_address (arg
);
1626 if (*(unsigned int *) c
->var
== 0)
1627 *(unsigned int *) c
->var
= UINT_MAX
;
1633 error_no_arg ("integer to set it to.");
1634 val
= parse_and_eval_address (arg
);
1636 *(int *) c
->var
= INT_MAX
;
1637 else if (val
>= INT_MAX
)
1638 error ("integer %u out of range", val
);
1640 *(int *) c
->var
= val
;
1645 error_no_arg ("integer to set it to.");
1646 *(int *) c
->var
= parse_and_eval_address (arg
);
1653 const char *match
= NULL
;
1656 /* if no argument was supplied, print an informative error message */
1660 strcpy (msg
, "Requires an argument. Valid arguments are ");
1661 for (i
= 0; c
->enums
[i
]; i
++)
1665 strcat (msg
, c
->enums
[i
]);
1671 p
= strchr (arg
, ' ');
1679 for (i
= 0; c
->enums
[i
]; i
++)
1680 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
1682 if (c
->enums
[i
][len
] == '\0')
1684 match
= c
->enums
[i
];
1686 break; /* exact match. */
1690 match
= c
->enums
[i
];
1696 error ("Undefined item: \"%s\".", arg
);
1699 error ("Ambiguous item \"%s\".", arg
);
1701 *(const char **) c
->var
= match
;
1705 error ("gdb internal error: bad var_type in do_setshow_command");
1708 else if (c
->type
== show_cmd
)
1711 struct cleanup
*old_chain
;
1712 struct ui_stream
*stb
;
1715 stb
= ui_out_stream_new (uiout
);
1716 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1719 /* Print doc minus "show" at start. */
1720 print_doc_line (gdb_stdout
, c
->doc
+ 5);
1723 ui_out_text (uiout
, " is ");
1724 ui_out_wrap_hint (uiout
, " ");
1726 switch (c
->var_type
)
1732 if (*(unsigned char **) c
->var
)
1733 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
1737 case var_string_noescape
:
1740 if (*(char **) c
->var
)
1741 fputs_filtered (*(char **) c
->var
, stb
->stream
);
1745 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
1747 case var_auto_boolean
:
1748 switch (*(enum cmd_auto_boolean
*) c
->var
)
1750 case CMD_AUTO_BOOLEAN_TRUE
:
1751 fputs_filtered ("on", stb
->stream
);
1753 case CMD_AUTO_BOOLEAN_FALSE
:
1754 fputs_filtered ("off", stb
->stream
);
1756 case CMD_AUTO_BOOLEAN_AUTO
:
1757 fputs_filtered ("auto", stb
->stream
);
1760 internal_error ("do_setshow_command: invalid var_auto_boolean");
1765 if (*(unsigned int *) c
->var
== UINT_MAX
)
1767 fputs_filtered ("unlimited", stb
->stream
);
1770 /* else fall through */
1772 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
1775 if (*(int *) c
->var
== INT_MAX
)
1777 fputs_filtered ("unlimited", stb
->stream
);
1780 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
1784 error ("gdb internal error: bad var_type in do_setshow_command");
1787 ui_out_text (uiout
, "\"");
1788 ui_out_field_stream (uiout
, "value", stb
);
1790 ui_out_text (uiout
, "\"");
1791 ui_out_text (uiout
, ".\n");
1792 do_cleanups (old_chain
);
1794 fputs_filtered (" is ", gdb_stdout
);
1796 switch (c
->var_type
)
1800 fputs_filtered ("\"", gdb_stdout
);
1801 if (*(unsigned char **) c
->var
)
1802 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
1803 fputs_filtered ("\"", gdb_stdout
);
1806 case var_string_noescape
:
1809 fputs_filtered ("\"", gdb_stdout
);
1810 if (*(char **) c
->var
)
1811 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
1812 fputs_filtered ("\"", gdb_stdout
);
1815 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
1817 case var_auto_boolean
:
1818 switch (*(enum cmd_auto_boolean
*) c
->var
)
1820 case CMD_AUTO_BOOLEAN_TRUE
:
1821 fputs_filtered ("on", gdb_stdout
);
1823 case CMD_AUTO_BOOLEAN_FALSE
:
1824 fputs_filtered ("off", gdb_stdout
);
1826 case CMD_AUTO_BOOLEAN_AUTO
:
1827 fputs_filtered ("auto", gdb_stdout
);
1830 internal_error ("do_setshow_command: invalid var_auto_boolean");
1835 if (*(unsigned int *) c
->var
== UINT_MAX
)
1837 fputs_filtered ("unlimited", gdb_stdout
);
1840 /* else fall through */
1842 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
1845 if (*(int *) c
->var
== INT_MAX
)
1847 fputs_filtered ("unlimited", gdb_stdout
);
1850 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
1854 error ("gdb internal error: bad var_type in do_setshow_command");
1856 fputs_filtered (".\n", gdb_stdout
);
1860 error ("gdb internal error: bad cmd_type in do_setshow_command");
1861 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1862 if (c
->type
== set_cmd
&& set_hook
)
1866 /* Show all the settings in a list of show commands. */
1869 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
1872 ui_out_list_begin (uiout
, "showlist");
1874 for (; list
!= NULL
; list
= list
->next
)
1876 /* If we find a prefix, run its list, prefixing our output by its
1877 prefix (with "show " skipped). */
1879 if (list
->prefixlist
&& !list
->abbrev_flag
)
1881 ui_out_list_begin (uiout
, "optionlist");
1882 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
1883 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1884 ui_out_list_end (uiout
);
1886 if (list
->type
== show_cmd
)
1888 ui_out_list_begin (uiout
, "option");
1889 ui_out_text (uiout
, prefix
);
1890 ui_out_field_string (uiout
, "name", list
->name
);
1891 ui_out_text (uiout
, ": ");
1892 do_setshow_command ((char *) NULL
, from_tty
, list
);
1893 ui_out_list_end (uiout
);
1896 if (list
->prefixlist
&& !list
->abbrev_flag
)
1897 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1898 if (list
->type
== show_cmd
)
1900 fputs_filtered (prefix
, gdb_stdout
);
1901 fputs_filtered (list
->name
, gdb_stdout
);
1902 fputs_filtered (": ", gdb_stdout
);
1903 do_setshow_command ((char *) NULL
, from_tty
, list
);
1908 ui_out_list_end (uiout
);
1914 shell_escape (char *arg
, int from_tty
)
1917 /* If ARG is NULL, they want an inferior shell, but `system' just
1918 reports if the shell is available when passed a NULL arg. */
1919 int rc
= system (arg
? arg
: "");
1922 arg
= "inferior shell";
1926 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", arg
,
1927 safe_strerror (errno
));
1928 gdb_flush (gdb_stderr
);
1932 fprintf_unfiltered (gdb_stderr
, "%s exited with status %d\n", arg
, rc
);
1933 gdb_flush (gdb_stderr
);
1936 /* Make sure to return to the directory GDB thinks it is, in case the
1937 shell command we just ran changed it. */
1938 chdir (current_directory
);
1940 #else /* Can fork. */
1941 int rc
, status
, pid
;
1942 char *p
, *user_shell
;
1944 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1945 user_shell
= "/bin/sh";
1947 /* Get the name of the shell for arg0 */
1948 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1951 p
++; /* Get past '/' */
1953 if ((pid
= fork ()) == 0)
1956 execl (user_shell
, p
, 0);
1958 execl (user_shell
, p
, "-c", arg
, 0);
1960 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", user_shell
,
1961 safe_strerror (errno
));
1962 gdb_flush (gdb_stderr
);
1967 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1970 error ("Fork failed");
1971 #endif /* Can fork. */
1975 make_command (char *arg
, int from_tty
)
1983 p
= xmalloc (sizeof ("make ") + strlen (arg
));
1984 strcpy (p
, "make ");
1985 strcpy (p
+ sizeof ("make ") - 1, arg
);
1988 shell_escape (p
, from_tty
);
1992 show_user_1 (struct cmd_list_element
*c
, struct ui_file
*stream
)
1994 register struct command_line
*cmdlines
;
1996 cmdlines
= c
->user_commands
;
1999 fputs_filtered ("User command ", stream
);
2000 fputs_filtered (c
->name
, stream
);
2001 fputs_filtered (":\n", stream
);
2004 print_command_lines (uiout
, cmdlines
, 1);
2005 fputs_filtered ("\n", stream
);
2009 print_command_line (cmdlines
, 4, stream
);
2010 cmdlines
= cmdlines
->next
;
2012 fputs_filtered ("\n", stream
);
2018 show_user (char *args
, int from_tty
)
2020 struct cmd_list_element
*c
;
2021 extern struct cmd_list_element
*cmdlist
;
2025 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
2026 if (c
->class != class_user
)
2027 error ("Not a user command.");
2028 show_user_1 (c
, gdb_stdout
);
2032 for (c
= cmdlist
; c
; c
= c
->next
)
2034 if (c
->class == class_user
)
2035 show_user_1 (c
, gdb_stdout
);
2041 _initialize_command (void)
2043 add_com ("shell", class_support
, shell_escape
,
2044 "Execute the rest of the line as a shell command. \n\
2045 With no arguments, run an inferior shell.");
2047 /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
2048 be a really useful feature. Unfortunatly, the below wont do
2049 this. Instead it adds support for the form ``(gdb) ! ls''
2050 (i.e. the space is required). If the ``!'' command below is
2051 added the complains about no ``!'' command would be replaced by
2052 complains about how the ``!'' command is broken :-) */
2054 add_com_alias ("!", "shell", class_support
, 0);
2056 add_com ("make", class_support
, make_command
,
2057 "Run the ``make'' program using the rest of the line as arguments.");
2058 add_cmd ("user", no_class
, show_user
,
2059 "Show definitions of user defined commands.\n\
2060 Argument is the name of the user defined command.\n\
2061 With no argument, show definitions of all user defined commands.", &showlist
);
2062 add_com ("apropos", class_support
, apropos_command
, "Search for commands matching a REGEXP");