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, 2011 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 /* 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 static struct program_space
*current_source_pspace
;
97 /* Default number of lines to print with commands like "list".
98 This is based on guessing how many long (i.e. more than chars_per_line
99 characters) lines there will be. To be completely correct, "list"
100 and friends should be rewritten to count characters and see where
101 things are wrapping, but that would be a fair amount of work. */
103 int lines_to_list
= 10;
105 show_lines_to_list (struct ui_file
*file
, int from_tty
,
106 struct cmd_list_element
*c
, const char *value
)
108 fprintf_filtered (file
, _("\
109 Number of source lines gdb will list by default is %s.\n"),
113 /* Line number of last line printed. Default for various commands.
114 current_source_line is usually, but not always, the same as this. */
116 static int last_line_listed
;
118 /* First line number listed by last listing command. */
120 static int first_line_listed
;
122 /* Saves the name of the last source file visited and a possible error code.
123 Used to prevent repeating annoying "No such file or directories" msgs */
125 static struct symtab
*last_source_visited
= NULL
;
126 static int last_source_error
= 0;
128 /* Return the first line listed by print_source_lines.
129 Used by command interpreters to request listing from
133 get_first_line_listed (void)
135 return first_line_listed
;
138 /* Return the default number of lines to print with commands like the
139 cli "list". The caller of print_source_lines must use this to
140 calculate the end line and use it in the call to print_source_lines
141 as it does not automatically use this value. */
144 get_lines_to_list (void)
146 return lines_to_list
;
149 /* Return the current source file for listing and next line to list.
150 NOTE: The returned sal pc and end fields are not valid. */
152 struct symtab_and_line
153 get_current_source_symtab_and_line (void)
155 struct symtab_and_line cursal
= { 0 };
157 cursal
.pspace
= current_source_pspace
;
158 cursal
.symtab
= current_source_symtab
;
159 cursal
.line
= current_source_line
;
166 /* If the current source file for listing is not set, try and get a default.
167 Usually called before get_current_source_symtab_and_line() is called.
168 It may err out if a default cannot be determined.
169 We must be cautious about where it is called, as it can recurse as the
170 process of determining a new default may call the caller!
171 Use get_current_source_symtab_and_line only to get whatever
172 we have without erroring out or trying to get a default. */
175 set_default_source_symtab_and_line (void)
177 if (!have_full_symbols () && !have_partial_symbols ())
178 error (_("No symbol table is loaded. Use the \"file\" command."));
180 /* Pull in a current source symtab if necessary */
181 if (current_source_symtab
== 0)
182 select_source_symtab (0);
185 /* Return the current default file for listing and next line to list
186 (the returned sal pc and end fields are not valid.)
187 and set the current default to whatever is in SAL.
188 NOTE: The returned sal pc and end fields are not valid. */
190 struct symtab_and_line
191 set_current_source_symtab_and_line (const struct symtab_and_line
*sal
)
193 struct symtab_and_line cursal
= { 0 };
195 cursal
.pspace
= current_source_pspace
;
196 cursal
.symtab
= current_source_symtab
;
197 cursal
.line
= current_source_line
;
201 current_source_pspace
= sal
->pspace
;
202 current_source_symtab
= sal
->symtab
;
203 current_source_line
= sal
->line
;
208 /* Reset any information stored about a default file and line to print. */
211 clear_current_source_symtab_and_line (void)
213 current_source_symtab
= 0;
214 current_source_line
= 0;
217 /* Set the source file default for the "list" command to be S.
219 If S is NULL, and we don't have a default, find one. This
220 should only be called when the user actually tries to use the
221 default, since we produce an error if we can't find a reasonable
222 default. Also, since this can cause symbols to be read, doing it
223 before we need to would make things slower than necessary. */
226 select_source_symtab (struct symtab
*s
)
228 struct symtabs_and_lines sals
;
229 struct symtab_and_line sal
;
234 current_source_symtab
= s
;
235 current_source_line
= 1;
236 current_source_pspace
= SYMTAB_PSPACE (s
);
240 if (current_source_symtab
)
243 /* Make the default place to list be the function `main'
245 if (lookup_symbol (main_name (), 0, VAR_DOMAIN
, 0))
247 sals
= decode_line_spec (main_name (), 1);
250 current_source_pspace
= sal
.pspace
;
251 current_source_symtab
= sal
.symtab
;
252 current_source_line
= max (sal
.line
- (lines_to_list
- 1), 1);
253 if (current_source_symtab
)
257 /* Alright; find the last file in the symtab list (ignoring .h's
258 and namespace symtabs). */
260 current_source_line
= 1;
264 for (s
= ofp
->symtabs
; s
; s
= s
->next
)
266 const char *name
= s
->filename
;
267 int len
= strlen (name
);
269 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
270 || strcmp (name
, "<<C++-namespaces>>") == 0)))
272 current_source_pspace
= current_program_space
;
273 current_source_symtab
= s
;
278 if (current_source_symtab
)
284 s
= ofp
->sf
->qf
->find_last_source_symtab (ofp
);
286 current_source_symtab
= s
;
288 if (current_source_symtab
)
291 error (_("Can't find a default source file"));
294 /* Handler for "set directories path-list" command.
295 "set dir mumble" doesn't prepend paths, it resets the entire
296 path list. The theory is that set(show(dir)) should be a no-op. */
299 set_directories_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
301 /* This is the value that was set.
302 It needs to be processed to maintain $cdir:$cwd and remove dups. */
303 char *set_path
= source_path
;
305 /* We preserve the invariant that $cdir:$cwd begins life at the end of
306 the list by calling init_source_path. If they appear earlier in
307 SET_PATH then mod_path will move them appropriately.
308 mod_path will also remove duplicates. */
310 if (*set_path
!= '\0')
311 mod_path (set_path
, &source_path
);
316 /* Print the list of source directories.
317 This is used by the "ld" command, so it has the signature of a command
321 show_directories_1 (char *ignore
, int from_tty
)
323 puts_filtered ("Source directories searched: ");
324 puts_filtered (source_path
);
325 puts_filtered ("\n");
328 /* Handler for "show directories" command. */
331 show_directories_command (struct ui_file
*file
, int from_tty
,
332 struct cmd_list_element
*c
, const char *value
)
334 show_directories_1 (NULL
, from_tty
);
337 /* Forget what we learned about line positions in source files, and
338 which directories contain them; must check again now since files
339 may be found in a different directory now. */
342 forget_cached_source_info (void)
344 struct program_space
*pspace
;
346 struct objfile
*objfile
;
349 ALL_PSPACE_OBJFILES (pspace
, objfile
)
351 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
->next
)
353 if (s
->line_charpos
!= NULL
)
355 xfree (s
->line_charpos
);
356 s
->line_charpos
= NULL
;
358 if (s
->fullname
!= NULL
)
366 objfile
->sf
->qf
->forget_cached_source_info (objfile
);
369 last_source_visited
= NULL
;
373 init_source_path (void)
377 sprintf (buf
, "$cdir%c$cwd", DIRNAME_SEPARATOR
);
378 source_path
= xstrdup (buf
);
379 forget_cached_source_info ();
382 /* Add zero or more directories to the front of the source path. */
385 directory_command (char *dirname
, int from_tty
)
388 /* FIXME, this goes to "delete dir"... */
391 if (!from_tty
|| query (_("Reinitialize source path to empty? ")))
399 mod_path (dirname
, &source_path
);
400 forget_cached_source_info ();
403 show_directories_1 ((char *) 0, from_tty
);
406 /* Add a path given with the -d command line switch.
407 This will not be quoted so we must not treat spaces as separators. */
410 directory_switch (char *dirname
, int from_tty
)
412 add_path (dirname
, &source_path
, 0);
415 /* Add zero or more directories to the front of an arbitrary path. */
418 mod_path (char *dirname
, char **which_path
)
420 add_path (dirname
, which_path
, 1);
423 /* Workhorse of mod_path. Takes an extra argument to determine
424 if dirname should be parsed for separators that indicate multiple
425 directories. This allows for interfaces that pre-parse the dirname
426 and allow specification of traditional separator characters such
430 add_path (char *dirname
, char **which_path
, int parse_separators
)
432 char *old
= *which_path
;
441 if (parse_separators
)
443 /* This will properly parse the space and tab separators
444 and any quotes that may exist. DIRNAME_SEPARATOR will
445 be dealt with later. */
446 argv
= gdb_buildargv (dirname
);
447 make_cleanup_freeargv (argv
);
453 arg
= xstrdup (dirname
);
454 make_cleanup (xfree
, arg
);
464 char *separator
= NULL
;
466 /* Spaces and tabs will have been removed by buildargv().
467 The directories will there be split into a list but
468 each entry may still contain DIRNAME_SEPARATOR. */
469 if (parse_separators
)
470 separator
= strchr (name
, DIRNAME_SEPARATOR
);
473 p
= arg
= name
+ strlen (name
);
478 while (*arg
== DIRNAME_SEPARATOR
)
482 /* If there are no more directories in this argument then start
483 on the next argument next time round the loop (if any). */
485 arg
= parse_separators
? argv
[++argv_index
] : NULL
;
488 /* name is the start of the directory.
489 p is the separator (or null) following the end. */
491 while (!(IS_DIR_SEPARATOR (*name
) && p
<= name
+ 1) /* "/" */
492 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
493 /* On MS-DOS and MS-Windows, h:\ is different from h: */
494 && !(p
== name
+ 3 && name
[1] == ':') /* "d:/" */
496 && IS_DIR_SEPARATOR (p
[-1]))
497 /* Sigh. "foo/" => "foo" */
501 while (p
> name
&& p
[-1] == '.')
505 /* "." => getwd (). */
506 name
= current_directory
;
509 else if (p
> name
+ 1 && IS_DIR_SEPARATOR (p
[-2]))
519 /* "...foo/." => "...foo". */
530 name
= tilde_expand (name
);
531 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
532 else if (IS_ABSOLUTE_PATH (name
) && p
== name
+ 2) /* "d:" => "d:." */
533 name
= concat (name
, ".", (char *)NULL
);
535 else if (!IS_ABSOLUTE_PATH (name
) && name
[0] != '$')
536 name
= concat (current_directory
, SLASH_STRING
, name
, (char *)NULL
);
538 name
= savestring (name
, p
- name
);
539 make_cleanup (xfree
, name
);
541 /* Unless it's a variable, check existence. */
544 /* These are warnings, not errors, since we don't want a
545 non-existent directory in a .gdbinit file to stop processing
546 of the .gdbinit file.
548 Whether they get added to the path is more debatable. Current
549 answer is yes, in case the user wants to go make the directory
550 or whatever. If the directory continues to not exist/not be
551 a directory/etc, then having them in the path should be
553 if (stat (name
, &st
) < 0)
555 int save_errno
= errno
;
557 fprintf_unfiltered (gdb_stderr
, "Warning: ");
558 print_sys_errmsg (name
, save_errno
);
560 else if ((st
.st_mode
& S_IFMT
) != S_IFDIR
)
561 warning (_("%s is not a directory."), name
);
566 unsigned int len
= strlen (name
);
571 /* FIXME: strncmp loses in interesting ways on MS-DOS and
572 MS-Windows because of case-insensitivity and two different
573 but functionally identical slash characters. We need a
574 special filesystem-dependent file-name comparison function.
576 Actually, even on Unix I would use realpath() or its work-
577 alike before comparing. Then all the code above which
578 removes excess slashes and dots could simply go away. */
579 if (!strncmp (p
, name
, len
)
580 && (p
[len
] == '\0' || p
[len
] == DIRNAME_SEPARATOR
))
582 /* Found it in the search path, remove old copy */
584 p
--; /* Back over leading separator */
585 if (prefix
> p
- *which_path
)
586 goto skip_dup
; /* Same dir twice in one cmd */
587 strcpy (p
, &p
[len
+ 1]); /* Copy from next \0 or : */
589 p
= strchr (p
, DIRNAME_SEPARATOR
);
599 tinybuf
[0] = DIRNAME_SEPARATOR
;
602 /* If we have already tacked on a name(s) in this command, be sure they stay
603 on the front as we tack on some more. */
610 temp
= concat (old
, tinybuf
, name
, (char *)NULL
);
612 *which_path
= concat (temp
, "", &old
[prefix
], (char *)NULL
);
613 prefix
= strlen (temp
);
618 *which_path
= concat (name
, (old
[0] ? tinybuf
: old
),
620 prefix
= strlen (name
);
633 source_info (char *ignore
, int from_tty
)
635 struct symtab
*s
= current_source_symtab
;
639 printf_filtered (_("No current source file.\n"));
642 printf_filtered (_("Current source file is %s\n"), s
->filename
);
644 printf_filtered (_("Compilation directory is %s\n"), s
->dirname
);
646 printf_filtered (_("Located in %s\n"), s
->fullname
);
648 printf_filtered (_("Contains %d line%s.\n"), s
->nlines
,
649 s
->nlines
== 1 ? "" : "s");
651 printf_filtered (_("Source language is %s.\n"), language_str (s
->language
));
652 printf_filtered (_("Compiled with %s debugging format.\n"), s
->debugformat
);
653 printf_filtered (_("%s preprocessor macro info.\n"),
654 s
->macro_table
? "Includes" : "Does not include");
658 /* Return True if the file NAME exists and is a regular file */
660 is_regular_file (const char *name
)
663 const int status
= stat (name
, &st
);
665 /* Stat should never fail except when the file does not exist.
666 If stat fails, analyze the source of error and return True
667 unless the file does not exist, to avoid returning false results
668 on obscure systems where stat does not work as expected.
671 return (errno
!= ENOENT
);
673 return S_ISREG (st
.st_mode
);
676 /* Open a file named STRING, searching path PATH (dir names sep by some char)
677 using mode MODE in the calls to open. You cannot use this function to
678 create files (O_CREAT).
680 OPTS specifies the function behaviour in specific cases.
682 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
683 (ie pretend the first element of PATH is "."). This also indicates
684 that a slash in STRING disables searching of the path (this is
685 so that "exec-file ./foo" or "symbol-file ./foo" insures that you
686 get that particular version of foo or an error message).
688 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
689 searched in path (we usually want this for source files but not for
692 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
693 the actual file opened (this string will always start with a "/"). We
694 have to take special pains to avoid doubling the "/" between the directory
695 and the file, sigh! Emacs gets confuzzed by this when we print the
698 If a file is found, return the descriptor.
699 Otherwise, return -1, with errno set for the last name we tried to open. */
701 /* >>>> This should only allow files of certain types,
702 >>>> eg executable, non-directory */
704 openp (const char *path
, int opts
, const char *string
,
705 int mode
, char **filename_opened
)
714 /* The open syscall MODE parameter is not specified. */
715 gdb_assert ((mode
& O_CREAT
) == 0);
716 gdb_assert (string
!= NULL
);
718 /* A file with an empty name cannot possibly exist. Report a failure
719 without further checking.
721 This is an optimization which also defends us against buggy
722 implementations of the "stat" function. For instance, we have
723 noticed that a MinGW debugger built on Windows XP 32bits crashes
724 when the debugger is started with an empty argument. */
725 if (string
[0] == '\0')
736 if ((opts
& OPF_TRY_CWD_FIRST
) || IS_ABSOLUTE_PATH (string
))
740 if (is_regular_file (string
))
742 filename
= alloca (strlen (string
) + 1);
743 strcpy (filename
, string
);
744 fd
= open (filename
, mode
);
754 if (!(opts
& OPF_SEARCH_IN_PATH
))
755 for (i
= 0; string
[i
]; i
++)
756 if (IS_DIR_SEPARATOR (string
[i
]))
760 /* For dos paths, d:/foo -> /foo, and d:foo -> foo. */
761 if (HAS_DRIVE_SPEC (string
))
762 string
= STRIP_DRIVE_SPEC (string
);
764 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
765 while (IS_DIR_SEPARATOR(string
[0]))
769 while (string
[0] == '.' && IS_DIR_SEPARATOR (string
[1]))
772 alloclen
= strlen (path
) + strlen (string
) + 2;
773 filename
= alloca (alloclen
);
775 for (p
= path
; p
; p
= p1
? p1
+ 1 : 0)
777 p1
= strchr (p
, DIRNAME_SEPARATOR
);
783 if (len
== 4 && p
[0] == '$' && p
[1] == 'c'
784 && p
[2] == 'w' && p
[3] == 'd')
786 /* Name is $cwd -- insert current directory name instead. */
789 /* First, realloc the filename buffer if too short. */
790 len
= strlen (current_directory
);
791 newlen
= len
+ strlen (string
) + 2;
792 if (newlen
> alloclen
)
795 filename
= alloca (alloclen
);
797 strcpy (filename
, current_directory
);
801 /* Normal file name in path -- just use it. */
802 strncpy (filename
, p
, len
);
805 /* Don't search $cdir. It's also a magic path like $cwd, but we
806 don't have enough information to expand it. The user *could*
807 have an actual directory named '$cdir' but handling that would
808 be confusing, it would mean different things in different
809 contexts. If the user really has '$cdir' one can use './$cdir'.
810 We can get $cdir when loading scripts. When loading source files
811 $cdir must have already been expanded to the correct value. */
812 if (strcmp (filename
, "$cdir") == 0)
816 /* Remove trailing slashes */
817 while (len
> 0 && IS_DIR_SEPARATOR (filename
[len
- 1]))
820 strcat (filename
+ len
, SLASH_STRING
);
821 strcat (filename
, string
);
823 if (is_regular_file (filename
))
825 fd
= open (filename
, mode
);
834 /* If a file was opened, canonicalize its filename. Use xfullpath
835 rather than gdb_realpath to avoid resolving the basename part
836 of filenames when the associated file is a symbolic link. This
837 fixes a potential inconsistency between the filenames known to
838 GDB and the filenames it prints in the annotations. */
840 *filename_opened
= NULL
;
841 else if (IS_ABSOLUTE_PATH (filename
))
842 *filename_opened
= xfullpath (filename
);
845 /* Beware the // my son, the Emacs barfs, the botch that catch... */
847 char *f
= concat (current_directory
,
848 IS_DIR_SEPARATOR (current_directory
[strlen (current_directory
) - 1])
850 filename
, (char *)NULL
);
852 *filename_opened
= xfullpath (f
);
861 /* This is essentially a convenience, for clients that want the behaviour
862 of openp, using source_path, but that really don't want the file to be
863 opened but want instead just to know what the full pathname is (as
864 qualified against source_path).
866 The current working directory is searched first.
868 If the file was found, this function returns 1, and FULL_PATHNAME is
869 set to the fully-qualified pathname.
871 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
873 source_full_path_of (const char *filename
, char **full_pathname
)
877 fd
= openp (source_path
, OPF_TRY_CWD_FIRST
| OPF_SEARCH_IN_PATH
, filename
,
878 O_RDONLY
, full_pathname
);
881 *full_pathname
= NULL
;
889 /* Return non-zero if RULE matches PATH, that is if the rule can be
893 substitute_path_rule_matches (const struct substitute_path_rule
*rule
,
896 const int from_len
= strlen (rule
->from
);
897 const int path_len
= strlen (path
);
900 if (path_len
< from_len
)
903 /* The substitution rules are anchored at the start of the path,
904 so the path should start with rule->from. There is no filename
905 comparison routine, so we need to extract the first FROM_LEN
906 characters from PATH first and use that to do the comparison. */
908 path_start
= alloca (from_len
+ 1);
909 strncpy (path_start
, path
, from_len
);
910 path_start
[from_len
] = '\0';
912 if (FILENAME_CMP (path_start
, rule
->from
) != 0)
915 /* Make sure that the region in the path that matches the substitution
916 rule is immediately followed by a directory separator (or the end of
917 string character). */
919 if (path
[from_len
] != '\0' && !IS_DIR_SEPARATOR (path
[from_len
]))
925 /* Find the substitute-path rule that applies to PATH and return it.
926 Return NULL if no rule applies. */
928 static struct substitute_path_rule
*
929 get_substitute_path_rule (const char *path
)
931 struct substitute_path_rule
*rule
= substitute_path_rules
;
933 while (rule
!= NULL
&& !substitute_path_rule_matches (rule
, path
))
939 /* If the user specified a source path substitution rule that applies
940 to PATH, then apply it and return the new path. This new path must
941 be deallocated afterwards.
943 Return NULL if no substitution rule was specified by the user,
944 or if no rule applied to the given PATH. */
947 rewrite_source_path (const char *path
)
949 const struct substitute_path_rule
*rule
= get_substitute_path_rule (path
);
956 from_len
= strlen (rule
->from
);
958 /* Compute the rewritten path and return it. */
961 (char *) xmalloc (strlen (path
) + 1 + strlen (rule
->to
) - from_len
);
962 strcpy (new_path
, rule
->to
);
963 strcat (new_path
, path
+ from_len
);
968 /* This function is capable of finding the absolute path to a
969 source file, and opening it, provided you give it a FILENAME. Both the
970 DIRNAME and FULLNAME are only added suggestions on where to find the file.
972 FILENAME should be the filename to open.
973 DIRNAME is the compilation directory of a particular source file.
974 Only some debug formats provide this info.
975 FULLNAME can be the last known absolute path to the file in question.
976 Space for the path must have been malloc'd. If a path substitution
977 is applied we free the old value and set a new one.
980 A valid file descriptor is returned. ( the return value is positive )
981 FULLNAME is set to the absolute path to the file just opened.
982 The caller is responsible for freeing FULLNAME.
985 An invalid file descriptor is returned. ( the return value is negative )
986 FULLNAME is set to NULL. */
989 find_and_open_source (const char *filename
,
993 char *path
= source_path
;
997 /* Quick way out if we already know its full name */
1001 /* The user may have requested that source paths be rewritten
1002 according to substitution rules he provided. If a substitution
1003 rule applies to this path, then apply it. */
1004 char *rewritten_fullname
= rewrite_source_path (*fullname
);
1006 if (rewritten_fullname
!= NULL
)
1009 *fullname
= rewritten_fullname
;
1012 result
= open (*fullname
, OPEN_MODE
);
1015 /* Didn't work -- free old one, try again. */
1020 if (dirname
!= NULL
)
1022 /* If necessary, rewrite the compilation directory name according
1023 to the source path substitution rules specified by the user. */
1025 char *rewritten_dirname
= rewrite_source_path (dirname
);
1027 if (rewritten_dirname
!= NULL
)
1029 make_cleanup (xfree
, rewritten_dirname
);
1030 dirname
= rewritten_dirname
;
1033 /* Replace a path entry of $cdir with the compilation directory name */
1035 /* We cast strstr's result in case an ANSIhole has made it const,
1036 which produces a "required warning" when assigned to a nonconst. */
1037 p
= (char *) strstr (source_path
, "$cdir");
1038 if (p
&& (p
== path
|| p
[-1] == DIRNAME_SEPARATOR
)
1039 && (p
[cdir_len
] == DIRNAME_SEPARATOR
|| p
[cdir_len
] == '\0'))
1044 alloca (strlen (source_path
) + 1 + strlen (dirname
) + 1);
1045 len
= p
- source_path
;
1046 strncpy (path
, source_path
, len
); /* Before $cdir */
1047 strcpy (path
+ len
, dirname
); /* new stuff */
1048 strcat (path
+ len
, source_path
+ len
+ cdir_len
); /* After $cdir */
1052 if (IS_ABSOLUTE_PATH (filename
))
1054 /* If filename is absolute path, try the source path
1055 substitution on it. */
1056 char *rewritten_filename
= rewrite_source_path (filename
);
1058 if (rewritten_filename
!= NULL
)
1060 make_cleanup (xfree
, rewritten_filename
);
1061 filename
= rewritten_filename
;
1065 result
= openp (path
, OPF_SEARCH_IN_PATH
, filename
, OPEN_MODE
, fullname
);
1068 /* Didn't work. Try using just the basename. */
1069 p
= lbasename (filename
);
1071 result
= openp (path
, OPF_SEARCH_IN_PATH
, p
, OPEN_MODE
, fullname
);
1077 /* Open a source file given a symtab S. Returns a file descriptor or
1078 negative number for error.
1080 This function is a convience function to find_and_open_source. */
1083 open_source_file (struct symtab
*s
)
1088 return find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1091 /* Finds the fullname that a symtab represents.
1093 If this functions finds the fullname, it will save it in s->fullname
1094 and it will also return the value.
1096 If this function fails to find the file that this symtab represents,
1097 NULL will be returned and s->fullname will be set to NULL. */
1099 symtab_to_fullname (struct symtab
*s
)
1106 /* Don't check s->fullname here, the file could have been
1107 deleted/moved/..., look for it again */
1108 r
= find_and_open_source (s
->filename
, s
->dirname
, &s
->fullname
);
1119 /* Create and initialize the table S->line_charpos that records
1120 the positions of the lines in the source file, which is assumed
1121 to be open on descriptor DESC.
1122 All set S->nlines to the number of such lines. */
1125 find_source_lines (struct symtab
*s
, int desc
)
1128 char *data
, *p
, *end
;
1130 int lines_allocated
= 1000;
1136 line_charpos
= (int *) xmalloc (lines_allocated
* sizeof (int));
1137 if (fstat (desc
, &st
) < 0)
1138 perror_with_name (s
->filename
);
1140 if (s
->objfile
&& s
->objfile
->obfd
)
1141 mtime
= s
->objfile
->mtime
;
1143 mtime
= exec_bfd_mtime
;
1145 if (mtime
&& mtime
< st
.st_mtime
)
1146 warning (_("Source file is more recent than executable."));
1148 #ifdef LSEEK_NOT_LINEAR
1152 /* Have to read it byte by byte to find out where the chars live */
1154 line_charpos
[0] = lseek (desc
, 0, SEEK_CUR
);
1156 while (myread (desc
, &c
, 1) > 0)
1160 if (nlines
== lines_allocated
)
1162 lines_allocated
*= 2;
1164 (int *) xrealloc ((char *) line_charpos
,
1165 sizeof (int) * lines_allocated
);
1167 line_charpos
[nlines
++] = lseek (desc
, 0, SEEK_CUR
);
1171 #else /* lseek linear. */
1173 struct cleanup
*old_cleanups
;
1175 /* st_size might be a large type, but we only support source files whose
1176 size fits in an int. */
1177 size
= (int) st
.st_size
;
1179 /* Use malloc, not alloca, because this may be pretty large, and we may
1180 run into various kinds of limits on stack size. */
1181 data
= (char *) xmalloc (size
);
1182 old_cleanups
= make_cleanup (xfree
, data
);
1184 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1185 size
= myread (desc
, data
, size
);
1187 perror_with_name (s
->filename
);
1190 line_charpos
[0] = 0;
1195 /* A newline at the end does not start a new line. */
1198 if (nlines
== lines_allocated
)
1200 lines_allocated
*= 2;
1202 (int *) xrealloc ((char *) line_charpos
,
1203 sizeof (int) * lines_allocated
);
1205 line_charpos
[nlines
++] = p
- data
;
1208 do_cleanups (old_cleanups
);
1210 #endif /* lseek linear. */
1213 (int *) xrealloc ((char *) line_charpos
, nlines
* sizeof (int));
1217 /* Return the character position of a line LINE in symtab S.
1218 Return 0 if anything is invalid. */
1220 #if 0 /* Currently unused */
1223 source_line_charpos (struct symtab
*s
, int line
)
1227 if (!s
->line_charpos
|| line
<= 0)
1229 if (line
> s
->nlines
)
1231 return s
->line_charpos
[line
- 1];
1234 /* Return the line number of character position POS in symtab S. */
1237 source_charpos_line (struct symtab
*s
, int chr
)
1242 if (s
== 0 || s
->line_charpos
== 0)
1244 lnp
= s
->line_charpos
;
1245 /* Files are usually short, so sequential search is Ok */
1246 while (line
< s
->nlines
&& *lnp
<= chr
)
1251 if (line
>= s
->nlines
)
1259 /* Get full pathname and line number positions for a symtab.
1260 Return nonzero if line numbers may have changed.
1261 Set *FULLNAME to actual name of the file as found by `openp',
1262 or to 0 if the file is not found. */
1265 get_filename_and_charpos (struct symtab
*s
, char **fullname
)
1267 int desc
, linenums_changed
= 0;
1268 struct cleanup
*cleanups
;
1270 desc
= open_source_file (s
);
1277 cleanups
= make_cleanup_close (desc
);
1279 *fullname
= s
->fullname
;
1280 if (s
->line_charpos
== 0)
1281 linenums_changed
= 1;
1282 if (linenums_changed
)
1283 find_source_lines (s
, desc
);
1284 do_cleanups (cleanups
);
1285 return linenums_changed
;
1288 /* Print text describing the full name of the source file S
1289 and the line number LINE and its corresponding character position.
1290 The text starts with two Ctrl-z so that the Emacs-GDB interface
1293 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1295 Return 1 if successful, 0 if could not find the file. */
1298 identify_source_line (struct symtab
*s
, int line
, int mid_statement
,
1301 if (s
->line_charpos
== 0)
1302 get_filename_and_charpos (s
, (char **) NULL
);
1303 if (s
->fullname
== 0)
1305 if (line
> s
->nlines
)
1306 /* Don't index off the end of the line_charpos array. */
1308 annotate_source (s
->fullname
, line
, s
->line_charpos
[line
- 1],
1309 mid_statement
, get_objfile_arch (s
->objfile
), pc
);
1311 current_source_line
= line
;
1312 first_line_listed
= line
;
1313 last_line_listed
= line
;
1314 current_source_symtab
= s
;
1319 /* Print source lines from the file of symtab S,
1320 starting with line number LINE and stopping before line number STOPLINE. */
1322 static void print_source_lines_base (struct symtab
*s
, int line
, int stopline
,
1325 print_source_lines_base (struct symtab
*s
, int line
, int stopline
, int noerror
)
1331 int nlines
= stopline
- line
;
1332 struct cleanup
*cleanup
;
1334 /* Regardless of whether we can open the file, set current_source_symtab. */
1335 current_source_symtab
= s
;
1336 current_source_line
= line
;
1337 first_line_listed
= line
;
1339 /* If printing of source lines is disabled, just print file and line number */
1340 if (ui_out_test_flags (uiout
, ui_source_list
))
1342 /* Only prints "No such file or directory" once */
1343 if ((s
!= last_source_visited
) || (!last_source_error
))
1345 last_source_visited
= s
;
1346 desc
= open_source_file (s
);
1350 desc
= last_source_error
;
1356 desc
= last_source_error
;
1361 if (desc
< 0 || noprint
)
1363 last_source_error
= desc
;
1367 char *name
= alloca (strlen (s
->filename
) + 100);
1368 sprintf (name
, "%d\t%s", line
, s
->filename
);
1369 print_sys_errmsg (name
, errno
);
1372 ui_out_field_int (uiout
, "line", line
);
1373 ui_out_text (uiout
, "\tin ");
1374 ui_out_field_string (uiout
, "file", s
->filename
);
1375 ui_out_text (uiout
, "\n");
1380 last_source_error
= 0;
1382 if (s
->line_charpos
== 0)
1383 find_source_lines (s
, desc
);
1385 if (line
< 1 || line
> s
->nlines
)
1388 error (_("Line number %d out of range; %s has %d lines."),
1389 line
, s
->filename
, s
->nlines
);
1392 if (lseek (desc
, s
->line_charpos
[line
- 1], 0) < 0)
1395 perror_with_name (s
->filename
);
1398 stream
= fdopen (desc
, FDOPEN_MODE
);
1400 cleanup
= make_cleanup_fclose (stream
);
1402 while (nlines
-- > 0)
1409 last_line_listed
= current_source_line
;
1410 sprintf (buf
, "%d\t", current_source_line
++);
1411 ui_out_text (uiout
, buf
);
1414 if (c
< 040 && c
!= '\t' && c
!= '\n' && c
!= '\r')
1416 sprintf (buf
, "^%c", c
+ 0100);
1417 ui_out_text (uiout
, buf
);
1420 ui_out_text (uiout
, "^?");
1423 /* Skip a \r character, but only before a \n. */
1424 int c1
= fgetc (stream
);
1427 printf_filtered ("^%c", c
+ 0100);
1429 ungetc (c1
, stream
);
1433 sprintf (buf
, "%c", c
);
1434 ui_out_text (uiout
, buf
);
1437 while (c
!= '\n' && (c
= fgetc (stream
)) >= 0);
1440 do_cleanups (cleanup
);
1443 /* Show source lines from the file of symtab S, starting with line
1444 number LINE and stopping before line number STOPLINE. If this is
1445 not the command line version, then the source is shown in the source
1446 window otherwise it is simply printed */
1449 print_source_lines (struct symtab
*s
, int line
, int stopline
, int noerror
)
1451 print_source_lines_base (s
, line
, stopline
, noerror
);
1454 /* Print info on range of pc's in a specified line. */
1457 line_info (char *arg
, int from_tty
)
1459 struct symtabs_and_lines sals
;
1460 struct symtab_and_line sal
;
1461 CORE_ADDR start_pc
, end_pc
;
1464 init_sal (&sal
); /* initialize to zeroes */
1468 sal
.symtab
= current_source_symtab
;
1469 sal
.line
= last_line_listed
;
1471 sals
.sals
= (struct symtab_and_line
*)
1472 xmalloc (sizeof (struct symtab_and_line
));
1477 sals
= decode_line_spec_1 (arg
, 0);
1482 /* C++ More than one line may have been specified, as when the user
1483 specifies an overloaded function name. Print info on them all. */
1484 for (i
= 0; i
< sals
.nelts
; i
++)
1488 if (sal
.symtab
== 0)
1490 struct gdbarch
*gdbarch
= get_current_arch ();
1492 printf_filtered (_("No line number information available"));
1495 /* This is useful for "info line *0x7f34". If we can't tell the
1496 user about a source line, at least let them have the symbolic
1498 printf_filtered (" for address ");
1500 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1503 printf_filtered (".");
1504 printf_filtered ("\n");
1506 else if (sal
.line
> 0
1507 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1509 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1511 if (start_pc
== end_pc
)
1513 printf_filtered ("Line %d of \"%s\"",
1514 sal
.line
, sal
.symtab
->filename
);
1516 printf_filtered (" is at address ");
1517 print_address (gdbarch
, start_pc
, gdb_stdout
);
1519 printf_filtered (" but contains no code.\n");
1523 printf_filtered ("Line %d of \"%s\"",
1524 sal
.line
, sal
.symtab
->filename
);
1526 printf_filtered (" starts at address ");
1527 print_address (gdbarch
, start_pc
, gdb_stdout
);
1529 printf_filtered (" and ends at ");
1530 print_address (gdbarch
, end_pc
, gdb_stdout
);
1531 printf_filtered (".\n");
1534 /* x/i should display this line's code. */
1535 set_next_address (gdbarch
, start_pc
);
1537 /* Repeating "info line" should do the following line. */
1538 last_line_listed
= sal
.line
+ 1;
1540 /* If this is the only line, show the source code. If it could
1541 not find the file, don't do anything special. */
1542 if (annotation_level
&& sals
.nelts
== 1)
1543 identify_source_line (sal
.symtab
, sal
.line
, 0, start_pc
);
1546 /* Is there any case in which we get here, and have an address
1547 which the user would want to see? If we have debugging symbols
1548 and no line numbers? */
1549 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
1550 sal
.line
, sal
.symtab
->filename
);
1555 /* Commands to search the source file for a regexp. */
1558 forward_search_command (char *regex
, int from_tty
)
1565 struct cleanup
*cleanups
;
1567 line
= last_line_listed
+ 1;
1569 msg
= (char *) re_comp (regex
);
1571 error (("%s"), msg
);
1573 if (current_source_symtab
== 0)
1574 select_source_symtab (0);
1576 desc
= open_source_file (current_source_symtab
);
1578 perror_with_name (current_source_symtab
->filename
);
1579 cleanups
= make_cleanup_close (desc
);
1581 if (current_source_symtab
->line_charpos
== 0)
1582 find_source_lines (current_source_symtab
, desc
);
1584 if (line
< 1 || line
> current_source_symtab
->nlines
)
1585 error (_("Expression not found"));
1587 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1588 perror_with_name (current_source_symtab
->filename
);
1590 discard_cleanups (cleanups
);
1591 stream
= fdopen (desc
, FDOPEN_MODE
);
1593 cleanups
= make_cleanup_fclose (stream
);
1596 static char *buf
= NULL
;
1598 int cursize
, newsize
;
1601 buf
= xmalloc (cursize
);
1610 if (p
- buf
== cursize
)
1612 newsize
= cursize
+ cursize
/ 2;
1613 buf
= xrealloc (buf
, newsize
);
1618 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1620 /* Remove the \r, if any, at the end of the line, otherwise
1621 regular expressions that end with $ or \n won't work. */
1622 if (p
- buf
> 1 && p
[-2] == '\r')
1628 /* we now have a source line in buf, null terminate and match */
1630 if (re_exec (buf
) > 0)
1633 do_cleanups (cleanups
);
1634 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1635 set_internalvar_integer (lookup_internalvar ("_"), line
);
1636 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1642 printf_filtered (_("Expression not found\n"));
1643 do_cleanups (cleanups
);
1647 reverse_search_command (char *regex
, int from_tty
)
1654 struct cleanup
*cleanups
;
1656 line
= last_line_listed
- 1;
1658 msg
= (char *) re_comp (regex
);
1660 error (("%s"), msg
);
1662 if (current_source_symtab
== 0)
1663 select_source_symtab (0);
1665 desc
= open_source_file (current_source_symtab
);
1667 perror_with_name (current_source_symtab
->filename
);
1668 cleanups
= make_cleanup_close (desc
);
1670 if (current_source_symtab
->line_charpos
== 0)
1671 find_source_lines (current_source_symtab
, desc
);
1673 if (line
< 1 || line
> current_source_symtab
->nlines
)
1674 error (_("Expression not found"));
1676 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1677 perror_with_name (current_source_symtab
->filename
);
1679 discard_cleanups (cleanups
);
1680 stream
= fdopen (desc
, FDOPEN_MODE
);
1682 cleanups
= make_cleanup_fclose (stream
);
1685 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1686 char buf
[4096]; /* Should be reasonable??? */
1696 while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1698 /* Remove the \r, if any, at the end of the line, otherwise
1699 regular expressions that end with $ or \n won't work. */
1700 if (p
- buf
> 1 && p
[-2] == '\r')
1706 /* We now have a source line in buf; null terminate and match. */
1708 if (re_exec (buf
) > 0)
1711 do_cleanups (cleanups
);
1712 print_source_lines (current_source_symtab
, line
, line
+ 1, 0);
1713 set_internalvar_integer (lookup_internalvar ("_"), line
);
1714 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1718 if (fseek (stream
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1720 do_cleanups (cleanups
);
1721 perror_with_name (current_source_symtab
->filename
);
1725 printf_filtered (_("Expression not found\n"));
1726 do_cleanups (cleanups
);
1730 /* If the last character of PATH is a directory separator, then strip it. */
1733 strip_trailing_directory_separator (char *path
)
1735 const int last
= strlen (path
) - 1;
1738 return; /* No stripping is needed if PATH is the empty string. */
1740 if (IS_DIR_SEPARATOR (path
[last
]))
1744 /* Return the path substitution rule that matches FROM.
1745 Return NULL if no rule matches. */
1747 static struct substitute_path_rule
*
1748 find_substitute_path_rule (const char *from
)
1750 struct substitute_path_rule
*rule
= substitute_path_rules
;
1752 while (rule
!= NULL
)
1754 if (FILENAME_CMP (rule
->from
, from
) == 0)
1762 /* Add a new substitute-path rule at the end of the current list of rules.
1763 The new rule will replace FROM into TO. */
1766 add_substitute_path_rule (char *from
, char *to
)
1768 struct substitute_path_rule
*rule
;
1769 struct substitute_path_rule
*new_rule
;
1771 new_rule
= xmalloc (sizeof (struct substitute_path_rule
));
1772 new_rule
->from
= xstrdup (from
);
1773 new_rule
->to
= xstrdup (to
);
1774 new_rule
->next
= NULL
;
1776 /* If the list of rules are empty, then insert the new rule
1777 at the head of the list. */
1779 if (substitute_path_rules
== NULL
)
1781 substitute_path_rules
= new_rule
;
1785 /* Otherwise, skip to the last rule in our list and then append
1788 rule
= substitute_path_rules
;
1789 while (rule
->next
!= NULL
)
1792 rule
->next
= new_rule
;
1795 /* Remove the given source path substitution rule from the current list
1796 of rules. The memory allocated for that rule is also deallocated. */
1799 delete_substitute_path_rule (struct substitute_path_rule
*rule
)
1801 if (rule
== substitute_path_rules
)
1802 substitute_path_rules
= rule
->next
;
1805 struct substitute_path_rule
*prev
= substitute_path_rules
;
1807 while (prev
!= NULL
&& prev
->next
!= rule
)
1810 gdb_assert (prev
!= NULL
);
1812 prev
->next
= rule
->next
;
1820 /* Implement the "show substitute-path" command. */
1823 show_substitute_path_command (char *args
, int from_tty
)
1825 struct substitute_path_rule
*rule
= substitute_path_rules
;
1829 argv
= gdb_buildargv (args
);
1830 make_cleanup_freeargv (argv
);
1832 /* We expect zero or one argument. */
1834 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1835 error (_("Too many arguments in command"));
1837 if (argv
!= NULL
&& argv
[0] != NULL
)
1840 /* Print the substitution rules. */
1844 (_("Source path substitution rule matching `%s':\n"), from
);
1846 printf_filtered (_("List of all source path substitution rules:\n"));
1848 while (rule
!= NULL
)
1850 if (from
== NULL
|| FILENAME_CMP (rule
->from
, from
) == 0)
1851 printf_filtered (" `%s' -> `%s'.\n", rule
->from
, rule
->to
);
1856 /* Implement the "unset substitute-path" command. */
1859 unset_substitute_path_command (char *args
, int from_tty
)
1861 struct substitute_path_rule
*rule
= substitute_path_rules
;
1862 char **argv
= gdb_buildargv (args
);
1866 /* This function takes either 0 or 1 argument. */
1868 make_cleanup_freeargv (argv
);
1869 if (argv
!= NULL
&& argv
[0] != NULL
&& argv
[1] != NULL
)
1870 error (_("Incorrect usage, too many arguments in command"));
1872 if (argv
!= NULL
&& argv
[0] != NULL
)
1875 /* If the user asked for all the rules to be deleted, ask him
1876 to confirm and give him a chance to abort before the action
1880 && !query (_("Delete all source path substitution rules? ")))
1881 error (_("Canceled"));
1883 /* Delete the rule matching the argument. No argument means that
1884 all rules should be deleted. */
1886 while (rule
!= NULL
)
1888 struct substitute_path_rule
*next
= rule
->next
;
1890 if (from
== NULL
|| FILENAME_CMP (from
, rule
->from
) == 0)
1892 delete_substitute_path_rule (rule
);
1899 /* If the user asked for a specific rule to be deleted but
1900 we could not find it, then report an error. */
1902 if (from
!= NULL
&& !rule_found
)
1903 error (_("No substitution rule defined for `%s'"), from
);
1905 forget_cached_source_info ();
1908 /* Add a new source path substitution rule. */
1911 set_substitute_path_command (char *args
, int from_tty
)
1914 struct substitute_path_rule
*rule
;
1916 argv
= gdb_buildargv (args
);
1917 make_cleanup_freeargv (argv
);
1919 if (argv
== NULL
|| argv
[0] == NULL
|| argv
[1] == NULL
)
1920 error (_("Incorrect usage, too few arguments in command"));
1922 if (argv
[2] != NULL
)
1923 error (_("Incorrect usage, too many arguments in command"));
1925 if (*(argv
[0]) == '\0')
1926 error (_("First argument must be at least one character long"));
1928 /* Strip any trailing directory separator character in either FROM
1929 or TO. The substitution rule already implicitly contains them. */
1930 strip_trailing_directory_separator (argv
[0]);
1931 strip_trailing_directory_separator (argv
[1]);
1933 /* If a rule with the same "from" was previously defined, then
1934 delete it. This new rule replaces it. */
1936 rule
= find_substitute_path_rule (argv
[0]);
1938 delete_substitute_path_rule (rule
);
1940 /* Insert the new substitution rule. */
1942 add_substitute_path_rule (argv
[0], argv
[1]);
1943 forget_cached_source_info ();
1948 _initialize_source (void)
1950 struct cmd_list_element
*c
;
1952 current_source_symtab
= 0;
1953 init_source_path ();
1955 /* The intention is to use POSIX Basic Regular Expressions.
1956 Always use the GNU regex routine for consistency across all hosts.
1957 Our current GNU regex.c does not have all the POSIX features, so this is
1958 just an approximation. */
1959 re_set_syntax (RE_SYNTAX_GREP
);
1961 c
= add_cmd ("directory", class_files
, directory_command
, _("\
1962 Add directory DIR to beginning of search path for source files.\n\
1963 Forget cached info on source file locations and line positions.\n\
1964 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1965 directory in which the source file was compiled into object code.\n\
1966 With no argument, reset the search path to $cdir:$cwd, the default."),
1970 add_com_alias ("use", "directory", class_files
, 0);
1972 set_cmd_completer (c
, filename_completer
);
1974 add_setshow_optional_filename_cmd ("directories",
1978 Set the search path for finding source files."),
1980 Show the search path for finding source files."),
1982 $cwd in the path means the current working directory.\n\
1983 $cdir in the path means the compilation directory of the source file.\n\
1984 GDB ensures the search path always ends with $cdir:$cwd by\n\
1985 appending these directories if necessary.\n\
1986 Setting the value to an empty string sets it to $cdir:$cwd, the default."),
1987 set_directories_command
,
1988 show_directories_command
,
1989 &setlist
, &showlist
);
1993 add_com_alias ("D", "directory", class_files
, 0);
1994 add_cmd ("ld", no_class
, show_directories_1
, _("\
1995 Current search path for finding source files.\n\
1996 $cwd in the path means the current working directory.\n\
1997 $cdir in the path means the compilation directory of the source file."),
2001 add_info ("source", source_info
,
2002 _("Information about the current source file."));
2004 add_info ("line", line_info
, _("\
2005 Core addresses of the code for a source line.\n\
2006 Line can be specified as\n\
2007 LINENUM, to list around that line in current file,\n\
2008 FILE:LINENUM, to list around that line in that file,\n\
2009 FUNCTION, to list around beginning of that function,\n\
2010 FILE:FUNCTION, to distinguish among like-named static functions.\n\
2011 Default is to describe the last source line that was listed.\n\n\
2012 This sets the default address for \"x\" to the line's first instruction\n\
2013 so that \"x/i\" suffices to start examining the machine code.\n\
2014 The address is also stored as the value of \"$_\"."));
2016 add_com ("forward-search", class_files
, forward_search_command
, _("\
2017 Search for regular expression (see regex(3)) from last line listed.\n\
2018 The matching line number is also stored as the value of \"$_\"."));
2019 add_com_alias ("search", "forward-search", class_files
, 0);
2021 add_com ("reverse-search", class_files
, reverse_search_command
, _("\
2022 Search backward for regular expression (see regex(3)) from last line listed.\n\
2023 The matching line number is also stored as the value of \"$_\"."));
2024 add_com_alias ("rev", "reverse-search", class_files
, 1);
2028 add_com_alias ("/", "forward-search", class_files
, 0);
2029 add_com_alias ("?", "reverse-search", class_files
, 0);
2032 add_setshow_integer_cmd ("listsize", class_support
, &lines_to_list
, _("\
2033 Set number of source lines gdb will list by default."), _("\
2034 Show number of source lines gdb will list by default."), NULL
,
2037 &setlist
, &showlist
);
2039 add_cmd ("substitute-path", class_files
, set_substitute_path_command
,
2041 Usage: set substitute-path FROM TO\n\
2042 Add a substitution rule replacing FROM into TO in source file names.\n\
2043 If a substitution rule was previously set for FROM, the old rule\n\
2044 is replaced by the new one."),
2047 add_cmd ("substitute-path", class_files
, unset_substitute_path_command
,
2049 Usage: unset substitute-path [FROM]\n\
2050 Delete the rule for substituting FROM in source file names. If FROM\n\
2051 is not specified, all substituting rules are deleted.\n\
2052 If the debugger cannot find a rule for FROM, it will display a warning."),
2055 add_cmd ("substitute-path", class_files
, show_substitute_path_command
,
2057 Usage: show substitute-path [FROM]\n\
2058 Print the rule for substituting FROM in source file names. If FROM\n\
2059 is not specified, print all substitution rules."),