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