Commit | Line | Data |
---|---|---|
d318976c | 1 | /* GDB CLI commands. |
8926118c AC |
2 | |
3 | Copyright 2000, 2001, 2002 Free Software Foundation, Inc. | |
d318976c FN |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "completer.h" | |
24 | #include "target.h" /* For baud_rate, remote_debug and remote_timeout */ | |
25 | #include "gdb_wait.h" /* For shell escape implementation */ | |
f77b92bf | 26 | #include "gdb_regex.h" /* Used by apropos_command */ |
fe4e3eb8 | 27 | #include "filenames.h" /* for DOSish file names */ |
d318976c | 28 | |
d318976c | 29 | #include "ui-out.h" |
d318976c FN |
30 | |
31 | #include "top.h" | |
32 | #include "cli/cli-decode.h" | |
33 | #include "cli/cli-script.h" | |
34 | #include "cli/cli-setshow.h" | |
35 | #include "cli/cli-cmds.h" | |
36 | ||
37 | #ifndef GDBINIT_FILENAME | |
38 | #define GDBINIT_FILENAME ".gdbinit" | |
39 | #endif | |
40 | ||
d318976c FN |
41 | /* From gdb/top.c */ |
42 | ||
43 | extern void dont_repeat (void); | |
44 | ||
45 | extern void set_verbose (char *, int, struct cmd_list_element *); | |
46 | ||
47 | extern void show_history (char *, int); | |
48 | ||
49 | extern void set_history (char *, int); | |
50 | ||
51 | extern void show_commands (char *, int); | |
52 | ||
53 | /* Prototypes for local functions */ | |
54 | ||
55 | static void complete_command (char *, int); | |
56 | ||
57 | static void echo_command (char *, int); | |
58 | ||
59 | static void pwd_command (char *, int); | |
60 | ||
61 | static void show_version (char *, int); | |
62 | ||
63 | static void validate_comname (char *); | |
64 | ||
65 | static void help_command (char *, int); | |
66 | ||
67 | static void show_command (char *, int); | |
68 | ||
69 | static void info_command (char *, int); | |
70 | ||
71 | static void show_debug (char *, int); | |
72 | ||
73 | static void set_debug (char *, int); | |
74 | ||
75 | static void show_user (char *, int); | |
76 | ||
77 | static void make_command (char *, int); | |
78 | ||
79 | static void shell_escape (char *, int); | |
80 | ||
81 | void apropos_command (char *, int); | |
82 | \f | |
20f01a46 DH |
83 | /* Limit the call depth of user-defined commands */ |
84 | int max_user_call_depth; | |
85 | ||
d318976c FN |
86 | /* Define all cmd_list_elements. */ |
87 | ||
88 | /* Chain containing all defined commands. */ | |
89 | ||
90 | struct cmd_list_element *cmdlist; | |
91 | ||
92 | /* Chain containing all defined info subcommands. */ | |
93 | ||
94 | struct cmd_list_element *infolist; | |
95 | ||
96 | /* Chain containing all defined enable subcommands. */ | |
97 | ||
98 | struct cmd_list_element *enablelist; | |
99 | ||
100 | /* Chain containing all defined disable subcommands. */ | |
101 | ||
102 | struct cmd_list_element *disablelist; | |
103 | ||
104 | /* Chain containing all defined toggle subcommands. */ | |
105 | ||
106 | struct cmd_list_element *togglelist; | |
107 | ||
108 | /* Chain containing all defined stop subcommands. */ | |
109 | ||
110 | struct cmd_list_element *stoplist; | |
111 | ||
112 | /* Chain containing all defined delete subcommands. */ | |
113 | ||
114 | struct cmd_list_element *deletelist; | |
115 | ||
116 | /* Chain containing all defined "enable breakpoint" subcommands. */ | |
117 | ||
118 | struct cmd_list_element *enablebreaklist; | |
119 | ||
120 | /* Chain containing all defined set subcommands */ | |
121 | ||
122 | struct cmd_list_element *setlist; | |
123 | ||
124 | /* Chain containing all defined unset subcommands */ | |
125 | ||
126 | struct cmd_list_element *unsetlist; | |
127 | ||
128 | /* Chain containing all defined show subcommands. */ | |
129 | ||
130 | struct cmd_list_element *showlist; | |
131 | ||
132 | /* Chain containing all defined \"set history\". */ | |
133 | ||
134 | struct cmd_list_element *sethistlist; | |
135 | ||
136 | /* Chain containing all defined \"show history\". */ | |
137 | ||
138 | struct cmd_list_element *showhistlist; | |
139 | ||
140 | /* Chain containing all defined \"unset history\". */ | |
141 | ||
142 | struct cmd_list_element *unsethistlist; | |
143 | ||
144 | /* Chain containing all defined maintenance subcommands. */ | |
145 | ||
146 | struct cmd_list_element *maintenancelist; | |
147 | ||
148 | /* Chain containing all defined "maintenance info" subcommands. */ | |
149 | ||
150 | struct cmd_list_element *maintenanceinfolist; | |
151 | ||
152 | /* Chain containing all defined "maintenance print" subcommands. */ | |
153 | ||
154 | struct cmd_list_element *maintenanceprintlist; | |
155 | ||
156 | struct cmd_list_element *setprintlist; | |
157 | ||
158 | struct cmd_list_element *showprintlist; | |
159 | ||
160 | struct cmd_list_element *setdebuglist; | |
161 | ||
162 | struct cmd_list_element *showdebuglist; | |
163 | ||
164 | struct cmd_list_element *setchecklist; | |
165 | ||
166 | struct cmd_list_element *showchecklist; | |
167 | \f | |
168 | /* Utility used everywhere when at least one argument is needed and | |
169 | none is supplied. */ | |
170 | ||
171 | void | |
172 | error_no_arg (char *why) | |
173 | { | |
174 | error ("Argument required (%s).", why); | |
175 | } | |
176 | ||
177 | /* The "info" command is defined as a prefix, with allow_unknown = 0. | |
178 | Therefore, its own definition is called only for "info" with no args. */ | |
179 | ||
180 | /* ARGSUSED */ | |
181 | static void | |
182 | info_command (char *arg, int from_tty) | |
183 | { | |
184 | printf_unfiltered ("\"info\" must be followed by the name of an info command.\n"); | |
185 | help_list (infolist, "info ", -1, gdb_stdout); | |
186 | } | |
187 | ||
188 | /* The "show" command with no arguments shows all the settings. */ | |
189 | ||
190 | /* ARGSUSED */ | |
191 | static void | |
192 | show_command (char *arg, int from_tty) | |
193 | { | |
194 | cmd_show_list (showlist, from_tty, ""); | |
195 | } | |
196 | \f | |
197 | /* Provide documentation on command or list given by COMMAND. FROM_TTY | |
198 | is ignored. */ | |
199 | ||
200 | /* ARGSUSED */ | |
201 | static void | |
202 | help_command (char *command, int from_tty) | |
203 | { | |
204 | help_cmd (command, gdb_stdout); | |
205 | } | |
206 | \f | |
83d31a92 TT |
207 | /* String compare function for qsort. */ |
208 | static int | |
209 | compare_strings (const void *arg1, const void *arg2) | |
210 | { | |
211 | const char **s1 = (const char **) arg1; | |
212 | const char **s2 = (const char **) arg2; | |
213 | return strcmp (*s1, *s2); | |
214 | } | |
215 | ||
d318976c FN |
216 | /* The "complete" command is used by Emacs to implement completion. */ |
217 | ||
218 | /* ARGSUSED */ | |
219 | static void | |
220 | complete_command (char *arg, int from_tty) | |
221 | { | |
222 | int i; | |
223 | int argpoint; | |
83d31a92 | 224 | char **completions; |
d318976c FN |
225 | |
226 | dont_repeat (); | |
227 | ||
228 | if (arg == NULL) | |
229 | arg = ""; | |
230 | argpoint = strlen (arg); | |
231 | ||
83d31a92 TT |
232 | completions = complete_line (arg, arg, argpoint); |
233 | ||
234 | if (completions) | |
d318976c | 235 | { |
83d31a92 TT |
236 | int item, size; |
237 | ||
238 | for (size = 0; completions[size]; ++size) | |
239 | ; | |
240 | qsort (completions, size, sizeof (char *), compare_strings); | |
241 | ||
242 | /* We do extra processing here since we only want to print each | |
243 | unique item once. */ | |
244 | item = 0; | |
245 | while (item < size) | |
246 | { | |
247 | int next_item; | |
248 | printf_unfiltered ("%s\n", completions[item]); | |
249 | next_item = item + 1; | |
250 | while (next_item < size | |
251 | && ! strcmp (completions[item], completions[next_item])) | |
252 | { | |
253 | xfree (completions[next_item]); | |
254 | ++next_item; | |
255 | } | |
256 | ||
257 | xfree (completions[item]); | |
258 | item = next_item; | |
259 | } | |
260 | ||
261 | xfree (completions); | |
d318976c FN |
262 | } |
263 | } | |
264 | ||
bbaca940 AC |
265 | int |
266 | is_complete_command (struct cmd_list_element *c) | |
d318976c | 267 | { |
bbaca940 | 268 | return cmd_cfunc_eq (c, complete_command); |
d318976c FN |
269 | } |
270 | ||
271 | /* ARGSUSED */ | |
272 | static void | |
273 | show_version (char *args, int from_tty) | |
274 | { | |
275 | immediate_quit++; | |
276 | print_gdb_version (gdb_stdout); | |
277 | printf_filtered ("\n"); | |
278 | immediate_quit--; | |
279 | } | |
280 | ||
281 | /* Handle the quit command. */ | |
282 | ||
283 | void | |
284 | quit_command (char *args, int from_tty) | |
285 | { | |
286 | if (!quit_confirm ()) | |
287 | error ("Not confirmed."); | |
288 | quit_force (args, from_tty); | |
289 | } | |
290 | ||
291 | /* ARGSUSED */ | |
292 | static void | |
293 | pwd_command (char *args, int from_tty) | |
294 | { | |
295 | if (args) | |
296 | error ("The \"pwd\" command does not take an argument: %s", args); | |
297 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); | |
298 | ||
299 | if (!STREQ (gdb_dirbuf, current_directory)) | |
300 | printf_unfiltered ("Working directory %s\n (canonically %s).\n", | |
301 | current_directory, gdb_dirbuf); | |
302 | else | |
303 | printf_unfiltered ("Working directory %s.\n", current_directory); | |
304 | } | |
305 | ||
306 | void | |
307 | cd_command (char *dir, int from_tty) | |
308 | { | |
309 | int len; | |
310 | /* Found something other than leading repetitions of "/..". */ | |
311 | int found_real_path; | |
312 | char *p; | |
313 | ||
314 | /* If the new directory is absolute, repeat is a no-op; if relative, | |
315 | repeat might be useful but is more likely to be a mistake. */ | |
316 | dont_repeat (); | |
317 | ||
318 | if (dir == 0) | |
319 | error_no_arg ("new working directory"); | |
320 | ||
321 | dir = tilde_expand (dir); | |
b8c9b27d | 322 | make_cleanup (xfree, dir); |
d318976c FN |
323 | |
324 | if (chdir (dir) < 0) | |
325 | perror_with_name (dir); | |
326 | ||
c3690141 | 327 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
d318976c FN |
328 | /* There's too much mess with DOSish names like "d:", "d:.", |
329 | "d:./foo" etc. Instead of having lots of special #ifdef'ed code, | |
330 | simply get the canonicalized name of the current directory. */ | |
331 | dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); | |
332 | #endif | |
333 | ||
334 | len = strlen (dir); | |
fe4e3eb8 | 335 | if (IS_DIR_SEPARATOR (dir[len - 1])) |
d318976c FN |
336 | { |
337 | /* Remove the trailing slash unless this is a root directory | |
338 | (including a drive letter on non-Unix systems). */ | |
339 | if (!(len == 1) /* "/" */ | |
c3690141 | 340 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
fe4e3eb8 | 341 | && !(len == 3 && dir[1] == ':') /* "d:/" */ |
d318976c FN |
342 | #endif |
343 | ) | |
344 | len--; | |
345 | } | |
346 | ||
347 | dir = savestring (dir, len); | |
fe4e3eb8 | 348 | if (IS_ABSOLUTE_PATH (dir)) |
d318976c FN |
349 | current_directory = dir; |
350 | else | |
351 | { | |
fe4e3eb8 | 352 | if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])) |
d318976c FN |
353 | current_directory = concat (current_directory, dir, NULL); |
354 | else | |
355 | current_directory = concat (current_directory, SLASH_STRING, dir, NULL); | |
b8c9b27d | 356 | xfree (dir); |
d318976c FN |
357 | } |
358 | ||
359 | /* Now simplify any occurrences of `.' and `..' in the pathname. */ | |
360 | ||
361 | found_real_path = 0; | |
362 | for (p = current_directory; *p;) | |
363 | { | |
fe4e3eb8 EZ |
364 | if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' |
365 | && (p[2] == 0 || IS_DIR_SEPARATOR (p[2]))) | |
d318976c | 366 | strcpy (p, p + 2); |
fe4e3eb8 EZ |
367 | else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.' |
368 | && (p[3] == 0 || IS_DIR_SEPARATOR (p[3]))) | |
d318976c FN |
369 | { |
370 | if (found_real_path) | |
371 | { | |
372 | /* Search backwards for the directory just before the "/.." | |
373 | and obliterate it and the "/..". */ | |
374 | char *q = p; | |
fe4e3eb8 | 375 | while (q != current_directory && !IS_DIR_SEPARATOR (q[-1])) |
d318976c FN |
376 | --q; |
377 | ||
378 | if (q == current_directory) | |
379 | /* current_directory is | |
380 | a relative pathname ("can't happen"--leave it alone). */ | |
381 | ++p; | |
382 | else | |
383 | { | |
384 | strcpy (q - 1, p + 3); | |
385 | p = q - 1; | |
386 | } | |
387 | } | |
388 | else | |
389 | /* We are dealing with leading repetitions of "/..", for example | |
390 | "/../..", which is the Mach super-root. */ | |
391 | p += 3; | |
392 | } | |
393 | else | |
394 | { | |
395 | found_real_path = 1; | |
396 | ++p; | |
397 | } | |
398 | } | |
399 | ||
400 | forget_cached_source_info (); | |
401 | ||
402 | if (from_tty) | |
403 | pwd_command ((char *) 0, 1); | |
404 | } | |
405 | \f | |
406 | void | |
407 | source_command (char *args, int from_tty) | |
408 | { | |
409 | FILE *stream; | |
410 | struct cleanup *old_cleanups; | |
411 | char *file = args; | |
412 | ||
413 | if (file == NULL) | |
414 | { | |
415 | error ("source command requires pathname of file to source."); | |
416 | } | |
417 | ||
418 | file = tilde_expand (file); | |
b8c9b27d | 419 | old_cleanups = make_cleanup (xfree, file); |
d318976c FN |
420 | |
421 | stream = fopen (file, FOPEN_RT); | |
422 | if (!stream) | |
423 | { | |
424 | if (from_tty) | |
425 | perror_with_name (file); | |
426 | else | |
427 | return; | |
428 | } | |
429 | ||
430 | script_from_file (stream, file); | |
431 | ||
432 | do_cleanups (old_cleanups); | |
433 | } | |
434 | ||
435 | /* ARGSUSED */ | |
436 | static void | |
437 | echo_command (char *text, int from_tty) | |
438 | { | |
439 | char *p = text; | |
440 | register int c; | |
441 | ||
442 | if (text) | |
443 | while ((c = *p++) != '\0') | |
444 | { | |
445 | if (c == '\\') | |
446 | { | |
447 | /* \ at end of argument is used after spaces | |
448 | so they won't be lost. */ | |
449 | if (*p == 0) | |
450 | return; | |
451 | ||
452 | c = parse_escape (&p); | |
453 | if (c >= 0) | |
454 | printf_filtered ("%c", c); | |
455 | } | |
456 | else | |
457 | printf_filtered ("%c", c); | |
458 | } | |
459 | ||
460 | /* Force this output to appear now. */ | |
461 | wrap_here (""); | |
462 | gdb_flush (gdb_stdout); | |
463 | } | |
464 | ||
465 | /* ARGSUSED */ | |
466 | static void | |
467 | shell_escape (char *arg, int from_tty) | |
468 | { | |
469 | #ifdef CANT_FORK | |
470 | /* If ARG is NULL, they want an inferior shell, but `system' just | |
471 | reports if the shell is available when passed a NULL arg. */ | |
472 | int rc = system (arg ? arg : ""); | |
473 | ||
474 | if (!arg) | |
475 | arg = "inferior shell"; | |
476 | ||
477 | if (rc == -1) | |
478 | { | |
479 | fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg, | |
480 | safe_strerror (errno)); | |
481 | gdb_flush (gdb_stderr); | |
482 | } | |
483 | else if (rc) | |
484 | { | |
485 | fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc); | |
486 | gdb_flush (gdb_stderr); | |
487 | } | |
2584159e | 488 | #ifdef GLOBAL_CURDIR |
d318976c FN |
489 | /* Make sure to return to the directory GDB thinks it is, in case the |
490 | shell command we just ran changed it. */ | |
491 | chdir (current_directory); | |
492 | #endif | |
493 | #else /* Can fork. */ | |
494 | int rc, status, pid; | |
495 | char *p, *user_shell; | |
496 | ||
497 | if ((user_shell = (char *) getenv ("SHELL")) == NULL) | |
498 | user_shell = "/bin/sh"; | |
499 | ||
500 | /* Get the name of the shell for arg0 */ | |
501 | if ((p = strrchr (user_shell, '/')) == NULL) | |
502 | p = user_shell; | |
503 | else | |
504 | p++; /* Get past '/' */ | |
505 | ||
506 | if ((pid = fork ()) == 0) | |
507 | { | |
508 | if (!arg) | |
509 | execl (user_shell, p, 0); | |
510 | else | |
511 | execl (user_shell, p, "-c", arg, 0); | |
512 | ||
513 | fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell, | |
514 | safe_strerror (errno)); | |
515 | gdb_flush (gdb_stderr); | |
516 | _exit (0177); | |
517 | } | |
518 | ||
519 | if (pid != -1) | |
520 | while ((rc = wait (&status)) != pid && rc != -1) | |
521 | ; | |
522 | else | |
523 | error ("Fork failed"); | |
524 | #endif /* Can fork. */ | |
525 | } | |
526 | ||
527 | static void | |
528 | make_command (char *arg, int from_tty) | |
529 | { | |
530 | char *p; | |
531 | ||
532 | if (arg == 0) | |
533 | p = "make"; | |
534 | else | |
535 | { | |
536 | p = xmalloc (sizeof ("make ") + strlen (arg)); | |
537 | strcpy (p, "make "); | |
538 | strcpy (p + sizeof ("make ") - 1, arg); | |
539 | } | |
540 | ||
541 | shell_escape (p, from_tty); | |
542 | } | |
543 | ||
544 | /* ARGSUSED */ | |
545 | static void | |
546 | show_user (char *args, int from_tty) | |
547 | { | |
548 | struct cmd_list_element *c; | |
549 | extern struct cmd_list_element *cmdlist; | |
550 | ||
551 | if (args) | |
552 | { | |
553 | c = lookup_cmd (&args, cmdlist, "", 0, 1); | |
554 | if (c->class != class_user) | |
555 | error ("Not a user command."); | |
556 | show_user_1 (c, gdb_stdout); | |
557 | } | |
558 | else | |
559 | { | |
560 | for (c = cmdlist; c; c = c->next) | |
561 | { | |
562 | if (c->class == class_user) | |
563 | show_user_1 (c, gdb_stdout); | |
564 | } | |
565 | } | |
566 | } | |
567 | ||
568 | /* Search through names of commands and documentations for a certain | |
569 | regular expression. | |
570 | */ | |
571 | void | |
572 | apropos_command (char *searchstr, int from_tty) | |
573 | { | |
574 | extern struct cmd_list_element *cmdlist; /*This is the main command list*/ | |
575 | regex_t pattern; | |
576 | char *pattern_fastmap; | |
577 | char errorbuffer[512]; | |
2e94c453 | 578 | pattern_fastmap = xcalloc (256, sizeof (char)); |
d318976c FN |
579 | if (searchstr == NULL) |
580 | error("REGEXP string is empty"); | |
581 | ||
582 | if (regcomp(&pattern,searchstr,REG_ICASE) == 0) | |
583 | { | |
584 | pattern.fastmap=pattern_fastmap; | |
585 | re_compile_fastmap(&pattern); | |
586 | apropos_cmd (gdb_stdout,cmdlist,&pattern,""); | |
587 | } | |
588 | else | |
589 | { | |
590 | regerror(regcomp(&pattern,searchstr,REG_ICASE),NULL,errorbuffer,512); | |
591 | error("Error in regular expression:%s",errorbuffer); | |
592 | } | |
2b5436af | 593 | xfree (pattern_fastmap); |
d318976c FN |
594 | } |
595 | \f | |
596 | static void | |
597 | set_debug (char *arg, int from_tty) | |
598 | { | |
599 | printf_unfiltered ("\"set debug\" must be followed by the name of a print subcommand.\n"); | |
600 | help_list (setdebuglist, "set debug ", -1, gdb_stdout); | |
601 | } | |
602 | ||
603 | static void | |
604 | show_debug (char *args, int from_tty) | |
605 | { | |
606 | cmd_show_list (showdebuglist, from_tty, ""); | |
607 | } | |
608 | ||
609 | void | |
610 | init_cmd_lists (void) | |
611 | { | |
20f01a46 DH |
612 | max_user_call_depth = 1024; |
613 | ||
d318976c FN |
614 | cmdlist = NULL; |
615 | infolist = NULL; | |
616 | enablelist = NULL; | |
617 | disablelist = NULL; | |
618 | togglelist = NULL; | |
619 | stoplist = NULL; | |
620 | deletelist = NULL; | |
621 | enablebreaklist = NULL; | |
622 | setlist = NULL; | |
623 | unsetlist = NULL; | |
624 | showlist = NULL; | |
625 | sethistlist = NULL; | |
626 | showhistlist = NULL; | |
627 | unsethistlist = NULL; | |
628 | maintenancelist = NULL; | |
629 | maintenanceinfolist = NULL; | |
630 | maintenanceprintlist = NULL; | |
631 | setprintlist = NULL; | |
632 | showprintlist = NULL; | |
633 | setchecklist = NULL; | |
634 | showchecklist = NULL; | |
635 | } | |
636 | ||
637 | \f | |
638 | void | |
639 | init_cli_cmds (void) | |
640 | { | |
641 | struct cmd_list_element *c; | |
642 | ||
643 | /* Define the classes of commands. | |
644 | They will appear in the help list in the reverse of this order. */ | |
645 | ||
e00d1dc8 | 646 | add_cmd ("internals", class_maintenance, NULL, |
d318976c FN |
647 | "Maintenance commands.\n\ |
648 | Some gdb commands are provided just for use by gdb maintainers.\n\ | |
649 | These commands are subject to frequent change, and may not be as\n\ | |
650 | well documented as user commands.", | |
651 | &cmdlist); | |
e00d1dc8 AC |
652 | add_cmd ("obscure", class_obscure, NULL, "Obscure features.", &cmdlist); |
653 | add_cmd ("aliases", class_alias, NULL, "Aliases of other commands.", &cmdlist); | |
654 | add_cmd ("user-defined", class_user, NULL, "User-defined commands.\n\ | |
d318976c FN |
655 | The commands in this class are those defined by the user.\n\ |
656 | Use the \"define\" command to define a command.", &cmdlist); | |
e00d1dc8 | 657 | add_cmd ("support", class_support, NULL, "Support facilities.", &cmdlist); |
d318976c | 658 | if (!dbx_commands) |
e00d1dc8 AC |
659 | add_cmd ("status", class_info, NULL, "Status inquiries.", &cmdlist); |
660 | add_cmd ("files", class_files, NULL, "Specifying and examining files.", &cmdlist); | |
661 | add_cmd ("breakpoints", class_breakpoint, NULL, "Making program stop at certain points.", &cmdlist); | |
662 | add_cmd ("data", class_vars, NULL, "Examining data.", &cmdlist); | |
663 | add_cmd ("stack", class_stack, NULL, "Examining the stack.\n\ | |
d318976c FN |
664 | The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ |
665 | counting from zero for the innermost (currently executing) frame.\n\n\ | |
666 | At any time gdb identifies one frame as the \"selected\" frame.\n\ | |
667 | Variable lookups are done with respect to the selected frame.\n\ | |
668 | When the program being debugged stops, gdb selects the innermost frame.\n\ | |
669 | The commands below can be used to select other frames by number or address.", | |
670 | &cmdlist); | |
e00d1dc8 | 671 | add_cmd ("running", class_run, NULL, "Running the program.", &cmdlist); |
d318976c FN |
672 | |
673 | /* Define general commands. */ | |
674 | ||
675 | add_com ("pwd", class_files, pwd_command, | |
676 | "Print working directory. This is used for your program as well."); | |
677 | c = add_cmd ("cd", class_files, cd_command, | |
678 | "Set working directory to DIR for debugger and program being debugged.\n\ | |
679 | The change does not take effect for the program being debugged\n\ | |
680 | until the next time it is started.", &cmdlist); | |
5ba2abeb | 681 | set_cmd_completer (c, filename_completer); |
d318976c FN |
682 | |
683 | add_com ("echo", class_support, echo_command, | |
684 | "Print a constant string. Give string as argument.\n\ | |
685 | C escape sequences may be used in the argument.\n\ | |
686 | No newline is added at the end of the argument;\n\ | |
687 | use \"\\n\" if you want a newline to be printed.\n\ | |
688 | Since leading and trailing whitespace are ignored in command arguments,\n\ | |
689 | if you want to print some you must use \"\\\" before leading whitespace\n\ | |
690 | to be printed or after trailing whitespace."); | |
691 | add_com ("document", class_support, document_command, | |
692 | "Document a user-defined command.\n\ | |
693 | Give command name as argument. Give documentation on following lines.\n\ | |
694 | End with a line of just \"end\"."); | |
695 | add_com ("define", class_support, define_command, | |
696 | "Define a new command name. Command name is argument.\n\ | |
697 | Definition appears on following lines, one command per line.\n\ | |
698 | End with a line of just \"end\".\n\ | |
699 | Use the \"document\" command to give documentation for the new command.\n\ | |
700 | Commands defined in this way may have up to ten arguments."); | |
701 | ||
d318976c FN |
702 | c = add_cmd ("source", class_support, source_command, |
703 | "Read commands from a file named FILE.\n\ | |
704 | Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\ | |
705 | when gdb is started.", &cmdlist); | |
5ba2abeb | 706 | set_cmd_completer (c, filename_completer); |
d318976c FN |
707 | |
708 | add_com ("quit", class_support, quit_command, "Exit gdb."); | |
db60ec62 | 709 | c = add_com ("help", class_support, help_command, "Print list of commands."); |
5ba2abeb | 710 | set_cmd_completer (c, command_completer); |
d318976c FN |
711 | add_com_alias ("q", "quit", class_support, 1); |
712 | add_com_alias ("h", "help", class_support, 1); | |
713 | ||
714 | c = add_set_cmd ("verbose", class_support, var_boolean, (char *) &info_verbose, | |
715 | "Set ", | |
716 | &setlist), | |
717 | add_show_from_set (c, &showlist); | |
9f60d481 | 718 | set_cmd_sfunc (c, set_verbose); |
d318976c FN |
719 | set_verbose (NULL, 0, c); |
720 | ||
721 | add_prefix_cmd ("history", class_support, set_history, | |
722 | "Generic command for setting command history parameters.", | |
723 | &sethistlist, "set history ", 0, &setlist); | |
724 | add_prefix_cmd ("history", class_support, show_history, | |
725 | "Generic command for showing command history parameters.", | |
726 | &showhistlist, "show history ", 0, &showlist); | |
727 | ||
728 | add_show_from_set | |
729 | (add_set_cmd ("expansion", no_class, var_boolean, (char *) &history_expansion_p, | |
730 | "Set history expansion on command input.\n\ | |
731 | Without an argument, history expansion is enabled.", &sethistlist), | |
732 | &showhistlist); | |
733 | ||
734 | add_prefix_cmd ("info", class_info, info_command, | |
735 | "Generic command for showing things about the program being debugged.", | |
736 | &infolist, "info ", 0, &cmdlist); | |
737 | add_com_alias ("i", "info", class_info, 1); | |
738 | ||
739 | add_com ("complete", class_obscure, complete_command, | |
740 | "List the completions for the rest of the line as a command."); | |
741 | ||
742 | add_prefix_cmd ("show", class_info, show_command, | |
743 | "Generic command for showing things about the debugger.", | |
744 | &showlist, "show ", 0, &cmdlist); | |
745 | /* Another way to get at the same thing. */ | |
746 | add_info ("set", show_command, "Show all GDB settings."); | |
747 | ||
748 | add_cmd ("commands", no_class, show_commands, | |
749 | "Show the history of commands you typed.\n\ | |
750 | You can supply a command number to start with, or a `+' to start after\n\ | |
751 | the previous command number shown.", | |
752 | &showlist); | |
753 | ||
754 | add_cmd ("version", no_class, show_version, | |
755 | "Show what version of GDB this is.", &showlist); | |
756 | ||
757 | add_com ("while", class_support, while_command, | |
758 | "Execute nested commands WHILE the conditional expression is non zero.\n\ | |
759 | The conditional expression must follow the word `while' and must in turn be\n\ | |
760 | followed by a new line. The nested commands must be entered one per line,\n\ | |
761 | and should be terminated by the word `end'."); | |
762 | ||
763 | add_com ("if", class_support, if_command, | |
764 | "Execute nested commands once IF the conditional expression is non zero.\n\ | |
765 | The conditional expression must follow the word `if' and must in turn be\n\ | |
766 | followed by a new line. The nested commands must be entered one per line,\n\ | |
767 | and should be terminated by the word 'else' or `end'. If an else clause\n\ | |
768 | is used, the same rules apply to its nested commands as to the first ones."); | |
769 | ||
770 | /* If target is open when baud changes, it doesn't take effect until the | |
771 | next open (I think, not sure). */ | |
772 | add_show_from_set (add_set_cmd ("remotebaud", no_class, | |
773 | var_zinteger, (char *) &baud_rate, | |
774 | "Set baud rate for remote serial I/O.\n\ | |
775 | This value is used to set the speed of the serial port when debugging\n\ | |
776 | using remote targets.", &setlist), | |
777 | &showlist); | |
778 | ||
779 | c = add_set_cmd ("remotedebug", no_class, var_zinteger, | |
780 | (char *) &remote_debug, | |
781 | "Set debugging of remote protocol.\n\ | |
782 | When enabled, each packet sent or received with the remote target\n\ | |
783 | is displayed.", &setlist); | |
784 | deprecate_cmd (c, "set debug remote"); | |
785 | deprecate_cmd (add_show_from_set (c, &showlist), "show debug remote"); | |
786 | ||
787 | add_show_from_set (add_set_cmd ("remote", no_class, var_zinteger, | |
788 | (char *) &remote_debug, | |
789 | "Set debugging of remote protocol.\n\ | |
790 | When enabled, each packet sent or received with the remote target\n\ | |
791 | is displayed.", &setdebuglist), | |
792 | &showdebuglist); | |
793 | ||
794 | add_show_from_set ( | |
795 | add_set_cmd ("remotetimeout", no_class, var_integer, (char *) &remote_timeout, | |
796 | "Set timeout limit to wait for target to respond.\n\ | |
797 | This value is used to set the time limit for gdb to wait for a response\n\ | |
798 | from the target.", &setlist), | |
799 | &showlist); | |
800 | ||
801 | add_prefix_cmd ("debug", no_class, set_debug, | |
802 | "Generic command for setting gdb debugging flags", | |
803 | &setdebuglist, "set debug ", 0, &setlist); | |
804 | ||
805 | add_prefix_cmd ("debug", no_class, show_debug, | |
806 | "Generic command for showing gdb debugging flags", | |
807 | &showdebuglist, "show debug ", 0, &showlist); | |
808 | ||
fa58ee11 | 809 | c = add_com ("shell", class_support, shell_escape, |
d4654627 | 810 | "Execute the rest of the line as a shell command.\n\ |
d318976c | 811 | With no arguments, run an inferior shell."); |
5ba2abeb | 812 | set_cmd_completer (c, filename_completer); |
d318976c FN |
813 | |
814 | /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would | |
815 | be a really useful feature. Unfortunately, the below wont do | |
816 | this. Instead it adds support for the form ``(gdb) ! ls'' | |
817 | (i.e. the space is required). If the ``!'' command below is | |
818 | added the complains about no ``!'' command would be replaced by | |
819 | complains about how the ``!'' command is broken :-) */ | |
820 | if (xdb_commands) | |
821 | add_com_alias ("!", "shell", class_support, 0); | |
822 | ||
fa58ee11 EZ |
823 | c = add_com ("make", class_support, make_command, |
824 | "Run the ``make'' program using the rest of the line as arguments."); | |
5ba2abeb | 825 | set_cmd_completer (c, filename_completer); |
d318976c FN |
826 | add_cmd ("user", no_class, show_user, |
827 | "Show definitions of user defined commands.\n\ | |
828 | Argument is the name of the user defined command.\n\ | |
829 | With no argument, show definitions of all user defined commands.", &showlist); | |
830 | add_com ("apropos", class_support, apropos_command, "Search for commands matching a REGEXP"); | |
20f01a46 DH |
831 | |
832 | add_show_from_set ( | |
833 | add_set_cmd ("max-user-call-depth", no_class, var_integer, | |
834 | (char *) &max_user_call_depth, | |
835 | "Set the max call depth for user-defined commands.\n", | |
836 | &setlist), | |
837 | &showlist); | |
d318976c | 838 | } |