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
;
352 init_source_path (void)
356 sprintf (buf
, "$cdir%c$cwd", DIRNAME_SEPARATOR
);
357 source_path
= xstrdup (buf
);
358 forget_cached_source_info ();
362 init_last_source_visited (void)
364 last_source_visited
= NULL
;
367 /* Add zero or more directories to the front of the source path. */
370 directory_command (char *dirname
, int from_tty
)
373 /* FIXME, this goes to "delete dir"... */
376 if (!from_tty
|| query (_("Reinitialize source path to empty? ")))
384 mod_path (dirname
, &source_path
);
385 last_source_visited
= NULL
;
388 show_directories ((char *) 0, from_tty
);
389 forget_cached_source_info ();
392 /* Add a path given with the -d command line switch.
393 This will not be quoted so we must not treat spaces as separators. */
396 directory_switch (char *dirname
, int from_tty
)
398 add_path (dirname
, &source_path
, 0);
401 /* Add zero or more directories to the front of an arbitrary path. */
404 mod_path (char *dirname
, char **which_path
)
406 add_path (dirname
, which_path
, 1);
409 /* Workhorse of mod_path. Takes an extra argument to determine
410 if dirname should be parsed for separators that indicate multiple
411 directories. This allows for interfaces that pre-parse the dirname
412 and allow specification of traditional separator characters such
416 add_path (char *dirname
, char **which_path
, int parse_separators
)
418 char *old
= *which_path
;
427 if (parse_separators
)
429 /* This will properly parse the space and tab separators
430 and any quotes that may exist. DIRNAME_SEPARATOR will
431 be dealt with later. */
432 argv
= gdb_buildargv (dirname
);
433 make_cleanup_freeargv (argv
);
439 arg
= xstrdup (dirname
);
440 make_cleanup (xfree
, arg
);
450 char *separator
= NULL
;
452 /* Spaces and tabs will have been removed by buildargv().
453 The directories will there be split into a list but
454 each entry may still contain DIRNAME_SEPARATOR. */
455 if (parse_separators
)
456 separator
= strchr (name
, DIRNAME_SEPARATOR
);
459 p
= arg
= name
+ strlen (name
);
464 while (*arg
== DIRNAME_SEPARATOR
)
468 /* If there are no more directories in this argument then start
469 on the next argument next time round the loop (if any). */
471 arg
= parse_separators
? argv
[++argv_index
] : NULL
;
474 /* name is the start of the directory.
475 p is the separator (or null) following the end. */
477 while (!(IS_DIR_SEPARATOR (*name
) && p
<= name
+ 1) /* "/" */
478 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
479 /* On MS-DOS and MS-Windows, h:\ is different from h: */
480 && !(p
== name
+ 3 && name
[1] == ':') /* "d:/" */
482 && IS_DIR_SEPARATOR (p
[-1]))
483 /* Sigh. "foo/" => "foo" */
487 while (p
> name
&& p
[-1] == '.')
491 /* "." => getwd (). */
492 name
= current_directory
;
495 else if (p
> name
+ 1 && IS_DIR_SEPARATOR (p
[-2]))
505 /* "...foo/." => "...foo". */
516 name
= tilde_expand (name
);
517 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
518 else if (IS_ABSOLUTE_PATH (name
) && p
== name
+ 2) /* "d:" => "d:." */
519 name
= concat (name
, ".", (char *)NULL
);
521 else if (!IS_ABSOLUTE_PATH (name
) && name
[0] != '$')
522 name
= concat (current_directory
, SLASH_STRING
, name
, (char *)NULL
);
524 name
= savestring (name
, p
- name
);
525 make_cleanup (xfree
, name
);
527 /* Unless it's a variable, check existence. */
530 /* These are warnings, not errors, since we don't want a
531 non-existent directory in a .gdbinit file to stop processing
532 of the .gdbinit file.
534 Whether they get added to the path is more debatable. Current
535 answer is yes, in case the user wants to go make the directory
536 or whatever. If the directory continues to not exist/not be
537 a directory/etc, then having them in the path should be
539 if (stat (name
, &st
) < 0)
541 int save_errno
= errno
;
542 fprintf_unfiltered (gdb_stderr
, "Warning: ");
543 print_sys_errmsg (name
, save_errno
);
545 else if ((st
.st_mode
& S_IFMT
) != S_IFDIR
)
546 warning (_("%s is not a directory."), name
);
551 unsigned int len
= strlen (name
);
556 /* FIXME: strncmp loses in interesting ways on MS-DOS and
557 MS-Windows because of case-insensitivity and two different
558 but functionally identical slash characters. We need a
559 special filesystem-dependent file-name comparison function.
561 Actually, even on Unix I would use realpath() or its work-
562 alike before comparing. Then all the code above which
563 removes excess slashes and dots could simply go away. */
564 if (!strncmp (p
, name
, len
)
565 && (p
[len
] == '\0' || p
[len
] == DIRNAME_SEPARATOR
))
567 /* Found it in the search path, remove old copy */
569 p
--; /* Back over leading separator */
570 if (prefix
> p
- *which_path
)
571 goto skip_dup
; /* Same dir twice in one cmd */
572 strcpy (p
, &p
[len
+ 1]); /* Copy from next \0 or : */
574 p
= strchr (p
, DIRNAME_SEPARATOR
);
584 tinybuf
[0] = DIRNAME_SEPARATOR
;
587 /* If we have already tacked on a name(s) in this command, be sure they stay
588 on the front as we tack on some more. */
595 temp
= concat (old
, tinybuf
, name
, (char *)NULL
);
597 *which_path
= concat (temp
, "", &old
[prefix
], (char *)NULL
);
598 prefix
= strlen (temp
);
603 *which_path
= concat (name
, (old
[0] ? tinybuf
: old
),
605 prefix
= strlen (name
);
618 source_info (char *ignore
, int from_tty
)
620 struct symtab
*s
= current_source_symtab
;
624 printf_filtered (_("No current source file.\n"));
627 printf_filtered (_("Current source file is %s\n"), s
->filename
);
629 printf_filtered (_("Compilation directory is %s\n"), s
->dirname
);
631 printf_filtered (_("Located in %s\n"), s
->fullname
);
633 printf_filtered (_("Contains %d line%s.\n"), s
->nlines
,
634 s
->nlines
== 1 ? "" : "s");
636 printf_filtered (_("Source language is %s.\n"), language_str (s
->language
));
637 printf_filtered (_("Compiled with %s debugging format.\n"), s
->debugformat
);
638 printf_filtered (_("%s preprocessor macro info.\n"),
639 s
->macro_table
? "Includes" : "Does not include");
643 /* Return True if the file NAME exists and is a regular file */
645 is_regular_file (const char *name
)
648 const int status
= stat (name
, &st
);
650 /* Stat should never fail except when the file does not exist.
651 If stat fails, analyze the source of error and return True
652 unless the file does not exist, to avoid returning false results
653 on obscure systems where stat does not work as expected.
656 return (errno
!= ENOENT
);
658 return S_ISREG (st
.st_mode
);
661 /* Open a file named STRING, searching path PATH (dir names sep by some char)
662 using mode MODE in the calls to open. You cannot use this function to
663 create files (O_CREAT).
665 OPTS specifies the function behaviour in specific cases.
667 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
668 (ie pretend the first element of PATH is "."). This also indicates
669 that a slash in STRING disables searching of the path (this is
670 so that "exec-file ./foo" or "symbol-file ./foo" insures that you
671 get that particular version of foo or an error message).
673 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
674 searched in path (we usually want this for source files but not for
677 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
678 the actual file opened (this string will always start with a "/"). We
679 have to take special pains to avoid doubling the "/" between the directory
680 and the file, sigh! Emacs gets confuzzed by this when we print the
683 If a file is found, return the descriptor.
684 Otherwise, return -1, with errno set for the last name we tried to open. */
686 /* >>>> This should only allow files of certain types,
687 >>>> eg executable, non-directory */
689 openp (const char *path
, int opts
, const char *string
,
690 int mode
, char **filename_opened
)
699 /* The open syscall MODE parameter is not specified. */
700 gdb_assert ((mode
& O_CREAT
) == 0);
707 if ((opts
& OPF_TRY_CWD_FIRST
) || IS_ABSOLUTE_PATH (string
))
711 if (is_regular_file (string
))
713 filename
= alloca (strlen (string
) + 1);
714 strcpy (filename
, string
);
715 fd
= open (filename
, mode
);
725 if (!(opts
& OPF_SEARCH_IN_PATH
))
726 for (i
= 0; string
[i
]; i
++)
727 if (IS_DIR_SEPARATOR (string
[i
]))
731 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
732 while (IS_DIR_SEPARATOR(string
[0]))
736 while (string
[0] == '.' && IS_DIR_SEPARATOR (string
[1]))
739 alloclen
= strlen (path
) + strlen (string
) + 2;
740 filename
= alloca (alloclen
);
742 for (p
= path
; p
; p
= p1
? p1
+ 1 : 0)
744 p1
= strchr (p
, DIRNAME_SEPARATOR
);
750 if (len
== 4 && p
[0] == '$' && p
[1] == 'c'
751 && p
[2] == 'w' && p
[3] == 'd')
753 /* Name is $cwd -- insert current directory name instead. */
756 /* First, realloc the filename buffer if too short. */
757 len
= strlen (current_directory
);
758 newlen
= len
+ strlen (string
) + 2;
759 if (newlen
> alloclen
)
762 filename
= alloca (alloclen
);
764 strcpy (filename
, current_directory
);
768 /* Normal file name in path -- just use it. */
769 strncpy (filename
, p
, len
);
773 /* Remove trailing slashes */
774 while (len
> 0 && IS_DIR_SEPARATOR (filename
[len
- 1]))
777 strcat (filename
+ len
, SLASH_STRING
);
778 strcat (filename
, string
);
780 if (is_regular_file (filename
))
782 fd
= open (filename
, mode
);
791 /* If a file was opened, canonicalize its filename. Use xfullpath
792 rather than gdb_realpath to avoid resolving the basename part
793 of filenames when the associated file is a symbolic link. This
794 fixes a potential inconsistency between the filenames known to
795 GDB and the filenames it prints in the annotations. */
797 *filename_opened
= NULL
;
798 else if (IS_ABSOLUTE_PATH (filename
))
799 *filename_opened
= xfullpath (filename
);
802 /* Beware the // my son, the Emacs barfs, the botch that catch... */
804 char *f
= concat (current_directory
,
805 IS_DIR_SEPARATOR (current_directory
[strlen (current_directory
) - 1])
807 filename
, (char *)NULL
);
808 *filename_opened
= xfullpath (f
);
817 /* This is essentially a convenience, for clients that want the behaviour
818 of openp, using source_path, but that really don't want the file to be
819 opened but want instead just to know what the full pathname is (as
820 qualified against source_path).
822 The current working directory is searched first.
824 If the file was found, this function returns 1, and FULL_PATHNAME is
825 set to the fully-qualified pathname.
827 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
829 source_full_path_of (const char *filename
, char **full_pathname
)
833 fd
= openp (source_path
, OPF_TRY_CWD_FIRST
| OPF_SEARCH_IN_PATH
, filename
,
834 O_RDONLY
, full_pathname
);
837 *full_pathname
= NULL
;
845 /* Return non-zero if RULE matches PATH, that is if the rule can be
849 substitute_path_rule_matches (const struct substitute_path_rule
*rule
,
852 const int from_len
= strlen (rule
->from
);
853 const int path_len
= strlen (path
);
856 if (path_len
< from_len
)
859 /* The substitution rules are anchored at the start of the path,
860 so the path should start with rule->from. There is no filename
861 comparison routine, so we need to extract the first FROM_LEN
862 characters from PATH first and use that to do the comparison. */
864 path_start
= alloca (from_len
+ 1);
865 strncpy (path_start
, path
, from_len
);
866 path_start
[from_len
] = '\0';
868 if (FILENAME_CMP (path_start
, rule
->from
) != 0)
871 /* Make sure that the region in the path that matches the substitution
872 rule is immediately followed by a directory separator (or the end of
873 string character). */
875 if (path
[from_len
] != '\0' && !IS_DIR_SEPARATOR (path
[from_len
]))
881 /* Find the substitute-path rule that applies to PATH and return it.
882 Return NULL if no rule applies. */
884 static struct substitute_path_rule
*
885 get_substitute_path_rule (const char *path
)
887 struct substitute_path_rule
*rule
= substitute_path_rules
;
889 while (rule
!= NULL
&& !substitute_path_rule_matches (rule
, path
))
895 /* If the user specified a source path substitution rule that applies
896 to PATH, then apply it and return the new path. This new path must
897 be deallocated afterwards.
899 Return NULL if no substitution rule was specified by the user,
900 or if no rule applied to the given PATH. */
903 rewrite_source_path (const char *path
)
905 const struct substitute_path_rule
*rule
= get_substitute_path_rule (path
);
912 from_len
= strlen (rule
->from
);
914 /* Compute the rewritten path and return it. */
917 (char *) xmalloc (strlen (path
) + 1 + strlen (rule
->to
) - from_len
);
918 strcpy (new_path
, rule
->to
);
919 strcat (new_path
, path
+ from_len
);
924 /* This function is capable of finding the absolute path to a
925 source file, and opening it, provided you give it a FILENAME. Both the
926 DIRNAME and FULLNAME are only added suggestions on where to find the file.
928 FILENAME should be the filename to open.
929 DIRNAME is the compilation directory of a particular source file.
930 Only some debug formats provide this info.
931 FULLNAME can be the last known absolute path to the file in question.
932 Space for the path must have been malloc'd. If a path substitution
933 is applied we free the old value and set a new one.
936 A valid file descriptor is returned. ( the return value is positive )
937 FULLNAME is set to the absolute path to the file just opened.
938 The caller is responsible for freeing FULLNAME.
941 An invalid file descriptor is returned. ( the return value is negative )
942 FULLNAME is set to NULL. */
945 find_and_open_source (const char *filename
,
949 char *path
= source_path
;
953 /* Quick way out if we already know its full name */
957 /* The user may have requested that source paths be rewritten
958 according to substitution rules he provided. If a substitution
959 rule applies to this path, then apply it. */
960 char *rewritten_fullname
= rewrite_source_path (*fullname
);
962 if (rewritten_fullname
!= NULL
)
965 *fullname
= rewritten_fullname
;
968 result
= open (*fullname
, OPEN_MODE
);
971 /* Didn't work -- free old one, try again. */
978 /* If necessary, rewrite the compilation directory name according
979 to the source path substitution rules specified by the user. */
981 char *rewritten_dirname
= rewrite_source_path (dirname
);
983 if (rewritten_dirname
!= NULL
)
985 make_cleanup (xfree
, rewritten_dirname
);
986 dirname
= rewritten_dirname
;
989 /* Replace a path entry of $cdir with the compilation directory name */
991 /* We cast strstr's result in case an ANSIhole has made it const,
992 which produces a "required warning" when assigned to a nonconst. */
993 p
= (char *) strstr (source_path
, "$cdir");
994 if (p
&& (p
== path
|| p
[-1] == DIRNAME_SEPARATOR
)
995 && (p
[cdir_len
] == DIRNAME_SEPARATOR
|| p
[cdir_len
] == '\0'))
1000 alloca (strlen (source_path
) + 1 + strlen (dirname
) + 1);
1001 len
= p
- source_path
;
1002 strncpy (path
, source_path
, len
); /* Before $cdir */
1003 strcpy (path
+ len
, dirname
); /* new stuff */
1004 strcat (path
+ len
, source_path
+ len
+ cdir_len
); /* After $cdir */
1008 if (IS_ABSOLUTE_PATH (filename
))
1010 /* If filename is absolute path, try the source path
1011 substitution on it. */
1012 char *rewritten_filename
= rewrite_source_path (filename
);
1014 if (rewritten_filename
!= NULL
)
1016 make_cleanup (xfree
, rewritten_filename
);
1017 filename
= rewritten_filename
;
1021 result
= openp (path
, OPF_SEARCH_IN_PATH
, filename
, OPEN_MODE
, fullname
);
1024 /* Didn't work. Try using just the basename. */
1025 p
= lbasename (filename
);
1027 result
= openp (path
, OPF_SEARCH_IN_PATH
, p
, OPEN_MODE
, fullname
);
1033 /* Open a source file given a symtab S. Returns a file descriptor or
1034 negative number for error.
1036 This function is a convience function to find_and_open_source. */
1039 open_source_file (struct symtab
*s
)
1044 return find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1047 /* Finds the fullname that a symtab represents.
1049 If this functions finds the fullname, it will save it in s->fullname
1050 and it will also return the value.
1052 If this function fails to find the file that this symtab represents,
1053 NULL will be returned and s->fullname will be set to NULL. */
1055 symtab_to_fullname (struct symtab
*s
)
1062 /* Don't check s->fullname here, the file could have been
1063 deleted/moved/..., look for it again */
1064 r
= find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1075 /* Finds the fullname that a partial_symtab represents.
1077 If this functions finds the fullname, it will save it in ps->fullname
1078 and it will also return the value.
1080 If this function fails to find the file that this partial_symtab represents,
1081 NULL will be returned and ps->fullname will be set to NULL. */
1083 psymtab_to_fullname (struct partial_symtab
*ps
)
1090 /* Don't check ps->fullname here, the file could have been
1091 deleted/moved/..., look for it again */
1092 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1097 return ps
->fullname
;
1103 /* Create and initialize the table S->line_charpos that records
1104 the positions of the lines in the source file, which is assumed
1105 to be open on descriptor DESC.
1106 All set S->nlines to the number of such lines. */
1109 find_source_lines (struct symtab
*s
, int desc
)
1112 char *data
, *p
, *end
;
1114 int lines_allocated
= 1000;
1120 line_charpos
= (int *) xmalloc (lines_allocated
* sizeof (int));
1121 if (fstat (desc
, &st
) < 0)
1122 perror_with_name (s
->filename
);
1124 if (s
->objfile
&& s
->objfile
->obfd
)
1125 mtime
= s
->objfile
->mtime
;
1127 mtime
= exec_bfd_mtime
;
1129 if (mtime
&& mtime
< st
.st_mtime
)
1130 warning (_("Source file is more recent than executable."));
1132 #ifdef LSEEK_NOT_LINEAR
1136 /* Have to read it byte by byte to find out where the chars live */
1138 line_charpos
[0] = lseek (desc
, 0, SEEK_CUR
);
1140 while (myread (desc
, &c
, 1) > 0)
1144 if (nlines
== lines_allocated
)
1146 lines_allocated
*= 2;
1148 (int *) xrealloc ((char *) line_charpos
,
1149 sizeof (int) * lines_allocated
);
1151 line_charpos
[nlines
++] = lseek (desc
, 0, SEEK_CUR
);
1155 #else /* lseek linear. */
1157 struct cleanup
*old_cleanups
;
1159 /* st_size might be a large type, but we only support source files whose
1160 size fits in an int. */
1161 size
= (int) st
.st_size
;
1163 /* Use malloc, not alloca, because this may be pretty large, and we may
1164 run into various kinds of limits on stack size. */
1165 data
= (char *) xmalloc (size
);
1166 old_cleanups
= make_cleanup (xfree
, data
);
1168 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1169 size
= myread (desc
, data
, size
);
1171 perror_with_name (s
->filename
);
1174 line_charpos
[0] = 0;
1179 /* A newline at the end does not start a new line. */
1182 if (nlines
== lines_allocated
)
1184 lines_allocated
*= 2;
1186 (int *) xrealloc ((char *) line_charpos
,
1187 sizeof (int) * lines_allocated
);
1189 line_charpos
[nlines
++] = p
- data
;
1192 do_cleanups (old_cleanups
);
1194 #endif /* lseek linear. */
1197 (int *) xrealloc ((char *) line_charpos
, nlines
* sizeof (int));
1201 /* Return the character position of a line LINE in symtab S.
1202 Return 0 if anything is invalid. */
1204 #if 0 /* Currently unused */
1207 source_line_charpos (struct symtab
*s
, int line
)
1211 if (!s
->line_charpos
|| line
<= 0)
1213 if (line
> s
->nlines
)
1215 return s
->line_charpos
[line
- 1];
1218 /* Return the line number of character position POS in symtab S. */
1221 source_charpos_line (struct symtab
*s
, int chr
)
1226 if (s
== 0 || s
->line_charpos
== 0)
1228 lnp
= s
->line_charpos
;
1229 /* Files are usually short, so sequential search is Ok */
1230 while (line
< s
->nlines
&& *lnp
<= chr
)
1235 if (line
>= s
->nlines
)
1243 /* Get full pathname and line number positions for a symtab.
1244 Return nonzero if line numbers may have changed.
1245 Set *FULLNAME to actual name of the file as found by `openp',
1246 or to 0 if the file is not found. */
1249 get_filename_and_charpos (struct symtab
*s
, char **fullname
)
1251 int desc
, linenums_changed
= 0;
1252 struct cleanup
*cleanups
;
1254 desc
= open_source_file (s
);
1261 cleanups
= make_cleanup_close (desc
);
1263 *fullname
= s
->fullname
;
1264 if (s
->line_charpos
== 0)
1265 linenums_changed
= 1;
1266 if (linenums_changed
)
1267 find_source_lines (s
, desc
);
1268 do_cleanups (cleanups
);
1269 return linenums_changed
;
1272 /* Print text describing the full name of the source file S
1273 and the line number LINE and its corresponding character position.
1274 The text starts with two Ctrl-z so that the Emacs-GDB interface
1277 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1279 Return 1 if successful, 0 if could not find the file. */
1282 identify_source_line (struct symtab
*s
, int line
, int mid_statement
,
1285 if (s
->line_charpos
== 0)
1286 get_filename_and_charpos (s
, (char **) NULL
);
1287 if (s
->fullname
== 0)
1289 if (line
> s
->nlines
)
1290 /* Don't index off the end of the line_charpos array. */
1292 annotate_source (s
->fullname
, line
, s
->line_charpos
[line
- 1],
1293 mid_statement
, get_objfile_arch (s
->objfile
), pc
);
1295 current_source_line
= line
;
1296 first_line_listed
= line
;
1297 last_line_listed
= line
;
1298 current_source_symtab
= s
;
1303 /* Print source lines from the file of symtab S,
1304 starting with line number LINE and stopping before line number STOPLINE. */
1306 static void print_source_lines_base (struct symtab
*s
, int line
, int stopline
,
1309 print_source_lines_base (struct symtab
*s
, int line
, int stopline
, int noerror
)
1314 int nlines
= stopline
- line
;
1315 struct cleanup
*cleanup
;
1317 /* Regardless of whether we can open the file, set current_source_symtab. */
1318 current_source_symtab
= s
;
1319 current_source_line
= line
;
1320 first_line_listed
= line
;
1322 /* If printing of source lines is disabled, just print file and line number */
1323 if (ui_out_test_flags (uiout
, ui_source_list
))
1325 /* Only prints "No such file or directory" once */
1326 if ((s
!= last_source_visited
) || (!last_source_error
))
1328 last_source_visited
= s
;
1329 desc
= open_source_file (s
);
1333 desc
= last_source_error
;
1345 last_source_error
= desc
;
1349 char *name
= alloca (strlen (s
->filename
) + 100);
1350 sprintf (name
, "%d\t%s", line
, s
->filename
);
1351 print_sys_errmsg (name
, errno
);
1354 ui_out_field_int (uiout
, "line", line
);
1355 ui_out_text (uiout
, "\tin ");
1356 ui_out_field_string (uiout
, "file", s
->filename
);
1357 ui_out_text (uiout
, "\n");
1362 last_source_error
= 0;
1364 if (s
->line_charpos
== 0)
1365 find_source_lines (s
, desc
);
1367 if (line
< 1 || line
> s
->nlines
)
1370 error (_("Line number %d out of range; %s has %d lines."),
1371 line
, s
->filename
, s
->nlines
);
1374 if (lseek (desc
, s
->line_charpos
[line
- 1], 0) < 0)
1377 perror_with_name (s
->filename
);
1380 stream
= fdopen (desc
, FDOPEN_MODE
);
1382 cleanup
= make_cleanup_fclose (stream
);
1384 while (nlines
-- > 0)
1391 last_line_listed
= current_source_line
;
1392 sprintf (buf
, "%d\t", current_source_line
++);
1393 ui_out_text (uiout
, buf
);
1396 if (c
< 040 && c
!= '\t' && c
!= '\n' && c
!= '\r')
1398 sprintf (buf
, "^%c", c
+ 0100);
1399 ui_out_text (uiout
, buf
);
1402 ui_out_text (uiout
, "^?");
1405 /* Skip a \r character, but only before a \n. */
1406 int c1
= fgetc (stream
);
1409 printf_filtered ("^%c", c
+ 0100);
1411 ungetc (c1
, stream
);
1415 sprintf (buf
, "%c", c
);
1416 ui_out_text (uiout
, buf
);
1419 while (c
!= '\n' && (c
= fgetc (stream
)) >= 0);
1422 do_cleanups (cleanup
);
1425 /* Show source lines from the file of symtab S, starting with line
1426 number LINE and stopping before line number STOPLINE. If this is
1427 not the command line version, then the source is shown in the source
1428 window otherwise it is simply printed */
1431 print_source_lines (struct symtab
*s
, int line
, int stopline
, int noerror
)
1433 print_source_lines_base (s
, line
, stopline
, noerror
);
1436 /* Print info on range of pc's in a specified line. */
1439 line_info (char *arg
, int from_tty
)
1441 struct symtabs_and_lines sals
;
1442 struct symtab_and_line sal
;
1443 CORE_ADDR start_pc
, end_pc
;
1446 init_sal (&sal
); /* initialize to zeroes */
1450 sal
.symtab
= current_source_symtab
;
1451 sal
.line
= last_line_listed
;
1453 sals
.sals
= (struct symtab_and_line
*)
1454 xmalloc (sizeof (struct symtab_and_line
));
1459 sals
= decode_line_spec_1 (arg
, 0);
1464 /* C++ More than one line may have been specified, as when the user
1465 specifies an overloaded function name. Print info on them all. */
1466 for (i
= 0; i
< sals
.nelts
; i
++)
1470 if (sal
.symtab
== 0)
1472 struct gdbarch
*gdbarch
= get_current_arch ();
1474 printf_filtered (_("No line number information available"));
1477 /* This is useful for "info line *0x7f34". If we can't tell the
1478 user about a source line, at least let them have the symbolic
1480 printf_filtered (" for address ");
1482 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1485 printf_filtered (".");
1486 printf_filtered ("\n");
1488 else if (sal
.line
> 0
1489 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1491 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1493 if (start_pc
== end_pc
)
1495 printf_filtered ("Line %d of \"%s\"",
1496 sal
.line
, sal
.symtab
->filename
);
1498 printf_filtered (" is at address ");
1499 print_address (gdbarch
, start_pc
, gdb_stdout
);
1501 printf_filtered (" but contains no code.\n");
1505 printf_filtered ("Line %d of \"%s\"",
1506 sal
.line
, sal
.symtab
->filename
);
1508 printf_filtered (" starts at address ");
1509 print_address (gdbarch
, start_pc
, gdb_stdout
);
1511 printf_filtered (" and ends at ");
1512 print_address (gdbarch
, end_pc
, gdb_stdout
);
1513 printf_filtered (".\n");
1516 /* x/i should display this line's code. */
1517 set_next_address (gdbarch
, start_pc
);
1519 /* Repeating "info line" should do the following line. */
1520 last_line_listed
= sal
.line
+ 1;
1522 /* If this is the only line, show the source code. If it could
1523 not find the file, don't do anything special. */
1524 if (annotation_level
&& sals
.nelts
== 1)
1525 identify_source_line (sal
.symtab
, sal
.line
, 0, start_pc
);
1528 /* Is there any case in which we get here, and have an address
1529 which the user would want to see? If we have debugging symbols
1530 and no line numbers? */
1531 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
1532 sal
.line
, sal
.symtab
->filename
);
1537 /* Commands to search the source file for a regexp. */
1540 forward_search_command (char *regex
, int from_tty
)
1547 struct cleanup
*cleanups
;
1549 line
= last_line_listed
+ 1;
1551 msg
= (char *) re_comp (regex
);
1553 error (("%s"), msg
);
1555 if (current_source_symtab
== 0)
1556 select_source_symtab (0);
1558 desc
= open_source_file (current_source_symtab
);
1560 perror_with_name (current_source_symtab
->filename
);
1561 cleanups
= make_cleanup_close (desc
);
1563 if (current_source_symtab
->line_charpos
== 0)
1564 find_source_lines (current_source_symtab
, desc
);
1566 if (line
< 1 || line
> current_source_symtab
->nlines
)
1567 error (_("Expression not found"));
1569 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1570 perror_with_name (current_source_symtab
->filename
);
1572 discard_cleanups (cleanups
);
1573 stream
= fdopen (desc
, FDOPEN_MODE
);
1575 cleanups
= make_cleanup_fclose (stream
);
1578 static char *buf
= NULL
;
1580 int cursize
, newsize
;
1583 buf
= xmalloc (cursize
);
1592 if (p
- buf
== cursize
)
1594 newsize
= cursize
+ cursize
/ 2;
1595 buf
= xrealloc (buf
, newsize
);
1600 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1602 /* Remove the \r, if any, at the end of the line, otherwise
1603 regular expressions that end with $ or \n won't work. */
1604 if (p
- buf
> 1 && p
[-2] == '\r')
1610 /* we now have a source line in buf, null terminate and match */
1612 if (re_exec (buf
) > 0)
1615 do_cleanups (cleanups
);
1616 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1617 set_internalvar_integer (lookup_internalvar ("_"), line
);
1618 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1624 printf_filtered (_("Expression not found\n"));
1625 do_cleanups (cleanups
);
1629 reverse_search_command (char *regex
, int from_tty
)
1636 struct cleanup
*cleanups
;
1638 line
= last_line_listed
- 1;
1640 msg
= (char *) re_comp (regex
);
1642 error (("%s"), msg
);
1644 if (current_source_symtab
== 0)
1645 select_source_symtab (0);
1647 desc
= open_source_file (current_source_symtab
);
1649 perror_with_name (current_source_symtab
->filename
);
1650 cleanups
= make_cleanup_close (desc
);
1652 if (current_source_symtab
->line_charpos
== 0)
1653 find_source_lines (current_source_symtab
, desc
);
1655 if (line
< 1 || line
> current_source_symtab
->nlines
)
1656 error (_("Expression not found"));
1658 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1659 perror_with_name (current_source_symtab
->filename
);
1661 discard_cleanups (cleanups
);
1662 stream
= fdopen (desc
, FDOPEN_MODE
);
1664 cleanups
= make_cleanup_fclose (stream
);
1667 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1668 char buf
[4096]; /* Should be reasonable??? */
1678 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1680 /* Remove the \r, if any, at the end of the line, otherwise
1681 regular expressions that end with $ or \n won't work. */
1682 if (p
- buf
> 1 && p
[-2] == '\r')
1688 /* We now have a source line in buf; null terminate and match. */
1690 if (re_exec (buf
) > 0)
1693 do_cleanups (cleanups
);
1694 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1695 set_internalvar_integer (lookup_internalvar ("_"), line
);
1696 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1700 if (fseek (stream
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1702 do_cleanups (cleanups
);
1703 perror_with_name (current_source_symtab
->filename
);
1707 printf_filtered (_("Expression not found\n"));
1708 do_cleanups (cleanups
);
1712 /* If the last character of PATH is a directory separator, then strip it. */
1715 strip_trailing_directory_separator (char *path
)
1717 const int last
= strlen (path
) - 1;
1720 return; /* No stripping is needed if PATH is the empty string. */
1722 if (IS_DIR_SEPARATOR (path
[last
]))
1726 /* Return the path substitution rule that matches FROM.
1727 Return NULL if no rule matches. */
1729 static struct substitute_path_rule
*
1730 find_substitute_path_rule (const char *from
)
1732 struct substitute_path_rule
*rule
= substitute_path_rules
;
1734 while (rule
!= NULL
)
1736 if (FILENAME_CMP (rule
->from
, from
) == 0)
1744 /* Add a new substitute-path rule at the end of the current list of rules.
1745 The new rule will replace FROM into TO. */
1748 add_substitute_path_rule (char *from
, char *to
)
1750 struct substitute_path_rule
*rule
;
1751 struct substitute_path_rule
*new_rule
;
1753 new_rule
= xmalloc (sizeof (struct substitute_path_rule
));
1754 new_rule
->from
= xstrdup (from
);
1755 new_rule
->to
= xstrdup (to
);
1756 new_rule
->next
= NULL
;
1758 /* If the list of rules are empty, then insert the new rule
1759 at the head of the list. */
1761 if (substitute_path_rules
== NULL
)
1763 substitute_path_rules
= new_rule
;
1767 /* Otherwise, skip to the last rule in our list and then append
1770 rule
= substitute_path_rules
;
1771 while (rule
->next
!= NULL
)
1774 rule
->next
= new_rule
;
1777 /* Remove the given source path substitution rule from the current list
1778 of rules. The memory allocated for that rule is also deallocated. */
1781 delete_substitute_path_rule (struct substitute_path_rule
*rule
)
1783 if (rule
== substitute_path_rules
)
1784 substitute_path_rules
= rule
->next
;
1787 struct substitute_path_rule
*prev
= substitute_path_rules
;
1789 while (prev
!= NULL
&& prev
->next
!= rule
)
1792 gdb_assert (prev
!= NULL
);
1794 prev
->next
= rule
->next
;
1802 /* Implement the "show substitute-path" command. */
1805 show_substitute_path_command (char *args
, int from_tty
)
1807 struct substitute_path_rule
*rule
= substitute_path_rules
;
1811 argv
= gdb_buildargv (args
);
1812 make_cleanup_freeargv (argv
);
1814 /* We expect zero or one argument. */
1816 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1817 error (_("Too many arguments in command"));
1819 if (argv
!= NULL
&& argv
[0] != NULL
)
1822 /* Print the substitution rules. */
1826 (_("Source path substitution rule matching `%s':\n"), from
);
1828 printf_filtered (_("List of all source path substitution rules:\n"));
1830 while (rule
!= NULL
)
1832 if (from
== NULL
|| FILENAME_CMP (rule
->from
, from
) == 0)
1833 printf_filtered (" `%s' -> `%s'.\n", rule
->from
, rule
->to
);
1838 /* Implement the "unset substitute-path" command. */
1841 unset_substitute_path_command (char *args
, int from_tty
)
1843 struct substitute_path_rule
*rule
= substitute_path_rules
;
1844 char **argv
= gdb_buildargv (args
);
1848 /* This function takes either 0 or 1 argument. */
1850 make_cleanup_freeargv (argv
);
1851 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1852 error (_("Incorrect usage, too many arguments in command"));
1854 if (argv
!= NULL
&& argv
[0] != NULL
)
1857 /* If the user asked for all the rules to be deleted, ask him
1858 to confirm and give him a chance to abort before the action
1862 && !query (_("Delete all source path substitution rules? ")))
1863 error (_("Canceled"));
1865 /* Delete the rule matching the argument. No argument means that
1866 all rules should be deleted. */
1868 while (rule
!= NULL
)
1870 struct substitute_path_rule
*next
= rule
->next
;
1872 if (from
== NULL
|| FILENAME_CMP (from
, rule
->from
) == 0)
1874 delete_substitute_path_rule (rule
);
1881 /* If the user asked for a specific rule to be deleted but
1882 we could not find it, then report an error. */
1884 if (from
!= NULL
&& !rule_found
)
1885 error (_("No substitution rule defined for `%s'"), from
);
1888 /* Add a new source path substitution rule. */
1891 set_substitute_path_command (char *args
, int from_tty
)
1893 char *from_path
, *to_path
;
1895 struct substitute_path_rule
*rule
;
1897 argv
= gdb_buildargv (args
);
1898 make_cleanup_freeargv (argv
);
1900 if (argv
== NULL
|| argv
[0] == NULL
|| argv
[1] == NULL
)
1901 error (_("Incorrect usage, too few arguments in command"));
1903 if (argv
[2] != NULL
)
1904 error (_("Incorrect usage, too many arguments in command"));
1906 if (*(argv
[0]) == '\0')
1907 error (_("First argument must be at least one character long"));
1909 /* Strip any trailing directory separator character in either FROM
1910 or TO. The substitution rule already implicitly contains them. */
1911 strip_trailing_directory_separator (argv
[0]);
1912 strip_trailing_directory_separator (argv
[1]);
1914 /* If a rule with the same "from" was previously defined, then
1915 delete it. This new rule replaces it. */
1917 rule
= find_substitute_path_rule (argv
[0]);
1919 delete_substitute_path_rule (rule
);
1921 /* Insert the new substitution rule. */
1923 add_substitute_path_rule (argv
[0], argv
[1]);
1928 _initialize_source (void)
1930 struct cmd_list_element
*c
;
1931 current_source_symtab
= 0;
1932 init_source_path ();
1934 /* The intention is to use POSIX Basic Regular Expressions.
1935 Always use the GNU regex routine for consistency across all hosts.
1936 Our current GNU regex.c does not have all the POSIX features, so this is
1937 just an approximation. */
1938 re_set_syntax (RE_SYNTAX_GREP
);
1940 c
= add_cmd ("directory", class_files
, directory_command
, _("\
1941 Add directory DIR to beginning of search path for source files.\n\
1942 Forget cached info on source file locations and line positions.\n\
1943 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1944 directory in which the source file was compiled into object code.\n\
1945 With no argument, reset the search path to $cdir:$cwd, the default."),
1949 add_com_alias ("use", "directory", class_files
, 0);
1951 set_cmd_completer (c
, filename_completer
);
1953 add_cmd ("directories", no_class
, show_directories
, _("\
1954 Current search path for finding source files.\n\
1955 $cwd in the path means the current working directory.\n\
1956 $cdir in the path means the compilation directory of the source file."),
1961 add_com_alias ("D", "directory", class_files
, 0);
1962 add_cmd ("ld", no_class
, show_directories
, _("\
1963 Current search path for finding source files.\n\
1964 $cwd in the path means the current working directory.\n\
1965 $cdir in the path means the compilation directory of the source file."),
1969 add_info ("source", source_info
,
1970 _("Information about the current source file."));
1972 add_info ("line", line_info
, _("\
1973 Core addresses of the code for a source line.\n\
1974 Line can be specified as\n\
1975 LINENUM, to list around that line in current file,\n\
1976 FILE:LINENUM, to list around that line in that file,\n\
1977 FUNCTION, to list around beginning of that function,\n\
1978 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1979 Default is to describe the last source line that was listed.\n\n\
1980 This sets the default address for \"x\" to the line's first instruction\n\
1981 so that \"x/i\" suffices to start examining the machine code.\n\
1982 The address is also stored as the value of \"$_\"."));
1984 add_com ("forward-search", class_files
, forward_search_command
, _("\
1985 Search for regular expression (see regex(3)) from last line listed.\n\
1986 The matching line number is also stored as the value of \"$_\"."));
1987 add_com_alias ("search", "forward-search", class_files
, 0);
1989 add_com ("reverse-search", class_files
, reverse_search_command
, _("\
1990 Search backward for regular expression (see regex(3)) from last line listed.\n\
1991 The matching line number is also stored as the value of \"$_\"."));
1995 add_com_alias ("/", "forward-search", class_files
, 0);
1996 add_com_alias ("?", "reverse-search", class_files
, 0);
1999 add_setshow_integer_cmd ("listsize", class_support
, &lines_to_list
, _("\
2000 Set number of source lines gdb will list by default."), _("\
2001 Show number of source lines gdb will list by default."), NULL
,
2004 &setlist
, &showlist
);
2006 add_cmd ("substitute-path", class_files
, set_substitute_path_command
,
2008 Usage: set substitute-path FROM TO\n\
2009 Add a substitution rule replacing FROM into TO in source file names.\n\
2010 If a substitution rule was previously set for FROM, the old rule\n\
2011 is replaced by the new one."),
2014 add_cmd ("substitute-path", class_files
, unset_substitute_path_command
,
2016 Usage: unset substitute-path [FROM]\n\
2017 Delete the rule for substituting FROM in source file names. If FROM\n\
2018 is not specified, all substituting rules are deleted.\n\
2019 If the debugger cannot find a rule for FROM, it will display a warning."),
2022 add_cmd ("substitute-path", class_files
, show_substitute_path_command
,
2024 Usage: show substitute-path [FROM]\n\
2025 Print the rule for substituting FROM in source file names. If FROM\n\
2026 is not specified, print all substitution rules."),