]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/command.c
import gdb-1999-09-08 snapshot
[thirdparty/binutils-gdb.git] / gdb / command.c
1 /* Handle lists of commands, their decoding and documentation, for GDB.
2 Copyright 1986, 1989, 1990, 1991, 1998 Free Software Foundation, Inc.
3
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.
8
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.
13
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. */
18
19 #include "defs.h"
20 #include "gdbcmd.h"
21 #include "symtab.h"
22 #include "value.h"
23 #include <ctype.h>
24 #include "gdb_string.h"
25
26 #ifdef HAVE_WAIT_H
27 #include <wait.h>
28 #else
29 #ifdef HAVE_SYS_WAIT_H
30 #include <sys/wait.h>
31 #endif
32 #endif
33
34 #include "wait.h"
35
36 /* FIXME: this should be auto-configured! */
37 #ifdef __MSDOS__
38 # define CANT_FORK
39 #endif
40
41 /* Prototypes for local functions */
42
43 static void undef_cmd_error PARAMS ((char *, char *));
44
45 static void show_user PARAMS ((char *, int));
46
47 static void show_user_1 PARAMS ((struct cmd_list_element *, GDB_FILE *));
48
49 static void make_command PARAMS ((char *, int));
50
51 static void shell_escape PARAMS ((char *, int));
52
53 static int parse_binary_operation PARAMS ((char *));
54
55 static void print_doc_line PARAMS ((GDB_FILE *, char *));
56
57 static struct cmd_list_element *find_cmd PARAMS ((char *command,
58 int len,
59 struct cmd_list_element * clist,
60 int ignore_help_classes,
61 int *nfound));
62
63 void _initialize_command PARAMS ((void));
64
65 /* Add element named NAME.
66 CLASS is the top level category into which commands are broken down
67 for "help" purposes.
68 FUN should be the function to execute the command;
69 it will get a character string as argument, with leading
70 and trailing blanks already eliminated.
71
72 DOC is a documentation string for the command.
73 Its first line should be a complete sentence.
74 It should start with ? for a command that is an abbreviation
75 or with * for a command that most users don't need to know about.
76
77 Add this command to command list *LIST.
78
79 Returns a pointer to the added command (not necessarily the head
80 of *LIST). */
81
82 struct cmd_list_element *
83 add_cmd (name, class, fun, doc, list)
84 char *name;
85 enum command_class class;
86 void (*fun) PARAMS ((char *, int));
87 char *doc;
88 struct cmd_list_element **list;
89 {
90 register struct cmd_list_element *c
91 = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
92 struct cmd_list_element *p;
93
94 delete_cmd (name, list);
95
96 if (*list == NULL || STRCMP ((*list)->name, name) >= 0)
97 {
98 c->next = *list;
99 *list = c;
100 }
101 else
102 {
103 p = *list;
104 while (p->next && STRCMP (p->next->name, name) <= 0)
105 {
106 p = p->next;
107 }
108 c->next = p->next;
109 p->next = c;
110 }
111
112 c->name = name;
113 c->class = class;
114 c->function.cfunc = fun;
115 c->doc = doc;
116 c->hook = NULL;
117 c->prefixlist = NULL;
118 c->prefixname = NULL;
119 c->allow_unknown = 0;
120 c->abbrev_flag = 0;
121 c->completer = make_symbol_completion_list;
122 c->type = not_set_cmd;
123 c->var = NULL;
124 c->var_type = var_boolean;
125 c->enums = NULL;
126 c->user_commands = NULL;
127 c->hookee = NULL;
128 c->cmd_pointer = NULL;
129
130 return c;
131 }
132
133 /* Same as above, except that the abbrev_flag is set. */
134
135 #if 0 /* Currently unused */
136
137 struct cmd_list_element *
138 add_abbrev_cmd (name, class, fun, doc, list)
139 char *name;
140 enum command_class class;
141 void (*fun) PARAMS ((char *, int));
142 char *doc;
143 struct cmd_list_element **list;
144 {
145 register struct cmd_list_element *c
146 = add_cmd (name, class, fun, doc, list);
147
148 c->abbrev_flag = 1;
149 return c;
150 }
151
152 #endif
153
154 struct cmd_list_element *
155 add_alias_cmd (name, oldname, class, abbrev_flag, list)
156 char *name;
157 char *oldname;
158 enum command_class class;
159 int abbrev_flag;
160 struct cmd_list_element **list;
161 {
162 /* Must do this since lookup_cmd tries to side-effect its first arg */
163 char *copied_name;
164 register struct cmd_list_element *old;
165 register struct cmd_list_element *c;
166 copied_name = (char *) alloca (strlen (oldname) + 1);
167 strcpy (copied_name, oldname);
168 old = lookup_cmd (&copied_name, *list, "", 1, 1);
169
170 if (old == 0)
171 {
172 delete_cmd (name, list);
173 return 0;
174 }
175
176 c = add_cmd (name, class, old->function.cfunc, old->doc, list);
177 c->prefixlist = old->prefixlist;
178 c->prefixname = old->prefixname;
179 c->allow_unknown = old->allow_unknown;
180 c->abbrev_flag = abbrev_flag;
181 c->cmd_pointer = old;
182 return c;
183 }
184
185 /* Like add_cmd but adds an element for a command prefix:
186 a name that should be followed by a subcommand to be looked up
187 in another command list. PREFIXLIST should be the address
188 of the variable containing that list. */
189
190 struct cmd_list_element *
191 add_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
192 allow_unknown, list)
193 char *name;
194 enum command_class class;
195 void (*fun) PARAMS ((char *, int));
196 char *doc;
197 struct cmd_list_element **prefixlist;
198 char *prefixname;
199 int allow_unknown;
200 struct cmd_list_element **list;
201 {
202 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
203 c->prefixlist = prefixlist;
204 c->prefixname = prefixname;
205 c->allow_unknown = allow_unknown;
206 return c;
207 }
208
209 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
210
211 struct cmd_list_element *
212 add_abbrev_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
213 allow_unknown, list)
214 char *name;
215 enum command_class class;
216 void (*fun) PARAMS ((char *, int));
217 char *doc;
218 struct cmd_list_element **prefixlist;
219 char *prefixname;
220 int allow_unknown;
221 struct cmd_list_element **list;
222 {
223 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
224 c->prefixlist = prefixlist;
225 c->prefixname = prefixname;
226 c->allow_unknown = allow_unknown;
227 c->abbrev_flag = 1;
228 return c;
229 }
230
231 /* This is an empty "cfunc". */
232 void
233 not_just_help_class_command (args, from_tty)
234 char *args;
235 int from_tty;
236 {
237 }
238
239 /* This is an empty "sfunc". */
240 static void empty_sfunc PARAMS ((char *, int, struct cmd_list_element *));
241
242 static void
243 empty_sfunc (args, from_tty, c)
244 char *args;
245 int from_tty;
246 struct cmd_list_element *c;
247 {
248 }
249
250 /* Add element named NAME to command list LIST (the list for set
251 or some sublist thereof).
252 CLASS is as in add_cmd.
253 VAR_TYPE is the kind of thing we are setting.
254 VAR is address of the variable being controlled by this command.
255 DOC is the documentation string. */
256
257 struct cmd_list_element *
258 add_set_cmd (name, class, var_type, var, doc, list)
259 char *name;
260 enum command_class class;
261 var_types var_type;
262 char *var;
263 char *doc;
264 struct cmd_list_element **list;
265 {
266 struct cmd_list_element *c
267 = add_cmd (name, class, NO_FUNCTION, doc, list);
268
269 c->type = set_cmd;
270 c->var_type = var_type;
271 c->var = var;
272 /* This needs to be something besides NO_FUNCTION so that this isn't
273 treated as a help class. */
274 c->function.sfunc = empty_sfunc;
275 return c;
276 }
277
278 /* Add element named NAME to command list LIST (the list for set
279 or some sublist thereof).
280 CLASS is as in add_cmd.
281 ENUMLIST is a list of strings which may follow NAME.
282 VAR is address of the variable which will contain the matching string
283 (from ENUMLIST).
284 DOC is the documentation string. */
285
286 struct cmd_list_element *
287 add_set_enum_cmd (name, class, enumlist, var, doc, list)
288 char *name;
289 enum command_class class;
290 char *enumlist[];
291 char *var;
292 char *doc;
293 struct cmd_list_element **list;
294 {
295 struct cmd_list_element *c
296 = add_set_cmd (name, class, var_enum, var, doc, list);
297 c->enums = enumlist;
298
299 return c;
300 }
301
302 /* Where SETCMD has already been added, add the corresponding show
303 command to LIST and return a pointer to the added command (not
304 necessarily the head of LIST). */
305 struct cmd_list_element *
306 add_show_from_set (setcmd, list)
307 struct cmd_list_element *setcmd;
308 struct cmd_list_element **list;
309 {
310 struct cmd_list_element *showcmd =
311 (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
312 struct cmd_list_element *p;
313
314 memcpy (showcmd, setcmd, sizeof (struct cmd_list_element));
315 delete_cmd (showcmd->name, list);
316 showcmd->type = show_cmd;
317
318 /* Replace "set " at start of docstring with "show ". */
319 if (setcmd->doc[0] == 'S' && setcmd->doc[1] == 'e'
320 && setcmd->doc[2] == 't' && setcmd->doc[3] == ' ')
321 showcmd->doc = concat ("Show ", setcmd->doc + 4, NULL);
322 else
323 fprintf_unfiltered (gdb_stderr, "GDB internal error: Bad docstring for set command\n");
324
325 if (*list == NULL || STRCMP ((*list)->name, showcmd->name) >= 0)
326 {
327 showcmd->next = *list;
328 *list = showcmd;
329 }
330 else
331 {
332 p = *list;
333 while (p->next && STRCMP (p->next->name, showcmd->name) <= 0)
334 {
335 p = p->next;
336 }
337 showcmd->next = p->next;
338 p->next = showcmd;
339 }
340
341 return showcmd;
342 }
343
344 /* Remove the command named NAME from the command list. */
345
346 void
347 delete_cmd (name, list)
348 char *name;
349 struct cmd_list_element **list;
350 {
351 register struct cmd_list_element *c;
352 struct cmd_list_element *p;
353
354 while (*list && STREQ ((*list)->name, name))
355 {
356 if ((*list)->hookee)
357 (*list)->hookee->hook = 0; /* Hook slips out of its mouth */
358 p = (*list)->next;
359 free ((PTR) * list);
360 *list = p;
361 }
362
363 if (*list)
364 for (c = *list; c->next;)
365 {
366 if (STREQ (c->next->name, name))
367 {
368 if (c->next->hookee)
369 c->next->hookee->hook = 0; /* hooked cmd gets away. */
370 p = c->next->next;
371 free ((PTR) c->next);
372 c->next = p;
373 }
374 else
375 c = c->next;
376 }
377 }
378
379 /* This command really has to deal with two things:
380 * 1) I want documentation on *this string* (usually called by
381 * "help commandname").
382 * 2) I want documentation on *this list* (usually called by
383 * giving a command that requires subcommands. Also called by saying
384 * just "help".)
385 *
386 * I am going to split this into two seperate comamnds, help_cmd and
387 * help_list.
388 */
389
390 void
391 help_cmd (command, stream)
392 char *command;
393 GDB_FILE *stream;
394 {
395 struct cmd_list_element *c;
396 extern struct cmd_list_element *cmdlist;
397
398 if (!command)
399 {
400 help_list (cmdlist, "", all_classes, stream);
401 return;
402 }
403
404 c = lookup_cmd (&command, cmdlist, "", 0, 0);
405
406 if (c == 0)
407 return;
408
409 /* There are three cases here.
410 If c->prefixlist is nonzero, we have a prefix command.
411 Print its documentation, then list its subcommands.
412
413 If c->function is nonzero, we really have a command.
414 Print its documentation and return.
415
416 If c->function is zero, we have a class name.
417 Print its documentation (as if it were a command)
418 and then set class to the number of this class
419 so that the commands in the class will be listed. */
420
421 fputs_filtered (c->doc, stream);
422 fputs_filtered ("\n", stream);
423
424 if (c->prefixlist == 0 && c->function.cfunc != NULL)
425 return;
426 fprintf_filtered (stream, "\n");
427
428 /* If this is a prefix command, print it's subcommands */
429 if (c->prefixlist)
430 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
431
432 /* If this is a class name, print all of the commands in the class */
433 if (c->function.cfunc == NULL)
434 help_list (cmdlist, "", c->class, stream);
435
436 if (c->hook)
437 fprintf_filtered (stream, "\nThis command has a hook defined: %s\n",
438 c->hook->name);
439 }
440
441 /*
442 * Get a specific kind of help on a command list.
443 *
444 * LIST is the list.
445 * CMDTYPE is the prefix to use in the title string.
446 * CLASS is the class with which to list the nodes of this list (see
447 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
448 * everything, ALL_CLASSES for just classes, and non-negative for only things
449 * in a specific class.
450 * and STREAM is the output stream on which to print things.
451 * If you call this routine with a class >= 0, it recurses.
452 */
453 void
454 help_list (list, cmdtype, class, stream)
455 struct cmd_list_element *list;
456 char *cmdtype;
457 enum command_class class;
458 GDB_FILE *stream;
459 {
460 int len;
461 char *cmdtype1, *cmdtype2;
462
463 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
464 len = strlen (cmdtype);
465 cmdtype1 = (char *) alloca (len + 1);
466 cmdtype1[0] = 0;
467 cmdtype2 = (char *) alloca (len + 4);
468 cmdtype2[0] = 0;
469 if (len)
470 {
471 cmdtype1[0] = ' ';
472 strncpy (cmdtype1 + 1, cmdtype, len - 1);
473 cmdtype1[len] = 0;
474 strncpy (cmdtype2, cmdtype, len - 1);
475 strcpy (cmdtype2 + len - 1, " sub");
476 }
477
478 if (class == all_classes)
479 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
480 else
481 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
482
483 help_cmd_list (list, class, cmdtype, (int) class >= 0, stream);
484
485 if (class == all_classes)
486 fprintf_filtered (stream, "\n\
487 Type \"help%s\" followed by a class name for a list of commands in that class.",
488 cmdtype1);
489
490 fprintf_filtered (stream, "\n\
491 Type \"help%s\" followed by %scommand name for full documentation.\n\
492 Command name abbreviations are allowed if unambiguous.\n",
493 cmdtype1, cmdtype2);
494 }
495
496 /* Print only the first line of STR on STREAM. */
497 static void
498 print_doc_line (stream, str)
499 GDB_FILE *stream;
500 char *str;
501 {
502 static char *line_buffer = 0;
503 static int line_size;
504 register char *p;
505
506 if (!line_buffer)
507 {
508 line_size = 80;
509 line_buffer = (char *) xmalloc (line_size);
510 }
511
512 p = str;
513 while (*p && *p != '\n' && *p != '.' && *p != ',')
514 p++;
515 if (p - str > line_size - 1)
516 {
517 line_size = p - str + 1;
518 free ((PTR) line_buffer);
519 line_buffer = (char *) xmalloc (line_size);
520 }
521 strncpy (line_buffer, str, p - str);
522 line_buffer[p - str] = '\0';
523 if (islower (line_buffer[0]))
524 line_buffer[0] = toupper (line_buffer[0]);
525 fputs_filtered (line_buffer, stream);
526 }
527
528 /*
529 * Implement a help command on command list LIST.
530 * RECURSE should be non-zero if this should be done recursively on
531 * all sublists of LIST.
532 * PREFIX is the prefix to print before each command name.
533 * STREAM is the stream upon which the output should be written.
534 * CLASS should be:
535 * A non-negative class number to list only commands in that
536 * class.
537 * ALL_COMMANDS to list all commands in list.
538 * ALL_CLASSES to list all classes in list.
539 *
540 * Note that RECURSE will be active on *all* sublists, not just the
541 * ones selected by the criteria above (ie. the selection mechanism
542 * is at the low level, not the high-level).
543 */
544 void
545 help_cmd_list (list, class, prefix, recurse, stream)
546 struct cmd_list_element *list;
547 enum command_class class;
548 char *prefix;
549 int recurse;
550 GDB_FILE *stream;
551 {
552 register struct cmd_list_element *c;
553
554 for (c = list; c; c = c->next)
555 {
556 if (c->abbrev_flag == 0 &&
557 (class == all_commands
558 || (class == all_classes && c->function.cfunc == NULL)
559 || (class == c->class && c->function.cfunc != NULL)))
560 {
561 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
562 print_doc_line (stream, c->doc);
563 fputs_filtered ("\n", stream);
564 }
565 if (recurse
566 && c->prefixlist != 0
567 && c->abbrev_flag == 0)
568 help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream);
569 }
570 }
571 \f
572
573 /* Search the input clist for 'command'. Return the command if
574 found (or NULL if not), and return the number of commands
575 found in nfound */
576
577 static struct cmd_list_element *
578 find_cmd (command, len, clist, ignore_help_classes, nfound)
579 char *command;
580 int len;
581 struct cmd_list_element *clist;
582 int ignore_help_classes;
583 int *nfound;
584 {
585 struct cmd_list_element *found, *c;
586
587 found = (struct cmd_list_element *) NULL;
588 *nfound = 0;
589 for (c = clist; c; c = c->next)
590 if (!strncmp (command, c->name, len)
591 && (!ignore_help_classes || c->function.cfunc))
592 {
593 found = c;
594 (*nfound)++;
595 if (c->name[len] == '\0')
596 {
597 *nfound = 1;
598 break;
599 }
600 }
601 return found;
602 }
603
604 /* This routine takes a line of TEXT and a CLIST in which to start the
605 lookup. When it returns it will have incremented the text pointer past
606 the section of text it matched, set *RESULT_LIST to point to the list in
607 which the last word was matched, and will return a pointer to the cmd
608 list element which the text matches. It will return NULL if no match at
609 all was possible. It will return -1 (cast appropriately, ick) if ambigous
610 matches are possible; in this case *RESULT_LIST will be set to point to
611 the list in which there are ambiguous choices (and *TEXT will be set to
612 the ambiguous text string).
613
614 If the located command was an abbreviation, this routine returns the base
615 command of the abbreviation.
616
617 It does no error reporting whatsoever; control will always return
618 to the superior routine.
619
620 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
621 at the prefix_command (ie. the best match) *or* (special case) will be NULL
622 if no prefix command was ever found. For example, in the case of "info a",
623 "info" matches without ambiguity, but "a" could be "args" or "address", so
624 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
625 RESULT_LIST should not be interpeted as a pointer to the beginning of a
626 list; it simply points to a specific command. In the case of an ambiguous
627 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
628 "info t" can be "info types" or "info target"; upon return *TEXT has been
629 advanced past "info ").
630
631 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
632 affect the operation).
633
634 This routine does *not* modify the text pointed to by TEXT.
635
636 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
637 are actually help classes rather than commands (i.e. the function field of
638 the struct cmd_list_element is NULL). */
639
640 struct cmd_list_element *
641 lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
642 char **text;
643 struct cmd_list_element *clist, **result_list;
644 int ignore_help_classes;
645 {
646 char *p, *command;
647 int len, tmp, nfound;
648 struct cmd_list_element *found, *c;
649
650 while (**text == ' ' || **text == '\t')
651 (*text)++;
652
653 /* Treating underscores as part of command words is important
654 so that "set args_foo()" doesn't get interpreted as
655 "set args _foo()". */
656 for (p = *text;
657 *p && (isalnum (*p) || *p == '-' || *p == '_' ||
658 (tui_version &&
659 (*p == '+' || *p == '<' || *p == '>' || *p == '$')) ||
660 (xdb_commands && (*p == '!' || *p == '/' || *p == '?')));
661 p++)
662 ;
663
664 /* If nothing but whitespace, return 0. */
665 if (p == *text)
666 return 0;
667
668 len = p - *text;
669
670 /* *text and p now bracket the first command word to lookup (and
671 it's length is len). We copy this into a local temporary */
672
673
674 command = (char *) alloca (len + 1);
675 for (tmp = 0; tmp < len; tmp++)
676 {
677 char x = (*text)[tmp];
678 command[tmp] = x;
679 }
680 command[len] = '\0';
681
682 /* Look it up. */
683 found = 0;
684 nfound = 0;
685 found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
686
687 /*
688 ** We didn't find the command in the entered case, so lower case it
689 ** and search again.
690 */
691 if (!found || nfound == 0)
692 {
693 for (tmp = 0; tmp < len; tmp++)
694 {
695 char x = command[tmp];
696 command[tmp] = isupper (x) ? tolower (x) : x;
697 }
698 found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
699 }
700
701 /* If nothing matches, we have a simple failure. */
702 if (nfound == 0)
703 return 0;
704
705 if (nfound > 1)
706 {
707 if (result_list != NULL)
708 /* Will be modified in calling routine
709 if we know what the prefix command is. */
710 *result_list = 0;
711 return (struct cmd_list_element *) -1; /* Ambiguous. */
712 }
713
714 /* We've matched something on this list. Move text pointer forward. */
715
716 *text = p;
717
718 /* If this was an abbreviation, use the base command instead. */
719
720 if (found->cmd_pointer)
721 found = found->cmd_pointer;
722
723 /* If we found a prefix command, keep looking. */
724
725 if (found->prefixlist)
726 {
727 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
728 ignore_help_classes);
729 if (!c)
730 {
731 /* Didn't find anything; this is as far as we got. */
732 if (result_list != NULL)
733 *result_list = clist;
734 return found;
735 }
736 else if (c == (struct cmd_list_element *) -1)
737 {
738 /* We've gotten this far properly, but the next step
739 is ambiguous. We need to set the result list to the best
740 we've found (if an inferior hasn't already set it). */
741 if (result_list != NULL)
742 if (!*result_list)
743 /* This used to say *result_list = *found->prefixlist
744 If that was correct, need to modify the documentation
745 at the top of this function to clarify what is supposed
746 to be going on. */
747 *result_list = found;
748 return c;
749 }
750 else
751 {
752 /* We matched! */
753 return c;
754 }
755 }
756 else
757 {
758 if (result_list != NULL)
759 *result_list = clist;
760 return found;
761 }
762 }
763
764 /* All this hair to move the space to the front of cmdtype */
765
766 static void
767 undef_cmd_error (cmdtype, q)
768 char *cmdtype, *q;
769 {
770 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
771 cmdtype,
772 q,
773 *cmdtype ? " " : "",
774 strlen (cmdtype) - 1,
775 cmdtype);
776 }
777
778 /* Look up the contents of *LINE as a command in the command list LIST.
779 LIST is a chain of struct cmd_list_element's.
780 If it is found, return the struct cmd_list_element for that command
781 and update *LINE to point after the command name, at the first argument.
782 If not found, call error if ALLOW_UNKNOWN is zero
783 otherwise (or if error returns) return zero.
784 Call error if specified command is ambiguous,
785 unless ALLOW_UNKNOWN is negative.
786 CMDTYPE precedes the word "command" in the error message.
787
788 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
789 elements which are actually help classes rather than commands (i.e.
790 the function field of the struct cmd_list_element is 0). */
791
792 struct cmd_list_element *
793 lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
794 char **line;
795 struct cmd_list_element *list;
796 char *cmdtype;
797 int allow_unknown;
798 int ignore_help_classes;
799 {
800 struct cmd_list_element *last_list = 0;
801 struct cmd_list_element *c =
802 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
803 #if 0
804 /* This is wrong for complete_command. */
805 char *ptr = (*line) + strlen (*line) - 1;
806
807 /* Clear off trailing whitespace. */
808 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
809 ptr--;
810 *(ptr + 1) = '\0';
811 #endif
812
813 if (!c)
814 {
815 if (!allow_unknown)
816 {
817 if (!*line)
818 error ("Lack of needed %scommand", cmdtype);
819 else
820 {
821 char *p = *line, *q;
822
823 while (isalnum (*p) || *p == '-')
824 p++;
825
826 q = (char *) alloca (p - *line + 1);
827 strncpy (q, *line, p - *line);
828 q[p - *line] = '\0';
829 undef_cmd_error (cmdtype, q);
830 }
831 }
832 else
833 return 0;
834 }
835 else if (c == (struct cmd_list_element *) -1)
836 {
837 /* Ambigous. Local values should be off prefixlist or called
838 values. */
839 int local_allow_unknown = (last_list ? last_list->allow_unknown :
840 allow_unknown);
841 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
842 struct cmd_list_element *local_list =
843 (last_list ? *(last_list->prefixlist) : list);
844
845 if (local_allow_unknown < 0)
846 {
847 if (last_list)
848 return last_list; /* Found something. */
849 else
850 return 0; /* Found nothing. */
851 }
852 else
853 {
854 /* Report as error. */
855 int amb_len;
856 char ambbuf[100];
857
858 for (amb_len = 0;
859 ((*line)[amb_len] && (*line)[amb_len] != ' '
860 && (*line)[amb_len] != '\t');
861 amb_len++)
862 ;
863
864 ambbuf[0] = 0;
865 for (c = local_list; c; c = c->next)
866 if (!strncmp (*line, c->name, amb_len))
867 {
868 if (strlen (ambbuf) + strlen (c->name) + 6 < (int) sizeof ambbuf)
869 {
870 if (strlen (ambbuf))
871 strcat (ambbuf, ", ");
872 strcat (ambbuf, c->name);
873 }
874 else
875 {
876 strcat (ambbuf, "..");
877 break;
878 }
879 }
880 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
881 *line, ambbuf);
882 return 0; /* lint */
883 }
884 }
885 else
886 {
887 /* We've got something. It may still not be what the caller
888 wants (if this command *needs* a subcommand). */
889 while (**line == ' ' || **line == '\t')
890 (*line)++;
891
892 if (c->prefixlist && **line && !c->allow_unknown)
893 undef_cmd_error (c->prefixname, *line);
894
895 /* Seems to be what he wants. Return it. */
896 return c;
897 }
898 return 0;
899 }
900
901 #if 0
902 /* Look up the contents of *LINE as a command in the command list LIST.
903 LIST is a chain of struct cmd_list_element's.
904 If it is found, return the struct cmd_list_element for that command
905 and update *LINE to point after the command name, at the first argument.
906 If not found, call error if ALLOW_UNKNOWN is zero
907 otherwise (or if error returns) return zero.
908 Call error if specified command is ambiguous,
909 unless ALLOW_UNKNOWN is negative.
910 CMDTYPE precedes the word "command" in the error message. */
911
912 struct cmd_list_element *
913 lookup_cmd (line, list, cmdtype, allow_unknown)
914 char **line;
915 struct cmd_list_element *list;
916 char *cmdtype;
917 int allow_unknown;
918 {
919 register char *p;
920 register struct cmd_list_element *c, *found;
921 int nfound;
922 char ambbuf[100];
923 char *processed_cmd;
924 int i, cmd_len;
925
926 /* Skip leading whitespace. */
927
928 while (**line == ' ' || **line == '\t')
929 (*line)++;
930
931 /* Clear out trailing whitespace. */
932
933 p = *line + strlen (*line);
934 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
935 p--;
936 *p = 0;
937
938 /* Find end of command name. */
939
940 p = *line;
941 while (*p == '-' || isalnum (*p))
942 p++;
943
944 /* Look up the command name.
945 If exact match, keep that.
946 Otherwise, take command abbreviated, if unique. Note that (in my
947 opinion) a null string does *not* indicate ambiguity; simply the
948 end of the argument. */
949
950 if (p == *line)
951 {
952 if (!allow_unknown)
953 error ("Lack of needed %scommand", cmdtype);
954 return 0;
955 }
956
957 /* Copy over to a local buffer, converting to lowercase on the way.
958 This is in case the command being parsed is a subcommand which
959 doesn't match anything, and that's ok. We want the original
960 untouched for the routine of the original command. */
961
962 processed_cmd = (char *) alloca (p - *line + 1);
963 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
964 {
965 char x = (*line)[cmd_len];
966 if (isupper (x))
967 processed_cmd[cmd_len] = tolower (x);
968 else
969 processed_cmd[cmd_len] = x;
970 }
971 processed_cmd[cmd_len] = '\0';
972
973 /* Check all possibilities in the current command list. */
974 found = 0;
975 nfound = 0;
976 for (c = list; c; c = c->next)
977 {
978 if (!strncmp (processed_cmd, c->name, cmd_len))
979 {
980 found = c;
981 nfound++;
982 if (c->name[cmd_len] == 0)
983 {
984 nfound = 1;
985 break;
986 }
987 }
988 }
989
990 /* Report error for undefined command name. */
991
992 if (nfound != 1)
993 {
994 if (nfound > 1 && allow_unknown >= 0)
995 {
996 ambbuf[0] = 0;
997 for (c = list; c; c = c->next)
998 if (!strncmp (processed_cmd, c->name, cmd_len))
999 {
1000 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
1001 {
1002 if (strlen (ambbuf))
1003 strcat (ambbuf, ", ");
1004 strcat (ambbuf, c->name);
1005 }
1006 else
1007 {
1008 strcat (ambbuf, "..");
1009 break;
1010 }
1011 }
1012 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
1013 processed_cmd, ambbuf);
1014 }
1015 else if (!allow_unknown)
1016 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
1017 return 0;
1018 }
1019
1020 /* Skip whitespace before the argument. */
1021
1022 while (*p == ' ' || *p == '\t')
1023 p++;
1024 *line = p;
1025
1026 if (found->prefixlist && *p)
1027 {
1028 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
1029 found->allow_unknown);
1030 if (c)
1031 return c;
1032 }
1033
1034 return found;
1035 }
1036 #endif
1037
1038 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1039
1040 /* Return a vector of char pointers which point to the different
1041 possible completions in LIST of TEXT.
1042
1043 WORD points in the same buffer as TEXT, and completions should be
1044 returned relative to this position. For example, suppose TEXT is "foo"
1045 and we want to complete to "foobar". If WORD is "oo", return
1046 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1047
1048 char **
1049 complete_on_cmdlist (list, text, word)
1050 struct cmd_list_element *list;
1051 char *text;
1052 char *word;
1053 {
1054 struct cmd_list_element *ptr;
1055 char **matchlist;
1056 int sizeof_matchlist;
1057 int matches;
1058 int textlen = strlen (text);
1059
1060 sizeof_matchlist = 10;
1061 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
1062 matches = 0;
1063
1064 for (ptr = list; ptr; ptr = ptr->next)
1065 if (!strncmp (ptr->name, text, textlen)
1066 && !ptr->abbrev_flag
1067 && (ptr->function.cfunc
1068 || ptr->prefixlist))
1069 {
1070 if (matches == sizeof_matchlist)
1071 {
1072 sizeof_matchlist *= 2;
1073 matchlist = (char **) xrealloc ((char *) matchlist,
1074 (sizeof_matchlist
1075 * sizeof (char *)));
1076 }
1077
1078 matchlist[matches] = (char *)
1079 xmalloc (strlen (word) + strlen (ptr->name) + 1);
1080 if (word == text)
1081 strcpy (matchlist[matches], ptr->name);
1082 else if (word > text)
1083 {
1084 /* Return some portion of ptr->name. */
1085 strcpy (matchlist[matches], ptr->name + (word - text));
1086 }
1087 else
1088 {
1089 /* Return some of text plus ptr->name. */
1090 strncpy (matchlist[matches], word, text - word);
1091 matchlist[matches][text - word] = '\0';
1092 strcat (matchlist[matches], ptr->name);
1093 }
1094 ++matches;
1095 }
1096
1097 if (matches == 0)
1098 {
1099 free ((PTR) matchlist);
1100 matchlist = 0;
1101 }
1102 else
1103 {
1104 matchlist = (char **) xrealloc ((char *) matchlist, ((matches + 1)
1105 * sizeof (char *)));
1106 matchlist[matches] = (char *) 0;
1107 }
1108
1109 return matchlist;
1110 }
1111
1112 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1113
1114 /* Return a vector of char pointers which point to the different
1115 possible completions in CMD of TEXT.
1116
1117 WORD points in the same buffer as TEXT, and completions should be
1118 returned relative to this position. For example, suppose TEXT is "foo"
1119 and we want to complete to "foobar". If WORD is "oo", return
1120 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1121
1122 char **
1123 complete_on_enum (enumlist, text, word)
1124 char **enumlist;
1125 char *text;
1126 char *word;
1127 {
1128 char **matchlist;
1129 int sizeof_matchlist;
1130 int matches;
1131 int textlen = strlen (text);
1132 int i;
1133 char *name;
1134
1135 sizeof_matchlist = 10;
1136 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
1137 matches = 0;
1138
1139 for (i = 0; (name = enumlist[i]) != NULL; i++)
1140 if (strncmp (name, text, textlen) == 0)
1141 {
1142 if (matches == sizeof_matchlist)
1143 {
1144 sizeof_matchlist *= 2;
1145 matchlist = (char **) xrealloc ((char *) matchlist,
1146 (sizeof_matchlist
1147 * sizeof (char *)));
1148 }
1149
1150 matchlist[matches] = (char *)
1151 xmalloc (strlen (word) + strlen (name) + 1);
1152 if (word == text)
1153 strcpy (matchlist[matches], name);
1154 else if (word > text)
1155 {
1156 /* Return some portion of name. */
1157 strcpy (matchlist[matches], name + (word - text));
1158 }
1159 else
1160 {
1161 /* Return some of text plus name. */
1162 strncpy (matchlist[matches], word, text - word);
1163 matchlist[matches][text - word] = '\0';
1164 strcat (matchlist[matches], name);
1165 }
1166 ++matches;
1167 }
1168
1169 if (matches == 0)
1170 {
1171 free ((PTR) matchlist);
1172 matchlist = 0;
1173 }
1174 else
1175 {
1176 matchlist = (char **) xrealloc ((char *) matchlist, ((matches + 1)
1177 * sizeof (char *)));
1178 matchlist[matches] = (char *) 0;
1179 }
1180
1181 return matchlist;
1182 }
1183
1184 static int
1185 parse_binary_operation (arg)
1186 char *arg;
1187 {
1188 int length;
1189
1190 if (!arg || !*arg)
1191 return 1;
1192
1193 length = strlen (arg);
1194
1195 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
1196 length--;
1197
1198 if (!strncmp (arg, "on", length)
1199 || !strncmp (arg, "1", length)
1200 || !strncmp (arg, "yes", length))
1201 return 1;
1202 else if (!strncmp (arg, "off", length)
1203 || !strncmp (arg, "0", length)
1204 || !strncmp (arg, "no", length))
1205 return 0;
1206 else
1207 {
1208 error ("\"on\" or \"off\" expected.");
1209 return 0;
1210 }
1211 }
1212
1213 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1214 of the argument, and FROM_TTY is nonzero if this command is being entered
1215 directly by the user (i.e. these are just like any other
1216 command). C is the command list element for the command. */
1217 void
1218 do_setshow_command (arg, from_tty, c)
1219 char *arg;
1220 int from_tty;
1221 struct cmd_list_element *c;
1222 {
1223 if (c->type == set_cmd)
1224 {
1225 switch (c->var_type)
1226 {
1227 case var_string:
1228 {
1229 char *new;
1230 char *p;
1231 char *q;
1232 int ch;
1233
1234 if (arg == NULL)
1235 arg = "";
1236 new = (char *) xmalloc (strlen (arg) + 2);
1237 p = arg;
1238 q = new;
1239 while ((ch = *p++) != '\000')
1240 {
1241 if (ch == '\\')
1242 {
1243 /* \ at end of argument is used after spaces
1244 so they won't be lost. */
1245 /* This is obsolete now that we no longer strip
1246 trailing whitespace and actually, the backslash
1247 didn't get here in my test, readline or
1248 something did something funky with a backslash
1249 right before a newline. */
1250 if (*p == 0)
1251 break;
1252 ch = parse_escape (&p);
1253 if (ch == 0)
1254 break; /* C loses */
1255 else if (ch > 0)
1256 *q++ = ch;
1257 }
1258 else
1259 *q++ = ch;
1260 }
1261 #if 0
1262 if (*(p - 1) != '\\')
1263 *q++ = ' ';
1264 #endif
1265 *q++ = '\0';
1266 new = (char *) xrealloc (new, q - new);
1267 if (*(char **) c->var != NULL)
1268 free (*(char **) c->var);
1269 *(char **) c->var = new;
1270 }
1271 break;
1272 case var_string_noescape:
1273 if (arg == NULL)
1274 arg = "";
1275 if (*(char **) c->var != NULL)
1276 free (*(char **) c->var);
1277 *(char **) c->var = savestring (arg, strlen (arg));
1278 break;
1279 case var_filename:
1280 if (arg == NULL)
1281 error_no_arg ("filename to set it to.");
1282 if (*(char **) c->var != NULL)
1283 free (*(char **) c->var);
1284 *(char **) c->var = tilde_expand (arg);
1285 break;
1286 case var_boolean:
1287 *(int *) c->var = parse_binary_operation (arg);
1288 break;
1289 case var_uinteger:
1290 if (arg == NULL)
1291 error_no_arg ("integer to set it to.");
1292 *(unsigned int *) c->var = parse_and_eval_address (arg);
1293 if (*(unsigned int *) c->var == 0)
1294 *(unsigned int *) c->var = UINT_MAX;
1295 break;
1296 case var_integer:
1297 {
1298 unsigned int val;
1299 if (arg == NULL)
1300 error_no_arg ("integer to set it to.");
1301 val = parse_and_eval_address (arg);
1302 if (val == 0)
1303 *(int *) c->var = INT_MAX;
1304 else if (val >= INT_MAX)
1305 error ("integer %u out of range", val);
1306 else
1307 *(int *) c->var = val;
1308 break;
1309 }
1310 case var_zinteger:
1311 if (arg == NULL)
1312 error_no_arg ("integer to set it to.");
1313 *(int *) c->var = parse_and_eval_address (arg);
1314 break;
1315 case var_enum:
1316 {
1317 int i;
1318 int len;
1319 int nmatches;
1320 char *match = NULL;
1321 char *p;
1322
1323 /* if no argument was supplied, print an informative error message */
1324 if (arg == NULL)
1325 {
1326 char msg[1024];
1327 strcpy (msg, "Requires an argument. Valid arguments are ");
1328 for (i = 0; c->enums[i]; i++)
1329 {
1330 if (i != 0)
1331 strcat (msg, ", ");
1332 strcat (msg, c->enums[i]);
1333 }
1334 strcat (msg, ".");
1335 error (msg);
1336 }
1337
1338 p = strchr (arg, ' ');
1339
1340 if (p)
1341 len = p - arg;
1342 else
1343 len = strlen (arg);
1344
1345 nmatches = 0;
1346 for (i = 0; c->enums[i]; i++)
1347 if (strncmp (arg, c->enums[i], len) == 0)
1348 {
1349 match = c->enums[i];
1350 nmatches++;
1351 }
1352
1353 if (nmatches <= 0)
1354 error ("Undefined item: \"%s\".", arg);
1355
1356 if (nmatches > 1)
1357 error ("Ambiguous item \"%s\".", arg);
1358
1359 *(char **) c->var = match;
1360 }
1361 break;
1362 default:
1363 error ("gdb internal error: bad var_type in do_setshow_command");
1364 }
1365 }
1366 else if (c->type == show_cmd)
1367 {
1368 /* Print doc minus "show" at start. */
1369 print_doc_line (gdb_stdout, c->doc + 5);
1370
1371 fputs_filtered (" is ", gdb_stdout);
1372 wrap_here (" ");
1373 switch (c->var_type)
1374 {
1375 case var_string:
1376 {
1377 fputs_filtered ("\"", gdb_stdout);
1378 if (*(unsigned char **) c->var)
1379 fputstr_filtered (*(unsigned char **) c->var, '"', gdb_stdout);
1380 fputs_filtered ("\"", gdb_stdout);
1381 }
1382 break;
1383 case var_string_noescape:
1384 case var_filename:
1385 case var_enum:
1386 fputs_filtered ("\"", gdb_stdout);
1387 if (*(char **) c->var)
1388 fputs_filtered (*(char **) c->var, gdb_stdout);
1389 fputs_filtered ("\"", gdb_stdout);
1390 break;
1391 case var_boolean:
1392 fputs_filtered (*(int *) c->var ? "on" : "off", gdb_stdout);
1393 break;
1394 case var_uinteger:
1395 if (*(unsigned int *) c->var == UINT_MAX)
1396 {
1397 fputs_filtered ("unlimited", gdb_stdout);
1398 break;
1399 }
1400 /* else fall through */
1401 case var_zinteger:
1402 fprintf_filtered (gdb_stdout, "%u", *(unsigned int *) c->var);
1403 break;
1404 case var_integer:
1405 if (*(int *) c->var == INT_MAX)
1406 {
1407 fputs_filtered ("unlimited", gdb_stdout);
1408 }
1409 else
1410 fprintf_filtered (gdb_stdout, "%d", *(int *) c->var);
1411 break;
1412
1413 default:
1414 error ("gdb internal error: bad var_type in do_setshow_command");
1415 }
1416 fputs_filtered (".\n", gdb_stdout);
1417 }
1418 else
1419 error ("gdb internal error: bad cmd_type in do_setshow_command");
1420 (*c->function.sfunc) (NULL, from_tty, c);
1421 if (c->type == set_cmd && set_hook)
1422 set_hook (c);
1423 }
1424
1425 /* Show all the settings in a list of show commands. */
1426
1427 void
1428 cmd_show_list (list, from_tty, prefix)
1429 struct cmd_list_element *list;
1430 int from_tty;
1431 char *prefix;
1432 {
1433 for (; list != NULL; list = list->next)
1434 {
1435 /* If we find a prefix, run its list, prefixing our output by its
1436 prefix (with "show " skipped). */
1437 if (list->prefixlist && !list->abbrev_flag)
1438 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1439 if (list->type == show_cmd)
1440 {
1441 fputs_filtered (prefix, gdb_stdout);
1442 fputs_filtered (list->name, gdb_stdout);
1443 fputs_filtered (": ", gdb_stdout);
1444 do_setshow_command ((char *) NULL, from_tty, list);
1445 }
1446 }
1447 }
1448
1449 /* ARGSUSED */
1450 static void
1451 shell_escape (arg, from_tty)
1452 char *arg;
1453 int from_tty;
1454 {
1455 #ifdef CANT_FORK
1456 /* If ARG is NULL, they want an inferior shell, but `system' just
1457 reports if the shell is available when passed a NULL arg. */
1458 int rc = system (arg ? arg : "");
1459
1460 if (!arg)
1461 arg = "inferior shell";
1462
1463 if (rc == -1)
1464 {
1465 fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
1466 safe_strerror (errno));
1467 gdb_flush (gdb_stderr);
1468 }
1469 else if (rc)
1470 {
1471 fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
1472 gdb_flush (gdb_stderr);
1473 }
1474 #ifdef __DJGPP__
1475 /* Make sure to return to the directory GDB thinks it is, in case the
1476 shell command we just ran changed it. */
1477 chdir (current_directory);
1478 #endif
1479 #else /* Can fork. */
1480 int rc, status, pid;
1481 char *p, *user_shell;
1482
1483 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1484 user_shell = "/bin/sh";
1485
1486 /* Get the name of the shell for arg0 */
1487 if ((p = strrchr (user_shell, '/')) == NULL)
1488 p = user_shell;
1489 else
1490 p++; /* Get past '/' */
1491
1492 if ((pid = fork ()) == 0)
1493 {
1494 if (!arg)
1495 execl (user_shell, p, 0);
1496 else
1497 execl (user_shell, p, "-c", arg, 0);
1498
1499 fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
1500 safe_strerror (errno));
1501 gdb_flush (gdb_stderr);
1502 _exit (0177);
1503 }
1504
1505 if (pid != -1)
1506 while ((rc = wait (&status)) != pid && rc != -1)
1507 ;
1508 else
1509 error ("Fork failed");
1510 #endif /* Can fork. */
1511 }
1512
1513 static void
1514 make_command (arg, from_tty)
1515 char *arg;
1516 int from_tty;
1517 {
1518 char *p;
1519
1520 if (arg == 0)
1521 p = "make";
1522 else
1523 {
1524 p = xmalloc (sizeof ("make ") + strlen (arg));
1525 strcpy (p, "make ");
1526 strcpy (p + sizeof ("make ") - 1, arg);
1527 }
1528
1529 shell_escape (p, from_tty);
1530 }
1531
1532 static void
1533 show_user_1 (c, stream)
1534 struct cmd_list_element *c;
1535 GDB_FILE *stream;
1536 {
1537 register struct command_line *cmdlines;
1538
1539 cmdlines = c->user_commands;
1540 if (!cmdlines)
1541 return;
1542 fputs_filtered ("User command ", stream);
1543 fputs_filtered (c->name, stream);
1544 fputs_filtered (":\n", stream);
1545
1546 while (cmdlines)
1547 {
1548 print_command_line (cmdlines, 4, stream);
1549 cmdlines = cmdlines->next;
1550 }
1551 fputs_filtered ("\n", stream);
1552 }
1553
1554 /* ARGSUSED */
1555 static void
1556 show_user (args, from_tty)
1557 char *args;
1558 int from_tty;
1559 {
1560 struct cmd_list_element *c;
1561 extern struct cmd_list_element *cmdlist;
1562
1563 if (args)
1564 {
1565 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1566 if (c->class != class_user)
1567 error ("Not a user command.");
1568 show_user_1 (c, gdb_stdout);
1569 }
1570 else
1571 {
1572 for (c = cmdlist; c; c = c->next)
1573 {
1574 if (c->class == class_user)
1575 show_user_1 (c, gdb_stdout);
1576 }
1577 }
1578 }
1579
1580 void
1581 _initialize_command ()
1582 {
1583 add_com ("shell", class_support, shell_escape,
1584 "Execute the rest of the line as a shell command. \n\
1585 With no arguments, run an inferior shell.");
1586
1587 if (xdb_commands)
1588 add_com_alias ("!", "shell", class_support, 0);
1589
1590 add_com ("make", class_support, make_command,
1591 "Run the ``make'' program using the rest of the line as arguments.");
1592 add_cmd ("user", no_class, show_user,
1593 "Show definitions of user defined commands.\n\
1594 Argument is the name of the user defined command.\n\
1595 With no argument, show definitions of all user defined commands.", &showlist);
1596 }