]>
Commit | Line | Data |
---|---|---|
d318976c | 1 | /* GDB CLI commands. |
8926118c | 2 | |
d01e8234 | 3 | Copyright (C) 2000-2025 Free Software Foundation, Inc. |
d318976c FN |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
d318976c FN |
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 | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
d318976c | 19 | |
13274fc3 | 20 | #include "arch-utils.h" |
05d9d66d | 21 | #include "exceptions.h" |
dbda9972 | 22 | #include "readline/tilde.h" |
d318976c | 23 | #include "completer.h" |
ef0f16cc TT |
24 | #include "target.h" |
25 | #include "gdbsupport/gdb_wait.h" | |
ef0f16cc | 26 | #include "gdbsupport/gdb_regex.h" |
325ed089 | 27 | #include "gdb_vfork.h" |
0378c332 FN |
28 | #include "linespec.h" |
29 | #include "expression.h" | |
83c31e7d FN |
30 | #include "frame.h" |
31 | #include "value.h" | |
0378c332 | 32 | #include "language.h" |
ef0f16cc | 33 | #include "filenames.h" |
0378c332 FN |
34 | #include "objfiles.h" |
35 | #include "source.h" | |
83c31e7d | 36 | #include "disasm.h" |
33da3f1c | 37 | #include "tracepoint.h" |
268a13a5 | 38 | #include "gdbsupport/filestuff.h" |
f00aae0f | 39 | #include "location.h" |
e9480230 | 40 | #include "block.h" |
91265a7d | 41 | #include "valprint.h" |
d318976c | 42 | |
d318976c | 43 | #include "ui-out.h" |
947d3946 | 44 | #include "interps.h" |
d318976c FN |
45 | |
46 | #include "top.h" | |
13d03262 | 47 | #include "ui.h" |
d318976c FN |
48 | #include "cli/cli-decode.h" |
49 | #include "cli/cli-script.h" | |
50 | #include "cli/cli-setshow.h" | |
51 | #include "cli/cli-cmds.h" | |
14309bb6 | 52 | #include "cli/cli-style.h" |
529480d0 | 53 | #include "cli/cli-utils.h" |
d318976c | 54 | |
6dddc817 | 55 | #include "extension.h" |
268a13a5 | 56 | #include "gdbsupport/pathstuff.h" |
1845e254 | 57 | #include "gdbsupport/gdb_tilde_expand.h" |
9858f29e | 58 | #include "gdbsupport/eintr.h" |
973817a3 | 59 | |
6a83354a | 60 | #ifdef TUI |
ef0f16cc | 61 | #include "tui/tui.h" |
6a83354a AC |
62 | #endif |
63 | ||
4b505b12 | 64 | #include <fcntl.h> |
325fac50 | 65 | #include <algorithm> |
a97e29d2 | 66 | #include <string> |
4b505b12 | 67 | |
0378c332 FN |
68 | /* Prototypes for local utility functions */ |
69 | ||
06871ae8 PA |
70 | static void print_sal_location (const symtab_and_line &sal); |
71 | ||
6c5b2ebe | 72 | static void ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals, |
e439fa14 PA |
73 | const char *format, ...) |
74 | ATTRIBUTE_PRINTF (2, 3); | |
f8eba3c6 | 75 | |
6c5b2ebe | 76 | static void filter_sals (std::vector<symtab_and_line> &); |
f8eba3c6 | 77 | |
d318976c | 78 | \f |
cc8dee1f | 79 | /* See cli-cmds.h. */ |
37163dcf | 80 | unsigned int max_user_call_depth = 1024; |
20f01a46 | 81 | |
d318976c FN |
82 | /* Define all cmd_list_elements. */ |
83 | ||
84 | /* Chain containing all defined commands. */ | |
85 | ||
86 | struct cmd_list_element *cmdlist; | |
87 | ||
88 | /* Chain containing all defined info subcommands. */ | |
89 | ||
90 | struct cmd_list_element *infolist; | |
91 | ||
ebcd3b23 | 92 | /* Chain containing all defined enable subcommands. */ |
d318976c FN |
93 | |
94 | struct cmd_list_element *enablelist; | |
95 | ||
ebcd3b23 | 96 | /* Chain containing all defined disable subcommands. */ |
d318976c FN |
97 | |
98 | struct cmd_list_element *disablelist; | |
99 | ||
ebcd3b23 | 100 | /* Chain containing all defined stop subcommands. */ |
d318976c FN |
101 | |
102 | struct cmd_list_element *stoplist; | |
103 | ||
ebcd3b23 | 104 | /* Chain containing all defined delete subcommands. */ |
d318976c FN |
105 | |
106 | struct cmd_list_element *deletelist; | |
107 | ||
ebcd3b23 | 108 | /* Chain containing all defined detach subcommands. */ |
f73adfeb AS |
109 | |
110 | struct cmd_list_element *detachlist; | |
111 | ||
ebcd3b23 | 112 | /* Chain containing all defined kill subcommands. */ |
2277426b PA |
113 | |
114 | struct cmd_list_element *killlist; | |
115 | ||
d318976c FN |
116 | /* Chain containing all defined set subcommands */ |
117 | ||
118 | struct cmd_list_element *setlist; | |
119 | ||
120 | /* Chain containing all defined unset subcommands */ | |
121 | ||
122 | struct cmd_list_element *unsetlist; | |
123 | ||
124 | /* Chain containing all defined show subcommands. */ | |
125 | ||
126 | struct cmd_list_element *showlist; | |
127 | ||
128 | /* Chain containing all defined \"set history\". */ | |
129 | ||
130 | struct cmd_list_element *sethistlist; | |
131 | ||
132 | /* Chain containing all defined \"show history\". */ | |
133 | ||
134 | struct cmd_list_element *showhistlist; | |
135 | ||
136 | /* Chain containing all defined \"unset history\". */ | |
137 | ||
138 | struct cmd_list_element *unsethistlist; | |
139 | ||
ebcd3b23 | 140 | /* Chain containing all defined maintenance subcommands. */ |
d318976c FN |
141 | |
142 | struct cmd_list_element *maintenancelist; | |
143 | ||
ebcd3b23 | 144 | /* Chain containing all defined "maintenance info" subcommands. */ |
d318976c FN |
145 | |
146 | struct cmd_list_element *maintenanceinfolist; | |
147 | ||
ebcd3b23 | 148 | /* Chain containing all defined "maintenance print" subcommands. */ |
d318976c FN |
149 | |
150 | struct cmd_list_element *maintenanceprintlist; | |
151 | ||
27d41eac YQ |
152 | /* Chain containing all defined "maintenance check" subcommands. */ |
153 | ||
154 | struct cmd_list_element *maintenancechecklist; | |
155 | ||
50a5f187 AB |
156 | /* Chain containing all defined "maintenance flush" subcommands. */ |
157 | ||
158 | struct cmd_list_element *maintenanceflushlist; | |
159 | ||
d318976c FN |
160 | struct cmd_list_element *setprintlist; |
161 | ||
162 | struct cmd_list_element *showprintlist; | |
163 | ||
164 | struct cmd_list_element *setdebuglist; | |
165 | ||
166 | struct cmd_list_element *showdebuglist; | |
167 | ||
168 | struct cmd_list_element *setchecklist; | |
169 | ||
170 | struct cmd_list_element *showchecklist; | |
16026cd7 | 171 | |
fde1a9a3 AB |
172 | struct cmd_list_element *setsourcelist; |
173 | ||
174 | struct cmd_list_element *showsourcelist; | |
175 | ||
16026cd7 AS |
176 | /* Command tracing state. */ |
177 | ||
178 | int source_verbose = 0; | |
491144b5 | 179 | bool trace_commands = false; |
d318976c | 180 | \f |
973817a3 JB |
181 | /* 'script-extension' option support. */ |
182 | ||
183 | static const char script_ext_off[] = "off"; | |
184 | static const char script_ext_soft[] = "soft"; | |
185 | static const char script_ext_strict[] = "strict"; | |
186 | ||
40478521 | 187 | static const char *const script_ext_enums[] = { |
973817a3 JB |
188 | script_ext_off, |
189 | script_ext_soft, | |
190 | script_ext_strict, | |
191 | NULL | |
192 | }; | |
193 | ||
194 | static const char *script_ext_mode = script_ext_soft; | |
195 | \f | |
61fb7376 TBA |
196 | |
197 | /* User-controllable flag to suppress event notification on CLI. */ | |
198 | ||
199 | static bool user_wants_cli_suppress_notification = false; | |
200 | ||
d318976c | 201 | /* Utility used everywhere when at least one argument is needed and |
ebcd3b23 | 202 | none is supplied. */ |
d318976c FN |
203 | |
204 | void | |
5b10184c | 205 | error_no_arg (const char *why) |
d318976c | 206 | { |
8a3fe4f8 | 207 | error (_("Argument required (%s)."), why); |
d318976c FN |
208 | } |
209 | ||
4fd6c7e8 TT |
210 | /* This implements the "info" prefix command. Normally such commands |
211 | are automatically handled by add_basic_prefix_cmd, but in this case | |
212 | a separate command is used so that it can be hooked into by | |
213 | gdb-gdb.gdb. */ | |
214 | ||
215 | static void | |
216 | info_command (const char *arg, int from_tty) | |
217 | { | |
652e09d5 | 218 | help_list (infolist, "info", all_commands, gdb_stdout); |
4fd6c7e8 TT |
219 | } |
220 | ||
fdbc9870 PA |
221 | /* See cli/cli-cmds.h. */ |
222 | ||
223 | void | |
224 | with_command_1 (const char *set_cmd_prefix, | |
225 | cmd_list_element *setlist, const char *args, int from_tty) | |
226 | { | |
26c957f1 PA |
227 | if (args == nullptr) |
228 | error (_("Missing arguments.")); | |
229 | ||
fdbc9870 PA |
230 | const char *delim = strstr (args, "--"); |
231 | const char *nested_cmd = nullptr; | |
232 | ||
233 | if (delim == args) | |
234 | error (_("Missing setting before '--' delimiter")); | |
235 | ||
236 | if (delim == nullptr || *skip_spaces (&delim[2]) == '\0') | |
237 | nested_cmd = repeat_previous (); | |
238 | ||
239 | cmd_list_element *set_cmd = lookup_cmd (&args, setlist, set_cmd_prefix, | |
cf00cd6f | 240 | nullptr, |
fdbc9870 PA |
241 | /*allow_unknown=*/ 0, |
242 | /*ignore_help_classes=*/ 1); | |
243 | gdb_assert (set_cmd != nullptr); | |
244 | ||
1d7fe7f0 | 245 | if (!set_cmd->var.has_value ()) |
fdbc9870 PA |
246 | error (_("Cannot use this setting with the \"with\" command")); |
247 | ||
248 | std::string temp_value | |
249 | = (delim == nullptr ? args : std::string (args, delim - args)); | |
250 | ||
251 | if (nested_cmd == nullptr) | |
252 | nested_cmd = skip_spaces (delim + 2); | |
253 | ||
1d7fe7f0 LS |
254 | gdb_assert (set_cmd->var.has_value ()); |
255 | std::string org_value = get_setshow_command_value_string (*set_cmd->var); | |
fdbc9870 PA |
256 | |
257 | /* Tweak the setting to the new temporary value. */ | |
258 | do_set_command (temp_value.c_str (), from_tty, set_cmd); | |
259 | ||
260 | try | |
261 | { | |
262 | scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); | |
263 | ||
264 | /* Execute the nested command. */ | |
265 | execute_command (nested_cmd, from_tty); | |
266 | } | |
267 | catch (const gdb_exception &ex) | |
268 | { | |
269 | /* Restore the setting and rethrow. If restoring the setting | |
270 | throws, swallow the new exception and warn. There's nothing | |
271 | else we can reasonably do. */ | |
272 | try | |
273 | { | |
274 | do_set_command (org_value.c_str (), from_tty, set_cmd); | |
275 | } | |
276 | catch (const gdb_exception &ex2) | |
277 | { | |
278 | warning (_("Couldn't restore setting: %s"), ex2.what ()); | |
279 | } | |
280 | ||
281 | throw; | |
282 | } | |
283 | ||
284 | /* Restore the setting. */ | |
285 | do_set_command (org_value.c_str (), from_tty, set_cmd); | |
286 | } | |
287 | ||
288 | /* See cli/cli-cmds.h. */ | |
289 | ||
290 | void | |
291 | with_command_completer_1 (const char *set_cmd_prefix, | |
292 | completion_tracker &tracker, | |
293 | const char *text) | |
294 | { | |
295 | tracker.set_use_custom_word_point (true); | |
296 | ||
297 | const char *delim = strstr (text, "--"); | |
298 | ||
299 | /* If we're still not past the "--" delimiter, complete the "with" | |
300 | command as if it was a "set" command. */ | |
301 | if (delim == text | |
302 | || delim == nullptr | |
303 | || !isspace (delim[-1]) | |
304 | || !(isspace (delim[2]) || delim[2] == '\0')) | |
305 | { | |
306 | std::string new_text = std::string (set_cmd_prefix) + text; | |
307 | tracker.advance_custom_word_point_by (-(int) strlen (set_cmd_prefix)); | |
308 | complete_nested_command_line (tracker, new_text.c_str ()); | |
309 | return; | |
310 | } | |
311 | ||
312 | /* We're past the "--" delimiter. Complete on the sub command. */ | |
313 | const char *nested_cmd = skip_spaces (delim + 2); | |
314 | tracker.advance_custom_word_point_by (nested_cmd - text); | |
315 | complete_nested_command_line (tracker, nested_cmd); | |
316 | } | |
317 | ||
318 | /* The "with" command. */ | |
319 | ||
320 | static void | |
321 | with_command (const char *args, int from_tty) | |
322 | { | |
323 | with_command_1 ("set ", setlist, args, from_tty); | |
324 | } | |
325 | ||
326 | /* "with" command completer. */ | |
327 | ||
328 | static void | |
329 | with_command_completer (struct cmd_list_element *ignore, | |
330 | completion_tracker &tracker, | |
331 | const char *text, const char * /*word*/) | |
332 | { | |
333 | with_command_completer_1 ("set ", tracker, text); | |
334 | } | |
335 | ||
cf00cd6f PW |
336 | /* Look up the contents of TEXT as a command usable with default args. |
337 | Throws an error if no such command is found. | |
338 | Return the found command and advances TEXT past the found command. | |
339 | If the found command is a postfix command, set *PREFIX_CMD to its | |
340 | prefix command. */ | |
341 | ||
342 | static struct cmd_list_element * | |
343 | lookup_cmd_for_default_args (const char **text, | |
344 | struct cmd_list_element **prefix_cmd) | |
345 | { | |
346 | const char *orig_text = *text; | |
347 | struct cmd_list_element *lcmd; | |
348 | ||
349 | if (*text == nullptr || skip_spaces (*text) == nullptr) | |
350 | error (_("ALIAS missing.")); | |
351 | ||
352 | /* We first use lookup_cmd to verify TEXT unambiguously identifies | |
353 | a command. */ | |
354 | lcmd = lookup_cmd (text, cmdlist, "", NULL, | |
355 | /*allow_unknown=*/ 0, | |
356 | /*ignore_help_classes=*/ 1); | |
357 | ||
358 | /* Note that we accept default args for prefix commands, | |
359 | as a prefix command can also be a valid usable | |
360 | command accepting some arguments. | |
361 | For example, "thread apply" applies a command to a | |
362 | list of thread ids, and is also the prefix command for | |
363 | thread apply all. */ | |
364 | ||
365 | /* We have an unambiguous command for which default args | |
366 | can be specified. What remains after having found LCMD | |
367 | is either spaces, or the default args character. */ | |
368 | ||
369 | /* We then use lookup_cmd_composition to detect if the user | |
370 | has specified an alias, and find the possible prefix_cmd | |
371 | of cmd. */ | |
372 | struct cmd_list_element *alias, *cmd; | |
373 | lookup_cmd_composition | |
374 | (std::string (orig_text, *text - orig_text).c_str (), | |
375 | &alias, prefix_cmd, &cmd); | |
376 | gdb_assert (cmd != nullptr); | |
377 | gdb_assert (cmd == lcmd); | |
378 | if (alias != nullptr) | |
379 | cmd = alias; | |
380 | ||
381 | return cmd; | |
382 | } | |
383 | ||
d318976c FN |
384 | /* Provide documentation on command or list given by COMMAND. FROM_TTY |
385 | is ignored. */ | |
386 | ||
d318976c | 387 | static void |
0b39b52e | 388 | help_command (const char *command, int from_tty) |
d318976c FN |
389 | { |
390 | help_cmd (command, gdb_stdout); | |
391 | } | |
392 | \f | |
eb3ff9a5 | 393 | |
ef0b411a GB |
394 | /* Note: The "complete" command is used by Emacs to implement completion. |
395 | [Is that why this function writes output with *_unfiltered?] */ | |
d318976c | 396 | |
d318976c | 397 | static void |
0b39b52e | 398 | complete_command (const char *arg, int from_tty) |
d318976c | 399 | { |
d318976c FN |
400 | dont_repeat (); |
401 | ||
ef0b411a GB |
402 | if (max_completions == 0) |
403 | { | |
404 | /* Only print this for non-mi frontends. An MI frontend may not | |
405 | be able to handle this. */ | |
112e8700 | 406 | if (!current_uiout->is_mi_like_p ()) |
ef0b411a GB |
407 | { |
408 | printf_unfiltered (_("max-completions is zero," | |
409 | " completion is disabled.\n")); | |
410 | } | |
411 | return; | |
412 | } | |
413 | ||
d318976c FN |
414 | if (arg == NULL) |
415 | arg = ""; | |
d9b52655 | 416 | |
6a2c1b87 PA |
417 | int quote_char = '\0'; |
418 | const char *word; | |
419 | ||
6e035501 | 420 | completion_result result = complete (arg, &word, "e_char); |
eb3ff9a5 | 421 | |
eb3ff9a5 PA |
422 | if (result.number_matches != 0) |
423 | { | |
fb7806c7 TV |
424 | std::string arg_prefix (arg, word - arg); |
425 | ||
1d1df753 | 426 | result.print_matches (arg_prefix, word, quote_char); |
d318976c FN |
427 | } |
428 | } | |
429 | ||
bbaca940 AC |
430 | int |
431 | is_complete_command (struct cmd_list_element *c) | |
d318976c | 432 | { |
3a553c80 | 433 | return cmd_simple_func_eq (c, complete_command); |
d318976c FN |
434 | } |
435 | ||
d318976c | 436 | static void |
dede02ce | 437 | show_version (const char *args, int from_tty) |
d318976c | 438 | { |
c61b06a1 | 439 | print_gdb_version (gdb_stdout, true); |
6cb06a8c | 440 | gdb_printf ("\n"); |
d318976c FN |
441 | } |
442 | ||
6eaaf48b | 443 | static void |
dede02ce | 444 | show_configuration (const char *args, int from_tty) |
6eaaf48b EZ |
445 | { |
446 | print_gdb_configuration (gdb_stdout); | |
447 | } | |
448 | ||
d318976c FN |
449 | /* Handle the quit command. */ |
450 | ||
451 | void | |
0b39b52e | 452 | quit_command (const char *args, int from_tty) |
d318976c | 453 | { |
36cf1806 TT |
454 | int exit_code = 0; |
455 | ||
456 | /* An optional expression may be used to cause gdb to terminate with | |
457 | the value of that expression. */ | |
458 | if (args) | |
459 | { | |
460 | struct value *val = parse_and_eval (args); | |
461 | ||
462 | exit_code = (int) value_as_long (val); | |
463 | } | |
464 | ||
d318976c | 465 | if (!quit_confirm ()) |
8a3fe4f8 | 466 | error (_("Not confirmed.")); |
d5551862 | 467 | |
be6a2dca TV |
468 | try |
469 | { | |
470 | query_if_trace_running (from_tty); | |
471 | } | |
472 | catch (const gdb_exception_error &ex) | |
473 | { | |
474 | if (ex.error == TARGET_CLOSE_ERROR) | |
475 | /* We don't care about this since we're quitting anyway, so keep | |
476 | quitting. */ | |
477 | exception_print (gdb_stderr, ex); | |
478 | else | |
479 | /* Rethrow, to properly handle error (_("Not confirmed.")). */ | |
480 | throw; | |
481 | } | |
d5551862 | 482 | |
36cf1806 | 483 | quit_force (args ? &exit_code : NULL, from_tty); |
d318976c FN |
484 | } |
485 | ||
d318976c | 486 | static void |
0b39b52e | 487 | pwd_command (const char *args, int from_tty) |
d318976c FN |
488 | { |
489 | if (args) | |
8a3fe4f8 | 490 | error (_("The \"pwd\" command does not take an argument: %s"), args); |
43573013 SDJ |
491 | |
492 | gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0)); | |
493 | ||
494 | if (cwd == NULL) | |
bf1d7d9c | 495 | error (_("Error finding name of working directory: %s"), |
dda83cd7 | 496 | safe_strerror (errno)); |
d318976c | 497 | |
43573013 | 498 | if (strcmp (cwd.get (), current_directory) != 0) |
6cb06a8c TT |
499 | gdb_printf (_("Working directory %ps\n (canonically %ps).\n"), |
500 | styled_string (file_name_style.style (), | |
501 | current_directory), | |
502 | styled_string (file_name_style.style (), cwd.get ())); | |
d318976c | 503 | else |
6cb06a8c TT |
504 | gdb_printf (_("Working directory %ps.\n"), |
505 | styled_string (file_name_style.style (), | |
506 | current_directory)); | |
d318976c FN |
507 | } |
508 | ||
509 | void | |
5e93d4c6 | 510 | cd_command (const char *dir, int from_tty) |
d318976c FN |
511 | { |
512 | int len; | |
513 | /* Found something other than leading repetitions of "/..". */ | |
514 | int found_real_path; | |
515 | char *p; | |
516 | ||
517 | /* If the new directory is absolute, repeat is a no-op; if relative, | |
518 | repeat might be useful but is more likely to be a mistake. */ | |
519 | dont_repeat (); | |
520 | ||
6eecf35f TT |
521 | gdb::unique_xmalloc_ptr<char> dir_holder |
522 | (tilde_expand (dir != NULL ? dir : "~")); | |
523 | dir = dir_holder.get (); | |
d318976c FN |
524 | |
525 | if (chdir (dir) < 0) | |
526 | perror_with_name (dir); | |
527 | ||
c3690141 | 528 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
d318976c FN |
529 | /* There's too much mess with DOSish names like "d:", "d:.", |
530 | "d:./foo" etc. Instead of having lots of special #ifdef'ed code, | |
531 | simply get the canonicalized name of the current directory. */ | |
43573013 SDJ |
532 | gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0)); |
533 | dir = cwd.get (); | |
d318976c FN |
534 | #endif |
535 | ||
536 | len = strlen (dir); | |
fe4e3eb8 | 537 | if (IS_DIR_SEPARATOR (dir[len - 1])) |
d318976c FN |
538 | { |
539 | /* Remove the trailing slash unless this is a root directory | |
dda83cd7 | 540 | (including a drive letter on non-Unix systems). */ |
d318976c | 541 | if (!(len == 1) /* "/" */ |
c3690141 | 542 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
fe4e3eb8 | 543 | && !(len == 3 && dir[1] == ':') /* "d:/" */ |
d318976c FN |
544 | #endif |
545 | ) | |
546 | len--; | |
547 | } | |
548 | ||
6eecf35f TT |
549 | dir_holder.reset (savestring (dir, len)); |
550 | if (IS_ABSOLUTE_PATH (dir_holder.get ())) | |
43573013 SDJ |
551 | { |
552 | xfree (current_directory); | |
553 | current_directory = dir_holder.release (); | |
554 | } | |
d318976c FN |
555 | else |
556 | { | |
fe4e3eb8 | 557 | if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])) |
6eecf35f TT |
558 | current_directory = concat (current_directory, dir_holder.get (), |
559 | (char *) NULL); | |
d318976c | 560 | else |
1754f103 | 561 | current_directory = concat (current_directory, SLASH_STRING, |
6eecf35f | 562 | dir_holder.get (), (char *) NULL); |
d318976c FN |
563 | } |
564 | ||
565 | /* Now simplify any occurrences of `.' and `..' in the pathname. */ | |
566 | ||
567 | found_real_path = 0; | |
568 | for (p = current_directory; *p;) | |
569 | { | |
fe4e3eb8 EZ |
570 | if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' |
571 | && (p[2] == 0 || IS_DIR_SEPARATOR (p[2]))) | |
b2a3b509 | 572 | memmove (p, p + 2, strlen (p + 2) + 1); |
fe4e3eb8 EZ |
573 | else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.' |
574 | && (p[3] == 0 || IS_DIR_SEPARATOR (p[3]))) | |
d318976c FN |
575 | { |
576 | if (found_real_path) | |
577 | { | |
578 | /* Search backwards for the directory just before the "/.." | |
dda83cd7 | 579 | and obliterate it and the "/..". */ |
d318976c | 580 | char *q = p; |
cdb27c12 | 581 | |
fe4e3eb8 | 582 | while (q != current_directory && !IS_DIR_SEPARATOR (q[-1])) |
d318976c FN |
583 | --q; |
584 | ||
585 | if (q == current_directory) | |
586 | /* current_directory is | |
587 | a relative pathname ("can't happen"--leave it alone). */ | |
588 | ++p; | |
589 | else | |
590 | { | |
b2a3b509 | 591 | memmove (q - 1, p + 3, strlen (p + 3) + 1); |
d318976c FN |
592 | p = q - 1; |
593 | } | |
594 | } | |
595 | else | |
ebcd3b23 MS |
596 | /* We are dealing with leading repetitions of "/..", for |
597 | example "/../..", which is the Mach super-root. */ | |
d318976c FN |
598 | p += 3; |
599 | } | |
600 | else | |
601 | { | |
602 | found_real_path = 1; | |
603 | ++p; | |
604 | } | |
605 | } | |
606 | ||
607 | forget_cached_source_info (); | |
608 | ||
609 | if (from_tty) | |
610 | pwd_command ((char *) 0, 1); | |
611 | } | |
612 | \f | |
973817a3 JB |
613 | /* Show the current value of the 'script-extension' option. */ |
614 | ||
615 | static void | |
616 | show_script_ext_mode (struct ui_file *file, int from_tty, | |
617 | struct cmd_list_element *c, const char *value) | |
d318976c | 618 | { |
6cb06a8c TT |
619 | gdb_printf (file, |
620 | _("Script filename extension recognition is \"%s\".\n"), | |
621 | value); | |
973817a3 JB |
622 | } |
623 | ||
3f7b2faa DE |
624 | /* Try to open SCRIPT_FILE. |
625 | If successful, the full path name is stored in *FULL_PATHP, | |
ed166945 TT |
626 | and the stream is returned. |
627 | If not successful, return NULL; errno is set for the last file | |
3f7b2faa DE |
628 | we tried to open. |
629 | ||
630 | If SEARCH_PATH is non-zero, and the file isn't found in cwd, | |
f5b95b50 | 631 | search for it in the source search path. */ |
3f7b2faa | 632 | |
6b09f134 | 633 | std::optional<open_script> |
ed166945 | 634 | find_and_open_script (const char *script_file, int search_path) |
973817a3 | 635 | { |
4b505b12 | 636 | int fd; |
24b9144d | 637 | openp_flags search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH; |
6b09f134 | 638 | std::optional<open_script> opened; |
d318976c | 639 | |
ee0c3293 | 640 | gdb::unique_xmalloc_ptr<char> file (tilde_expand (script_file)); |
d318976c | 641 | |
3f7b2faa DE |
642 | if (search_path) |
643 | search_flags |= OPF_SEARCH_IN_PATH; | |
4b505b12 | 644 | |
3f7b2faa DE |
645 | /* Search for and open 'file' on the search path used for source |
646 | files. Put the full location in *FULL_PATHP. */ | |
e0cc99a6 | 647 | gdb::unique_xmalloc_ptr<char> full_path; |
e0700ba4 | 648 | fd = openp (source_path.c_str (), search_flags, |
e0cc99a6 | 649 | file.get (), O_RDONLY, &full_path); |
4b505b12 AS |
650 | |
651 | if (fd == -1) | |
ee0c3293 | 652 | return opened; |
973817a3 | 653 | |
ed166945 TT |
654 | FILE *result = fdopen (fd, FOPEN_RT); |
655 | if (result == NULL) | |
77a35dd8 JK |
656 | { |
657 | int save_errno = errno; | |
658 | ||
659 | close (fd); | |
77a35dd8 | 660 | errno = save_errno; |
77a35dd8 | 661 | } |
ed166945 TT |
662 | else |
663 | opened.emplace (gdb_file_up (result), std::move (full_path)); | |
77a35dd8 | 664 | |
ed166945 | 665 | return opened; |
973817a3 JB |
666 | } |
667 | ||
1a70ae97 DE |
668 | /* Load script FILE, which has already been opened as STREAM. |
669 | FILE_TO_OPEN is the form of FILE to use if one needs to open the file. | |
670 | This is provided as FILE may have been found via the source search path. | |
671 | An important thing to note here is that FILE may be a symlink to a file | |
672 | with a different or non-existing suffix, and thus one cannot infer the | |
673 | extension language from FILE_TO_OPEN. */ | |
973817a3 | 674 | |
3f7b2faa | 675 | static void |
1a70ae97 DE |
676 | source_script_from_stream (FILE *stream, const char *file, |
677 | const char *file_to_open) | |
3f7b2faa | 678 | { |
6dddc817 | 679 | if (script_ext_mode != script_ext_off) |
973817a3 | 680 | { |
6dddc817 DE |
681 | const struct extension_language_defn *extlang |
682 | = get_ext_lang_of_file (file); | |
683 | ||
684 | if (extlang != NULL) | |
973817a3 | 685 | { |
6dddc817 DE |
686 | if (ext_lang_present_p (extlang)) |
687 | { | |
688 | script_sourcer_func *sourcer | |
689 | = ext_lang_script_sourcer (extlang); | |
690 | ||
691 | gdb_assert (sourcer != NULL); | |
1a70ae97 | 692 | sourcer (extlang, stream, file_to_open); |
6dddc817 DE |
693 | return; |
694 | } | |
695 | else if (script_ext_mode == script_ext_soft) | |
696 | { | |
697 | /* Assume the file is a gdb script. | |
698 | This is handled below. */ | |
699 | } | |
700 | else | |
701 | throw_ext_lang_unsupported (extlang); | |
973817a3 JB |
702 | } |
703 | } | |
6dddc817 DE |
704 | |
705 | script_from_file (stream, file); | |
3f7b2faa | 706 | } |
d318976c | 707 | |
3f7b2faa DE |
708 | /* Worker to perform the "source" command. |
709 | Load script FILE. | |
710 | If SEARCH_PATH is non-zero, and the file isn't found in cwd, | |
711 | search for it in the source search path. */ | |
712 | ||
713 | static void | |
714 | source_script_with_search (const char *file, int from_tty, int search_path) | |
715 | { | |
3f7b2faa DE |
716 | |
717 | if (file == NULL || *file == 0) | |
718 | error (_("source command requires file name of file to source.")); | |
719 | ||
6b09f134 | 720 | std::optional<open_script> opened = find_and_open_script (file, search_path); |
ed166945 | 721 | if (!opened) |
3f7b2faa | 722 | { |
d234ef5c | 723 | /* The script wasn't found, or was otherwise inaccessible. |
dda83cd7 | 724 | If the source command was invoked interactively, throw an |
ebcd3b23 | 725 | error. Otherwise (e.g. if it was invoked by a script), |
7c647d61 | 726 | just emit a warning, rather than cause an error. */ |
3f7b2faa DE |
727 | if (from_tty) |
728 | perror_with_name (file); | |
729 | else | |
7c647d61 JB |
730 | { |
731 | perror_warning_with_name (file); | |
732 | return; | |
733 | } | |
3f7b2faa DE |
734 | } |
735 | ||
d234ef5c DE |
736 | /* The python support reopens the file, so we need to pass full_path here |
737 | in case the file was found on the search path. It's useful to do this | |
738 | anyway so that error messages show the actual file used. But only do | |
739 | this if we (may have) used search_path, as printing the full path in | |
740 | errors for the non-search case can be more noise than signal. */ | |
1845e254 | 741 | const char *file_to_open; |
e0c34637 | 742 | std::string tilde_expanded_file; |
1845e254 AB |
743 | if (search_path) |
744 | file_to_open = opened->full_path.get (); | |
745 | else | |
746 | { | |
e0c34637 SM |
747 | tilde_expanded_file = gdb_tilde_expand (file); |
748 | file_to_open = tilde_expanded_file.c_str (); | |
1845e254 AB |
749 | } |
750 | source_script_from_stream (opened->stream.get (), file, file_to_open); | |
d318976c FN |
751 | } |
752 | ||
3f7b2faa DE |
753 | /* Wrapper around source_script_with_search to export it to main.c |
754 | for use in loading .gdbinit scripts. */ | |
755 | ||
756 | void | |
50dd9793 | 757 | source_script (const char *file, int from_tty) |
3f7b2faa DE |
758 | { |
759 | source_script_with_search (file, from_tty, 0); | |
760 | } | |
761 | ||
16026cd7 | 762 | static void |
dede02ce | 763 | source_command (const char *args, int from_tty) |
16026cd7 | 764 | { |
dede02ce | 765 | const char *file = args; |
3f7b2faa | 766 | int search_path = 0; |
16026cd7 | 767 | |
2ec845e7 | 768 | scoped_restore save_source_verbose = make_scoped_restore (&source_verbose); |
16026cd7 AS |
769 | |
770 | /* -v causes the source command to run in verbose mode. | |
3f7b2faa DE |
771 | -s causes the file to be searched in the source search path, |
772 | even if the file name contains a '/'. | |
16026cd7 AS |
773 | We still have to be able to handle filenames with spaces in a |
774 | backward compatible way, so buildargv is not appropriate. */ | |
775 | ||
776 | if (args) | |
777 | { | |
3f7b2faa | 778 | while (args[0] != '\0') |
16026cd7 | 779 | { |
ebcd3b23 MS |
780 | /* Make sure leading white space does not break the |
781 | comparisons. */ | |
529480d0 | 782 | args = skip_spaces (args); |
3f7b2faa DE |
783 | |
784 | if (args[0] != '-') | |
785 | break; | |
786 | ||
787 | if (args[1] == 'v' && isspace (args[2])) | |
788 | { | |
789 | source_verbose = 1; | |
790 | ||
791 | /* Skip passed -v. */ | |
792 | args = &args[3]; | |
793 | } | |
794 | else if (args[1] == 's' && isspace (args[2])) | |
795 | { | |
796 | search_path = 1; | |
16026cd7 | 797 | |
3f7b2faa DE |
798 | /* Skip passed -s. */ |
799 | args = &args[3]; | |
800 | } | |
801 | else | |
802 | break; | |
16026cd7 | 803 | } |
3f7b2faa | 804 | |
529480d0 | 805 | file = skip_spaces (args); |
16026cd7 AS |
806 | } |
807 | ||
3f7b2faa | 808 | source_script_with_search (file, from_tty, search_path); |
16026cd7 AS |
809 | } |
810 | ||
811 | ||
d318976c | 812 | static void |
0b39b52e | 813 | echo_command (const char *text, int from_tty) |
d318976c | 814 | { |
d7561cbb | 815 | const char *p = text; |
d5b5ac79 | 816 | int c; |
d318976c FN |
817 | |
818 | if (text) | |
819 | while ((c = *p++) != '\0') | |
820 | { | |
821 | if (c == '\\') | |
822 | { | |
823 | /* \ at end of argument is used after spaces | |
824 | so they won't be lost. */ | |
825 | if (*p == 0) | |
826 | return; | |
827 | ||
f870a310 | 828 | c = parse_escape (get_current_arch (), &p); |
d318976c | 829 | if (c >= 0) |
6cb06a8c | 830 | gdb_printf ("%c", c); |
d318976c FN |
831 | } |
832 | else | |
6cb06a8c | 833 | gdb_printf ("%c", c); |
d318976c FN |
834 | } |
835 | ||
067bb424 | 836 | gdb_stdout->emit_style_escape (ui_file_style ()); |
ef1dfa36 | 837 | |
d318976c | 838 | /* Force this output to appear now. */ |
d318976c FN |
839 | gdb_flush (gdb_stdout); |
840 | } | |
841 | ||
947d3946 PW |
842 | /* Sets the last launched shell command convenience variables based on |
843 | EXIT_STATUS. */ | |
844 | ||
845 | static void | |
846 | exit_status_set_internal_vars (int exit_status) | |
847 | { | |
848 | struct internalvar *var_code = lookup_internalvar ("_shell_exitcode"); | |
849 | struct internalvar *var_signal = lookup_internalvar ("_shell_exitsignal"); | |
850 | ||
851 | clear_internalvar (var_code); | |
852 | clear_internalvar (var_signal); | |
91265a7d PA |
853 | |
854 | /* Keep the logic here in sync with shell_internal_fn. */ | |
855 | ||
947d3946 PW |
856 | if (WIFEXITED (exit_status)) |
857 | set_internalvar_integer (var_code, WEXITSTATUS (exit_status)); | |
559e7e50 EZ |
858 | #ifdef __MINGW32__ |
859 | else if (WIFSIGNALED (exit_status) && WTERMSIG (exit_status) == -1) | |
860 | { | |
861 | /* The -1 condition can happen on MinGW, if we don't recognize | |
862 | the fatal exception code encoded in the exit status; see | |
863 | gdbsupport/gdb_wait.c. We don't want to lose information in | |
864 | the exit status in that case. Record it as a normal exit | |
865 | with the full exit status, including the higher 0xC0000000 | |
866 | bits. */ | |
867 | set_internalvar_integer (var_code, exit_status); | |
868 | } | |
869 | #endif | |
947d3946 PW |
870 | else if (WIFSIGNALED (exit_status)) |
871 | set_internalvar_integer (var_signal, WTERMSIG (exit_status)); | |
872 | else | |
422186a9 | 873 | warning (_("unexpected shell command exit status %d"), exit_status); |
947d3946 PW |
874 | } |
875 | ||
91265a7d PA |
876 | /* Run ARG under the shell, and return the exit status. If ARG is |
877 | NULL, run an interactive shell. */ | |
878 | ||
879 | static int | |
880 | run_under_shell (const char *arg, int from_tty) | |
d318976c | 881 | { |
9b265ec2 MM |
882 | #if defined(CANT_FORK) || \ |
883 | (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK)) | |
d318976c FN |
884 | /* If ARG is NULL, they want an inferior shell, but `system' just |
885 | reports if the shell is available when passed a NULL arg. */ | |
886 | int rc = system (arg ? arg : ""); | |
887 | ||
888 | if (!arg) | |
889 | arg = "inferior shell"; | |
890 | ||
891 | if (rc == -1) | |
6cb06a8c TT |
892 | gdb_printf (gdb_stderr, "Cannot execute %s: %s\n", arg, |
893 | safe_strerror (errno)); | |
d318976c | 894 | else if (rc) |
6cb06a8c | 895 | gdb_printf (gdb_stderr, "%s exited with status %d\n", arg, rc); |
2584159e | 896 | #ifdef GLOBAL_CURDIR |
ebcd3b23 MS |
897 | /* Make sure to return to the directory GDB thinks it is, in case |
898 | the shell command we just ran changed it. */ | |
d318976c FN |
899 | chdir (current_directory); |
900 | #endif | |
91265a7d | 901 | return rc; |
d318976c | 902 | #else /* Can fork. */ |
5be4dfca | 903 | int status, pid; |
d318976c | 904 | |
325ed089 | 905 | if ((pid = vfork ()) == 0) |
d318976c | 906 | { |
974e6844 | 907 | const char *p, *user_shell = get_shell (); |
30e94205 | 908 | |
614c279d TT |
909 | close_most_fds (); |
910 | ||
ebcd3b23 | 911 | /* Get the name of the shell for arg0. */ |
9f37bbcc | 912 | p = lbasename (user_shell); |
30e94205 | 913 | |
d318976c | 914 | if (!arg) |
36662fde | 915 | execl (user_shell, p, (char *) 0); |
d318976c | 916 | else |
36662fde | 917 | execl (user_shell, p, "-c", arg, (char *) 0); |
d318976c | 918 | |
6cb06a8c TT |
919 | gdb_printf (gdb_stderr, "Cannot execute %s: %s\n", user_shell, |
920 | safe_strerror (errno)); | |
d318976c FN |
921 | _exit (0177); |
922 | } | |
923 | ||
924 | if (pid != -1) | |
9858f29e | 925 | { |
658a03e9 | 926 | int ret = gdb::waitpid (pid, &status, 0); |
9858f29e TV |
927 | if (ret == -1) |
928 | perror_with_name ("Cannot get status of shell command"); | |
929 | } | |
d318976c | 930 | else |
8a3fe4f8 | 931 | error (_("Fork failed")); |
91265a7d | 932 | return status; |
d318976c FN |
933 | #endif /* Can fork. */ |
934 | } | |
935 | ||
91265a7d PA |
936 | /* Escape out to the shell to run ARG. If ARG is NULL, launch and |
937 | interactive shell. Sets $_shell_exitcode and $_shell_exitsignal | |
938 | convenience variables based on the exits status. */ | |
939 | ||
940 | static void | |
941 | shell_escape (const char *arg, int from_tty) | |
942 | { | |
943 | int status = run_under_shell (arg, from_tty); | |
944 | exit_status_set_internal_vars (status); | |
945 | } | |
946 | ||
be47f9e8 PA |
947 | /* Implementation of the "shell" command. */ |
948 | ||
949 | static void | |
0b39b52e | 950 | shell_command (const char *arg, int from_tty) |
be47f9e8 PA |
951 | { |
952 | shell_escape (arg, from_tty); | |
953 | } | |
954 | ||
036e5c0c AB |
955 | /* Completion for the shell command. Currently, this just uses filename |
956 | completion, but we could, potentially, complete command names from $PATH | |
957 | for the first word, which would make this even more shell like. */ | |
958 | ||
959 | static void | |
960 | shell_command_completer (struct cmd_list_element *ignore, | |
961 | completion_tracker &tracker, | |
962 | const char *text, const char * /* word */) | |
963 | { | |
964 | tracker.set_use_custom_word_point (true); | |
965 | const char *word | |
966 | = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); | |
967 | filename_maybe_quoted_completer (ignore, tracker, text, word); | |
968 | } | |
969 | ||
0378c332 | 970 | static void |
0b39b52e | 971 | edit_command (const char *arg, int from_tty) |
0378c332 | 972 | { |
0378c332 FN |
973 | struct symtab_and_line sal; |
974 | struct symbol *sym; | |
a121b7c1 | 975 | const char *editor; |
0b0865da | 976 | const char *fn; |
0378c332 | 977 | |
d5529a84 | 978 | /* Pull in the current default source line if necessary. */ |
0378c332 | 979 | if (arg == 0) |
53cb0458 FN |
980 | { |
981 | set_default_source_symtab_and_line (); | |
3bae94c0 | 982 | sal = get_current_source_symtab_and_line (current_program_space); |
53cb0458 | 983 | } |
0378c332 | 984 | |
ebcd3b23 | 985 | /* Bare "edit" edits file with present line. */ |
0378c332 FN |
986 | |
987 | if (arg == 0) | |
988 | { | |
989 | if (sal.symtab == 0) | |
8a3fe4f8 | 990 | error (_("No default source file yet.")); |
31ada87f AB |
991 | if (get_first_line_listed () != 0) |
992 | sal.line = get_first_line_listed () + get_lines_to_list () / 2; | |
0378c332 FN |
993 | } |
994 | else | |
995 | { | |
f2fc3015 | 996 | const char *arg1; |
0378c332 | 997 | |
f00aae0f | 998 | /* Now should only be one argument -- decode it in SAL. */ |
0378c332 | 999 | arg1 = arg; |
264f9890 PA |
1000 | location_spec_up locspec = string_to_location_spec (&arg1, |
1001 | current_language); | |
82d0a72c AB |
1002 | |
1003 | if (*arg1) | |
1004 | error (_("Junk at end of line specification.")); | |
1005 | ||
264f9890 | 1006 | std::vector<symtab_and_line> sals = decode_line_1 (locspec.get (), |
6c5b2ebe PA |
1007 | DECODE_LINE_LIST_MODE, |
1008 | NULL, NULL, 0); | |
0378c332 | 1009 | |
6c5b2ebe PA |
1010 | filter_sals (sals); |
1011 | if (sals.empty ()) | |
d5529a84 TT |
1012 | { |
1013 | /* C++ */ | |
1014 | return; | |
1015 | } | |
6c5b2ebe | 1016 | if (sals.size () > 1) |
d5529a84 | 1017 | { |
6c5b2ebe | 1018 | ambiguous_line_spec (sals, |
e439fa14 | 1019 | _("Specified line is ambiguous:\n")); |
d5529a84 TT |
1020 | return; |
1021 | } | |
0378c332 | 1022 | |
6c5b2ebe | 1023 | sal = sals[0]; |
0378c332 | 1024 | |
ebcd3b23 | 1025 | /* If line was specified by address, first print exactly which |
dda83cd7 SM |
1026 | line, and which file. In this case, sal.symtab == 0 means |
1027 | address is outside of all known source files, not that user | |
1028 | failed to give a filename. */ | |
0378c332 | 1029 | if (*arg == '*') |
dda83cd7 | 1030 | { |
5af949e3 | 1031 | struct gdbarch *gdbarch; |
cdb27c12 | 1032 | |
dda83cd7 | 1033 | if (sal.symtab == 0) |
8a3fe4f8 | 1034 | error (_("No source file for address %s."), |
2b69941d | 1035 | paddress (get_current_arch (), sal.pc)); |
5af949e3 | 1036 | |
3c86fae3 | 1037 | gdbarch = sal.symtab->compunit ()->objfile ()->arch (); |
dda83cd7 SM |
1038 | sym = find_pc_function (sal.pc); |
1039 | if (sym) | |
bcb92f7b AB |
1040 | gdb_printf ("%ps is in %ps (%ps:%ps).\n", |
1041 | styled_string (address_style.style (), | |
1042 | paddress (gdbarch, sal.pc)), | |
1043 | styled_string (function_name_style.style (), | |
1044 | sym->print_name ()), | |
1045 | styled_string (file_name_style.style (), | |
1046 | symtab_to_filename_for_display (sal.symtab)), | |
1047 | styled_string (line_number_style.style (), | |
1048 | pulongest (sal.line))); | |
dda83cd7 | 1049 | else |
bcb92f7b AB |
1050 | gdb_printf ("%ps is at %ps:%ps.\n", |
1051 | styled_string (address_style.style (), | |
1052 | paddress (gdbarch, sal.pc)), | |
1053 | styled_string (file_name_style.style (), | |
1054 | symtab_to_filename_for_display (sal.symtab)), | |
1055 | styled_string (line_number_style.style (), | |
1056 | pulongest (sal.line))); | |
dda83cd7 | 1057 | } |
0378c332 | 1058 | |
ebcd3b23 | 1059 | /* If what was given does not imply a symtab, it must be an |
dda83cd7 | 1060 | undebuggable symbol which means no source code. */ |
0378c332 FN |
1061 | |
1062 | if (sal.symtab == 0) | |
dda83cd7 | 1063 | error (_("No line number known for %s."), arg); |
0378c332 FN |
1064 | } |
1065 | ||
081bca4d TT |
1066 | if ((editor = getenv ("EDITOR")) == NULL) |
1067 | editor = "/bin/ex"; | |
a955ca71 | 1068 | |
f35a17b5 | 1069 | fn = symtab_to_fullname (sal.symtab); |
0378c332 | 1070 | |
a955ca71 EZ |
1071 | /* Quote the file name, in case it has whitespace or other special |
1072 | characters. */ | |
8579fd13 AB |
1073 | gdb::unique_xmalloc_ptr<char> p |
1074 | = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn); | |
1075 | shell_escape (p.get (), from_tty); | |
0378c332 FN |
1076 | } |
1077 | ||
5f4ba3e7 PA |
1078 | /* The options for the "pipe" command. */ |
1079 | ||
1080 | struct pipe_cmd_opts | |
1081 | { | |
1082 | /* For "-d". */ | |
e0700ba4 | 1083 | std::string delimiter; |
5f4ba3e7 PA |
1084 | }; |
1085 | ||
1086 | static const gdb::option::option_def pipe_cmd_option_defs[] = { | |
1087 | ||
1088 | gdb::option::string_option_def<pipe_cmd_opts> { | |
1089 | "d", | |
1090 | [] (pipe_cmd_opts *opts) { return &opts->delimiter; }, | |
1091 | nullptr, | |
1092 | N_("Indicates to use the specified delimiter string to separate\n\ | |
1093 | COMMAND from SHELL_COMMAND, in alternative to |. This is useful in\n\ | |
1094 | case COMMAND contains a | character."), | |
1095 | }, | |
1096 | ||
1097 | }; | |
1098 | ||
1099 | /* Create an option_def_group for the "pipe" command's options, with | |
1100 | OPTS as context. */ | |
1101 | ||
1102 | static inline gdb::option::option_def_group | |
1103 | make_pipe_cmd_options_def_group (pipe_cmd_opts *opts) | |
1104 | { | |
1105 | return {{pipe_cmd_option_defs}, opts}; | |
1106 | } | |
1107 | ||
947d3946 PW |
1108 | /* Implementation of the "pipe" command. */ |
1109 | ||
1110 | static void | |
1111 | pipe_command (const char *arg, int from_tty) | |
1112 | { | |
5f4ba3e7 | 1113 | pipe_cmd_opts opts; |
947d3946 | 1114 | |
5f4ba3e7 PA |
1115 | auto grp = make_pipe_cmd_options_def_group (&opts); |
1116 | gdb::option::process_options | |
1117 | (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); | |
1118 | ||
1119 | const char *delim = "|"; | |
e0700ba4 SM |
1120 | if (!opts.delimiter.empty ()) |
1121 | delim = opts.delimiter.c_str (); | |
947d3946 PW |
1122 | |
1123 | const char *command = arg; | |
1124 | if (command == nullptr) | |
1125 | error (_("Missing COMMAND")); | |
1126 | ||
5f4ba3e7 | 1127 | arg = strstr (arg, delim); |
947d3946 PW |
1128 | |
1129 | if (arg == nullptr) | |
1130 | error (_("Missing delimiter before SHELL_COMMAND")); | |
1131 | ||
1132 | std::string gdb_cmd (command, arg - command); | |
1133 | ||
5f4ba3e7 | 1134 | arg += strlen (delim); /* Skip the delimiter. */ |
947d3946 PW |
1135 | |
1136 | if (gdb_cmd.empty ()) | |
fdbc9870 | 1137 | gdb_cmd = repeat_previous (); |
947d3946 PW |
1138 | |
1139 | const char *shell_command = skip_spaces (arg); | |
1140 | if (*shell_command == '\0') | |
1141 | error (_("Missing SHELL_COMMAND")); | |
1142 | ||
1143 | FILE *to_shell_command = popen (shell_command, "w"); | |
1144 | ||
1145 | if (to_shell_command == nullptr) | |
1146 | error (_("Error launching \"%s\""), shell_command); | |
1147 | ||
58706ec7 TV |
1148 | int exit_status; |
1149 | { | |
1150 | SCOPE_EXIT { exit_status = pclose (to_shell_command); }; | |
947d3946 | 1151 | |
58706ec7 | 1152 | stdio_file pipe_file (to_shell_command); |
947d3946 | 1153 | |
58706ec7 TV |
1154 | execute_command_to_ui_file (&pipe_file, gdb_cmd.c_str (), from_tty); |
1155 | } | |
947d3946 PW |
1156 | |
1157 | if (exit_status < 0) | |
1158 | error (_("shell command \"%s\" failed: %s"), shell_command, | |
dda83cd7 | 1159 | safe_strerror (errno)); |
947d3946 PW |
1160 | exit_status_set_internal_vars (exit_status); |
1161 | } | |
1162 | ||
5f4ba3e7 PA |
1163 | /* Completer for the pipe command. */ |
1164 | ||
1165 | static void | |
1166 | pipe_command_completer (struct cmd_list_element *ignore, | |
1167 | completion_tracker &tracker, | |
1168 | const char *text, const char *word_ignored) | |
1169 | { | |
1170 | pipe_cmd_opts opts; | |
1171 | ||
1172 | const char *org_text = text; | |
1173 | auto grp = make_pipe_cmd_options_def_group (&opts); | |
1174 | if (gdb::option::complete_options | |
1175 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp)) | |
1176 | return; | |
1177 | ||
1178 | const char *delimiter = "|"; | |
e0700ba4 SM |
1179 | if (!opts.delimiter.empty ()) |
1180 | delimiter = opts.delimiter.c_str (); | |
5f4ba3e7 PA |
1181 | |
1182 | /* Check if we're past option values already. */ | |
1183 | if (text > org_text && !isspace (text[-1])) | |
1184 | return; | |
1185 | ||
1186 | const char *delim = strstr (text, delimiter); | |
1187 | ||
1188 | /* If we're still not past the delimiter, complete the gdb | |
1189 | command. */ | |
1190 | if (delim == nullptr || delim == text) | |
1191 | { | |
1192 | complete_nested_command_line (tracker, text); | |
1193 | return; | |
1194 | } | |
1195 | ||
a66ed82c AB |
1196 | /* We're past the delimiter now, or at least, DELIM points to the |
1197 | delimiter string. Update TEXT to point to the start of whatever | |
1198 | appears after the delimiter. */ | |
1199 | text = skip_spaces (delim + strlen (delimiter)); | |
1200 | ||
1201 | /* We really are past the delimiter now, so offer completions. This is | |
1202 | like GDB's "shell" command, currently we only offer filename | |
1203 | completion, but in the future this could be improved by offering | |
1204 | completion of command names from $PATH. | |
1205 | ||
1206 | What we don't do here is offer completions for the empty string. It | |
1207 | is assumed that the first word after the delimiter is going to be a | |
1208 | command name from $PATH, not a filename, so if the user has typed | |
1209 | nothing (yet) and tries to complete, there's no point offering a list | |
1210 | of files from the current directory. | |
1211 | ||
1212 | Once the user has started to type something though, then we do start | |
1213 | offering filename completions. */ | |
1214 | if (*text == '\0') | |
1215 | return; | |
1216 | ||
1217 | tracker.set_use_custom_word_point (true); | |
1218 | tracker.advance_custom_word_point_by (text - org_text); | |
1219 | const char *word | |
1220 | = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); | |
1221 | filename_maybe_quoted_completer (ignore, tracker, text, word); | |
5f4ba3e7 PA |
1222 | } |
1223 | ||
0f819434 BL |
1224 | /* Helper for the list_command function. Prints the lines around (and |
1225 | including) line stored in CURSAL. ARG contains the arguments used in | |
1226 | the command invocation, and is used to determine a special case when | |
1227 | printing backwards. */ | |
1228 | static void | |
1229 | list_around_line (const char *arg, symtab_and_line cursal) | |
1230 | { | |
1231 | int first; | |
1232 | ||
1233 | first = std::max (cursal.line - get_lines_to_list () / 2, 1); | |
1234 | ||
1235 | /* A small special case --- if listing backwards, and we | |
1236 | should list only one line, list the preceding line, | |
1237 | instead of the exact line we've just shown after e.g., | |
1238 | stopping for a breakpoint. */ | |
1239 | if (arg != NULL && arg[0] == '-' | |
1240 | && get_lines_to_list () == 1 && first > 1) | |
1241 | first -= 1; | |
1242 | ||
1243 | print_source_lines (cursal.symtab, source_lines_range (first), 0); | |
1244 | } | |
1245 | ||
0378c332 | 1246 | static void |
0b39b52e | 1247 | list_command (const char *arg, int from_tty) |
0378c332 | 1248 | { |
0378c332 | 1249 | struct symbol *sym; |
f2fc3015 | 1250 | const char *arg1; |
0378c332 FN |
1251 | int no_end = 1; |
1252 | int dummy_end = 0; | |
1253 | int dummy_beg = 0; | |
1254 | int linenum_beg = 0; | |
0b39b52e | 1255 | const char *p; |
0378c332 | 1256 | |
ebcd3b23 | 1257 | /* Pull in the current default source line if necessary. */ |
3e3a1874 | 1258 | if (arg == NULL || ((arg[0] == '+' || arg[0] == '-' || arg[0] == '.') && arg[1] == '\0')) |
53cb0458 | 1259 | { |
5166082f PA |
1260 | /* If this is the first "list" since we've set the current |
1261 | source line, center the listing around that line. */ | |
3e3a1874 | 1262 | if (get_first_line_listed () == 0 && (arg == nullptr || arg[0] != '.')) |
5166082f | 1263 | { |
e61c7092 | 1264 | set_default_source_symtab_and_line (); |
3bae94c0 SM |
1265 | list_around_line |
1266 | (arg, get_current_source_symtab_and_line (current_program_space)); | |
5166082f | 1267 | } |
0378c332 | 1268 | |
f52625f1 BL |
1269 | /* "l" and "l +" lists the next few lines, unless we're listing past |
1270 | the end of the file. */ | |
1271 | else if (arg == nullptr || arg[0] == '+') | |
1272 | { | |
e61c7092 | 1273 | set_default_source_symtab_and_line (); |
3bae94c0 SM |
1274 | const symtab_and_line cursal |
1275 | = get_current_source_symtab_and_line (current_program_space); | |
f52625f1 BL |
1276 | if (last_symtab_line (cursal.symtab) >= cursal.line) |
1277 | print_source_lines (cursal.symtab, | |
1278 | source_lines_range (cursal.line), 0); | |
1279 | else | |
e61c7092 GL |
1280 | error (_("End of the file was already reached, use \"list .\" to" |
1281 | " list the current location again")); | |
f52625f1 | 1282 | } |
0378c332 | 1283 | |
1a48ce76 AB |
1284 | /* "l -" lists previous ten lines, the ones before the ten just |
1285 | listed. */ | |
a0def019 | 1286 | else if (arg[0] == '-') |
3b2464a8 | 1287 | { |
e61c7092 | 1288 | set_default_source_symtab_and_line (); |
3bae94c0 SM |
1289 | const symtab_and_line cursal |
1290 | = get_current_source_symtab_and_line (current_program_space); | |
e61c7092 | 1291 | |
3b2464a8 AB |
1292 | if (get_first_line_listed () == 1) |
1293 | error (_("Already at the start of %s."), | |
1294 | symtab_to_filename_for_display (cursal.symtab)); | |
e61c7092 | 1295 | |
0e2a2133 AB |
1296 | source_lines_range range (get_first_line_listed (), |
1297 | source_lines_range::BACKWARD); | |
1298 | print_source_lines (cursal.symtab, range, 0); | |
3b2464a8 | 1299 | } |
0378c332 | 1300 | |
12f567bc | 1301 | /* "list ." lists the default location again. */ |
3e3a1874 BL |
1302 | else if (arg[0] == '.') |
1303 | { | |
e61c7092 | 1304 | symtab_and_line cursal; |
12f567bc | 1305 | if (target_has_stack ()) |
3e3a1874 BL |
1306 | { |
1307 | /* Find the current line by getting the PC of the currently | |
1308 | selected frame, and finding the line associated to it. */ | |
1309 | frame_info_ptr frame = get_selected_frame (nullptr); | |
1310 | CORE_ADDR curr_pc = get_frame_pc (frame); | |
1311 | cursal = find_pc_line (curr_pc, 0); | |
e61c7092 GL |
1312 | |
1313 | if (cursal.symtab == nullptr) | |
1314 | error | |
1315 | (_("Insufficient debug info for showing source lines at " | |
1316 | "current PC (%s)."), paddress (get_frame_arch (frame), | |
1317 | curr_pc)); | |
3e3a1874 | 1318 | } |
12f567bc | 1319 | else |
3e3a1874 | 1320 | { |
12f567bc GL |
1321 | /* The inferior is not running, so reset the current source |
1322 | location to the default (usually the main function). */ | |
fbee6a57 | 1323 | clear_current_source_symtab_and_line (current_program_space); |
e61c7092 GL |
1324 | try |
1325 | { | |
1326 | set_default_source_symtab_and_line (); | |
1327 | } | |
1328 | catch (const gdb_exception &e) | |
1329 | { | |
1330 | error (_("Insufficient debug info for showing source " | |
1331 | "lines at default location")); | |
1332 | } | |
3bae94c0 SM |
1333 | cursal |
1334 | = get_current_source_symtab_and_line (current_program_space); | |
e61c7092 GL |
1335 | |
1336 | gdb_assert (cursal.symtab != nullptr); | |
3e3a1874 | 1337 | } |
e61c7092 | 1338 | |
3e3a1874 | 1339 | list_around_line (arg, cursal); |
e61c7092 | 1340 | |
12f567bc | 1341 | /* Set the repeat args so just pressing "enter" after using "list ." |
3e3a1874 | 1342 | will print the following lines instead of the same lines again. */ |
12f567bc GL |
1343 | if (from_tty) |
1344 | set_repeat_arguments (""); | |
3e3a1874 BL |
1345 | } |
1346 | ||
0378c332 FN |
1347 | return; |
1348 | } | |
1349 | ||
1350 | /* Now if there is only one argument, decode it in SAL | |
1351 | and set NO_END. | |
1352 | If there are two arguments, decode them in SAL and SAL_END | |
1353 | and clear NO_END; however, if one of the arguments is blank, | |
1354 | set DUMMY_BEG or DUMMY_END to record that fact. */ | |
1355 | ||
9c067e28 SM |
1356 | if (!have_full_symbols (current_program_space) |
1357 | && !have_partial_symbols (current_program_space)) | |
8a3fe4f8 | 1358 | error (_("No symbol table is loaded. Use the \"file\" command.")); |
0378c332 | 1359 | |
6c5b2ebe | 1360 | std::vector<symtab_and_line> sals; |
51abb421 | 1361 | symtab_and_line sal, sal_end; |
6c5b2ebe | 1362 | |
0378c332 FN |
1363 | arg1 = arg; |
1364 | if (*arg1 == ',') | |
1365 | dummy_beg = 1; | |
1366 | else | |
1367 | { | |
264f9890 PA |
1368 | location_spec_up locspec |
1369 | = string_to_location_spec (&arg1, current_language); | |
1370 | ||
1371 | /* We know that the ARG string is not empty, yet the attempt to | |
1372 | parse a location spec from the string consumed no characters. | |
1373 | This most likely means that the first thing in ARG looks like | |
1374 | a location spec condition, and so the string_to_location_spec | |
1375 | call stopped parsing. */ | |
3c5fcec6 AB |
1376 | if (arg1 == arg) |
1377 | error (_("Junk at end of line specification.")); | |
1378 | ||
264f9890 | 1379 | sals = decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE, |
ffc2605c | 1380 | NULL, NULL, 0); |
6c5b2ebe PA |
1381 | filter_sals (sals); |
1382 | if (sals.empty ()) | |
f00aae0f KS |
1383 | { |
1384 | /* C++ */ | |
f00aae0f KS |
1385 | return; |
1386 | } | |
0378c332 | 1387 | |
6c5b2ebe | 1388 | sal = sals[0]; |
0378c332 FN |
1389 | } |
1390 | ||
1391 | /* Record whether the BEG arg is all digits. */ | |
1392 | ||
1393 | for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++); | |
1394 | linenum_beg = (p == arg1); | |
1395 | ||
e439fa14 PA |
1396 | /* Save the range of the first argument, in case we need to let the |
1397 | user know it was ambiguous. */ | |
1398 | const char *beg = arg; | |
1399 | size_t beg_len = arg1 - beg; | |
1400 | ||
0378c332 FN |
1401 | while (*arg1 == ' ' || *arg1 == '\t') |
1402 | arg1++; | |
1403 | if (*arg1 == ',') | |
1404 | { | |
1405 | no_end = 0; | |
6c5b2ebe | 1406 | if (sals.size () > 1) |
0d999a6e | 1407 | { |
6c5b2ebe | 1408 | ambiguous_line_spec (sals, |
e439fa14 PA |
1409 | _("Specified first line '%.*s' is ambiguous:\n"), |
1410 | (int) beg_len, beg); | |
0d999a6e ZZ |
1411 | return; |
1412 | } | |
0378c332 FN |
1413 | arg1++; |
1414 | while (*arg1 == ' ' || *arg1 == '\t') | |
1415 | arg1++; | |
1416 | if (*arg1 == 0) | |
1417 | dummy_end = 1; | |
1418 | else | |
1419 | { | |
e439fa14 PA |
1420 | /* Save the last argument, in case we need to let the user |
1421 | know it was ambiguous. */ | |
1422 | const char *end_arg = arg1; | |
1423 | ||
264f9890 PA |
1424 | location_spec_up locspec |
1425 | = string_to_location_spec (&arg1, current_language); | |
f00aae0f | 1426 | |
3c5fcec6 AB |
1427 | if (*arg1) |
1428 | error (_("Junk at end of line specification.")); | |
1429 | ||
6c5b2ebe PA |
1430 | std::vector<symtab_and_line> sals_end |
1431 | = (dummy_beg | |
264f9890 | 1432 | ? decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE, |
6c5b2ebe | 1433 | NULL, NULL, 0) |
264f9890 | 1434 | : decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE, |
6c5b2ebe PA |
1435 | NULL, sal.symtab, sal.line)); |
1436 | ||
1437 | filter_sals (sals_end); | |
1438 | if (sals_end.empty ()) | |
1439 | return; | |
1440 | if (sals_end.size () > 1) | |
0d999a6e | 1441 | { |
6c5b2ebe | 1442 | ambiguous_line_spec (sals_end, |
e439fa14 PA |
1443 | _("Specified last line '%s' is ambiguous:\n"), |
1444 | end_arg); | |
0378c332 FN |
1445 | return; |
1446 | } | |
6c5b2ebe | 1447 | sal_end = sals_end[0]; |
0378c332 FN |
1448 | } |
1449 | } | |
1450 | ||
1451 | if (*arg1) | |
8a3fe4f8 | 1452 | error (_("Junk at end of line specification.")); |
0378c332 FN |
1453 | |
1454 | if (!no_end && !dummy_beg && !dummy_end | |
1455 | && sal.symtab != sal_end.symtab) | |
e439fa14 | 1456 | error (_("Specified first and last lines are in different files.")); |
0378c332 | 1457 | if (dummy_beg && dummy_end) |
8a3fe4f8 | 1458 | error (_("Two empty args do not say what lines to list.")); |
0378c332 | 1459 | |
ebcd3b23 | 1460 | /* If line was specified by address, |
0378c332 | 1461 | first print exactly which line, and which file. |
ebcd3b23 MS |
1462 | |
1463 | In this case, sal.symtab == 0 means address is outside of all | |
1464 | known source files, not that user failed to give a filename. */ | |
0378c332 FN |
1465 | if (*arg == '*') |
1466 | { | |
5af949e3 | 1467 | struct gdbarch *gdbarch; |
cdb27c12 | 1468 | |
0378c332 | 1469 | if (sal.symtab == 0) |
8a3fe4f8 | 1470 | error (_("No source file for address %s."), |
2b69941d | 1471 | paddress (get_current_arch (), sal.pc)); |
5af949e3 | 1472 | |
3c86fae3 | 1473 | gdbarch = sal.symtab->compunit ()->objfile ()->arch (); |
0378c332 FN |
1474 | sym = find_pc_function (sal.pc); |
1475 | if (sym) | |
6cb06a8c TT |
1476 | gdb_printf ("%s is in %s (%s:%d).\n", |
1477 | paddress (gdbarch, sal.pc), | |
1478 | sym->print_name (), | |
1479 | symtab_to_filename_for_display (sal.symtab), sal.line); | |
0378c332 | 1480 | else |
6cb06a8c TT |
1481 | gdb_printf ("%s is at %s:%d.\n", |
1482 | paddress (gdbarch, sal.pc), | |
1483 | symtab_to_filename_for_display (sal.symtab), sal.line); | |
0378c332 FN |
1484 | } |
1485 | ||
ebcd3b23 MS |
1486 | /* If line was not specified by just a line number, and it does not |
1487 | imply a symtab, it must be an undebuggable symbol which means no | |
1488 | source code. */ | |
0378c332 FN |
1489 | |
1490 | if (!linenum_beg && sal.symtab == 0) | |
8a3fe4f8 | 1491 | error (_("No line number known for %s."), arg); |
0378c332 FN |
1492 | |
1493 | /* If this command is repeated with RET, | |
1494 | turn it into the no-arg variant. */ | |
1495 | ||
1496 | if (from_tty) | |
85c4be7c | 1497 | set_repeat_arguments (""); |
0378c332 FN |
1498 | |
1499 | if (dummy_beg && sal_end.symtab == 0) | |
8a3fe4f8 | 1500 | error (_("No default source file yet. Do \"help list\".")); |
0378c332 | 1501 | if (dummy_beg) |
0e2a2133 AB |
1502 | { |
1503 | source_lines_range range (sal_end.line + 1, | |
1504 | source_lines_range::BACKWARD); | |
1505 | print_source_lines (sal_end.symtab, range, 0); | |
1506 | } | |
0378c332 | 1507 | else if (sal.symtab == 0) |
8a3fe4f8 | 1508 | error (_("No default source file yet. Do \"help list\".")); |
0378c332 FN |
1509 | else if (no_end) |
1510 | { | |
6c5b2ebe | 1511 | for (int i = 0; i < sals.size (); i++) |
0d999a6e | 1512 | { |
6c5b2ebe | 1513 | sal = sals[i]; |
0d999a6e ZZ |
1514 | int first_line = sal.line - get_lines_to_list () / 2; |
1515 | if (first_line < 1) | |
1516 | first_line = 1; | |
6c5b2ebe | 1517 | if (sals.size () > 1) |
06871ae8 | 1518 | print_sal_location (sal); |
0e2a2133 | 1519 | print_source_lines (sal.symtab, source_lines_range (first_line), 0); |
0d999a6e | 1520 | } |
0378c332 | 1521 | } |
0e2a2133 AB |
1522 | else if (dummy_end) |
1523 | print_source_lines (sal.symtab, source_lines_range (sal.line), 0); | |
0378c332 | 1524 | else |
0e2a2133 AB |
1525 | print_source_lines (sal.symtab, |
1526 | source_lines_range (sal.line, (sal_end.line + 1)), | |
0378c332 FN |
1527 | 0); |
1528 | } | |
1529 | ||
d14508fe DE |
1530 | /* Subroutine of disassemble_command to simplify it. |
1531 | Perform the disassembly. | |
1532 | NAME is the name of the function if known, or NULL. | |
1533 | [LOW,HIGH) are the range of addresses to disassemble. | |
e9480230 KB |
1534 | BLOCK is the block to disassemble; it needs to be provided |
1535 | when non-contiguous blocks are disassembled; otherwise | |
1536 | it can be NULL. | |
d14508fe DE |
1537 | MIXED is non-zero to print source with the assembler. */ |
1538 | ||
1539 | static void | |
13274fc3 | 1540 | print_disassembly (struct gdbarch *gdbarch, const char *name, |
9a24775b | 1541 | CORE_ADDR low, CORE_ADDR high, |
e9480230 | 1542 | const struct block *block, |
9a24775b | 1543 | gdb_disassembly_flags flags) |
d14508fe DE |
1544 | { |
1545 | #if defined(TUI) | |
f9ba974d TT |
1546 | if (tui_is_window_visible (DISASSEM_WIN)) |
1547 | tui_show_assembly (gdbarch, low); | |
1548 | else | |
d14508fe DE |
1549 | #endif |
1550 | { | |
6cb06a8c | 1551 | gdb_printf (_("Dump of assembler code ")); |
d14508fe | 1552 | if (name != NULL) |
6cb06a8c TT |
1553 | gdb_printf (_("for function %ps:\n"), |
1554 | styled_string (function_name_style.style (), name)); | |
086d03c9 | 1555 | if (block == nullptr || block->is_contiguous ()) |
dda83cd7 | 1556 | { |
e9480230 | 1557 | if (name == NULL) |
6cb06a8c TT |
1558 | gdb_printf (_("from %ps to %ps:\n"), |
1559 | styled_string (address_style.style (), | |
1560 | paddress (gdbarch, low)), | |
1561 | styled_string (address_style.style (), | |
1562 | paddress (gdbarch, high))); | |
d14508fe | 1563 | |
e9480230 KB |
1564 | /* Dump the specified range. */ |
1565 | gdb_disassembly (gdbarch, current_uiout, flags, -1, low, high); | |
1566 | } | |
1567 | else | |
dda83cd7 | 1568 | { |
f73b4922 | 1569 | for (const blockrange &range : block->ranges ()) |
e9480230 | 1570 | { |
f73b4922 SM |
1571 | CORE_ADDR range_low = range.start (); |
1572 | CORE_ADDR range_high = range.end (); | |
1573 | ||
6cb06a8c TT |
1574 | gdb_printf (_("Address range %ps to %ps:\n"), |
1575 | styled_string (address_style.style (), | |
1576 | paddress (gdbarch, range_low)), | |
1577 | styled_string (address_style.style (), | |
1578 | paddress (gdbarch, range_high))); | |
b926417a TT |
1579 | gdb_disassembly (gdbarch, current_uiout, flags, -1, |
1580 | range_low, range_high); | |
e9480230 KB |
1581 | } |
1582 | } | |
6cb06a8c | 1583 | gdb_printf (_("End of assembler dump.\n")); |
d14508fe | 1584 | } |
d14508fe DE |
1585 | } |
1586 | ||
1587 | /* Subroutine of disassemble_command to simplify it. | |
9c419145 | 1588 | Print a disassembly of the current function according to FLAGS. */ |
d14508fe DE |
1589 | |
1590 | static void | |
9a24775b | 1591 | disassemble_current_function (gdb_disassembly_flags flags) |
d14508fe | 1592 | { |
26522e34 AB |
1593 | frame_info_ptr frame = get_selected_frame (_("No frame selected.")); |
1594 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1595 | CORE_ADDR pc = get_frame_address_in_block (frame); | |
d14508fe | 1596 | |
26522e34 AB |
1597 | const general_symbol_info *gsi; |
1598 | const struct block *block; | |
1599 | CORE_ADDR low, high; | |
1600 | if (find_pc_partial_function_sym (pc, &gsi, &low, &high, &block) == 0) | |
d14508fe | 1601 | error (_("No function contains program counter for selected frame.")); |
26522e34 AB |
1602 | |
1603 | gdb_assert (gsi != nullptr); | |
1604 | const char *name = asm_demangle ? gsi->print_name () : gsi->linkage_name (); | |
1605 | ||
d14508fe DE |
1606 | #if defined(TUI) |
1607 | /* NOTE: cagney/2003-02-13 The `tui_active' was previously | |
1608 | `tui_version'. */ | |
1609 | if (tui_active) | |
1610 | /* FIXME: cagney/2004-02-07: This should be an observer. */ | |
13274fc3 | 1611 | low = tui_get_low_disassembly_address (gdbarch, low, pc); |
d14508fe | 1612 | #endif |
13274fc3 | 1613 | low += gdbarch_deprecated_function_start_offset (gdbarch); |
d14508fe | 1614 | |
e9480230 | 1615 | print_disassembly (gdbarch, name, low, high, block, flags); |
d14508fe DE |
1616 | } |
1617 | ||
1618 | /* Dump a specified section of assembly code. | |
1619 | ||
1620 | Usage: | |
6ff0ba5f | 1621 | disassemble [/mrs] |
d14508fe | 1622 | - dump the assembly code for the function of the current pc |
6ff0ba5f | 1623 | disassemble [/mrs] addr |
d14508fe | 1624 | - dump the assembly code for the function at ADDR |
6ff0ba5f DE |
1625 | disassemble [/mrs] low,high |
1626 | disassemble [/mrs] low,+length | |
53a71c06 | 1627 | - dump the assembly code in the range [LOW,HIGH), or [LOW,LOW+length) |
d14508fe | 1628 | |
6ff0ba5f DE |
1629 | A /m modifier will include source code with the assembly in a |
1630 | "source centric" view. This view lists only the file of the first insn, | |
1631 | even if other source files are involved (e.g., inlined functions), and | |
1632 | the output is in source order, even with optimized code. This view is | |
1633 | considered deprecated as it hasn't been useful in practice. | |
1634 | ||
1635 | A /r modifier will include raw instructions in hex with the assembly. | |
1636 | ||
d4ce49b7 AB |
1637 | A /b modifier is similar to /r except the instruction bytes are printed |
1638 | as separate bytes with no grouping, or endian switching. | |
1639 | ||
6ff0ba5f DE |
1640 | A /s modifier will include source code with the assembly, like /m, with |
1641 | two important differences: | |
1642 | 1) The output is still in pc address order. | |
1643 | 2) File names and contents for all relevant source files are displayed. */ | |
83c31e7d | 1644 | |
83c31e7d | 1645 | static void |
0b39b52e | 1646 | disassemble_command (const char *arg, int from_tty) |
83c31e7d | 1647 | { |
13274fc3 | 1648 | struct gdbarch *gdbarch = get_current_arch (); |
83c31e7d | 1649 | CORE_ADDR low, high; |
f75a0693 | 1650 | const general_symbol_info *symbol = nullptr; |
2c02bd72 | 1651 | const char *name; |
d36fc00b | 1652 | CORE_ADDR pc; |
9a24775b | 1653 | gdb_disassembly_flags flags; |
bbc13ae3 | 1654 | const char *p; |
e9480230 | 1655 | const struct block *block = nullptr; |
83c31e7d | 1656 | |
bbc13ae3 | 1657 | p = arg; |
83c31e7d | 1658 | name = NULL; |
e6158f16 | 1659 | flags = 0; |
d14508fe | 1660 | |
bbc13ae3 | 1661 | if (p && *p == '/') |
83c31e7d | 1662 | { |
bbc13ae3 | 1663 | ++p; |
d14508fe | 1664 | |
bbc13ae3 | 1665 | if (*p == '\0') |
d14508fe DE |
1666 | error (_("Missing modifier.")); |
1667 | ||
bbc13ae3 | 1668 | while (*p && ! isspace (*p)) |
d14508fe | 1669 | { |
bbc13ae3 | 1670 | switch (*p++) |
d14508fe DE |
1671 | { |
1672 | case 'm': | |
6ff0ba5f | 1673 | flags |= DISASSEMBLY_SOURCE_DEPRECATED; |
e6158f16 HZ |
1674 | break; |
1675 | case 'r': | |
1676 | flags |= DISASSEMBLY_RAW_INSN; | |
d14508fe | 1677 | break; |
d4ce49b7 AB |
1678 | case 'b': |
1679 | flags |= DISASSEMBLY_RAW_BYTES; | |
1680 | break; | |
6ff0ba5f DE |
1681 | case 's': |
1682 | flags |= DISASSEMBLY_SOURCE; | |
1683 | break; | |
d14508fe DE |
1684 | default: |
1685 | error (_("Invalid disassembly modifier.")); | |
1686 | } | |
1687 | } | |
1688 | ||
f1735a53 | 1689 | p = skip_spaces (p); |
d14508fe DE |
1690 | } |
1691 | ||
6ff0ba5f DE |
1692 | if ((flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE)) |
1693 | == (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE)) | |
1694 | error (_("Cannot specify both /m and /s.")); | |
1695 | ||
f3a8a979 AB |
1696 | if ((flags & (DISASSEMBLY_RAW_INSN | DISASSEMBLY_RAW_BYTES)) |
1697 | == (DISASSEMBLY_RAW_INSN | DISASSEMBLY_RAW_BYTES)) | |
1698 | error (_("Cannot specify both /r and /b.")); | |
1699 | ||
bbc13ae3 | 1700 | if (! p || ! *p) |
d14508fe | 1701 | { |
9c419145 | 1702 | flags |= DISASSEMBLY_OMIT_FNAME; |
e6158f16 | 1703 | disassemble_current_function (flags); |
d14508fe | 1704 | return; |
83c31e7d | 1705 | } |
d14508fe | 1706 | |
bbc13ae3 KS |
1707 | pc = value_as_address (parse_to_comma_and_eval (&p)); |
1708 | if (p[0] == ',') | |
1709 | ++p; | |
1710 | if (p[0] == '\0') | |
83c31e7d FN |
1711 | { |
1712 | /* One argument. */ | |
f75a0693 | 1713 | if (!find_pc_partial_function_sym (pc, &symbol, &low, &high, &block)) |
8a3fe4f8 | 1714 | error (_("No function contains specified address.")); |
f75a0693 AB |
1715 | |
1716 | if (asm_demangle) | |
1717 | name = symbol->print_name (); | |
1718 | else | |
1719 | name = symbol->linkage_name (); | |
1720 | ||
83c31e7d | 1721 | #if defined(TUI) |
021e7609 AC |
1722 | /* NOTE: cagney/2003-02-13 The `tui_active' was previously |
1723 | `tui_version'. */ | |
22940a24 AC |
1724 | if (tui_active) |
1725 | /* FIXME: cagney/2004-02-07: This should be an observer. */ | |
13274fc3 | 1726 | low = tui_get_low_disassembly_address (gdbarch, low, pc); |
83c31e7d | 1727 | #endif |
13274fc3 | 1728 | low += gdbarch_deprecated_function_start_offset (gdbarch); |
9c419145 | 1729 | flags |= DISASSEMBLY_OMIT_FNAME; |
83c31e7d FN |
1730 | } |
1731 | else | |
1732 | { | |
1733 | /* Two arguments. */ | |
53a71c06 | 1734 | int incl_flag = 0; |
21a0512e | 1735 | low = pc; |
f1735a53 | 1736 | p = skip_spaces (p); |
bbc13ae3 | 1737 | if (p[0] == '+') |
53a71c06 | 1738 | { |
bbc13ae3 | 1739 | ++p; |
53a71c06 CR |
1740 | incl_flag = 1; |
1741 | } | |
bbc13ae3 | 1742 | high = parse_and_eval_address (p); |
53a71c06 CR |
1743 | if (incl_flag) |
1744 | high += low; | |
83c31e7d FN |
1745 | } |
1746 | ||
e9480230 | 1747 | print_disassembly (gdbarch, name, low, high, block, flags); |
83c31e7d FN |
1748 | } |
1749 | ||
b20885b0 AB |
1750 | /* Command completion for the disassemble command. */ |
1751 | ||
1752 | static void | |
1753 | disassemble_command_completer (struct cmd_list_element *ignore, | |
1754 | completion_tracker &tracker, | |
1755 | const char *text, const char * /* word */) | |
1756 | { | |
1757 | if (skip_over_slash_fmt (tracker, &text)) | |
1758 | return; | |
1759 | ||
1760 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
1761 | expression_completer (ignore, tracker, text, word); | |
1762 | } | |
1763 | ||
d318976c | 1764 | static void |
0b39b52e | 1765 | make_command (const char *arg, int from_tty) |
d318976c | 1766 | { |
d318976c | 1767 | if (arg == 0) |
be47f9e8 | 1768 | shell_escape ("make", from_tty); |
d318976c FN |
1769 | else |
1770 | { | |
be47f9e8 | 1771 | std::string cmd = std::string ("make ") + arg; |
d318976c | 1772 | |
be47f9e8 PA |
1773 | shell_escape (cmd.c_str (), from_tty); |
1774 | } | |
d318976c FN |
1775 | } |
1776 | ||
d318976c | 1777 | static void |
dede02ce | 1778 | show_user (const char *args, int from_tty) |
d318976c FN |
1779 | { |
1780 | struct cmd_list_element *c; | |
d318976c FN |
1781 | |
1782 | if (args) | |
1783 | { | |
6f937416 | 1784 | const char *comname = args; |
cdb27c12 | 1785 | |
cf00cd6f | 1786 | c = lookup_cmd (&comname, cmdlist, "", NULL, 0, 1); |
a9f116cb | 1787 | if (!cli_user_command_p (c)) |
8a3fe4f8 | 1788 | error (_("Not a user command.")); |
adb483fe | 1789 | show_user_1 (c, "", args, gdb_stdout); |
d318976c FN |
1790 | } |
1791 | else | |
1792 | { | |
1793 | for (c = cmdlist; c; c = c->next) | |
1794 | { | |
3d0b3564 | 1795 | if (cli_user_command_p (c) || c->is_prefix ()) |
adb483fe | 1796 | show_user_1 (c, "", c->name, gdb_stdout); |
d318976c FN |
1797 | } |
1798 | } | |
1799 | } | |
1800 | ||
cc81bc2d LS |
1801 | /* Return true if COMMAND or any of its sub-commands is a user defined command. |
1802 | This is a helper function for show_user_completer. */ | |
1803 | ||
1804 | static bool | |
1805 | has_user_subcmd (struct cmd_list_element *command) | |
1806 | { | |
1807 | if (cli_user_command_p (command)) | |
1808 | return true; | |
1809 | ||
1810 | /* Alias command can yield false positive. Ignore them as the targeted | |
1811 | command should be reachable anyway. */ | |
1812 | if (command->is_alias ()) | |
1813 | return false; | |
1814 | ||
1815 | if (command->is_prefix ()) | |
1816 | for (struct cmd_list_element *subcommand = *command->subcommands; | |
1817 | subcommand != nullptr; | |
1818 | subcommand = subcommand->next) | |
1819 | if (has_user_subcmd (subcommand)) | |
1820 | return true; | |
1821 | ||
1822 | return false; | |
1823 | } | |
1824 | ||
1825 | /* Implement completer for the 'show user' command. */ | |
1826 | ||
1827 | static void | |
1828 | show_user_completer (cmd_list_element *, | |
1829 | completion_tracker &tracker, const char *text, | |
1830 | const char *word) | |
1831 | { | |
1832 | struct cmd_list_element *cmd_group = cmdlist; | |
1833 | ||
1834 | /* TEXT can contain a chain of commands and subcommands. Follow the | |
1835 | commands chain until we reach the point where the user wants a | |
1836 | completion. */ | |
1837 | while (word > text) | |
1838 | { | |
1839 | const char *curr_cmd = text; | |
1840 | const char *after = skip_to_space (text); | |
1841 | const size_t curr_cmd_len = after - text; | |
1842 | text = skip_spaces (after); | |
1843 | ||
1844 | for (struct cmd_list_element *c = cmd_group; c != nullptr; c = c->next) | |
1845 | { | |
1846 | if (strlen (c->name) == curr_cmd_len | |
1847 | && strncmp (c->name, curr_cmd, curr_cmd_len) == 0) | |
1848 | { | |
1849 | if (c->subcommands == nullptr) | |
1850 | /* We arrived after a command with no child, so nothing more | |
1851 | to complete. */ | |
1852 | return; | |
1853 | ||
1854 | cmd_group = *c->subcommands; | |
1855 | break; | |
1856 | } | |
1857 | } | |
1858 | } | |
1859 | ||
1860 | const int wordlen = strlen (word); | |
1861 | for (struct cmd_list_element *c = cmd_group; c != nullptr; c = c->next) | |
1862 | if (has_user_subcmd (c)) | |
1863 | { | |
1864 | if (strncmp (c->name, word, wordlen) == 0) | |
1865 | tracker.add_completion | |
1866 | (gdb::unique_xmalloc_ptr<char> (xstrdup (c->name))); | |
1867 | } | |
1868 | } | |
1869 | ||
d318976c | 1870 | /* Search through names of commands and documentations for a certain |
ebcd3b23 MS |
1871 | regular expression. */ |
1872 | ||
66d8c862 PW |
1873 | static void |
1874 | apropos_command (const char *arg, int from_tty) | |
d318976c | 1875 | { |
66d8c862 PW |
1876 | bool verbose = arg && check_for_argument (&arg, "-v", 2); |
1877 | ||
66d8c862 | 1878 | if (arg == NULL || *arg == '\0') |
f55af66d | 1879 | error (_("REGEXP string is empty")); |
d318976c | 1880 | |
66d8c862 | 1881 | compiled_regex pattern (arg, REG_ICASE, |
2d7cc5c7 | 1882 | _("Error in regular expression")); |
dc92e161 | 1883 | |
c4e37fa8 | 1884 | apropos_cmd (gdb_stdout, cmdlist, verbose, pattern); |
d318976c | 1885 | } |
5a56e9c5 | 1886 | |
cf00cd6f PW |
1887 | /* The options for the "alias" command. */ |
1888 | ||
1889 | struct alias_opts | |
1890 | { | |
1891 | /* For "-a". */ | |
1892 | bool abbrev_flag = false; | |
1893 | }; | |
1894 | ||
1895 | static const gdb::option::option_def alias_option_defs[] = { | |
1896 | ||
1897 | gdb::option::flag_option_def<alias_opts> { | |
1898 | "a", | |
1899 | [] (alias_opts *opts) { return &opts->abbrev_flag; }, | |
1900 | N_("Specify that ALIAS is an abbreviation of COMMAND.\n\ | |
1901 | Abbreviations are not used in command completion."), | |
1902 | }, | |
1903 | ||
1904 | }; | |
1905 | ||
1906 | /* Create an option_def_group for the "alias" options, with | |
1907 | A_OPTS as context. */ | |
1908 | ||
1909 | static gdb::option::option_def_group | |
1910 | make_alias_options_def_group (alias_opts *a_opts) | |
1911 | { | |
1912 | return {{alias_option_defs}, a_opts}; | |
1913 | } | |
1914 | ||
1915 | /* Completer for the "alias_command". */ | |
1916 | ||
1917 | static void | |
1918 | alias_command_completer (struct cmd_list_element *ignore, | |
1919 | completion_tracker &tracker, | |
1920 | const char *text, const char *word) | |
1921 | { | |
1922 | const auto grp = make_alias_options_def_group (nullptr); | |
1923 | ||
1924 | tracker.set_use_custom_word_point (true); | |
1925 | ||
1926 | if (gdb::option::complete_options | |
1927 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp)) | |
1928 | return; | |
1929 | ||
1930 | const char *delim = strchr (text, '='); | |
1931 | ||
1932 | /* If we're past the "=" delimiter, complete the | |
1933 | "alias ALIAS = COMMAND [DEFAULT-ARGS...]" as if the user is | |
1934 | typing COMMAND DEFAULT-ARGS... */ | |
1935 | if (delim != text | |
1936 | && delim != nullptr | |
1937 | && isspace (delim[-1]) | |
1938 | && (isspace (delim[1]) || delim[1] == '\0')) | |
1939 | { | |
1940 | std::string new_text = std::string (delim + 1); | |
1941 | ||
1942 | tracker.advance_custom_word_point_by (delim + 1 - text); | |
1943 | complete_nested_command_line (tracker, new_text.c_str ()); | |
1944 | return; | |
1945 | } | |
1946 | ||
1947 | /* We're not yet past the "=" delimiter. Complete a command, as | |
1948 | the user might type an alias following a prefix command. */ | |
1949 | complete_nested_command_line (tracker, text); | |
1950 | } | |
1951 | ||
5a56e9c5 DE |
1952 | /* Subroutine of alias_command to simplify it. |
1953 | Return the first N elements of ARGV flattened back to a string | |
1954 | with a space separating each element. | |
1955 | ARGV may not be NULL. | |
1956 | This does not take care of quoting elements in case they contain spaces | |
1957 | on purpose. */ | |
1958 | ||
a97e29d2 TT |
1959 | static std::string |
1960 | argv_to_string (char **argv, int n) | |
5a56e9c5 DE |
1961 | { |
1962 | int i; | |
a97e29d2 | 1963 | std::string result; |
5a56e9c5 DE |
1964 | |
1965 | gdb_assert (argv != NULL); | |
1966 | gdb_assert (n >= 0 && n <= countargv (argv)); | |
1967 | ||
1968 | for (i = 0; i < n; ++i) | |
1969 | { | |
1970 | if (i > 0) | |
a97e29d2 TT |
1971 | result += " "; |
1972 | result += argv[i]; | |
5a56e9c5 DE |
1973 | } |
1974 | ||
1975 | return result; | |
1976 | } | |
1977 | ||
1978 | /* Subroutine of alias_command to simplify it. | |
cf00cd6f PW |
1979 | Verifies that COMMAND can have an alias: |
1980 | COMMAND must exist. | |
1981 | COMMAND must not have default args. | |
1982 | This last condition is to avoid the following: | |
1983 | alias aaa = backtrace -full | |
1984 | alias bbb = aaa -past-main | |
1985 | as (at least currently), alias default args are not cumulative | |
1986 | and the user would expect bbb to execute 'backtrace -full -past-main' | |
1987 | while it will execute 'backtrace -past-main'. */ | |
5a56e9c5 | 1988 | |
3947f654 | 1989 | static cmd_list_element * |
cf00cd6f | 1990 | validate_aliased_command (const char *command) |
5a56e9c5 | 1991 | { |
cf00cd6f | 1992 | std::string default_args; |
3947f654 SM |
1993 | cmd_list_element *c |
1994 | = lookup_cmd_1 (& command, cmdlist, NULL, &default_args, 1); | |
5a56e9c5 DE |
1995 | |
1996 | if (c == NULL || c == (struct cmd_list_element *) -1) | |
cf00cd6f PW |
1997 | error (_("Invalid command to alias to: %s"), command); |
1998 | ||
1999 | if (!default_args.empty ()) | |
2000 | error (_("Cannot define an alias of an alias that has default args")); | |
3947f654 SM |
2001 | |
2002 | return c; | |
5a56e9c5 DE |
2003 | } |
2004 | ||
7f31862a PA |
2005 | /* Called when "alias" was incorrectly used. */ |
2006 | ||
2007 | static void | |
2008 | alias_usage_error (void) | |
2009 | { | |
cf00cd6f | 2010 | error (_("Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]")); |
7f31862a PA |
2011 | } |
2012 | ||
5a56e9c5 DE |
2013 | /* Make an alias of an existing command. */ |
2014 | ||
2015 | static void | |
0b39b52e | 2016 | alias_command (const char *args, int from_tty) |
5a56e9c5 | 2017 | { |
cf00cd6f PW |
2018 | alias_opts a_opts; |
2019 | ||
2020 | auto grp = make_alias_options_def_group (&a_opts); | |
2021 | gdb::option::process_options | |
2022 | (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp); | |
2023 | ||
5a56e9c5 | 2024 | int i, alias_argc, command_argc; |
0b39b52e | 2025 | const char *equals; |
a97e29d2 | 2026 | const char *alias, *command; |
5a56e9c5 DE |
2027 | |
2028 | if (args == NULL || strchr (args, '=') == NULL) | |
7f31862a | 2029 | alias_usage_error (); |
5a56e9c5 | 2030 | |
773a1edc TT |
2031 | equals = strchr (args, '='); |
2032 | std::string args2 (args, equals - args); | |
2033 | ||
2034 | gdb_argv built_alias_argv (args2.c_str ()); | |
cf00cd6f PW |
2035 | |
2036 | const char *default_args = equals + 1; | |
2037 | struct cmd_list_element *c_command_prefix; | |
2038 | ||
2039 | lookup_cmd_for_default_args (&default_args, &c_command_prefix); | |
2040 | std::string command_argv_str (equals + 1, | |
2041 | default_args == nullptr | |
2042 | ? strlen (equals + 1) | |
2043 | : default_args - equals - 1); | |
2044 | gdb_argv command_argv (command_argv_str.c_str ()); | |
5a56e9c5 | 2045 | |
773a1edc | 2046 | char **alias_argv = built_alias_argv.get (); |
5a56e9c5 DE |
2047 | |
2048 | if (alias_argv[0] == NULL || command_argv[0] == NULL | |
2049 | || *alias_argv[0] == '\0' || *command_argv[0] == '\0') | |
7f31862a | 2050 | alias_usage_error (); |
5a56e9c5 DE |
2051 | |
2052 | for (i = 0; alias_argv[i] != NULL; ++i) | |
2053 | { | |
2054 | if (! valid_user_defined_cmd_name_p (alias_argv[i])) | |
2055 | { | |
2056 | if (i == 0) | |
2057 | error (_("Invalid command name: %s"), alias_argv[i]); | |
2058 | else | |
2059 | error (_("Invalid command element name: %s"), alias_argv[i]); | |
2060 | } | |
2061 | } | |
2062 | ||
2063 | alias_argc = countargv (alias_argv); | |
773a1edc | 2064 | command_argc = command_argv.count (); |
5a56e9c5 | 2065 | |
cf00cd6f | 2066 | /* COMMAND must exist, and cannot have default args. |
5a56e9c5 DE |
2067 | Reconstruct the command to remove any extraneous spaces, |
2068 | for better error messages. */ | |
773a1edc TT |
2069 | std::string command_string (argv_to_string (command_argv.get (), |
2070 | command_argc)); | |
a97e29d2 | 2071 | command = command_string.c_str (); |
3947f654 | 2072 | cmd_list_element *target_cmd = validate_aliased_command (command); |
5a56e9c5 DE |
2073 | |
2074 | /* ALIAS must not exist. */ | |
a97e29d2 TT |
2075 | std::string alias_string (argv_to_string (alias_argv, alias_argc)); |
2076 | alias = alias_string.c_str (); | |
0605465f PW |
2077 | { |
2078 | cmd_list_element *alias_cmd, *prefix_cmd, *cmd; | |
2079 | ||
2080 | if (lookup_cmd_composition (alias, &alias_cmd, &prefix_cmd, &cmd)) | |
2081 | { | |
2082 | const char *alias_name = alias_argv[alias_argc-1]; | |
2083 | ||
2084 | /* If we found an existing ALIAS_CMD, check that the prefix differ or | |
2085 | the name differ. */ | |
2086 | ||
2087 | if (alias_cmd != nullptr | |
2088 | && alias_cmd->prefix == prefix_cmd | |
2089 | && strcmp (alias_name, alias_cmd->name) == 0) | |
2090 | error (_("Alias already exists: %s"), alias); | |
2091 | ||
2092 | /* Check ALIAS differs from the found CMD. */ | |
2093 | ||
2094 | if (cmd->prefix == prefix_cmd | |
2095 | && strcmp (alias_name, cmd->name) == 0) | |
2096 | error (_("Alias %s is the name of an existing command"), alias); | |
2097 | } | |
2098 | } | |
2099 | ||
5a56e9c5 | 2100 | |
cf00cd6f PW |
2101 | struct cmd_list_element *alias_cmd; |
2102 | ||
5a56e9c5 DE |
2103 | /* If ALIAS is one word, it is an alias for the entire COMMAND. |
2104 | Example: alias spe = set print elements | |
2105 | ||
2106 | Otherwise ALIAS and COMMAND must have the same number of words, | |
b65b566c PW |
2107 | and every word except the last must identify the same prefix command; |
2108 | and the last word of ALIAS is made an alias of the last word of COMMAND. | |
5a56e9c5 DE |
2109 | Example: alias set print elms = set pr elem |
2110 | Note that unambiguous abbreviations are allowed. */ | |
2111 | ||
2112 | if (alias_argc == 1) | |
2113 | { | |
2114 | /* add_cmd requires *we* allocate space for name, hence the xstrdup. */ | |
3947f654 SM |
2115 | alias_cmd = add_com_alias (xstrdup (alias_argv[0]), target_cmd, |
2116 | class_alias, a_opts.abbrev_flag); | |
5a56e9c5 DE |
2117 | } |
2118 | else | |
2119 | { | |
6f937416 | 2120 | const char *alias_prefix, *command_prefix; |
5a56e9c5 DE |
2121 | struct cmd_list_element *c_alias, *c_command; |
2122 | ||
2123 | if (alias_argc != command_argc) | |
2124 | error (_("Mismatched command length between ALIAS and COMMAND.")); | |
2125 | ||
2126 | /* Create copies of ALIAS and COMMAND without the last word, | |
b65b566c PW |
2127 | and use that to verify the leading elements give the same |
2128 | prefix command. */ | |
a97e29d2 TT |
2129 | std::string alias_prefix_string (argv_to_string (alias_argv, |
2130 | alias_argc - 1)); | |
b65b566c | 2131 | std::string command_prefix_string (argv_to_string (command_argv.get (), |
a97e29d2 TT |
2132 | command_argc - 1)); |
2133 | alias_prefix = alias_prefix_string.c_str (); | |
2134 | command_prefix = command_prefix_string.c_str (); | |
5a56e9c5 | 2135 | |
cf00cd6f | 2136 | c_command = lookup_cmd_1 (& command_prefix, cmdlist, NULL, NULL, 1); |
5a56e9c5 DE |
2137 | /* We've already tried to look up COMMAND. */ |
2138 | gdb_assert (c_command != NULL | |
2139 | && c_command != (struct cmd_list_element *) -1); | |
3d0b3564 | 2140 | gdb_assert (c_command->is_prefix ()); |
cf00cd6f | 2141 | c_alias = lookup_cmd_1 (& alias_prefix, cmdlist, NULL, NULL, 1); |
5a56e9c5 DE |
2142 | if (c_alias != c_command) |
2143 | error (_("ALIAS and COMMAND prefixes do not match.")); | |
2144 | ||
2145 | /* add_cmd requires *we* allocate space for name, hence the xstrdup. */ | |
cf00cd6f | 2146 | alias_cmd = add_alias_cmd (xstrdup (alias_argv[alias_argc - 1]), |
5e84b7ee | 2147 | target_cmd, class_alias, a_opts.abbrev_flag, |
14b42fc4 | 2148 | c_command->subcommands); |
cf00cd6f PW |
2149 | } |
2150 | ||
2151 | gdb_assert (alias_cmd != nullptr); | |
2152 | gdb_assert (alias_cmd->default_args.empty ()); | |
2153 | if (default_args != nullptr) | |
2154 | { | |
2155 | default_args = skip_spaces (default_args); | |
2156 | ||
2157 | alias_cmd->default_args = default_args; | |
5a56e9c5 DE |
2158 | } |
2159 | } | |
d318976c | 2160 | \f |
06871ae8 PA |
2161 | /* Print the file / line number / symbol name of the location |
2162 | specified by SAL. */ | |
2163 | ||
2164 | static void | |
2165 | print_sal_location (const symtab_and_line &sal) | |
2166 | { | |
2167 | scoped_restore_current_program_space restore_pspace; | |
2168 | set_current_program_space (sal.pspace); | |
2169 | ||
2170 | const char *sym_name = NULL; | |
2171 | if (sal.symbol != NULL) | |
987012b8 | 2172 | sym_name = sal.symbol->print_name (); |
887ae0cf | 2173 | gdb_printf (_("file: \"%s\", line number: %ps, symbol: \"%s\"\n"), |
6cb06a8c | 2174 | symtab_to_filename_for_display (sal.symtab), |
887ae0cf TT |
2175 | styled_string (line_number_style.style (), |
2176 | pulongest (sal.line)), | |
2177 | sym_name != NULL ? sym_name : "???"); | |
06871ae8 PA |
2178 | } |
2179 | ||
0378c332 | 2180 | /* Print a list of files and line numbers which a user may choose from |
ebcd3b23 | 2181 | in order to list a function which was specified ambiguously (as |
6c5b2ebe PA |
2182 | with `list classname::overloadedfuncname', for example). The SALS |
2183 | array provides the filenames and line numbers. FORMAT is a | |
2184 | printf-style format string used to tell the user what was | |
e439fa14 | 2185 | ambiguous. */ |
0378c332 FN |
2186 | |
2187 | static void | |
6c5b2ebe PA |
2188 | ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals, |
2189 | const char *format, ...) | |
0378c332 | 2190 | { |
e439fa14 PA |
2191 | va_list ap; |
2192 | va_start (ap, format); | |
19a7b8ab | 2193 | gdb_vprintf (format, ap); |
e439fa14 PA |
2194 | va_end (ap); |
2195 | ||
6c5b2ebe | 2196 | for (const auto &sal : sals) |
06871ae8 | 2197 | print_sal_location (sal); |
0378c332 FN |
2198 | } |
2199 | ||
6c5b2ebe PA |
2200 | /* Comparison function for filter_sals. Returns a qsort-style |
2201 | result. */ | |
f8eba3c6 TT |
2202 | |
2203 | static int | |
6c5b2ebe | 2204 | cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb) |
f8eba3c6 | 2205 | { |
e4730328 SM |
2206 | const char *dira = sala.symtab->compunit ()->dirname (); |
2207 | const char *dirb = salb.symtab->compunit ()->dirname (); | |
f8eba3c6 TT |
2208 | int r; |
2209 | ||
ee6f8984 | 2210 | if (dira == NULL) |
f8eba3c6 | 2211 | { |
ee6f8984 | 2212 | if (dirb != NULL) |
f8eba3c6 TT |
2213 | return -1; |
2214 | } | |
ee6f8984 | 2215 | else if (dirb == NULL) |
f8eba3c6 | 2216 | { |
ee6f8984 | 2217 | if (dira != NULL) |
f8eba3c6 TT |
2218 | return 1; |
2219 | } | |
2220 | else | |
2221 | { | |
ee6f8984 | 2222 | r = filename_cmp (dira, dirb); |
f8eba3c6 TT |
2223 | if (r) |
2224 | return r; | |
2225 | } | |
2226 | ||
6c5b2ebe | 2227 | r = filename_cmp (sala.symtab->filename, salb.symtab->filename); |
f8eba3c6 TT |
2228 | if (r) |
2229 | return r; | |
2230 | ||
6c5b2ebe | 2231 | if (sala.line < salb.line) |
f8eba3c6 | 2232 | return -1; |
6c5b2ebe | 2233 | return sala.line == salb.line ? 0 : 1; |
f8eba3c6 TT |
2234 | } |
2235 | ||
2236 | /* Remove any SALs that do not match the current program space, or | |
2237 | which appear to be "file:line" duplicates. */ | |
2238 | ||
2239 | static void | |
6c5b2ebe | 2240 | filter_sals (std::vector<symtab_and_line> &sals) |
f8eba3c6 | 2241 | { |
6c5b2ebe PA |
2242 | /* Remove SALs that do not match. */ |
2243 | auto from = std::remove_if (sals.begin (), sals.end (), | |
2244 | [&] (const symtab_and_line &sal) | |
2245 | { return (sal.pspace != current_program_space || sal.symtab == NULL); }); | |
2246 | ||
2247 | /* Remove dups. */ | |
2248 | std::sort (sals.begin (), from, | |
2249 | [] (const symtab_and_line &sala, const symtab_and_line &salb) | |
2250 | { return cmp_symtabs (sala, salb) < 0; }); | |
2251 | ||
2252 | from = std::unique (sals.begin (), from, | |
2253 | [&] (const symtab_and_line &sala, | |
2254 | const symtab_and_line &salb) | |
2255 | { return cmp_symtabs (sala, salb) == 0; }); | |
2256 | ||
2257 | sals.erase (from, sals.end ()); | |
f8eba3c6 TT |
2258 | } |
2259 | ||
920d2a44 AC |
2260 | static void |
2261 | show_info_verbose (struct ui_file *file, int from_tty, | |
2262 | struct cmd_list_element *c, | |
2263 | const char *value) | |
2264 | { | |
2265 | if (info_verbose) | |
6cb06a8c TT |
2266 | gdb_printf (file, |
2267 | _("Verbose printing of informational messages is %s.\n"), | |
2268 | value); | |
920d2a44 | 2269 | else |
6cb06a8c | 2270 | gdb_printf (file, _("Verbosity is %s.\n"), value); |
920d2a44 AC |
2271 | } |
2272 | ||
2273 | static void | |
2274 | show_history_expansion_p (struct ui_file *file, int from_tty, | |
2275 | struct cmd_list_element *c, const char *value) | |
2276 | { | |
6cb06a8c TT |
2277 | gdb_printf (file, _("History expansion on command input is %s.\n"), |
2278 | value); | |
920d2a44 AC |
2279 | } |
2280 | ||
920d2a44 AC |
2281 | static void |
2282 | show_max_user_call_depth (struct ui_file *file, int from_tty, | |
2283 | struct cmd_list_element *c, const char *value) | |
2284 | { | |
6cb06a8c TT |
2285 | gdb_printf (file, |
2286 | _("The max call depth for user-defined commands is %s.\n"), | |
2287 | value); | |
920d2a44 AC |
2288 | } |
2289 | ||
61fb7376 TBA |
2290 | /* Implement 'show suppress-cli-notifications'. */ |
2291 | ||
2292 | static void | |
2293 | show_suppress_cli_notifications (ui_file *file, int from_tty, | |
2294 | cmd_list_element *c, const char *value) | |
2295 | { | |
6cb06a8c TT |
2296 | gdb_printf (file, _("Suppression of printing CLI notifications " |
2297 | "is %s.\n"), value); | |
61fb7376 TBA |
2298 | } |
2299 | ||
2300 | /* Implement 'set suppress-cli-notifications'. */ | |
2301 | ||
2302 | static void | |
2303 | set_suppress_cli_notifications (const char *args, int from_tty, | |
2304 | cmd_list_element *c) | |
2305 | { | |
2306 | cli_suppress_notification.user_selected_context | |
2307 | = user_wants_cli_suppress_notification; | |
2308 | cli_suppress_notification.normal_stop | |
2309 | = user_wants_cli_suppress_notification; | |
2310 | } | |
2311 | ||
9ad9b77d PW |
2312 | /* Returns the cmd_list_element in SHOWLIST corresponding to the first |
2313 | argument of ARGV, which must contain one single value. | |
2314 | Throws an error if no value provided, or value not correct. | |
2315 | FNNAME is used in the error message. */ | |
2316 | ||
2317 | static cmd_list_element * | |
2318 | setting_cmd (const char *fnname, struct cmd_list_element *showlist, | |
2319 | int argc, struct value **argv) | |
2320 | { | |
2321 | if (argc == 0) | |
2322 | error (_("You must provide an argument to %s"), fnname); | |
2323 | if (argc != 1) | |
2324 | error (_("You can only provide one argument to %s"), fnname); | |
2325 | ||
d0c97917 | 2326 | struct type *type0 = check_typedef (argv[0]->type ()); |
9ad9b77d | 2327 | |
78134374 SM |
2328 | if (type0->code () != TYPE_CODE_ARRAY |
2329 | && type0->code () != TYPE_CODE_STRING) | |
9ad9b77d PW |
2330 | error (_("First argument of %s must be a string."), fnname); |
2331 | ||
ec5e9488 AB |
2332 | /* Not all languages null-terminate their strings, by moving the string |
2333 | content into a std::string we ensure that a null-terminator is added. | |
2334 | For languages that do add a null-terminator the std::string might end | |
2335 | up with two null characters at the end, but that's harmless. */ | |
2336 | const std::string setting ((const char *) argv[0]->contents ().data (), | |
2337 | type0->length ()); | |
2338 | const char *a0 = setting.c_str (); | |
cf00cd6f | 2339 | cmd_list_element *cmd = lookup_cmd (&a0, showlist, "", NULL, -1, 0); |
9ad9b77d | 2340 | |
cd4c4c07 | 2341 | if (cmd == nullptr || cmd->type != show_cmd) |
a02fcd08 AB |
2342 | { |
2343 | gdb_assert (showlist->prefix != nullptr); | |
2344 | std::vector<std::string> components | |
2345 | = showlist->prefix->command_components (); | |
2346 | std::string full_name = components[0]; | |
2347 | for (int i = 1; i < components.size (); ++i) | |
2348 | full_name += " " + components[i]; | |
2349 | error (_("First argument of %s must be a valid setting of the " | |
2350 | "'%s' command."), fnname, full_name.c_str ()); | |
2351 | } | |
9ad9b77d PW |
2352 | |
2353 | return cmd; | |
2354 | } | |
2355 | ||
2356 | /* Builds a value from the show CMD. */ | |
2357 | ||
2358 | static struct value * | |
1d7fe7f0 | 2359 | value_from_setting (const setting &var, struct gdbarch *gdbarch) |
9ad9b77d | 2360 | { |
1d7fe7f0 | 2361 | switch (var.type ()) |
9ad9b77d | 2362 | { |
7aeb03e2 | 2363 | case var_uinteger: |
9ad9b77d | 2364 | case var_integer: |
7aeb03e2 MR |
2365 | case var_pinteger: |
2366 | { | |
2367 | LONGEST value | |
2368 | = (var.type () == var_uinteger | |
2369 | ? static_cast<LONGEST> (var.get<unsigned int> ()) | |
2370 | : static_cast<LONGEST> (var.get<int> ())); | |
2371 | ||
2372 | if (var.extra_literals () != nullptr) | |
2373 | for (const literal_def *l = var.extra_literals (); | |
2374 | l->literal != nullptr; | |
2375 | l++) | |
2376 | if (value == l->use) | |
2377 | { | |
2378 | if (l->val.has_value ()) | |
2379 | value = *l->val; | |
2380 | else | |
317c3ed9 | 2381 | return value::allocate (builtin_type (gdbarch)->builtin_void); |
7aeb03e2 MR |
2382 | break; |
2383 | } | |
2384 | ||
2385 | if (var.type () == var_uinteger) | |
2386 | return | |
2387 | value_from_ulongest (builtin_type (gdbarch)->builtin_unsigned_int, | |
2388 | static_cast<unsigned int> (value)); | |
2389 | else | |
2390 | return | |
2391 | value_from_longest (builtin_type (gdbarch)->builtin_int, | |
2392 | static_cast<int> (value)); | |
2393 | } | |
9ad9b77d PW |
2394 | case var_boolean: |
2395 | return value_from_longest (builtin_type (gdbarch)->builtin_int, | |
1d7fe7f0 | 2396 | var.get<bool> () ? 1 : 0); |
9ad9b77d PW |
2397 | case var_auto_boolean: |
2398 | { | |
2399 | int val; | |
2400 | ||
1d7fe7f0 | 2401 | switch (var.get<enum auto_boolean> ()) |
9ad9b77d PW |
2402 | { |
2403 | case AUTO_BOOLEAN_TRUE: | |
2404 | val = 1; | |
2405 | break; | |
2406 | case AUTO_BOOLEAN_FALSE: | |
2407 | val = 0; | |
2408 | break; | |
2409 | case AUTO_BOOLEAN_AUTO: | |
2410 | val = -1; | |
2411 | break; | |
2412 | default: | |
2413 | gdb_assert_not_reached ("invalid var_auto_boolean"); | |
2414 | } | |
2415 | return value_from_longest (builtin_type (gdbarch)->builtin_int, | |
2416 | val); | |
2417 | } | |
9ad9b77d PW |
2418 | case var_string: |
2419 | case var_string_noescape: | |
2420 | case var_optional_filename: | |
2421 | case var_filename: | |
2422 | case var_enum: | |
1d7fe7f0 LS |
2423 | { |
2424 | const char *value; | |
e0700ba4 | 2425 | size_t len; |
1d7fe7f0 | 2426 | if (var.type () == var_enum) |
e0700ba4 SM |
2427 | { |
2428 | value = var.get<const char *> (); | |
2429 | len = strlen (value); | |
2430 | } | |
1d7fe7f0 | 2431 | else |
e0700ba4 SM |
2432 | { |
2433 | const std::string &st = var.get<std::string> (); | |
2434 | value = st.c_str (); | |
2435 | len = st.length (); | |
2436 | } | |
1d7fe7f0 | 2437 | |
baab3753 | 2438 | return current_language->value_string (gdbarch, value, len); |
1d7fe7f0 | 2439 | } |
6447969d AP |
2440 | case var_color: |
2441 | { | |
2442 | std::string s = var.get<ui_file_style::color> ().to_string (); | |
2443 | return current_language->value_string (gdbarch, s.c_str (), s.size ()); | |
2444 | } | |
9ad9b77d PW |
2445 | default: |
2446 | gdb_assert_not_reached ("bad var_type"); | |
2447 | } | |
2448 | } | |
2449 | ||
2450 | /* Implementation of the convenience function $_gdb_setting. */ | |
2451 | ||
2452 | static struct value * | |
2453 | gdb_setting_internal_fn (struct gdbarch *gdbarch, | |
2454 | const struct language_defn *language, | |
2455 | void *cookie, int argc, struct value **argv) | |
2456 | { | |
1d7fe7f0 LS |
2457 | cmd_list_element *show_cmd |
2458 | = setting_cmd ("$_gdb_setting", showlist, argc, argv); | |
2459 | ||
2460 | gdb_assert (show_cmd->var.has_value ()); | |
2461 | ||
2462 | return value_from_setting (*show_cmd->var, gdbarch); | |
9ad9b77d PW |
2463 | } |
2464 | ||
2465 | /* Implementation of the convenience function $_gdb_maint_setting. */ | |
2466 | ||
2467 | static struct value * | |
2468 | gdb_maint_setting_internal_fn (struct gdbarch *gdbarch, | |
2469 | const struct language_defn *language, | |
2470 | void *cookie, int argc, struct value **argv) | |
2471 | { | |
1d7fe7f0 LS |
2472 | cmd_list_element *show_cmd |
2473 | = setting_cmd ("$_gdb_maint_setting", maintenance_show_cmdlist, argc, argv); | |
2474 | ||
2475 | gdb_assert (show_cmd->var.has_value ()); | |
2476 | ||
2477 | return value_from_setting (*show_cmd->var, gdbarch); | |
9ad9b77d PW |
2478 | } |
2479 | ||
2480 | /* Builds a string value from the show CMD. */ | |
2481 | ||
2482 | static struct value * | |
1d7fe7f0 | 2483 | str_value_from_setting (const setting &var, struct gdbarch *gdbarch) |
9ad9b77d | 2484 | { |
1d7fe7f0 | 2485 | switch (var.type ()) |
9ad9b77d | 2486 | { |
7aeb03e2 | 2487 | case var_uinteger: |
9ad9b77d | 2488 | case var_integer: |
7aeb03e2 | 2489 | case var_pinteger: |
9ad9b77d | 2490 | case var_boolean: |
9ad9b77d | 2491 | case var_auto_boolean: |
6447969d | 2492 | case var_color: |
9ad9b77d | 2493 | { |
1d7fe7f0 | 2494 | std::string cmd_val = get_setshow_command_value_string (var); |
9ad9b77d | 2495 | |
baab3753 AB |
2496 | return current_language->value_string (gdbarch, cmd_val.c_str (), |
2497 | cmd_val.size ()); | |
9ad9b77d PW |
2498 | } |
2499 | ||
2500 | case var_string: | |
2501 | case var_string_noescape: | |
2502 | case var_optional_filename: | |
2503 | case var_filename: | |
2504 | case var_enum: | |
2505 | /* For these cases, we do not use get_setshow_command_value_string, | |
2506 | as this function handle some characters specially, e.g. by | |
1d7fe7f0 LS |
2507 | escaping quotevar. So, we directly use the var string value, |
2508 | similarly to the value_from_setting code for these casevar. */ | |
2509 | { | |
2510 | const char *value; | |
e0700ba4 | 2511 | size_t len; |
1d7fe7f0 | 2512 | if (var.type () == var_enum) |
e0700ba4 SM |
2513 | { |
2514 | value = var.get<const char *> (); | |
2515 | len = strlen (value); | |
2516 | } | |
1d7fe7f0 | 2517 | else |
e0700ba4 SM |
2518 | { |
2519 | const std::string &st = var.get<std::string> (); | |
2520 | value = st.c_str (); | |
2521 | len = st.length (); | |
2522 | } | |
9ad9b77d | 2523 | |
baab3753 | 2524 | return current_language->value_string (gdbarch, value, len); |
1d7fe7f0 | 2525 | } |
9ad9b77d PW |
2526 | default: |
2527 | gdb_assert_not_reached ("bad var_type"); | |
2528 | } | |
2529 | } | |
2530 | ||
2531 | /* Implementation of the convenience function $_gdb_setting_str. */ | |
2532 | ||
2533 | static struct value * | |
2534 | gdb_setting_str_internal_fn (struct gdbarch *gdbarch, | |
2535 | const struct language_defn *language, | |
2536 | void *cookie, int argc, struct value **argv) | |
2537 | { | |
1d7fe7f0 LS |
2538 | cmd_list_element *show_cmd |
2539 | = setting_cmd ("$_gdb_setting_str", showlist, argc, argv); | |
2540 | ||
2541 | gdb_assert (show_cmd->var.has_value ()); | |
2542 | ||
2543 | return str_value_from_setting (*show_cmd->var, gdbarch); | |
9ad9b77d PW |
2544 | } |
2545 | ||
2546 | ||
2547 | /* Implementation of the convenience function $_gdb_maint_setting_str. */ | |
2548 | ||
2549 | static struct value * | |
2550 | gdb_maint_setting_str_internal_fn (struct gdbarch *gdbarch, | |
2551 | const struct language_defn *language, | |
2552 | void *cookie, int argc, struct value **argv) | |
2553 | { | |
1d7fe7f0 LS |
2554 | cmd_list_element *show_cmd |
2555 | = setting_cmd ("$_gdb_maint_setting_str", maintenance_show_cmdlist, argc, | |
2556 | argv); | |
2557 | ||
2558 | gdb_assert (show_cmd->var.has_value ()); | |
2559 | ||
2560 | return str_value_from_setting (*show_cmd->var, gdbarch); | |
9ad9b77d PW |
2561 | } |
2562 | ||
91265a7d PA |
2563 | /* Implementation of the convenience function $_shell. */ |
2564 | ||
2565 | static struct value * | |
2566 | shell_internal_fn (struct gdbarch *gdbarch, | |
2567 | const struct language_defn *language, | |
2568 | void *cookie, int argc, struct value **argv) | |
2569 | { | |
2570 | if (argc != 1) | |
2571 | error (_("You must provide one argument for $_shell.")); | |
2572 | ||
2573 | value *val = argv[0]; | |
2574 | struct type *type = check_typedef (val->type ()); | |
2575 | ||
2576 | if (!language->is_string_type_p (type)) | |
2577 | error (_("Argument must be a string.")); | |
2578 | ||
2579 | value_print_options opts; | |
2580 | get_no_prettyformat_print_options (&opts); | |
2581 | ||
2582 | string_file stream; | |
2583 | value_print (val, &stream, &opts); | |
2584 | ||
2585 | /* We should always have two quote chars, which we'll strip. */ | |
2586 | gdb_assert (stream.size () >= 2); | |
2587 | ||
2588 | /* Now strip them. We don't need the original string, so it's | |
2589 | cheaper to do it in place, avoiding a string allocation. */ | |
2590 | std::string str = stream.release (); | |
2591 | str[str.size () - 1] = 0; | |
2592 | const char *command = str.c_str () + 1; | |
2593 | ||
2594 | int exit_status = run_under_shell (command, 0); | |
2595 | ||
2596 | struct type *int_type = builtin_type (gdbarch)->builtin_int; | |
2597 | ||
2598 | /* Keep the logic here in sync with | |
2599 | exit_status_set_internal_vars. */ | |
2600 | ||
2601 | if (WIFEXITED (exit_status)) | |
2602 | return value_from_longest (int_type, WEXITSTATUS (exit_status)); | |
2603 | #ifdef __MINGW32__ | |
2604 | else if (WIFSIGNALED (exit_status) && WTERMSIG (exit_status) == -1) | |
2605 | { | |
2606 | /* See exit_status_set_internal_vars. */ | |
2607 | return value_from_longest (int_type, exit_status); | |
2608 | } | |
2609 | #endif | |
2610 | else if (WIFSIGNALED (exit_status)) | |
2611 | { | |
2612 | /* (0x80 | SIGNO) is what most (all?) POSIX-like shells set as | |
2613 | exit code on fatal signal termination. */ | |
2614 | return value_from_longest (int_type, 0x80 | WTERMSIG (exit_status)); | |
2615 | } | |
2616 | else | |
2617 | return value::allocate_optimized_out (int_type); | |
2618 | } | |
2619 | ||
5fe70629 | 2620 | INIT_GDB_FILE (cli_cmds) |
d318976c FN |
2621 | { |
2622 | struct cmd_list_element *c; | |
2623 | ||
2624 | /* Define the classes of commands. | |
1bfeeb0f | 2625 | They will appear in the help list in alphabetical order. */ |
d318976c | 2626 | |
0450cc4c | 2627 | add_cmd ("internals", class_maintenance, _("\ |
1a966eab | 2628 | Maintenance commands.\n\ |
d318976c FN |
2629 | Some gdb commands are provided just for use by gdb maintainers.\n\ |
2630 | These commands are subject to frequent change, and may not be as\n\ | |
1a966eab | 2631 | well documented as user commands."), |
d318976c | 2632 | &cmdlist); |
0450cc4c TT |
2633 | add_cmd ("obscure", class_obscure, _("Obscure features."), &cmdlist); |
2634 | add_cmd ("aliases", class_alias, | |
cf00cd6f | 2635 | _("User-defined aliases of other commands."), &cmdlist); |
0450cc4c | 2636 | add_cmd ("user-defined", class_user, _("\ |
1a966eab | 2637 | User-defined commands.\n\ |
d318976c | 2638 | The commands in this class are those defined by the user.\n\ |
1a966eab | 2639 | Use the \"define\" command to define a command."), &cmdlist); |
0450cc4c | 2640 | add_cmd ("support", class_support, _("Support facilities."), &cmdlist); |
49a82d50 | 2641 | add_cmd ("status", class_info, _("Status inquiries."), &cmdlist); |
0450cc4c | 2642 | add_cmd ("files", class_files, _("Specifying and examining files."), |
1a966eab | 2643 | &cmdlist); |
0450cc4c | 2644 | add_cmd ("breakpoints", class_breakpoint, |
1a966eab | 2645 | _("Making program stop at certain points."), &cmdlist); |
0450cc4c TT |
2646 | add_cmd ("data", class_vars, _("Examining data."), &cmdlist); |
2647 | add_cmd ("stack", class_stack, _("\ | |
1a966eab | 2648 | Examining the stack.\n\ |
d318976c FN |
2649 | The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ |
2650 | counting from zero for the innermost (currently executing) frame.\n\n\ | |
2651 | At any time gdb identifies one frame as the \"selected\" frame.\n\ | |
2652 | Variable lookups are done with respect to the selected frame.\n\ | |
2653 | When the program being debugged stops, gdb selects the innermost frame.\n\ | |
1a966eab | 2654 | The commands below can be used to select other frames by number or address."), |
d318976c | 2655 | &cmdlist); |
e98d2e6d PW |
2656 | #ifdef TUI |
2657 | add_cmd ("text-user-interface", class_tui, | |
2658 | _("TUI is the GDB text based interface.\n\ | |
2659 | In TUI mode, GDB can display several text windows showing\n\ | |
2660 | the source file, the processor registers, the program disassembly, ..."), &cmdlist); | |
2661 | #endif | |
0450cc4c | 2662 | add_cmd ("running", class_run, _("Running the program."), &cmdlist); |
d318976c | 2663 | |
ebcd3b23 | 2664 | /* Define general commands. */ |
d318976c | 2665 | |
d729566a | 2666 | add_com ("pwd", class_files, pwd_command, _("\ |
590042fc PW |
2667 | Print working directory.\n\ |
2668 | This is used for your program as well.")); | |
4f8d22e3 | 2669 | |
1a966eab | 2670 | c = add_cmd ("cd", class_files, cd_command, _("\ |
d092c5a2 SDJ |
2671 | Set working directory to DIR for debugger.\n\ |
2672 | The debugger's current working directory specifies where scripts and other\n\ | |
2673 | files that can be loaded by GDB are located.\n\ | |
2674 | In order to change the inferior's current working directory, the recommended\n\ | |
2675 | way is to use the \"set cwd\" command."), &cmdlist); | |
dc22ab49 | 2676 | set_cmd_completer (c, deprecated_filename_completer); |
d318976c | 2677 | |
1bedd215 AC |
2678 | add_com ("echo", class_support, echo_command, _("\ |
2679 | Print a constant string. Give string as argument.\n\ | |
d318976c FN |
2680 | C escape sequences may be used in the argument.\n\ |
2681 | No newline is added at the end of the argument;\n\ | |
2682 | use \"\\n\" if you want a newline to be printed.\n\ | |
2683 | Since leading and trailing whitespace are ignored in command arguments,\n\ | |
2684 | if you want to print some you must use \"\\\" before leading whitespace\n\ | |
1bedd215 | 2685 | to be printed or after trailing whitespace.")); |
d318976c | 2686 | |
973817a3 JB |
2687 | add_setshow_enum_cmd ("script-extension", class_support, |
2688 | script_ext_enums, &script_ext_mode, _("\ | |
2689 | Set mode for script filename extension recognition."), _("\ | |
2690 | Show mode for script filename extension recognition."), _("\ | |
2691 | off == no filename extension recognition (all sourced files are GDB scripts)\n\ | |
fc55e99a TT |
2692 | soft == evaluate script according to filename extension, fallback to GDB script\n\ |
2693 | strict == evaluate script according to filename extension,\n\ | |
2694 | error if not supported" | |
973817a3 JB |
2695 | ), |
2696 | NULL, | |
2697 | show_script_ext_mode, | |
2698 | &setlist, &showlist); | |
2699 | ||
3947f654 SM |
2700 | cmd_list_element *quit_cmd |
2701 | = add_com ("quit", class_support, quit_command, _("\ | |
bdb52a22 | 2702 | Exit gdb.\n\ |
fa8f0a0f | 2703 | Usage: quit [EXPR] or exit [EXPR]\n\ |
bdb52a22 TT |
2704 | The optional expression EXPR, if present, is evaluated and the result\n\ |
2705 | used as GDB's exit code. The default is zero.")); | |
3947f654 SM |
2706 | cmd_list_element *help_cmd |
2707 | = add_com ("help", class_support, help_command, | |
1bedd215 | 2708 | _("Print list of commands.")); |
3947f654 SM |
2709 | set_cmd_completer (help_cmd, command_completer); |
2710 | add_com_alias ("q", quit_cmd, class_support, 1); | |
fa8f0a0f | 2711 | add_com_alias ("exit", quit_cmd, class_support, 1); |
3947f654 | 2712 | add_com_alias ("h", help_cmd, class_support, 1); |
d318976c | 2713 | |
5bf193a2 AC |
2714 | add_setshow_boolean_cmd ("verbose", class_support, &info_verbose, _("\ |
2715 | Set verbosity."), _("\ | |
2716 | Show verbosity."), NULL, | |
2717 | set_verbose, | |
920d2a44 | 2718 | show_info_verbose, |
5bf193a2 | 2719 | &setlist, &showlist); |
d318976c | 2720 | |
f54bdb6d SM |
2721 | add_setshow_prefix_cmd |
2722 | ("history", class_support, | |
2723 | _("Generic command for setting command history parameters."), | |
2724 | _("Generic command for showing command history parameters."), | |
2725 | &sethistlist, &showhistlist, &setlist, &showlist); | |
d318976c | 2726 | |
5bf193a2 AC |
2727 | add_setshow_boolean_cmd ("expansion", no_class, &history_expansion_p, _("\ |
2728 | Set history expansion on command input."), _("\ | |
2729 | Show history expansion on command input."), _("\ | |
2730 | Without an argument, history expansion is enabled."), | |
2731 | NULL, | |
920d2a44 | 2732 | show_history_expansion_p, |
5bf193a2 | 2733 | &sethistlist, &showhistlist); |
d318976c | 2734 | |
3947f654 SM |
2735 | cmd_list_element *info_cmd |
2736 | = add_prefix_cmd ("info", class_info, info_command, _("\ | |
1bedd215 | 2737 | Generic command for showing things about the program being debugged."), |
3947f654 SM |
2738 | &infolist, 0, &cmdlist); |
2739 | add_com_alias ("i", info_cmd, class_info, 1); | |
2740 | add_com_alias ("inf", info_cmd, class_info, 1); | |
d318976c FN |
2741 | |
2742 | add_com ("complete", class_obscure, complete_command, | |
1bedd215 | 2743 | _("List the completions for the rest of the line as a command.")); |
d318976c | 2744 | |
a7b9ceb8 | 2745 | c = add_show_prefix_cmd ("show", class_info, _("\ |
700b53b1 | 2746 | Generic command for showing things about the debugger."), |
2f822da5 | 2747 | &showlist, 0, &cmdlist); |
d318976c | 2748 | /* Another way to get at the same thing. */ |
a7b9ceb8 | 2749 | add_alias_cmd ("set", c, class_info, 0, &infolist); |
d318976c | 2750 | |
3947f654 SM |
2751 | cmd_list_element *with_cmd |
2752 | = add_com ("with", class_vars, with_command, _("\ | |
fdbc9870 PA |
2753 | Temporarily set SETTING to VALUE, run COMMAND, and restore SETTING.\n\ |
2754 | Usage: with SETTING [VALUE] [-- COMMAND]\n\ | |
2755 | Usage: w SETTING [VALUE] [-- COMMAND]\n\ | |
2756 | With no COMMAND, repeats the last executed command.\n\ | |
2757 | \n\ | |
2758 | SETTING is any setting you can change with the \"set\" subcommands.\n\ | |
2759 | E.g.:\n\ | |
2760 | with language pascal -- print obj\n\ | |
2761 | with print elements unlimited -- print obj\n\ | |
2762 | \n\ | |
2763 | You can change multiple settings using nested with, and use\n\ | |
2764 | abbreviations for commands and/or values. E.g.:\n\ | |
2765 | w la p -- w p el u -- p obj")); | |
3947f654 SM |
2766 | set_cmd_completer_handle_brkchars (with_cmd, with_command_completer); |
2767 | add_com_alias ("w", with_cmd, class_vars, 1); | |
fdbc9870 | 2768 | |
9ad9b77d PW |
2769 | add_internal_function ("_gdb_setting_str", _("\ |
2770 | $_gdb_setting_str - returns the value of a GDB setting as a string.\n\ | |
2771 | Usage: $_gdb_setting_str (setting)\n\ | |
2772 | \n\ | |
2773 | auto-boolean values are \"off\", \"on\", \"auto\".\n\ | |
2774 | boolean values are \"off\", \"on\".\n\ | |
2775 | Some integer settings accept an unlimited value, returned\n\ | |
2776 | as \"unlimited\"."), | |
2777 | gdb_setting_str_internal_fn, NULL); | |
2778 | ||
2779 | add_internal_function ("_gdb_setting", _("\ | |
2780 | $_gdb_setting - returns the value of a GDB setting.\n\ | |
2781 | Usage: $_gdb_setting (setting)\n\ | |
2782 | auto-boolean values are \"off\", \"on\", \"auto\".\n\ | |
2783 | boolean values are \"off\", \"on\".\n\ | |
2784 | Some integer settings accept an unlimited value, returned\n\ | |
2785 | as 0 or -1 depending on the setting."), | |
2786 | gdb_setting_internal_fn, NULL); | |
2787 | ||
2788 | add_internal_function ("_gdb_maint_setting_str", _("\ | |
fc55e99a | 2789 | $_gdb_maint_setting_str - returns the value of a GDB maintenance setting.\n\ |
9ad9b77d PW |
2790 | Usage: $_gdb_maint_setting_str (setting)\n\ |
2791 | \n\ | |
fc55e99a | 2792 | Like \"$_gdb_maint_setting\", but the return value is always a string.\n\ |
9ad9b77d PW |
2793 | auto-boolean values are \"off\", \"on\", \"auto\".\n\ |
2794 | boolean values are \"off\", \"on\".\n\ | |
2795 | Some integer settings accept an unlimited value, returned\n\ | |
2796 | as \"unlimited\"."), | |
2797 | gdb_maint_setting_str_internal_fn, NULL); | |
2798 | ||
2799 | add_internal_function ("_gdb_maint_setting", _("\ | |
2800 | $_gdb_maint_setting - returns the value of a GDB maintenance setting.\n\ | |
2801 | Usage: $_gdb_maint_setting (setting)\n\ | |
2802 | auto-boolean values are \"off\", \"on\", \"auto\".\n\ | |
2803 | boolean values are \"off\", \"on\".\n\ | |
2804 | Some integer settings accept an unlimited value, returned\n\ | |
2805 | as 0 or -1 depending on the setting."), | |
2806 | gdb_maint_setting_internal_fn, NULL); | |
2807 | ||
91265a7d PA |
2808 | add_internal_function ("_shell", _("\ |
2809 | $_shell - execute a shell command and return the result.\n\ | |
2810 | \n\ | |
2811 | Usage: $_shell (COMMAND)\n\ | |
2812 | \n\ | |
2813 | Arguments:\n\ | |
2814 | \n\ | |
2815 | COMMAND: The command to execute. Must be a string.\n\ | |
2816 | \n\ | |
2817 | Returns:\n\ | |
2818 | The command's exit code: zero on success, non-zero otherwise."), | |
2819 | shell_internal_fn, NULL); | |
2820 | ||
db5f229b | 2821 | add_cmd ("commands", no_set_class, show_commands, _("\ |
1a966eab | 2822 | Show the history of commands you typed.\n\ |
d318976c | 2823 | You can supply a command number to start with, or a `+' to start after\n\ |
1a966eab | 2824 | the previous command number shown."), |
d318976c FN |
2825 | &showlist); |
2826 | ||
db5f229b | 2827 | add_cmd ("version", no_set_class, show_version, |
1a966eab | 2828 | _("Show what version of GDB this is."), &showlist); |
d318976c | 2829 | |
6eaaf48b EZ |
2830 | add_cmd ("configuration", no_set_class, show_configuration, |
2831 | _("Show how GDB was configured at build time."), &showlist); | |
2832 | ||
f54bdb6d SM |
2833 | add_setshow_prefix_cmd ("debug", no_class, |
2834 | _("Generic command for setting gdb debugging flags."), | |
2835 | _("Generic command for showing gdb debugging flags."), | |
2836 | &setdebuglist, &showdebuglist, | |
2837 | &setlist, &showlist); | |
d318976c | 2838 | |
3947f654 SM |
2839 | cmd_list_element *shell_cmd |
2840 | = add_com ("shell", class_support, shell_command, _("\ | |
1bedd215 AC |
2841 | Execute the rest of the line as a shell command.\n\ |
2842 | With no arguments, run an inferior shell.")); | |
036e5c0c | 2843 | set_cmd_completer_handle_brkchars (shell_cmd, shell_command_completer); |
d318976c | 2844 | |
3947f654 | 2845 | add_com_alias ("!", shell_cmd, class_support, 0); |
d563b953 | 2846 | |
1bedd215 AC |
2847 | c = add_com ("edit", class_files, edit_command, _("\ |
2848 | Edit specified file or function.\n\ | |
0378c332 | 2849 | With no argument, edits file containing most recent line listed.\n\ |
0378c332 FN |
2850 | Editing targets can be specified in these ways:\n\ |
2851 | FILE:LINENUM, to edit at that line in that file,\n\ | |
2852 | FUNCTION, to edit at the beginning of that function,\n\ | |
2853 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
2854 | *ADDRESS, to edit at the line containing that address.\n\ | |
1bedd215 | 2855 | Uses EDITOR environment variable contents as editor (or ex as default).")); |
0378c332 FN |
2856 | |
2857 | c->completer = location_completer; | |
2858 | ||
3947f654 SM |
2859 | cmd_list_element *pipe_cmd |
2860 | = add_com ("pipe", class_support, pipe_command, _("\ | |
947d3946 PW |
2861 | Send the output of a gdb command to a shell command.\n\ |
2862 | Usage: | [COMMAND] | SHELL_COMMAND\n\ | |
2863 | Usage: | -d DELIM COMMAND DELIM SHELL_COMMAND\n\ | |
2864 | Usage: pipe [COMMAND] | SHELL_COMMAND\n\ | |
2865 | Usage: pipe -d DELIM COMMAND DELIM SHELL_COMMAND\n\ | |
2866 | \n\ | |
2867 | Executes COMMAND and sends its output to SHELL_COMMAND.\n\ | |
2868 | \n\ | |
2869 | The -d option indicates to use the string DELIM to separate COMMAND\n\ | |
2870 | from SHELL_COMMAND, in alternative to |. This is useful in\n\ | |
2871 | case COMMAND contains a | character.\n\ | |
2872 | \n\ | |
2873 | With no COMMAND, repeat the last executed command\n\ | |
2874 | and send its output to SHELL_COMMAND.")); | |
3947f654 SM |
2875 | set_cmd_completer_handle_brkchars (pipe_cmd, pipe_command_completer); |
2876 | add_com_alias ("|", pipe_cmd, class_support, 0); | |
947d3946 | 2877 | |
3947f654 SM |
2878 | cmd_list_element *list_cmd |
2879 | = add_com ("list", class_files, list_command, _("\ | |
1bedd215 | 2880 | List specified function or line.\n\ |
0378c332 | 2881 | With no argument, lists ten more lines after or around previous listing.\n\ |
a4e5901b | 2882 | \"list +\" lists the ten lines following a previous ten-line listing.\n\ |
0378c332 | 2883 | \"list -\" lists the ten lines before a previous ten-line listing.\n\ |
12f567bc | 2884 | \"list .\" lists ten lines around the point of execution in the current frame.\n\ |
0378c332 FN |
2885 | One argument specifies a line, and ten lines are listed around that line.\n\ |
2886 | Two arguments with comma between specify starting and ending lines to list.\n\ | |
0378c332 FN |
2887 | Lines can be specified in these ways:\n\ |
2888 | LINENUM, to list around that line in current file,\n\ | |
2889 | FILE:LINENUM, to list around that line in that file,\n\ | |
2890 | FUNCTION, to list around beginning of that function,\n\ | |
2891 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
2892 | *ADDRESS, to list around the line containing that address.\n\ | |
4fdd372d AB |
2893 | With two args, if one is empty, it stands for ten lines away from\n\ |
2894 | the other arg.\n\ | |
2895 | \n\ | |
2896 | By default, when a single location is given, display ten lines.\n\ | |
2897 | This can be changed using \"set listsize\", and the current value\n\ | |
2898 | can be shown using \"show listsize\".")); | |
0378c332 | 2899 | |
3947f654 | 2900 | add_com_alias ("l", list_cmd, class_files, 1); |
0378c332 | 2901 | |
1bedd215 AC |
2902 | c = add_com ("disassemble", class_vars, disassemble_command, _("\ |
2903 | Disassemble a specified section of memory.\n\ | |
16f3242c | 2904 | Usage: disassemble[/m|/r|/s] START [, END]\n\ |
83c31e7d | 2905 | Default is the function surrounding the pc of the selected frame.\n\ |
6ff0ba5f | 2906 | \n\ |
16f3242c TT |
2907 | With a /s modifier, source lines are included (if available).\n\ |
2908 | In this mode, the output is displayed in PC address order, and\n\ | |
2909 | file names and contents for all relevant source files are displayed.\n\ | |
2910 | \n\ | |
d14508fe | 2911 | With a /m modifier, source lines are included (if available).\n\ |
6ff0ba5f DE |
2912 | This view is \"source centric\": the output is in source line order,\n\ |
2913 | regardless of any optimization that is present. Only the main source file\n\ | |
2914 | is displayed, not those of, e.g., any inlined functions.\n\ | |
2915 | This modifier hasn't proved useful in practice and is deprecated\n\ | |
2916 | in favor of /s.\n\ | |
2917 | \n\ | |
e6158f16 | 2918 | With a /r modifier, raw instructions in hex are included.\n\ |
6ff0ba5f | 2919 | \n\ |
83c31e7d | 2920 | With a single argument, the function surrounding that address is dumped.\n\ |
53a71c06 | 2921 | Two arguments (separated by a comma) are taken as a range of memory to dump,\n\ |
7e1e0340 DE |
2922 | in the form of \"start,end\", or \"start,+length\".\n\ |
2923 | \n\ | |
2924 | Note that the address is interpreted as an expression, not as a location\n\ | |
2925 | like in the \"break\" command.\n\ | |
2926 | So, for example, if you want to disassemble function bar in file foo.c\n\ | |
2927 | you must type \"disassemble 'foo.c'::bar\" and not \"disassemble foo.c:bar\".")); | |
b20885b0 | 2928 | set_cmd_completer_handle_brkchars (c, disassemble_command_completer); |
0378c332 | 2929 | |
1bedd215 AC |
2930 | c = add_com ("make", class_support, make_command, _("\ |
2931 | Run the ``make'' program using the rest of the line as arguments.")); | |
dc22ab49 AB |
2932 | set_cmd_completer (c, deprecated_filename_completer); |
2933 | ||
cc81bc2d | 2934 | c = add_cmd ("user", no_class, show_user, _("\ |
ed3ef339 | 2935 | Show definitions of non-python/scheme user defined commands.\n\ |
d318976c | 2936 | Argument is the name of the user defined command.\n\ |
1a966eab | 2937 | With no argument, show definitions of all user defined commands."), &showlist); |
cc81bc2d | 2938 | set_cmd_completer (c, show_user_completer); |
66d8c862 | 2939 | add_com ("apropos", class_support, apropos_command, _("\ |
590042fc | 2940 | Search for commands matching a REGEXP.\n\ |
66d8c862 PW |
2941 | Usage: apropos [-v] REGEXP\n\ |
2942 | Flag -v indicates to produce a verbose output, showing full documentation\n\ | |
2943 | of the matching commands.")); | |
20f01a46 | 2944 | |
883b9c6c | 2945 | add_setshow_uinteger_cmd ("max-user-call-depth", no_class, |
c0d88b1b | 2946 | &max_user_call_depth, _("\ |
ed3ef339 DE |
2947 | Set the max call depth for non-python/scheme user-defined commands."), _("\ |
2948 | Show the max call depth for non-python/scheme user-defined commands."), NULL, | |
883b9c6c YQ |
2949 | NULL, |
2950 | show_max_user_call_depth, | |
2951 | &setlist, &showlist); | |
16026cd7 AS |
2952 | |
2953 | add_setshow_boolean_cmd ("trace-commands", no_class, &trace_commands, _("\ | |
2954 | Set tracing of GDB CLI commands."), _("\ | |
2955 | Show state of GDB CLI command tracing."), _("\ | |
2956 | When 'on', each command is displayed as it is executed."), | |
2957 | NULL, | |
2958 | NULL, | |
2959 | &setlist, &showlist); | |
5a56e9c5 | 2960 | |
cf00cd6f PW |
2961 | const auto alias_opts = make_alias_options_def_group (nullptr); |
2962 | ||
2963 | static std::string alias_help | |
2964 | = gdb::option::build_help (_("\ | |
5a56e9c5 | 2965 | Define a new command that is an alias of an existing command.\n\ |
cf00cd6f | 2966 | Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]\n\ |
5a56e9c5 DE |
2967 | ALIAS is the name of the alias command to create.\n\ |
2968 | COMMAND is the command being aliased to.\n\ | |
cf00cd6f PW |
2969 | \n\ |
2970 | Options:\n\ | |
2971 | %OPTIONS%\n\ | |
2972 | \n\ | |
2973 | GDB will automatically prepend the provided DEFAULT-ARGS to the list\n\ | |
2974 | of arguments explicitly provided when using ALIAS.\n\ | |
2975 | Use \"help aliases\" to list all user defined aliases and their default args.\n\ | |
5a56e9c5 DE |
2976 | \n\ |
2977 | Examples:\n\ | |
2978 | Make \"spe\" an alias of \"set print elements\":\n\ | |
e0c45ded | 2979 | alias spe = set print elements\n\ |
5a56e9c5 | 2980 | Make \"elms\" an alias of \"elements\" in the \"set print\" command:\n\ |
e0c45ded | 2981 | alias -a set print elms = set print elements\n\ |
cf00cd6f PW |
2982 | Make \"btf\" an alias of \"backtrace -full -past-entry -past-main\" :\n\ |
2983 | alias btf = backtrace -full -past-entry -past-main\n\ | |
2984 | Make \"wLapPeu\" an alias of 2 nested \"with\":\n\ | |
2985 | alias wLapPeu = with language pascal -- with print elements unlimited --"), | |
2986 | alias_opts); | |
2987 | ||
2988 | c = add_com ("alias", class_support, alias_command, | |
2989 | alias_help.c_str ()); | |
2990 | ||
2991 | set_cmd_completer_handle_brkchars (c, alias_command_completer); | |
43e4916f | 2992 | |
61fb7376 TBA |
2993 | add_setshow_boolean_cmd ("suppress-cli-notifications", no_class, |
2994 | &user_wants_cli_suppress_notification, | |
2995 | _("\ | |
2996 | Set whether printing notifications on CLI is suppressed."), _("\ | |
2997 | Show whether printing notifications on CLI is suppressed."), _("\ | |
2998 | When on, printing notifications (such as inferior/thread switch)\n\ | |
2999 | on CLI is suppressed."), | |
3000 | set_suppress_cli_notifications, | |
3001 | show_suppress_cli_notifications, | |
3002 | &setlist, | |
3003 | &showlist); | |
3004 | ||
b777eb6d | 3005 | const char *source_help_text = xstrprintf (_("\ |
43e4916f TT |
3006 | Read commands from a file named FILE.\n\ |
3007 | \n\ | |
3008 | Usage: source [-s] [-v] FILE\n\ | |
3009 | -s: search for the script in the source search path,\n\ | |
3010 | even if FILE contains directories.\n\ | |
3011 | -v: each command in FILE is echoed as it is executed.\n\ | |
3012 | \n\ | |
3013 | Note that the file \"%s\" is read automatically in this way\n\ | |
8579fd13 | 3014 | when GDB is started."), GDBINIT).release (); |
43e4916f TT |
3015 | c = add_cmd ("source", class_support, source_command, |
3016 | source_help_text, &cmdlist); | |
dc22ab49 | 3017 | set_cmd_completer (c, deprecated_filename_completer); |
43e4916f | 3018 | } |