1 /* Handle lists of commands, their decoding and documentation, for GDB.
2 Copyright 1986, 1989, 1990, 1991, 1998, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "gnu-regex.h"
31 /* FIXME: this should be auto-configured! */
36 /* Prototypes for local functions */
38 static void undef_cmd_error (char *, char *);
40 static void show_user (char *, int);
42 static void show_user_1 (struct cmd_list_element
*, struct ui_file
*);
44 static void make_command (char *, int);
46 static void shell_escape (char *, int);
48 static int parse_binary_operation (char *);
50 static void print_doc_line (struct ui_file
*, char *);
52 static struct cmd_list_element
*find_cmd (char *command
,
54 struct cmd_list_element
*clist
,
55 int ignore_help_classes
,
57 static void apropos_cmd_helper (struct ui_file
*, struct cmd_list_element
*,
58 struct re_pattern_buffer
*, char *);
60 static void help_all (struct ui_file
*stream
);
62 void apropos_command (char *, int);
64 void _initialize_command (void);
66 /* Add element named NAME.
67 CLASS is the top level category into which commands are broken down
69 FUN should be the function to execute the command;
70 it will get a character string as argument, with leading
71 and trailing blanks already eliminated.
73 DOC is a documentation string for the command.
74 Its first line should be a complete sentence.
75 It should start with ? for a command that is an abbreviation
76 or with * for a command that most users don't need to know about.
78 Add this command to command list *LIST.
80 Returns a pointer to the added command (not necessarily the head
83 struct cmd_list_element
*
84 add_cmd (name
, class, fun
, doc
, list
)
86 enum command_class
class;
87 void (*fun
) (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 (struct cmd_list_element
*cmd
, char *replacement
)
150 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
152 if (replacement
!= NULL
)
153 cmd
->replacement
= replacement
;
155 cmd
->replacement
= NULL
;
161 /* Same as above, except that the abbrev_flag is set. */
163 #if 0 /* Currently unused */
165 struct cmd_list_element
*
166 add_abbrev_cmd (name
, class, fun
, doc
, list
)
168 enum command_class
class;
169 void (*fun
) (char *, int);
171 struct cmd_list_element
**list
;
173 register struct cmd_list_element
*c
174 = add_cmd (name
, class, fun
, doc
, list
);
182 struct cmd_list_element
*
183 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
184 int abbrev_flag
, struct cmd_list_element
**list
)
186 /* Must do this since lookup_cmd tries to side-effect its first arg */
188 register struct cmd_list_element
*old
;
189 register struct cmd_list_element
*c
;
190 copied_name
= (char *) alloca (strlen (oldname
) + 1);
191 strcpy (copied_name
, oldname
);
192 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
196 delete_cmd (name
, list
);
200 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
201 c
->prefixlist
= old
->prefixlist
;
202 c
->prefixname
= old
->prefixname
;
203 c
->allow_unknown
= old
->allow_unknown
;
204 c
->abbrev_flag
= abbrev_flag
;
205 c
->cmd_pointer
= old
;
209 /* Like add_cmd but adds an element for a command prefix:
210 a name that should be followed by a subcommand to be looked up
211 in another command list. PREFIXLIST should be the address
212 of the variable containing that list. */
214 struct cmd_list_element
*
215 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
218 enum command_class
class;
219 void (*fun
) (char *, int);
221 struct cmd_list_element
**prefixlist
;
224 struct cmd_list_element
**list
;
226 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
227 c
->prefixlist
= prefixlist
;
228 c
->prefixname
= prefixname
;
229 c
->allow_unknown
= allow_unknown
;
233 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
235 struct cmd_list_element
*
236 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
239 enum command_class
class;
240 void (*fun
) (char *, int);
242 struct cmd_list_element
**prefixlist
;
245 struct cmd_list_element
**list
;
247 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
248 c
->prefixlist
= prefixlist
;
249 c
->prefixname
= prefixname
;
250 c
->allow_unknown
= allow_unknown
;
255 /* This is an empty "cfunc". */
257 not_just_help_class_command (char *args
, int from_tty
)
261 /* This is an empty "sfunc". */
262 static void empty_sfunc (char *, int, struct cmd_list_element
*);
265 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
269 /* Add element named NAME to command list LIST (the list for set
270 or some sublist thereof).
271 CLASS is as in add_cmd.
272 VAR_TYPE is the kind of thing we are setting.
273 VAR is address of the variable being controlled by this command.
274 DOC is the documentation string. */
276 struct cmd_list_element
*
277 add_set_cmd (char *name
,
278 enum command_class
class,
282 struct cmd_list_element
**list
)
284 struct cmd_list_element
*c
285 = add_cmd (name
, class, NO_FUNCTION
, doc
, list
);
288 c
->var_type
= var_type
;
290 /* This needs to be something besides NO_FUNCTION so that this isn't
291 treated as a help class. */
292 c
->function
.sfunc
= empty_sfunc
;
296 /* Add element named NAME to command list LIST (the list for set
297 or some sublist thereof).
298 CLASS is as in add_cmd.
299 ENUMLIST is a list of strings which may follow NAME.
300 VAR is address of the variable which will contain the matching string
302 DOC is the documentation string. */
304 struct cmd_list_element
*
305 add_set_enum_cmd (char *name
,
306 enum command_class
class,
307 const char *enumlist
[],
310 struct cmd_list_element
**list
)
312 struct cmd_list_element
*c
313 = add_set_cmd (name
, class, var_enum
, var
, doc
, list
);
319 /* Add element named NAME to command list LIST (the list for set
320 or some sublist thereof).
321 CLASS is as in add_cmd.
322 VAR is address of the variable which will contain the value.
323 DOC is the documentation string. */
324 struct cmd_list_element
*
325 add_set_auto_boolean_cmd (char *name
,
326 enum command_class
class,
327 enum cmd_auto_boolean
*var
,
329 struct cmd_list_element
**list
)
331 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
332 struct cmd_list_element
*c
;
333 c
= add_set_cmd (name
, class, var_auto_boolean
, var
, doc
, list
);
334 c
->enums
= auto_boolean_enums
;
338 /* Where SETCMD has already been added, add the corresponding show
339 command to LIST and return a pointer to the added command (not
340 necessarily the head of LIST). */
341 struct cmd_list_element
*
342 add_show_from_set (struct cmd_list_element
*setcmd
,
343 struct cmd_list_element
**list
)
345 struct cmd_list_element
*showcmd
=
346 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
347 struct cmd_list_element
*p
;
349 memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
350 delete_cmd (showcmd
->name
, list
);
351 showcmd
->type
= show_cmd
;
353 /* Replace "set " at start of docstring with "show ". */
354 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
355 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
356 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
358 fprintf_unfiltered (gdb_stderr
, "GDB internal error: Bad docstring for set command\n");
360 if (*list
== NULL
|| STRCMP ((*list
)->name
, showcmd
->name
) >= 0)
362 showcmd
->next
= *list
;
368 while (p
->next
&& STRCMP (p
->next
->name
, showcmd
->name
) <= 0)
372 showcmd
->next
= p
->next
;
379 /* Remove the command named NAME from the command list. */
382 delete_cmd (char *name
, struct cmd_list_element
**list
)
384 register struct cmd_list_element
*c
;
385 struct cmd_list_element
*p
;
387 while (*list
&& STREQ ((*list
)->name
, name
))
390 (*list
)->hookee
->hook
= 0; /* Hook slips out of its mouth */
397 for (c
= *list
; c
->next
;)
399 if (STREQ (c
->next
->name
, name
))
402 c
->next
->hookee
->hook
= 0; /* hooked cmd gets away. */
404 free ((PTR
) c
->next
);
411 /* Recursively walk the commandlist structures, and print out the
412 documentation of commands that match our regex in either their
413 name, or their documentation.
416 apropos_cmd_helper (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
417 struct re_pattern_buffer
*regex
, char *prefix
)
419 register struct cmd_list_element
*c
;
420 int returnvalue
=1; /*Needed to avoid double printing*/
421 /* Walk through the commands */
422 for (c
=commandlist
;c
;c
=c
->next
)
426 /* Try to match against the name*/
427 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
428 if (returnvalue
>= 0)
430 /* Stolen from help_cmd_list. We don't directly use
431 * help_cmd_list because it doesn't let us print out
434 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
435 print_doc_line (stream
, c
->doc
);
436 fputs_filtered ("\n", stream
);
437 returnvalue
=0; /*Set this so we don't print it again.*/
440 if (c
->doc
!= NULL
&& returnvalue
!= 0)
442 /* Try to match against documentation */
443 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
445 /* Stolen from help_cmd_list. We don't directly use
446 * help_cmd_list because it doesn't let us print out
449 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
450 print_doc_line (stream
, c
->doc
);
451 fputs_filtered ("\n", stream
);
454 /* Check if this command has subcommands */
455 if (c
->prefixlist
!= NULL
)
457 /* Recursively call ourselves on the subcommand list,
458 passing the right prefix in.
460 apropos_cmd_helper(stream
,*c
->prefixlist
,regex
,c
->prefixname
);
464 /* Search through names of commands and documentations for a certain
468 apropos_command (char *searchstr
, int from_tty
)
470 extern struct cmd_list_element
*cmdlist
; /*This is the main command list*/
472 char *pattern_fastmap
;
473 char errorbuffer
[512];
474 pattern_fastmap
=calloc(256,sizeof(char));
475 if (searchstr
== NULL
)
476 error("REGEXP string is empty");
478 if (regcomp(&pattern
,searchstr
,REG_ICASE
) == 0)
480 pattern
.fastmap
=pattern_fastmap
;
481 re_compile_fastmap(&pattern
);
482 apropos_cmd_helper(gdb_stdout
,cmdlist
,&pattern
,"");
486 regerror(regcomp(&pattern
,searchstr
,REG_ICASE
),NULL
,errorbuffer
,512);
487 error("Error in regular expression:%s",errorbuffer
);
489 free(pattern_fastmap
);
493 /* This command really has to deal with two things:
494 * 1) I want documentation on *this string* (usually called by
495 * "help commandname").
496 * 2) I want documentation on *this list* (usually called by
497 * giving a command that requires subcommands. Also called by saying
500 * I am going to split this into two seperate comamnds, help_cmd and
505 help_cmd (char *command
, struct ui_file
*stream
)
507 struct cmd_list_element
*c
;
508 extern struct cmd_list_element
*cmdlist
;
512 help_list (cmdlist
, "", all_classes
, stream
);
516 if (strcmp (command
, "all") == 0)
522 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
527 /* There are three cases here.
528 If c->prefixlist is nonzero, we have a prefix command.
529 Print its documentation, then list its subcommands.
531 If c->function is nonzero, we really have a command.
532 Print its documentation and return.
534 If c->function is zero, we have a class name.
535 Print its documentation (as if it were a command)
536 and then set class to the number of this class
537 so that the commands in the class will be listed. */
539 fputs_filtered (c
->doc
, stream
);
540 fputs_filtered ("\n", stream
);
542 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
544 fprintf_filtered (stream
, "\n");
546 /* If this is a prefix command, print it's subcommands */
548 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
550 /* If this is a class name, print all of the commands in the class */
551 if (c
->function
.cfunc
== NULL
)
552 help_list (cmdlist
, "", c
->class, stream
);
555 fprintf_filtered (stream
, "\nThis command has a hook defined: %s\n",
560 * Get a specific kind of help on a command list.
563 * CMDTYPE is the prefix to use in the title string.
564 * CLASS is the class with which to list the nodes of this list (see
565 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
566 * everything, ALL_CLASSES for just classes, and non-negative for only things
567 * in a specific class.
568 * and STREAM is the output stream on which to print things.
569 * If you call this routine with a class >= 0, it recurses.
572 help_list (struct cmd_list_element
*list
, char *cmdtype
,
573 enum command_class
class, struct ui_file
*stream
)
576 char *cmdtype1
, *cmdtype2
;
578 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
579 len
= strlen (cmdtype
);
580 cmdtype1
= (char *) alloca (len
+ 1);
582 cmdtype2
= (char *) alloca (len
+ 4);
587 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
589 strncpy (cmdtype2
, cmdtype
, len
- 1);
590 strcpy (cmdtype2
+ len
- 1, " sub");
593 if (class == all_classes
)
594 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
596 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
598 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
600 if (class == all_classes
)
601 fprintf_filtered (stream
, "\n\
602 Type \"help%s\" followed by a class name for a list of commands in that class.",
605 fprintf_filtered (stream
, "\n\
606 Type \"help%s\" followed by %scommand name for full documentation.\n\
607 Command name abbreviations are allowed if unambiguous.\n",
612 help_all (struct ui_file
*stream
)
614 struct cmd_list_element
*c
;
615 extern struct cmd_list_element
*cmdlist
;
617 for (c
= cmdlist
; c
; c
= c
->next
)
621 /* If this is a prefix command, print it's subcommands */
623 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 0, stream
);
625 /* If this is a class name, print all of the commands in the class */
626 else if (c
->function
.cfunc
== NULL
)
627 help_cmd_list (cmdlist
, c
->class, "", 0, stream
);
631 /* Print only the first line of STR on STREAM. */
633 print_doc_line (struct ui_file
*stream
, char *str
)
635 static char *line_buffer
= 0;
636 static int line_size
;
642 line_buffer
= (char *) xmalloc (line_size
);
646 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
648 if (p
- str
> line_size
- 1)
650 line_size
= p
- str
+ 1;
651 free ((PTR
) line_buffer
);
652 line_buffer
= (char *) xmalloc (line_size
);
654 strncpy (line_buffer
, str
, p
- str
);
655 line_buffer
[p
- str
] = '\0';
656 if (islower (line_buffer
[0]))
657 line_buffer
[0] = toupper (line_buffer
[0]);
659 ui_out_text (uiout
, line_buffer
);
661 fputs_filtered (line_buffer
, stream
);
666 * Implement a help command on command list LIST.
667 * RECURSE should be non-zero if this should be done recursively on
668 * all sublists of LIST.
669 * PREFIX is the prefix to print before each command name.
670 * STREAM is the stream upon which the output should be written.
672 * A non-negative class number to list only commands in that
674 * ALL_COMMANDS to list all commands in list.
675 * ALL_CLASSES to list all classes in list.
677 * Note that RECURSE will be active on *all* sublists, not just the
678 * ones selected by the criteria above (ie. the selection mechanism
679 * is at the low level, not the high-level).
682 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
683 char *prefix
, int recurse
, struct ui_file
*stream
)
685 register struct cmd_list_element
*c
;
687 for (c
= list
; c
; c
= c
->next
)
689 if (c
->abbrev_flag
== 0 &&
690 (class == all_commands
691 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
692 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
694 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
695 print_doc_line (stream
, c
->doc
);
696 fputs_filtered ("\n", stream
);
699 && c
->prefixlist
!= 0
700 && c
->abbrev_flag
== 0)
701 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
706 /* Search the input clist for 'command'. Return the command if
707 found (or NULL if not), and return the number of commands
710 static struct cmd_list_element
*
711 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
712 int ignore_help_classes
, int *nfound
)
714 struct cmd_list_element
*found
, *c
;
716 found
= (struct cmd_list_element
*) NULL
;
718 for (c
= clist
; c
; c
= c
->next
)
719 if (!strncmp (command
, c
->name
, len
)
720 && (!ignore_help_classes
|| c
->function
.cfunc
))
724 if (c
->name
[len
] == '\0')
733 /* This routine takes a line of TEXT and a CLIST in which to start the
734 lookup. When it returns it will have incremented the text pointer past
735 the section of text it matched, set *RESULT_LIST to point to the list in
736 which the last word was matched, and will return a pointer to the cmd
737 list element which the text matches. It will return NULL if no match at
738 all was possible. It will return -1 (cast appropriately, ick) if ambigous
739 matches are possible; in this case *RESULT_LIST will be set to point to
740 the list in which there are ambiguous choices (and *TEXT will be set to
741 the ambiguous text string).
743 If the located command was an abbreviation, this routine returns the base
744 command of the abbreviation.
746 It does no error reporting whatsoever; control will always return
747 to the superior routine.
749 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
750 at the prefix_command (ie. the best match) *or* (special case) will be NULL
751 if no prefix command was ever found. For example, in the case of "info a",
752 "info" matches without ambiguity, but "a" could be "args" or "address", so
753 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
754 RESULT_LIST should not be interpeted as a pointer to the beginning of a
755 list; it simply points to a specific command. In the case of an ambiguous
756 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
757 "info t" can be "info types" or "info target"; upon return *TEXT has been
758 advanced past "info ").
760 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
761 affect the operation).
763 This routine does *not* modify the text pointed to by TEXT.
765 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
766 are actually help classes rather than commands (i.e. the function field of
767 the struct cmd_list_element is NULL). */
769 struct cmd_list_element
*
770 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
771 struct cmd_list_element
**result_list
, int ignore_help_classes
)
774 int len
, tmp
, nfound
;
775 struct cmd_list_element
*found
, *c
;
778 while (**text
== ' ' || **text
== '\t')
781 /* Treating underscores as part of command words is important
782 so that "set args_foo()" doesn't get interpreted as
783 "set args _foo()". */
785 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
787 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
788 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
792 /* If nothing but whitespace, return 0. */
798 /* *text and p now bracket the first command word to lookup (and
799 it's length is len). We copy this into a local temporary */
802 command
= (char *) alloca (len
+ 1);
803 for (tmp
= 0; tmp
< len
; tmp
++)
805 char x
= (*text
)[tmp
];
813 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
816 ** We didn't find the command in the entered case, so lower case it
819 if (!found
|| nfound
== 0)
821 for (tmp
= 0; tmp
< len
; tmp
++)
823 char x
= command
[tmp
];
824 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
826 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
829 /* If nothing matches, we have a simple failure. */
835 if (result_list
!= NULL
)
836 /* Will be modified in calling routine
837 if we know what the prefix command is. */
839 return (struct cmd_list_element
*) -1; /* Ambiguous. */
842 /* We've matched something on this list. Move text pointer forward. */
846 if (found
->cmd_pointer
)
848 /* We drop the alias (abbreviation) in favor of the command it is
849 pointing to. If the alias is deprecated, though, we need to
850 warn the user about it before we drop it. Note that while we
851 are warning about the alias, we may also warn about the command
852 itself and we will adjust the appropriate DEPRECATED_WARN_USER
855 if (found
->flags
& DEPRECATED_WARN_USER
)
856 deprecated_cmd_warning (&line
);
857 found
= found
->cmd_pointer
;
859 /* If we found a prefix command, keep looking. */
861 if (found
->prefixlist
)
863 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
864 ignore_help_classes
);
867 /* Didn't find anything; this is as far as we got. */
868 if (result_list
!= NULL
)
869 *result_list
= clist
;
872 else if (c
== (struct cmd_list_element
*) -1)
874 /* We've gotten this far properly, but the next step
875 is ambiguous. We need to set the result list to the best
876 we've found (if an inferior hasn't already set it). */
877 if (result_list
!= NULL
)
879 /* This used to say *result_list = *found->prefixlist
880 If that was correct, need to modify the documentation
881 at the top of this function to clarify what is supposed
883 *result_list
= found
;
894 if (result_list
!= NULL
)
895 *result_list
= clist
;
900 /* All this hair to move the space to the front of cmdtype */
903 undef_cmd_error (char *cmdtype
, char *q
)
905 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
909 strlen (cmdtype
) - 1,
913 /* Look up the contents of *LINE as a command in the command list LIST.
914 LIST is a chain of struct cmd_list_element's.
915 If it is found, return the struct cmd_list_element for that command
916 and update *LINE to point after the command name, at the first argument.
917 If not found, call error if ALLOW_UNKNOWN is zero
918 otherwise (or if error returns) return zero.
919 Call error if specified command is ambiguous,
920 unless ALLOW_UNKNOWN is negative.
921 CMDTYPE precedes the word "command" in the error message.
923 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
924 elements which are actually help classes rather than commands (i.e.
925 the function field of the struct cmd_list_element is 0). */
927 struct cmd_list_element
*
928 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
929 int allow_unknown
, int ignore_help_classes
)
931 struct cmd_list_element
*last_list
= 0;
932 struct cmd_list_element
*c
=
933 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
935 /* This is wrong for complete_command. */
936 char *ptr
= (*line
) + strlen (*line
) - 1;
938 /* Clear off trailing whitespace. */
939 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
949 error ("Lack of needed %scommand", cmdtype
);
954 while (isalnum (*p
) || *p
== '-')
957 q
= (char *) alloca (p
- *line
+ 1);
958 strncpy (q
, *line
, p
- *line
);
960 undef_cmd_error (cmdtype
, q
);
966 else if (c
== (struct cmd_list_element
*) -1)
968 /* Ambigous. Local values should be off prefixlist or called
970 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
972 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
973 struct cmd_list_element
*local_list
=
974 (last_list
? *(last_list
->prefixlist
) : list
);
976 if (local_allow_unknown
< 0)
979 return last_list
; /* Found something. */
981 return 0; /* Found nothing. */
985 /* Report as error. */
990 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
991 && (*line
)[amb_len
] != '\t');
996 for (c
= local_list
; c
; c
= c
->next
)
997 if (!strncmp (*line
, c
->name
, amb_len
))
999 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1001 if (strlen (ambbuf
))
1002 strcat (ambbuf
, ", ");
1003 strcat (ambbuf
, c
->name
);
1007 strcat (ambbuf
, "..");
1011 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
1013 return 0; /* lint */
1018 /* We've got something. It may still not be what the caller
1019 wants (if this command *needs* a subcommand). */
1020 while (**line
== ' ' || **line
== '\t')
1023 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1024 undef_cmd_error (c
->prefixname
, *line
);
1026 /* Seems to be what he wants. Return it. */
1032 /* We are here presumably because an alias or command in *TEXT is
1033 deprecated and a warning message should be generated. This function
1034 decodes *TEXT and potentially generates a warning message as outlined
1037 Example for 'set endian big' which has a fictitious alias 'seb'.
1039 If alias wasn't used in *TEXT, and the command is deprecated:
1040 "warning: 'set endian big' is deprecated."
1042 If alias was used, and only the alias is deprecated:
1043 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1045 If alias was used and command is deprecated (regardless of whether the
1046 alias itself is deprecated:
1048 "warning: 'set endian big' (seb) is deprecated."
1050 After the message has been sent, clear the appropriate flags in the
1051 command and/or the alias so the user is no longer bothered.
1055 deprecated_cmd_warning (char **text
)
1057 struct cmd_list_element
*alias
= NULL
;
1058 struct cmd_list_element
*prefix_cmd
= NULL
;
1059 struct cmd_list_element
*cmd
= NULL
;
1060 struct cmd_list_element
*c
;
1063 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1064 /* return if text doesn't evaluate to a command */
1067 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1068 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1069 /* return if nothing is deprecated */
1072 printf_filtered ("Warning:");
1074 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1075 printf_filtered (" '%s', an alias for the", alias
->name
);
1077 printf_filtered (" command '");
1080 printf_filtered ("%s", prefix_cmd
->prefixname
);
1082 printf_filtered ("%s", cmd
->name
);
1084 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1085 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1087 printf_filtered ("' is deprecated.\n");
1090 /* if it is only the alias that is deprecated, we want to indicate the
1091 new alias, otherwise we'll indicate the new command */
1093 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1095 if (alias
->replacement
)
1096 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1098 printf_filtered ("No alternative known.\n\n");
1102 if (cmd
->replacement
)
1103 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1105 printf_filtered ("No alternative known.\n\n");
1108 /* We've warned you, now we'll keep quiet */
1110 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1112 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1117 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1118 Return 1 on success, 0 on failure.
1120 If LINE refers to an alias, *alias will point to that alias.
1122 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1123 command) set *prefix_cmd.
1125 Set *cmd to point to the command LINE indicates.
1127 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1128 exist, they are NULL when we return.
1132 lookup_cmd_composition (char *text
,
1133 struct cmd_list_element
**alias
,
1134 struct cmd_list_element
**prefix_cmd
,
1135 struct cmd_list_element
**cmd
)
1138 int len
, tmp
, nfound
;
1139 struct cmd_list_element
*cur_list
;
1140 struct cmd_list_element
*prev_cmd
;
1149 /* Go through as many command lists as we need to
1150 to find the command TEXT refers to. */
1154 while (*text
== ' ' || *text
== '\t')
1157 /* Treating underscores as part of command words is important
1158 so that "set args_foo()" doesn't get interpreted as
1159 "set args _foo()". */
1161 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1163 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
1164 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
1168 /* If nothing but whitespace, return. */
1174 /* text and p now bracket the first command word to lookup (and
1175 it's length is len). We copy this into a local temporary */
1177 command
= (char *) alloca (len
+ 1);
1178 for (tmp
= 0; tmp
< len
; tmp
++)
1183 command
[len
] = '\0';
1188 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1190 /* We didn't find the command in the entered case, so lower case it
1193 if (!*cmd
|| nfound
== 0)
1195 for (tmp
= 0; tmp
< len
; tmp
++)
1197 char x
= command
[tmp
];
1198 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1200 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1203 if (*cmd
== (struct cmd_list_element
*) -1)
1205 return 0; /* ambiguous */
1209 return 0; /* nothing found */
1212 if ((*cmd
)->cmd_pointer
)
1214 /* cmd was actually an alias, we note that an alias was used
1215 (by assigning *alais) and we set *cmd.
1218 *cmd
= (*cmd
)->cmd_pointer
;
1220 *prefix_cmd
= prev_cmd
;
1222 if ((*cmd
)->prefixlist
)
1223 cur_list
= *(*cmd
)->prefixlist
;
1235 /* Look up the contents of *LINE as a command in the command list LIST.
1236 LIST is a chain of struct cmd_list_element's.
1237 If it is found, return the struct cmd_list_element for that command
1238 and update *LINE to point after the command name, at the first argument.
1239 If not found, call error if ALLOW_UNKNOWN is zero
1240 otherwise (or if error returns) return zero.
1241 Call error if specified command is ambiguous,
1242 unless ALLOW_UNKNOWN is negative.
1243 CMDTYPE precedes the word "command" in the error message. */
1245 struct cmd_list_element
*
1246 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1250 register struct cmd_list_element
*c
, *found
;
1253 char *processed_cmd
;
1256 /* Skip leading whitespace. */
1258 while (**line
== ' ' || **line
== '\t')
1261 /* Clear out trailing whitespace. */
1263 p
= *line
+ strlen (*line
);
1264 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1268 /* Find end of command name. */
1271 while (*p
== '-' || isalnum (*p
))
1274 /* Look up the command name.
1275 If exact match, keep that.
1276 Otherwise, take command abbreviated, if unique. Note that (in my
1277 opinion) a null string does *not* indicate ambiguity; simply the
1278 end of the argument. */
1283 error ("Lack of needed %scommand", cmdtype
);
1287 /* Copy over to a local buffer, converting to lowercase on the way.
1288 This is in case the command being parsed is a subcommand which
1289 doesn't match anything, and that's ok. We want the original
1290 untouched for the routine of the original command. */
1292 processed_cmd
= (char *) alloca (p
- *line
+ 1);
1293 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
1295 char x
= (*line
)[cmd_len
];
1297 processed_cmd
[cmd_len
] = tolower (x
);
1299 processed_cmd
[cmd_len
] = x
;
1301 processed_cmd
[cmd_len
] = '\0';
1303 /* Check all possibilities in the current command list. */
1306 for (c
= list
; c
; c
= c
->next
)
1308 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1312 if (c
->name
[cmd_len
] == 0)
1320 /* Report error for undefined command name. */
1324 if (nfound
> 1 && allow_unknown
>= 0)
1327 for (c
= list
; c
; c
= c
->next
)
1328 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1330 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
1332 if (strlen (ambbuf
))
1333 strcat (ambbuf
, ", ");
1334 strcat (ambbuf
, c
->name
);
1338 strcat (ambbuf
, "..");
1342 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
1343 processed_cmd
, ambbuf
);
1345 else if (!allow_unknown
)
1346 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
1350 /* Skip whitespace before the argument. */
1352 while (*p
== ' ' || *p
== '\t')
1356 if (found
->prefixlist
&& *p
)
1358 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
1359 found
->allow_unknown
);
1368 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1370 /* Return a vector of char pointers which point to the different
1371 possible completions in LIST of TEXT.
1373 WORD points in the same buffer as TEXT, and completions should be
1374 returned relative to this position. For example, suppose TEXT is "foo"
1375 and we want to complete to "foobar". If WORD is "oo", return
1376 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1379 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1381 struct cmd_list_element
*ptr
;
1383 int sizeof_matchlist
;
1385 int textlen
= strlen (text
);
1387 sizeof_matchlist
= 10;
1388 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1391 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1392 if (!strncmp (ptr
->name
, text
, textlen
)
1393 && !ptr
->abbrev_flag
1394 && (ptr
->function
.cfunc
1395 || ptr
->prefixlist
))
1397 if (matches
== sizeof_matchlist
)
1399 sizeof_matchlist
*= 2;
1400 matchlist
= (char **) xrealloc ((char *) matchlist
,
1402 * sizeof (char *)));
1405 matchlist
[matches
] = (char *)
1406 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1408 strcpy (matchlist
[matches
], ptr
->name
);
1409 else if (word
> text
)
1411 /* Return some portion of ptr->name. */
1412 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1416 /* Return some of text plus ptr->name. */
1417 strncpy (matchlist
[matches
], word
, text
- word
);
1418 matchlist
[matches
][text
- word
] = '\0';
1419 strcat (matchlist
[matches
], ptr
->name
);
1426 free ((PTR
) matchlist
);
1431 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1432 * sizeof (char *)));
1433 matchlist
[matches
] = (char *) 0;
1439 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1441 /* Return a vector of char pointers which point to the different
1442 possible completions in CMD of TEXT.
1444 WORD points in the same buffer as TEXT, and completions should be
1445 returned relative to this position. For example, suppose TEXT is "foo"
1446 and we want to complete to "foobar". If WORD is "oo", return
1447 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1450 complete_on_enum (const char *enumlist
[],
1455 int sizeof_matchlist
;
1457 int textlen
= strlen (text
);
1461 sizeof_matchlist
= 10;
1462 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1465 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1466 if (strncmp (name
, text
, textlen
) == 0)
1468 if (matches
== sizeof_matchlist
)
1470 sizeof_matchlist
*= 2;
1471 matchlist
= (char **) xrealloc ((char *) matchlist
,
1473 * sizeof (char *)));
1476 matchlist
[matches
] = (char *)
1477 xmalloc (strlen (word
) + strlen (name
) + 1);
1479 strcpy (matchlist
[matches
], name
);
1480 else if (word
> text
)
1482 /* Return some portion of name. */
1483 strcpy (matchlist
[matches
], name
+ (word
- text
));
1487 /* Return some of text plus name. */
1488 strncpy (matchlist
[matches
], word
, text
- word
);
1489 matchlist
[matches
][text
- word
] = '\0';
1490 strcat (matchlist
[matches
], name
);
1497 free ((PTR
) matchlist
);
1502 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1503 * sizeof (char *)));
1504 matchlist
[matches
] = (char *) 0;
1510 static enum cmd_auto_boolean
1511 parse_auto_binary_operation (const char *arg
)
1513 if (arg
!= NULL
&& *arg
!= '\0')
1515 int length
= strlen (arg
);
1516 while (isspace (arg
[length
- 1]) && length
> 0)
1518 if (strncmp (arg
, "on", length
) == 0
1519 || strncmp (arg
, "1", length
) == 0
1520 || strncmp (arg
, "yes", length
) == 0
1521 || strncmp (arg
, "enable", length
) == 0)
1522 return CMD_AUTO_BOOLEAN_TRUE
;
1523 else if (strncmp (arg
, "off", length
) == 0
1524 || strncmp (arg
, "0", length
) == 0
1525 || strncmp (arg
, "no", length
) == 0
1526 || strncmp (arg
, "disable", length
) == 0)
1527 return CMD_AUTO_BOOLEAN_FALSE
;
1528 else if (strncmp (arg
, "auto", length
) == 0
1529 || (strncmp (arg
, "-1", length
) == 0 && length
> 1))
1530 return CMD_AUTO_BOOLEAN_AUTO
;
1532 error ("\"on\", \"off\" or \"auto\" expected.");
1533 return CMD_AUTO_BOOLEAN_AUTO
; /* pacify GCC */
1537 parse_binary_operation (char *arg
)
1544 length
= strlen (arg
);
1546 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
1549 if (strncmp (arg
, "on", length
) == 0
1550 || strncmp (arg
, "1", length
) == 0
1551 || strncmp (arg
, "yes", length
) == 0
1552 || strncmp (arg
, "enable", length
) == 0)
1554 else if (strncmp (arg
, "off", length
) == 0
1555 || strncmp (arg
, "0", length
) == 0
1556 || strncmp (arg
, "no", length
) == 0
1557 || strncmp (arg
, "disable", length
) == 0)
1561 error ("\"on\" or \"off\" expected.");
1566 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1567 of the argument, and FROM_TTY is nonzero if this command is being entered
1568 directly by the user (i.e. these are just like any other
1569 command). C is the command list element for the command. */
1571 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
1573 if (c
->type
== set_cmd
)
1575 switch (c
->var_type
)
1586 new = (char *) xmalloc (strlen (arg
) + 2);
1589 while ((ch
= *p
++) != '\000')
1593 /* \ at end of argument is used after spaces
1594 so they won't be lost. */
1595 /* This is obsolete now that we no longer strip
1596 trailing whitespace and actually, the backslash
1597 didn't get here in my test, readline or
1598 something did something funky with a backslash
1599 right before a newline. */
1602 ch
= parse_escape (&p
);
1604 break; /* C loses */
1612 if (*(p
- 1) != '\\')
1616 new = (char *) xrealloc (new, q
- new);
1617 if (*(char **) c
->var
!= NULL
)
1618 free (*(char **) c
->var
);
1619 *(char **) c
->var
= new;
1622 case var_string_noescape
:
1625 if (*(char **) c
->var
!= NULL
)
1626 free (*(char **) c
->var
);
1627 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1631 error_no_arg ("filename to set it to.");
1632 if (*(char **) c
->var
!= NULL
)
1633 free (*(char **) c
->var
);
1634 *(char **) c
->var
= tilde_expand (arg
);
1637 *(int *) c
->var
= parse_binary_operation (arg
);
1639 case var_auto_boolean
:
1640 *(enum cmd_auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
1644 error_no_arg ("integer to set it to.");
1645 *(unsigned int *) c
->var
= parse_and_eval_address (arg
);
1646 if (*(unsigned int *) c
->var
== 0)
1647 *(unsigned int *) c
->var
= UINT_MAX
;
1653 error_no_arg ("integer to set it to.");
1654 val
= parse_and_eval_address (arg
);
1656 *(int *) c
->var
= INT_MAX
;
1657 else if (val
>= INT_MAX
)
1658 error ("integer %u out of range", val
);
1660 *(int *) c
->var
= val
;
1665 error_no_arg ("integer to set it to.");
1666 *(int *) c
->var
= parse_and_eval_address (arg
);
1673 const char *match
= NULL
;
1676 /* if no argument was supplied, print an informative error message */
1680 strcpy (msg
, "Requires an argument. Valid arguments are ");
1681 for (i
= 0; c
->enums
[i
]; i
++)
1685 strcat (msg
, c
->enums
[i
]);
1691 p
= strchr (arg
, ' ');
1699 for (i
= 0; c
->enums
[i
]; i
++)
1700 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
1702 if (c
->enums
[i
][len
] == '\0')
1704 match
= c
->enums
[i
];
1706 break; /* exact match. */
1710 match
= c
->enums
[i
];
1716 error ("Undefined item: \"%s\".", arg
);
1719 error ("Ambiguous item \"%s\".", arg
);
1721 *(const char **) c
->var
= match
;
1725 error ("gdb internal error: bad var_type in do_setshow_command");
1728 else if (c
->type
== show_cmd
)
1731 struct cleanup
*old_chain
;
1732 struct ui_stream
*stb
;
1735 stb
= ui_out_stream_new (uiout
);
1736 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1739 /* Print doc minus "show" at start. */
1740 print_doc_line (gdb_stdout
, c
->doc
+ 5);
1743 ui_out_text (uiout
, " is ");
1744 ui_out_wrap_hint (uiout
, " ");
1746 switch (c
->var_type
)
1752 if (*(unsigned char **) c
->var
)
1753 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
1757 case var_string_noescape
:
1760 if (*(char **) c
->var
)
1761 fputs_filtered (*(char **) c
->var
, stb
->stream
);
1765 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
1767 case var_auto_boolean
:
1768 switch (*(enum cmd_auto_boolean
*) c
->var
)
1770 case CMD_AUTO_BOOLEAN_TRUE
:
1771 fputs_filtered ("on", stb
->stream
);
1773 case CMD_AUTO_BOOLEAN_FALSE
:
1774 fputs_filtered ("off", stb
->stream
);
1776 case CMD_AUTO_BOOLEAN_AUTO
:
1777 fputs_filtered ("auto", stb
->stream
);
1780 internal_error ("do_setshow_command: invalid var_auto_boolean");
1785 if (*(unsigned int *) c
->var
== UINT_MAX
)
1787 fputs_filtered ("unlimited", stb
->stream
);
1790 /* else fall through */
1792 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
1795 if (*(int *) c
->var
== INT_MAX
)
1797 fputs_filtered ("unlimited", stb
->stream
);
1800 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
1804 error ("gdb internal error: bad var_type in do_setshow_command");
1807 ui_out_text (uiout
, "\"");
1808 ui_out_field_stream (uiout
, "value", stb
);
1810 ui_out_text (uiout
, "\"");
1811 ui_out_text (uiout
, ".\n");
1812 do_cleanups (old_chain
);
1814 fputs_filtered (" is ", gdb_stdout
);
1816 switch (c
->var_type
)
1820 fputs_filtered ("\"", gdb_stdout
);
1821 if (*(unsigned char **) c
->var
)
1822 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
1823 fputs_filtered ("\"", gdb_stdout
);
1826 case var_string_noescape
:
1829 fputs_filtered ("\"", gdb_stdout
);
1830 if (*(char **) c
->var
)
1831 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
1832 fputs_filtered ("\"", gdb_stdout
);
1835 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
1837 case var_auto_boolean
:
1838 switch (*(enum cmd_auto_boolean
*) c
->var
)
1840 case CMD_AUTO_BOOLEAN_TRUE
:
1841 fputs_filtered ("on", gdb_stdout
);
1843 case CMD_AUTO_BOOLEAN_FALSE
:
1844 fputs_filtered ("off", gdb_stdout
);
1846 case CMD_AUTO_BOOLEAN_AUTO
:
1847 fputs_filtered ("auto", gdb_stdout
);
1850 internal_error ("do_setshow_command: invalid var_auto_boolean");
1855 if (*(unsigned int *) c
->var
== UINT_MAX
)
1857 fputs_filtered ("unlimited", gdb_stdout
);
1860 /* else fall through */
1862 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
1865 if (*(int *) c
->var
== INT_MAX
)
1867 fputs_filtered ("unlimited", gdb_stdout
);
1870 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
1874 error ("gdb internal error: bad var_type in do_setshow_command");
1876 fputs_filtered (".\n", gdb_stdout
);
1880 error ("gdb internal error: bad cmd_type in do_setshow_command");
1881 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1882 if (c
->type
== set_cmd
&& set_hook
)
1886 /* Show all the settings in a list of show commands. */
1889 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
1892 ui_out_list_begin (uiout
, "showlist");
1894 for (; list
!= NULL
; list
= list
->next
)
1896 /* If we find a prefix, run its list, prefixing our output by its
1897 prefix (with "show " skipped). */
1899 if (list
->prefixlist
&& !list
->abbrev_flag
)
1901 ui_out_list_begin (uiout
, "optionlist");
1902 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
1903 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1904 ui_out_list_end (uiout
);
1906 if (list
->type
== show_cmd
)
1908 ui_out_list_begin (uiout
, "option");
1909 ui_out_text (uiout
, prefix
);
1910 ui_out_field_string (uiout
, "name", list
->name
);
1911 ui_out_text (uiout
, ": ");
1912 do_setshow_command ((char *) NULL
, from_tty
, list
);
1913 ui_out_list_end (uiout
);
1916 if (list
->prefixlist
&& !list
->abbrev_flag
)
1917 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1918 if (list
->type
== show_cmd
)
1920 fputs_filtered (prefix
, gdb_stdout
);
1921 fputs_filtered (list
->name
, gdb_stdout
);
1922 fputs_filtered (": ", gdb_stdout
);
1923 do_setshow_command ((char *) NULL
, from_tty
, list
);
1928 ui_out_list_end (uiout
);
1934 shell_escape (char *arg
, int from_tty
)
1937 /* If ARG is NULL, they want an inferior shell, but `system' just
1938 reports if the shell is available when passed a NULL arg. */
1939 int rc
= system (arg
? arg
: "");
1942 arg
= "inferior shell";
1946 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", arg
,
1947 safe_strerror (errno
));
1948 gdb_flush (gdb_stderr
);
1952 fprintf_unfiltered (gdb_stderr
, "%s exited with status %d\n", arg
, rc
);
1953 gdb_flush (gdb_stderr
);
1956 /* Make sure to return to the directory GDB thinks it is, in case the
1957 shell command we just ran changed it. */
1958 chdir (current_directory
);
1960 #else /* Can fork. */
1961 int rc
, status
, pid
;
1962 char *p
, *user_shell
;
1964 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1965 user_shell
= "/bin/sh";
1967 /* Get the name of the shell for arg0 */
1968 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1971 p
++; /* Get past '/' */
1973 if ((pid
= fork ()) == 0)
1976 execl (user_shell
, p
, 0);
1978 execl (user_shell
, p
, "-c", arg
, 0);
1980 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", user_shell
,
1981 safe_strerror (errno
));
1982 gdb_flush (gdb_stderr
);
1987 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1990 error ("Fork failed");
1991 #endif /* Can fork. */
1995 make_command (char *arg
, int from_tty
)
2003 p
= xmalloc (sizeof ("make ") + strlen (arg
));
2004 strcpy (p
, "make ");
2005 strcpy (p
+ sizeof ("make ") - 1, arg
);
2008 shell_escape (p
, from_tty
);
2012 show_user_1 (struct cmd_list_element
*c
, struct ui_file
*stream
)
2014 register struct command_line
*cmdlines
;
2016 cmdlines
= c
->user_commands
;
2019 fputs_filtered ("User command ", stream
);
2020 fputs_filtered (c
->name
, stream
);
2021 fputs_filtered (":\n", stream
);
2024 print_command_lines (uiout
, cmdlines
, 1);
2025 fputs_filtered ("\n", stream
);
2029 print_command_line (cmdlines
, 4, stream
);
2030 cmdlines
= cmdlines
->next
;
2032 fputs_filtered ("\n", stream
);
2038 show_user (char *args
, int from_tty
)
2040 struct cmd_list_element
*c
;
2041 extern struct cmd_list_element
*cmdlist
;
2045 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
2046 if (c
->class != class_user
)
2047 error ("Not a user command.");
2048 show_user_1 (c
, gdb_stdout
);
2052 for (c
= cmdlist
; c
; c
= c
->next
)
2054 if (c
->class == class_user
)
2055 show_user_1 (c
, gdb_stdout
);
2061 _initialize_command (void)
2063 add_com ("shell", class_support
, shell_escape
,
2064 "Execute the rest of the line as a shell command. \n\
2065 With no arguments, run an inferior shell.");
2067 /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
2068 be a really useful feature. Unfortunatly, the below wont do
2069 this. Instead it adds support for the form ``(gdb) ! ls''
2070 (i.e. the space is required). If the ``!'' command below is
2071 added the complains about no ``!'' command would be replaced by
2072 complains about how the ``!'' command is broken :-) */
2074 add_com_alias ("!", "shell", class_support
, 0);
2076 add_com ("make", class_support
, make_command
,
2077 "Run the ``make'' program using the rest of the line as arguments.");
2078 add_cmd ("user", no_class
, show_user
,
2079 "Show definitions of user defined commands.\n\
2080 Argument is the name of the user defined command.\n\
2081 With no argument, show definitions of all user defined commands.", &showlist
);
2082 add_com ("apropos", class_support
, apropos_command
, "Search for commands matching a REGEXP");