1 /* List lines of source files for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
4 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
24 #include "expression.h"
31 #include "gdb_assert.h"
33 #include <sys/types.h>
34 #include "gdb_string.h"
38 #include "gdb_regex.h"
44 #include "filenames.h" /* for DOSish file names */
45 #include "completer.h"
47 #include "readline/readline.h"
50 #define OPEN_MODE (O_RDONLY | O_BINARY)
51 #define FDOPEN_MODE FOPEN_RB
53 /* Prototypes for exported functions. */
55 void _initialize_source (void);
57 /* Prototypes for local functions. */
59 static int get_filename_and_charpos (struct symtab
*, char **);
61 static void reverse_search_command (char *, int);
63 static void forward_search_command (char *, int);
65 static void line_info (char *, int);
67 static void source_info (char *, int);
69 static void show_directories (char *, int);
71 /* Path of directories to search for source files.
72 Same format as the PATH environment variable's value. */
76 /* Support for source path substitution commands. */
78 struct substitute_path_rule
82 struct substitute_path_rule
*next
;
85 static struct substitute_path_rule
*substitute_path_rules
= NULL
;
87 /* Symtab of default file for listing lines of. */
89 static struct symtab
*current_source_symtab
;
91 /* Default next line to list. */
93 static int current_source_line
;
95 /* Default number of lines to print with commands like "list".
96 This is based on guessing how many long (i.e. more than chars_per_line
97 characters) lines there will be. To be completely correct, "list"
98 and friends should be rewritten to count characters and see where
99 things are wrapping, but that would be a fair amount of work. */
101 int lines_to_list
= 10;
103 show_lines_to_list (struct ui_file
*file
, int from_tty
,
104 struct cmd_list_element
*c
, const char *value
)
106 fprintf_filtered (file
, _("\
107 Number of source lines gdb will list by default is %s.\n"),
111 /* Line number of last line printed. Default for various commands.
112 current_source_line is usually, but not always, the same as this. */
114 static int last_line_listed
;
116 /* First line number listed by last listing command. */
118 static int first_line_listed
;
120 /* Saves the name of the last source file visited and a possible error code.
121 Used to prevent repeating annoying "No such file or directories" msgs */
123 static struct symtab
*last_source_visited
= NULL
;
124 static int last_source_error
= 0;
126 /* Return the first line listed by print_source_lines.
127 Used by command interpreters to request listing from
131 get_first_line_listed (void)
133 return first_line_listed
;
136 /* Return the default number of lines to print with commands like the
137 cli "list". The caller of print_source_lines must use this to
138 calculate the end line and use it in the call to print_source_lines
139 as it does not automatically use this value. */
142 get_lines_to_list (void)
144 return lines_to_list
;
147 /* Return the current source file for listing and next line to list.
148 NOTE: The returned sal pc and end fields are not valid. */
150 struct symtab_and_line
151 get_current_source_symtab_and_line (void)
153 struct symtab_and_line cursal
= { 0 };
155 cursal
.symtab
= current_source_symtab
;
156 cursal
.line
= current_source_line
;
163 /* If the current source file for listing is not set, try and get a default.
164 Usually called before get_current_source_symtab_and_line() is called.
165 It may err out if a default cannot be determined.
166 We must be cautious about where it is called, as it can recurse as the
167 process of determining a new default may call the caller!
168 Use get_current_source_symtab_and_line only to get whatever
169 we have without erroring out or trying to get a default. */
172 set_default_source_symtab_and_line (void)
174 struct symtab_and_line cursal
;
176 if (!have_full_symbols () && !have_partial_symbols ())
177 error (_("No symbol table is loaded. Use the \"file\" command."));
179 /* Pull in a current source symtab if necessary */
180 if (current_source_symtab
== 0)
181 select_source_symtab (0);
184 /* Return the current default file for listing and next line to list
185 (the returned sal pc and end fields are not valid.)
186 and set the current default to whatever is in SAL.
187 NOTE: The returned sal pc and end fields are not valid. */
189 struct symtab_and_line
190 set_current_source_symtab_and_line (const struct symtab_and_line
*sal
)
192 struct symtab_and_line cursal
= { 0 };
194 cursal
.symtab
= current_source_symtab
;
195 cursal
.line
= current_source_line
;
197 current_source_symtab
= sal
->symtab
;
198 current_source_line
= sal
->line
;
205 /* Reset any information stored about a default file and line to print. */
208 clear_current_source_symtab_and_line (void)
210 current_source_symtab
= 0;
211 current_source_line
= 0;
214 /* Set the source file default for the "list" command to be S.
216 If S is NULL, and we don't have a default, find one. This
217 should only be called when the user actually tries to use the
218 default, since we produce an error if we can't find a reasonable
219 default. Also, since this can cause symbols to be read, doing it
220 before we need to would make things slower than necessary. */
223 select_source_symtab (struct symtab
*s
)
225 struct symtabs_and_lines sals
;
226 struct symtab_and_line sal
;
227 struct partial_symtab
*ps
;
228 struct partial_symtab
*cs_pst
= 0;
233 current_source_symtab
= s
;
234 current_source_line
= 1;
238 if (current_source_symtab
)
241 /* Make the default place to list be the function `main'
243 if (lookup_symbol (main_name (), 0, VAR_DOMAIN
, 0))
245 sals
= decode_line_spec (main_name (), 1);
248 current_source_symtab
= sal
.symtab
;
249 current_source_line
= max (sal
.line
- (lines_to_list
- 1), 1);
250 if (current_source_symtab
)
254 /* Alright; find the last file in the symtab list (ignoring .h's
255 and namespace symtabs). */
257 current_source_line
= 1;
259 for (ofp
= object_files
; ofp
!= NULL
; ofp
= ofp
->next
)
261 for (s
= ofp
->symtabs
; s
; s
= s
->next
)
263 const char *name
= s
->filename
;
264 int len
= strlen (name
);
265 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
266 || strcmp (name
, "<<C++-namespaces>>") == 0)))
267 current_source_symtab
= s
;
270 if (current_source_symtab
)
273 /* How about the partial symbol tables? */
275 for (ofp
= object_files
; ofp
!= NULL
; ofp
= ofp
->next
)
277 for (ps
= ofp
->psymtabs
; ps
!= NULL
; ps
= ps
->next
)
279 const char *name
= ps
->filename
;
280 int len
= strlen (name
);
281 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
282 || strcmp (name
, "<<C++-namespaces>>") == 0)))
290 internal_error (__FILE__
, __LINE__
,
291 _("select_source_symtab: "
292 "readin pst found and no symtabs."));
296 current_source_symtab
= PSYMTAB_TO_SYMTAB (cs_pst
);
299 if (current_source_symtab
)
302 error (_("Can't find a default source file"));
306 show_directories (char *ignore
, int from_tty
)
308 puts_filtered ("Source directories searched: ");
309 puts_filtered (source_path
);
310 puts_filtered ("\n");
313 /* Forget what we learned about line positions in source files, and
314 which directories contain them; must check again now since files
315 may be found in a different directory now. */
318 forget_cached_source_info (void)
321 struct objfile
*objfile
;
322 struct partial_symtab
*pst
;
324 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
->next
)
326 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
->next
)
328 if (s
->line_charpos
!= NULL
)
330 xfree (s
->line_charpos
);
331 s
->line_charpos
= NULL
;
333 if (s
->fullname
!= NULL
)
340 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
342 if (pst
->fullname
!= NULL
)
344 xfree (pst
->fullname
);
345 pst
->fullname
= NULL
;
350 last_source_visited
= NULL
;
354 init_source_path (void)
358 sprintf (buf
, "$cdir%c$cwd", DIRNAME_SEPARATOR
);
359 source_path
= xstrdup (buf
);
360 forget_cached_source_info ();
363 /* Add zero or more directories to the front of the source path. */
366 directory_command (char *dirname
, int from_tty
)
369 /* FIXME, this goes to "delete dir"... */
372 if (!from_tty
|| query (_("Reinitialize source path to empty? ")))
380 mod_path (dirname
, &source_path
);
381 forget_cached_source_info ();
384 show_directories ((char *) 0, from_tty
);
387 /* Add a path given with the -d command line switch.
388 This will not be quoted so we must not treat spaces as separators. */
391 directory_switch (char *dirname
, int from_tty
)
393 add_path (dirname
, &source_path
, 0);
396 /* Add zero or more directories to the front of an arbitrary path. */
399 mod_path (char *dirname
, char **which_path
)
401 add_path (dirname
, which_path
, 1);
404 /* Workhorse of mod_path. Takes an extra argument to determine
405 if dirname should be parsed for separators that indicate multiple
406 directories. This allows for interfaces that pre-parse the dirname
407 and allow specification of traditional separator characters such
411 add_path (char *dirname
, char **which_path
, int parse_separators
)
413 char *old
= *which_path
;
422 if (parse_separators
)
424 /* This will properly parse the space and tab separators
425 and any quotes that may exist. DIRNAME_SEPARATOR will
426 be dealt with later. */
427 argv
= gdb_buildargv (dirname
);
428 make_cleanup_freeargv (argv
);
434 arg
= xstrdup (dirname
);
435 make_cleanup (xfree
, arg
);
445 char *separator
= NULL
;
447 /* Spaces and tabs will have been removed by buildargv().
448 The directories will there be split into a list but
449 each entry may still contain DIRNAME_SEPARATOR. */
450 if (parse_separators
)
451 separator
= strchr (name
, DIRNAME_SEPARATOR
);
454 p
= arg
= name
+ strlen (name
);
459 while (*arg
== DIRNAME_SEPARATOR
)
463 /* If there are no more directories in this argument then start
464 on the next argument next time round the loop (if any). */
466 arg
= parse_separators
? argv
[++argv_index
] : NULL
;
469 /* name is the start of the directory.
470 p is the separator (or null) following the end. */
472 while (!(IS_DIR_SEPARATOR (*name
) && p
<= name
+ 1) /* "/" */
473 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
474 /* On MS-DOS and MS-Windows, h:\ is different from h: */
475 && !(p
== name
+ 3 && name
[1] == ':') /* "d:/" */
477 && IS_DIR_SEPARATOR (p
[-1]))
478 /* Sigh. "foo/" => "foo" */
482 while (p
> name
&& p
[-1] == '.')
486 /* "." => getwd (). */
487 name
= current_directory
;
490 else if (p
> name
+ 1 && IS_DIR_SEPARATOR (p
[-2]))
500 /* "...foo/." => "...foo". */
511 name
= tilde_expand (name
);
512 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
513 else if (IS_ABSOLUTE_PATH (name
) && p
== name
+ 2) /* "d:" => "d:." */
514 name
= concat (name
, ".", (char *)NULL
);
516 else if (!IS_ABSOLUTE_PATH (name
) && name
[0] != '$')
517 name
= concat (current_directory
, SLASH_STRING
, name
, (char *)NULL
);
519 name
= savestring (name
, p
- name
);
520 make_cleanup (xfree
, name
);
522 /* Unless it's a variable, check existence. */
525 /* These are warnings, not errors, since we don't want a
526 non-existent directory in a .gdbinit file to stop processing
527 of the .gdbinit file.
529 Whether they get added to the path is more debatable. Current
530 answer is yes, in case the user wants to go make the directory
531 or whatever. If the directory continues to not exist/not be
532 a directory/etc, then having them in the path should be
534 if (stat (name
, &st
) < 0)
536 int save_errno
= errno
;
537 fprintf_unfiltered (gdb_stderr
, "Warning: ");
538 print_sys_errmsg (name
, save_errno
);
540 else if ((st
.st_mode
& S_IFMT
) != S_IFDIR
)
541 warning (_("%s is not a directory."), name
);
546 unsigned int len
= strlen (name
);
551 /* FIXME: strncmp loses in interesting ways on MS-DOS and
552 MS-Windows because of case-insensitivity and two different
553 but functionally identical slash characters. We need a
554 special filesystem-dependent file-name comparison function.
556 Actually, even on Unix I would use realpath() or its work-
557 alike before comparing. Then all the code above which
558 removes excess slashes and dots could simply go away. */
559 if (!strncmp (p
, name
, len
)
560 && (p
[len
] == '\0' || p
[len
] == DIRNAME_SEPARATOR
))
562 /* Found it in the search path, remove old copy */
564 p
--; /* Back over leading separator */
565 if (prefix
> p
- *which_path
)
566 goto skip_dup
; /* Same dir twice in one cmd */
567 strcpy (p
, &p
[len
+ 1]); /* Copy from next \0 or : */
569 p
= strchr (p
, DIRNAME_SEPARATOR
);
579 tinybuf
[0] = DIRNAME_SEPARATOR
;
582 /* If we have already tacked on a name(s) in this command, be sure they stay
583 on the front as we tack on some more. */
590 temp
= concat (old
, tinybuf
, name
, (char *)NULL
);
592 *which_path
= concat (temp
, "", &old
[prefix
], (char *)NULL
);
593 prefix
= strlen (temp
);
598 *which_path
= concat (name
, (old
[0] ? tinybuf
: old
),
600 prefix
= strlen (name
);
613 source_info (char *ignore
, int from_tty
)
615 struct symtab
*s
= current_source_symtab
;
619 printf_filtered (_("No current source file.\n"));
622 printf_filtered (_("Current source file is %s\n"), s
->filename
);
624 printf_filtered (_("Compilation directory is %s\n"), s
->dirname
);
626 printf_filtered (_("Located in %s\n"), s
->fullname
);
628 printf_filtered (_("Contains %d line%s.\n"), s
->nlines
,
629 s
->nlines
== 1 ? "" : "s");
631 printf_filtered (_("Source language is %s.\n"), language_str (s
->language
));
632 printf_filtered (_("Compiled with %s debugging format.\n"), s
->debugformat
);
633 printf_filtered (_("%s preprocessor macro info.\n"),
634 s
->macro_table
? "Includes" : "Does not include");
638 /* Return True if the file NAME exists and is a regular file */
640 is_regular_file (const char *name
)
643 const int status
= stat (name
, &st
);
645 /* Stat should never fail except when the file does not exist.
646 If stat fails, analyze the source of error and return True
647 unless the file does not exist, to avoid returning false results
648 on obscure systems where stat does not work as expected.
651 return (errno
!= ENOENT
);
653 return S_ISREG (st
.st_mode
);
656 /* Open a file named STRING, searching path PATH (dir names sep by some char)
657 using mode MODE in the calls to open. You cannot use this function to
658 create files (O_CREAT).
660 OPTS specifies the function behaviour in specific cases.
662 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
663 (ie pretend the first element of PATH is "."). This also indicates
664 that a slash in STRING disables searching of the path (this is
665 so that "exec-file ./foo" or "symbol-file ./foo" insures that you
666 get that particular version of foo or an error message).
668 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
669 searched in path (we usually want this for source files but not for
672 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
673 the actual file opened (this string will always start with a "/"). We
674 have to take special pains to avoid doubling the "/" between the directory
675 and the file, sigh! Emacs gets confuzzed by this when we print the
678 If a file is found, return the descriptor.
679 Otherwise, return -1, with errno set for the last name we tried to open. */
681 /* >>>> This should only allow files of certain types,
682 >>>> eg executable, non-directory */
684 openp (const char *path
, int opts
, const char *string
,
685 int mode
, char **filename_opened
)
694 /* The open syscall MODE parameter is not specified. */
695 gdb_assert ((mode
& O_CREAT
) == 0);
702 if ((opts
& OPF_TRY_CWD_FIRST
) || IS_ABSOLUTE_PATH (string
))
706 if (is_regular_file (string
))
708 filename
= alloca (strlen (string
) + 1);
709 strcpy (filename
, string
);
710 fd
= open (filename
, mode
);
720 if (!(opts
& OPF_SEARCH_IN_PATH
))
721 for (i
= 0; string
[i
]; i
++)
722 if (IS_DIR_SEPARATOR (string
[i
]))
726 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
727 while (IS_DIR_SEPARATOR(string
[0]))
731 while (string
[0] == '.' && IS_DIR_SEPARATOR (string
[1]))
734 alloclen
= strlen (path
) + strlen (string
) + 2;
735 filename
= alloca (alloclen
);
737 for (p
= path
; p
; p
= p1
? p1
+ 1 : 0)
739 p1
= strchr (p
, DIRNAME_SEPARATOR
);
745 if (len
== 4 && p
[0] == '$' && p
[1] == 'c'
746 && p
[2] == 'w' && p
[3] == 'd')
748 /* Name is $cwd -- insert current directory name instead. */
751 /* First, realloc the filename buffer if too short. */
752 len
= strlen (current_directory
);
753 newlen
= len
+ strlen (string
) + 2;
754 if (newlen
> alloclen
)
757 filename
= alloca (alloclen
);
759 strcpy (filename
, current_directory
);
763 /* Normal file name in path -- just use it. */
764 strncpy (filename
, p
, len
);
768 /* Remove trailing slashes */
769 while (len
> 0 && IS_DIR_SEPARATOR (filename
[len
- 1]))
772 strcat (filename
+ len
, SLASH_STRING
);
773 strcat (filename
, string
);
775 if (is_regular_file (filename
))
777 fd
= open (filename
, mode
);
786 /* If a file was opened, canonicalize its filename. Use xfullpath
787 rather than gdb_realpath to avoid resolving the basename part
788 of filenames when the associated file is a symbolic link. This
789 fixes a potential inconsistency between the filenames known to
790 GDB and the filenames it prints in the annotations. */
792 *filename_opened
= NULL
;
793 else if (IS_ABSOLUTE_PATH (filename
))
794 *filename_opened
= xfullpath (filename
);
797 /* Beware the // my son, the Emacs barfs, the botch that catch... */
799 char *f
= concat (current_directory
,
800 IS_DIR_SEPARATOR (current_directory
[strlen (current_directory
) - 1])
802 filename
, (char *)NULL
);
803 *filename_opened
= xfullpath (f
);
812 /* This is essentially a convenience, for clients that want the behaviour
813 of openp, using source_path, but that really don't want the file to be
814 opened but want instead just to know what the full pathname is (as
815 qualified against source_path).
817 The current working directory is searched first.
819 If the file was found, this function returns 1, and FULL_PATHNAME is
820 set to the fully-qualified pathname.
822 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
824 source_full_path_of (const char *filename
, char **full_pathname
)
828 fd
= openp (source_path
, OPF_TRY_CWD_FIRST
| OPF_SEARCH_IN_PATH
, filename
,
829 O_RDONLY
, full_pathname
);
832 *full_pathname
= NULL
;
840 /* Return non-zero if RULE matches PATH, that is if the rule can be
844 substitute_path_rule_matches (const struct substitute_path_rule
*rule
,
847 const int from_len
= strlen (rule
->from
);
848 const int path_len
= strlen (path
);
851 if (path_len
< from_len
)
854 /* The substitution rules are anchored at the start of the path,
855 so the path should start with rule->from. There is no filename
856 comparison routine, so we need to extract the first FROM_LEN
857 characters from PATH first and use that to do the comparison. */
859 path_start
= alloca (from_len
+ 1);
860 strncpy (path_start
, path
, from_len
);
861 path_start
[from_len
] = '\0';
863 if (FILENAME_CMP (path_start
, rule
->from
) != 0)
866 /* Make sure that the region in the path that matches the substitution
867 rule is immediately followed by a directory separator (or the end of
868 string character). */
870 if (path
[from_len
] != '\0' && !IS_DIR_SEPARATOR (path
[from_len
]))
876 /* Find the substitute-path rule that applies to PATH and return it.
877 Return NULL if no rule applies. */
879 static struct substitute_path_rule
*
880 get_substitute_path_rule (const char *path
)
882 struct substitute_path_rule
*rule
= substitute_path_rules
;
884 while (rule
!= NULL
&& !substitute_path_rule_matches (rule
, path
))
890 /* If the user specified a source path substitution rule that applies
891 to PATH, then apply it and return the new path. This new path must
892 be deallocated afterwards.
894 Return NULL if no substitution rule was specified by the user,
895 or if no rule applied to the given PATH. */
898 rewrite_source_path (const char *path
)
900 const struct substitute_path_rule
*rule
= get_substitute_path_rule (path
);
907 from_len
= strlen (rule
->from
);
909 /* Compute the rewritten path and return it. */
912 (char *) xmalloc (strlen (path
) + 1 + strlen (rule
->to
) - from_len
);
913 strcpy (new_path
, rule
->to
);
914 strcat (new_path
, path
+ from_len
);
919 /* This function is capable of finding the absolute path to a
920 source file, and opening it, provided you give it a FILENAME. Both the
921 DIRNAME and FULLNAME are only added suggestions on where to find the file.
923 FILENAME should be the filename to open.
924 DIRNAME is the compilation directory of a particular source file.
925 Only some debug formats provide this info.
926 FULLNAME can be the last known absolute path to the file in question.
927 Space for the path must have been malloc'd. If a path substitution
928 is applied we free the old value and set a new one.
931 A valid file descriptor is returned. ( the return value is positive )
932 FULLNAME is set to the absolute path to the file just opened.
933 The caller is responsible for freeing FULLNAME.
936 An invalid file descriptor is returned. ( the return value is negative )
937 FULLNAME is set to NULL. */
940 find_and_open_source (const char *filename
,
944 char *path
= source_path
;
948 /* Quick way out if we already know its full name */
952 /* The user may have requested that source paths be rewritten
953 according to substitution rules he provided. If a substitution
954 rule applies to this path, then apply it. */
955 char *rewritten_fullname
= rewrite_source_path (*fullname
);
957 if (rewritten_fullname
!= NULL
)
960 *fullname
= rewritten_fullname
;
963 result
= open (*fullname
, OPEN_MODE
);
966 /* Didn't work -- free old one, try again. */
973 /* If necessary, rewrite the compilation directory name according
974 to the source path substitution rules specified by the user. */
976 char *rewritten_dirname
= rewrite_source_path (dirname
);
978 if (rewritten_dirname
!= NULL
)
980 make_cleanup (xfree
, rewritten_dirname
);
981 dirname
= rewritten_dirname
;
984 /* Replace a path entry of $cdir with the compilation directory name */
986 /* We cast strstr's result in case an ANSIhole has made it const,
987 which produces a "required warning" when assigned to a nonconst. */
988 p
= (char *) strstr (source_path
, "$cdir");
989 if (p
&& (p
== path
|| p
[-1] == DIRNAME_SEPARATOR
)
990 && (p
[cdir_len
] == DIRNAME_SEPARATOR
|| p
[cdir_len
] == '\0'))
995 alloca (strlen (source_path
) + 1 + strlen (dirname
) + 1);
996 len
= p
- source_path
;
997 strncpy (path
, source_path
, len
); /* Before $cdir */
998 strcpy (path
+ len
, dirname
); /* new stuff */
999 strcat (path
+ len
, source_path
+ len
+ cdir_len
); /* After $cdir */
1003 if (IS_ABSOLUTE_PATH (filename
))
1005 /* If filename is absolute path, try the source path
1006 substitution on it. */
1007 char *rewritten_filename
= rewrite_source_path (filename
);
1009 if (rewritten_filename
!= NULL
)
1011 make_cleanup (xfree
, rewritten_filename
);
1012 filename
= rewritten_filename
;
1016 result
= openp (path
, OPF_SEARCH_IN_PATH
, filename
, OPEN_MODE
, fullname
);
1019 /* Didn't work. Try using just the basename. */
1020 p
= lbasename (filename
);
1022 result
= openp (path
, OPF_SEARCH_IN_PATH
, p
, OPEN_MODE
, fullname
);
1028 /* Open a source file given a symtab S. Returns a file descriptor or
1029 negative number for error.
1031 This function is a convience function to find_and_open_source. */
1034 open_source_file (struct symtab
*s
)
1039 return find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1042 /* Finds the fullname that a symtab represents.
1044 If this functions finds the fullname, it will save it in s->fullname
1045 and it will also return the value.
1047 If this function fails to find the file that this symtab represents,
1048 NULL will be returned and s->fullname will be set to NULL. */
1050 symtab_to_fullname (struct symtab
*s
)
1057 /* Don't check s->fullname here, the file could have been
1058 deleted/moved/..., look for it again */
1059 r
= find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1070 /* Finds the fullname that a partial_symtab represents.
1072 If this functions finds the fullname, it will save it in ps->fullname
1073 and it will also return the value.
1075 If this function fails to find the file that this partial_symtab represents,
1076 NULL will be returned and ps->fullname will be set to NULL. */
1078 psymtab_to_fullname (struct partial_symtab
*ps
)
1085 /* Don't check ps->fullname here, the file could have been
1086 deleted/moved/..., look for it again */
1087 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1092 return ps
->fullname
;
1098 /* Create and initialize the table S->line_charpos that records
1099 the positions of the lines in the source file, which is assumed
1100 to be open on descriptor DESC.
1101 All set S->nlines to the number of such lines. */
1104 find_source_lines (struct symtab
*s
, int desc
)
1107 char *data
, *p
, *end
;
1109 int lines_allocated
= 1000;
1115 line_charpos
= (int *) xmalloc (lines_allocated
* sizeof (int));
1116 if (fstat (desc
, &st
) < 0)
1117 perror_with_name (s
->filename
);
1119 if (s
->objfile
&& s
->objfile
->obfd
)
1120 mtime
= s
->objfile
->mtime
;
1122 mtime
= exec_bfd_mtime
;
1124 if (mtime
&& mtime
< st
.st_mtime
)
1125 warning (_("Source file is more recent than executable."));
1127 #ifdef LSEEK_NOT_LINEAR
1131 /* Have to read it byte by byte to find out where the chars live */
1133 line_charpos
[0] = lseek (desc
, 0, SEEK_CUR
);
1135 while (myread (desc
, &c
, 1) > 0)
1139 if (nlines
== lines_allocated
)
1141 lines_allocated
*= 2;
1143 (int *) xrealloc ((char *) line_charpos
,
1144 sizeof (int) * lines_allocated
);
1146 line_charpos
[nlines
++] = lseek (desc
, 0, SEEK_CUR
);
1150 #else /* lseek linear. */
1152 struct cleanup
*old_cleanups
;
1154 /* st_size might be a large type, but we only support source files whose
1155 size fits in an int. */
1156 size
= (int) st
.st_size
;
1158 /* Use malloc, not alloca, because this may be pretty large, and we may
1159 run into various kinds of limits on stack size. */
1160 data
= (char *) xmalloc (size
);
1161 old_cleanups
= make_cleanup (xfree
, data
);
1163 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1164 size
= myread (desc
, data
, size
);
1166 perror_with_name (s
->filename
);
1169 line_charpos
[0] = 0;
1174 /* A newline at the end does not start a new line. */
1177 if (nlines
== lines_allocated
)
1179 lines_allocated
*= 2;
1181 (int *) xrealloc ((char *) line_charpos
,
1182 sizeof (int) * lines_allocated
);
1184 line_charpos
[nlines
++] = p
- data
;
1187 do_cleanups (old_cleanups
);
1189 #endif /* lseek linear. */
1192 (int *) xrealloc ((char *) line_charpos
, nlines
* sizeof (int));
1196 /* Return the character position of a line LINE in symtab S.
1197 Return 0 if anything is invalid. */
1199 #if 0 /* Currently unused */
1202 source_line_charpos (struct symtab
*s
, int line
)
1206 if (!s
->line_charpos
|| line
<= 0)
1208 if (line
> s
->nlines
)
1210 return s
->line_charpos
[line
- 1];
1213 /* Return the line number of character position POS in symtab S. */
1216 source_charpos_line (struct symtab
*s
, int chr
)
1221 if (s
== 0 || s
->line_charpos
== 0)
1223 lnp
= s
->line_charpos
;
1224 /* Files are usually short, so sequential search is Ok */
1225 while (line
< s
->nlines
&& *lnp
<= chr
)
1230 if (line
>= s
->nlines
)
1238 /* Get full pathname and line number positions for a symtab.
1239 Return nonzero if line numbers may have changed.
1240 Set *FULLNAME to actual name of the file as found by `openp',
1241 or to 0 if the file is not found. */
1244 get_filename_and_charpos (struct symtab
*s
, char **fullname
)
1246 int desc
, linenums_changed
= 0;
1247 struct cleanup
*cleanups
;
1249 desc
= open_source_file (s
);
1256 cleanups
= make_cleanup_close (desc
);
1258 *fullname
= s
->fullname
;
1259 if (s
->line_charpos
== 0)
1260 linenums_changed
= 1;
1261 if (linenums_changed
)
1262 find_source_lines (s
, desc
);
1263 do_cleanups (cleanups
);
1264 return linenums_changed
;
1267 /* Print text describing the full name of the source file S
1268 and the line number LINE and its corresponding character position.
1269 The text starts with two Ctrl-z so that the Emacs-GDB interface
1272 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1274 Return 1 if successful, 0 if could not find the file. */
1277 identify_source_line (struct symtab
*s
, int line
, int mid_statement
,
1280 if (s
->line_charpos
== 0)
1281 get_filename_and_charpos (s
, (char **) NULL
);
1282 if (s
->fullname
== 0)
1284 if (line
> s
->nlines
)
1285 /* Don't index off the end of the line_charpos array. */
1287 annotate_source (s
->fullname
, line
, s
->line_charpos
[line
- 1],
1288 mid_statement
, get_objfile_arch (s
->objfile
), pc
);
1290 current_source_line
= line
;
1291 first_line_listed
= line
;
1292 last_line_listed
= line
;
1293 current_source_symtab
= s
;
1298 /* Print source lines from the file of symtab S,
1299 starting with line number LINE and stopping before line number STOPLINE. */
1301 static void print_source_lines_base (struct symtab
*s
, int line
, int stopline
,
1304 print_source_lines_base (struct symtab
*s
, int line
, int stopline
, int noerror
)
1309 int nlines
= stopline
- line
;
1310 struct cleanup
*cleanup
;
1312 /* Regardless of whether we can open the file, set current_source_symtab. */
1313 current_source_symtab
= s
;
1314 current_source_line
= line
;
1315 first_line_listed
= line
;
1317 /* If printing of source lines is disabled, just print file and line number */
1318 if (ui_out_test_flags (uiout
, ui_source_list
))
1320 /* Only prints "No such file or directory" once */
1321 if ((s
!= last_source_visited
) || (!last_source_error
))
1323 last_source_visited
= s
;
1324 desc
= open_source_file (s
);
1328 desc
= last_source_error
;
1340 last_source_error
= desc
;
1344 char *name
= alloca (strlen (s
->filename
) + 100);
1345 sprintf (name
, "%d\t%s", line
, s
->filename
);
1346 print_sys_errmsg (name
, errno
);
1349 ui_out_field_int (uiout
, "line", line
);
1350 ui_out_text (uiout
, "\tin ");
1351 ui_out_field_string (uiout
, "file", s
->filename
);
1352 ui_out_text (uiout
, "\n");
1357 last_source_error
= 0;
1359 if (s
->line_charpos
== 0)
1360 find_source_lines (s
, desc
);
1362 if (line
< 1 || line
> s
->nlines
)
1365 error (_("Line number %d out of range; %s has %d lines."),
1366 line
, s
->filename
, s
->nlines
);
1369 if (lseek (desc
, s
->line_charpos
[line
- 1], 0) < 0)
1372 perror_with_name (s
->filename
);
1375 stream
= fdopen (desc
, FDOPEN_MODE
);
1377 cleanup
= make_cleanup_fclose (stream
);
1379 while (nlines
-- > 0)
1386 last_line_listed
= current_source_line
;
1387 sprintf (buf
, "%d\t", current_source_line
++);
1388 ui_out_text (uiout
, buf
);
1391 if (c
< 040 && c
!= '\t' && c
!= '\n' && c
!= '\r')
1393 sprintf (buf
, "^%c", c
+ 0100);
1394 ui_out_text (uiout
, buf
);
1397 ui_out_text (uiout
, "^?");
1400 /* Skip a \r character, but only before a \n. */
1401 int c1
= fgetc (stream
);
1404 printf_filtered ("^%c", c
+ 0100);
1406 ungetc (c1
, stream
);
1410 sprintf (buf
, "%c", c
);
1411 ui_out_text (uiout
, buf
);
1414 while (c
!= '\n' && (c
= fgetc (stream
)) >= 0);
1417 do_cleanups (cleanup
);
1420 /* Show source lines from the file of symtab S, starting with line
1421 number LINE and stopping before line number STOPLINE. If this is
1422 not the command line version, then the source is shown in the source
1423 window otherwise it is simply printed */
1426 print_source_lines (struct symtab
*s
, int line
, int stopline
, int noerror
)
1428 print_source_lines_base (s
, line
, stopline
, noerror
);
1431 /* Print info on range of pc's in a specified line. */
1434 line_info (char *arg
, int from_tty
)
1436 struct symtabs_and_lines sals
;
1437 struct symtab_and_line sal
;
1438 CORE_ADDR start_pc
, end_pc
;
1441 init_sal (&sal
); /* initialize to zeroes */
1445 sal
.symtab
= current_source_symtab
;
1446 sal
.line
= last_line_listed
;
1448 sals
.sals
= (struct symtab_and_line
*)
1449 xmalloc (sizeof (struct symtab_and_line
));
1454 sals
= decode_line_spec_1 (arg
, 0);
1459 /* C++ More than one line may have been specified, as when the user
1460 specifies an overloaded function name. Print info on them all. */
1461 for (i
= 0; i
< sals
.nelts
; i
++)
1465 if (sal
.symtab
== 0)
1467 struct gdbarch
*gdbarch
= get_current_arch ();
1469 printf_filtered (_("No line number information available"));
1472 /* This is useful for "info line *0x7f34". If we can't tell the
1473 user about a source line, at least let them have the symbolic
1475 printf_filtered (" for address ");
1477 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1480 printf_filtered (".");
1481 printf_filtered ("\n");
1483 else if (sal
.line
> 0
1484 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1486 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1488 if (start_pc
== end_pc
)
1490 printf_filtered ("Line %d of \"%s\"",
1491 sal
.line
, sal
.symtab
->filename
);
1493 printf_filtered (" is at address ");
1494 print_address (gdbarch
, start_pc
, gdb_stdout
);
1496 printf_filtered (" but contains no code.\n");
1500 printf_filtered ("Line %d of \"%s\"",
1501 sal
.line
, sal
.symtab
->filename
);
1503 printf_filtered (" starts at address ");
1504 print_address (gdbarch
, start_pc
, gdb_stdout
);
1506 printf_filtered (" and ends at ");
1507 print_address (gdbarch
, end_pc
, gdb_stdout
);
1508 printf_filtered (".\n");
1511 /* x/i should display this line's code. */
1512 set_next_address (gdbarch
, start_pc
);
1514 /* Repeating "info line" should do the following line. */
1515 last_line_listed
= sal
.line
+ 1;
1517 /* If this is the only line, show the source code. If it could
1518 not find the file, don't do anything special. */
1519 if (annotation_level
&& sals
.nelts
== 1)
1520 identify_source_line (sal
.symtab
, sal
.line
, 0, start_pc
);
1523 /* Is there any case in which we get here, and have an address
1524 which the user would want to see? If we have debugging symbols
1525 and no line numbers? */
1526 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
1527 sal
.line
, sal
.symtab
->filename
);
1532 /* Commands to search the source file for a regexp. */
1535 forward_search_command (char *regex
, int from_tty
)
1542 struct cleanup
*cleanups
;
1544 line
= last_line_listed
+ 1;
1546 msg
= (char *) re_comp (regex
);
1548 error (("%s"), msg
);
1550 if (current_source_symtab
== 0)
1551 select_source_symtab (0);
1553 desc
= open_source_file (current_source_symtab
);
1555 perror_with_name (current_source_symtab
->filename
);
1556 cleanups
= make_cleanup_close (desc
);
1558 if (current_source_symtab
->line_charpos
== 0)
1559 find_source_lines (current_source_symtab
, desc
);
1561 if (line
< 1 || line
> current_source_symtab
->nlines
)
1562 error (_("Expression not found"));
1564 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1565 perror_with_name (current_source_symtab
->filename
);
1567 discard_cleanups (cleanups
);
1568 stream
= fdopen (desc
, FDOPEN_MODE
);
1570 cleanups
= make_cleanup_fclose (stream
);
1573 static char *buf
= NULL
;
1575 int cursize
, newsize
;
1578 buf
= xmalloc (cursize
);
1587 if (p
- buf
== cursize
)
1589 newsize
= cursize
+ cursize
/ 2;
1590 buf
= xrealloc (buf
, newsize
);
1595 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1597 /* Remove the \r, if any, at the end of the line, otherwise
1598 regular expressions that end with $ or \n won't work. */
1599 if (p
- buf
> 1 && p
[-2] == '\r')
1605 /* we now have a source line in buf, null terminate and match */
1607 if (re_exec (buf
) > 0)
1610 do_cleanups (cleanups
);
1611 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1612 set_internalvar_integer (lookup_internalvar ("_"), line
);
1613 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1619 printf_filtered (_("Expression not found\n"));
1620 do_cleanups (cleanups
);
1624 reverse_search_command (char *regex
, int from_tty
)
1631 struct cleanup
*cleanups
;
1633 line
= last_line_listed
- 1;
1635 msg
= (char *) re_comp (regex
);
1637 error (("%s"), msg
);
1639 if (current_source_symtab
== 0)
1640 select_source_symtab (0);
1642 desc
= open_source_file (current_source_symtab
);
1644 perror_with_name (current_source_symtab
->filename
);
1645 cleanups
= make_cleanup_close (desc
);
1647 if (current_source_symtab
->line_charpos
== 0)
1648 find_source_lines (current_source_symtab
, desc
);
1650 if (line
< 1 || line
> current_source_symtab
->nlines
)
1651 error (_("Expression not found"));
1653 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1654 perror_with_name (current_source_symtab
->filename
);
1656 discard_cleanups (cleanups
);
1657 stream
= fdopen (desc
, FDOPEN_MODE
);
1659 cleanups
= make_cleanup_fclose (stream
);
1662 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1663 char buf
[4096]; /* Should be reasonable??? */
1673 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1675 /* Remove the \r, if any, at the end of the line, otherwise
1676 regular expressions that end with $ or \n won't work. */
1677 if (p
- buf
> 1 && p
[-2] == '\r')
1683 /* We now have a source line in buf; null terminate and match. */
1685 if (re_exec (buf
) > 0)
1688 do_cleanups (cleanups
);
1689 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1690 set_internalvar_integer (lookup_internalvar ("_"), line
);
1691 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1695 if (fseek (stream
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1697 do_cleanups (cleanups
);
1698 perror_with_name (current_source_symtab
->filename
);
1702 printf_filtered (_("Expression not found\n"));
1703 do_cleanups (cleanups
);
1707 /* If the last character of PATH is a directory separator, then strip it. */
1710 strip_trailing_directory_separator (char *path
)
1712 const int last
= strlen (path
) - 1;
1715 return; /* No stripping is needed if PATH is the empty string. */
1717 if (IS_DIR_SEPARATOR (path
[last
]))
1721 /* Return the path substitution rule that matches FROM.
1722 Return NULL if no rule matches. */
1724 static struct substitute_path_rule
*
1725 find_substitute_path_rule (const char *from
)
1727 struct substitute_path_rule
*rule
= substitute_path_rules
;
1729 while (rule
!= NULL
)
1731 if (FILENAME_CMP (rule
->from
, from
) == 0)
1739 /* Add a new substitute-path rule at the end of the current list of rules.
1740 The new rule will replace FROM into TO. */
1743 add_substitute_path_rule (char *from
, char *to
)
1745 struct substitute_path_rule
*rule
;
1746 struct substitute_path_rule
*new_rule
;
1748 new_rule
= xmalloc (sizeof (struct substitute_path_rule
));
1749 new_rule
->from
= xstrdup (from
);
1750 new_rule
->to
= xstrdup (to
);
1751 new_rule
->next
= NULL
;
1753 /* If the list of rules are empty, then insert the new rule
1754 at the head of the list. */
1756 if (substitute_path_rules
== NULL
)
1758 substitute_path_rules
= new_rule
;
1762 /* Otherwise, skip to the last rule in our list and then append
1765 rule
= substitute_path_rules
;
1766 while (rule
->next
!= NULL
)
1769 rule
->next
= new_rule
;
1772 /* Remove the given source path substitution rule from the current list
1773 of rules. The memory allocated for that rule is also deallocated. */
1776 delete_substitute_path_rule (struct substitute_path_rule
*rule
)
1778 if (rule
== substitute_path_rules
)
1779 substitute_path_rules
= rule
->next
;
1782 struct substitute_path_rule
*prev
= substitute_path_rules
;
1784 while (prev
!= NULL
&& prev
->next
!= rule
)
1787 gdb_assert (prev
!= NULL
);
1789 prev
->next
= rule
->next
;
1797 /* Implement the "show substitute-path" command. */
1800 show_substitute_path_command (char *args
, int from_tty
)
1802 struct substitute_path_rule
*rule
= substitute_path_rules
;
1806 argv
= gdb_buildargv (args
);
1807 make_cleanup_freeargv (argv
);
1809 /* We expect zero or one argument. */
1811 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1812 error (_("Too many arguments in command"));
1814 if (argv
!= NULL
&& argv
[0] != NULL
)
1817 /* Print the substitution rules. */
1821 (_("Source path substitution rule matching `%s':\n"), from
);
1823 printf_filtered (_("List of all source path substitution rules:\n"));
1825 while (rule
!= NULL
)
1827 if (from
== NULL
|| FILENAME_CMP (rule
->from
, from
) == 0)
1828 printf_filtered (" `%s' -> `%s'.\n", rule
->from
, rule
->to
);
1833 /* Implement the "unset substitute-path" command. */
1836 unset_substitute_path_command (char *args
, int from_tty
)
1838 struct substitute_path_rule
*rule
= substitute_path_rules
;
1839 char **argv
= gdb_buildargv (args
);
1843 /* This function takes either 0 or 1 argument. */
1845 make_cleanup_freeargv (argv
);
1846 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1847 error (_("Incorrect usage, too many arguments in command"));
1849 if (argv
!= NULL
&& argv
[0] != NULL
)
1852 /* If the user asked for all the rules to be deleted, ask him
1853 to confirm and give him a chance to abort before the action
1857 && !query (_("Delete all source path substitution rules? ")))
1858 error (_("Canceled"));
1860 /* Delete the rule matching the argument. No argument means that
1861 all rules should be deleted. */
1863 while (rule
!= NULL
)
1865 struct substitute_path_rule
*next
= rule
->next
;
1867 if (from
== NULL
|| FILENAME_CMP (from
, rule
->from
) == 0)
1869 delete_substitute_path_rule (rule
);
1876 /* If the user asked for a specific rule to be deleted but
1877 we could not find it, then report an error. */
1879 if (from
!= NULL
&& !rule_found
)
1880 error (_("No substitution rule defined for `%s'"), from
);
1882 forget_cached_source_info ();
1885 /* Add a new source path substitution rule. */
1888 set_substitute_path_command (char *args
, int from_tty
)
1890 char *from_path
, *to_path
;
1892 struct substitute_path_rule
*rule
;
1894 argv
= gdb_buildargv (args
);
1895 make_cleanup_freeargv (argv
);
1897 if (argv
== NULL
|| argv
[0] == NULL
|| argv
[1] == NULL
)
1898 error (_("Incorrect usage, too few arguments in command"));
1900 if (argv
[2] != NULL
)
1901 error (_("Incorrect usage, too many arguments in command"));
1903 if (*(argv
[0]) == '\0')
1904 error (_("First argument must be at least one character long"));
1906 /* Strip any trailing directory separator character in either FROM
1907 or TO. The substitution rule already implicitly contains them. */
1908 strip_trailing_directory_separator (argv
[0]);
1909 strip_trailing_directory_separator (argv
[1]);
1911 /* If a rule with the same "from" was previously defined, then
1912 delete it. This new rule replaces it. */
1914 rule
= find_substitute_path_rule (argv
[0]);
1916 delete_substitute_path_rule (rule
);
1918 /* Insert the new substitution rule. */
1920 add_substitute_path_rule (argv
[0], argv
[1]);
1921 forget_cached_source_info ();
1926 _initialize_source (void)
1928 struct cmd_list_element
*c
;
1929 current_source_symtab
= 0;
1930 init_source_path ();
1932 /* The intention is to use POSIX Basic Regular Expressions.
1933 Always use the GNU regex routine for consistency across all hosts.
1934 Our current GNU regex.c does not have all the POSIX features, so this is
1935 just an approximation. */
1936 re_set_syntax (RE_SYNTAX_GREP
);
1938 c
= add_cmd ("directory", class_files
, directory_command
, _("\
1939 Add directory DIR to beginning of search path for source files.\n\
1940 Forget cached info on source file locations and line positions.\n\
1941 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1942 directory in which the source file was compiled into object code.\n\
1943 With no argument, reset the search path to $cdir:$cwd, the default."),
1947 add_com_alias ("use", "directory", class_files
, 0);
1949 set_cmd_completer (c
, filename_completer
);
1951 add_cmd ("directories", no_class
, show_directories
, _("\
1952 Current search path for finding source files.\n\
1953 $cwd in the path means the current working directory.\n\
1954 $cdir in the path means the compilation directory of the source file."),
1959 add_com_alias ("D", "directory", class_files
, 0);
1960 add_cmd ("ld", no_class
, show_directories
, _("\
1961 Current search path for finding source files.\n\
1962 $cwd in the path means the current working directory.\n\
1963 $cdir in the path means the compilation directory of the source file."),
1967 add_info ("source", source_info
,
1968 _("Information about the current source file."));
1970 add_info ("line", line_info
, _("\
1971 Core addresses of the code for a source line.\n\
1972 Line can be specified as\n\
1973 LINENUM, to list around that line in current file,\n\
1974 FILE:LINENUM, to list around that line in that file,\n\
1975 FUNCTION, to list around beginning of that function,\n\
1976 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1977 Default is to describe the last source line that was listed.\n\n\
1978 This sets the default address for \"x\" to the line's first instruction\n\
1979 so that \"x/i\" suffices to start examining the machine code.\n\
1980 The address is also stored as the value of \"$_\"."));
1982 add_com ("forward-search", class_files
, forward_search_command
, _("\
1983 Search for regular expression (see regex(3)) from last line listed.\n\
1984 The matching line number is also stored as the value of \"$_\"."));
1985 add_com_alias ("search", "forward-search", class_files
, 0);
1987 add_com ("reverse-search", class_files
, reverse_search_command
, _("\
1988 Search backward for regular expression (see regex(3)) from last line listed.\n\
1989 The matching line number is also stored as the value of \"$_\"."));
1993 add_com_alias ("/", "forward-search", class_files
, 0);
1994 add_com_alias ("?", "reverse-search", class_files
, 0);
1997 add_setshow_integer_cmd ("listsize", class_support
, &lines_to_list
, _("\
1998 Set number of source lines gdb will list by default."), _("\
1999 Show number of source lines gdb will list by default."), NULL
,
2002 &setlist
, &showlist
);
2004 add_cmd ("substitute-path", class_files
, set_substitute_path_command
,
2006 Usage: set substitute-path FROM TO\n\
2007 Add a substitution rule replacing FROM into TO in source file names.\n\
2008 If a substitution rule was previously set for FROM, the old rule\n\
2009 is replaced by the new one."),
2012 add_cmd ("substitute-path", class_files
, unset_substitute_path_command
,
2014 Usage: unset substitute-path [FROM]\n\
2015 Delete the rule for substituting FROM in source file names. If FROM\n\
2016 is not specified, all substituting rules are deleted.\n\
2017 If the debugger cannot find a rule for FROM, it will display a warning."),
2020 add_cmd ("substitute-path", class_files
, show_substitute_path_command
,
2022 Usage: show substitute-path [FROM]\n\
2023 Print the rule for substituting FROM in source file names. If FROM\n\
2024 is not specified, print all substitution rules."),