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, 2010 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"
52 #define OPEN_MODE (O_RDONLY | O_BINARY)
53 #define FDOPEN_MODE FOPEN_RB
55 /* Prototypes for exported functions. */
57 void _initialize_source (void);
59 /* Prototypes for local functions. */
61 static int get_filename_and_charpos (struct symtab
*, char **);
63 static void reverse_search_command (char *, int);
65 static void forward_search_command (char *, int);
67 static void line_info (char *, int);
69 static void source_info (char *, int);
71 static void show_directories (char *, int);
73 /* Path of directories to search for source files.
74 Same format as the PATH environment variable's value. */
78 /* Support for source path substitution commands. */
80 struct substitute_path_rule
84 struct substitute_path_rule
*next
;
87 static struct substitute_path_rule
*substitute_path_rules
= NULL
;
89 /* Symtab of default file for listing lines of. */
91 static struct symtab
*current_source_symtab
;
93 /* Default next line to list. */
95 static int current_source_line
;
97 static struct program_space
*current_source_pspace
;
99 /* Default number of lines to print with commands like "list".
100 This is based on guessing how many long (i.e. more than chars_per_line
101 characters) lines there will be. To be completely correct, "list"
102 and friends should be rewritten to count characters and see where
103 things are wrapping, but that would be a fair amount of work. */
105 int lines_to_list
= 10;
107 show_lines_to_list (struct ui_file
*file
, int from_tty
,
108 struct cmd_list_element
*c
, const char *value
)
110 fprintf_filtered (file
, _("\
111 Number of source lines gdb will list by default is %s.\n"),
115 /* Line number of last line printed. Default for various commands.
116 current_source_line is usually, but not always, the same as this. */
118 static int last_line_listed
;
120 /* First line number listed by last listing command. */
122 static int first_line_listed
;
124 /* Saves the name of the last source file visited and a possible error code.
125 Used to prevent repeating annoying "No such file or directories" msgs */
127 static struct symtab
*last_source_visited
= NULL
;
128 static int last_source_error
= 0;
130 /* Return the first line listed by print_source_lines.
131 Used by command interpreters to request listing from
135 get_first_line_listed (void)
137 return first_line_listed
;
140 /* Return the default number of lines to print with commands like the
141 cli "list". The caller of print_source_lines must use this to
142 calculate the end line and use it in the call to print_source_lines
143 as it does not automatically use this value. */
146 get_lines_to_list (void)
148 return lines_to_list
;
151 /* Return the current source file for listing and next line to list.
152 NOTE: The returned sal pc and end fields are not valid. */
154 struct symtab_and_line
155 get_current_source_symtab_and_line (void)
157 struct symtab_and_line cursal
= { 0 };
159 cursal
.pspace
= current_source_pspace
;
160 cursal
.symtab
= current_source_symtab
;
161 cursal
.line
= current_source_line
;
168 /* If the current source file for listing is not set, try and get a default.
169 Usually called before get_current_source_symtab_and_line() is called.
170 It may err out if a default cannot be determined.
171 We must be cautious about where it is called, as it can recurse as the
172 process of determining a new default may call the caller!
173 Use get_current_source_symtab_and_line only to get whatever
174 we have without erroring out or trying to get a default. */
177 set_default_source_symtab_and_line (void)
179 struct symtab_and_line cursal
;
181 if (!have_full_symbols () && !have_partial_symbols ())
182 error (_("No symbol table is loaded. Use the \"file\" command."));
184 /* Pull in a current source symtab if necessary */
185 if (current_source_symtab
== 0)
186 select_source_symtab (0);
189 /* Return the current default file for listing and next line to list
190 (the returned sal pc and end fields are not valid.)
191 and set the current default to whatever is in SAL.
192 NOTE: The returned sal pc and end fields are not valid. */
194 struct symtab_and_line
195 set_current_source_symtab_and_line (const struct symtab_and_line
*sal
)
197 struct symtab_and_line cursal
= { 0 };
199 cursal
.pspace
= current_source_pspace
;
200 cursal
.symtab
= current_source_symtab
;
201 cursal
.line
= current_source_line
;
205 current_source_pspace
= sal
->pspace
;
206 current_source_symtab
= sal
->symtab
;
207 current_source_line
= sal
->line
;
212 /* Reset any information stored about a default file and line to print. */
215 clear_current_source_symtab_and_line (void)
217 current_source_symtab
= 0;
218 current_source_line
= 0;
221 /* Set the source file default for the "list" command to be S.
223 If S is NULL, and we don't have a default, find one. This
224 should only be called when the user actually tries to use the
225 default, since we produce an error if we can't find a reasonable
226 default. Also, since this can cause symbols to be read, doing it
227 before we need to would make things slower than necessary. */
230 select_source_symtab (struct symtab
*s
)
232 struct symtabs_and_lines sals
;
233 struct symtab_and_line sal
;
238 current_source_symtab
= s
;
239 current_source_line
= 1;
240 current_source_pspace
= SYMTAB_PSPACE (s
);
244 if (current_source_symtab
)
247 /* Make the default place to list be the function `main'
249 if (lookup_symbol (main_name (), 0, VAR_DOMAIN
, 0))
251 sals
= decode_line_spec (main_name (), 1);
254 current_source_pspace
= sal
.pspace
;
255 current_source_symtab
= sal
.symtab
;
256 current_source_line
= max (sal
.line
- (lines_to_list
- 1), 1);
257 if (current_source_symtab
)
261 /* Alright; find the last file in the symtab list (ignoring .h's
262 and namespace symtabs). */
264 current_source_line
= 1;
268 for (s
= ofp
->symtabs
; s
; s
= s
->next
)
270 const char *name
= s
->filename
;
271 int len
= strlen (name
);
272 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
273 || strcmp (name
, "<<C++-namespaces>>") == 0)))
275 current_source_pspace
= current_program_space
;
276 current_source_symtab
= s
;
281 if (current_source_symtab
)
287 s
= ofp
->sf
->qf
->find_last_source_symtab (ofp
);
289 current_source_symtab
= s
;
291 if (current_source_symtab
)
294 error (_("Can't find a default source file"));
298 show_directories (char *ignore
, int from_tty
)
300 puts_filtered ("Source directories searched: ");
301 puts_filtered (source_path
);
302 puts_filtered ("\n");
305 /* Forget what we learned about line positions in source files, and
306 which directories contain them; must check again now since files
307 may be found in a different directory now. */
310 forget_cached_source_info (void)
312 struct program_space
*pspace
;
314 struct objfile
*objfile
;
317 ALL_PSPACE_OBJFILES (pspace
, objfile
)
319 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
->next
)
321 if (s
->line_charpos
!= NULL
)
323 xfree (s
->line_charpos
);
324 s
->line_charpos
= NULL
;
326 if (s
->fullname
!= NULL
)
334 objfile
->sf
->qf
->forget_cached_source_info (objfile
);
337 last_source_visited
= NULL
;
341 init_source_path (void)
345 sprintf (buf
, "$cdir%c$cwd", DIRNAME_SEPARATOR
);
346 source_path
= xstrdup (buf
);
347 forget_cached_source_info ();
350 /* Add zero or more directories to the front of the source path. */
353 directory_command (char *dirname
, int from_tty
)
356 /* FIXME, this goes to "delete dir"... */
359 if (!from_tty
|| query (_("Reinitialize source path to empty? ")))
367 mod_path (dirname
, &source_path
);
368 forget_cached_source_info ();
371 show_directories ((char *) 0, from_tty
);
374 /* Add a path given with the -d command line switch.
375 This will not be quoted so we must not treat spaces as separators. */
378 directory_switch (char *dirname
, int from_tty
)
380 add_path (dirname
, &source_path
, 0);
383 /* Add zero or more directories to the front of an arbitrary path. */
386 mod_path (char *dirname
, char **which_path
)
388 add_path (dirname
, which_path
, 1);
391 /* Workhorse of mod_path. Takes an extra argument to determine
392 if dirname should be parsed for separators that indicate multiple
393 directories. This allows for interfaces that pre-parse the dirname
394 and allow specification of traditional separator characters such
398 add_path (char *dirname
, char **which_path
, int parse_separators
)
400 char *old
= *which_path
;
409 if (parse_separators
)
411 /* This will properly parse the space and tab separators
412 and any quotes that may exist. DIRNAME_SEPARATOR will
413 be dealt with later. */
414 argv
= gdb_buildargv (dirname
);
415 make_cleanup_freeargv (argv
);
421 arg
= xstrdup (dirname
);
422 make_cleanup (xfree
, arg
);
432 char *separator
= NULL
;
434 /* Spaces and tabs will have been removed by buildargv().
435 The directories will there be split into a list but
436 each entry may still contain DIRNAME_SEPARATOR. */
437 if (parse_separators
)
438 separator
= strchr (name
, DIRNAME_SEPARATOR
);
441 p
= arg
= name
+ strlen (name
);
446 while (*arg
== DIRNAME_SEPARATOR
)
450 /* If there are no more directories in this argument then start
451 on the next argument next time round the loop (if any). */
453 arg
= parse_separators
? argv
[++argv_index
] : NULL
;
456 /* name is the start of the directory.
457 p is the separator (or null) following the end. */
459 while (!(IS_DIR_SEPARATOR (*name
) && p
<= name
+ 1) /* "/" */
460 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
461 /* On MS-DOS and MS-Windows, h:\ is different from h: */
462 && !(p
== name
+ 3 && name
[1] == ':') /* "d:/" */
464 && IS_DIR_SEPARATOR (p
[-1]))
465 /* Sigh. "foo/" => "foo" */
469 while (p
> name
&& p
[-1] == '.')
473 /* "." => getwd (). */
474 name
= current_directory
;
477 else if (p
> name
+ 1 && IS_DIR_SEPARATOR (p
[-2]))
487 /* "...foo/." => "...foo". */
498 name
= tilde_expand (name
);
499 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
500 else if (IS_ABSOLUTE_PATH (name
) && p
== name
+ 2) /* "d:" => "d:." */
501 name
= concat (name
, ".", (char *)NULL
);
503 else if (!IS_ABSOLUTE_PATH (name
) && name
[0] != '$')
504 name
= concat (current_directory
, SLASH_STRING
, name
, (char *)NULL
);
506 name
= savestring (name
, p
- name
);
507 make_cleanup (xfree
, name
);
509 /* Unless it's a variable, check existence. */
512 /* These are warnings, not errors, since we don't want a
513 non-existent directory in a .gdbinit file to stop processing
514 of the .gdbinit file.
516 Whether they get added to the path is more debatable. Current
517 answer is yes, in case the user wants to go make the directory
518 or whatever. If the directory continues to not exist/not be
519 a directory/etc, then having them in the path should be
521 if (stat (name
, &st
) < 0)
523 int save_errno
= errno
;
524 fprintf_unfiltered (gdb_stderr
, "Warning: ");
525 print_sys_errmsg (name
, save_errno
);
527 else if ((st
.st_mode
& S_IFMT
) != S_IFDIR
)
528 warning (_("%s is not a directory."), name
);
533 unsigned int len
= strlen (name
);
538 /* FIXME: strncmp loses in interesting ways on MS-DOS and
539 MS-Windows because of case-insensitivity and two different
540 but functionally identical slash characters. We need a
541 special filesystem-dependent file-name comparison function.
543 Actually, even on Unix I would use realpath() or its work-
544 alike before comparing. Then all the code above which
545 removes excess slashes and dots could simply go away. */
546 if (!strncmp (p
, name
, len
)
547 && (p
[len
] == '\0' || p
[len
] == DIRNAME_SEPARATOR
))
549 /* Found it in the search path, remove old copy */
551 p
--; /* Back over leading separator */
552 if (prefix
> p
- *which_path
)
553 goto skip_dup
; /* Same dir twice in one cmd */
554 strcpy (p
, &p
[len
+ 1]); /* Copy from next \0 or : */
556 p
= strchr (p
, DIRNAME_SEPARATOR
);
566 tinybuf
[0] = DIRNAME_SEPARATOR
;
569 /* If we have already tacked on a name(s) in this command, be sure they stay
570 on the front as we tack on some more. */
577 temp
= concat (old
, tinybuf
, name
, (char *)NULL
);
579 *which_path
= concat (temp
, "", &old
[prefix
], (char *)NULL
);
580 prefix
= strlen (temp
);
585 *which_path
= concat (name
, (old
[0] ? tinybuf
: old
),
587 prefix
= strlen (name
);
600 source_info (char *ignore
, int from_tty
)
602 struct symtab
*s
= current_source_symtab
;
606 printf_filtered (_("No current source file.\n"));
609 printf_filtered (_("Current source file is %s\n"), s
->filename
);
611 printf_filtered (_("Compilation directory is %s\n"), s
->dirname
);
613 printf_filtered (_("Located in %s\n"), s
->fullname
);
615 printf_filtered (_("Contains %d line%s.\n"), s
->nlines
,
616 s
->nlines
== 1 ? "" : "s");
618 printf_filtered (_("Source language is %s.\n"), language_str (s
->language
));
619 printf_filtered (_("Compiled with %s debugging format.\n"), s
->debugformat
);
620 printf_filtered (_("%s preprocessor macro info.\n"),
621 s
->macro_table
? "Includes" : "Does not include");
625 /* Return True if the file NAME exists and is a regular file */
627 is_regular_file (const char *name
)
630 const int status
= stat (name
, &st
);
632 /* Stat should never fail except when the file does not exist.
633 If stat fails, analyze the source of error and return True
634 unless the file does not exist, to avoid returning false results
635 on obscure systems where stat does not work as expected.
638 return (errno
!= ENOENT
);
640 return S_ISREG (st
.st_mode
);
643 /* Open a file named STRING, searching path PATH (dir names sep by some char)
644 using mode MODE in the calls to open. You cannot use this function to
645 create files (O_CREAT).
647 OPTS specifies the function behaviour in specific cases.
649 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
650 (ie pretend the first element of PATH is "."). This also indicates
651 that a slash in STRING disables searching of the path (this is
652 so that "exec-file ./foo" or "symbol-file ./foo" insures that you
653 get that particular version of foo or an error message).
655 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
656 searched in path (we usually want this for source files but not for
659 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
660 the actual file opened (this string will always start with a "/"). We
661 have to take special pains to avoid doubling the "/" between the directory
662 and the file, sigh! Emacs gets confuzzed by this when we print the
665 If a file is found, return the descriptor.
666 Otherwise, return -1, with errno set for the last name we tried to open. */
668 /* >>>> This should only allow files of certain types,
669 >>>> eg executable, non-directory */
671 openp (const char *path
, int opts
, const char *string
,
672 int mode
, char **filename_opened
)
681 /* The open syscall MODE parameter is not specified. */
682 gdb_assert ((mode
& O_CREAT
) == 0);
683 gdb_assert (string
!= NULL
);
685 /* A file with an empty name cannot possibly exist. Report a failure
686 without further checking.
688 This is an optimization which also defends us against buggy
689 implementations of the "stat" function. For instance, we have
690 noticed that a MinGW debugger built on Windows XP 32bits crashes
691 when the debugger is started with an empty argument. */
692 if (string
[0] == '\0')
703 if ((opts
& OPF_TRY_CWD_FIRST
) || IS_ABSOLUTE_PATH (string
))
707 if (is_regular_file (string
))
709 filename
= alloca (strlen (string
) + 1);
710 strcpy (filename
, string
);
711 fd
= open (filename
, mode
);
721 if (!(opts
& OPF_SEARCH_IN_PATH
))
722 for (i
= 0; string
[i
]; i
++)
723 if (IS_DIR_SEPARATOR (string
[i
]))
727 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
728 while (IS_DIR_SEPARATOR(string
[0]))
732 while (string
[0] == '.' && IS_DIR_SEPARATOR (string
[1]))
735 alloclen
= strlen (path
) + strlen (string
) + 2;
736 filename
= alloca (alloclen
);
738 for (p
= path
; p
; p
= p1
? p1
+ 1 : 0)
740 p1
= strchr (p
, DIRNAME_SEPARATOR
);
746 if (len
== 4 && p
[0] == '$' && p
[1] == 'c'
747 && p
[2] == 'w' && p
[3] == 'd')
749 /* Name is $cwd -- insert current directory name instead. */
752 /* First, realloc the filename buffer if too short. */
753 len
= strlen (current_directory
);
754 newlen
= len
+ strlen (string
) + 2;
755 if (newlen
> alloclen
)
758 filename
= alloca (alloclen
);
760 strcpy (filename
, current_directory
);
764 /* Normal file name in path -- just use it. */
765 strncpy (filename
, p
, len
);
768 /* Don't search $cdir. It's also a magic path like $cwd, but we
769 don't have enough information to expand it. The user *could*
770 have an actual directory named '$cdir' but handling that would
771 be confusing, it would mean different things in different
772 contexts. If the user really has '$cdir' one can use './$cdir'.
773 We can get $cdir when loading scripts. When loading source files
774 $cdir must have already been expanded to the correct value. */
775 if (strcmp (filename
, "$cdir") == 0)
779 /* Remove trailing slashes */
780 while (len
> 0 && IS_DIR_SEPARATOR (filename
[len
- 1]))
783 strcat (filename
+ len
, SLASH_STRING
);
784 strcat (filename
, string
);
786 if (is_regular_file (filename
))
788 fd
= open (filename
, mode
);
797 /* If a file was opened, canonicalize its filename. Use xfullpath
798 rather than gdb_realpath to avoid resolving the basename part
799 of filenames when the associated file is a symbolic link. This
800 fixes a potential inconsistency between the filenames known to
801 GDB and the filenames it prints in the annotations. */
803 *filename_opened
= NULL
;
804 else if (IS_ABSOLUTE_PATH (filename
))
805 *filename_opened
= xfullpath (filename
);
808 /* Beware the // my son, the Emacs barfs, the botch that catch... */
810 char *f
= concat (current_directory
,
811 IS_DIR_SEPARATOR (current_directory
[strlen (current_directory
) - 1])
813 filename
, (char *)NULL
);
814 *filename_opened
= xfullpath (f
);
823 /* This is essentially a convenience, for clients that want the behaviour
824 of openp, using source_path, but that really don't want the file to be
825 opened but want instead just to know what the full pathname is (as
826 qualified against source_path).
828 The current working directory is searched first.
830 If the file was found, this function returns 1, and FULL_PATHNAME is
831 set to the fully-qualified pathname.
833 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
835 source_full_path_of (const char *filename
, char **full_pathname
)
839 fd
= openp (source_path
, OPF_TRY_CWD_FIRST
| OPF_SEARCH_IN_PATH
, filename
,
840 O_RDONLY
, full_pathname
);
843 *full_pathname
= NULL
;
851 /* Return non-zero if RULE matches PATH, that is if the rule can be
855 substitute_path_rule_matches (const struct substitute_path_rule
*rule
,
858 const int from_len
= strlen (rule
->from
);
859 const int path_len
= strlen (path
);
862 if (path_len
< from_len
)
865 /* The substitution rules are anchored at the start of the path,
866 so the path should start with rule->from. There is no filename
867 comparison routine, so we need to extract the first FROM_LEN
868 characters from PATH first and use that to do the comparison. */
870 path_start
= alloca (from_len
+ 1);
871 strncpy (path_start
, path
, from_len
);
872 path_start
[from_len
] = '\0';
874 if (FILENAME_CMP (path_start
, rule
->from
) != 0)
877 /* Make sure that the region in the path that matches the substitution
878 rule is immediately followed by a directory separator (or the end of
879 string character). */
881 if (path
[from_len
] != '\0' && !IS_DIR_SEPARATOR (path
[from_len
]))
887 /* Find the substitute-path rule that applies to PATH and return it.
888 Return NULL if no rule applies. */
890 static struct substitute_path_rule
*
891 get_substitute_path_rule (const char *path
)
893 struct substitute_path_rule
*rule
= substitute_path_rules
;
895 while (rule
!= NULL
&& !substitute_path_rule_matches (rule
, path
))
901 /* If the user specified a source path substitution rule that applies
902 to PATH, then apply it and return the new path. This new path must
903 be deallocated afterwards.
905 Return NULL if no substitution rule was specified by the user,
906 or if no rule applied to the given PATH. */
909 rewrite_source_path (const char *path
)
911 const struct substitute_path_rule
*rule
= get_substitute_path_rule (path
);
918 from_len
= strlen (rule
->from
);
920 /* Compute the rewritten path and return it. */
923 (char *) xmalloc (strlen (path
) + 1 + strlen (rule
->to
) - from_len
);
924 strcpy (new_path
, rule
->to
);
925 strcat (new_path
, path
+ from_len
);
930 /* This function is capable of finding the absolute path to a
931 source file, and opening it, provided you give it a FILENAME. Both the
932 DIRNAME and FULLNAME are only added suggestions on where to find the file.
934 FILENAME should be the filename to open.
935 DIRNAME is the compilation directory of a particular source file.
936 Only some debug formats provide this info.
937 FULLNAME can be the last known absolute path to the file in question.
938 Space for the path must have been malloc'd. If a path substitution
939 is applied we free the old value and set a new one.
942 A valid file descriptor is returned. ( the return value is positive )
943 FULLNAME is set to the absolute path to the file just opened.
944 The caller is responsible for freeing FULLNAME.
947 An invalid file descriptor is returned. ( the return value is negative )
948 FULLNAME is set to NULL. */
951 find_and_open_source (const char *filename
,
955 char *path
= source_path
;
959 /* Quick way out if we already know its full name */
963 /* The user may have requested that source paths be rewritten
964 according to substitution rules he provided. If a substitution
965 rule applies to this path, then apply it. */
966 char *rewritten_fullname
= rewrite_source_path (*fullname
);
968 if (rewritten_fullname
!= NULL
)
971 *fullname
= rewritten_fullname
;
974 result
= open (*fullname
, OPEN_MODE
);
977 /* Didn't work -- free old one, try again. */
984 /* If necessary, rewrite the compilation directory name according
985 to the source path substitution rules specified by the user. */
987 char *rewritten_dirname
= rewrite_source_path (dirname
);
989 if (rewritten_dirname
!= NULL
)
991 make_cleanup (xfree
, rewritten_dirname
);
992 dirname
= rewritten_dirname
;
995 /* Replace a path entry of $cdir with the compilation directory name */
997 /* We cast strstr's result in case an ANSIhole has made it const,
998 which produces a "required warning" when assigned to a nonconst. */
999 p
= (char *) strstr (source_path
, "$cdir");
1000 if (p
&& (p
== path
|| p
[-1] == DIRNAME_SEPARATOR
)
1001 && (p
[cdir_len
] == DIRNAME_SEPARATOR
|| p
[cdir_len
] == '\0'))
1006 alloca (strlen (source_path
) + 1 + strlen (dirname
) + 1);
1007 len
= p
- source_path
;
1008 strncpy (path
, source_path
, len
); /* Before $cdir */
1009 strcpy (path
+ len
, dirname
); /* new stuff */
1010 strcat (path
+ len
, source_path
+ len
+ cdir_len
); /* After $cdir */
1014 if (IS_ABSOLUTE_PATH (filename
))
1016 /* If filename is absolute path, try the source path
1017 substitution on it. */
1018 char *rewritten_filename
= rewrite_source_path (filename
);
1020 if (rewritten_filename
!= NULL
)
1022 make_cleanup (xfree
, rewritten_filename
);
1023 filename
= rewritten_filename
;
1027 result
= openp (path
, OPF_SEARCH_IN_PATH
, filename
, OPEN_MODE
, fullname
);
1030 /* Didn't work. Try using just the basename. */
1031 p
= lbasename (filename
);
1033 result
= openp (path
, OPF_SEARCH_IN_PATH
, p
, OPEN_MODE
, fullname
);
1039 /* Open a source file given a symtab S. Returns a file descriptor or
1040 negative number for error.
1042 This function is a convience function to find_and_open_source. */
1045 open_source_file (struct symtab
*s
)
1050 return find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1053 /* Finds the fullname that a symtab represents.
1055 If this functions finds the fullname, it will save it in s->fullname
1056 and it will also return the value.
1058 If this function fails to find the file that this symtab represents,
1059 NULL will be returned and s->fullname will be set to NULL. */
1061 symtab_to_fullname (struct symtab
*s
)
1068 /* Don't check s->fullname here, the file could have been
1069 deleted/moved/..., look for it again */
1070 r
= find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1081 /* Create and initialize the table S->line_charpos that records
1082 the positions of the lines in the source file, which is assumed
1083 to be open on descriptor DESC.
1084 All set S->nlines to the number of such lines. */
1087 find_source_lines (struct symtab
*s
, int desc
)
1090 char *data
, *p
, *end
;
1092 int lines_allocated
= 1000;
1098 line_charpos
= (int *) xmalloc (lines_allocated
* sizeof (int));
1099 if (fstat (desc
, &st
) < 0)
1100 perror_with_name (s
->filename
);
1102 if (s
->objfile
&& s
->objfile
->obfd
)
1103 mtime
= s
->objfile
->mtime
;
1105 mtime
= exec_bfd_mtime
;
1107 if (mtime
&& mtime
< st
.st_mtime
)
1108 warning (_("Source file is more recent than executable."));
1110 #ifdef LSEEK_NOT_LINEAR
1114 /* Have to read it byte by byte to find out where the chars live */
1116 line_charpos
[0] = lseek (desc
, 0, SEEK_CUR
);
1118 while (myread (desc
, &c
, 1) > 0)
1122 if (nlines
== lines_allocated
)
1124 lines_allocated
*= 2;
1126 (int *) xrealloc ((char *) line_charpos
,
1127 sizeof (int) * lines_allocated
);
1129 line_charpos
[nlines
++] = lseek (desc
, 0, SEEK_CUR
);
1133 #else /* lseek linear. */
1135 struct cleanup
*old_cleanups
;
1137 /* st_size might be a large type, but we only support source files whose
1138 size fits in an int. */
1139 size
= (int) st
.st_size
;
1141 /* Use malloc, not alloca, because this may be pretty large, and we may
1142 run into various kinds of limits on stack size. */
1143 data
= (char *) xmalloc (size
);
1144 old_cleanups
= make_cleanup (xfree
, data
);
1146 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1147 size
= myread (desc
, data
, size
);
1149 perror_with_name (s
->filename
);
1152 line_charpos
[0] = 0;
1157 /* A newline at the end does not start a new line. */
1160 if (nlines
== lines_allocated
)
1162 lines_allocated
*= 2;
1164 (int *) xrealloc ((char *) line_charpos
,
1165 sizeof (int) * lines_allocated
);
1167 line_charpos
[nlines
++] = p
- data
;
1170 do_cleanups (old_cleanups
);
1172 #endif /* lseek linear. */
1175 (int *) xrealloc ((char *) line_charpos
, nlines
* sizeof (int));
1179 /* Return the character position of a line LINE in symtab S.
1180 Return 0 if anything is invalid. */
1182 #if 0 /* Currently unused */
1185 source_line_charpos (struct symtab
*s
, int line
)
1189 if (!s
->line_charpos
|| line
<= 0)
1191 if (line
> s
->nlines
)
1193 return s
->line_charpos
[line
- 1];
1196 /* Return the line number of character position POS in symtab S. */
1199 source_charpos_line (struct symtab
*s
, int chr
)
1204 if (s
== 0 || s
->line_charpos
== 0)
1206 lnp
= s
->line_charpos
;
1207 /* Files are usually short, so sequential search is Ok */
1208 while (line
< s
->nlines
&& *lnp
<= chr
)
1213 if (line
>= s
->nlines
)
1221 /* Get full pathname and line number positions for a symtab.
1222 Return nonzero if line numbers may have changed.
1223 Set *FULLNAME to actual name of the file as found by `openp',
1224 or to 0 if the file is not found. */
1227 get_filename_and_charpos (struct symtab
*s
, char **fullname
)
1229 int desc
, linenums_changed
= 0;
1230 struct cleanup
*cleanups
;
1232 desc
= open_source_file (s
);
1239 cleanups
= make_cleanup_close (desc
);
1241 *fullname
= s
->fullname
;
1242 if (s
->line_charpos
== 0)
1243 linenums_changed
= 1;
1244 if (linenums_changed
)
1245 find_source_lines (s
, desc
);
1246 do_cleanups (cleanups
);
1247 return linenums_changed
;
1250 /* Print text describing the full name of the source file S
1251 and the line number LINE and its corresponding character position.
1252 The text starts with two Ctrl-z so that the Emacs-GDB interface
1255 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1257 Return 1 if successful, 0 if could not find the file. */
1260 identify_source_line (struct symtab
*s
, int line
, int mid_statement
,
1263 if (s
->line_charpos
== 0)
1264 get_filename_and_charpos (s
, (char **) NULL
);
1265 if (s
->fullname
== 0)
1267 if (line
> s
->nlines
)
1268 /* Don't index off the end of the line_charpos array. */
1270 annotate_source (s
->fullname
, line
, s
->line_charpos
[line
- 1],
1271 mid_statement
, get_objfile_arch (s
->objfile
), pc
);
1273 current_source_line
= line
;
1274 first_line_listed
= line
;
1275 last_line_listed
= line
;
1276 current_source_symtab
= s
;
1281 /* Print source lines from the file of symtab S,
1282 starting with line number LINE and stopping before line number STOPLINE. */
1284 static void print_source_lines_base (struct symtab
*s
, int line
, int stopline
,
1287 print_source_lines_base (struct symtab
*s
, int line
, int stopline
, int noerror
)
1292 int nlines
= stopline
- line
;
1293 struct cleanup
*cleanup
;
1295 /* Regardless of whether we can open the file, set current_source_symtab. */
1296 current_source_symtab
= s
;
1297 current_source_line
= line
;
1298 first_line_listed
= line
;
1300 /* If printing of source lines is disabled, just print file and line number */
1301 if (ui_out_test_flags (uiout
, ui_source_list
))
1303 /* Only prints "No such file or directory" once */
1304 if ((s
!= last_source_visited
) || (!last_source_error
))
1306 last_source_visited
= s
;
1307 desc
= open_source_file (s
);
1311 desc
= last_source_error
;
1323 last_source_error
= desc
;
1327 char *name
= alloca (strlen (s
->filename
) + 100);
1328 sprintf (name
, "%d\t%s", line
, s
->filename
);
1329 print_sys_errmsg (name
, errno
);
1332 ui_out_field_int (uiout
, "line", line
);
1333 ui_out_text (uiout
, "\tin ");
1334 ui_out_field_string (uiout
, "file", s
->filename
);
1335 ui_out_text (uiout
, "\n");
1340 last_source_error
= 0;
1342 if (s
->line_charpos
== 0)
1343 find_source_lines (s
, desc
);
1345 if (line
< 1 || line
> s
->nlines
)
1348 error (_("Line number %d out of range; %s has %d lines."),
1349 line
, s
->filename
, s
->nlines
);
1352 if (lseek (desc
, s
->line_charpos
[line
- 1], 0) < 0)
1355 perror_with_name (s
->filename
);
1358 stream
= fdopen (desc
, FDOPEN_MODE
);
1360 cleanup
= make_cleanup_fclose (stream
);
1362 while (nlines
-- > 0)
1369 last_line_listed
= current_source_line
;
1370 sprintf (buf
, "%d\t", current_source_line
++);
1371 ui_out_text (uiout
, buf
);
1374 if (c
< 040 && c
!= '\t' && c
!= '\n' && c
!= '\r')
1376 sprintf (buf
, "^%c", c
+ 0100);
1377 ui_out_text (uiout
, buf
);
1380 ui_out_text (uiout
, "^?");
1383 /* Skip a \r character, but only before a \n. */
1384 int c1
= fgetc (stream
);
1387 printf_filtered ("^%c", c
+ 0100);
1389 ungetc (c1
, stream
);
1393 sprintf (buf
, "%c", c
);
1394 ui_out_text (uiout
, buf
);
1397 while (c
!= '\n' && (c
= fgetc (stream
)) >= 0);
1400 do_cleanups (cleanup
);
1403 /* Show source lines from the file of symtab S, starting with line
1404 number LINE and stopping before line number STOPLINE. If this is
1405 not the command line version, then the source is shown in the source
1406 window otherwise it is simply printed */
1409 print_source_lines (struct symtab
*s
, int line
, int stopline
, int noerror
)
1411 print_source_lines_base (s
, line
, stopline
, noerror
);
1414 /* Print info on range of pc's in a specified line. */
1417 line_info (char *arg
, int from_tty
)
1419 struct symtabs_and_lines sals
;
1420 struct symtab_and_line sal
;
1421 CORE_ADDR start_pc
, end_pc
;
1424 init_sal (&sal
); /* initialize to zeroes */
1428 sal
.symtab
= current_source_symtab
;
1429 sal
.line
= last_line_listed
;
1431 sals
.sals
= (struct symtab_and_line
*)
1432 xmalloc (sizeof (struct symtab_and_line
));
1437 sals
= decode_line_spec_1 (arg
, 0);
1442 /* C++ More than one line may have been specified, as when the user
1443 specifies an overloaded function name. Print info on them all. */
1444 for (i
= 0; i
< sals
.nelts
; i
++)
1448 if (sal
.symtab
== 0)
1450 struct gdbarch
*gdbarch
= get_current_arch ();
1452 printf_filtered (_("No line number information available"));
1455 /* This is useful for "info line *0x7f34". If we can't tell the
1456 user about a source line, at least let them have the symbolic
1458 printf_filtered (" for address ");
1460 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1463 printf_filtered (".");
1464 printf_filtered ("\n");
1466 else if (sal
.line
> 0
1467 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1469 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1471 if (start_pc
== end_pc
)
1473 printf_filtered ("Line %d of \"%s\"",
1474 sal
.line
, sal
.symtab
->filename
);
1476 printf_filtered (" is at address ");
1477 print_address (gdbarch
, start_pc
, gdb_stdout
);
1479 printf_filtered (" but contains no code.\n");
1483 printf_filtered ("Line %d of \"%s\"",
1484 sal
.line
, sal
.symtab
->filename
);
1486 printf_filtered (" starts at address ");
1487 print_address (gdbarch
, start_pc
, gdb_stdout
);
1489 printf_filtered (" and ends at ");
1490 print_address (gdbarch
, end_pc
, gdb_stdout
);
1491 printf_filtered (".\n");
1494 /* x/i should display this line's code. */
1495 set_next_address (gdbarch
, start_pc
);
1497 /* Repeating "info line" should do the following line. */
1498 last_line_listed
= sal
.line
+ 1;
1500 /* If this is the only line, show the source code. If it could
1501 not find the file, don't do anything special. */
1502 if (annotation_level
&& sals
.nelts
== 1)
1503 identify_source_line (sal
.symtab
, sal
.line
, 0, start_pc
);
1506 /* Is there any case in which we get here, and have an address
1507 which the user would want to see? If we have debugging symbols
1508 and no line numbers? */
1509 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
1510 sal
.line
, sal
.symtab
->filename
);
1515 /* Commands to search the source file for a regexp. */
1518 forward_search_command (char *regex
, int from_tty
)
1525 struct cleanup
*cleanups
;
1527 line
= last_line_listed
+ 1;
1529 msg
= (char *) re_comp (regex
);
1531 error (("%s"), msg
);
1533 if (current_source_symtab
== 0)
1534 select_source_symtab (0);
1536 desc
= open_source_file (current_source_symtab
);
1538 perror_with_name (current_source_symtab
->filename
);
1539 cleanups
= make_cleanup_close (desc
);
1541 if (current_source_symtab
->line_charpos
== 0)
1542 find_source_lines (current_source_symtab
, desc
);
1544 if (line
< 1 || line
> current_source_symtab
->nlines
)
1545 error (_("Expression not found"));
1547 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1548 perror_with_name (current_source_symtab
->filename
);
1550 discard_cleanups (cleanups
);
1551 stream
= fdopen (desc
, FDOPEN_MODE
);
1553 cleanups
= make_cleanup_fclose (stream
);
1556 static char *buf
= NULL
;
1558 int cursize
, newsize
;
1561 buf
= xmalloc (cursize
);
1570 if (p
- buf
== cursize
)
1572 newsize
= cursize
+ cursize
/ 2;
1573 buf
= xrealloc (buf
, newsize
);
1578 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1580 /* Remove the \r, if any, at the end of the line, otherwise
1581 regular expressions that end with $ or \n won't work. */
1582 if (p
- buf
> 1 && p
[-2] == '\r')
1588 /* we now have a source line in buf, null terminate and match */
1590 if (re_exec (buf
) > 0)
1593 do_cleanups (cleanups
);
1594 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1595 set_internalvar_integer (lookup_internalvar ("_"), line
);
1596 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1602 printf_filtered (_("Expression not found\n"));
1603 do_cleanups (cleanups
);
1607 reverse_search_command (char *regex
, int from_tty
)
1614 struct cleanup
*cleanups
;
1616 line
= last_line_listed
- 1;
1618 msg
= (char *) re_comp (regex
);
1620 error (("%s"), msg
);
1622 if (current_source_symtab
== 0)
1623 select_source_symtab (0);
1625 desc
= open_source_file (current_source_symtab
);
1627 perror_with_name (current_source_symtab
->filename
);
1628 cleanups
= make_cleanup_close (desc
);
1630 if (current_source_symtab
->line_charpos
== 0)
1631 find_source_lines (current_source_symtab
, desc
);
1633 if (line
< 1 || line
> current_source_symtab
->nlines
)
1634 error (_("Expression not found"));
1636 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1637 perror_with_name (current_source_symtab
->filename
);
1639 discard_cleanups (cleanups
);
1640 stream
= fdopen (desc
, FDOPEN_MODE
);
1642 cleanups
= make_cleanup_fclose (stream
);
1645 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1646 char buf
[4096]; /* Should be reasonable??? */
1656 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1658 /* Remove the \r, if any, at the end of the line, otherwise
1659 regular expressions that end with $ or \n won't work. */
1660 if (p
- buf
> 1 && p
[-2] == '\r')
1666 /* We now have a source line in buf; null terminate and match. */
1668 if (re_exec (buf
) > 0)
1671 do_cleanups (cleanups
);
1672 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1673 set_internalvar_integer (lookup_internalvar ("_"), line
);
1674 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1678 if (fseek (stream
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1680 do_cleanups (cleanups
);
1681 perror_with_name (current_source_symtab
->filename
);
1685 printf_filtered (_("Expression not found\n"));
1686 do_cleanups (cleanups
);
1690 /* If the last character of PATH is a directory separator, then strip it. */
1693 strip_trailing_directory_separator (char *path
)
1695 const int last
= strlen (path
) - 1;
1698 return; /* No stripping is needed if PATH is the empty string. */
1700 if (IS_DIR_SEPARATOR (path
[last
]))
1704 /* Return the path substitution rule that matches FROM.
1705 Return NULL if no rule matches. */
1707 static struct substitute_path_rule
*
1708 find_substitute_path_rule (const char *from
)
1710 struct substitute_path_rule
*rule
= substitute_path_rules
;
1712 while (rule
!= NULL
)
1714 if (FILENAME_CMP (rule
->from
, from
) == 0)
1722 /* Add a new substitute-path rule at the end of the current list of rules.
1723 The new rule will replace FROM into TO. */
1726 add_substitute_path_rule (char *from
, char *to
)
1728 struct substitute_path_rule
*rule
;
1729 struct substitute_path_rule
*new_rule
;
1731 new_rule
= xmalloc (sizeof (struct substitute_path_rule
));
1732 new_rule
->from
= xstrdup (from
);
1733 new_rule
->to
= xstrdup (to
);
1734 new_rule
->next
= NULL
;
1736 /* If the list of rules are empty, then insert the new rule
1737 at the head of the list. */
1739 if (substitute_path_rules
== NULL
)
1741 substitute_path_rules
= new_rule
;
1745 /* Otherwise, skip to the last rule in our list and then append
1748 rule
= substitute_path_rules
;
1749 while (rule
->next
!= NULL
)
1752 rule
->next
= new_rule
;
1755 /* Remove the given source path substitution rule from the current list
1756 of rules. The memory allocated for that rule is also deallocated. */
1759 delete_substitute_path_rule (struct substitute_path_rule
*rule
)
1761 if (rule
== substitute_path_rules
)
1762 substitute_path_rules
= rule
->next
;
1765 struct substitute_path_rule
*prev
= substitute_path_rules
;
1767 while (prev
!= NULL
&& prev
->next
!= rule
)
1770 gdb_assert (prev
!= NULL
);
1772 prev
->next
= rule
->next
;
1780 /* Implement the "show substitute-path" command. */
1783 show_substitute_path_command (char *args
, int from_tty
)
1785 struct substitute_path_rule
*rule
= substitute_path_rules
;
1789 argv
= gdb_buildargv (args
);
1790 make_cleanup_freeargv (argv
);
1792 /* We expect zero or one argument. */
1794 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1795 error (_("Too many arguments in command"));
1797 if (argv
!= NULL
&& argv
[0] != NULL
)
1800 /* Print the substitution rules. */
1804 (_("Source path substitution rule matching `%s':\n"), from
);
1806 printf_filtered (_("List of all source path substitution rules:\n"));
1808 while (rule
!= NULL
)
1810 if (from
== NULL
|| FILENAME_CMP (rule
->from
, from
) == 0)
1811 printf_filtered (" `%s' -> `%s'.\n", rule
->from
, rule
->to
);
1816 /* Implement the "unset substitute-path" command. */
1819 unset_substitute_path_command (char *args
, int from_tty
)
1821 struct substitute_path_rule
*rule
= substitute_path_rules
;
1822 char **argv
= gdb_buildargv (args
);
1826 /* This function takes either 0 or 1 argument. */
1828 make_cleanup_freeargv (argv
);
1829 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1830 error (_("Incorrect usage, too many arguments in command"));
1832 if (argv
!= NULL
&& argv
[0] != NULL
)
1835 /* If the user asked for all the rules to be deleted, ask him
1836 to confirm and give him a chance to abort before the action
1840 && !query (_("Delete all source path substitution rules? ")))
1841 error (_("Canceled"));
1843 /* Delete the rule matching the argument. No argument means that
1844 all rules should be deleted. */
1846 while (rule
!= NULL
)
1848 struct substitute_path_rule
*next
= rule
->next
;
1850 if (from
== NULL
|| FILENAME_CMP (from
, rule
->from
) == 0)
1852 delete_substitute_path_rule (rule
);
1859 /* If the user asked for a specific rule to be deleted but
1860 we could not find it, then report an error. */
1862 if (from
!= NULL
&& !rule_found
)
1863 error (_("No substitution rule defined for `%s'"), from
);
1865 forget_cached_source_info ();
1868 /* Add a new source path substitution rule. */
1871 set_substitute_path_command (char *args
, int from_tty
)
1873 char *from_path
, *to_path
;
1875 struct substitute_path_rule
*rule
;
1877 argv
= gdb_buildargv (args
);
1878 make_cleanup_freeargv (argv
);
1880 if (argv
== NULL
|| argv
[0] == NULL
|| argv
[1] == NULL
)
1881 error (_("Incorrect usage, too few arguments in command"));
1883 if (argv
[2] != NULL
)
1884 error (_("Incorrect usage, too many arguments in command"));
1886 if (*(argv
[0]) == '\0')
1887 error (_("First argument must be at least one character long"));
1889 /* Strip any trailing directory separator character in either FROM
1890 or TO. The substitution rule already implicitly contains them. */
1891 strip_trailing_directory_separator (argv
[0]);
1892 strip_trailing_directory_separator (argv
[1]);
1894 /* If a rule with the same "from" was previously defined, then
1895 delete it. This new rule replaces it. */
1897 rule
= find_substitute_path_rule (argv
[0]);
1899 delete_substitute_path_rule (rule
);
1901 /* Insert the new substitution rule. */
1903 add_substitute_path_rule (argv
[0], argv
[1]);
1904 forget_cached_source_info ();
1909 _initialize_source (void)
1911 struct cmd_list_element
*c
;
1912 current_source_symtab
= 0;
1913 init_source_path ();
1915 /* The intention is to use POSIX Basic Regular Expressions.
1916 Always use the GNU regex routine for consistency across all hosts.
1917 Our current GNU regex.c does not have all the POSIX features, so this is
1918 just an approximation. */
1919 re_set_syntax (RE_SYNTAX_GREP
);
1921 c
= add_cmd ("directory", class_files
, directory_command
, _("\
1922 Add directory DIR to beginning of search path for source files.\n\
1923 Forget cached info on source file locations and line positions.\n\
1924 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1925 directory in which the source file was compiled into object code.\n\
1926 With no argument, reset the search path to $cdir:$cwd, the default."),
1930 add_com_alias ("use", "directory", class_files
, 0);
1932 set_cmd_completer (c
, filename_completer
);
1934 add_cmd ("directories", no_class
, show_directories
, _("\
1935 Current search path for finding source files.\n\
1936 $cwd in the path means the current working directory.\n\
1937 $cdir in the path means the compilation directory of the source file."),
1942 add_com_alias ("D", "directory", class_files
, 0);
1943 add_cmd ("ld", no_class
, show_directories
, _("\
1944 Current search path for finding source files.\n\
1945 $cwd in the path means the current working directory.\n\
1946 $cdir in the path means the compilation directory of the source file."),
1950 add_info ("source", source_info
,
1951 _("Information about the current source file."));
1953 add_info ("line", line_info
, _("\
1954 Core addresses of the code for a source line.\n\
1955 Line can be specified as\n\
1956 LINENUM, to list around that line in current file,\n\
1957 FILE:LINENUM, to list around that line in that file,\n\
1958 FUNCTION, to list around beginning of that function,\n\
1959 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1960 Default is to describe the last source line that was listed.\n\n\
1961 This sets the default address for \"x\" to the line's first instruction\n\
1962 so that \"x/i\" suffices to start examining the machine code.\n\
1963 The address is also stored as the value of \"$_\"."));
1965 add_com ("forward-search", class_files
, forward_search_command
, _("\
1966 Search for regular expression (see regex(3)) from last line listed.\n\
1967 The matching line number is also stored as the value of \"$_\"."));
1968 add_com_alias ("search", "forward-search", class_files
, 0);
1970 add_com ("reverse-search", class_files
, reverse_search_command
, _("\
1971 Search backward for regular expression (see regex(3)) from last line listed.\n\
1972 The matching line number is also stored as the value of \"$_\"."));
1976 add_com_alias ("/", "forward-search", class_files
, 0);
1977 add_com_alias ("?", "reverse-search", class_files
, 0);
1980 add_setshow_integer_cmd ("listsize", class_support
, &lines_to_list
, _("\
1981 Set number of source lines gdb will list by default."), _("\
1982 Show number of source lines gdb will list by default."), NULL
,
1985 &setlist
, &showlist
);
1987 add_cmd ("substitute-path", class_files
, set_substitute_path_command
,
1989 Usage: set substitute-path FROM TO\n\
1990 Add a substitution rule replacing FROM into TO in source file names.\n\
1991 If a substitution rule was previously set for FROM, the old rule\n\
1992 is replaced by the new one."),
1995 add_cmd ("substitute-path", class_files
, unset_substitute_path_command
,
1997 Usage: unset substitute-path [FROM]\n\
1998 Delete the rule for substituting FROM in source file names. If FROM\n\
1999 is not specified, all substituting rules are deleted.\n\
2000 If the debugger cannot find a rule for FROM, it will display a warning."),
2003 add_cmd ("substitute-path", class_files
, show_substitute_path_command
,
2005 Usage: show substitute-path [FROM]\n\
2006 Print the rule for substituting FROM in source file names. If FROM\n\
2007 is not specified, print all substitution rules."),