1 /* List lines of source files for GDB, the GNU debugger.
2 Copyright (C) 1986-2017 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "arch-utils.h"
22 #include "expression.h"
29 #include "filestuff.h"
31 #include <sys/types.h>
35 #include "gdb_regex.h"
41 #include "filenames.h" /* for DOSish file names */
42 #include "completer.h"
44 #include "readline/readline.h"
45 #include "common/enum-flags.h"
48 #define OPEN_MODE (O_RDONLY | O_BINARY)
49 #define FDOPEN_MODE FOPEN_RB
51 /* Prototypes for local functions. */
53 static int get_filename_and_charpos (struct symtab *, char **);
55 static void info_line_command (char *, int);
57 static void info_source_command (char *, int);
59 /* Path of directories to search for source files.
60 Same format as the PATH environment variable's value. */
64 /* Support for source path substitution commands. */
66 struct substitute_path_rule
70 struct substitute_path_rule *next;
73 static struct substitute_path_rule *substitute_path_rules = NULL;
75 /* Symtab of default file for listing lines of. */
77 static struct symtab *current_source_symtab;
79 /* Default next line to list. */
81 static int current_source_line;
83 static struct program_space *current_source_pspace;
85 /* Default number of lines to print with commands like "list".
86 This is based on guessing how many long (i.e. more than chars_per_line
87 characters) lines there will be. To be completely correct, "list"
88 and friends should be rewritten to count characters and see where
89 things are wrapping, but that would be a fair amount of work. */
91 static int lines_to_list = 10;
93 show_lines_to_list (struct ui_file *file, int from_tty,
94 struct cmd_list_element *c, const char *value)
96 fprintf_filtered (file,
97 _("Number of source lines gdb "
98 "will list by default is %s.\n"),
102 /* Possible values of 'set filename-display'. */
103 static const char filename_display_basename[] = "basename";
104 static const char filename_display_relative[] = "relative";
105 static const char filename_display_absolute[] = "absolute";
107 static const char *const filename_display_kind_names[] = {
108 filename_display_basename,
109 filename_display_relative,
110 filename_display_absolute,
114 static const char *filename_display_string = filename_display_relative;
117 show_filename_display_string (struct ui_file *file, int from_tty,
118 struct cmd_list_element *c, const char *value)
120 fprintf_filtered (file, _("Filenames are displayed as \"%s\".\n"), value);
123 /* Line number of last line printed. Default for various commands.
124 current_source_line is usually, but not always, the same as this. */
126 static int last_line_listed;
128 /* First line number listed by last listing command. If 0, then no
129 source lines have yet been listed since the last time the current
130 source line was changed. */
132 static int first_line_listed;
134 /* Saves the name of the last source file visited and a possible error code.
135 Used to prevent repeating annoying "No such file or directories" msgs. */
137 static struct symtab *last_source_visited = NULL;
138 static int last_source_error = 0;
140 /* Return the first line listed by print_source_lines.
141 Used by command interpreters to request listing from
145 get_first_line_listed (void)
147 return first_line_listed;
150 /* Clear line listed range. This makes the next "list" center the
151 printed source lines around the current source line. */
154 clear_lines_listed_range (void)
156 first_line_listed = 0;
157 last_line_listed = 0;
160 /* Return the default number of lines to print with commands like the
161 cli "list". The caller of print_source_lines must use this to
162 calculate the end line and use it in the call to print_source_lines
163 as it does not automatically use this value. */
166 get_lines_to_list (void)
168 return lines_to_list;
171 /* Return the current source file for listing and next line to list.
172 NOTE: The returned sal pc and end fields are not valid. */
174 struct symtab_and_line
175 get_current_source_symtab_and_line (void)
177 symtab_and_line cursal;
179 cursal.pspace = current_source_pspace;
180 cursal.symtab = current_source_symtab;
181 cursal.line = current_source_line;
188 /* If the current source file for listing is not set, try and get a default.
189 Usually called before get_current_source_symtab_and_line() is called.
190 It may err out if a default cannot be determined.
191 We must be cautious about where it is called, as it can recurse as the
192 process of determining a new default may call the caller!
193 Use get_current_source_symtab_and_line only to get whatever
194 we have without erroring out or trying to get a default. */
197 set_default_source_symtab_and_line (void)
199 if (!have_full_symbols () && !have_partial_symbols ())
200 error (_("No symbol table is loaded. Use the \"file\" command."));
202 /* Pull in a current source symtab if necessary. */
203 if (current_source_symtab == 0)
204 select_source_symtab (0);
207 /* Return the current default file for listing and next line to list
208 (the returned sal pc and end fields are not valid.)
209 and set the current default to whatever is in SAL.
210 NOTE: The returned sal pc and end fields are not valid. */
212 struct symtab_and_line
213 set_current_source_symtab_and_line (const symtab_and_line &sal)
215 symtab_and_line cursal;
217 cursal.pspace = current_source_pspace;
218 cursal.symtab = current_source_symtab;
219 cursal.line = current_source_line;
223 current_source_pspace = sal.pspace;
224 current_source_symtab = sal.symtab;
225 current_source_line = sal.line;
227 /* Force the next "list" to center around the current line. */
228 clear_lines_listed_range ();
233 /* Reset any information stored about a default file and line to print. */
236 clear_current_source_symtab_and_line (void)
238 current_source_symtab = 0;
239 current_source_line = 0;
242 /* Set the source file default for the "list" command to be S.
244 If S is NULL, and we don't have a default, find one. This
245 should only be called when the user actually tries to use the
246 default, since we produce an error if we can't find a reasonable
247 default. Also, since this can cause symbols to be read, doing it
248 before we need to would make things slower than necessary. */
251 select_source_symtab (struct symtab *s)
254 struct compunit_symtab *cu;
258 current_source_symtab = s;
259 current_source_line = 1;
260 current_source_pspace = SYMTAB_PSPACE (s);
264 if (current_source_symtab)
267 /* Make the default place to list be the function `main'
269 if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0).symbol)
271 std::vector<symtab_and_line> sals
272 = decode_line_with_current_source (main_name (),
273 DECODE_LINE_FUNFIRSTLINE);
274 const symtab_and_line &sal = sals[0];
275 current_source_pspace = sal.pspace;
276 current_source_symtab = sal.symtab;
277 current_source_line = std::max (sal.line - (lines_to_list - 1), 1);
278 if (current_source_symtab)
282 /* Alright; find the last file in the symtab list (ignoring .h's
283 and namespace symtabs). */
285 current_source_line = 1;
287 ALL_FILETABS (ofp, cu, s)
289 const char *name = s->filename;
290 int len = strlen (name);
292 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
293 || strcmp (name, "<<C++-namespaces>>") == 0)))
295 current_source_pspace = current_program_space;
296 current_source_symtab = s;
300 if (current_source_symtab)
306 s = ofp->sf->qf->find_last_source_symtab (ofp);
308 current_source_symtab = s;
310 if (current_source_symtab)
313 error (_("Can't find a default source file"));
316 /* Handler for "set directories path-list" command.
317 "set dir mumble" doesn't prepend paths, it resets the entire
318 path list. The theory is that set(show(dir)) should be a no-op. */
321 set_directories_command (char *args, int from_tty, struct cmd_list_element *c)
323 /* This is the value that was set.
324 It needs to be processed to maintain $cdir:$cwd and remove dups. */
325 char *set_path = source_path;
327 /* We preserve the invariant that $cdir:$cwd begins life at the end of
328 the list by calling init_source_path. If they appear earlier in
329 SET_PATH then mod_path will move them appropriately.
330 mod_path will also remove duplicates. */
332 if (*set_path != '\0')
333 mod_path (set_path, &source_path);
338 /* Print the list of source directories.
339 This is used by the "ld" command, so it has the signature of a command
343 show_directories_1 (char *ignore, int from_tty)
345 puts_filtered ("Source directories searched: ");
346 puts_filtered (source_path);
347 puts_filtered ("\n");
350 /* Handler for "show directories" command. */
353 show_directories_command (struct ui_file *file, int from_tty,
354 struct cmd_list_element *c, const char *value)
356 show_directories_1 (NULL, from_tty);
359 /* Forget line positions and file names for the symtabs in a
360 particular objfile. */
363 forget_cached_source_info_for_objfile (struct objfile *objfile)
365 struct compunit_symtab *cu;
368 ALL_OBJFILE_FILETABS (objfile, cu, s)
370 if (s->line_charpos != NULL)
372 xfree (s->line_charpos);
373 s->line_charpos = NULL;
375 if (s->fullname != NULL)
383 objfile->sf->qf->forget_cached_source_info (objfile);
386 /* Forget what we learned about line positions in source files, and
387 which directories contain them; must check again now since files
388 may be found in a different directory now. */
391 forget_cached_source_info (void)
393 struct program_space *pspace;
394 struct objfile *objfile;
397 ALL_PSPACE_OBJFILES (pspace, objfile)
399 forget_cached_source_info_for_objfile (objfile);
402 last_source_visited = NULL;
406 init_source_path (void)
410 xsnprintf (buf, sizeof (buf), "$cdir%c$cwd", DIRNAME_SEPARATOR);
411 source_path = xstrdup (buf);
412 forget_cached_source_info ();
415 /* Add zero or more directories to the front of the source path. */
418 directory_command (char *dirname, int from_tty)
421 /* FIXME, this goes to "delete dir"... */
424 if (!from_tty || query (_("Reinitialize source path to empty? ")))
432 mod_path (dirname, &source_path);
433 forget_cached_source_info ();
436 show_directories_1 ((char *) 0, from_tty);
439 /* Add a path given with the -d command line switch.
440 This will not be quoted so we must not treat spaces as separators. */
443 directory_switch (const char *dirname, int from_tty)
445 add_path (dirname, &source_path, 0);
448 /* Add zero or more directories to the front of an arbitrary path. */
451 mod_path (const char *dirname, char **which_path)
453 add_path (dirname, which_path, 1);
456 /* Workhorse of mod_path. Takes an extra argument to determine
457 if dirname should be parsed for separators that indicate multiple
458 directories. This allows for interfaces that pre-parse the dirname
459 and allow specification of traditional separator characters such
463 add_path (const char *dirname, char **which_path, int parse_separators)
465 char *old = *which_path;
467 VEC (char_ptr) *dir_vec = NULL;
468 struct cleanup *back_to;
475 if (parse_separators)
477 /* This will properly parse the space and tab separators
478 and any quotes that may exist. */
479 gdb_argv argv (dirname);
481 for (char *arg : argv)
482 dirnames_to_char_ptr_vec_append (&dir_vec, arg);
485 VEC_safe_push (char_ptr, dir_vec, xstrdup (dirname));
486 back_to = make_cleanup_free_char_ptr_vec (dir_vec);
488 for (ix = 0; VEC_iterate (char_ptr, dir_vec, ix, name); ++ix)
493 /* Spaces and tabs will have been removed by buildargv().
494 NAME is the start of the directory.
495 P is the '\0' following the end. */
496 p = name + strlen (name);
498 while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */
499 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
500 /* On MS-DOS and MS-Windows, h:\ is different from h: */
501 && !(p == name + 3 && name[1] == ':') /* "d:/" */
503 && IS_DIR_SEPARATOR (p[-1]))
504 /* Sigh. "foo/" => "foo" */
508 while (p > name && p[-1] == '.')
512 /* "." => getwd (). */
513 name = current_directory;
516 else if (p > name + 1 && IS_DIR_SEPARATOR (p[-2]))
526 /* "...foo/." => "...foo". */
537 name = tilde_expand (name);
538 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
539 else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */
540 name = concat (name, ".", (char *)NULL);
542 else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$')
543 name = concat (current_directory, SLASH_STRING, name, (char *)NULL);
545 name = savestring (name, p - name);
546 make_cleanup (xfree, name);
548 /* Unless it's a variable, check existence. */
551 /* These are warnings, not errors, since we don't want a
552 non-existent directory in a .gdbinit file to stop processing
553 of the .gdbinit file.
555 Whether they get added to the path is more debatable. Current
556 answer is yes, in case the user wants to go make the directory
557 or whatever. If the directory continues to not exist/not be
558 a directory/etc, then having them in the path should be
560 if (stat (name, &st) < 0)
562 int save_errno = errno;
564 fprintf_unfiltered (gdb_stderr, "Warning: ");
565 print_sys_errmsg (name, save_errno);
567 else if ((st.st_mode & S_IFMT) != S_IFDIR)
568 warning (_("%s is not a directory."), name);
573 unsigned int len = strlen (name);
579 /* FIXME: we should use realpath() or its work-alike
580 before comparing. Then all the code above which
581 removes excess slashes and dots could simply go away. */
582 if (!filename_ncmp (p, name, len)
583 && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
585 /* Found it in the search path, remove old copy. */
588 /* Back over leading separator. */
591 if (prefix > p - *which_path)
593 /* Same dir twice in one cmd. */
596 /* Copy from next '\0' or ':'. */
597 memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1);
599 p = strchr (p, DIRNAME_SEPARATOR);
606 tinybuf[0] = DIRNAME_SEPARATOR;
609 /* If we have already tacked on a name(s) in this command,
610 be sure they stay on the front as we tack on some
618 temp = concat (old, tinybuf, name, (char *)NULL);
620 *which_path = concat (temp, "", &old[prefix], (char *) NULL);
621 prefix = strlen (temp);
626 *which_path = concat (name, (old[0] ? tinybuf : old),
628 prefix = strlen (name);
637 do_cleanups (back_to);
642 info_source_command (char *ignore, int from_tty)
644 struct symtab *s = current_source_symtab;
645 struct compunit_symtab *cust;
649 printf_filtered (_("No current source file.\n"));
653 cust = SYMTAB_COMPUNIT (s);
654 printf_filtered (_("Current source file is %s\n"), s->filename);
655 if (SYMTAB_DIRNAME (s) != NULL)
656 printf_filtered (_("Compilation directory is %s\n"), SYMTAB_DIRNAME (s));
658 printf_filtered (_("Located in %s\n"), s->fullname);
660 printf_filtered (_("Contains %d line%s.\n"), s->nlines,
661 s->nlines == 1 ? "" : "s");
663 printf_filtered (_("Source language is %s.\n"), language_str (s->language));
664 printf_filtered (_("Producer is %s.\n"),
665 COMPUNIT_PRODUCER (cust) != NULL
666 ? COMPUNIT_PRODUCER (cust) : _("unknown"));
667 printf_filtered (_("Compiled with %s debugging format.\n"),
668 COMPUNIT_DEBUGFORMAT (cust));
669 printf_filtered (_("%s preprocessor macro info.\n"),
670 COMPUNIT_MACRO_TABLE (cust) != NULL
671 ? "Includes" : "Does not include");
675 /* Return True if the file NAME exists and is a regular file.
676 If the result is false then *ERRNO_PTR is set to a useful value assuming
677 we're expecting a regular file. */
680 is_regular_file (const char *name, int *errno_ptr)
683 const int status = stat (name, &st);
685 /* Stat should never fail except when the file does not exist.
686 If stat fails, analyze the source of error and return True
687 unless the file does not exist, to avoid returning false results
688 on obscure systems where stat does not work as expected. */
698 if (S_ISREG (st.st_mode))
701 if (S_ISDIR (st.st_mode))
708 /* Open a file named STRING, searching path PATH (dir names sep by some char)
709 using mode MODE in the calls to open. You cannot use this function to
710 create files (O_CREAT).
712 OPTS specifies the function behaviour in specific cases.
714 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
715 (ie pretend the first element of PATH is "."). This also indicates
716 that, unless OPF_SEARCH_IN_PATH is also specified, a slash in STRING
717 disables searching of the path (this is so that "exec-file ./foo" or
718 "symbol-file ./foo" insures that you get that particular version of
719 foo or an error message).
721 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
722 searched in path (we usually want this for source files but not for
725 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
726 the actual file opened (this string will always start with a "/"). We
727 have to take special pains to avoid doubling the "/" between the directory
728 and the file, sigh! Emacs gets confuzzed by this when we print the
731 If OPTS has OPF_RETURN_REALPATH set return FILENAME_OPENED resolved by
732 gdb_realpath. Even without OPF_RETURN_REALPATH this function still returns
733 filename starting with "/". If FILENAME_OPENED is NULL this option has no
736 If a file is found, return the descriptor.
737 Otherwise, return -1, with errno set for the last name we tried to open. */
739 /* >>>> This should only allow files of certain types,
740 >>>> eg executable, non-directory. */
742 openp (const char *path, int opts, const char *string,
743 int mode, char **filename_opened)
748 VEC (char_ptr) *dir_vec;
749 struct cleanup *back_to;
752 /* The errno set for the last name we tried to open (and
756 /* The open syscall MODE parameter is not specified. */
757 gdb_assert ((mode & O_CREAT) == 0);
758 gdb_assert (string != NULL);
760 /* A file with an empty name cannot possibly exist. Report a failure
761 without further checking.
763 This is an optimization which also defends us against buggy
764 implementations of the "stat" function. For instance, we have
765 noticed that a MinGW debugger built on Windows XP 32bits crashes
766 when the debugger is started with an empty argument. */
767 if (string[0] == '\0')
778 if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string))
780 int i, reg_file_errno;
782 if (is_regular_file (string, ®_file_errno))
784 filename = (char *) alloca (strlen (string) + 1);
785 strcpy (filename, string);
786 fd = gdb_open_cloexec (filename, mode, 0);
795 last_errno = reg_file_errno;
798 if (!(opts & OPF_SEARCH_IN_PATH))
799 for (i = 0; string[i]; i++)
800 if (IS_DIR_SEPARATOR (string[i]))
804 /* For dos paths, d:/foo -> /foo, and d:foo -> foo. */
805 if (HAS_DRIVE_SPEC (string))
806 string = STRIP_DRIVE_SPEC (string);
808 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
809 while (IS_DIR_SEPARATOR(string[0]))
813 while (string[0] == '.' && IS_DIR_SEPARATOR (string[1]))
816 alloclen = strlen (path) + strlen (string) + 2;
817 filename = (char *) alloca (alloclen);
821 dir_vec = dirnames_to_char_ptr_vec (path);
822 back_to = make_cleanup_free_char_ptr_vec (dir_vec);
824 for (ix = 0; VEC_iterate (char_ptr, dir_vec, ix, dir); ++ix)
826 size_t len = strlen (dir);
829 if (strcmp (dir, "$cwd") == 0)
831 /* Name is $cwd -- insert current directory name instead. */
834 /* First, realloc the filename buffer if too short. */
835 len = strlen (current_directory);
836 newlen = len + strlen (string) + 2;
837 if (newlen > alloclen)
840 filename = (char *) alloca (alloclen);
842 strcpy (filename, current_directory);
844 else if (strchr(dir, '~'))
846 /* See whether we need to expand the tilde. */
849 gdb::unique_xmalloc_ptr<char> tilde_expanded (tilde_expand (dir));
851 /* First, realloc the filename buffer if too short. */
852 len = strlen (tilde_expanded.get ());
853 newlen = len + strlen (string) + 2;
854 if (newlen > alloclen)
857 filename = (char *) alloca (alloclen);
859 strcpy (filename, tilde_expanded.get ());
863 /* Normal file name in path -- just use it. */
864 strcpy (filename, dir);
866 /* Don't search $cdir. It's also a magic path like $cwd, but we
867 don't have enough information to expand it. The user *could*
868 have an actual directory named '$cdir' but handling that would
869 be confusing, it would mean different things in different
870 contexts. If the user really has '$cdir' one can use './$cdir'.
871 We can get $cdir when loading scripts. When loading source files
872 $cdir must have already been expanded to the correct value. */
873 if (strcmp (dir, "$cdir") == 0)
877 /* Remove trailing slashes. */
878 while (len > 0 && IS_DIR_SEPARATOR (filename[len - 1]))
881 strcat (filename + len, SLASH_STRING);
882 strcat (filename, string);
884 if (is_regular_file (filename, ®_file_errno))
886 fd = gdb_open_cloexec (filename, mode, 0);
892 last_errno = reg_file_errno;
895 do_cleanups (back_to);
900 /* If a file was opened, canonicalize its filename. */
902 *filename_opened = NULL;
903 else if ((opts & OPF_RETURN_REALPATH) != 0)
904 *filename_opened = gdb_realpath (filename).release ();
906 *filename_opened = gdb_abspath (filename).release ();
914 /* This is essentially a convenience, for clients that want the behaviour
915 of openp, using source_path, but that really don't want the file to be
916 opened but want instead just to know what the full pathname is (as
917 qualified against source_path).
919 The current working directory is searched first.
921 If the file was found, this function returns 1, and FULL_PATHNAME is
922 set to the fully-qualified pathname.
924 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
926 source_full_path_of (const char *filename, char **full_pathname)
930 fd = openp (source_path,
931 OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH,
932 filename, O_RDONLY, full_pathname);
935 *full_pathname = NULL;
943 /* Return non-zero if RULE matches PATH, that is if the rule can be
947 substitute_path_rule_matches (const struct substitute_path_rule *rule,
950 const int from_len = strlen (rule->from);
951 const int path_len = strlen (path);
953 if (path_len < from_len)
956 /* The substitution rules are anchored at the start of the path,
957 so the path should start with rule->from. */
959 if (filename_ncmp (path, rule->from, from_len) != 0)
962 /* Make sure that the region in the path that matches the substitution
963 rule is immediately followed by a directory separator (or the end of
964 string character). */
966 if (path[from_len] != '\0' && !IS_DIR_SEPARATOR (path[from_len]))
972 /* Find the substitute-path rule that applies to PATH and return it.
973 Return NULL if no rule applies. */
975 static struct substitute_path_rule *
976 get_substitute_path_rule (const char *path)
978 struct substitute_path_rule *rule = substitute_path_rules;
980 while (rule != NULL && !substitute_path_rule_matches (rule, path))
986 /* If the user specified a source path substitution rule that applies
987 to PATH, then apply it and return the new path.
989 Return NULL if no substitution rule was specified by the user,
990 or if no rule applied to the given PATH. */
992 gdb::unique_xmalloc_ptr<char>
993 rewrite_source_path (const char *path)
995 const struct substitute_path_rule *rule = get_substitute_path_rule (path);
1002 from_len = strlen (rule->from);
1004 /* Compute the rewritten path and return it. */
1007 (char *) xmalloc (strlen (path) + 1 + strlen (rule->to) - from_len);
1008 strcpy (new_path, rule->to);
1009 strcat (new_path, path + from_len);
1011 return gdb::unique_xmalloc_ptr<char> (new_path);
1015 find_and_open_source (const char *filename,
1016 const char *dirname,
1019 char *path = source_path;
1023 /* Quick way out if we already know its full name. */
1027 /* The user may have requested that source paths be rewritten
1028 according to substitution rules he provided. If a substitution
1029 rule applies to this path, then apply it. */
1030 char *rewritten_fullname = rewrite_source_path (*fullname).release ();
1032 if (rewritten_fullname != NULL)
1035 *fullname = rewritten_fullname;
1038 result = gdb_open_cloexec (*fullname, OPEN_MODE, 0);
1041 char *lpath = gdb_realpath (*fullname).release ();
1048 /* Didn't work -- free old one, try again. */
1053 gdb::unique_xmalloc_ptr<char> rewritten_dirname;
1054 if (dirname != NULL)
1056 /* If necessary, rewrite the compilation directory name according
1057 to the source path substitution rules specified by the user. */
1059 rewritten_dirname = rewrite_source_path (dirname);
1061 if (rewritten_dirname != NULL)
1062 dirname = rewritten_dirname.get ();
1064 /* Replace a path entry of $cdir with the compilation directory
1067 /* We cast strstr's result in case an ANSIhole has made it const,
1068 which produces a "required warning" when assigned to a nonconst. */
1069 p = (char *) strstr (source_path, "$cdir");
1070 if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)
1071 && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0'))
1076 alloca (strlen (source_path) + 1 + strlen (dirname) + 1);
1077 len = p - source_path;
1078 strncpy (path, source_path, len); /* Before $cdir */
1079 strcpy (path + len, dirname); /* new stuff */
1080 strcat (path + len, source_path + len + cdir_len); /* After
1085 gdb::unique_xmalloc_ptr<char> rewritten_filename;
1086 if (IS_ABSOLUTE_PATH (filename))
1088 /* If filename is absolute path, try the source path
1089 substitution on it. */
1090 rewritten_filename = rewrite_source_path (filename);
1092 if (rewritten_filename != NULL)
1093 filename = rewritten_filename.get ();
1096 result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename,
1097 OPEN_MODE, fullname);
1100 /* Didn't work. Try using just the basename. */
1101 p = lbasename (filename);
1103 result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, p,
1104 OPEN_MODE, fullname);
1110 /* Open a source file given a symtab S. Returns a file descriptor or
1111 negative number for error.
1113 This function is a convience function to find_and_open_source. */
1116 open_source_file (struct symtab *s)
1121 return find_and_open_source (s->filename, SYMTAB_DIRNAME (s), &s->fullname);
1124 /* Finds the fullname that a symtab represents.
1126 This functions finds the fullname and saves it in s->fullname.
1127 It will also return the value.
1129 If this function fails to find the file that this symtab represents,
1130 the expected fullname is used. Therefore the files does not have to
1134 symtab_to_fullname (struct symtab *s)
1136 /* Use cached copy if we have it.
1137 We rely on forget_cached_source_info being called appropriately
1138 to handle cases like the file being moved. */
1139 if (s->fullname == NULL)
1141 int fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s),
1148 gdb::unique_xmalloc_ptr<char> fullname;
1150 /* rewrite_source_path would be applied by find_and_open_source, we
1151 should report the pathname where GDB tried to find the file. */
1153 if (SYMTAB_DIRNAME (s) == NULL || IS_ABSOLUTE_PATH (s->filename))
1154 fullname.reset (xstrdup (s->filename));
1156 fullname.reset (concat (SYMTAB_DIRNAME (s), SLASH_STRING,
1157 s->filename, (char *) NULL));
1159 s->fullname = rewrite_source_path (fullname.get ()).release ();
1160 if (s->fullname == NULL)
1161 s->fullname = fullname.release ();
1168 /* See commentary in source.h. */
1171 symtab_to_filename_for_display (struct symtab *symtab)
1173 if (filename_display_string == filename_display_basename)
1174 return lbasename (symtab->filename);
1175 else if (filename_display_string == filename_display_absolute)
1176 return symtab_to_fullname (symtab);
1177 else if (filename_display_string == filename_display_relative)
1178 return symtab->filename;
1180 internal_error (__FILE__, __LINE__, _("invalid filename_display_string"));
1183 /* Create and initialize the table S->line_charpos that records
1184 the positions of the lines in the source file, which is assumed
1185 to be open on descriptor DESC.
1186 All set S->nlines to the number of such lines. */
1189 find_source_lines (struct symtab *s, int desc)
1192 char *data, *p, *end;
1194 int lines_allocated = 1000;
1200 line_charpos = XNEWVEC (int, lines_allocated);
1201 if (fstat (desc, &st) < 0)
1202 perror_with_name (symtab_to_filename_for_display (s));
1204 if (SYMTAB_OBJFILE (s) != NULL && SYMTAB_OBJFILE (s)->obfd != NULL)
1205 mtime = SYMTAB_OBJFILE (s)->mtime;
1207 mtime = exec_bfd_mtime;
1209 if (mtime && mtime < st.st_mtime)
1210 warning (_("Source file is more recent than executable."));
1213 struct cleanup *old_cleanups;
1215 /* st_size might be a large type, but we only support source files whose
1216 size fits in an int. */
1217 size = (int) st.st_size;
1219 /* Use malloc, not alloca, because this may be pretty large, and we may
1220 run into various kinds of limits on stack size. */
1221 data = (char *) xmalloc (size);
1222 old_cleanups = make_cleanup (xfree, data);
1224 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1225 size = myread (desc, data, size);
1227 perror_with_name (symtab_to_filename_for_display (s));
1230 line_charpos[0] = 0;
1235 /* A newline at the end does not start a new line. */
1238 if (nlines == lines_allocated)
1240 lines_allocated *= 2;
1242 (int *) xrealloc ((char *) line_charpos,
1243 sizeof (int) * lines_allocated);
1245 line_charpos[nlines++] = p - data;
1248 do_cleanups (old_cleanups);
1253 (int *) xrealloc ((char *) line_charpos, nlines * sizeof (int));
1259 /* Get full pathname and line number positions for a symtab.
1260 Return nonzero if line numbers may have changed.
1261 Set *FULLNAME to actual name of the file as found by `openp',
1262 or to 0 if the file is not found. */
1265 get_filename_and_charpos (struct symtab *s, char **fullname)
1267 int desc, linenums_changed = 0;
1268 struct cleanup *cleanups;
1270 desc = open_source_file (s);
1277 cleanups = make_cleanup_close (desc);
1279 *fullname = s->fullname;
1280 if (s->line_charpos == 0)
1281 linenums_changed = 1;
1282 if (linenums_changed)
1283 find_source_lines (s, desc);
1284 do_cleanups (cleanups);
1285 return linenums_changed;
1288 /* Print text describing the full name of the source file S
1289 and the line number LINE and its corresponding character position.
1290 The text starts with two Ctrl-z so that the Emacs-GDB interface
1293 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1295 Return 1 if successful, 0 if could not find the file. */
1298 identify_source_line (struct symtab *s, int line, int mid_statement,
1301 if (s->line_charpos == 0)
1302 get_filename_and_charpos (s, (char **) NULL);
1303 if (s->fullname == 0)
1305 if (line > s->nlines)
1306 /* Don't index off the end of the line_charpos array. */
1308 annotate_source (s->fullname, line, s->line_charpos[line - 1],
1309 mid_statement, get_objfile_arch (SYMTAB_OBJFILE (s)), pc);
1311 current_source_line = line;
1312 current_source_symtab = s;
1313 clear_lines_listed_range ();
1318 /* Print source lines from the file of symtab S,
1319 starting with line number LINE and stopping before line number STOPLINE. */
1322 print_source_lines_base (struct symtab *s, int line, int stopline,
1323 print_source_lines_flags flags)
1328 int nlines = stopline - line;
1329 struct ui_out *uiout = current_uiout;
1331 /* Regardless of whether we can open the file, set current_source_symtab. */
1332 current_source_symtab = s;
1333 current_source_line = line;
1334 first_line_listed = line;
1336 /* If printing of source lines is disabled, just print file and line
1338 if (uiout->test_flags (ui_source_list))
1340 /* Only prints "No such file or directory" once. */
1341 if ((s != last_source_visited) || (!last_source_error))
1343 last_source_visited = s;
1344 desc = open_source_file (s);
1348 desc = last_source_error;
1349 flags |= PRINT_SOURCE_LINES_NOERROR;
1354 desc = last_source_error;
1355 flags |= PRINT_SOURCE_LINES_NOERROR;
1359 if (desc < 0 || noprint)
1361 last_source_error = desc;
1363 if (!(flags & PRINT_SOURCE_LINES_NOERROR))
1365 const char *filename = symtab_to_filename_for_display (s);
1366 int len = strlen (filename) + 100;
1367 char *name = (char *) alloca (len);
1369 xsnprintf (name, len, "%d\t%s", line, filename);
1370 print_sys_errmsg (name, errno);
1374 uiout->field_int ("line", line);
1375 uiout->text ("\tin ");
1377 /* CLI expects only the "file" field. TUI expects only the
1378 "fullname" field (and TUI does break if "file" is printed).
1379 MI expects both fields. ui_source_list is set only for CLI,
1381 if (uiout->is_mi_like_p () || uiout->test_flags (ui_source_list))
1382 uiout->field_string ("file", symtab_to_filename_for_display (s));
1383 if (uiout->is_mi_like_p () || !uiout->test_flags (ui_source_list))
1385 const char *s_fullname = symtab_to_fullname (s);
1386 char *local_fullname;
1388 /* ui_out_field_string may free S_FULLNAME by calling
1389 open_source_file for it again. See e.g.,
1390 tui_field_string->tui_show_source. */
1391 local_fullname = (char *) alloca (strlen (s_fullname) + 1);
1392 strcpy (local_fullname, s_fullname);
1394 uiout->field_string ("fullname", local_fullname);
1403 last_source_error = 0;
1405 if (s->line_charpos == 0)
1406 find_source_lines (s, desc);
1408 if (line < 1 || line > s->nlines)
1411 error (_("Line number %d out of range; %s has %d lines."),
1412 line, symtab_to_filename_for_display (s), s->nlines);
1415 if (lseek (desc, s->line_charpos[line - 1], 0) < 0)
1418 perror_with_name (symtab_to_filename_for_display (s));
1421 gdb_file_up stream (fdopen (desc, FDOPEN_MODE));
1422 clearerr (stream.get ());
1424 while (nlines-- > 0)
1428 c = fgetc (stream.get ());
1431 last_line_listed = current_source_line;
1432 if (flags & PRINT_SOURCE_LINES_FILENAME)
1434 uiout->text (symtab_to_filename_for_display (s));
1437 xsnprintf (buf, sizeof (buf), "%d\t", current_source_line++);
1441 if (c < 040 && c != '\t' && c != '\n' && c != '\r')
1443 xsnprintf (buf, sizeof (buf), "^%c", c + 0100);
1450 /* Skip a \r character, but only before a \n. */
1451 int c1 = fgetc (stream.get ());
1454 printf_filtered ("^%c", c + 0100);
1456 ungetc (c1, stream.get ());
1460 xsnprintf (buf, sizeof (buf), "%c", c);
1464 while (c != '\n' && (c = fgetc (stream.get ())) >= 0);
1468 /* Show source lines from the file of symtab S, starting with line
1469 number LINE and stopping before line number STOPLINE. If this is
1470 not the command line version, then the source is shown in the source
1471 window otherwise it is simply printed. */
1474 print_source_lines (struct symtab *s, int line, int stopline,
1475 print_source_lines_flags flags)
1477 print_source_lines_base (s, line, stopline, flags);
1480 /* Print info on range of pc's in a specified line. */
1483 info_line_command (char *arg, int from_tty)
1485 CORE_ADDR start_pc, end_pc;
1487 std::vector<symtab_and_line> decoded_sals;
1488 symtab_and_line curr_sal;
1489 gdb::array_view<symtab_and_line> sals;
1493 curr_sal.symtab = current_source_symtab;
1494 curr_sal.pspace = current_program_space;
1495 if (last_line_listed != 0)
1496 curr_sal.line = last_line_listed;
1498 curr_sal.line = current_source_line;
1504 decoded_sals = decode_line_with_last_displayed (arg,
1505 DECODE_LINE_LIST_MODE);
1506 sals = decoded_sals;
1511 /* C++ More than one line may have been specified, as when the user
1512 specifies an overloaded function name. Print info on them all. */
1513 for (const auto &sal : sals)
1515 if (sal.pspace != current_program_space)
1518 if (sal.symtab == 0)
1520 struct gdbarch *gdbarch = get_current_arch ();
1522 printf_filtered (_("No line number information available"));
1525 /* This is useful for "info line *0x7f34". If we can't tell the
1526 user about a source line, at least let them have the symbolic
1528 printf_filtered (" for address ");
1530 print_address (gdbarch, sal.pc, gdb_stdout);
1533 printf_filtered (".");
1534 printf_filtered ("\n");
1536 else if (sal.line > 0
1537 && find_line_pc_range (sal, &start_pc, &end_pc))
1539 struct gdbarch *gdbarch
1540 = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
1542 if (start_pc == end_pc)
1544 printf_filtered ("Line %d of \"%s\"",
1546 symtab_to_filename_for_display (sal.symtab));
1548 printf_filtered (" is at address ");
1549 print_address (gdbarch, start_pc, gdb_stdout);
1551 printf_filtered (" but contains no code.\n");
1555 printf_filtered ("Line %d of \"%s\"",
1557 symtab_to_filename_for_display (sal.symtab));
1559 printf_filtered (" starts at address ");
1560 print_address (gdbarch, start_pc, gdb_stdout);
1562 printf_filtered (" and ends at ");
1563 print_address (gdbarch, end_pc, gdb_stdout);
1564 printf_filtered (".\n");
1567 /* x/i should display this line's code. */
1568 set_next_address (gdbarch, start_pc);
1570 /* Repeating "info line" should do the following line. */
1571 last_line_listed = sal.line + 1;
1573 /* If this is the only line, show the source code. If it could
1574 not find the file, don't do anything special. */
1575 if (annotation_level && sals.size () == 1)
1576 identify_source_line (sal.symtab, sal.line, 0, start_pc);
1579 /* Is there any case in which we get here, and have an address
1580 which the user would want to see? If we have debugging symbols
1581 and no line numbers? */
1582 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
1583 sal.line, symtab_to_filename_for_display (sal.symtab));
1587 /* Commands to search the source file for a regexp. */
1590 forward_search_command (const char *regex, int from_tty)
1596 struct cleanup *cleanups;
1598 line = last_line_listed + 1;
1600 msg = (char *) re_comp (regex);
1602 error (("%s"), msg);
1604 if (current_source_symtab == 0)
1605 select_source_symtab (0);
1607 desc = open_source_file (current_source_symtab);
1609 perror_with_name (symtab_to_filename_for_display (current_source_symtab));
1610 cleanups = make_cleanup_close (desc);
1612 if (current_source_symtab->line_charpos == 0)
1613 find_source_lines (current_source_symtab, desc);
1615 if (line < 1 || line > current_source_symtab->nlines)
1616 error (_("Expression not found"));
1618 if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
1619 perror_with_name (symtab_to_filename_for_display (current_source_symtab));
1621 discard_cleanups (cleanups);
1622 gdb_file_up stream (fdopen (desc, FDOPEN_MODE));
1623 clearerr (stream.get ());
1626 static char *buf = NULL;
1628 int cursize, newsize;
1631 buf = (char *) xmalloc (cursize);
1634 c = fgetc (stream.get ());
1640 if (p - buf == cursize)
1642 newsize = cursize + cursize / 2;
1643 buf = (char *) xrealloc (buf, newsize);
1648 while (c != '\n' && (c = fgetc (stream.get ())) >= 0);
1650 /* Remove the \r, if any, at the end of the line, otherwise
1651 regular expressions that end with $ or \n won't work. */
1652 if (p - buf > 1 && p[-2] == '\r')
1658 /* We now have a source line in buf, null terminate and match. */
1660 if (re_exec (buf) > 0)
1663 print_source_lines (current_source_symtab, line, line + 1, 0);
1664 set_internalvar_integer (lookup_internalvar ("_"), line);
1665 current_source_line = std::max (line - lines_to_list / 2, 1);
1671 printf_filtered (_("Expression not found\n"));
1675 reverse_search_command (const char *regex, int from_tty)
1681 struct cleanup *cleanups;
1683 line = last_line_listed - 1;
1685 msg = (char *) re_comp (regex);
1687 error (("%s"), msg);
1689 if (current_source_symtab == 0)
1690 select_source_symtab (0);
1692 desc = open_source_file (current_source_symtab);
1694 perror_with_name (symtab_to_filename_for_display (current_source_symtab));
1695 cleanups = make_cleanup_close (desc);
1697 if (current_source_symtab->line_charpos == 0)
1698 find_source_lines (current_source_symtab, desc);
1700 if (line < 1 || line > current_source_symtab->nlines)
1701 error (_("Expression not found"));
1703 if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
1704 perror_with_name (symtab_to_filename_for_display (current_source_symtab));
1706 discard_cleanups (cleanups);
1707 gdb_file_up stream (fdopen (desc, FDOPEN_MODE));
1708 clearerr (stream.get ());
1711 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1712 char buf[4096]; /* Should be reasonable??? */
1715 c = fgetc (stream.get ());
1722 while (c != '\n' && (c = fgetc (stream.get ())) >= 0);
1724 /* Remove the \r, if any, at the end of the line, otherwise
1725 regular expressions that end with $ or \n won't work. */
1726 if (p - buf > 1 && p[-2] == '\r')
1732 /* We now have a source line in buf; null terminate and match. */
1734 if (re_exec (buf) > 0)
1737 print_source_lines (current_source_symtab, line, line + 1, 0);
1738 set_internalvar_integer (lookup_internalvar ("_"), line);
1739 current_source_line = std::max (line - lines_to_list / 2, 1);
1743 if (fseek (stream.get (),
1744 current_source_symtab->line_charpos[line - 1], 0) < 0)
1746 const char *filename;
1748 filename = symtab_to_filename_for_display (current_source_symtab);
1749 perror_with_name (filename);
1753 printf_filtered (_("Expression not found\n"));
1757 /* If the last character of PATH is a directory separator, then strip it. */
1760 strip_trailing_directory_separator (char *path)
1762 const int last = strlen (path) - 1;
1765 return; /* No stripping is needed if PATH is the empty string. */
1767 if (IS_DIR_SEPARATOR (path[last]))
1771 /* Return the path substitution rule that matches FROM.
1772 Return NULL if no rule matches. */
1774 static struct substitute_path_rule *
1775 find_substitute_path_rule (const char *from)
1777 struct substitute_path_rule *rule = substitute_path_rules;
1779 while (rule != NULL)
1781 if (FILENAME_CMP (rule->from, from) == 0)
1789 /* Add a new substitute-path rule at the end of the current list of rules.
1790 The new rule will replace FROM into TO. */
1793 add_substitute_path_rule (char *from, char *to)
1795 struct substitute_path_rule *rule;
1796 struct substitute_path_rule *new_rule = XNEW (struct substitute_path_rule);
1798 new_rule->from = xstrdup (from);
1799 new_rule->to = xstrdup (to);
1800 new_rule->next = NULL;
1802 /* If the list of rules are empty, then insert the new rule
1803 at the head of the list. */
1805 if (substitute_path_rules == NULL)
1807 substitute_path_rules = new_rule;
1811 /* Otherwise, skip to the last rule in our list and then append
1814 rule = substitute_path_rules;
1815 while (rule->next != NULL)
1818 rule->next = new_rule;
1821 /* Remove the given source path substitution rule from the current list
1822 of rules. The memory allocated for that rule is also deallocated. */
1825 delete_substitute_path_rule (struct substitute_path_rule *rule)
1827 if (rule == substitute_path_rules)
1828 substitute_path_rules = rule->next;
1831 struct substitute_path_rule *prev = substitute_path_rules;
1833 while (prev != NULL && prev->next != rule)
1836 gdb_assert (prev != NULL);
1838 prev->next = rule->next;
1846 /* Implement the "show substitute-path" command. */
1849 show_substitute_path_command (const char *args, int from_tty)
1851 struct substitute_path_rule *rule = substitute_path_rules;
1854 gdb_argv argv (args);
1856 /* We expect zero or one argument. */
1858 if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
1859 error (_("Too many arguments in command"));
1861 if (argv != NULL && argv[0] != NULL)
1864 /* Print the substitution rules. */
1868 (_("Source path substitution rule matching `%s':\n"), from);
1870 printf_filtered (_("List of all source path substitution rules:\n"));
1872 while (rule != NULL)
1874 if (from == NULL || substitute_path_rule_matches (rule, from) != 0)
1875 printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to);
1880 /* Implement the "unset substitute-path" command. */
1883 unset_substitute_path_command (const char *args, int from_tty)
1885 struct substitute_path_rule *rule = substitute_path_rules;
1886 gdb_argv argv (args);
1890 /* This function takes either 0 or 1 argument. */
1892 if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
1893 error (_("Incorrect usage, too many arguments in command"));
1895 if (argv != NULL && argv[0] != NULL)
1898 /* If the user asked for all the rules to be deleted, ask him
1899 to confirm and give him a chance to abort before the action
1903 && !query (_("Delete all source path substitution rules? ")))
1904 error (_("Canceled"));
1906 /* Delete the rule matching the argument. No argument means that
1907 all rules should be deleted. */
1909 while (rule != NULL)
1911 struct substitute_path_rule *next = rule->next;
1913 if (from == NULL || FILENAME_CMP (from, rule->from) == 0)
1915 delete_substitute_path_rule (rule);
1922 /* If the user asked for a specific rule to be deleted but
1923 we could not find it, then report an error. */
1925 if (from != NULL && !rule_found)
1926 error (_("No substitution rule defined for `%s'"), from);
1928 forget_cached_source_info ();
1931 /* Add a new source path substitution rule. */
1934 set_substitute_path_command (const char *args, int from_tty)
1936 struct substitute_path_rule *rule;
1938 gdb_argv argv (args);
1940 if (argv == NULL || argv[0] == NULL || argv [1] == NULL)
1941 error (_("Incorrect usage, too few arguments in command"));
1943 if (argv[2] != NULL)
1944 error (_("Incorrect usage, too many arguments in command"));
1946 if (*(argv[0]) == '\0')
1947 error (_("First argument must be at least one character long"));
1949 /* Strip any trailing directory separator character in either FROM
1950 or TO. The substitution rule already implicitly contains them. */
1951 strip_trailing_directory_separator (argv[0]);
1952 strip_trailing_directory_separator (argv[1]);
1954 /* If a rule with the same "from" was previously defined, then
1955 delete it. This new rule replaces it. */
1957 rule = find_substitute_path_rule (argv[0]);
1959 delete_substitute_path_rule (rule);
1961 /* Insert the new substitution rule. */
1963 add_substitute_path_rule (argv[0], argv[1]);
1964 forget_cached_source_info ();
1969 _initialize_source (void)
1971 struct cmd_list_element *c;
1973 current_source_symtab = 0;
1974 init_source_path ();
1976 /* The intention is to use POSIX Basic Regular Expressions.
1977 Always use the GNU regex routine for consistency across all hosts.
1978 Our current GNU regex.c does not have all the POSIX features, so this is
1979 just an approximation. */
1980 re_set_syntax (RE_SYNTAX_GREP);
1982 c = add_cmd ("directory", class_files, directory_command, _("\
1983 Add directory DIR to beginning of search path for source files.\n\
1984 Forget cached info on source file locations and line positions.\n\
1985 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1986 directory in which the source file was compiled into object code.\n\
1987 With no argument, reset the search path to $cdir:$cwd, the default."),
1991 add_com_alias ("use", "directory", class_files, 0);
1993 set_cmd_completer (c, filename_completer);
1995 add_setshow_optional_filename_cmd ("directories",
1999 Set the search path for finding source files."),
2001 Show the search path for finding source files."),
2003 $cwd in the path means the current working directory.\n\
2004 $cdir in the path means the compilation directory of the source file.\n\
2005 GDB ensures the search path always ends with $cdir:$cwd by\n\
2006 appending these directories if necessary.\n\
2007 Setting the value to an empty string sets it to $cdir:$cwd, the default."),
2008 set_directories_command,
2009 show_directories_command,
2010 &setlist, &showlist);
2012 add_info ("source", info_source_command,
2013 _("Information about the current source file."));
2015 add_info ("line", info_line_command, _("\
2016 Core addresses of the code for a source line.\n\
2017 Line can be specified as\n\
2018 LINENUM, to list around that line in current file,\n\
2019 FILE:LINENUM, to list around that line in that file,\n\
2020 FUNCTION, to list around beginning of that function,\n\
2021 FILE:FUNCTION, to distinguish among like-named static functions.\n\
2022 Default is to describe the last source line that was listed.\n\n\
2023 This sets the default address for \"x\" to the line's first instruction\n\
2024 so that \"x/i\" suffices to start examining the machine code.\n\
2025 The address is also stored as the value of \"$_\"."));
2027 add_com ("forward-search", class_files, forward_search_command, _("\
2028 Search for regular expression (see regex(3)) from last line listed.\n\
2029 The matching line number is also stored as the value of \"$_\"."));
2030 add_com_alias ("search", "forward-search", class_files, 0);
2031 add_com_alias ("fo", "forward-search", class_files, 1);
2033 add_com ("reverse-search", class_files, reverse_search_command, _("\
2034 Search backward for regular expression (see regex(3)) from last line listed.\n\
2035 The matching line number is also stored as the value of \"$_\"."));
2036 add_com_alias ("rev", "reverse-search", class_files, 1);
2038 add_setshow_integer_cmd ("listsize", class_support, &lines_to_list, _("\
2039 Set number of source lines gdb will list by default."), _("\
2040 Show number of source lines gdb will list by default."), _("\
2041 Use this to choose how many source lines the \"list\" displays (unless\n\
2042 the \"list\" argument explicitly specifies some other number).\n\
2043 A value of \"unlimited\", or zero, means there's no limit."),
2046 &setlist, &showlist);
2048 add_cmd ("substitute-path", class_files, set_substitute_path_command,
2050 Usage: set substitute-path FROM TO\n\
2051 Add a substitution rule replacing FROM into TO in source file names.\n\
2052 If a substitution rule was previously set for FROM, the old rule\n\
2053 is replaced by the new one."),
2056 add_cmd ("substitute-path", class_files, unset_substitute_path_command,
2058 Usage: unset substitute-path [FROM]\n\
2059 Delete the rule for substituting FROM in source file names. If FROM\n\
2060 is not specified, all substituting rules are deleted.\n\
2061 If the debugger cannot find a rule for FROM, it will display a warning."),
2064 add_cmd ("substitute-path", class_files, show_substitute_path_command,
2066 Usage: show substitute-path [FROM]\n\
2067 Print the rule for substituting FROM in source file names. If FROM\n\
2068 is not specified, print all substitution rules."),
2071 add_setshow_enum_cmd ("filename-display", class_files,
2072 filename_display_kind_names,
2073 &filename_display_string, _("\
2074 Set how to display filenames."), _("\
2075 Show how to display filenames."), _("\
2076 filename-display can be:\n\
2077 basename - display only basename of a filename\n\
2078 relative - display a filename relative to the compilation directory\n\
2079 absolute - display an absolute filename\n\
2080 By default, relative filenames are displayed."),
2082 show_filename_display_string,
2083 &setlist, &showlist);