cli-cmds.c revision 1.5 1 1.1 christos /* GDB CLI commands.
2 1.1 christos
3 1.3 christos Copyright (C) 2000-2015 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "defs.h"
21 1.1 christos #include "arch-utils.h"
22 1.1 christos #include "dyn-string.h"
23 1.1 christos #include "readline/readline.h"
24 1.1 christos #include "readline/tilde.h"
25 1.1 christos #include "completer.h"
26 1.1 christos #include "target.h" /* For baud_rate, remote_debug and remote_timeout. */
27 1.1 christos #include "gdb_wait.h" /* For shell escape implementation. */
28 1.1 christos #include "gdb_regex.h" /* Used by apropos_command. */
29 1.1 christos #include "gdb_vfork.h"
30 1.1 christos #include "linespec.h"
31 1.1 christos #include "expression.h"
32 1.1 christos #include "frame.h"
33 1.1 christos #include "value.h"
34 1.1 christos #include "language.h"
35 1.1 christos #include "filenames.h" /* For DOSish file names. */
36 1.1 christos #include "objfiles.h"
37 1.1 christos #include "source.h"
38 1.1 christos #include "disasm.h"
39 1.1 christos #include "tracepoint.h"
40 1.1 christos #include "filestuff.h"
41 1.1 christos
42 1.1 christos #include "ui-out.h"
43 1.1 christos
44 1.1 christos #include "top.h"
45 1.1 christos #include "cli/cli-decode.h"
46 1.1 christos #include "cli/cli-script.h"
47 1.1 christos #include "cli/cli-setshow.h"
48 1.1 christos #include "cli/cli-cmds.h"
49 1.1 christos #include "cli/cli-utils.h"
50 1.1 christos
51 1.3 christos #include "extension.h"
52 1.1 christos
53 1.1 christos #ifdef TUI
54 1.1 christos #include "tui/tui.h" /* For tui_active et.al. */
55 1.1 christos #endif
56 1.1 christos
57 1.1 christos #include <fcntl.h>
58 1.1 christos
59 1.1 christos /* Prototypes for local command functions */
60 1.1 christos
61 1.1 christos static void complete_command (char *, int);
62 1.1 christos
63 1.1 christos static void echo_command (char *, int);
64 1.1 christos
65 1.1 christos static void pwd_command (char *, int);
66 1.1 christos
67 1.1 christos static void show_version (char *, int);
68 1.1 christos
69 1.1 christos static void help_command (char *, int);
70 1.1 christos
71 1.1 christos static void show_command (char *, int);
72 1.1 christos
73 1.1 christos static void info_command (char *, int);
74 1.1 christos
75 1.1 christos static void show_debug (char *, int);
76 1.1 christos
77 1.1 christos static void set_debug (char *, int);
78 1.1 christos
79 1.1 christos static void show_user (char *, int);
80 1.1 christos
81 1.1 christos static void make_command (char *, int);
82 1.1 christos
83 1.1 christos static void shell_escape (char *, int);
84 1.1 christos
85 1.1 christos static void edit_command (char *, int);
86 1.1 christos
87 1.1 christos static void list_command (char *, int);
88 1.1 christos
89 1.1 christos /* Prototypes for local utility functions */
90 1.1 christos
91 1.1 christos static void ambiguous_line_spec (struct symtabs_and_lines *);
92 1.1 christos
93 1.1 christos static void filter_sals (struct symtabs_and_lines *);
94 1.1 christos
95 1.1 christos
96 1.1 christos /* Limit the call depth of user-defined commands */
98 1.1 christos unsigned int max_user_call_depth;
99 1.1 christos
100 1.1 christos /* Define all cmd_list_elements. */
101 1.1 christos
102 1.1 christos /* Chain containing all defined commands. */
103 1.1 christos
104 1.1 christos struct cmd_list_element *cmdlist;
105 1.1 christos
106 1.1 christos /* Chain containing all defined info subcommands. */
107 1.1 christos
108 1.1 christos struct cmd_list_element *infolist;
109 1.1 christos
110 1.1 christos /* Chain containing all defined enable subcommands. */
111 1.1 christos
112 1.1 christos struct cmd_list_element *enablelist;
113 1.1 christos
114 1.1 christos /* Chain containing all defined disable subcommands. */
115 1.1 christos
116 1.1 christos struct cmd_list_element *disablelist;
117 1.1 christos
118 1.1 christos /* Chain containing all defined stop subcommands. */
119 1.1 christos
120 1.1 christos struct cmd_list_element *stoplist;
121 1.1 christos
122 1.1 christos /* Chain containing all defined delete subcommands. */
123 1.1 christos
124 1.1 christos struct cmd_list_element *deletelist;
125 1.1 christos
126 1.1 christos /* Chain containing all defined detach subcommands. */
127 1.1 christos
128 1.1 christos struct cmd_list_element *detachlist;
129 1.1 christos
130 1.1 christos /* Chain containing all defined kill subcommands. */
131 1.1 christos
132 1.1 christos struct cmd_list_element *killlist;
133 1.1 christos
134 1.1 christos /* Chain containing all defined set subcommands */
135 1.1 christos
136 1.1 christos struct cmd_list_element *setlist;
137 1.1 christos
138 1.1 christos /* Chain containing all defined unset subcommands */
139 1.1 christos
140 1.1 christos struct cmd_list_element *unsetlist;
141 1.1 christos
142 1.1 christos /* Chain containing all defined show subcommands. */
143 1.1 christos
144 1.1 christos struct cmd_list_element *showlist;
145 1.1 christos
146 1.1 christos /* Chain containing all defined \"set history\". */
147 1.1 christos
148 1.1 christos struct cmd_list_element *sethistlist;
149 1.1 christos
150 1.1 christos /* Chain containing all defined \"show history\". */
151 1.1 christos
152 1.1 christos struct cmd_list_element *showhistlist;
153 1.1 christos
154 1.1 christos /* Chain containing all defined \"unset history\". */
155 1.1 christos
156 1.1 christos struct cmd_list_element *unsethistlist;
157 1.1 christos
158 1.1 christos /* Chain containing all defined maintenance subcommands. */
159 1.1 christos
160 1.1 christos struct cmd_list_element *maintenancelist;
161 1.1 christos
162 1.1 christos /* Chain containing all defined "maintenance info" subcommands. */
163 1.1 christos
164 1.1 christos struct cmd_list_element *maintenanceinfolist;
165 1.1 christos
166 1.1 christos /* Chain containing all defined "maintenance print" subcommands. */
167 1.1 christos
168 1.1 christos struct cmd_list_element *maintenanceprintlist;
169 1.1 christos
170 1.1 christos struct cmd_list_element *setprintlist;
171 1.1 christos
172 1.1 christos struct cmd_list_element *showprintlist;
173 1.1 christos
174 1.1 christos struct cmd_list_element *setdebuglist;
175 1.1 christos
176 1.1 christos struct cmd_list_element *showdebuglist;
177 1.1 christos
178 1.1 christos struct cmd_list_element *setchecklist;
179 1.1 christos
180 1.1 christos struct cmd_list_element *showchecklist;
181 1.1 christos
182 1.1 christos /* Command tracing state. */
183 1.1 christos
184 1.1 christos int source_verbose = 0;
185 1.1 christos int trace_commands = 0;
186 1.1 christos
187 1.1 christos /* 'script-extension' option support. */
189 1.1 christos
190 1.1 christos static const char script_ext_off[] = "off";
191 1.1 christos static const char script_ext_soft[] = "soft";
192 1.1 christos static const char script_ext_strict[] = "strict";
193 1.1 christos
194 1.1 christos static const char *const script_ext_enums[] = {
195 1.1 christos script_ext_off,
196 1.1 christos script_ext_soft,
197 1.1 christos script_ext_strict,
198 1.1 christos NULL
199 1.1 christos };
200 1.1 christos
201 1.1 christos static const char *script_ext_mode = script_ext_soft;
202 1.1 christos
203 1.1 christos /* Utility used everywhere when at least one argument is needed and
205 1.3 christos none is supplied. */
206 1.1 christos
207 1.1 christos void
208 1.1 christos error_no_arg (const char *why)
209 1.1 christos {
210 1.1 christos error (_("Argument required (%s)."), why);
211 1.1 christos }
212 1.1 christos
213 1.1 christos /* The "info" command is defined as a prefix, with allow_unknown = 0.
214 1.1 christos Therefore, its own definition is called only for "info" with no
215 1.1 christos args. */
216 1.1 christos
217 1.1 christos static void
218 1.1 christos info_command (char *arg, int from_tty)
219 1.3 christos {
220 1.1 christos printf_unfiltered (_("\"info\" must be followed by "
221 1.1 christos "the name of an info command.\n"));
222 1.1 christos help_list (infolist, "info ", all_commands, gdb_stdout);
223 1.1 christos }
224 1.1 christos
225 1.1 christos /* The "show" command with no arguments shows all the settings. */
226 1.1 christos
227 1.1 christos static void
228 1.1 christos show_command (char *arg, int from_tty)
229 1.1 christos {
230 1.1 christos cmd_show_list (showlist, from_tty, "");
231 1.1 christos }
232 1.1 christos
233 1.1 christos /* Provide documentation on command or list given by COMMAND. FROM_TTY
235 1.1 christos is ignored. */
236 1.1 christos
237 1.1 christos static void
238 1.1 christos help_command (char *command, int from_tty)
239 1.5 christos {
240 1.5 christos help_cmd (command, gdb_stdout);
241 1.1 christos }
242 1.1 christos
243 1.1 christos /* Note: The "complete" command is used by Emacs to implement completion.
245 1.1 christos [Is that why this function writes output with *_unfiltered?] */
246 1.1 christos
247 1.1 christos static void
248 1.1 christos complete_command (char *arg, int from_tty)
249 1.1 christos {
250 1.1 christos int argpoint;
251 1.5 christos char *point, *arg_prefix;
252 1.5 christos VEC (char_ptr) *completions;
253 1.5 christos
254 1.5 christos dont_repeat ();
255 1.5 christos
256 1.5 christos if (max_completions == 0)
257 1.5 christos {
258 1.5 christos /* Only print this for non-mi frontends. An MI frontend may not
259 1.5 christos be able to handle this. */
260 1.5 christos if (!ui_out_is_mi_like_p (current_uiout))
261 1.5 christos {
262 1.5 christos printf_unfiltered (_("max-completions is zero,"
263 1.1 christos " completion is disabled.\n"));
264 1.1 christos }
265 1.1 christos return;
266 1.1 christos }
267 1.1 christos
268 1.1 christos if (arg == NULL)
269 1.1 christos arg = "";
270 1.1 christos argpoint = strlen (arg);
271 1.1 christos
272 1.1 christos /* complete_line assumes that its first argument is somewhere
273 1.1 christos within, and except for filenames at the beginning of, the word to
274 1.1 christos be completed. The following crude imitation of readline's
275 1.1 christos word-breaking tries to accomodate this. */
276 1.1 christos point = arg + argpoint;
277 1.1 christos while (point > arg)
278 1.1 christos {
279 1.1 christos if (strchr (rl_completer_word_break_characters, point[-1]) != 0)
280 1.1 christos break;
281 1.1 christos point--;
282 1.1 christos }
283 1.1 christos
284 1.1 christos arg_prefix = alloca (point - arg + 1);
285 1.1 christos memcpy (arg_prefix, arg, point - arg);
286 1.1 christos arg_prefix[point - arg] = 0;
287 1.1 christos
288 1.1 christos completions = complete_line (point, arg, argpoint);
289 1.1 christos
290 1.1 christos if (completions)
291 1.1 christos {
292 1.1 christos int ix, size = VEC_length (char_ptr, completions);
293 1.1 christos char *item, *prev = NULL;
294 1.1 christos
295 1.1 christos qsort (VEC_address (char_ptr, completions), size,
296 1.1 christos sizeof (char *), compare_strings);
297 1.1 christos
298 1.1 christos /* We do extra processing here since we only want to print each
299 1.1 christos unique item once. */
300 1.1 christos for (ix = 0; VEC_iterate (char_ptr, completions, ix, item); ++ix)
301 1.1 christos {
302 1.1 christos if (prev == NULL || strcmp (item, prev) != 0)
303 1.1 christos {
304 1.1 christos printf_unfiltered ("%s%s\n", arg_prefix, item);
305 1.1 christos xfree (prev);
306 1.1 christos prev = item;
307 1.1 christos }
308 1.1 christos else
309 1.5 christos xfree (item);
310 1.5 christos }
311 1.5 christos
312 1.5 christos xfree (prev);
313 1.5 christos VEC_free (char_ptr, completions);
314 1.5 christos
315 1.5 christos if (size == max_completions)
316 1.5 christos {
317 1.5 christos /* ARG_PREFIX and POINT are included in the output so that emacs
318 1.1 christos will include the message in the output. */
319 1.1 christos printf_unfiltered (_("%s%s %s\n"),
320 1.1 christos arg_prefix, point,
321 1.1 christos get_max_completions_reached_message ());
322 1.1 christos }
323 1.1 christos }
324 1.1 christos }
325 1.1 christos
326 1.1 christos int
327 1.1 christos is_complete_command (struct cmd_list_element *c)
328 1.1 christos {
329 1.1 christos return cmd_cfunc_eq (c, complete_command);
330 1.1 christos }
331 1.1 christos
332 1.1 christos static void
333 1.1 christos show_version (char *args, int from_tty)
334 1.1 christos {
335 1.1 christos print_gdb_version (gdb_stdout);
336 1.1 christos printf_filtered ("\n");
337 1.1 christos }
338 1.1 christos
339 1.1 christos static void
340 1.1 christos show_configuration (char *args, int from_tty)
341 1.1 christos {
342 1.1 christos print_gdb_configuration (gdb_stdout);
343 1.1 christos }
344 1.1 christos
345 1.1 christos /* Handle the quit command. */
346 1.1 christos
347 1.1 christos void
348 1.1 christos quit_command (char *args, int from_tty)
349 1.1 christos {
350 1.1 christos if (!quit_confirm ())
351 1.1 christos error (_("Not confirmed."));
352 1.1 christos
353 1.1 christos query_if_trace_running (from_tty);
354 1.1 christos
355 1.1 christos quit_force (args, from_tty);
356 1.1 christos }
357 1.1 christos
358 1.1 christos static void
359 1.1 christos pwd_command (char *args, int from_tty)
360 1.1 christos {
361 1.1 christos if (args)
362 1.1 christos error (_("The \"pwd\" command does not take an argument: %s"), args);
363 1.1 christos if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
364 1.1 christos error (_("Error finding name of working directory: %s"),
365 1.1 christos safe_strerror (errno));
366 1.1 christos
367 1.1 christos if (strcmp (gdb_dirbuf, current_directory) != 0)
368 1.1 christos printf_unfiltered (_("Working directory %s\n (canonically %s).\n"),
369 1.1 christos current_directory, gdb_dirbuf);
370 1.1 christos else
371 1.1 christos printf_unfiltered (_("Working directory %s.\n"), current_directory);
372 1.1 christos }
373 1.1 christos
374 1.1 christos void
375 1.1 christos cd_command (char *dir, int from_tty)
376 1.1 christos {
377 1.1 christos int len;
378 1.1 christos /* Found something other than leading repetitions of "/..". */
379 1.1 christos int found_real_path;
380 1.1 christos char *p;
381 1.1 christos struct cleanup *cleanup;
382 1.1 christos
383 1.1 christos /* If the new directory is absolute, repeat is a no-op; if relative,
384 1.1 christos repeat might be useful but is more likely to be a mistake. */
385 1.1 christos dont_repeat ();
386 1.1 christos
387 1.1 christos if (dir == 0)
388 1.1 christos dir = "~";
389 1.1 christos
390 1.1 christos dir = tilde_expand (dir);
391 1.1 christos cleanup = make_cleanup (xfree, dir);
392 1.1 christos
393 1.1 christos if (chdir (dir) < 0)
394 1.1 christos perror_with_name (dir);
395 1.1 christos
396 1.1 christos #ifdef HAVE_DOS_BASED_FILE_SYSTEM
397 1.1 christos /* There's too much mess with DOSish names like "d:", "d:.",
398 1.1 christos "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
399 1.1 christos simply get the canonicalized name of the current directory. */
400 1.1 christos dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
401 1.1 christos #endif
402 1.1 christos
403 1.1 christos len = strlen (dir);
404 1.1 christos if (IS_DIR_SEPARATOR (dir[len - 1]))
405 1.1 christos {
406 1.1 christos /* Remove the trailing slash unless this is a root directory
407 1.1 christos (including a drive letter on non-Unix systems). */
408 1.1 christos if (!(len == 1) /* "/" */
409 1.1 christos #ifdef HAVE_DOS_BASED_FILE_SYSTEM
410 1.1 christos && !(len == 3 && dir[1] == ':') /* "d:/" */
411 1.1 christos #endif
412 1.1 christos )
413 1.1 christos len--;
414 1.1 christos }
415 1.1 christos
416 1.1 christos dir = savestring (dir, len);
417 1.1 christos if (IS_ABSOLUTE_PATH (dir))
418 1.1 christos current_directory = dir;
419 1.1 christos else
420 1.1 christos {
421 1.1 christos if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]))
422 1.1 christos current_directory = concat (current_directory, dir, (char *)NULL);
423 1.1 christos else
424 1.1 christos current_directory = concat (current_directory, SLASH_STRING,
425 1.1 christos dir, (char *)NULL);
426 1.1 christos xfree (dir);
427 1.1 christos }
428 1.1 christos
429 1.1 christos /* Now simplify any occurrences of `.' and `..' in the pathname. */
430 1.1 christos
431 1.1 christos found_real_path = 0;
432 1.1 christos for (p = current_directory; *p;)
433 1.1 christos {
434 1.1 christos if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.'
435 1.1 christos && (p[2] == 0 || IS_DIR_SEPARATOR (p[2])))
436 1.1 christos memmove (p, p + 2, strlen (p + 2) + 1);
437 1.1 christos else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.'
438 1.1 christos && (p[3] == 0 || IS_DIR_SEPARATOR (p[3])))
439 1.1 christos {
440 1.1 christos if (found_real_path)
441 1.1 christos {
442 1.1 christos /* Search backwards for the directory just before the "/.."
443 1.1 christos and obliterate it and the "/..". */
444 1.1 christos char *q = p;
445 1.1 christos
446 1.1 christos while (q != current_directory && !IS_DIR_SEPARATOR (q[-1]))
447 1.1 christos --q;
448 1.1 christos
449 1.1 christos if (q == current_directory)
450 1.1 christos /* current_directory is
451 1.1 christos a relative pathname ("can't happen"--leave it alone). */
452 1.1 christos ++p;
453 1.1 christos else
454 1.1 christos {
455 1.1 christos memmove (q - 1, p + 3, strlen (p + 3) + 1);
456 1.1 christos p = q - 1;
457 1.1 christos }
458 1.1 christos }
459 1.1 christos else
460 1.1 christos /* We are dealing with leading repetitions of "/..", for
461 1.1 christos example "/../..", which is the Mach super-root. */
462 1.1 christos p += 3;
463 1.1 christos }
464 1.1 christos else
465 1.1 christos {
466 1.1 christos found_real_path = 1;
467 1.1 christos ++p;
468 1.1 christos }
469 1.1 christos }
470 1.1 christos
471 1.1 christos forget_cached_source_info ();
472 1.1 christos
473 1.1 christos if (from_tty)
474 1.1 christos pwd_command ((char *) 0, 1);
475 1.1 christos
476 1.1 christos do_cleanups (cleanup);
477 1.1 christos }
478 1.1 christos
479 1.1 christos /* Show the current value of the 'script-extension' option. */
481 1.1 christos
482 1.1 christos static void
483 1.1 christos show_script_ext_mode (struct ui_file *file, int from_tty,
484 1.1 christos struct cmd_list_element *c, const char *value)
485 1.1 christos {
486 1.1 christos fprintf_filtered (file,
487 1.1 christos _("Script filename extension recognition is \"%s\".\n"),
488 1.1 christos value);
489 1.1 christos }
490 1.1 christos
491 1.1 christos /* Try to open SCRIPT_FILE.
492 1.1 christos If successful, the full path name is stored in *FULL_PATHP,
493 1.1 christos the stream is stored in *STREAMP, and return 1.
494 1.1 christos The caller is responsible for freeing *FULL_PATHP.
495 1.1 christos If not successful, return 0; errno is set for the last file
496 1.1 christos we tried to open.
497 1.1 christos
498 1.1 christos If SEARCH_PATH is non-zero, and the file isn't found in cwd,
499 1.1 christos search for it in the source search path. */
500 1.1 christos
501 1.1 christos int
502 1.1 christos find_and_open_script (const char *script_file, int search_path,
503 1.1 christos FILE **streamp, char **full_pathp)
504 1.1 christos {
505 1.1 christos char *file;
506 1.1 christos int fd;
507 1.1 christos struct cleanup *old_cleanups;
508 1.1 christos int search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
509 1.1 christos
510 1.1 christos file = tilde_expand (script_file);
511 1.1 christos old_cleanups = make_cleanup (xfree, file);
512 1.1 christos
513 1.1 christos if (search_path)
514 1.1 christos search_flags |= OPF_SEARCH_IN_PATH;
515 1.1 christos
516 1.1 christos /* Search for and open 'file' on the search path used for source
517 1.1 christos files. Put the full location in *FULL_PATHP. */
518 1.1 christos fd = openp (source_path, search_flags,
519 1.1 christos file, O_RDONLY, full_pathp);
520 1.1 christos
521 1.1 christos if (fd == -1)
522 1.1 christos {
523 1.1 christos int save_errno = errno;
524 1.1 christos do_cleanups (old_cleanups);
525 1.1 christos errno = save_errno;
526 1.1 christos return 0;
527 1.1 christos }
528 1.1 christos
529 1.1 christos do_cleanups (old_cleanups);
530 1.1 christos
531 1.1 christos *streamp = fdopen (fd, FOPEN_RT);
532 1.1 christos if (*streamp == NULL)
533 1.1 christos {
534 1.1 christos int save_errno = errno;
535 1.1 christos
536 1.1 christos close (fd);
537 1.1 christos if (full_pathp)
538 1.1 christos xfree (*full_pathp);
539 1.1 christos errno = save_errno;
540 1.1 christos return 0;
541 1.1 christos }
542 1.1 christos
543 1.1 christos return 1;
544 1.1 christos }
545 1.3 christos
546 1.1 christos /* Load script FILE, which has already been opened as STREAM. */
547 1.3 christos
548 1.3 christos static void
549 1.3 christos source_script_from_stream (FILE *stream, const char *file)
550 1.3 christos {
551 1.1 christos if (script_ext_mode != script_ext_off)
552 1.3 christos {
553 1.3 christos const struct extension_language_defn *extlang
554 1.3 christos = get_ext_lang_of_file (file);
555 1.3 christos
556 1.3 christos if (extlang != NULL)
557 1.3 christos {
558 1.3 christos if (ext_lang_present_p (extlang))
559 1.3 christos {
560 1.3 christos script_sourcer_func *sourcer
561 1.3 christos = ext_lang_script_sourcer (extlang);
562 1.3 christos
563 1.3 christos gdb_assert (sourcer != NULL);
564 1.3 christos sourcer (extlang, stream, file);
565 1.3 christos return;
566 1.3 christos }
567 1.3 christos else if (script_ext_mode == script_ext_soft)
568 1.1 christos {
569 1.1 christos /* Assume the file is a gdb script.
570 1.3 christos This is handled below. */
571 1.3 christos }
572 1.1 christos else
573 1.1 christos throw_ext_lang_unsupported (extlang);
574 1.1 christos }
575 1.1 christos }
576 1.1 christos
577 1.1 christos script_from_file (stream, file);
578 1.1 christos }
579 1.1 christos
580 1.1 christos /* Worker to perform the "source" command.
581 1.1 christos Load script FILE.
582 1.1 christos If SEARCH_PATH is non-zero, and the file isn't found in cwd,
583 1.1 christos search for it in the source search path. */
584 1.1 christos
585 1.1 christos static void
586 1.1 christos source_script_with_search (const char *file, int from_tty, int search_path)
587 1.1 christos {
588 1.1 christos FILE *stream;
589 1.1 christos char *full_path;
590 1.1 christos struct cleanup *old_cleanups;
591 1.1 christos
592 1.1 christos if (file == NULL || *file == 0)
593 1.1 christos error (_("source command requires file name of file to source."));
594 1.1 christos
595 1.1 christos if (!find_and_open_script (file, search_path, &stream, &full_path))
596 1.1 christos {
597 1.1 christos /* The script wasn't found, or was otherwise inaccessible.
598 1.1 christos If the source command was invoked interactively, throw an
599 1.1 christos error. Otherwise (e.g. if it was invoked by a script),
600 1.1 christos just emit a warning, rather than cause an error. */
601 1.1 christos if (from_tty)
602 1.1 christos perror_with_name (file);
603 1.1 christos else
604 1.1 christos {
605 1.1 christos perror_warning_with_name (file);
606 1.1 christos return;
607 1.1 christos }
608 1.1 christos }
609 1.1 christos
610 1.1 christos old_cleanups = make_cleanup (xfree, full_path);
611 1.1 christos make_cleanup_fclose (stream);
612 1.1 christos /* The python support reopens the file, so we need to pass full_path here
613 1.1 christos in case the file was found on the search path. It's useful to do this
614 1.1 christos anyway so that error messages show the actual file used. But only do
615 1.1 christos this if we (may have) used search_path, as printing the full path in
616 1.1 christos errors for the non-search case can be more noise than signal. */
617 1.1 christos source_script_from_stream (stream, search_path ? full_path : file);
618 1.1 christos do_cleanups (old_cleanups);
619 1.1 christos }
620 1.1 christos
621 1.1 christos /* Wrapper around source_script_with_search to export it to main.c
622 1.1 christos for use in loading .gdbinit scripts. */
623 1.1 christos
624 1.1 christos void
625 1.1 christos source_script (const char *file, int from_tty)
626 1.1 christos {
627 1.1 christos source_script_with_search (file, from_tty, 0);
628 1.1 christos }
629 1.1 christos
630 1.1 christos /* Return the source_verbose global variable to its previous state
631 1.1 christos on exit from the source command, by whatever means. */
632 1.1 christos static void
633 1.1 christos source_verbose_cleanup (void *old_value)
634 1.1 christos {
635 1.1 christos source_verbose = *(int *)old_value;
636 1.1 christos xfree (old_value);
637 1.1 christos }
638 1.1 christos
639 1.1 christos static void
640 1.1 christos source_command (char *args, int from_tty)
641 1.1 christos {
642 1.1 christos struct cleanup *old_cleanups;
643 1.1 christos char *file = args;
644 1.1 christos int *old_source_verbose = xmalloc (sizeof(int));
645 1.1 christos int search_path = 0;
646 1.1 christos
647 1.1 christos *old_source_verbose = source_verbose;
648 1.1 christos old_cleanups = make_cleanup (source_verbose_cleanup,
649 1.1 christos old_source_verbose);
650 1.1 christos
651 1.1 christos /* -v causes the source command to run in verbose mode.
652 1.1 christos -s causes the file to be searched in the source search path,
653 1.1 christos even if the file name contains a '/'.
654 1.1 christos We still have to be able to handle filenames with spaces in a
655 1.1 christos backward compatible way, so buildargv is not appropriate. */
656 1.1 christos
657 1.1 christos if (args)
658 1.1 christos {
659 1.1 christos while (args[0] != '\0')
660 1.1 christos {
661 1.1 christos /* Make sure leading white space does not break the
662 1.1 christos comparisons. */
663 1.1 christos args = skip_spaces (args);
664 1.1 christos
665 1.1 christos if (args[0] != '-')
666 1.1 christos break;
667 1.1 christos
668 1.1 christos if (args[1] == 'v' && isspace (args[2]))
669 1.1 christos {
670 1.1 christos source_verbose = 1;
671 1.1 christos
672 1.1 christos /* Skip passed -v. */
673 1.1 christos args = &args[3];
674 1.1 christos }
675 1.1 christos else if (args[1] == 's' && isspace (args[2]))
676 1.1 christos {
677 1.1 christos search_path = 1;
678 1.1 christos
679 1.1 christos /* Skip passed -s. */
680 1.1 christos args = &args[3];
681 1.1 christos }
682 1.1 christos else
683 1.1 christos break;
684 1.1 christos }
685 1.1 christos
686 1.1 christos file = skip_spaces (args);
687 1.1 christos }
688 1.1 christos
689 1.1 christos source_script_with_search (file, from_tty, search_path);
690 1.1 christos
691 1.1 christos do_cleanups (old_cleanups);
692 1.1 christos }
693 1.1 christos
694 1.1 christos
695 1.1 christos static void
696 1.1 christos echo_command (char *text, int from_tty)
697 1.1 christos {
698 1.1 christos const char *p = text;
699 1.1 christos int c;
700 1.1 christos
701 1.1 christos if (text)
702 1.1 christos while ((c = *p++) != '\0')
703 1.1 christos {
704 1.1 christos if (c == '\\')
705 1.1 christos {
706 1.1 christos /* \ at end of argument is used after spaces
707 1.1 christos so they won't be lost. */
708 1.1 christos if (*p == 0)
709 1.1 christos return;
710 1.1 christos
711 1.1 christos c = parse_escape (get_current_arch (), &p);
712 1.1 christos if (c >= 0)
713 1.1 christos printf_filtered ("%c", c);
714 1.1 christos }
715 1.1 christos else
716 1.1 christos printf_filtered ("%c", c);
717 1.1 christos }
718 1.1 christos
719 1.1 christos /* Force this output to appear now. */
720 1.1 christos wrap_here ("");
721 1.1 christos gdb_flush (gdb_stdout);
722 1.1 christos }
723 1.1 christos
724 1.1 christos static void
725 1.1 christos shell_escape (char *arg, int from_tty)
726 1.1 christos {
727 1.1 christos #if defined(CANT_FORK) || \
728 1.1 christos (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
729 1.1 christos /* If ARG is NULL, they want an inferior shell, but `system' just
730 1.1 christos reports if the shell is available when passed a NULL arg. */
731 1.1 christos int rc = system (arg ? arg : "");
732 1.1 christos
733 1.1 christos if (!arg)
734 1.1 christos arg = "inferior shell";
735 1.1 christos
736 1.1 christos if (rc == -1)
737 1.1 christos {
738 1.1 christos fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
739 1.1 christos safe_strerror (errno));
740 1.1 christos gdb_flush (gdb_stderr);
741 1.1 christos }
742 1.1 christos else if (rc)
743 1.1 christos {
744 1.1 christos fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
745 1.1 christos gdb_flush (gdb_stderr);
746 1.1 christos }
747 1.1 christos #ifdef GLOBAL_CURDIR
748 1.1 christos /* Make sure to return to the directory GDB thinks it is, in case
749 1.1 christos the shell command we just ran changed it. */
750 1.1 christos chdir (current_directory);
751 1.1 christos #endif
752 1.1 christos #else /* Can fork. */
753 1.1 christos int status, pid;
754 1.1 christos
755 1.1 christos if ((pid = vfork ()) == 0)
756 1.1 christos {
757 1.1 christos const char *p, *user_shell;
758 1.1 christos
759 1.1 christos close_most_fds ();
760 1.1 christos
761 1.1 christos if ((user_shell = (char *) getenv ("SHELL")) == NULL)
762 1.1 christos user_shell = "/bin/sh";
763 1.1 christos
764 1.1 christos /* Get the name of the shell for arg0. */
765 1.1 christos p = lbasename (user_shell);
766 1.1 christos
767 1.1 christos if (!arg)
768 1.1 christos execl (user_shell, p, (char *) 0);
769 1.1 christos else
770 1.1 christos execl (user_shell, p, "-c", arg, (char *) 0);
771 1.1 christos
772 1.1 christos fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
773 1.1 christos safe_strerror (errno));
774 1.1 christos gdb_flush (gdb_stderr);
775 1.1 christos _exit (0177);
776 1.1 christos }
777 1.1 christos
778 1.1 christos if (pid != -1)
779 1.1 christos waitpid (pid, &status, 0);
780 1.1 christos else
781 1.1 christos error (_("Fork failed"));
782 1.1 christos #endif /* Can fork. */
783 1.1 christos }
784 1.1 christos
785 1.1 christos static void
786 1.1 christos edit_command (char *arg, int from_tty)
787 1.1 christos {
788 1.1 christos struct symtabs_and_lines sals;
789 1.1 christos struct symtab_and_line sal;
790 1.1 christos struct symbol *sym;
791 1.1 christos char *arg1;
792 1.1 christos char *editor;
793 1.1 christos char *p;
794 1.1 christos const char *fn;
795 1.1 christos
796 1.1 christos /* Pull in the current default source line if necessary. */
797 1.1 christos if (arg == 0)
798 1.1 christos {
799 1.1 christos set_default_source_symtab_and_line ();
800 1.1 christos sal = get_current_source_symtab_and_line ();
801 1.1 christos }
802 1.1 christos
803 1.1 christos /* Bare "edit" edits file with present line. */
804 1.1 christos
805 1.1 christos if (arg == 0)
806 1.1 christos {
807 1.1 christos if (sal.symtab == 0)
808 1.1 christos error (_("No default source file yet."));
809 1.1 christos sal.line += get_lines_to_list () / 2;
810 1.1 christos }
811 1.1 christos else
812 1.1 christos {
813 1.1 christos /* Now should only be one argument -- decode it in SAL. */
814 1.1 christos
815 1.1 christos arg1 = arg;
816 1.1 christos sals = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
817 1.1 christos
818 1.1 christos filter_sals (&sals);
819 1.1 christos if (! sals.nelts)
820 1.1 christos {
821 1.1 christos /* C++ */
822 1.1 christos return;
823 1.1 christos }
824 1.1 christos if (sals.nelts > 1)
825 1.1 christos {
826 1.1 christos ambiguous_line_spec (&sals);
827 1.1 christos xfree (sals.sals);
828 1.1 christos return;
829 1.1 christos }
830 1.1 christos
831 1.1 christos sal = sals.sals[0];
832 1.1 christos xfree (sals.sals);
833 1.1 christos
834 1.1 christos if (*arg1)
835 1.1 christos error (_("Junk at end of line specification."));
836 1.1 christos
837 1.1 christos /* If line was specified by address, first print exactly which
838 1.1 christos line, and which file. In this case, sal.symtab == 0 means
839 1.1 christos address is outside of all known source files, not that user
840 1.1 christos failed to give a filename. */
841 1.1 christos if (*arg == '*')
842 1.1 christos {
843 1.3 christos struct gdbarch *gdbarch;
844 1.1 christos
845 1.1 christos if (sal.symtab == 0)
846 1.1 christos error (_("No source file for address %s."),
847 1.1 christos paddress (get_current_arch (), sal.pc));
848 1.1 christos
849 1.1 christos gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
850 1.1 christos sym = find_pc_function (sal.pc);
851 1.1 christos if (sym)
852 1.1 christos printf_filtered ("%s is in %s (%s:%d).\n",
853 1.1 christos paddress (gdbarch, sal.pc),
854 1.1 christos SYMBOL_PRINT_NAME (sym),
855 1.1 christos symtab_to_filename_for_display (sal.symtab),
856 1.1 christos sal.line);
857 1.1 christos else
858 1.1 christos printf_filtered ("%s is at %s:%d.\n",
859 1.1 christos paddress (gdbarch, sal.pc),
860 1.1 christos symtab_to_filename_for_display (sal.symtab),
861 1.1 christos sal.line);
862 1.1 christos }
863 1.1 christos
864 1.1 christos /* If what was given does not imply a symtab, it must be an
865 1.1 christos undebuggable symbol which means no source code. */
866 1.1 christos
867 1.1 christos if (sal.symtab == 0)
868 1.1 christos error (_("No line number known for %s."), arg);
869 1.1 christos }
870 1.1 christos
871 1.1 christos if ((editor = (char *) getenv ("EDITOR")) == NULL)
872 1.1 christos editor = "/bin/ex";
873 1.1 christos
874 1.1 christos fn = symtab_to_fullname (sal.symtab);
875 1.1 christos
876 1.1 christos /* Quote the file name, in case it has whitespace or other special
877 1.1 christos characters. */
878 1.1 christos p = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn);
879 1.1 christos shell_escape (p, from_tty);
880 1.1 christos xfree (p);
881 1.1 christos }
882 1.1 christos
883 1.1 christos static void
884 1.1 christos list_command (char *arg, int from_tty)
885 1.1 christos {
886 1.1 christos struct symtabs_and_lines sals, sals_end;
887 1.1 christos struct symtab_and_line sal = { 0 };
888 1.1 christos struct symtab_and_line sal_end = { 0 };
889 1.1 christos struct symtab_and_line cursal = { 0 };
890 1.1 christos struct symbol *sym;
891 1.1 christos char *arg1;
892 1.1 christos int no_end = 1;
893 1.1 christos int dummy_end = 0;
894 1.1 christos int dummy_beg = 0;
895 1.1 christos int linenum_beg = 0;
896 1.1 christos char *p;
897 1.3 christos
898 1.3 christos /* Pull in the current default source line if necessary. */
899 1.3 christos if (arg == 0 || arg[0] == '+' || arg[0] == '-')
900 1.3 christos {
901 1.3 christos set_default_source_symtab_and_line ();
902 1.3 christos cursal = get_current_source_symtab_and_line ();
903 1.3 christos
904 1.3 christos /* If this is the first "list" since we've set the current
905 1.3 christos source line, center the listing around that line. */
906 1.3 christos if (get_first_line_listed () == 0)
907 1.3 christos {
908 1.3 christos int first;
909 1.3 christos
910 1.3 christos first = max (cursal.line - get_lines_to_list () / 2, 1);
911 1.3 christos
912 1.3 christos /* A small special case --- if listing backwards, and we
913 1.3 christos should list only one line, list the preceding line,
914 1.3 christos instead of the exact line we've just shown after e.g.,
915 1.3 christos stopping for a breakpoint. */
916 1.3 christos if (arg != NULL && arg[0] == '-'
917 1.3 christos && get_lines_to_list () == 1 && first > 1)
918 1.1 christos first -= 1;
919 1.1 christos
920 1.1 christos print_source_lines (cursal.symtab, first,
921 1.1 christos first + get_lines_to_list (), 0);
922 1.1 christos return;
923 1.1 christos }
924 1.1 christos }
925 1.1 christos
926 1.1 christos /* "l" or "l +" lists next ten lines. */
927 1.1 christos
928 1.1 christos if (arg == 0 || strcmp (arg, "+") == 0)
929 1.1 christos {
930 1.1 christos print_source_lines (cursal.symtab, cursal.line,
931 1.1 christos cursal.line + get_lines_to_list (), 0);
932 1.1 christos return;
933 1.1 christos }
934 1.1 christos
935 1.1 christos /* "l -" lists previous ten lines, the ones before the ten just
936 1.1 christos listed. */
937 1.1 christos if (strcmp (arg, "-") == 0)
938 1.1 christos {
939 1.1 christos print_source_lines (cursal.symtab,
940 1.1 christos max (get_first_line_listed ()
941 1.1 christos - get_lines_to_list (), 1),
942 1.1 christos get_first_line_listed (), 0);
943 1.1 christos return;
944 1.1 christos }
945 1.1 christos
946 1.1 christos /* Now if there is only one argument, decode it in SAL
947 1.1 christos and set NO_END.
948 1.1 christos If there are two arguments, decode them in SAL and SAL_END
949 1.1 christos and clear NO_END; however, if one of the arguments is blank,
950 1.1 christos set DUMMY_BEG or DUMMY_END to record that fact. */
951 1.1 christos
952 1.1 christos if (!have_full_symbols () && !have_partial_symbols ())
953 1.1 christos error (_("No symbol table is loaded. Use the \"file\" command."));
954 1.1 christos
955 1.1 christos arg1 = arg;
956 1.1 christos if (*arg1 == ',')
957 1.1 christos dummy_beg = 1;
958 1.1 christos else
959 1.1 christos {
960 1.1 christos sals = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
961 1.1 christos
962 1.1 christos filter_sals (&sals);
963 1.1 christos if (!sals.nelts)
964 1.1 christos return; /* C++ */
965 1.1 christos if (sals.nelts > 1)
966 1.1 christos {
967 1.1 christos ambiguous_line_spec (&sals);
968 1.1 christos xfree (sals.sals);
969 1.1 christos return;
970 1.1 christos }
971 1.1 christos
972 1.1 christos sal = sals.sals[0];
973 1.1 christos xfree (sals.sals);
974 1.1 christos }
975 1.1 christos
976 1.1 christos /* Record whether the BEG arg is all digits. */
977 1.1 christos
978 1.1 christos for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++);
979 1.1 christos linenum_beg = (p == arg1);
980 1.1 christos
981 1.1 christos while (*arg1 == ' ' || *arg1 == '\t')
982 1.1 christos arg1++;
983 1.1 christos if (*arg1 == ',')
984 1.1 christos {
985 1.1 christos no_end = 0;
986 1.1 christos arg1++;
987 1.1 christos while (*arg1 == ' ' || *arg1 == '\t')
988 1.1 christos arg1++;
989 1.1 christos if (*arg1 == 0)
990 1.1 christos dummy_end = 1;
991 1.1 christos else
992 1.1 christos {
993 1.1 christos if (dummy_beg)
994 1.1 christos sals_end = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
995 1.1 christos else
996 1.1 christos sals_end = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE,
997 1.1 christos sal.symtab, sal.line);
998 1.1 christos filter_sals (&sals_end);
999 1.1 christos if (sals_end.nelts == 0)
1000 1.1 christos return;
1001 1.1 christos if (sals_end.nelts > 1)
1002 1.1 christos {
1003 1.1 christos ambiguous_line_spec (&sals_end);
1004 1.1 christos xfree (sals_end.sals);
1005 1.1 christos return;
1006 1.1 christos }
1007 1.1 christos sal_end = sals_end.sals[0];
1008 1.1 christos xfree (sals_end.sals);
1009 1.1 christos }
1010 1.1 christos }
1011 1.1 christos
1012 1.1 christos if (*arg1)
1013 1.1 christos error (_("Junk at end of line specification."));
1014 1.1 christos
1015 1.1 christos if (!no_end && !dummy_beg && !dummy_end
1016 1.1 christos && sal.symtab != sal_end.symtab)
1017 1.1 christos error (_("Specified start and end are in different files."));
1018 1.1 christos if (dummy_beg && dummy_end)
1019 1.1 christos error (_("Two empty args do not say what lines to list."));
1020 1.1 christos
1021 1.1 christos /* If line was specified by address,
1022 1.1 christos first print exactly which line, and which file.
1023 1.1 christos
1024 1.1 christos In this case, sal.symtab == 0 means address is outside of all
1025 1.1 christos known source files, not that user failed to give a filename. */
1026 1.1 christos if (*arg == '*')
1027 1.1 christos {
1028 1.3 christos struct gdbarch *gdbarch;
1029 1.1 christos
1030 1.1 christos if (sal.symtab == 0)
1031 1.1 christos error (_("No source file for address %s."),
1032 1.1 christos paddress (get_current_arch (), sal.pc));
1033 1.1 christos
1034 1.1 christos gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
1035 1.1 christos sym = find_pc_function (sal.pc);
1036 1.1 christos if (sym)
1037 1.1 christos printf_filtered ("%s is in %s (%s:%d).\n",
1038 1.1 christos paddress (gdbarch, sal.pc),
1039 1.1 christos SYMBOL_PRINT_NAME (sym),
1040 1.1 christos symtab_to_filename_for_display (sal.symtab), sal.line);
1041 1.1 christos else
1042 1.1 christos printf_filtered ("%s is at %s:%d.\n",
1043 1.1 christos paddress (gdbarch, sal.pc),
1044 1.1 christos symtab_to_filename_for_display (sal.symtab), sal.line);
1045 1.1 christos }
1046 1.1 christos
1047 1.1 christos /* If line was not specified by just a line number, and it does not
1048 1.1 christos imply a symtab, it must be an undebuggable symbol which means no
1049 1.1 christos source code. */
1050 1.1 christos
1051 1.1 christos if (!linenum_beg && sal.symtab == 0)
1052 1.1 christos error (_("No line number known for %s."), arg);
1053 1.1 christos
1054 1.1 christos /* If this command is repeated with RET,
1055 1.1 christos turn it into the no-arg variant. */
1056 1.1 christos
1057 1.1 christos if (from_tty)
1058 1.1 christos *arg = 0;
1059 1.1 christos
1060 1.1 christos if (dummy_beg && sal_end.symtab == 0)
1061 1.1 christos error (_("No default source file yet. Do \"help list\"."));
1062 1.1 christos if (dummy_beg)
1063 1.1 christos print_source_lines (sal_end.symtab,
1064 1.1 christos max (sal_end.line - (get_lines_to_list () - 1), 1),
1065 1.1 christos sal_end.line + 1, 0);
1066 1.1 christos else if (sal.symtab == 0)
1067 1.1 christos error (_("No default source file yet. Do \"help list\"."));
1068 1.1 christos else if (no_end)
1069 1.1 christos {
1070 1.1 christos int first_line = sal.line - get_lines_to_list () / 2;
1071 1.1 christos
1072 1.1 christos if (first_line < 1) first_line = 1;
1073 1.1 christos
1074 1.1 christos print_source_lines (sal.symtab,
1075 1.1 christos first_line,
1076 1.1 christos first_line + get_lines_to_list (),
1077 1.1 christos 0);
1078 1.1 christos }
1079 1.1 christos else
1080 1.1 christos print_source_lines (sal.symtab, sal.line,
1081 1.1 christos (dummy_end
1082 1.1 christos ? sal.line + get_lines_to_list ()
1083 1.1 christos : sal_end.line + 1),
1084 1.1 christos 0);
1085 1.1 christos }
1086 1.1 christos
1087 1.1 christos /* Subroutine of disassemble_command to simplify it.
1088 1.1 christos Perform the disassembly.
1089 1.1 christos NAME is the name of the function if known, or NULL.
1090 1.1 christos [LOW,HIGH) are the range of addresses to disassemble.
1091 1.1 christos MIXED is non-zero to print source with the assembler. */
1092 1.1 christos
1093 1.1 christos static void
1094 1.1 christos print_disassembly (struct gdbarch *gdbarch, const char *name,
1095 1.1 christos CORE_ADDR low, CORE_ADDR high, int flags)
1096 1.1 christos {
1097 1.1 christos #if defined(TUI)
1098 1.1 christos if (!tui_is_window_visible (DISASSEM_WIN))
1099 1.1 christos #endif
1100 1.1 christos {
1101 1.1 christos printf_filtered ("Dump of assembler code ");
1102 1.1 christos if (name != NULL)
1103 1.1 christos printf_filtered ("for function %s:\n", name);
1104 1.1 christos else
1105 1.1 christos printf_filtered ("from %s to %s:\n",
1106 1.1 christos paddress (gdbarch, low), paddress (gdbarch, high));
1107 1.1 christos
1108 1.1 christos /* Dump the specified range. */
1109 1.1 christos gdb_disassembly (gdbarch, current_uiout, 0, flags, -1, low, high);
1110 1.1 christos
1111 1.1 christos printf_filtered ("End of assembler dump.\n");
1112 1.1 christos gdb_flush (gdb_stdout);
1113 1.1 christos }
1114 1.1 christos #if defined(TUI)
1115 1.1 christos else
1116 1.1 christos {
1117 1.1 christos tui_show_assembly (gdbarch, low);
1118 1.1 christos }
1119 1.1 christos #endif
1120 1.1 christos }
1121 1.1 christos
1122 1.1 christos /* Subroutine of disassemble_command to simplify it.
1123 1.1 christos Print a disassembly of the current function according to FLAGS. */
1124 1.1 christos
1125 1.1 christos static void
1126 1.1 christos disassemble_current_function (int flags)
1127 1.1 christos {
1128 1.1 christos struct frame_info *frame;
1129 1.1 christos struct gdbarch *gdbarch;
1130 1.1 christos CORE_ADDR low, high, pc;
1131 1.1 christos const char *name;
1132 1.1 christos
1133 1.1 christos frame = get_selected_frame (_("No frame selected."));
1134 1.1 christos gdbarch = get_frame_arch (frame);
1135 1.1 christos pc = get_frame_address_in_block (frame);
1136 1.1 christos if (find_pc_partial_function (pc, &name, &low, &high) == 0)
1137 1.1 christos error (_("No function contains program counter for selected frame."));
1138 1.1 christos #if defined(TUI)
1139 1.1 christos /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1140 1.1 christos `tui_version'. */
1141 1.1 christos if (tui_active)
1142 1.1 christos /* FIXME: cagney/2004-02-07: This should be an observer. */
1143 1.1 christos low = tui_get_low_disassembly_address (gdbarch, low, pc);
1144 1.1 christos #endif
1145 1.1 christos low += gdbarch_deprecated_function_start_offset (gdbarch);
1146 1.1 christos
1147 1.1 christos print_disassembly (gdbarch, name, low, high, flags);
1148 1.1 christos }
1149 1.1 christos
1150 1.1 christos /* Dump a specified section of assembly code.
1151 1.1 christos
1152 1.1 christos Usage:
1153 1.1 christos disassemble [/mr]
1154 1.1 christos - dump the assembly code for the function of the current pc
1155 1.1 christos disassemble [/mr] addr
1156 1.1 christos - dump the assembly code for the function at ADDR
1157 1.1 christos disassemble [/mr] low,high
1158 1.1 christos disassemble [/mr] low,+length
1159 1.1 christos - dump the assembly code in the range [LOW,HIGH), or [LOW,LOW+length)
1160 1.1 christos
1161 1.1 christos A /m modifier will include source code with the assembly.
1162 1.1 christos A /r modifier will include raw instructions in hex with the assembly. */
1163 1.1 christos
1164 1.1 christos static void
1165 1.1 christos disassemble_command (char *arg, int from_tty)
1166 1.1 christos {
1167 1.1 christos struct gdbarch *gdbarch = get_current_arch ();
1168 1.1 christos CORE_ADDR low, high;
1169 1.1 christos const char *name;
1170 1.1 christos CORE_ADDR pc;
1171 1.1 christos int flags;
1172 1.1 christos const char *p;
1173 1.1 christos
1174 1.1 christos p = arg;
1175 1.1 christos name = NULL;
1176 1.1 christos flags = 0;
1177 1.1 christos
1178 1.1 christos if (p && *p == '/')
1179 1.1 christos {
1180 1.1 christos ++p;
1181 1.1 christos
1182 1.1 christos if (*p == '\0')
1183 1.1 christos error (_("Missing modifier."));
1184 1.1 christos
1185 1.1 christos while (*p && ! isspace (*p))
1186 1.1 christos {
1187 1.1 christos switch (*p++)
1188 1.1 christos {
1189 1.1 christos case 'm':
1190 1.1 christos flags |= DISASSEMBLY_SOURCE;
1191 1.1 christos break;
1192 1.1 christos case 'r':
1193 1.1 christos flags |= DISASSEMBLY_RAW_INSN;
1194 1.1 christos break;
1195 1.1 christos default:
1196 1.1 christos error (_("Invalid disassembly modifier."));
1197 1.1 christos }
1198 1.1 christos }
1199 1.1 christos
1200 1.1 christos p = skip_spaces_const (p);
1201 1.1 christos }
1202 1.1 christos
1203 1.1 christos if (! p || ! *p)
1204 1.1 christos {
1205 1.1 christos flags |= DISASSEMBLY_OMIT_FNAME;
1206 1.1 christos disassemble_current_function (flags);
1207 1.1 christos return;
1208 1.1 christos }
1209 1.1 christos
1210 1.1 christos pc = value_as_address (parse_to_comma_and_eval (&p));
1211 1.1 christos if (p[0] == ',')
1212 1.1 christos ++p;
1213 1.1 christos if (p[0] == '\0')
1214 1.1 christos {
1215 1.1 christos /* One argument. */
1216 1.1 christos if (find_pc_partial_function (pc, &name, &low, &high) == 0)
1217 1.1 christos error (_("No function contains specified address."));
1218 1.1 christos #if defined(TUI)
1219 1.1 christos /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1220 1.1 christos `tui_version'. */
1221 1.1 christos if (tui_active)
1222 1.1 christos /* FIXME: cagney/2004-02-07: This should be an observer. */
1223 1.1 christos low = tui_get_low_disassembly_address (gdbarch, low, pc);
1224 1.1 christos #endif
1225 1.1 christos low += gdbarch_deprecated_function_start_offset (gdbarch);
1226 1.1 christos flags |= DISASSEMBLY_OMIT_FNAME;
1227 1.1 christos }
1228 1.1 christos else
1229 1.1 christos {
1230 1.1 christos /* Two arguments. */
1231 1.1 christos int incl_flag = 0;
1232 1.1 christos low = pc;
1233 1.1 christos p = skip_spaces_const (p);
1234 1.1 christos if (p[0] == '+')
1235 1.1 christos {
1236 1.1 christos ++p;
1237 1.1 christos incl_flag = 1;
1238 1.1 christos }
1239 1.1 christos high = parse_and_eval_address (p);
1240 1.1 christos if (incl_flag)
1241 1.1 christos high += low;
1242 1.1 christos }
1243 1.1 christos
1244 1.1 christos print_disassembly (gdbarch, name, low, high, flags);
1245 1.1 christos }
1246 1.1 christos
1247 1.1 christos static void
1248 1.1 christos make_command (char *arg, int from_tty)
1249 1.1 christos {
1250 1.1 christos char *p;
1251 1.1 christos
1252 1.1 christos if (arg == 0)
1253 1.1 christos p = "make";
1254 1.1 christos else
1255 1.1 christos {
1256 1.1 christos p = xmalloc (sizeof ("make ") + strlen (arg));
1257 1.1 christos strcpy (p, "make ");
1258 1.1 christos strcpy (p + sizeof ("make ") - 1, arg);
1259 1.1 christos }
1260 1.1 christos
1261 1.1 christos shell_escape (p, from_tty);
1262 1.1 christos }
1263 1.1 christos
1264 1.1 christos static void
1265 1.1 christos show_user (char *args, int from_tty)
1266 1.1 christos {
1267 1.1 christos struct cmd_list_element *c;
1268 1.1 christos extern struct cmd_list_element *cmdlist;
1269 1.3 christos
1270 1.1 christos if (args)
1271 1.1 christos {
1272 1.1 christos const char *comname = args;
1273 1.1 christos
1274 1.1 christos c = lookup_cmd (&comname, cmdlist, "", 0, 1);
1275 1.1 christos if (!cli_user_command_p (c))
1276 1.1 christos error (_("Not a user command."));
1277 1.3 christos show_user_1 (c, "", args, gdb_stdout);
1278 1.1 christos }
1279 1.1 christos else
1280 1.1 christos {
1281 1.1 christos for (c = cmdlist; c; c = c->next)
1282 1.1 christos {
1283 1.1 christos if (cli_user_command_p (c) || c->prefixlist != NULL)
1284 1.1 christos show_user_1 (c, "", c->name, gdb_stdout);
1285 1.1 christos }
1286 1.1 christos }
1287 1.1 christos }
1288 1.1 christos
1289 1.1 christos /* Search through names of commands and documentations for a certain
1290 1.1 christos regular expression. */
1291 1.1 christos
1292 1.1 christos static void
1293 1.1 christos apropos_command (char *searchstr, int from_tty)
1294 1.1 christos {
1295 1.1 christos regex_t pattern;
1296 1.1 christos int code;
1297 1.1 christos
1298 1.1 christos if (searchstr == NULL)
1299 1.1 christos error (_("REGEXP string is empty"));
1300 1.1 christos
1301 1.1 christos code = regcomp (&pattern, searchstr, REG_ICASE);
1302 1.1 christos if (code == 0)
1303 1.1 christos {
1304 1.1 christos struct cleanup *cleanups;
1305 1.1 christos
1306 1.1 christos cleanups = make_regfree_cleanup (&pattern);
1307 1.1 christos apropos_cmd (gdb_stdout, cmdlist, &pattern, "");
1308 1.1 christos do_cleanups (cleanups);
1309 1.1 christos }
1310 1.1 christos else
1311 1.1 christos {
1312 1.1 christos char *err = get_regcomp_error (code, &pattern);
1313 1.1 christos
1314 1.1 christos make_cleanup (xfree, err);
1315 1.1 christos error (_("Error in regular expression: %s"), err);
1316 1.1 christos }
1317 1.1 christos }
1318 1.1 christos
1319 1.1 christos /* Subroutine of alias_command to simplify it.
1320 1.1 christos Return the first N elements of ARGV flattened back to a string
1321 1.1 christos with a space separating each element.
1322 1.1 christos ARGV may not be NULL.
1323 1.1 christos This does not take care of quoting elements in case they contain spaces
1324 1.1 christos on purpose. */
1325 1.1 christos
1326 1.1 christos static dyn_string_t
1327 1.1 christos argv_to_dyn_string (char **argv, int n)
1328 1.1 christos {
1329 1.1 christos int i;
1330 1.1 christos dyn_string_t result = dyn_string_new (10);
1331 1.1 christos
1332 1.1 christos gdb_assert (argv != NULL);
1333 1.1 christos gdb_assert (n >= 0 && n <= countargv (argv));
1334 1.1 christos
1335 1.1 christos for (i = 0; i < n; ++i)
1336 1.1 christos {
1337 1.1 christos if (i > 0)
1338 1.1 christos dyn_string_append_char (result, ' ');
1339 1.1 christos dyn_string_append_cstr (result, argv[i]);
1340 1.1 christos }
1341 1.1 christos
1342 1.1 christos return result;
1343 1.1 christos }
1344 1.1 christos
1345 1.1 christos /* Subroutine of alias_command to simplify it.
1346 1.1 christos Return TRUE if COMMAND exists, unambiguously. Otherwise FALSE. */
1347 1.1 christos
1348 1.1 christos static int
1349 1.1 christos valid_command_p (const char *command)
1350 1.1 christos {
1351 1.1 christos struct cmd_list_element *c;
1352 1.1 christos
1353 1.1 christos c = lookup_cmd_1 (& command, cmdlist, NULL, 1);
1354 1.1 christos
1355 1.1 christos if (c == NULL || c == (struct cmd_list_element *) -1)
1356 1.1 christos return FALSE;
1357 1.1 christos
1358 1.1 christos /* This is the slightly tricky part.
1359 1.1 christos lookup_cmd_1 will return a pointer to the last part of COMMAND
1360 1.1 christos to match, leaving COMMAND pointing at the remainder. */
1361 1.1 christos while (*command == ' ' || *command == '\t')
1362 1.1 christos ++command;
1363 1.1 christos return *command == '\0';
1364 1.1 christos }
1365 1.1 christos
1366 1.1 christos /* Make an alias of an existing command. */
1367 1.1 christos
1368 1.1 christos static void
1369 1.1 christos alias_command (char *args, int from_tty)
1370 1.1 christos {
1371 1.1 christos int i, alias_argc, command_argc;
1372 1.1 christos int abbrev_flag = 0;
1373 1.1 christos char *args2, *equals, *alias, *command;
1374 1.1 christos char **alias_argv, **command_argv;
1375 1.1 christos dyn_string_t alias_dyn_string, command_dyn_string;
1376 1.1 christos struct cleanup *cleanup;
1377 1.1 christos static const char usage[] = N_("Usage: alias [-a] [--] ALIAS = COMMAND");
1378 1.1 christos
1379 1.1 christos if (args == NULL || strchr (args, '=') == NULL)
1380 1.1 christos error (_(usage));
1381 1.1 christos
1382 1.1 christos args2 = xstrdup (args);
1383 1.1 christos cleanup = make_cleanup (xfree, args2);
1384 1.1 christos equals = strchr (args2, '=');
1385 1.1 christos *equals = '\0';
1386 1.1 christos alias_argv = gdb_buildargv (args2);
1387 1.1 christos make_cleanup_freeargv (alias_argv);
1388 1.1 christos command_argv = gdb_buildargv (equals + 1);
1389 1.1 christos make_cleanup_freeargv (command_argv);
1390 1.1 christos
1391 1.1 christos for (i = 0; alias_argv[i] != NULL; )
1392 1.1 christos {
1393 1.1 christos if (strcmp (alias_argv[i], "-a") == 0)
1394 1.1 christos {
1395 1.1 christos ++alias_argv;
1396 1.1 christos abbrev_flag = 1;
1397 1.1 christos }
1398 1.1 christos else if (strcmp (alias_argv[i], "--") == 0)
1399 1.1 christos {
1400 1.1 christos ++alias_argv;
1401 1.1 christos break;
1402 1.1 christos }
1403 1.1 christos else
1404 1.1 christos break;
1405 1.1 christos }
1406 1.1 christos
1407 1.1 christos if (alias_argv[0] == NULL || command_argv[0] == NULL
1408 1.1 christos || *alias_argv[0] == '\0' || *command_argv[0] == '\0')
1409 1.1 christos error (_(usage));
1410 1.1 christos
1411 1.1 christos for (i = 0; alias_argv[i] != NULL; ++i)
1412 1.1 christos {
1413 1.1 christos if (! valid_user_defined_cmd_name_p (alias_argv[i]))
1414 1.1 christos {
1415 1.1 christos if (i == 0)
1416 1.1 christos error (_("Invalid command name: %s"), alias_argv[i]);
1417 1.1 christos else
1418 1.1 christos error (_("Invalid command element name: %s"), alias_argv[i]);
1419 1.1 christos }
1420 1.1 christos }
1421 1.1 christos
1422 1.1 christos alias_argc = countargv (alias_argv);
1423 1.1 christos command_argc = countargv (command_argv);
1424 1.1 christos
1425 1.1 christos /* COMMAND must exist.
1426 1.1 christos Reconstruct the command to remove any extraneous spaces,
1427 1.1 christos for better error messages. */
1428 1.1 christos command_dyn_string = argv_to_dyn_string (command_argv, command_argc);
1429 1.1 christos make_cleanup_dyn_string_delete (command_dyn_string);
1430 1.1 christos command = dyn_string_buf (command_dyn_string);
1431 1.1 christos if (! valid_command_p (command))
1432 1.1 christos error (_("Invalid command to alias to: %s"), command);
1433 1.1 christos
1434 1.1 christos /* ALIAS must not exist. */
1435 1.1 christos alias_dyn_string = argv_to_dyn_string (alias_argv, alias_argc);
1436 1.1 christos make_cleanup_dyn_string_delete (alias_dyn_string);
1437 1.1 christos alias = dyn_string_buf (alias_dyn_string);
1438 1.1 christos if (valid_command_p (alias))
1439 1.1 christos error (_("Alias already exists: %s"), alias);
1440 1.1 christos
1441 1.1 christos /* If ALIAS is one word, it is an alias for the entire COMMAND.
1442 1.1 christos Example: alias spe = set print elements
1443 1.1 christos
1444 1.1 christos Otherwise ALIAS and COMMAND must have the same number of words,
1445 1.1 christos and every word except the last must match; and the last word of
1446 1.1 christos ALIAS is made an alias of the last word of COMMAND.
1447 1.1 christos Example: alias set print elms = set pr elem
1448 1.1 christos Note that unambiguous abbreviations are allowed. */
1449 1.1 christos
1450 1.1 christos if (alias_argc == 1)
1451 1.1 christos {
1452 1.1 christos /* add_cmd requires *we* allocate space for name, hence the xstrdup. */
1453 1.1 christos add_com_alias (xstrdup (alias_argv[0]), command, class_alias,
1454 1.1 christos abbrev_flag);
1455 1.1 christos }
1456 1.1 christos else
1457 1.1 christos {
1458 1.1 christos dyn_string_t alias_prefix_dyn_string, command_prefix_dyn_string;
1459 1.1 christos const char *alias_prefix, *command_prefix;
1460 1.1 christos struct cmd_list_element *c_alias, *c_command;
1461 1.1 christos
1462 1.1 christos if (alias_argc != command_argc)
1463 1.1 christos error (_("Mismatched command length between ALIAS and COMMAND."));
1464 1.1 christos
1465 1.1 christos /* Create copies of ALIAS and COMMAND without the last word,
1466 1.1 christos and use that to verify the leading elements match. */
1467 1.1 christos alias_prefix_dyn_string =
1468 1.1 christos argv_to_dyn_string (alias_argv, alias_argc - 1);
1469 1.1 christos make_cleanup_dyn_string_delete (alias_prefix_dyn_string);
1470 1.1 christos command_prefix_dyn_string =
1471 1.1 christos argv_to_dyn_string (alias_argv, command_argc - 1);
1472 1.1 christos make_cleanup_dyn_string_delete (command_prefix_dyn_string);
1473 1.1 christos alias_prefix = dyn_string_buf (alias_prefix_dyn_string);
1474 1.1 christos command_prefix = dyn_string_buf (command_prefix_dyn_string);
1475 1.1 christos
1476 1.1 christos c_command = lookup_cmd_1 (& command_prefix, cmdlist, NULL, 1);
1477 1.1 christos /* We've already tried to look up COMMAND. */
1478 1.1 christos gdb_assert (c_command != NULL
1479 1.1 christos && c_command != (struct cmd_list_element *) -1);
1480 1.1 christos gdb_assert (c_command->prefixlist != NULL);
1481 1.1 christos c_alias = lookup_cmd_1 (& alias_prefix, cmdlist, NULL, 1);
1482 1.1 christos if (c_alias != c_command)
1483 1.1 christos error (_("ALIAS and COMMAND prefixes do not match."));
1484 1.1 christos
1485 1.1 christos /* add_cmd requires *we* allocate space for name, hence the xstrdup. */
1486 1.1 christos add_alias_cmd (xstrdup (alias_argv[alias_argc - 1]),
1487 1.1 christos command_argv[command_argc - 1],
1488 1.1 christos class_alias, abbrev_flag, c_command->prefixlist);
1489 1.1 christos }
1490 1.1 christos
1491 1.1 christos do_cleanups (cleanup);
1492 1.1 christos }
1493 1.1 christos
1494 1.1 christos /* Print a list of files and line numbers which a user may choose from
1496 1.1 christos in order to list a function which was specified ambiguously (as
1497 1.1 christos with `list classname::overloadedfuncname', for example). The
1498 1.1 christos vector in SALS provides the filenames and line numbers. */
1499 1.1 christos
1500 1.1 christos static void
1501 1.1 christos ambiguous_line_spec (struct symtabs_and_lines *sals)
1502 1.1 christos {
1503 1.1 christos int i;
1504 1.1 christos
1505 1.1 christos for (i = 0; i < sals->nelts; ++i)
1506 1.1 christos printf_filtered (_("file: \"%s\", line number: %d\n"),
1507 1.1 christos symtab_to_filename_for_display (sals->sals[i].symtab),
1508 1.1 christos sals->sals[i].line);
1509 1.1 christos }
1510 1.1 christos
1511 1.3 christos /* Sort function for filter_sals. */
1512 1.3 christos
1513 1.1 christos static int
1514 1.1 christos compare_symtabs (const void *a, const void *b)
1515 1.3 christos {
1516 1.1 christos const struct symtab_and_line *sala = a;
1517 1.3 christos const struct symtab_and_line *salb = b;
1518 1.1 christos const char *dira = SYMTAB_DIRNAME (sala->symtab);
1519 1.1 christos const char *dirb = SYMTAB_DIRNAME (salb->symtab);
1520 1.3 christos int r;
1521 1.1 christos
1522 1.3 christos if (dira == NULL)
1523 1.1 christos {
1524 1.1 christos if (dirb != NULL)
1525 1.1 christos return -1;
1526 1.1 christos }
1527 1.3 christos else if (dirb == NULL)
1528 1.1 christos {
1529 1.1 christos if (dira != NULL)
1530 1.1 christos return 1;
1531 1.1 christos }
1532 1.1 christos else
1533 1.1 christos {
1534 1.1 christos r = filename_cmp (dira, dirb);
1535 1.1 christos if (r)
1536 1.1 christos return r;
1537 1.1 christos }
1538 1.1 christos
1539 1.1 christos r = filename_cmp (sala->symtab->filename, salb->symtab->filename);
1540 1.1 christos if (r)
1541 1.1 christos return r;
1542 1.1 christos
1543 1.1 christos if (sala->line < salb->line)
1544 1.1 christos return -1;
1545 1.1 christos return sala->line == salb->line ? 0 : 1;
1546 1.1 christos }
1547 1.1 christos
1548 1.1 christos /* Remove any SALs that do not match the current program space, or
1549 1.1 christos which appear to be "file:line" duplicates. */
1550 1.1 christos
1551 1.1 christos static void
1552 1.1 christos filter_sals (struct symtabs_and_lines *sals)
1553 1.1 christos {
1554 1.1 christos int i, out, prev;
1555 1.1 christos
1556 1.1 christos out = 0;
1557 1.1 christos for (i = 0; i < sals->nelts; ++i)
1558 1.1 christos {
1559 1.1 christos if (sals->sals[i].pspace == current_program_space
1560 1.1 christos && sals->sals[i].symtab != NULL)
1561 1.1 christos {
1562 1.1 christos sals->sals[out] = sals->sals[i];
1563 1.1 christos ++out;
1564 1.1 christos }
1565 1.1 christos }
1566 1.1 christos sals->nelts = out;
1567 1.1 christos
1568 1.1 christos qsort (sals->sals, sals->nelts, sizeof (struct symtab_and_line),
1569 1.1 christos compare_symtabs);
1570 1.1 christos
1571 1.1 christos out = 1;
1572 1.1 christos prev = 0;
1573 1.1 christos for (i = 1; i < sals->nelts; ++i)
1574 1.1 christos {
1575 1.1 christos if (compare_symtabs (&sals->sals[prev], &sals->sals[i]))
1576 1.1 christos {
1577 1.1 christos /* Symtabs differ. */
1578 1.1 christos sals->sals[out] = sals->sals[i];
1579 1.1 christos prev = out;
1580 1.1 christos ++out;
1581 1.1 christos }
1582 1.1 christos }
1583 1.1 christos
1584 1.1 christos if (sals->nelts == 0)
1585 1.1 christos {
1586 1.1 christos xfree (sals->sals);
1587 1.1 christos sals->sals = NULL;
1588 1.1 christos }
1589 1.1 christos else
1590 1.1 christos sals->nelts = out;
1591 1.3 christos }
1592 1.1 christos
1593 1.1 christos static void
1594 1.1 christos set_debug (char *arg, int from_tty)
1595 1.1 christos {
1596 1.1 christos printf_unfiltered (_("\"set debug\" must be followed by "
1597 1.1 christos "the name of a debug subcommand.\n"));
1598 1.1 christos help_list (setdebuglist, "set debug ", all_commands, gdb_stdout);
1599 1.1 christos }
1600 1.1 christos
1601 1.1 christos static void
1602 1.1 christos show_debug (char *args, int from_tty)
1603 1.1 christos {
1604 1.1 christos cmd_show_list (showdebuglist, from_tty, "");
1605 1.1 christos }
1606 1.1 christos
1607 1.1 christos void
1608 1.1 christos init_cmd_lists (void)
1609 1.1 christos {
1610 1.1 christos max_user_call_depth = 1024;
1611 1.1 christos }
1612 1.1 christos
1613 1.1 christos static void
1614 1.1 christos show_info_verbose (struct ui_file *file, int from_tty,
1615 1.1 christos struct cmd_list_element *c,
1616 1.1 christos const char *value)
1617 1.1 christos {
1618 1.1 christos if (info_verbose)
1619 1.1 christos fprintf_filtered (file,
1620 1.1 christos _("Verbose printing of informational messages is %s.\n"),
1621 1.1 christos value);
1622 1.1 christos else
1623 1.1 christos fprintf_filtered (file, _("Verbosity is %s.\n"), value);
1624 1.1 christos }
1625 1.1 christos
1626 1.1 christos static void
1627 1.1 christos show_history_expansion_p (struct ui_file *file, int from_tty,
1628 1.1 christos struct cmd_list_element *c, const char *value)
1629 1.1 christos {
1630 1.1 christos fprintf_filtered (file, _("History expansion on command input is %s.\n"),
1631 1.1 christos value);
1632 1.1 christos }
1633 1.1 christos
1634 1.1 christos static void
1635 1.1 christos show_remote_debug (struct ui_file *file, int from_tty,
1636 1.1 christos struct cmd_list_element *c, const char *value)
1637 1.1 christos {
1638 1.1 christos fprintf_filtered (file, _("Debugging of remote protocol is %s.\n"),
1639 1.1 christos value);
1640 1.1 christos }
1641 1.1 christos
1642 1.1 christos static void
1643 1.1 christos show_remote_timeout (struct ui_file *file, int from_tty,
1644 1.1 christos struct cmd_list_element *c, const char *value)
1645 1.1 christos {
1646 1.1 christos fprintf_filtered (file,
1647 1.1 christos _("Timeout limit to wait for target to respond is %s.\n"),
1648 1.1 christos value);
1649 1.1 christos }
1650 1.1 christos
1651 1.1 christos static void
1652 1.1 christos show_max_user_call_depth (struct ui_file *file, int from_tty,
1653 1.1 christos struct cmd_list_element *c, const char *value)
1654 1.1 christos {
1655 1.1 christos fprintf_filtered (file,
1656 1.1 christos _("The max call depth for user-defined commands is %s.\n"),
1657 1.1 christos value);
1658 1.1 christos }
1659 1.1 christos
1660 1.1 christos
1661 1.1 christos
1663 1.1 christos initialize_file_ftype _initialize_cli_cmds;
1664 1.1 christos
1665 1.1 christos void
1666 1.1 christos _initialize_cli_cmds (void)
1667 1.1 christos {
1668 1.1 christos struct cmd_list_element *c;
1669 1.1 christos
1670 1.1 christos /* Define the classes of commands.
1671 1.1 christos They will appear in the help list in alphabetical order. */
1672 1.1 christos
1673 1.1 christos add_cmd ("internals", class_maintenance, NULL, _("\
1674 1.1 christos Maintenance commands.\n\
1675 1.1 christos Some gdb commands are provided just for use by gdb maintainers.\n\
1676 1.1 christos These commands are subject to frequent change, and may not be as\n\
1677 1.1 christos well documented as user commands."),
1678 1.1 christos &cmdlist);
1679 1.1 christos add_cmd ("obscure", class_obscure, NULL, _("Obscure features."), &cmdlist);
1680 1.1 christos add_cmd ("aliases", class_alias, NULL,
1681 1.1 christos _("Aliases of other commands."), &cmdlist);
1682 1.1 christos add_cmd ("user-defined", class_user, NULL, _("\
1683 1.1 christos User-defined commands.\n\
1684 1.1 christos The commands in this class are those defined by the user.\n\
1685 1.1 christos Use the \"define\" command to define a command."), &cmdlist);
1686 1.1 christos add_cmd ("support", class_support, NULL, _("Support facilities."), &cmdlist);
1687 1.1 christos if (!dbx_commands)
1688 1.1 christos add_cmd ("status", class_info, NULL, _("Status inquiries."), &cmdlist);
1689 1.1 christos add_cmd ("files", class_files, NULL, _("Specifying and examining files."),
1690 1.1 christos &cmdlist);
1691 1.1 christos add_cmd ("breakpoints", class_breakpoint, NULL,
1692 1.1 christos _("Making program stop at certain points."), &cmdlist);
1693 1.1 christos add_cmd ("data", class_vars, NULL, _("Examining data."), &cmdlist);
1694 1.1 christos add_cmd ("stack", class_stack, NULL, _("\
1695 1.1 christos Examining the stack.\n\
1696 1.1 christos The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
1697 1.1 christos counting from zero for the innermost (currently executing) frame.\n\n\
1698 1.1 christos At any time gdb identifies one frame as the \"selected\" frame.\n\
1699 1.1 christos Variable lookups are done with respect to the selected frame.\n\
1700 1.1 christos When the program being debugged stops, gdb selects the innermost frame.\n\
1701 1.1 christos The commands below can be used to select other frames by number or address."),
1702 1.1 christos &cmdlist);
1703 1.1 christos add_cmd ("running", class_run, NULL, _("Running the program."), &cmdlist);
1704 1.1 christos
1705 1.1 christos /* Define general commands. */
1706 1.1 christos
1707 1.1 christos add_com ("pwd", class_files, pwd_command, _("\
1708 1.1 christos Print working directory. This is used for your program as well."));
1709 1.1 christos
1710 1.1 christos c = add_cmd ("cd", class_files, cd_command, _("\
1711 1.1 christos Set working directory to DIR for debugger and program being debugged.\n\
1712 1.1 christos The change does not take effect for the program being debugged\n\
1713 1.1 christos until the next time it is started."), &cmdlist);
1714 1.1 christos set_cmd_completer (c, filename_completer);
1715 1.1 christos
1716 1.1 christos add_com ("echo", class_support, echo_command, _("\
1717 1.1 christos Print a constant string. Give string as argument.\n\
1718 1.1 christos C escape sequences may be used in the argument.\n\
1719 1.1 christos No newline is added at the end of the argument;\n\
1720 1.1 christos use \"\\n\" if you want a newline to be printed.\n\
1721 1.1 christos Since leading and trailing whitespace are ignored in command arguments,\n\
1722 1.1 christos if you want to print some you must use \"\\\" before leading whitespace\n\
1723 1.1 christos to be printed or after trailing whitespace."));
1724 1.1 christos
1725 1.1 christos add_setshow_enum_cmd ("script-extension", class_support,
1726 1.1 christos script_ext_enums, &script_ext_mode, _("\
1727 1.1 christos Set mode for script filename extension recognition."), _("\
1728 1.1 christos Show mode for script filename extension recognition."), _("\
1729 1.1 christos off == no filename extension recognition (all sourced files are GDB scripts)\n\
1730 1.3 christos soft == evaluate script according to filename extension, fallback to GDB script"
1731 1.3 christos "\n\
1732 1.3 christos strict == evaluate script according to filename extension, error if not supported"
1733 1.3 christos ),
1734 1.3 christos NULL,
1735 1.1 christos show_script_ext_mode,
1736 1.1 christos &setlist, &showlist);
1737 1.1 christos
1738 1.1 christos add_com ("quit", class_support, quit_command, _("\
1739 1.1 christos Exit gdb.\n\
1740 1.1 christos Usage: quit [EXPR]\n\
1741 1.1 christos The optional expression EXPR, if present, is evaluated and the result\n\
1742 1.1 christos used as GDB's exit code. The default is zero."));
1743 1.1 christos c = add_com ("help", class_support, help_command,
1744 1.1 christos _("Print list of commands."));
1745 1.1 christos set_cmd_completer (c, command_completer);
1746 1.1 christos add_com_alias ("q", "quit", class_support, 1);
1747 1.1 christos add_com_alias ("h", "help", class_support, 1);
1748 1.1 christos
1749 1.1 christos add_setshow_boolean_cmd ("verbose", class_support, &info_verbose, _("\
1750 1.1 christos Set verbosity."), _("\
1751 1.1 christos Show verbosity."), NULL,
1752 1.1 christos set_verbose,
1753 1.1 christos show_info_verbose,
1754 1.1 christos &setlist, &showlist);
1755 1.1 christos
1756 1.1 christos add_prefix_cmd ("history", class_support, set_history,
1757 1.1 christos _("Generic command for setting command history parameters."),
1758 1.1 christos &sethistlist, "set history ", 0, &setlist);
1759 1.1 christos add_prefix_cmd ("history", class_support, show_history,
1760 1.1 christos _("Generic command for showing command history parameters."),
1761 1.1 christos &showhistlist, "show history ", 0, &showlist);
1762 1.1 christos
1763 1.1 christos add_setshow_boolean_cmd ("expansion", no_class, &history_expansion_p, _("\
1764 1.1 christos Set history expansion on command input."), _("\
1765 1.1 christos Show history expansion on command input."), _("\
1766 1.1 christos Without an argument, history expansion is enabled."),
1767 1.1 christos NULL,
1768 1.1 christos show_history_expansion_p,
1769 1.1 christos &sethistlist, &showhistlist);
1770 1.1 christos
1771 1.1 christos add_prefix_cmd ("info", class_info, info_command, _("\
1772 1.1 christos Generic command for showing things about the program being debugged."),
1773 1.1 christos &infolist, "info ", 0, &cmdlist);
1774 1.1 christos add_com_alias ("i", "info", class_info, 1);
1775 1.1 christos add_com_alias ("inf", "info", class_info, 1);
1776 1.1 christos
1777 1.1 christos add_com ("complete", class_obscure, complete_command,
1778 1.1 christos _("List the completions for the rest of the line as a command."));
1779 1.1 christos
1780 1.1 christos add_prefix_cmd ("show", class_info, show_command, _("\
1781 1.1 christos Generic command for showing things about the debugger."),
1782 1.1 christos &showlist, "show ", 0, &cmdlist);
1783 1.1 christos /* Another way to get at the same thing. */
1784 1.1 christos add_info ("set", show_command, _("Show all GDB settings."));
1785 1.1 christos
1786 1.1 christos add_cmd ("commands", no_set_class, show_commands, _("\
1787 1.1 christos Show the history of commands you typed.\n\
1788 1.1 christos You can supply a command number to start with, or a `+' to start after\n\
1789 1.1 christos the previous command number shown."),
1790 1.1 christos &showlist);
1791 1.1 christos
1792 1.1 christos add_cmd ("version", no_set_class, show_version,
1793 1.1 christos _("Show what version of GDB this is."), &showlist);
1794 1.1 christos
1795 1.1 christos add_cmd ("configuration", no_set_class, show_configuration,
1796 1.1 christos _("Show how GDB was configured at build time."), &showlist);
1797 1.1 christos
1798 1.1 christos add_setshow_zinteger_cmd ("remote", no_class, &remote_debug, _("\
1799 1.1 christos Set debugging of remote protocol."), _("\
1800 1.1 christos Show debugging of remote protocol."), _("\
1801 1.1 christos When enabled, each packet sent or received with the remote target\n\
1802 1.1 christos is displayed."),
1803 1.1 christos NULL,
1804 1.1 christos show_remote_debug,
1805 1.1 christos &setdebuglist, &showdebuglist);
1806 1.1 christos
1807 1.1 christos add_setshow_zuinteger_unlimited_cmd ("remotetimeout", no_class,
1808 1.1 christos &remote_timeout, _("\
1809 1.1 christos Set timeout limit to wait for target to respond."), _("\
1810 1.1 christos Show timeout limit to wait for target to respond."), _("\
1811 1.1 christos This value is used to set the time limit for gdb to wait for a response\n\
1812 1.1 christos from the target."),
1813 1.1 christos NULL,
1814 1.1 christos show_remote_timeout,
1815 1.1 christos &setlist, &showlist);
1816 1.1 christos
1817 1.1 christos add_prefix_cmd ("debug", no_class, set_debug,
1818 1.1 christos _("Generic command for setting gdb debugging flags"),
1819 1.1 christos &setdebuglist, "set debug ", 0, &setlist);
1820 1.1 christos
1821 1.1 christos add_prefix_cmd ("debug", no_class, show_debug,
1822 1.1 christos _("Generic command for showing gdb debugging flags"),
1823 1.1 christos &showdebuglist, "show debug ", 0, &showlist);
1824 1.1 christos
1825 1.1 christos c = add_com ("shell", class_support, shell_escape, _("\
1826 1.1 christos Execute the rest of the line as a shell command.\n\
1827 1.1 christos With no arguments, run an inferior shell."));
1828 1.1 christos set_cmd_completer (c, filename_completer);
1829 1.1 christos
1830 1.1 christos c = add_com ("edit", class_files, edit_command, _("\
1831 1.1 christos Edit specified file or function.\n\
1832 1.1 christos With no argument, edits file containing most recent line listed.\n\
1833 1.1 christos Editing targets can be specified in these ways:\n\
1834 1.1 christos FILE:LINENUM, to edit at that line in that file,\n\
1835 1.1 christos FUNCTION, to edit at the beginning of that function,\n\
1836 1.1 christos FILE:FUNCTION, to distinguish among like-named static functions.\n\
1837 1.1 christos *ADDRESS, to edit at the line containing that address.\n\
1838 1.1 christos Uses EDITOR environment variable contents as editor (or ex as default)."));
1839 1.1 christos
1840 1.1 christos c->completer = location_completer;
1841 1.1 christos
1842 1.1 christos add_com ("list", class_files, list_command, _("\
1843 1.1 christos List specified function or line.\n\
1844 1.1 christos With no argument, lists ten more lines after or around previous listing.\n\
1845 1.1 christos \"list -\" lists the ten lines before a previous ten-line listing.\n\
1846 1.1 christos One argument specifies a line, and ten lines are listed around that line.\n\
1847 1.1 christos Two arguments with comma between specify starting and ending lines to list.\n\
1848 1.1 christos Lines can be specified in these ways:\n\
1849 1.5 christos LINENUM, to list around that line in current file,\n\
1850 1.1 christos FILE:LINENUM, to list around that line in that file,\n\
1851 1.1 christos FUNCTION, to list around beginning of that function,\n\
1852 1.1 christos FILE:FUNCTION, to distinguish among like-named static functions.\n\
1853 1.1 christos *ADDRESS, to list around the line containing that address.\n\
1854 1.1 christos With two args if one is empty it stands for ten lines away from \
1855 1.1 christos the other arg."));
1856 1.1 christos
1857 1.1 christos add_com_alias ("l", "list", class_files, 1);
1858 1.1 christos
1859 1.1 christos if (dbx_commands)
1860 1.1 christos add_com_alias ("file", "list", class_files, 1);
1861 1.1 christos
1862 1.1 christos c = add_com ("disassemble", class_vars, disassemble_command, _("\
1863 1.1 christos Disassemble a specified section of memory.\n\
1864 1.1 christos Default is the function surrounding the pc of the selected frame.\n\
1865 1.1 christos With a /m modifier, source lines are included (if available).\n\
1866 1.1 christos With a /r modifier, raw instructions in hex are included.\n\
1867 1.1 christos With a single argument, the function surrounding that address is dumped.\n\
1868 1.1 christos Two arguments (separated by a comma) are taken as a range of memory to dump,\n\
1869 1.1 christos in the form of \"start,end\", or \"start,+length\".\n\
1870 1.1 christos \n\
1871 1.1 christos Note that the address is interpreted as an expression, not as a location\n\
1872 1.1 christos like in the \"break\" command.\n\
1873 1.1 christos So, for example, if you want to disassemble function bar in file foo.c\n\
1874 1.1 christos you must type \"disassemble 'foo.c'::bar\" and not \"disassemble foo.c:bar\"."));
1875 1.3 christos set_cmd_completer (c, location_completer);
1876 1.1 christos
1877 1.1 christos add_com_alias ("!", "shell", class_support, 0);
1878 1.1 christos
1879 1.1 christos c = add_com ("make", class_support, make_command, _("\
1880 1.1 christos Run the ``make'' program using the rest of the line as arguments."));
1881 1.1 christos set_cmd_completer (c, filename_completer);
1882 1.1 christos add_cmd ("user", no_class, show_user, _("\
1883 1.3 christos Show definitions of non-python/scheme user defined commands.\n\
1884 1.3 christos Argument is the name of the user defined command.\n\
1885 1.1 christos With no argument, show definitions of all user defined commands."), &showlist);
1886 1.1 christos add_com ("apropos", class_support, apropos_command,
1887 1.1 christos _("Search for commands matching a REGEXP"));
1888 1.1 christos
1889 1.1 christos add_setshow_uinteger_cmd ("max-user-call-depth", no_class,
1890 1.1 christos &max_user_call_depth, _("\
1891 1.1 christos Set the max call depth for non-python/scheme user-defined commands."), _("\
1892 1.1 christos Show the max call depth for non-python/scheme user-defined commands."), NULL,
1893 1.1 christos NULL,
1894 1.1 christos show_max_user_call_depth,
1895 1.1 christos &setlist, &showlist);
1896 1.1 christos
1897 1.1 christos add_setshow_boolean_cmd ("trace-commands", no_class, &trace_commands, _("\
1898 1.1 christos Set tracing of GDB CLI commands."), _("\
1899 1.1 christos Show state of GDB CLI command tracing."), _("\
1900 1.1 christos When 'on', each command is displayed as it is executed."),
1901 1.1 christos NULL,
1902 1.1 christos NULL,
1903 1.1 christos &setlist, &showlist);
1904 1.1 christos
1905 1.1 christos c = add_com ("alias", class_support, alias_command, _("\
1906 1.1 christos Define a new command that is an alias of an existing command.\n\
1907 1.1 christos Usage: alias [-a] [--] ALIAS = COMMAND\n\
1908 1.1 christos ALIAS is the name of the alias command to create.\n\
1909 1.1 christos COMMAND is the command being aliased to.\n\
1910 1.1 christos If \"-a\" is specified, the command is an abbreviation,\n\
1911 1.1 christos and will not appear in help command list output.\n\
1912 1.1 christos \n\
1913 1.1 christos Examples:\n\
1914 1.1 christos Make \"spe\" an alias of \"set print elements\":\n\
1915 1.1 christos alias spe = set print elements\n\
1916 1.1 christos Make \"elms\" an alias of \"elements\" in the \"set print\" command:\n\
1917 1.1 christos alias -a set print elms = set print elements"));
1918 1.1 christos }
1919 1.1 christos
1920 1.1 christos void
1921 1.1 christos init_cli_cmds (void)
1922 1.1 christos {
1923 1.1 christos struct cmd_list_element *c;
1924 1.1 christos char *source_help_text;
1925 1.1 christos
1926 1.1 christos source_help_text = xstrprintf (_("\
1927 1.1 christos Read commands from a file named FILE.\n\
1928 1.1 christos \n\
1929 1.1 christos Usage: source [-s] [-v] FILE\n\
1930 1.1 christos -s: search for the script in the source search path,\n\
1931 1.1 christos even if FILE contains directories.\n\
1932 -v: each command in FILE is echoed as it is executed.\n\
1933 \n\
1934 Note that the file \"%s\" is read automatically in this way\n\
1935 when GDB is started."), gdbinit);
1936 c = add_cmd ("source", class_support, source_command,
1937 source_help_text, &cmdlist);
1938 set_cmd_completer (c, filename_completer);
1939 }
1940