198944Sobrien/* GDB CLI commands. 298944Sobrien 3130803Smarcel Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 498944Sobrien 598944Sobrien This file is part of GDB. 698944Sobrien 798944Sobrien This program is free software; you can redistribute it and/or modify 898944Sobrien it under the terms of the GNU General Public License as published by 998944Sobrien the Free Software Foundation; either version 2 of the License, or 1098944Sobrien (at your option) any later version. 1198944Sobrien 1298944Sobrien This program is distributed in the hope that it will be useful, 1398944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1498944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1598944Sobrien GNU General Public License for more details. 1698944Sobrien 1798944Sobrien You should have received a copy of the GNU General Public License 1898944Sobrien along with this program; if not, write to the Free Software 1998944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2098944Sobrien Boston, MA 02111-1307, USA. */ 2198944Sobrien 2298944Sobrien#include "defs.h" 23130803Smarcel#include "readline/readline.h" 24130803Smarcel#include "readline/tilde.h" 2598944Sobrien#include "completer.h" 2698944Sobrien#include "target.h" /* For baud_rate, remote_debug and remote_timeout */ 2798944Sobrien#include "gdb_wait.h" /* For shell escape implementation */ 2898944Sobrien#include "gdb_regex.h" /* Used by apropos_command */ 29130803Smarcel#include "gdb_string.h" 30130803Smarcel#include "gdb_vfork.h" 31130803Smarcel#include "linespec.h" 32130803Smarcel#include "expression.h" 33130803Smarcel#include "frame.h" 34130803Smarcel#include "value.h" 35130803Smarcel#include "language.h" 3698944Sobrien#include "filenames.h" /* for DOSish file names */ 37130803Smarcel#include "objfiles.h" 38130803Smarcel#include "source.h" 39130803Smarcel#include "disasm.h" 4098944Sobrien 4198944Sobrien#include "ui-out.h" 4298944Sobrien 4398944Sobrien#include "top.h" 4498944Sobrien#include "cli/cli-decode.h" 4598944Sobrien#include "cli/cli-script.h" 4698944Sobrien#include "cli/cli-setshow.h" 4798944Sobrien#include "cli/cli-cmds.h" 4898944Sobrien 49130803Smarcel#ifdef TUI 50130803Smarcel#include "tui/tui.h" /* For tui_active et.al. */ 51130803Smarcel#endif 52130803Smarcel 5398944Sobrien#ifndef GDBINIT_FILENAME 5498944Sobrien#define GDBINIT_FILENAME ".gdbinit" 5598944Sobrien#endif 5698944Sobrien 57130803Smarcel/* Prototypes for local command functions */ 5898944Sobrien 5998944Sobrienstatic void complete_command (char *, int); 6098944Sobrien 6198944Sobrienstatic void echo_command (char *, int); 6298944Sobrien 6398944Sobrienstatic void pwd_command (char *, int); 6498944Sobrien 6598944Sobrienstatic void show_version (char *, int); 6698944Sobrien 6798944Sobrienstatic void help_command (char *, int); 6898944Sobrien 6998944Sobrienstatic void show_command (char *, int); 7098944Sobrien 7198944Sobrienstatic void info_command (char *, int); 7298944Sobrien 7398944Sobrienstatic void show_debug (char *, int); 7498944Sobrien 7598944Sobrienstatic void set_debug (char *, int); 7698944Sobrien 7798944Sobrienstatic void show_user (char *, int); 7898944Sobrien 7998944Sobrienstatic void make_command (char *, int); 8098944Sobrien 8198944Sobrienstatic void shell_escape (char *, int); 8298944Sobrien 83130803Smarcelstatic void edit_command (char *, int); 84130803Smarcel 85130803Smarcelstatic void list_command (char *, int); 86130803Smarcel 8798944Sobrienvoid apropos_command (char *, int); 88130803Smarcel 89130803Smarcel/* Prototypes for local utility functions */ 90130803Smarcel 91130803Smarcelstatic void ambiguous_line_spec (struct symtabs_and_lines *); 9298944Sobrien 93130803Smarcel/* Limit the call depth of user-defined commands */ 94130803Smarcelint max_user_call_depth; 95130803Smarcel 9698944Sobrien/* Define all cmd_list_elements. */ 9798944Sobrien 9898944Sobrien/* Chain containing all defined commands. */ 9998944Sobrien 10098944Sobrienstruct cmd_list_element *cmdlist; 10198944Sobrien 10298944Sobrien/* Chain containing all defined info subcommands. */ 10398944Sobrien 10498944Sobrienstruct cmd_list_element *infolist; 10598944Sobrien 10698944Sobrien/* Chain containing all defined enable subcommands. */ 10798944Sobrien 10898944Sobrienstruct cmd_list_element *enablelist; 10998944Sobrien 11098944Sobrien/* Chain containing all defined disable subcommands. */ 11198944Sobrien 11298944Sobrienstruct cmd_list_element *disablelist; 11398944Sobrien 11498944Sobrien/* Chain containing all defined toggle subcommands. */ 11598944Sobrien 11698944Sobrienstruct cmd_list_element *togglelist; 11798944Sobrien 11898944Sobrien/* Chain containing all defined stop subcommands. */ 11998944Sobrien 12098944Sobrienstruct cmd_list_element *stoplist; 12198944Sobrien 12298944Sobrien/* Chain containing all defined delete subcommands. */ 12398944Sobrien 12498944Sobrienstruct cmd_list_element *deletelist; 12598944Sobrien 12698944Sobrien/* Chain containing all defined "enable breakpoint" subcommands. */ 12798944Sobrien 12898944Sobrienstruct cmd_list_element *enablebreaklist; 12998944Sobrien 13098944Sobrien/* Chain containing all defined set subcommands */ 13198944Sobrien 13298944Sobrienstruct cmd_list_element *setlist; 13398944Sobrien 13498944Sobrien/* Chain containing all defined unset subcommands */ 13598944Sobrien 13698944Sobrienstruct cmd_list_element *unsetlist; 13798944Sobrien 13898944Sobrien/* Chain containing all defined show subcommands. */ 13998944Sobrien 14098944Sobrienstruct cmd_list_element *showlist; 14198944Sobrien 14298944Sobrien/* Chain containing all defined \"set history\". */ 14398944Sobrien 14498944Sobrienstruct cmd_list_element *sethistlist; 14598944Sobrien 14698944Sobrien/* Chain containing all defined \"show history\". */ 14798944Sobrien 14898944Sobrienstruct cmd_list_element *showhistlist; 14998944Sobrien 15098944Sobrien/* Chain containing all defined \"unset history\". */ 15198944Sobrien 15298944Sobrienstruct cmd_list_element *unsethistlist; 15398944Sobrien 15498944Sobrien/* Chain containing all defined maintenance subcommands. */ 15598944Sobrien 15698944Sobrienstruct cmd_list_element *maintenancelist; 15798944Sobrien 15898944Sobrien/* Chain containing all defined "maintenance info" subcommands. */ 15998944Sobrien 16098944Sobrienstruct cmd_list_element *maintenanceinfolist; 16198944Sobrien 16298944Sobrien/* Chain containing all defined "maintenance print" subcommands. */ 16398944Sobrien 16498944Sobrienstruct cmd_list_element *maintenanceprintlist; 16598944Sobrien 16698944Sobrienstruct cmd_list_element *setprintlist; 16798944Sobrien 16898944Sobrienstruct cmd_list_element *showprintlist; 16998944Sobrien 17098944Sobrienstruct cmd_list_element *setdebuglist; 17198944Sobrien 17298944Sobrienstruct cmd_list_element *showdebuglist; 17398944Sobrien 17498944Sobrienstruct cmd_list_element *setchecklist; 17598944Sobrien 17698944Sobrienstruct cmd_list_element *showchecklist; 17798944Sobrien 17898944Sobrien/* Utility used everywhere when at least one argument is needed and 17998944Sobrien none is supplied. */ 18098944Sobrien 18198944Sobrienvoid 18298944Sobrienerror_no_arg (char *why) 18398944Sobrien{ 18498944Sobrien error ("Argument required (%s).", why); 18598944Sobrien} 18698944Sobrien 18798944Sobrien/* The "info" command is defined as a prefix, with allow_unknown = 0. 18898944Sobrien Therefore, its own definition is called only for "info" with no args. */ 18998944Sobrien 19098944Sobrienstatic void 19198944Sobrieninfo_command (char *arg, int from_tty) 19298944Sobrien{ 19398944Sobrien printf_unfiltered ("\"info\" must be followed by the name of an info command.\n"); 19498944Sobrien help_list (infolist, "info ", -1, gdb_stdout); 19598944Sobrien} 19698944Sobrien 19798944Sobrien/* The "show" command with no arguments shows all the settings. */ 19898944Sobrien 19998944Sobrienstatic void 20098944Sobrienshow_command (char *arg, int from_tty) 20198944Sobrien{ 20298944Sobrien cmd_show_list (showlist, from_tty, ""); 20398944Sobrien} 20498944Sobrien 20598944Sobrien/* Provide documentation on command or list given by COMMAND. FROM_TTY 20698944Sobrien is ignored. */ 20798944Sobrien 20898944Sobrienstatic void 20998944Sobrienhelp_command (char *command, int from_tty) 21098944Sobrien{ 21198944Sobrien help_cmd (command, gdb_stdout); 21298944Sobrien} 21398944Sobrien 21498944Sobrien/* String compare function for qsort. */ 21598944Sobrienstatic int 21698944Sobriencompare_strings (const void *arg1, const void *arg2) 21798944Sobrien{ 21898944Sobrien const char **s1 = (const char **) arg1; 21998944Sobrien const char **s2 = (const char **) arg2; 22098944Sobrien return strcmp (*s1, *s2); 22198944Sobrien} 22298944Sobrien 22398944Sobrien/* The "complete" command is used by Emacs to implement completion. */ 22498944Sobrien 22598944Sobrienstatic void 22698944Sobriencomplete_command (char *arg, int from_tty) 22798944Sobrien{ 22898944Sobrien int i; 22998944Sobrien int argpoint; 230130803Smarcel char **completions, *point, *arg_prefix; 23198944Sobrien 23298944Sobrien dont_repeat (); 23398944Sobrien 23498944Sobrien if (arg == NULL) 23598944Sobrien arg = ""; 23698944Sobrien argpoint = strlen (arg); 23798944Sobrien 238130803Smarcel /* complete_line assumes that its first argument is somewhere within, 239130803Smarcel and except for filenames at the beginning of, the word to be completed. 240130803Smarcel The following crude imitation of readline's word-breaking tries to 241130803Smarcel accomodate this. */ 242130803Smarcel point = arg + argpoint; 243130803Smarcel while (point > arg) 244130803Smarcel { 245130803Smarcel if (strchr (rl_completer_word_break_characters, point[-1]) != 0) 246130803Smarcel break; 247130803Smarcel point--; 248130803Smarcel } 24998944Sobrien 250130803Smarcel arg_prefix = alloca (point - arg + 1); 251130803Smarcel memcpy (arg_prefix, arg, point - arg); 252130803Smarcel arg_prefix[point - arg] = 0; 253130803Smarcel 254130803Smarcel completions = complete_line (point, arg, argpoint); 255130803Smarcel 25698944Sobrien if (completions) 25798944Sobrien { 25898944Sobrien int item, size; 25998944Sobrien 26098944Sobrien for (size = 0; completions[size]; ++size) 26198944Sobrien ; 26298944Sobrien qsort (completions, size, sizeof (char *), compare_strings); 26398944Sobrien 26498944Sobrien /* We do extra processing here since we only want to print each 26598944Sobrien unique item once. */ 26698944Sobrien item = 0; 26798944Sobrien while (item < size) 26898944Sobrien { 26998944Sobrien int next_item; 270130803Smarcel printf_unfiltered ("%s%s\n", arg_prefix, completions[item]); 27198944Sobrien next_item = item + 1; 27298944Sobrien while (next_item < size 27398944Sobrien && ! strcmp (completions[item], completions[next_item])) 27498944Sobrien { 27598944Sobrien xfree (completions[next_item]); 27698944Sobrien ++next_item; 27798944Sobrien } 27898944Sobrien 27998944Sobrien xfree (completions[item]); 28098944Sobrien item = next_item; 28198944Sobrien } 28298944Sobrien 28398944Sobrien xfree (completions); 28498944Sobrien } 28598944Sobrien} 28698944Sobrien 28798944Sobrienint 28898944Sobrienis_complete_command (struct cmd_list_element *c) 28998944Sobrien{ 29098944Sobrien return cmd_cfunc_eq (c, complete_command); 29198944Sobrien} 29298944Sobrien 29398944Sobrienstatic void 29498944Sobrienshow_version (char *args, int from_tty) 29598944Sobrien{ 29698944Sobrien immediate_quit++; 29798944Sobrien print_gdb_version (gdb_stdout); 29898944Sobrien printf_filtered ("\n"); 29998944Sobrien immediate_quit--; 30098944Sobrien} 30198944Sobrien 30298944Sobrien/* Handle the quit command. */ 30398944Sobrien 30498944Sobrienvoid 30598944Sobrienquit_command (char *args, int from_tty) 30698944Sobrien{ 30798944Sobrien if (!quit_confirm ()) 30898944Sobrien error ("Not confirmed."); 30998944Sobrien quit_force (args, from_tty); 31098944Sobrien} 31198944Sobrien 31298944Sobrienstatic void 31398944Sobrienpwd_command (char *args, int from_tty) 31498944Sobrien{ 31598944Sobrien if (args) 31698944Sobrien error ("The \"pwd\" command does not take an argument: %s", args); 31798944Sobrien getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); 31898944Sobrien 319130803Smarcel if (strcmp (gdb_dirbuf, current_directory) != 0) 32098944Sobrien printf_unfiltered ("Working directory %s\n (canonically %s).\n", 32198944Sobrien current_directory, gdb_dirbuf); 32298944Sobrien else 32398944Sobrien printf_unfiltered ("Working directory %s.\n", current_directory); 32498944Sobrien} 32598944Sobrien 32698944Sobrienvoid 32798944Sobriencd_command (char *dir, int from_tty) 32898944Sobrien{ 32998944Sobrien int len; 33098944Sobrien /* Found something other than leading repetitions of "/..". */ 33198944Sobrien int found_real_path; 33298944Sobrien char *p; 33398944Sobrien 33498944Sobrien /* If the new directory is absolute, repeat is a no-op; if relative, 33598944Sobrien repeat might be useful but is more likely to be a mistake. */ 33698944Sobrien dont_repeat (); 33798944Sobrien 33898944Sobrien if (dir == 0) 33998944Sobrien error_no_arg ("new working directory"); 34098944Sobrien 34198944Sobrien dir = tilde_expand (dir); 34298944Sobrien make_cleanup (xfree, dir); 34398944Sobrien 34498944Sobrien if (chdir (dir) < 0) 34598944Sobrien perror_with_name (dir); 34698944Sobrien 34798944Sobrien#ifdef HAVE_DOS_BASED_FILE_SYSTEM 34898944Sobrien /* There's too much mess with DOSish names like "d:", "d:.", 34998944Sobrien "d:./foo" etc. Instead of having lots of special #ifdef'ed code, 35098944Sobrien simply get the canonicalized name of the current directory. */ 35198944Sobrien dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); 35298944Sobrien#endif 35398944Sobrien 35498944Sobrien len = strlen (dir); 35598944Sobrien if (IS_DIR_SEPARATOR (dir[len - 1])) 35698944Sobrien { 35798944Sobrien /* Remove the trailing slash unless this is a root directory 35898944Sobrien (including a drive letter on non-Unix systems). */ 35998944Sobrien if (!(len == 1) /* "/" */ 36098944Sobrien#ifdef HAVE_DOS_BASED_FILE_SYSTEM 36198944Sobrien && !(len == 3 && dir[1] == ':') /* "d:/" */ 36298944Sobrien#endif 36398944Sobrien ) 36498944Sobrien len--; 36598944Sobrien } 36698944Sobrien 36798944Sobrien dir = savestring (dir, len); 36898944Sobrien if (IS_ABSOLUTE_PATH (dir)) 36998944Sobrien current_directory = dir; 37098944Sobrien else 37198944Sobrien { 37298944Sobrien if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])) 37398944Sobrien current_directory = concat (current_directory, dir, NULL); 37498944Sobrien else 37598944Sobrien current_directory = concat (current_directory, SLASH_STRING, dir, NULL); 37698944Sobrien xfree (dir); 37798944Sobrien } 37898944Sobrien 37998944Sobrien /* Now simplify any occurrences of `.' and `..' in the pathname. */ 38098944Sobrien 38198944Sobrien found_real_path = 0; 38298944Sobrien for (p = current_directory; *p;) 38398944Sobrien { 38498944Sobrien if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' 38598944Sobrien && (p[2] == 0 || IS_DIR_SEPARATOR (p[2]))) 38698944Sobrien strcpy (p, p + 2); 38798944Sobrien else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.' 38898944Sobrien && (p[3] == 0 || IS_DIR_SEPARATOR (p[3]))) 38998944Sobrien { 39098944Sobrien if (found_real_path) 39198944Sobrien { 39298944Sobrien /* Search backwards for the directory just before the "/.." 39398944Sobrien and obliterate it and the "/..". */ 39498944Sobrien char *q = p; 39598944Sobrien while (q != current_directory && !IS_DIR_SEPARATOR (q[-1])) 39698944Sobrien --q; 39798944Sobrien 39898944Sobrien if (q == current_directory) 39998944Sobrien /* current_directory is 40098944Sobrien a relative pathname ("can't happen"--leave it alone). */ 40198944Sobrien ++p; 40298944Sobrien else 40398944Sobrien { 40498944Sobrien strcpy (q - 1, p + 3); 40598944Sobrien p = q - 1; 40698944Sobrien } 40798944Sobrien } 40898944Sobrien else 40998944Sobrien /* We are dealing with leading repetitions of "/..", for example 41098944Sobrien "/../..", which is the Mach super-root. */ 41198944Sobrien p += 3; 41298944Sobrien } 41398944Sobrien else 41498944Sobrien { 41598944Sobrien found_real_path = 1; 41698944Sobrien ++p; 41798944Sobrien } 41898944Sobrien } 41998944Sobrien 42098944Sobrien forget_cached_source_info (); 42198944Sobrien 42298944Sobrien if (from_tty) 42398944Sobrien pwd_command ((char *) 0, 1); 42498944Sobrien} 42598944Sobrien 42698944Sobrienvoid 42798944Sobriensource_command (char *args, int from_tty) 42898944Sobrien{ 42998944Sobrien FILE *stream; 43098944Sobrien struct cleanup *old_cleanups; 43198944Sobrien char *file = args; 43298944Sobrien 43398944Sobrien if (file == NULL) 43498944Sobrien { 43598944Sobrien error ("source command requires pathname of file to source."); 43698944Sobrien } 43798944Sobrien 43898944Sobrien file = tilde_expand (file); 43998944Sobrien old_cleanups = make_cleanup (xfree, file); 44098944Sobrien 44198944Sobrien stream = fopen (file, FOPEN_RT); 44298944Sobrien if (!stream) 44398944Sobrien { 44498944Sobrien if (from_tty) 44598944Sobrien perror_with_name (file); 44698944Sobrien else 44798944Sobrien return; 44898944Sobrien } 44998944Sobrien 45098944Sobrien script_from_file (stream, file); 45198944Sobrien 45298944Sobrien do_cleanups (old_cleanups); 45398944Sobrien} 45498944Sobrien 45598944Sobrienstatic void 45698944Sobrienecho_command (char *text, int from_tty) 45798944Sobrien{ 45898944Sobrien char *p = text; 459130803Smarcel int c; 46098944Sobrien 46198944Sobrien if (text) 46298944Sobrien while ((c = *p++) != '\0') 46398944Sobrien { 46498944Sobrien if (c == '\\') 46598944Sobrien { 46698944Sobrien /* \ at end of argument is used after spaces 46798944Sobrien so they won't be lost. */ 46898944Sobrien if (*p == 0) 46998944Sobrien return; 47098944Sobrien 47198944Sobrien c = parse_escape (&p); 47298944Sobrien if (c >= 0) 47398944Sobrien printf_filtered ("%c", c); 47498944Sobrien } 47598944Sobrien else 47698944Sobrien printf_filtered ("%c", c); 47798944Sobrien } 47898944Sobrien 47998944Sobrien /* Force this output to appear now. */ 48098944Sobrien wrap_here (""); 48198944Sobrien gdb_flush (gdb_stdout); 48298944Sobrien} 48398944Sobrien 48498944Sobrienstatic void 48598944Sobrienshell_escape (char *arg, int from_tty) 48698944Sobrien{ 48798944Sobrien#ifdef CANT_FORK 48898944Sobrien /* If ARG is NULL, they want an inferior shell, but `system' just 48998944Sobrien reports if the shell is available when passed a NULL arg. */ 49098944Sobrien int rc = system (arg ? arg : ""); 49198944Sobrien 49298944Sobrien if (!arg) 49398944Sobrien arg = "inferior shell"; 49498944Sobrien 49598944Sobrien if (rc == -1) 49698944Sobrien { 49798944Sobrien fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg, 49898944Sobrien safe_strerror (errno)); 49998944Sobrien gdb_flush (gdb_stderr); 50098944Sobrien } 50198944Sobrien else if (rc) 50298944Sobrien { 50398944Sobrien fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc); 50498944Sobrien gdb_flush (gdb_stderr); 50598944Sobrien } 50698944Sobrien#ifdef GLOBAL_CURDIR 50798944Sobrien /* Make sure to return to the directory GDB thinks it is, in case the 50898944Sobrien shell command we just ran changed it. */ 50998944Sobrien chdir (current_directory); 51098944Sobrien#endif 51198944Sobrien#else /* Can fork. */ 51298944Sobrien int rc, status, pid; 51398944Sobrien 514130803Smarcel if ((pid = vfork ()) == 0) 515130803Smarcel { 516130803Smarcel char *p, *user_shell; 51798944Sobrien 518130803Smarcel if ((user_shell = (char *) getenv ("SHELL")) == NULL) 519130803Smarcel user_shell = "/bin/sh"; 52098944Sobrien 521130803Smarcel /* Get the name of the shell for arg0 */ 522130803Smarcel if ((p = strrchr (user_shell, '/')) == NULL) 523130803Smarcel p = user_shell; 524130803Smarcel else 525130803Smarcel p++; /* Get past '/' */ 526130803Smarcel 52798944Sobrien if (!arg) 528130803Smarcel execl (user_shell, p, (char *) 0); 52998944Sobrien else 530130803Smarcel execl (user_shell, p, "-c", arg, (char *) 0); 53198944Sobrien 53298944Sobrien fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell, 53398944Sobrien safe_strerror (errno)); 53498944Sobrien gdb_flush (gdb_stderr); 53598944Sobrien _exit (0177); 53698944Sobrien } 53798944Sobrien 53898944Sobrien if (pid != -1) 53998944Sobrien while ((rc = wait (&status)) != pid && rc != -1) 54098944Sobrien ; 54198944Sobrien else 54298944Sobrien error ("Fork failed"); 54398944Sobrien#endif /* Can fork. */ 54498944Sobrien} 54598944Sobrien 54698944Sobrienstatic void 547130803Smarceledit_command (char *arg, int from_tty) 548130803Smarcel{ 549130803Smarcel struct symtabs_and_lines sals; 550130803Smarcel struct symtab_and_line sal; 551130803Smarcel struct symbol *sym; 552130803Smarcel char *arg1; 553130803Smarcel int cmdlen, log10; 554130803Smarcel unsigned m; 555130803Smarcel char *editor; 556130803Smarcel char *p; 557130803Smarcel 558130803Smarcel /* Pull in the current default source line if necessary */ 559130803Smarcel if (arg == 0) 560130803Smarcel { 561130803Smarcel set_default_source_symtab_and_line (); 562130803Smarcel sal = get_current_source_symtab_and_line (); 563130803Smarcel } 564130803Smarcel 565130803Smarcel /* bare "edit" edits file with present line. */ 566130803Smarcel 567130803Smarcel if (arg == 0) 568130803Smarcel { 569130803Smarcel if (sal.symtab == 0) 570130803Smarcel error ("No default source file yet."); 571130803Smarcel sal.line += get_lines_to_list () / 2; 572130803Smarcel } 573130803Smarcel else 574130803Smarcel { 575130803Smarcel 576130803Smarcel /* Now should only be one argument -- decode it in SAL */ 577130803Smarcel 578130803Smarcel arg1 = arg; 579130803Smarcel sals = decode_line_1 (&arg1, 0, 0, 0, 0, 0); 580130803Smarcel 581130803Smarcel if (! sals.nelts) return; /* C++ */ 582130803Smarcel if (sals.nelts > 1) { 583130803Smarcel ambiguous_line_spec (&sals); 584130803Smarcel xfree (sals.sals); 585130803Smarcel return; 586130803Smarcel } 587130803Smarcel 588130803Smarcel sal = sals.sals[0]; 589130803Smarcel xfree (sals.sals); 590130803Smarcel 591130803Smarcel if (*arg1) 592130803Smarcel error ("Junk at end of line specification."); 593130803Smarcel 594130803Smarcel /* if line was specified by address, 595130803Smarcel first print exactly which line, and which file. 596130803Smarcel In this case, sal.symtab == 0 means address is outside 597130803Smarcel of all known source files, not that user failed to give a filename. */ 598130803Smarcel if (*arg == '*') 599130803Smarcel { 600130803Smarcel if (sal.symtab == 0) 601130803Smarcel /* FIXME-32x64--assumes sal.pc fits in long. */ 602130803Smarcel error ("No source file for address %s.", 603130803Smarcel local_hex_string((unsigned long) sal.pc)); 604130803Smarcel sym = find_pc_function (sal.pc); 605130803Smarcel if (sym) 606130803Smarcel { 607130803Smarcel print_address_numeric (sal.pc, 1, gdb_stdout); 608130803Smarcel printf_filtered (" is in "); 609130803Smarcel fputs_filtered (SYMBOL_PRINT_NAME (sym), gdb_stdout); 610130803Smarcel printf_filtered (" (%s:%d).\n", sal.symtab->filename, sal.line); 611130803Smarcel } 612130803Smarcel else 613130803Smarcel { 614130803Smarcel print_address_numeric (sal.pc, 1, gdb_stdout); 615130803Smarcel printf_filtered (" is at %s:%d.\n", 616130803Smarcel sal.symtab->filename, sal.line); 617130803Smarcel } 618130803Smarcel } 619130803Smarcel 620130803Smarcel /* If what was given does not imply a symtab, it must be an undebuggable 621130803Smarcel symbol which means no source code. */ 622130803Smarcel 623130803Smarcel if (sal.symtab == 0) 624130803Smarcel error ("No line number known for %s.", arg); 625130803Smarcel } 626130803Smarcel 627130803Smarcel if ((editor = (char *) getenv ("EDITOR")) == NULL) 628130803Smarcel editor = "/bin/ex"; 629130803Smarcel 630130803Smarcel /* Approximate base-10 log of line to 1 unit for digit count */ 631130803Smarcel for(log10=32, m=0x80000000; !(sal.line & m) && log10>0; log10--, m=m>>1); 632130803Smarcel log10 = 1 + (int)((log10 + (0 == ((m-1) & sal.line)))/3.32192809); 633130803Smarcel 634130803Smarcel cmdlen = strlen(editor) + 1 635130803Smarcel + (NULL == sal.symtab->dirname ? 0 : strlen(sal.symtab->dirname) + 1) 636130803Smarcel + (NULL == sal.symtab->filename? 0 : strlen(sal.symtab->filename)+ 1) 637130803Smarcel + log10 + 2; 638130803Smarcel 639130803Smarcel p = xmalloc(cmdlen); 640130803Smarcel sprintf(p,"%s +%d %s%s",editor,sal.line, 641130803Smarcel (NULL == sal.symtab->dirname ? "./" : 642130803Smarcel (NULL != sal.symtab->filename && *(sal.symtab->filename) != '/') ? 643130803Smarcel sal.symtab->dirname : ""), 644130803Smarcel (NULL == sal.symtab->filename ? "unknown" : sal.symtab->filename) 645130803Smarcel ); 646130803Smarcel shell_escape(p, from_tty); 647130803Smarcel 648130803Smarcel xfree(p); 649130803Smarcel} 650130803Smarcel 651130803Smarcelstatic void 652130803Smarcellist_command (char *arg, int from_tty) 653130803Smarcel{ 654130803Smarcel struct symtabs_and_lines sals, sals_end; 655130803Smarcel struct symtab_and_line sal, sal_end, cursal; 656130803Smarcel struct symbol *sym; 657130803Smarcel char *arg1; 658130803Smarcel int no_end = 1; 659130803Smarcel int dummy_end = 0; 660130803Smarcel int dummy_beg = 0; 661130803Smarcel int linenum_beg = 0; 662130803Smarcel char *p; 663130803Smarcel 664130803Smarcel /* Pull in the current default source line if necessary */ 665130803Smarcel if (arg == 0 || arg[0] == '+' || arg[0] == '-') 666130803Smarcel { 667130803Smarcel set_default_source_symtab_and_line (); 668130803Smarcel cursal = get_current_source_symtab_and_line (); 669130803Smarcel } 670130803Smarcel 671130803Smarcel /* "l" or "l +" lists next ten lines. */ 672130803Smarcel 673130803Smarcel if (arg == 0 || strcmp (arg, "+") == 0) 674130803Smarcel { 675130803Smarcel print_source_lines (cursal.symtab, cursal.line, 676130803Smarcel cursal.line + get_lines_to_list (), 0); 677130803Smarcel return; 678130803Smarcel } 679130803Smarcel 680130803Smarcel /* "l -" lists previous ten lines, the ones before the ten just listed. */ 681130803Smarcel if (strcmp (arg, "-") == 0) 682130803Smarcel { 683130803Smarcel print_source_lines (cursal.symtab, 684130803Smarcel max (get_first_line_listed () - get_lines_to_list (), 1), 685130803Smarcel get_first_line_listed (), 0); 686130803Smarcel return; 687130803Smarcel } 688130803Smarcel 689130803Smarcel /* Now if there is only one argument, decode it in SAL 690130803Smarcel and set NO_END. 691130803Smarcel If there are two arguments, decode them in SAL and SAL_END 692130803Smarcel and clear NO_END; however, if one of the arguments is blank, 693130803Smarcel set DUMMY_BEG or DUMMY_END to record that fact. */ 694130803Smarcel 695130803Smarcel if (!have_full_symbols () && !have_partial_symbols ()) 696130803Smarcel error ("No symbol table is loaded. Use the \"file\" command."); 697130803Smarcel 698130803Smarcel arg1 = arg; 699130803Smarcel if (*arg1 == ',') 700130803Smarcel dummy_beg = 1; 701130803Smarcel else 702130803Smarcel { 703130803Smarcel sals = decode_line_1 (&arg1, 0, 0, 0, 0, 0); 704130803Smarcel 705130803Smarcel if (!sals.nelts) 706130803Smarcel return; /* C++ */ 707130803Smarcel if (sals.nelts > 1) 708130803Smarcel { 709130803Smarcel ambiguous_line_spec (&sals); 710130803Smarcel xfree (sals.sals); 711130803Smarcel return; 712130803Smarcel } 713130803Smarcel 714130803Smarcel sal = sals.sals[0]; 715130803Smarcel xfree (sals.sals); 716130803Smarcel } 717130803Smarcel 718130803Smarcel /* Record whether the BEG arg is all digits. */ 719130803Smarcel 720130803Smarcel for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++); 721130803Smarcel linenum_beg = (p == arg1); 722130803Smarcel 723130803Smarcel while (*arg1 == ' ' || *arg1 == '\t') 724130803Smarcel arg1++; 725130803Smarcel if (*arg1 == ',') 726130803Smarcel { 727130803Smarcel no_end = 0; 728130803Smarcel arg1++; 729130803Smarcel while (*arg1 == ' ' || *arg1 == '\t') 730130803Smarcel arg1++; 731130803Smarcel if (*arg1 == 0) 732130803Smarcel dummy_end = 1; 733130803Smarcel else 734130803Smarcel { 735130803Smarcel if (dummy_beg) 736130803Smarcel sals_end = decode_line_1 (&arg1, 0, 0, 0, 0, 0); 737130803Smarcel else 738130803Smarcel sals_end = decode_line_1 (&arg1, 0, sal.symtab, sal.line, 0, 0); 739130803Smarcel if (sals_end.nelts == 0) 740130803Smarcel return; 741130803Smarcel if (sals_end.nelts > 1) 742130803Smarcel { 743130803Smarcel ambiguous_line_spec (&sals_end); 744130803Smarcel xfree (sals_end.sals); 745130803Smarcel return; 746130803Smarcel } 747130803Smarcel sal_end = sals_end.sals[0]; 748130803Smarcel xfree (sals_end.sals); 749130803Smarcel } 750130803Smarcel } 751130803Smarcel 752130803Smarcel if (*arg1) 753130803Smarcel error ("Junk at end of line specification."); 754130803Smarcel 755130803Smarcel if (!no_end && !dummy_beg && !dummy_end 756130803Smarcel && sal.symtab != sal_end.symtab) 757130803Smarcel error ("Specified start and end are in different files."); 758130803Smarcel if (dummy_beg && dummy_end) 759130803Smarcel error ("Two empty args do not say what lines to list."); 760130803Smarcel 761130803Smarcel /* if line was specified by address, 762130803Smarcel first print exactly which line, and which file. 763130803Smarcel In this case, sal.symtab == 0 means address is outside 764130803Smarcel of all known source files, not that user failed to give a filename. */ 765130803Smarcel if (*arg == '*') 766130803Smarcel { 767130803Smarcel if (sal.symtab == 0) 768130803Smarcel /* FIXME-32x64--assumes sal.pc fits in long. */ 769130803Smarcel error ("No source file for address %s.", 770130803Smarcel local_hex_string ((unsigned long) sal.pc)); 771130803Smarcel sym = find_pc_function (sal.pc); 772130803Smarcel if (sym) 773130803Smarcel { 774130803Smarcel print_address_numeric (sal.pc, 1, gdb_stdout); 775130803Smarcel printf_filtered (" is in "); 776130803Smarcel fputs_filtered (SYMBOL_PRINT_NAME (sym), gdb_stdout); 777130803Smarcel printf_filtered (" (%s:%d).\n", sal.symtab->filename, sal.line); 778130803Smarcel } 779130803Smarcel else 780130803Smarcel { 781130803Smarcel print_address_numeric (sal.pc, 1, gdb_stdout); 782130803Smarcel printf_filtered (" is at %s:%d.\n", 783130803Smarcel sal.symtab->filename, sal.line); 784130803Smarcel } 785130803Smarcel } 786130803Smarcel 787130803Smarcel /* If line was not specified by just a line number, 788130803Smarcel and it does not imply a symtab, it must be an undebuggable symbol 789130803Smarcel which means no source code. */ 790130803Smarcel 791130803Smarcel if (!linenum_beg && sal.symtab == 0) 792130803Smarcel error ("No line number known for %s.", arg); 793130803Smarcel 794130803Smarcel /* If this command is repeated with RET, 795130803Smarcel turn it into the no-arg variant. */ 796130803Smarcel 797130803Smarcel if (from_tty) 798130803Smarcel *arg = 0; 799130803Smarcel 800130803Smarcel if (dummy_beg && sal_end.symtab == 0) 801130803Smarcel error ("No default source file yet. Do \"help list\"."); 802130803Smarcel if (dummy_beg) 803130803Smarcel print_source_lines (sal_end.symtab, 804130803Smarcel max (sal_end.line - (get_lines_to_list () - 1), 1), 805130803Smarcel sal_end.line + 1, 0); 806130803Smarcel else if (sal.symtab == 0) 807130803Smarcel error ("No default source file yet. Do \"help list\"."); 808130803Smarcel else if (no_end) 809130803Smarcel { 810130803Smarcel int first_line = sal.line - get_lines_to_list () / 2; 811130803Smarcel 812130803Smarcel if (first_line < 1) first_line = 1; 813130803Smarcel 814130803Smarcel print_source_lines (sal.symtab, 815130803Smarcel first_line, 816130803Smarcel first_line + get_lines_to_list (), 817130803Smarcel 0); 818130803Smarcel } 819130803Smarcel else 820130803Smarcel print_source_lines (sal.symtab, sal.line, 821130803Smarcel (dummy_end 822130803Smarcel ? sal.line + get_lines_to_list () 823130803Smarcel : sal_end.line + 1), 824130803Smarcel 0); 825130803Smarcel} 826130803Smarcel 827130803Smarcel/* Dump a specified section of assembly code. With no command line 828130803Smarcel arguments, this command will dump the assembly code for the 829130803Smarcel function surrounding the pc value in the selected frame. With one 830130803Smarcel argument, it will dump the assembly code surrounding that pc value. 831130803Smarcel Two arguments are interpeted as bounds within which to dump 832130803Smarcel assembly. */ 833130803Smarcel 834130803Smarcelstatic void 835130803Smarceldisassemble_command (char *arg, int from_tty) 836130803Smarcel{ 837130803Smarcel CORE_ADDR low, high; 838130803Smarcel char *name; 839130803Smarcel CORE_ADDR pc, pc_masked; 840130803Smarcel char *space_index; 841130803Smarcel#if 0 842130803Smarcel asection *section; 843130803Smarcel#endif 844130803Smarcel 845130803Smarcel name = NULL; 846130803Smarcel if (!arg) 847130803Smarcel { 848130803Smarcel if (!deprecated_selected_frame) 849130803Smarcel error ("No frame selected.\n"); 850130803Smarcel 851130803Smarcel pc = get_frame_pc (deprecated_selected_frame); 852130803Smarcel if (find_pc_partial_function (pc, &name, &low, &high) == 0) 853130803Smarcel error ("No function contains program counter for selected frame.\n"); 854130803Smarcel#if defined(TUI) 855130803Smarcel /* NOTE: cagney/2003-02-13 The `tui_active' was previously 856130803Smarcel `tui_version'. */ 857130803Smarcel if (tui_active) 858130803Smarcel /* FIXME: cagney/2004-02-07: This should be an observer. */ 859130803Smarcel low = tui_get_low_disassembly_address (low, pc); 860130803Smarcel#endif 861130803Smarcel low += FUNCTION_START_OFFSET; 862130803Smarcel } 863130803Smarcel else if (!(space_index = (char *) strchr (arg, ' '))) 864130803Smarcel { 865130803Smarcel /* One argument. */ 866130803Smarcel pc = parse_and_eval_address (arg); 867130803Smarcel if (find_pc_partial_function (pc, &name, &low, &high) == 0) 868130803Smarcel error ("No function contains specified address.\n"); 869130803Smarcel#if defined(TUI) 870130803Smarcel /* NOTE: cagney/2003-02-13 The `tui_active' was previously 871130803Smarcel `tui_version'. */ 872130803Smarcel if (tui_active) 873130803Smarcel /* FIXME: cagney/2004-02-07: This should be an observer. */ 874130803Smarcel low = tui_get_low_disassembly_address (low, pc); 875130803Smarcel#endif 876130803Smarcel low += FUNCTION_START_OFFSET; 877130803Smarcel } 878130803Smarcel else 879130803Smarcel { 880130803Smarcel /* Two arguments. */ 881130803Smarcel *space_index = '\0'; 882130803Smarcel low = parse_and_eval_address (arg); 883130803Smarcel high = parse_and_eval_address (space_index + 1); 884130803Smarcel } 885130803Smarcel 886130803Smarcel#if defined(TUI) 887130803Smarcel if (!tui_is_window_visible (DISASSEM_WIN)) 888130803Smarcel#endif 889130803Smarcel { 890130803Smarcel printf_filtered ("Dump of assembler code "); 891130803Smarcel if (name != NULL) 892130803Smarcel { 893130803Smarcel printf_filtered ("for function %s:\n", name); 894130803Smarcel } 895130803Smarcel else 896130803Smarcel { 897130803Smarcel printf_filtered ("from "); 898130803Smarcel print_address_numeric (low, 1, gdb_stdout); 899130803Smarcel printf_filtered (" to "); 900130803Smarcel print_address_numeric (high, 1, gdb_stdout); 901130803Smarcel printf_filtered (":\n"); 902130803Smarcel } 903130803Smarcel 904130803Smarcel /* Dump the specified range. */ 905130803Smarcel gdb_disassembly (uiout, 0, 0, 0, -1, low, high); 906130803Smarcel 907130803Smarcel printf_filtered ("End of assembler dump.\n"); 908130803Smarcel gdb_flush (gdb_stdout); 909130803Smarcel } 910130803Smarcel#if defined(TUI) 911130803Smarcel else 912130803Smarcel { 913130803Smarcel tui_show_assembly (low); 914130803Smarcel } 915130803Smarcel#endif 916130803Smarcel} 917130803Smarcel 918130803Smarcelstatic void 91998944Sobrienmake_command (char *arg, int from_tty) 92098944Sobrien{ 92198944Sobrien char *p; 92298944Sobrien 92398944Sobrien if (arg == 0) 92498944Sobrien p = "make"; 92598944Sobrien else 92698944Sobrien { 92798944Sobrien p = xmalloc (sizeof ("make ") + strlen (arg)); 92898944Sobrien strcpy (p, "make "); 92998944Sobrien strcpy (p + sizeof ("make ") - 1, arg); 93098944Sobrien } 93198944Sobrien 93298944Sobrien shell_escape (p, from_tty); 93398944Sobrien} 93498944Sobrien 93598944Sobrienstatic void 93698944Sobrienshow_user (char *args, int from_tty) 93798944Sobrien{ 93898944Sobrien struct cmd_list_element *c; 93998944Sobrien extern struct cmd_list_element *cmdlist; 94098944Sobrien 94198944Sobrien if (args) 94298944Sobrien { 94398944Sobrien c = lookup_cmd (&args, cmdlist, "", 0, 1); 94498944Sobrien if (c->class != class_user) 94598944Sobrien error ("Not a user command."); 94698944Sobrien show_user_1 (c, gdb_stdout); 94798944Sobrien } 94898944Sobrien else 94998944Sobrien { 95098944Sobrien for (c = cmdlist; c; c = c->next) 95198944Sobrien { 95298944Sobrien if (c->class == class_user) 95398944Sobrien show_user_1 (c, gdb_stdout); 95498944Sobrien } 95598944Sobrien } 95698944Sobrien} 95798944Sobrien 95898944Sobrien/* Search through names of commands and documentations for a certain 95998944Sobrien regular expression. 96098944Sobrien*/ 96198944Sobrienvoid 96298944Sobrienapropos_command (char *searchstr, int from_tty) 96398944Sobrien{ 96498944Sobrien extern struct cmd_list_element *cmdlist; /*This is the main command list*/ 96598944Sobrien regex_t pattern; 96698944Sobrien char *pattern_fastmap; 96798944Sobrien char errorbuffer[512]; 96898944Sobrien pattern_fastmap = xcalloc (256, sizeof (char)); 96998944Sobrien if (searchstr == NULL) 97098944Sobrien error("REGEXP string is empty"); 97198944Sobrien 97298944Sobrien if (regcomp(&pattern,searchstr,REG_ICASE) == 0) 97398944Sobrien { 97498944Sobrien pattern.fastmap=pattern_fastmap; 97598944Sobrien re_compile_fastmap(&pattern); 97698944Sobrien apropos_cmd (gdb_stdout,cmdlist,&pattern,""); 97798944Sobrien } 97898944Sobrien else 97998944Sobrien { 98098944Sobrien regerror(regcomp(&pattern,searchstr,REG_ICASE),NULL,errorbuffer,512); 98198944Sobrien error("Error in regular expression:%s",errorbuffer); 98298944Sobrien } 98398944Sobrien xfree (pattern_fastmap); 98498944Sobrien} 98598944Sobrien 986130803Smarcel/* Print a list of files and line numbers which a user may choose from 987130803Smarcel in order to list a function which was specified ambiguously (as with 988130803Smarcel `list classname::overloadedfuncname', for example). The vector in 989130803Smarcel SALS provides the filenames and line numbers. */ 990130803Smarcel 99198944Sobrienstatic void 992130803Smarcelambiguous_line_spec (struct symtabs_and_lines *sals) 993130803Smarcel{ 994130803Smarcel int i; 995130803Smarcel 996130803Smarcel for (i = 0; i < sals->nelts; ++i) 997130803Smarcel printf_filtered ("file: \"%s\", line number: %d\n", 998130803Smarcel sals->sals[i].symtab->filename, sals->sals[i].line); 999130803Smarcel} 1000130803Smarcel 1001130803Smarcelstatic void 100298944Sobrienset_debug (char *arg, int from_tty) 100398944Sobrien{ 100498944Sobrien printf_unfiltered ("\"set debug\" must be followed by the name of a print subcommand.\n"); 100598944Sobrien help_list (setdebuglist, "set debug ", -1, gdb_stdout); 100698944Sobrien} 100798944Sobrien 100898944Sobrienstatic void 100998944Sobrienshow_debug (char *args, int from_tty) 101098944Sobrien{ 101198944Sobrien cmd_show_list (showdebuglist, from_tty, ""); 101298944Sobrien} 101398944Sobrien 101498944Sobrienvoid 101598944Sobrieninit_cmd_lists (void) 101698944Sobrien{ 1017130803Smarcel max_user_call_depth = 1024; 1018130803Smarcel 101998944Sobrien cmdlist = NULL; 102098944Sobrien infolist = NULL; 102198944Sobrien enablelist = NULL; 102298944Sobrien disablelist = NULL; 102398944Sobrien togglelist = NULL; 102498944Sobrien stoplist = NULL; 102598944Sobrien deletelist = NULL; 102698944Sobrien enablebreaklist = NULL; 102798944Sobrien setlist = NULL; 102898944Sobrien unsetlist = NULL; 102998944Sobrien showlist = NULL; 103098944Sobrien sethistlist = NULL; 103198944Sobrien showhistlist = NULL; 103298944Sobrien unsethistlist = NULL; 103398944Sobrien maintenancelist = NULL; 103498944Sobrien maintenanceinfolist = NULL; 103598944Sobrien maintenanceprintlist = NULL; 103698944Sobrien setprintlist = NULL; 103798944Sobrien showprintlist = NULL; 103898944Sobrien setchecklist = NULL; 103998944Sobrien showchecklist = NULL; 104098944Sobrien} 104198944Sobrien 104298944Sobrien 104398944Sobrienvoid 104498944Sobrieninit_cli_cmds (void) 104598944Sobrien{ 104698944Sobrien struct cmd_list_element *c; 104798944Sobrien 104898944Sobrien /* Define the classes of commands. 104998944Sobrien They will appear in the help list in the reverse of this order. */ 105098944Sobrien 105198944Sobrien add_cmd ("internals", class_maintenance, NULL, 105298944Sobrien "Maintenance commands.\n\ 105398944SobrienSome gdb commands are provided just for use by gdb maintainers.\n\ 105498944SobrienThese commands are subject to frequent change, and may not be as\n\ 105598944Sobrienwell documented as user commands.", 105698944Sobrien &cmdlist); 105798944Sobrien add_cmd ("obscure", class_obscure, NULL, "Obscure features.", &cmdlist); 105898944Sobrien add_cmd ("aliases", class_alias, NULL, "Aliases of other commands.", &cmdlist); 105998944Sobrien add_cmd ("user-defined", class_user, NULL, "User-defined commands.\n\ 106098944SobrienThe commands in this class are those defined by the user.\n\ 106198944SobrienUse the \"define\" command to define a command.", &cmdlist); 106298944Sobrien add_cmd ("support", class_support, NULL, "Support facilities.", &cmdlist); 106398944Sobrien if (!dbx_commands) 106498944Sobrien add_cmd ("status", class_info, NULL, "Status inquiries.", &cmdlist); 106598944Sobrien add_cmd ("files", class_files, NULL, "Specifying and examining files.", &cmdlist); 106698944Sobrien add_cmd ("breakpoints", class_breakpoint, NULL, "Making program stop at certain points.", &cmdlist); 106798944Sobrien add_cmd ("data", class_vars, NULL, "Examining data.", &cmdlist); 106898944Sobrien add_cmd ("stack", class_stack, NULL, "Examining the stack.\n\ 106998944SobrienThe stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ 107098944Sobriencounting from zero for the innermost (currently executing) frame.\n\n\ 107198944SobrienAt any time gdb identifies one frame as the \"selected\" frame.\n\ 107298944SobrienVariable lookups are done with respect to the selected frame.\n\ 107398944SobrienWhen the program being debugged stops, gdb selects the innermost frame.\n\ 107498944SobrienThe commands below can be used to select other frames by number or address.", 107598944Sobrien &cmdlist); 107698944Sobrien add_cmd ("running", class_run, NULL, "Running the program.", &cmdlist); 107798944Sobrien 107898944Sobrien /* Define general commands. */ 107998944Sobrien 108098944Sobrien add_com ("pwd", class_files, pwd_command, 108198944Sobrien "Print working directory. This is used for your program as well."); 108298944Sobrien c = add_cmd ("cd", class_files, cd_command, 108398944Sobrien "Set working directory to DIR for debugger and program being debugged.\n\ 108498944SobrienThe change does not take effect for the program being debugged\n\ 108598944Sobrienuntil the next time it is started.", &cmdlist); 1086130803Smarcel set_cmd_completer (c, filename_completer); 108798944Sobrien 108898944Sobrien add_com ("echo", class_support, echo_command, 108998944Sobrien "Print a constant string. Give string as argument.\n\ 109098944SobrienC escape sequences may be used in the argument.\n\ 109198944SobrienNo newline is added at the end of the argument;\n\ 109298944Sobrienuse \"\\n\" if you want a newline to be printed.\n\ 109398944SobrienSince leading and trailing whitespace are ignored in command arguments,\n\ 109498944Sobrienif you want to print some you must use \"\\\" before leading whitespace\n\ 109598944Sobriento be printed or after trailing whitespace."); 109698944Sobrien add_com ("document", class_support, document_command, 109798944Sobrien "Document a user-defined command.\n\ 109898944SobrienGive command name as argument. Give documentation on following lines.\n\ 109998944SobrienEnd with a line of just \"end\"."); 110098944Sobrien add_com ("define", class_support, define_command, 110198944Sobrien "Define a new command name. Command name is argument.\n\ 110298944SobrienDefinition appears on following lines, one command per line.\n\ 110398944SobrienEnd with a line of just \"end\".\n\ 110498944SobrienUse the \"document\" command to give documentation for the new command.\n\ 110598944SobrienCommands defined in this way may have up to ten arguments."); 110698944Sobrien 110798944Sobrien c = add_cmd ("source", class_support, source_command, 110898944Sobrien "Read commands from a file named FILE.\n\ 110998944SobrienNote that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\ 111098944Sobrienwhen gdb is started.", &cmdlist); 1111130803Smarcel set_cmd_completer (c, filename_completer); 111298944Sobrien 111398944Sobrien add_com ("quit", class_support, quit_command, "Exit gdb."); 111498944Sobrien c = add_com ("help", class_support, help_command, "Print list of commands."); 1115130803Smarcel set_cmd_completer (c, command_completer); 111698944Sobrien add_com_alias ("q", "quit", class_support, 1); 111798944Sobrien add_com_alias ("h", "help", class_support, 1); 111898944Sobrien 111998944Sobrien c = add_set_cmd ("verbose", class_support, var_boolean, (char *) &info_verbose, 112098944Sobrien "Set ", 112198944Sobrien &setlist), 112298944Sobrien add_show_from_set (c, &showlist); 112398944Sobrien set_cmd_sfunc (c, set_verbose); 112498944Sobrien set_verbose (NULL, 0, c); 112598944Sobrien 112698944Sobrien add_prefix_cmd ("history", class_support, set_history, 112798944Sobrien "Generic command for setting command history parameters.", 112898944Sobrien &sethistlist, "set history ", 0, &setlist); 112998944Sobrien add_prefix_cmd ("history", class_support, show_history, 113098944Sobrien "Generic command for showing command history parameters.", 113198944Sobrien &showhistlist, "show history ", 0, &showlist); 113298944Sobrien 113398944Sobrien add_show_from_set 113498944Sobrien (add_set_cmd ("expansion", no_class, var_boolean, (char *) &history_expansion_p, 113598944Sobrien "Set history expansion on command input.\n\ 113698944SobrienWithout an argument, history expansion is enabled.", &sethistlist), 113798944Sobrien &showhistlist); 113898944Sobrien 113998944Sobrien add_prefix_cmd ("info", class_info, info_command, 114098944Sobrien "Generic command for showing things about the program being debugged.", 114198944Sobrien &infolist, "info ", 0, &cmdlist); 114298944Sobrien add_com_alias ("i", "info", class_info, 1); 114398944Sobrien 114498944Sobrien add_com ("complete", class_obscure, complete_command, 114598944Sobrien "List the completions for the rest of the line as a command."); 114698944Sobrien 114798944Sobrien add_prefix_cmd ("show", class_info, show_command, 114898944Sobrien "Generic command for showing things about the debugger.", 114998944Sobrien &showlist, "show ", 0, &cmdlist); 115098944Sobrien /* Another way to get at the same thing. */ 115198944Sobrien add_info ("set", show_command, "Show all GDB settings."); 115298944Sobrien 115398944Sobrien add_cmd ("commands", no_class, show_commands, 115498944Sobrien "Show the history of commands you typed.\n\ 115598944SobrienYou can supply a command number to start with, or a `+' to start after\n\ 115698944Sobrienthe previous command number shown.", 115798944Sobrien &showlist); 115898944Sobrien 115998944Sobrien add_cmd ("version", no_class, show_version, 116098944Sobrien "Show what version of GDB this is.", &showlist); 116198944Sobrien 116298944Sobrien add_com ("while", class_support, while_command, 116398944Sobrien "Execute nested commands WHILE the conditional expression is non zero.\n\ 116498944SobrienThe conditional expression must follow the word `while' and must in turn be\n\ 116598944Sobrienfollowed by a new line. The nested commands must be entered one per line,\n\ 116698944Sobrienand should be terminated by the word `end'."); 116798944Sobrien 116898944Sobrien add_com ("if", class_support, if_command, 116998944Sobrien "Execute nested commands once IF the conditional expression is non zero.\n\ 117098944SobrienThe conditional expression must follow the word `if' and must in turn be\n\ 117198944Sobrienfollowed by a new line. The nested commands must be entered one per line,\n\ 117298944Sobrienand should be terminated by the word 'else' or `end'. If an else clause\n\ 117398944Sobrienis used, the same rules apply to its nested commands as to the first ones."); 117498944Sobrien 117598944Sobrien /* If target is open when baud changes, it doesn't take effect until the 117698944Sobrien next open (I think, not sure). */ 117798944Sobrien add_show_from_set (add_set_cmd ("remotebaud", no_class, 117898944Sobrien var_zinteger, (char *) &baud_rate, 117998944Sobrien "Set baud rate for remote serial I/O.\n\ 118098944SobrienThis value is used to set the speed of the serial port when debugging\n\ 118198944Sobrienusing remote targets.", &setlist), 118298944Sobrien &showlist); 118398944Sobrien 118498944Sobrien c = add_set_cmd ("remotedebug", no_class, var_zinteger, 118598944Sobrien (char *) &remote_debug, 118698944Sobrien "Set debugging of remote protocol.\n\ 118798944SobrienWhen enabled, each packet sent or received with the remote target\n\ 118898944Sobrienis displayed.", &setlist); 118998944Sobrien deprecate_cmd (c, "set debug remote"); 119098944Sobrien deprecate_cmd (add_show_from_set (c, &showlist), "show debug remote"); 119198944Sobrien 119298944Sobrien add_show_from_set (add_set_cmd ("remote", no_class, var_zinteger, 119398944Sobrien (char *) &remote_debug, 119498944Sobrien "Set debugging of remote protocol.\n\ 119598944SobrienWhen enabled, each packet sent or received with the remote target\n\ 119698944Sobrienis displayed.", &setdebuglist), 119798944Sobrien &showdebuglist); 119898944Sobrien 119998944Sobrien add_show_from_set ( 120098944Sobrien add_set_cmd ("remotetimeout", no_class, var_integer, (char *) &remote_timeout, 120198944Sobrien "Set timeout limit to wait for target to respond.\n\ 120298944SobrienThis value is used to set the time limit for gdb to wait for a response\n\ 120398944Sobrienfrom the target.", &setlist), 120498944Sobrien &showlist); 120598944Sobrien 120698944Sobrien add_prefix_cmd ("debug", no_class, set_debug, 120798944Sobrien "Generic command for setting gdb debugging flags", 120898944Sobrien &setdebuglist, "set debug ", 0, &setlist); 120998944Sobrien 121098944Sobrien add_prefix_cmd ("debug", no_class, show_debug, 121198944Sobrien "Generic command for showing gdb debugging flags", 121298944Sobrien &showdebuglist, "show debug ", 0, &showlist); 121398944Sobrien 121498944Sobrien c = add_com ("shell", class_support, shell_escape, 1215130803Smarcel "Execute the rest of the line as a shell command.\n\ 121698944SobrienWith no arguments, run an inferior shell."); 1217130803Smarcel set_cmd_completer (c, filename_completer); 121898944Sobrien 1219130803Smarcel c = add_com ("edit", class_files, edit_command, 1220130803Smarcel concat ("Edit specified file or function.\n\ 1221130803SmarcelWith no argument, edits file containing most recent line listed.\n\ 1222130803Smarcel", "\ 1223130803SmarcelEditing targets can be specified in these ways:\n\ 1224130803Smarcel FILE:LINENUM, to edit at that line in that file,\n\ 1225130803Smarcel FUNCTION, to edit at the beginning of that function,\n\ 1226130803Smarcel FILE:FUNCTION, to distinguish among like-named static functions.\n\ 1227130803Smarcel *ADDRESS, to edit at the line containing that address.\n\ 1228130803SmarcelUses EDITOR environment variable contents as editor (or ex as default).",NULL)); 1229130803Smarcel 1230130803Smarcel c->completer = location_completer; 1231130803Smarcel 1232130803Smarcel add_com ("list", class_files, list_command, 1233130803Smarcel concat ("List specified function or line.\n\ 1234130803SmarcelWith no argument, lists ten more lines after or around previous listing.\n\ 1235130803Smarcel\"list -\" lists the ten lines before a previous ten-line listing.\n\ 1236130803SmarcelOne argument specifies a line, and ten lines are listed around that line.\n\ 1237130803SmarcelTwo arguments with comma between specify starting and ending lines to list.\n\ 1238130803Smarcel", "\ 1239130803SmarcelLines can be specified in these ways:\n\ 1240130803Smarcel LINENUM, to list around that line in current file,\n\ 1241130803Smarcel FILE:LINENUM, to list around that line in that file,\n\ 1242130803Smarcel FUNCTION, to list around beginning of that function,\n\ 1243130803Smarcel FILE:FUNCTION, to distinguish among like-named static functions.\n\ 1244130803Smarcel *ADDRESS, to list around the line containing that address.\n\ 1245130803SmarcelWith two args if one is empty it stands for ten lines away from the other arg.", NULL)); 1246130803Smarcel 1247130803Smarcel if (!xdb_commands) 1248130803Smarcel add_com_alias ("l", "list", class_files, 1); 1249130803Smarcel else 1250130803Smarcel add_com_alias ("v", "list", class_files, 1); 1251130803Smarcel 1252130803Smarcel if (dbx_commands) 1253130803Smarcel add_com_alias ("file", "list", class_files, 1); 1254130803Smarcel 1255130803Smarcel c = add_com ("disassemble", class_vars, disassemble_command, 1256130803Smarcel "Disassemble a specified section of memory.\n\ 1257130803SmarcelDefault is the function surrounding the pc of the selected frame.\n\ 1258130803SmarcelWith a single argument, the function surrounding that address is dumped.\n\ 1259130803SmarcelTwo arguments are taken as a range of memory to dump."); 1260130803Smarcel set_cmd_completer (c, location_completer); 1261130803Smarcel if (xdb_commands) 1262130803Smarcel add_com_alias ("va", "disassemble", class_xdb, 0); 1263130803Smarcel 126498944Sobrien /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would 126598944Sobrien be a really useful feature. Unfortunately, the below wont do 126698944Sobrien this. Instead it adds support for the form ``(gdb) ! ls'' 126798944Sobrien (i.e. the space is required). If the ``!'' command below is 126898944Sobrien added the complains about no ``!'' command would be replaced by 126998944Sobrien complains about how the ``!'' command is broken :-) */ 127098944Sobrien if (xdb_commands) 127198944Sobrien add_com_alias ("!", "shell", class_support, 0); 127298944Sobrien 127398944Sobrien c = add_com ("make", class_support, make_command, 127498944Sobrien "Run the ``make'' program using the rest of the line as arguments."); 1275130803Smarcel set_cmd_completer (c, filename_completer); 127698944Sobrien add_cmd ("user", no_class, show_user, 127798944Sobrien "Show definitions of user defined commands.\n\ 127898944SobrienArgument is the name of the user defined command.\n\ 127998944SobrienWith no argument, show definitions of all user defined commands.", &showlist); 128098944Sobrien add_com ("apropos", class_support, apropos_command, "Search for commands matching a REGEXP"); 1281130803Smarcel 1282130803Smarcel add_show_from_set ( 1283130803Smarcel add_set_cmd ("max-user-call-depth", no_class, var_integer, 1284130803Smarcel (char *) &max_user_call_depth, 1285130803Smarcel "Set the max call depth for user-defined commands.\n", 1286130803Smarcel &setlist), 1287130803Smarcel &showlist); 128898944Sobrien} 1289