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
;
118 c
->prefixlist
= NULL
;
119 c
->prefixname
= NULL
;
120 c
->allow_unknown
= 0;
122 c
->completer
= make_symbol_completion_list
;
123 c
->type
= not_set_cmd
;
125 c
->var_type
= var_boolean
;
127 c
->user_commands
= NULL
;
128 c
->hookee_pre
= NULL
;
129 c
->hookee_post
= NULL
;
130 c
->cmd_pointer
= NULL
;
136 /* Deprecates a command CMD.
137 REPLACEMENT is the name of the command which should be used in place
138 of this command, or NULL if no such command exists.
140 This function does not check to see if command REPLACEMENT exists
141 since gdb may not have gotten around to adding REPLACEMENT when this
144 Returns a pointer to the deprecated command. */
146 struct cmd_list_element
*
147 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
149 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
151 if (replacement
!= NULL
)
152 cmd
->replacement
= replacement
;
154 cmd
->replacement
= NULL
;
160 /* Same as above, except that the abbrev_flag is set. */
162 #if 0 /* Currently unused */
164 struct cmd_list_element
*
165 add_abbrev_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
166 char *doc
, struct cmd_list_element
**list
)
168 register struct cmd_list_element
*c
169 = add_cmd (name
, class, fun
, doc
, list
);
177 struct cmd_list_element
*
178 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
179 int abbrev_flag
, struct cmd_list_element
**list
)
181 /* Must do this since lookup_cmd tries to side-effect its first arg */
183 register struct cmd_list_element
*old
;
184 register struct cmd_list_element
*c
;
185 copied_name
= (char *) alloca (strlen (oldname
) + 1);
186 strcpy (copied_name
, oldname
);
187 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
191 delete_cmd (name
, list
);
195 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
196 c
->prefixlist
= old
->prefixlist
;
197 c
->prefixname
= old
->prefixname
;
198 c
->allow_unknown
= old
->allow_unknown
;
199 c
->abbrev_flag
= abbrev_flag
;
200 c
->cmd_pointer
= old
;
204 /* Like add_cmd but adds an element for a command prefix:
205 a name that should be followed by a subcommand to be looked up
206 in another command list. PREFIXLIST should be the address
207 of the variable containing that list. */
209 struct cmd_list_element
*
210 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
211 char *doc
, struct cmd_list_element
**prefixlist
,
212 char *prefixname
, int allow_unknown
,
213 struct cmd_list_element
**list
)
215 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
216 c
->prefixlist
= prefixlist
;
217 c
->prefixname
= prefixname
;
218 c
->allow_unknown
= allow_unknown
;
222 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
224 struct cmd_list_element
*
225 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
226 void (*fun
) (char *, int), char *doc
,
227 struct cmd_list_element
**prefixlist
, char *prefixname
,
228 int allow_unknown
, struct cmd_list_element
**list
)
230 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
231 c
->prefixlist
= prefixlist
;
232 c
->prefixname
= prefixname
;
233 c
->allow_unknown
= allow_unknown
;
238 /* This is an empty "cfunc". */
240 not_just_help_class_command (char *args
, int from_tty
)
244 /* This is an empty "sfunc". */
245 static void empty_sfunc (char *, int, struct cmd_list_element
*);
248 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
252 /* Add element named NAME to command list LIST (the list for set
253 or some sublist thereof).
254 CLASS is as in add_cmd.
255 VAR_TYPE is the kind of thing we are setting.
256 VAR is address of the variable being controlled by this command.
257 DOC is the documentation string. */
259 struct cmd_list_element
*
260 add_set_cmd (char *name
,
261 enum command_class
class,
265 struct cmd_list_element
**list
)
267 struct cmd_list_element
*c
268 = add_cmd (name
, class, NO_FUNCTION
, doc
, list
);
271 c
->var_type
= var_type
;
273 /* This needs to be something besides NO_FUNCTION so that this isn't
274 treated as a help class. */
275 c
->function
.sfunc
= empty_sfunc
;
279 /* Add element named NAME to command list LIST (the list for set
280 or some sublist thereof).
281 CLASS is as in add_cmd.
282 ENUMLIST is a list of strings which may follow NAME.
283 VAR is address of the variable which will contain the matching string
285 DOC is the documentation string. */
287 struct cmd_list_element
*
288 add_set_enum_cmd (char *name
,
289 enum command_class
class,
290 const char *enumlist
[],
293 struct cmd_list_element
**list
)
295 struct cmd_list_element
*c
296 = add_set_cmd (name
, class, var_enum
, var
, doc
, list
);
302 /* Add element named NAME to command list LIST (the list for set
303 or some sublist thereof).
304 CLASS is as in add_cmd.
305 VAR is address of the variable which will contain the value.
306 DOC is the documentation string. */
307 struct cmd_list_element
*
308 add_set_auto_boolean_cmd (char *name
,
309 enum command_class
class,
310 enum cmd_auto_boolean
*var
,
312 struct cmd_list_element
**list
)
314 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
315 struct cmd_list_element
*c
;
316 c
= add_set_cmd (name
, class, var_auto_boolean
, var
, doc
, list
);
317 c
->enums
= auto_boolean_enums
;
321 /* Where SETCMD has already been added, add the corresponding show
322 command to LIST and return a pointer to the added command (not
323 necessarily the head of LIST). */
324 struct cmd_list_element
*
325 add_show_from_set (struct cmd_list_element
*setcmd
,
326 struct cmd_list_element
**list
)
328 struct cmd_list_element
*showcmd
=
329 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
330 struct cmd_list_element
*p
;
332 memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
333 delete_cmd (showcmd
->name
, list
);
334 showcmd
->type
= show_cmd
;
336 /* Replace "set " at start of docstring with "show ". */
337 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
338 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
339 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
341 fprintf_unfiltered (gdb_stderr
, "GDB internal error: Bad docstring for set command\n");
343 if (*list
== NULL
|| STRCMP ((*list
)->name
, showcmd
->name
) >= 0)
345 showcmd
->next
= *list
;
351 while (p
->next
&& STRCMP (p
->next
->name
, showcmd
->name
) <= 0)
355 showcmd
->next
= p
->next
;
362 /* Remove the command named NAME from the command list. */
365 delete_cmd (char *name
, struct cmd_list_element
**list
)
367 register struct cmd_list_element
*c
;
368 struct cmd_list_element
*p
;
370 while (*list
&& STREQ ((*list
)->name
, name
))
372 if ((*list
)->hookee_pre
)
373 (*list
)->hookee_pre
->hook_pre
= 0; /* Hook slips out of its mouth */
374 if ((*list
)->hookee_post
)
375 (*list
)->hookee_post
->hook_post
= 0; /* Hook slips out of its bottom */
382 for (c
= *list
; c
->next
;)
384 if (STREQ (c
->next
->name
, name
))
386 if (c
->next
->hookee_pre
)
387 c
->next
->hookee_pre
->hook_pre
= 0; /* hooked cmd gets away. */
388 if (c
->next
->hookee_post
)
389 c
->next
->hookee_post
->hook_post
= 0; /* remove post hook */
390 /* :( no fishing metaphore */
392 free ((PTR
) c
->next
);
399 /* Recursively walk the commandlist structures, and print out the
400 documentation of commands that match our regex in either their
401 name, or their documentation.
404 apropos_cmd_helper (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
405 struct re_pattern_buffer
*regex
, char *prefix
)
407 register struct cmd_list_element
*c
;
408 int returnvalue
=1; /*Needed to avoid double printing*/
409 /* Walk through the commands */
410 for (c
=commandlist
;c
;c
=c
->next
)
414 /* Try to match against the name*/
415 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
416 if (returnvalue
>= 0)
418 /* Stolen from help_cmd_list. We don't directly use
419 * help_cmd_list because it doesn't let us print out
422 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
423 print_doc_line (stream
, c
->doc
);
424 fputs_filtered ("\n", stream
);
425 returnvalue
=0; /*Set this so we don't print it again.*/
428 if (c
->doc
!= NULL
&& returnvalue
!= 0)
430 /* Try to match against documentation */
431 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
433 /* Stolen from help_cmd_list. We don't directly use
434 * help_cmd_list because it doesn't let us print out
437 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
438 print_doc_line (stream
, c
->doc
);
439 fputs_filtered ("\n", stream
);
442 /* Check if this command has subcommands */
443 if (c
->prefixlist
!= NULL
)
445 /* Recursively call ourselves on the subcommand list,
446 passing the right prefix in.
448 apropos_cmd_helper(stream
,*c
->prefixlist
,regex
,c
->prefixname
);
452 /* Search through names of commands and documentations for a certain
456 apropos_command (char *searchstr
, int from_tty
)
458 extern struct cmd_list_element
*cmdlist
; /*This is the main command list*/
460 char *pattern_fastmap
;
461 char errorbuffer
[512];
462 pattern_fastmap
=calloc(256,sizeof(char));
463 if (searchstr
== NULL
)
464 error("REGEXP string is empty");
466 if (regcomp(&pattern
,searchstr
,REG_ICASE
) == 0)
468 pattern
.fastmap
=pattern_fastmap
;
469 re_compile_fastmap(&pattern
);
470 apropos_cmd_helper(gdb_stdout
,cmdlist
,&pattern
,"");
474 regerror(regcomp(&pattern
,searchstr
,REG_ICASE
),NULL
,errorbuffer
,512);
475 error("Error in regular expression:%s",errorbuffer
);
477 free(pattern_fastmap
);
481 /* This command really has to deal with two things:
482 * 1) I want documentation on *this string* (usually called by
483 * "help commandname").
484 * 2) I want documentation on *this list* (usually called by
485 * giving a command that requires subcommands. Also called by saying
488 * I am going to split this into two seperate comamnds, help_cmd and
493 help_cmd (char *command
, struct ui_file
*stream
)
495 struct cmd_list_element
*c
;
496 extern struct cmd_list_element
*cmdlist
;
500 help_list (cmdlist
, "", all_classes
, stream
);
504 if (strcmp (command
, "all") == 0)
510 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
515 /* There are three cases here.
516 If c->prefixlist is nonzero, we have a prefix command.
517 Print its documentation, then list its subcommands.
519 If c->function is nonzero, we really have a command.
520 Print its documentation and return.
522 If c->function is zero, we have a class name.
523 Print its documentation (as if it were a command)
524 and then set class to the number of this class
525 so that the commands in the class will be listed. */
527 fputs_filtered (c
->doc
, stream
);
528 fputs_filtered ("\n", stream
);
530 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
532 fprintf_filtered (stream
, "\n");
534 /* If this is a prefix command, print it's subcommands */
536 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
538 /* If this is a class name, print all of the commands in the class */
539 if (c
->function
.cfunc
== NULL
)
540 help_list (cmdlist
, "", c
->class, stream
);
542 if (c
->hook_pre
|| c
->hook_post
)
543 fprintf_filtered (stream
,
544 "\nThis command has a hook (or hooks) defined:\n");
547 fprintf_filtered (stream
,
548 "\tThis command is run after : %s (pre hook)\n",
551 fprintf_filtered (stream
,
552 "\tThis command is run before : %s (post hook)\n",
557 * Get a specific kind of help on a command list.
560 * CMDTYPE is the prefix to use in the title string.
561 * CLASS is the class with which to list the nodes of this list (see
562 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
563 * everything, ALL_CLASSES for just classes, and non-negative for only things
564 * in a specific class.
565 * and STREAM is the output stream on which to print things.
566 * If you call this routine with a class >= 0, it recurses.
569 help_list (struct cmd_list_element
*list
, char *cmdtype
,
570 enum command_class
class, struct ui_file
*stream
)
573 char *cmdtype1
, *cmdtype2
;
575 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
576 len
= strlen (cmdtype
);
577 cmdtype1
= (char *) alloca (len
+ 1);
579 cmdtype2
= (char *) alloca (len
+ 4);
584 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
586 strncpy (cmdtype2
, cmdtype
, len
- 1);
587 strcpy (cmdtype2
+ len
- 1, " sub");
590 if (class == all_classes
)
591 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
593 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
595 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
597 if (class == all_classes
)
598 fprintf_filtered (stream
, "\n\
599 Type \"help%s\" followed by a class name for a list of commands in that class.",
602 fprintf_filtered (stream
, "\n\
603 Type \"help%s\" followed by %scommand name for full documentation.\n\
604 Command name abbreviations are allowed if unambiguous.\n",
609 help_all (struct ui_file
*stream
)
611 struct cmd_list_element
*c
;
612 extern struct cmd_list_element
*cmdlist
;
614 for (c
= cmdlist
; c
; c
= c
->next
)
618 /* If this is a prefix command, print it's subcommands */
620 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 0, stream
);
622 /* If this is a class name, print all of the commands in the class */
623 else if (c
->function
.cfunc
== NULL
)
624 help_cmd_list (cmdlist
, c
->class, "", 0, stream
);
628 /* Print only the first line of STR on STREAM. */
630 print_doc_line (struct ui_file
*stream
, char *str
)
632 static char *line_buffer
= 0;
633 static int line_size
;
639 line_buffer
= (char *) xmalloc (line_size
);
643 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
645 if (p
- str
> line_size
- 1)
647 line_size
= p
- str
+ 1;
648 free ((PTR
) line_buffer
);
649 line_buffer
= (char *) xmalloc (line_size
);
651 strncpy (line_buffer
, str
, p
- str
);
652 line_buffer
[p
- str
] = '\0';
653 if (islower (line_buffer
[0]))
654 line_buffer
[0] = toupper (line_buffer
[0]);
656 ui_out_text (uiout
, line_buffer
);
658 fputs_filtered (line_buffer
, stream
);
663 * Implement a help command on command list LIST.
664 * RECURSE should be non-zero if this should be done recursively on
665 * all sublists of LIST.
666 * PREFIX is the prefix to print before each command name.
667 * STREAM is the stream upon which the output should be written.
669 * A non-negative class number to list only commands in that
671 * ALL_COMMANDS to list all commands in list.
672 * ALL_CLASSES to list all classes in list.
674 * Note that RECURSE will be active on *all* sublists, not just the
675 * ones selected by the criteria above (ie. the selection mechanism
676 * is at the low level, not the high-level).
679 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
680 char *prefix
, int recurse
, struct ui_file
*stream
)
682 register struct cmd_list_element
*c
;
684 for (c
= list
; c
; c
= c
->next
)
686 if (c
->abbrev_flag
== 0 &&
687 (class == all_commands
688 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
689 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
691 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
692 print_doc_line (stream
, c
->doc
);
693 fputs_filtered ("\n", stream
);
696 && c
->prefixlist
!= 0
697 && c
->abbrev_flag
== 0)
698 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
703 /* Search the input clist for 'command'. Return the command if
704 found (or NULL if not), and return the number of commands
707 static struct cmd_list_element
*
708 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
709 int ignore_help_classes
, int *nfound
)
711 struct cmd_list_element
*found
, *c
;
713 found
= (struct cmd_list_element
*) NULL
;
715 for (c
= clist
; c
; c
= c
->next
)
716 if (!strncmp (command
, c
->name
, len
)
717 && (!ignore_help_classes
|| c
->function
.cfunc
))
721 if (c
->name
[len
] == '\0')
730 /* This routine takes a line of TEXT and a CLIST in which to start the
731 lookup. When it returns it will have incremented the text pointer past
732 the section of text it matched, set *RESULT_LIST to point to the list in
733 which the last word was matched, and will return a pointer to the cmd
734 list element which the text matches. It will return NULL if no match at
735 all was possible. It will return -1 (cast appropriately, ick) if ambigous
736 matches are possible; in this case *RESULT_LIST will be set to point to
737 the list in which there are ambiguous choices (and *TEXT will be set to
738 the ambiguous text string).
740 If the located command was an abbreviation, this routine returns the base
741 command of the abbreviation.
743 It does no error reporting whatsoever; control will always return
744 to the superior routine.
746 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
747 at the prefix_command (ie. the best match) *or* (special case) will be NULL
748 if no prefix command was ever found. For example, in the case of "info a",
749 "info" matches without ambiguity, but "a" could be "args" or "address", so
750 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
751 RESULT_LIST should not be interpeted as a pointer to the beginning of a
752 list; it simply points to a specific command. In the case of an ambiguous
753 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
754 "info t" can be "info types" or "info target"; upon return *TEXT has been
755 advanced past "info ").
757 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
758 affect the operation).
760 This routine does *not* modify the text pointed to by TEXT.
762 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
763 are actually help classes rather than commands (i.e. the function field of
764 the struct cmd_list_element is NULL). */
766 struct cmd_list_element
*
767 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
768 struct cmd_list_element
**result_list
, int ignore_help_classes
)
771 int len
, tmp
, nfound
;
772 struct cmd_list_element
*found
, *c
;
775 while (**text
== ' ' || **text
== '\t')
778 /* Treating underscores as part of command words is important
779 so that "set args_foo()" doesn't get interpreted as
780 "set args _foo()". */
782 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
784 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
785 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
789 /* If nothing but whitespace, return 0. */
795 /* *text and p now bracket the first command word to lookup (and
796 it's length is len). We copy this into a local temporary */
799 command
= (char *) alloca (len
+ 1);
800 for (tmp
= 0; tmp
< len
; tmp
++)
802 char x
= (*text
)[tmp
];
810 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
813 ** We didn't find the command in the entered case, so lower case it
816 if (!found
|| nfound
== 0)
818 for (tmp
= 0; tmp
< len
; tmp
++)
820 char x
= command
[tmp
];
821 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
823 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
826 /* If nothing matches, we have a simple failure. */
832 if (result_list
!= NULL
)
833 /* Will be modified in calling routine
834 if we know what the prefix command is. */
836 return (struct cmd_list_element
*) -1; /* Ambiguous. */
839 /* We've matched something on this list. Move text pointer forward. */
843 if (found
->cmd_pointer
)
845 /* We drop the alias (abbreviation) in favor of the command it is
846 pointing to. If the alias is deprecated, though, we need to
847 warn the user about it before we drop it. Note that while we
848 are warning about the alias, we may also warn about the command
849 itself and we will adjust the appropriate DEPRECATED_WARN_USER
852 if (found
->flags
& DEPRECATED_WARN_USER
)
853 deprecated_cmd_warning (&line
);
854 found
= found
->cmd_pointer
;
856 /* If we found a prefix command, keep looking. */
858 if (found
->prefixlist
)
860 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
861 ignore_help_classes
);
864 /* Didn't find anything; this is as far as we got. */
865 if (result_list
!= NULL
)
866 *result_list
= clist
;
869 else if (c
== (struct cmd_list_element
*) -1)
871 /* We've gotten this far properly, but the next step
872 is ambiguous. We need to set the result list to the best
873 we've found (if an inferior hasn't already set it). */
874 if (result_list
!= NULL
)
876 /* This used to say *result_list = *found->prefixlist
877 If that was correct, need to modify the documentation
878 at the top of this function to clarify what is supposed
880 *result_list
= found
;
891 if (result_list
!= NULL
)
892 *result_list
= clist
;
897 /* All this hair to move the space to the front of cmdtype */
900 undef_cmd_error (char *cmdtype
, char *q
)
902 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
906 strlen (cmdtype
) - 1,
910 /* Look up the contents of *LINE as a command in the command list LIST.
911 LIST is a chain of struct cmd_list_element's.
912 If it is found, return the struct cmd_list_element for that command
913 and update *LINE to point after the command name, at the first argument.
914 If not found, call error if ALLOW_UNKNOWN is zero
915 otherwise (or if error returns) return zero.
916 Call error if specified command is ambiguous,
917 unless ALLOW_UNKNOWN is negative.
918 CMDTYPE precedes the word "command" in the error message.
920 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
921 elements which are actually help classes rather than commands (i.e.
922 the function field of the struct cmd_list_element is 0). */
924 struct cmd_list_element
*
925 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
926 int allow_unknown
, int ignore_help_classes
)
928 struct cmd_list_element
*last_list
= 0;
929 struct cmd_list_element
*c
=
930 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
932 /* This is wrong for complete_command. */
933 char *ptr
= (*line
) + strlen (*line
) - 1;
935 /* Clear off trailing whitespace. */
936 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
946 error ("Lack of needed %scommand", cmdtype
);
951 while (isalnum (*p
) || *p
== '-')
954 q
= (char *) alloca (p
- *line
+ 1);
955 strncpy (q
, *line
, p
- *line
);
957 undef_cmd_error (cmdtype
, q
);
963 else if (c
== (struct cmd_list_element
*) -1)
965 /* Ambigous. Local values should be off prefixlist or called
967 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
969 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
970 struct cmd_list_element
*local_list
=
971 (last_list
? *(last_list
->prefixlist
) : list
);
973 if (local_allow_unknown
< 0)
976 return last_list
; /* Found something. */
978 return 0; /* Found nothing. */
982 /* Report as error. */
987 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
988 && (*line
)[amb_len
] != '\t');
993 for (c
= local_list
; c
; c
= c
->next
)
994 if (!strncmp (*line
, c
->name
, amb_len
))
996 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
999 strcat (ambbuf
, ", ");
1000 strcat (ambbuf
, c
->name
);
1004 strcat (ambbuf
, "..");
1008 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
1010 return 0; /* lint */
1015 /* We've got something. It may still not be what the caller
1016 wants (if this command *needs* a subcommand). */
1017 while (**line
== ' ' || **line
== '\t')
1020 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1021 undef_cmd_error (c
->prefixname
, *line
);
1023 /* Seems to be what he wants. Return it. */
1029 /* We are here presumably because an alias or command in *TEXT is
1030 deprecated and a warning message should be generated. This function
1031 decodes *TEXT and potentially generates a warning message as outlined
1034 Example for 'set endian big' which has a fictitious alias 'seb'.
1036 If alias wasn't used in *TEXT, and the command is deprecated:
1037 "warning: 'set endian big' is deprecated."
1039 If alias was used, and only the alias is deprecated:
1040 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1042 If alias was used and command is deprecated (regardless of whether the
1043 alias itself is deprecated:
1045 "warning: 'set endian big' (seb) is deprecated."
1047 After the message has been sent, clear the appropriate flags in the
1048 command and/or the alias so the user is no longer bothered.
1052 deprecated_cmd_warning (char **text
)
1054 struct cmd_list_element
*alias
= NULL
;
1055 struct cmd_list_element
*prefix_cmd
= NULL
;
1056 struct cmd_list_element
*cmd
= NULL
;
1057 struct cmd_list_element
*c
;
1060 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1061 /* return if text doesn't evaluate to a command */
1064 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1065 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1066 /* return if nothing is deprecated */
1069 printf_filtered ("Warning:");
1071 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1072 printf_filtered (" '%s', an alias for the", alias
->name
);
1074 printf_filtered (" command '");
1077 printf_filtered ("%s", prefix_cmd
->prefixname
);
1079 printf_filtered ("%s", cmd
->name
);
1081 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1082 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1084 printf_filtered ("' is deprecated.\n");
1087 /* if it is only the alias that is deprecated, we want to indicate the
1088 new alias, otherwise we'll indicate the new command */
1090 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1092 if (alias
->replacement
)
1093 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1095 printf_filtered ("No alternative known.\n\n");
1099 if (cmd
->replacement
)
1100 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1102 printf_filtered ("No alternative known.\n\n");
1105 /* We've warned you, now we'll keep quiet */
1107 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1109 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1114 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1115 Return 1 on success, 0 on failure.
1117 If LINE refers to an alias, *alias will point to that alias.
1119 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1120 command) set *prefix_cmd.
1122 Set *cmd to point to the command LINE indicates.
1124 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1125 exist, they are NULL when we return.
1129 lookup_cmd_composition (char *text
,
1130 struct cmd_list_element
**alias
,
1131 struct cmd_list_element
**prefix_cmd
,
1132 struct cmd_list_element
**cmd
)
1135 int len
, tmp
, nfound
;
1136 struct cmd_list_element
*cur_list
;
1137 struct cmd_list_element
*prev_cmd
;
1146 /* Go through as many command lists as we need to
1147 to find the command TEXT refers to. */
1151 while (*text
== ' ' || *text
== '\t')
1154 /* Treating underscores as part of command words is important
1155 so that "set args_foo()" doesn't get interpreted as
1156 "set args _foo()". */
1158 *p
&& (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1160 (*p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')) ||
1161 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')));
1165 /* If nothing but whitespace, return. */
1171 /* text and p now bracket the first command word to lookup (and
1172 it's length is len). We copy this into a local temporary */
1174 command
= (char *) alloca (len
+ 1);
1175 for (tmp
= 0; tmp
< len
; tmp
++)
1180 command
[len
] = '\0';
1185 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1187 /* We didn't find the command in the entered case, so lower case it
1190 if (!*cmd
|| nfound
== 0)
1192 for (tmp
= 0; tmp
< len
; tmp
++)
1194 char x
= command
[tmp
];
1195 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1197 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1200 if (*cmd
== (struct cmd_list_element
*) -1)
1202 return 0; /* ambiguous */
1206 return 0; /* nothing found */
1209 if ((*cmd
)->cmd_pointer
)
1211 /* cmd was actually an alias, we note that an alias was used
1212 (by assigning *alais) and we set *cmd.
1215 *cmd
= (*cmd
)->cmd_pointer
;
1217 *prefix_cmd
= prev_cmd
;
1219 if ((*cmd
)->prefixlist
)
1220 cur_list
= *(*cmd
)->prefixlist
;
1232 /* Look up the contents of *LINE as a command in the command list LIST.
1233 LIST is a chain of struct cmd_list_element's.
1234 If it is found, return the struct cmd_list_element for that command
1235 and update *LINE to point after the command name, at the first argument.
1236 If not found, call error if ALLOW_UNKNOWN is zero
1237 otherwise (or if error returns) return zero.
1238 Call error if specified command is ambiguous,
1239 unless ALLOW_UNKNOWN is negative.
1240 CMDTYPE precedes the word "command" in the error message. */
1242 struct cmd_list_element
*
1243 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1247 register struct cmd_list_element
*c
, *found
;
1250 char *processed_cmd
;
1253 /* Skip leading whitespace. */
1255 while (**line
== ' ' || **line
== '\t')
1258 /* Clear out trailing whitespace. */
1260 p
= *line
+ strlen (*line
);
1261 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1265 /* Find end of command name. */
1268 while (*p
== '-' || isalnum (*p
))
1271 /* Look up the command name.
1272 If exact match, keep that.
1273 Otherwise, take command abbreviated, if unique. Note that (in my
1274 opinion) a null string does *not* indicate ambiguity; simply the
1275 end of the argument. */
1280 error ("Lack of needed %scommand", cmdtype
);
1284 /* Copy over to a local buffer, converting to lowercase on the way.
1285 This is in case the command being parsed is a subcommand which
1286 doesn't match anything, and that's ok. We want the original
1287 untouched for the routine of the original command. */
1289 processed_cmd
= (char *) alloca (p
- *line
+ 1);
1290 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
1292 char x
= (*line
)[cmd_len
];
1294 processed_cmd
[cmd_len
] = tolower (x
);
1296 processed_cmd
[cmd_len
] = x
;
1298 processed_cmd
[cmd_len
] = '\0';
1300 /* Check all possibilities in the current command list. */
1303 for (c
= list
; c
; c
= c
->next
)
1305 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1309 if (c
->name
[cmd_len
] == 0)
1317 /* Report error for undefined command name. */
1321 if (nfound
> 1 && allow_unknown
>= 0)
1324 for (c
= list
; c
; c
= c
->next
)
1325 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
1327 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
1329 if (strlen (ambbuf
))
1330 strcat (ambbuf
, ", ");
1331 strcat (ambbuf
, c
->name
);
1335 strcat (ambbuf
, "..");
1339 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
1340 processed_cmd
, ambbuf
);
1342 else if (!allow_unknown
)
1343 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
1347 /* Skip whitespace before the argument. */
1349 while (*p
== ' ' || *p
== '\t')
1353 if (found
->prefixlist
&& *p
)
1355 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
1356 found
->allow_unknown
);
1365 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1367 /* Return a vector of char pointers which point to the different
1368 possible completions in LIST of TEXT.
1370 WORD points in the same buffer as TEXT, and completions should be
1371 returned relative to this position. For example, suppose TEXT is "foo"
1372 and we want to complete to "foobar". If WORD is "oo", return
1373 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1376 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1378 struct cmd_list_element
*ptr
;
1380 int sizeof_matchlist
;
1382 int textlen
= strlen (text
);
1384 sizeof_matchlist
= 10;
1385 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1388 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1389 if (!strncmp (ptr
->name
, text
, textlen
)
1390 && !ptr
->abbrev_flag
1391 && (ptr
->function
.cfunc
1392 || ptr
->prefixlist
))
1394 if (matches
== sizeof_matchlist
)
1396 sizeof_matchlist
*= 2;
1397 matchlist
= (char **) xrealloc ((char *) matchlist
,
1399 * sizeof (char *)));
1402 matchlist
[matches
] = (char *)
1403 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1405 strcpy (matchlist
[matches
], ptr
->name
);
1406 else if (word
> text
)
1408 /* Return some portion of ptr->name. */
1409 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1413 /* Return some of text plus ptr->name. */
1414 strncpy (matchlist
[matches
], word
, text
- word
);
1415 matchlist
[matches
][text
- word
] = '\0';
1416 strcat (matchlist
[matches
], ptr
->name
);
1423 free ((PTR
) matchlist
);
1428 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1429 * sizeof (char *)));
1430 matchlist
[matches
] = (char *) 0;
1436 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1438 /* Return a vector of char pointers which point to the different
1439 possible completions in CMD of TEXT.
1441 WORD points in the same buffer as TEXT, and completions should be
1442 returned relative to this position. For example, suppose TEXT is "foo"
1443 and we want to complete to "foobar". If WORD is "oo", return
1444 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1447 complete_on_enum (const char *enumlist
[],
1452 int sizeof_matchlist
;
1454 int textlen
= strlen (text
);
1458 sizeof_matchlist
= 10;
1459 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1462 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1463 if (strncmp (name
, text
, textlen
) == 0)
1465 if (matches
== sizeof_matchlist
)
1467 sizeof_matchlist
*= 2;
1468 matchlist
= (char **) xrealloc ((char *) matchlist
,
1470 * sizeof (char *)));
1473 matchlist
[matches
] = (char *)
1474 xmalloc (strlen (word
) + strlen (name
) + 1);
1476 strcpy (matchlist
[matches
], name
);
1477 else if (word
> text
)
1479 /* Return some portion of name. */
1480 strcpy (matchlist
[matches
], name
+ (word
- text
));
1484 /* Return some of text plus name. */
1485 strncpy (matchlist
[matches
], word
, text
- word
);
1486 matchlist
[matches
][text
- word
] = '\0';
1487 strcat (matchlist
[matches
], name
);
1494 free ((PTR
) matchlist
);
1499 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1500 * sizeof (char *)));
1501 matchlist
[matches
] = (char *) 0;
1507 static enum cmd_auto_boolean
1508 parse_auto_binary_operation (const char *arg
)
1510 if (arg
!= NULL
&& *arg
!= '\0')
1512 int length
= strlen (arg
);
1513 while (isspace (arg
[length
- 1]) && length
> 0)
1515 if (strncmp (arg
, "on", length
) == 0
1516 || strncmp (arg
, "1", length
) == 0
1517 || strncmp (arg
, "yes", length
) == 0
1518 || strncmp (arg
, "enable", length
) == 0)
1519 return CMD_AUTO_BOOLEAN_TRUE
;
1520 else if (strncmp (arg
, "off", length
) == 0
1521 || strncmp (arg
, "0", length
) == 0
1522 || strncmp (arg
, "no", length
) == 0
1523 || strncmp (arg
, "disable", length
) == 0)
1524 return CMD_AUTO_BOOLEAN_FALSE
;
1525 else if (strncmp (arg
, "auto", length
) == 0
1526 || (strncmp (arg
, "-1", length
) == 0 && length
> 1))
1527 return CMD_AUTO_BOOLEAN_AUTO
;
1529 error ("\"on\", \"off\" or \"auto\" expected.");
1530 return CMD_AUTO_BOOLEAN_AUTO
; /* pacify GCC */
1534 parse_binary_operation (char *arg
)
1541 length
= strlen (arg
);
1543 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
1546 if (strncmp (arg
, "on", length
) == 0
1547 || strncmp (arg
, "1", length
) == 0
1548 || strncmp (arg
, "yes", length
) == 0
1549 || strncmp (arg
, "enable", length
) == 0)
1551 else if (strncmp (arg
, "off", length
) == 0
1552 || strncmp (arg
, "0", length
) == 0
1553 || strncmp (arg
, "no", length
) == 0
1554 || strncmp (arg
, "disable", length
) == 0)
1558 error ("\"on\" or \"off\" expected.");
1563 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1564 of the argument, and FROM_TTY is nonzero if this command is being entered
1565 directly by the user (i.e. these are just like any other
1566 command). C is the command list element for the command. */
1568 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
1570 if (c
->type
== set_cmd
)
1572 switch (c
->var_type
)
1583 new = (char *) xmalloc (strlen (arg
) + 2);
1586 while ((ch
= *p
++) != '\000')
1590 /* \ at end of argument is used after spaces
1591 so they won't be lost. */
1592 /* This is obsolete now that we no longer strip
1593 trailing whitespace and actually, the backslash
1594 didn't get here in my test, readline or
1595 something did something funky with a backslash
1596 right before a newline. */
1599 ch
= parse_escape (&p
);
1601 break; /* C loses */
1609 if (*(p
- 1) != '\\')
1613 new = (char *) xrealloc (new, q
- new);
1614 if (*(char **) c
->var
!= NULL
)
1615 free (*(char **) c
->var
);
1616 *(char **) c
->var
= new;
1619 case var_string_noescape
:
1622 if (*(char **) c
->var
!= NULL
)
1623 free (*(char **) c
->var
);
1624 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1628 error_no_arg ("filename to set it to.");
1629 if (*(char **) c
->var
!= NULL
)
1630 free (*(char **) c
->var
);
1631 *(char **) c
->var
= tilde_expand (arg
);
1634 *(int *) c
->var
= parse_binary_operation (arg
);
1636 case var_auto_boolean
:
1637 *(enum cmd_auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
1641 error_no_arg ("integer to set it to.");
1642 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
1643 if (*(unsigned int *) c
->var
== 0)
1644 *(unsigned int *) c
->var
= UINT_MAX
;
1650 error_no_arg ("integer to set it to.");
1651 val
= parse_and_eval_long (arg
);
1653 *(int *) c
->var
= INT_MAX
;
1654 else if (val
>= INT_MAX
)
1655 error ("integer %u out of range", val
);
1657 *(int *) c
->var
= val
;
1662 error_no_arg ("integer to set it to.");
1663 *(int *) c
->var
= parse_and_eval_long (arg
);
1670 const char *match
= NULL
;
1673 /* if no argument was supplied, print an informative error message */
1677 strcpy (msg
, "Requires an argument. Valid arguments are ");
1678 for (i
= 0; c
->enums
[i
]; i
++)
1682 strcat (msg
, c
->enums
[i
]);
1688 p
= strchr (arg
, ' ');
1696 for (i
= 0; c
->enums
[i
]; i
++)
1697 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
1699 if (c
->enums
[i
][len
] == '\0')
1701 match
= c
->enums
[i
];
1703 break; /* exact match. */
1707 match
= c
->enums
[i
];
1713 error ("Undefined item: \"%s\".", arg
);
1716 error ("Ambiguous item \"%s\".", arg
);
1718 *(const char **) c
->var
= match
;
1722 error ("gdb internal error: bad var_type in do_setshow_command");
1725 else if (c
->type
== show_cmd
)
1728 struct cleanup
*old_chain
;
1729 struct ui_stream
*stb
;
1732 stb
= ui_out_stream_new (uiout
);
1733 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1736 /* Print doc minus "show" at start. */
1737 print_doc_line (gdb_stdout
, c
->doc
+ 5);
1740 ui_out_text (uiout
, " is ");
1741 ui_out_wrap_hint (uiout
, " ");
1743 switch (c
->var_type
)
1749 if (*(unsigned char **) c
->var
)
1750 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
1754 case var_string_noescape
:
1757 if (*(char **) c
->var
)
1758 fputs_filtered (*(char **) c
->var
, stb
->stream
);
1762 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
1764 case var_auto_boolean
:
1765 switch (*(enum cmd_auto_boolean
*) c
->var
)
1767 case CMD_AUTO_BOOLEAN_TRUE
:
1768 fputs_filtered ("on", stb
->stream
);
1770 case CMD_AUTO_BOOLEAN_FALSE
:
1771 fputs_filtered ("off", stb
->stream
);
1773 case CMD_AUTO_BOOLEAN_AUTO
:
1774 fputs_filtered ("auto", stb
->stream
);
1777 internal_error ("do_setshow_command: invalid var_auto_boolean");
1782 if (*(unsigned int *) c
->var
== UINT_MAX
)
1784 fputs_filtered ("unlimited", stb
->stream
);
1787 /* else fall through */
1789 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
1792 if (*(int *) c
->var
== INT_MAX
)
1794 fputs_filtered ("unlimited", stb
->stream
);
1797 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
1801 error ("gdb internal error: bad var_type in do_setshow_command");
1804 ui_out_text (uiout
, "\"");
1805 ui_out_field_stream (uiout
, "value", stb
);
1807 ui_out_text (uiout
, "\"");
1808 ui_out_text (uiout
, ".\n");
1809 do_cleanups (old_chain
);
1811 fputs_filtered (" is ", gdb_stdout
);
1813 switch (c
->var_type
)
1817 fputs_filtered ("\"", gdb_stdout
);
1818 if (*(unsigned char **) c
->var
)
1819 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
1820 fputs_filtered ("\"", gdb_stdout
);
1823 case var_string_noescape
:
1826 fputs_filtered ("\"", gdb_stdout
);
1827 if (*(char **) c
->var
)
1828 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
1829 fputs_filtered ("\"", gdb_stdout
);
1832 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
1834 case var_auto_boolean
:
1835 switch (*(enum cmd_auto_boolean
*) c
->var
)
1837 case CMD_AUTO_BOOLEAN_TRUE
:
1838 fputs_filtered ("on", gdb_stdout
);
1840 case CMD_AUTO_BOOLEAN_FALSE
:
1841 fputs_filtered ("off", gdb_stdout
);
1843 case CMD_AUTO_BOOLEAN_AUTO
:
1844 fputs_filtered ("auto", gdb_stdout
);
1847 internal_error ("do_setshow_command: invalid var_auto_boolean");
1852 if (*(unsigned int *) c
->var
== UINT_MAX
)
1854 fputs_filtered ("unlimited", gdb_stdout
);
1857 /* else fall through */
1859 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
1862 if (*(int *) c
->var
== INT_MAX
)
1864 fputs_filtered ("unlimited", gdb_stdout
);
1867 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
1871 error ("gdb internal error: bad var_type in do_setshow_command");
1873 fputs_filtered (".\n", gdb_stdout
);
1877 error ("gdb internal error: bad cmd_type in do_setshow_command");
1878 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1879 if (c
->type
== set_cmd
&& set_hook
)
1883 /* Show all the settings in a list of show commands. */
1886 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
1889 ui_out_list_begin (uiout
, "showlist");
1891 for (; list
!= NULL
; list
= list
->next
)
1893 /* If we find a prefix, run its list, prefixing our output by its
1894 prefix (with "show " skipped). */
1896 if (list
->prefixlist
&& !list
->abbrev_flag
)
1898 ui_out_list_begin (uiout
, "optionlist");
1899 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
1900 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1901 ui_out_list_end (uiout
);
1903 if (list
->type
== show_cmd
)
1905 ui_out_list_begin (uiout
, "option");
1906 ui_out_text (uiout
, prefix
);
1907 ui_out_field_string (uiout
, "name", list
->name
);
1908 ui_out_text (uiout
, ": ");
1909 do_setshow_command ((char *) NULL
, from_tty
, list
);
1910 ui_out_list_end (uiout
);
1913 if (list
->prefixlist
&& !list
->abbrev_flag
)
1914 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1915 if (list
->type
== show_cmd
)
1917 fputs_filtered (prefix
, gdb_stdout
);
1918 fputs_filtered (list
->name
, gdb_stdout
);
1919 fputs_filtered (": ", gdb_stdout
);
1920 do_setshow_command ((char *) NULL
, from_tty
, list
);
1925 ui_out_list_end (uiout
);
1931 shell_escape (char *arg
, int from_tty
)
1934 /* If ARG is NULL, they want an inferior shell, but `system' just
1935 reports if the shell is available when passed a NULL arg. */
1936 int rc
= system (arg
? arg
: "");
1939 arg
= "inferior shell";
1943 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", arg
,
1944 safe_strerror (errno
));
1945 gdb_flush (gdb_stderr
);
1949 fprintf_unfiltered (gdb_stderr
, "%s exited with status %d\n", arg
, rc
);
1950 gdb_flush (gdb_stderr
);
1953 /* Make sure to return to the directory GDB thinks it is, in case the
1954 shell command we just ran changed it. */
1955 chdir (current_directory
);
1957 #else /* Can fork. */
1958 int rc
, status
, pid
;
1959 char *p
, *user_shell
;
1961 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1962 user_shell
= "/bin/sh";
1964 /* Get the name of the shell for arg0 */
1965 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1968 p
++; /* Get past '/' */
1970 if ((pid
= fork ()) == 0)
1973 execl (user_shell
, p
, 0);
1975 execl (user_shell
, p
, "-c", arg
, 0);
1977 fprintf_unfiltered (gdb_stderr
, "Cannot execute %s: %s\n", user_shell
,
1978 safe_strerror (errno
));
1979 gdb_flush (gdb_stderr
);
1984 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1987 error ("Fork failed");
1988 #endif /* Can fork. */
1992 make_command (char *arg
, int from_tty
)
2000 p
= xmalloc (sizeof ("make ") + strlen (arg
));
2001 strcpy (p
, "make ");
2002 strcpy (p
+ sizeof ("make ") - 1, arg
);
2005 shell_escape (p
, from_tty
);
2009 show_user_1 (struct cmd_list_element
*c
, struct ui_file
*stream
)
2011 register struct command_line
*cmdlines
;
2013 cmdlines
= c
->user_commands
;
2016 fputs_filtered ("User command ", stream
);
2017 fputs_filtered (c
->name
, stream
);
2018 fputs_filtered (":\n", stream
);
2021 print_command_lines (uiout
, cmdlines
, 1);
2022 fputs_filtered ("\n", stream
);
2026 print_command_line (cmdlines
, 4, stream
);
2027 cmdlines
= cmdlines
->next
;
2029 fputs_filtered ("\n", stream
);
2035 show_user (char *args
, int from_tty
)
2037 struct cmd_list_element
*c
;
2038 extern struct cmd_list_element
*cmdlist
;
2042 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
2043 if (c
->class != class_user
)
2044 error ("Not a user command.");
2045 show_user_1 (c
, gdb_stdout
);
2049 for (c
= cmdlist
; c
; c
= c
->next
)
2051 if (c
->class == class_user
)
2052 show_user_1 (c
, gdb_stdout
);
2058 _initialize_command (void)
2060 add_com ("shell", class_support
, shell_escape
,
2061 "Execute the rest of the line as a shell command. \n\
2062 With no arguments, run an inferior shell.");
2064 /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
2065 be a really useful feature. Unfortunately, the below wont do
2066 this. Instead it adds support for the form ``(gdb) ! ls''
2067 (i.e. the space is required). If the ``!'' command below is
2068 added the complains about no ``!'' command would be replaced by
2069 complains about how the ``!'' command is broken :-) */
2071 add_com_alias ("!", "shell", class_support
, 0);
2073 add_com ("make", class_support
, make_command
,
2074 "Run the ``make'' program using the rest of the line as arguments.");
2075 add_cmd ("user", no_class
, show_user
,
2076 "Show definitions of user defined commands.\n\
2077 Argument is the name of the user defined command.\n\
2078 With no argument, show definitions of all user defined commands.", &showlist
);
2079 add_com ("apropos", class_support
, apropos_command
, "Search for commands matching a REGEXP");