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