]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/source.c
* gdb/score-tdep.c: Delete dead codes.
[thirdparty/binutils-gdb.git] / gdb / source.c
CommitLineData
c906108c 1/* List lines of source files for GDB, the GNU debugger.
6aba47ca 2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
0fb0cc75
JB
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
4 2009 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#include "defs.h"
5af949e3 22#include "arch-utils.h"
c906108c
SS
23#include "symtab.h"
24#include "expression.h"
25#include "language.h"
26#include "command.h"
c2c6d25f 27#include "source.h"
c906108c
SS
28#include "gdbcmd.h"
29#include "frame.h"
30#include "value.h"
2f61ca93 31#include "gdb_assert.h"
c906108c
SS
32
33#include <sys/types.h>
34#include "gdb_string.h"
35#include "gdb_stat.h"
36#include <fcntl.h>
c906108c 37#include "gdbcore.h"
88987551 38#include "gdb_regex.h"
c906108c
SS
39#include "symfile.h"
40#include "objfiles.h"
41#include "annotate.h"
42#include "gdbtypes.h"
c5f0f3d0 43#include "linespec.h"
fe4e3eb8 44#include "filenames.h" /* for DOSish file names */
d75b5104 45#include "completer.h"
8b93c638 46#include "ui-out.h"
dbda9972 47#include "readline/readline.h"
c906108c 48
3e3a28f1 49
c906108c
SS
50#define OPEN_MODE (O_RDONLY | O_BINARY)
51#define FDOPEN_MODE FOPEN_RB
52
c906108c
SS
53/* Prototypes for exported functions. */
54
a14ed312 55void _initialize_source (void);
c906108c
SS
56
57/* Prototypes for local functions. */
58
a14ed312 59static int get_filename_and_charpos (struct symtab *, char **);
c906108c 60
a14ed312 61static void reverse_search_command (char *, int);
c906108c 62
a14ed312 63static void forward_search_command (char *, int);
c906108c 64
a14ed312 65static void line_info (char *, int);
c906108c 66
a14ed312 67static void source_info (char *, int);
c906108c 68
a14ed312 69static void show_directories (char *, int);
c906108c
SS
70
71/* Path of directories to search for source files.
72 Same format as the PATH environment variable's value. */
73
74char *source_path;
75
2f61ca93
JB
76/* Support for source path substitution commands. */
77
78struct substitute_path_rule
79{
80 char *from;
81 char *to;
82 struct substitute_path_rule *next;
83};
84
85static struct substitute_path_rule *substitute_path_rules = NULL;
86
c906108c
SS
87/* Symtab of default file for listing lines of. */
88
0378c332 89static struct symtab *current_source_symtab;
c906108c
SS
90
91/* Default next line to list. */
92
0378c332 93static int current_source_line;
c906108c
SS
94
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. */
100
101int lines_to_list = 10;
920d2a44
AC
102static void
103show_lines_to_list (struct ui_file *file, int from_tty,
104 struct cmd_list_element *c, const char *value)
105{
106 fprintf_filtered (file, _("\
107Number of source lines gdb will list by default is %s.\n"),
108 value);
109}
c906108c
SS
110
111/* Line number of last line printed. Default for various commands.
112 current_source_line is usually, but not always, the same as this. */
113
114static int last_line_listed;
115
116/* First line number listed by last listing command. */
117
118static int first_line_listed;
119
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 */
122
123static struct symtab *last_source_visited = NULL;
124static int last_source_error = 0;
c906108c 125\f
0378c332
FN
126/* Return the first line listed by print_source_lines.
127 Used by command interpreters to request listing from
128 a previous point. */
129
130int
131get_first_line_listed (void)
132{
133 return first_line_listed;
134}
135
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. */
140
141int
142get_lines_to_list (void)
143{
144 return lines_to_list;
145}
146
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. */
149
150struct symtab_and_line
151get_current_source_symtab_and_line (void)
152{
245c7f48 153 struct symtab_and_line cursal = { 0 };
0378c332
FN
154
155 cursal.symtab = current_source_symtab;
156 cursal.line = current_source_line;
53cb0458
FN
157 cursal.pc = 0;
158 cursal.end = 0;
0378c332
FN
159
160 return cursal;
161}
162
53cb0458
FN
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.
0378c332 165 It may err out if a default cannot be determined.
53cb0458
FN
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. */
0378c332 170
53cb0458
FN
171void
172set_default_source_symtab_and_line (void)
0378c332
FN
173{
174 struct symtab_and_line cursal;
175
176 if (!have_full_symbols () && !have_partial_symbols ())
8a3fe4f8 177 error (_("No symbol table is loaded. Use the \"file\" command."));
0378c332
FN
178
179 /* Pull in a current source symtab if necessary */
180 if (current_source_symtab == 0)
181 select_source_symtab (0);
0378c332
FN
182}
183
184/* Return the current default file for listing and next line to list
185 (the returned sal pc and end fields are not valid.)
53cb0458
FN
186 and set the current default to whatever is in SAL.
187 NOTE: The returned sal pc and end fields are not valid. */
0378c332
FN
188
189struct symtab_and_line
53cb0458 190set_current_source_symtab_and_line (const struct symtab_and_line *sal)
0378c332 191{
245c7f48 192 struct symtab_and_line cursal = { 0 };
0378c332
FN
193
194 cursal.symtab = current_source_symtab;
195 cursal.line = current_source_line;
196
197 current_source_symtab = sal->symtab;
198 current_source_line = sal->line;
c214a6fd
FN
199 cursal.pc = 0;
200 cursal.end = 0;
0378c332
FN
201
202 return cursal;
203}
204
205/* Reset any information stored about a default file and line to print. */
206
207void
208clear_current_source_symtab_and_line (void)
209{
210 current_source_symtab = 0;
211 current_source_line = 0;
212}
c5aa993b 213
c906108c
SS
214/* Set the source file default for the "list" command to be S.
215
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. */
221
222void
aa1ee363 223select_source_symtab (struct symtab *s)
c906108c
SS
224{
225 struct symtabs_and_lines sals;
226 struct symtab_and_line sal;
227 struct partial_symtab *ps;
228 struct partial_symtab *cs_pst = 0;
229 struct objfile *ofp;
c5aa993b 230
c906108c
SS
231 if (s)
232 {
233 current_source_symtab = s;
234 current_source_line = 1;
235 return;
236 }
237
238 if (current_source_symtab)
239 return;
240
241 /* Make the default place to list be the function `main'
242 if one exists. */
2570f2b7 243 if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0))
c906108c 244 {
51cc5b07 245 sals = decode_line_spec (main_name (), 1);
c906108c 246 sal = sals.sals[0];
b8c9b27d 247 xfree (sals.sals);
c906108c
SS
248 current_source_symtab = sal.symtab;
249 current_source_line = max (sal.line - (lines_to_list - 1), 1);
250 if (current_source_symtab)
c5aa993b 251 return;
c906108c 252 }
c5aa993b 253
8340a3fb
LM
254 /* Alright; find the last file in the symtab list (ignoring .h's
255 and namespace symtabs). */
c906108c
SS
256
257 current_source_line = 1;
258
c5aa993b 259 for (ofp = object_files; ofp != NULL; ofp = ofp->next)
c906108c 260 {
c5aa993b 261 for (s = ofp->symtabs; s; s = s->next)
c906108c 262 {
591e78ff 263 const char *name = s->filename;
c906108c 264 int len = strlen (name);
8340a3fb
LM
265 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
266 || strcmp (name, "<<C++-namespaces>>") == 0)))
591e78ff 267 current_source_symtab = s;
c906108c
SS
268 }
269 }
270 if (current_source_symtab)
271 return;
272
8340a3fb 273 /* How about the partial symbol tables? */
c906108c 274
c5aa993b 275 for (ofp = object_files; ofp != NULL; ofp = ofp->next)
c906108c 276 {
c5aa993b 277 for (ps = ofp->psymtabs; ps != NULL; ps = ps->next)
c906108c 278 {
591e78ff 279 const char *name = ps->filename;
c906108c 280 int len = strlen (name);
8340a3fb
LM
281 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
282 || strcmp (name, "<<C++-namespaces>>") == 0)))
591e78ff 283 cs_pst = ps;
c906108c
SS
284 }
285 }
286 if (cs_pst)
287 {
c5aa993b 288 if (cs_pst->readin)
c906108c 289 {
8e65ff28 290 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
291 _("select_source_symtab: "
292 "readin pst found and no symtabs."));
c906108c
SS
293 }
294 else
295 {
296 current_source_symtab = PSYMTAB_TO_SYMTAB (cs_pst);
297 }
298 }
299 if (current_source_symtab)
300 return;
301
8a3fe4f8 302 error (_("Can't find a default source file"));
c906108c
SS
303}
304\f
305static void
fba45db2 306show_directories (char *ignore, int from_tty)
c906108c
SS
307{
308 puts_filtered ("Source directories searched: ");
309 puts_filtered (source_path);
310 puts_filtered ("\n");
311}
312
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. */
316
317void
fba45db2 318forget_cached_source_info (void)
c906108c 319{
52f0bd74
AC
320 struct symtab *s;
321 struct objfile *objfile;
58d370e0 322 struct partial_symtab *pst;
c906108c 323
c5aa993b 324 for (objfile = object_files; objfile != NULL; objfile = objfile->next)
c906108c 325 {
c5aa993b 326 for (s = objfile->symtabs; s != NULL; s = s->next)
c906108c 327 {
c5aa993b 328 if (s->line_charpos != NULL)
c906108c 329 {
2dc74dc1 330 xfree (s->line_charpos);
c5aa993b 331 s->line_charpos = NULL;
c906108c 332 }
c5aa993b 333 if (s->fullname != NULL)
c906108c 334 {
2dc74dc1 335 xfree (s->fullname);
c5aa993b 336 s->fullname = NULL;
c906108c
SS
337 }
338 }
58d370e0
TT
339
340 ALL_OBJFILE_PSYMTABS (objfile, pst)
341 {
342 if (pst->fullname != NULL)
343 {
344 xfree (pst->fullname);
345 pst->fullname = NULL;
346 }
347 }
c906108c 348 }
c4e86dd4
DJ
349
350 last_source_visited = NULL;
c906108c
SS
351}
352
353void
fba45db2 354init_source_path (void)
c906108c
SS
355{
356 char buf[20];
357
358 sprintf (buf, "$cdir%c$cwd", DIRNAME_SEPARATOR);
4fcf66da 359 source_path = xstrdup (buf);
c906108c
SS
360 forget_cached_source_info ();
361}
362
363/* Add zero or more directories to the front of the source path. */
c5aa993b 364
c906108c 365void
fba45db2 366directory_command (char *dirname, int from_tty)
c906108c
SS
367{
368 dont_repeat ();
369 /* FIXME, this goes to "delete dir"... */
370 if (dirname == 0)
371 {
80618b99 372 if (!from_tty || query (_("Reinitialize source path to empty? ")))
c906108c 373 {
b8c9b27d 374 xfree (source_path);
c906108c
SS
375 init_source_path ();
376 }
377 }
378 else
379 {
380 mod_path (dirname, &source_path);
c4e86dd4 381 forget_cached_source_info ();
c906108c
SS
382 }
383 if (from_tty)
c5aa993b 384 show_directories ((char *) 0, from_tty);
c906108c
SS
385}
386
13d35ae5
AS
387/* Add a path given with the -d command line switch.
388 This will not be quoted so we must not treat spaces as separators. */
389
390void
391directory_switch (char *dirname, int from_tty)
392{
393 add_path (dirname, &source_path, 0);
394}
395
c906108c
SS
396/* Add zero or more directories to the front of an arbitrary path. */
397
398void
fba45db2 399mod_path (char *dirname, char **which_path)
c04e0a08
JJ
400{
401 add_path (dirname, which_path, 1);
402}
403
404/* Workhorse of mod_path. Takes an extra argument to determine
405 if dirname should be parsed for separators that indicate multiple
406 directories. This allows for interfaces that pre-parse the dirname
407 and allow specification of traditional separator characters such
408 as space or tab. */
409
410void
411add_path (char *dirname, char **which_path, int parse_separators)
c906108c
SS
412{
413 char *old = *which_path;
414 int prefix = 0;
13d35ae5
AS
415 char **argv = NULL;
416 char *arg;
417 int argv_index = 0;
c906108c
SS
418
419 if (dirname == 0)
420 return;
421
13d35ae5
AS
422 if (parse_separators)
423 {
424 /* This will properly parse the space and tab separators
425 and any quotes that may exist. DIRNAME_SEPARATOR will
426 be dealt with later. */
d1a41061 427 argv = gdb_buildargv (dirname);
13d35ae5
AS
428 make_cleanup_freeargv (argv);
429
13d35ae5
AS
430 arg = argv[0];
431 }
432 else
433 {
434 arg = xstrdup (dirname);
435 make_cleanup (xfree, arg);
436 }
c906108c
SS
437
438 do
439 {
13d35ae5 440 char *name = arg;
aa1ee363 441 char *p;
c906108c
SS
442 struct stat st;
443
444 {
c04e0a08 445 char *separator = NULL;
c04e0a08 446
13d35ae5
AS
447 /* Spaces and tabs will have been removed by buildargv().
448 The directories will there be split into a list but
449 each entry may still contain DIRNAME_SEPARATOR. */
c04e0a08 450 if (parse_separators)
13d35ae5 451 separator = strchr (name, DIRNAME_SEPARATOR);
c906108c 452
13d35ae5
AS
453 if (separator == 0)
454 p = arg = name + strlen (name);
c906108c
SS
455 else
456 {
13d35ae5
AS
457 p = separator;
458 arg = p + 1;
459 while (*arg == DIRNAME_SEPARATOR)
460 ++arg;
c906108c 461 }
13d35ae5
AS
462
463 /* If there are no more directories in this argument then start
464 on the next argument next time round the loop (if any). */
465 if (*arg == '\0')
466 arg = parse_separators ? argv[++argv_index] : NULL;
c906108c
SS
467 }
468
13d35ae5
AS
469 /* name is the start of the directory.
470 p is the separator (or null) following the end. */
471
472 while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */
c3690141 473#ifdef HAVE_DOS_BASED_FILE_SYSTEM
7be570e7 474 /* On MS-DOS and MS-Windows, h:\ is different from h: */
13d35ae5 475 && !(p == name + 3 && name[1] == ':') /* "d:/" */
7be570e7 476#endif
13d35ae5 477 && IS_DIR_SEPARATOR (p[-1]))
c906108c
SS
478 /* Sigh. "foo/" => "foo" */
479 --p;
c906108c
SS
480 *p = '\0';
481
7be570e7 482 while (p > name && p[-1] == '.')
c906108c
SS
483 {
484 if (p - name == 1)
485 {
486 /* "." => getwd (). */
487 name = current_directory;
488 goto append;
489 }
fe4e3eb8 490 else if (p > name + 1 && IS_DIR_SEPARATOR (p[-2]))
c906108c
SS
491 {
492 if (p - name == 2)
493 {
494 /* "/." => "/". */
495 *--p = '\0';
496 goto append;
497 }
498 else
499 {
500 /* "...foo/." => "...foo". */
501 p -= 2;
502 *p = '\0';
503 continue;
504 }
505 }
506 else
507 break;
508 }
509
510 if (name[0] == '~')
511 name = tilde_expand (name);
c3690141 512#ifdef HAVE_DOS_BASED_FILE_SYSTEM
fe4e3eb8 513 else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */
1754f103 514 name = concat (name, ".", (char *)NULL);
7be570e7 515#endif
fe4e3eb8 516 else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$')
1754f103 517 name = concat (current_directory, SLASH_STRING, name, (char *)NULL);
c906108c
SS
518 else
519 name = savestring (name, p - name);
b8c9b27d 520 make_cleanup (xfree, name);
c906108c
SS
521
522 /* Unless it's a variable, check existence. */
c5aa993b
JM
523 if (name[0] != '$')
524 {
525 /* These are warnings, not errors, since we don't want a
526 non-existent directory in a .gdbinit file to stop processing
527 of the .gdbinit file.
528
529 Whether they get added to the path is more debatable. Current
530 answer is yes, in case the user wants to go make the directory
531 or whatever. If the directory continues to not exist/not be
532 a directory/etc, then having them in the path should be
533 harmless. */
534 if (stat (name, &st) < 0)
535 {
536 int save_errno = errno;
537 fprintf_unfiltered (gdb_stderr, "Warning: ");
538 print_sys_errmsg (name, save_errno);
539 }
540 else if ((st.st_mode & S_IFMT) != S_IFDIR)
8a3fe4f8 541 warning (_("%s is not a directory."), name);
c5aa993b 542 }
c906108c
SS
543
544 append:
545 {
aa1ee363 546 unsigned int len = strlen (name);
c906108c
SS
547
548 p = *which_path;
549 while (1)
550 {
7be570e7
JM
551 /* FIXME: strncmp loses in interesting ways on MS-DOS and
552 MS-Windows because of case-insensitivity and two different
553 but functionally identical slash characters. We need a
554 special filesystem-dependent file-name comparison function.
555
556 Actually, even on Unix I would use realpath() or its work-
557 alike before comparing. Then all the code above which
558 removes excess slashes and dots could simply go away. */
c906108c
SS
559 if (!strncmp (p, name, len)
560 && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
561 {
562 /* Found it in the search path, remove old copy */
563 if (p > *which_path)
c5aa993b 564 p--; /* Back over leading separator */
c906108c
SS
565 if (prefix > p - *which_path)
566 goto skip_dup; /* Same dir twice in one cmd */
c5aa993b 567 strcpy (p, &p[len + 1]); /* Copy from next \0 or : */
c906108c
SS
568 }
569 p = strchr (p, DIRNAME_SEPARATOR);
570 if (p != 0)
571 ++p;
572 else
573 break;
574 }
575 if (p == 0)
576 {
577 char tinybuf[2];
578
579 tinybuf[0] = DIRNAME_SEPARATOR;
580 tinybuf[1] = '\0';
581
c04e0a08
JJ
582 /* If we have already tacked on a name(s) in this command, be sure they stay
583 on the front as we tack on some more. */
c906108c
SS
584 if (prefix)
585 {
586 char *temp, c;
587
588 c = old[prefix];
589 old[prefix] = '\0';
1754f103 590 temp = concat (old, tinybuf, name, (char *)NULL);
c906108c 591 old[prefix] = c;
1754f103 592 *which_path = concat (temp, "", &old[prefix], (char *)NULL);
c906108c 593 prefix = strlen (temp);
b8c9b27d 594 xfree (temp);
c906108c
SS
595 }
596 else
597 {
1754f103
MK
598 *which_path = concat (name, (old[0] ? tinybuf : old),
599 old, (char *)NULL);
c906108c
SS
600 prefix = strlen (name);
601 }
b8c9b27d 602 xfree (old);
c906108c
SS
603 old = *which_path;
604 }
605 }
c5aa993b
JM
606 skip_dup:;
607 }
13d35ae5 608 while (arg != NULL);
c906108c
SS
609}
610
611
612static void
fba45db2 613source_info (char *ignore, int from_tty)
c906108c 614{
52f0bd74 615 struct symtab *s = current_source_symtab;
c906108c
SS
616
617 if (!s)
618 {
a3f17187 619 printf_filtered (_("No current source file.\n"));
c906108c
SS
620 return;
621 }
a3f17187 622 printf_filtered (_("Current source file is %s\n"), s->filename);
c906108c 623 if (s->dirname)
a3f17187 624 printf_filtered (_("Compilation directory is %s\n"), s->dirname);
c906108c 625 if (s->fullname)
a3f17187 626 printf_filtered (_("Located in %s\n"), s->fullname);
c906108c 627 if (s->nlines)
a3f17187 628 printf_filtered (_("Contains %d line%s.\n"), s->nlines,
c906108c
SS
629 s->nlines == 1 ? "" : "s");
630
a3f17187
AC
631 printf_filtered (_("Source language is %s.\n"), language_str (s->language));
632 printf_filtered (_("Compiled with %s debugging format.\n"), s->debugformat);
633 printf_filtered (_("%s preprocessor macro info.\n"),
919d772c 634 s->macro_table ? "Includes" : "Does not include");
c906108c 635}
c5aa993b 636\f
c906108c 637
1da1a192
JB
638/* Return True if the file NAME exists and is a regular file */
639static int
640is_regular_file (const char *name)
641{
642 struct stat st;
643 const int status = stat (name, &st);
644
645 /* Stat should never fail except when the file does not exist.
646 If stat fails, analyze the source of error and return True
647 unless the file does not exist, to avoid returning false results
648 on obscure systems where stat does not work as expected.
649 */
650 if (status != 0)
651 return (errno != ENOENT);
652
653 return S_ISREG (st.st_mode);
654}
c906108c 655
c906108c 656/* Open a file named STRING, searching path PATH (dir names sep by some char)
fbdebf46
JK
657 using mode MODE in the calls to open. You cannot use this function to
658 create files (O_CREAT).
c906108c 659
014d698b
EZ
660 OPTS specifies the function behaviour in specific cases.
661
662 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
c906108c
SS
663 (ie pretend the first element of PATH is "."). This also indicates
664 that a slash in STRING disables searching of the path (this is
665 so that "exec-file ./foo" or "symbol-file ./foo" insures that you
666 get that particular version of foo or an error message).
667
014d698b
EZ
668 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
669 searched in path (we usually want this for source files but not for
670 executables).
671
e7a8479f 672 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
a89f66e4 673 the actual file opened (this string will always start with a "/"). We
c906108c
SS
674 have to take special pains to avoid doubling the "/" between the directory
675 and the file, sigh! Emacs gets confuzzed by this when we print the
676 source file name!!!
677
678 If a file is found, return the descriptor.
679 Otherwise, return -1, with errno set for the last name we tried to open. */
680
681/* >>>> This should only allow files of certain types,
f2172603 682 >>>> eg executable, non-directory */
c906108c 683int
014d698b 684openp (const char *path, int opts, const char *string,
fbdebf46 685 int mode, char **filename_opened)
c906108c 686{
52f0bd74
AC
687 int fd;
688 char *filename;
1f8cc6db
AC
689 const char *p;
690 const char *p1;
52f0bd74 691 int len;
c906108c
SS
692 int alloclen;
693
fbdebf46
JK
694 /* The open syscall MODE parameter is not specified. */
695 gdb_assert ((mode & O_CREAT) == 0);
696
c906108c
SS
697 if (!path)
698 path = ".";
699
c906108c 700 mode |= O_BINARY;
c906108c 701
014d698b 702 if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string))
c906108c
SS
703 {
704 int i;
072b1022
DJ
705
706 if (is_regular_file (string))
707 {
708 filename = alloca (strlen (string) + 1);
709 strcpy (filename, string);
fbdebf46 710 fd = open (filename, mode);
072b1022
DJ
711 if (fd >= 0)
712 goto done;
713 }
714 else
3f565f1e
DJ
715 {
716 filename = NULL;
717 fd = -1;
718 }
072b1022 719
014d698b
EZ
720 if (!(opts & OPF_SEARCH_IN_PATH))
721 for (i = 0; string[i]; i++)
722 if (IS_DIR_SEPARATOR (string[i]))
723 goto done;
c906108c
SS
724 }
725
014d698b
EZ
726 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
727 while (IS_DIR_SEPARATOR(string[0]))
728 string++;
729
c906108c 730 /* ./foo => foo */
fe4e3eb8 731 while (string[0] == '.' && IS_DIR_SEPARATOR (string[1]))
c906108c
SS
732 string += 2;
733
734 alloclen = strlen (path) + strlen (string) + 2;
1f8cc6db 735 filename = alloca (alloclen);
c906108c
SS
736 fd = -1;
737 for (p = path; p; p = p1 ? p1 + 1 : 0)
738 {
1f8cc6db 739 p1 = strchr (p, DIRNAME_SEPARATOR);
c906108c
SS
740 if (p1)
741 len = p1 - p;
742 else
743 len = strlen (p);
744
745 if (len == 4 && p[0] == '$' && p[1] == 'c'
c5aa993b
JM
746 && p[2] == 'w' && p[3] == 'd')
747 {
748 /* Name is $cwd -- insert current directory name instead. */
749 int newlen;
750
751 /* First, realloc the filename buffer if too short. */
752 len = strlen (current_directory);
753 newlen = len + strlen (string) + 2;
754 if (newlen > alloclen)
755 {
756 alloclen = newlen;
1f8cc6db 757 filename = alloca (alloclen);
c5aa993b
JM
758 }
759 strcpy (filename, current_directory);
760 }
761 else
762 {
763 /* Normal file name in path -- just use it. */
764 strncpy (filename, p, len);
765 filename[len] = 0;
c906108c 766 }
c906108c
SS
767
768 /* Remove trailing slashes */
fe4e3eb8 769 while (len > 0 && IS_DIR_SEPARATOR (filename[len - 1]))
c906108c
SS
770 filename[--len] = 0;
771
c5aa993b 772 strcat (filename + len, SLASH_STRING);
c906108c
SS
773 strcat (filename, string);
774
1da1a192 775 if (is_regular_file (filename))
5e987968
AS
776 {
777 fd = open (filename, mode);
778 if (fd >= 0)
779 break;
780 }
c906108c
SS
781 }
782
c5aa993b 783done:
c906108c
SS
784 if (filename_opened)
785 {
a89f66e4
JB
786 /* If a file was opened, canonicalize its filename. Use xfullpath
787 rather than gdb_realpath to avoid resolving the basename part
788 of filenames when the associated file is a symbolic link. This
789 fixes a potential inconsistency between the filenames known to
790 GDB and the filenames it prints in the annotations. */
c906108c 791 if (fd < 0)
1f8cc6db 792 *filename_opened = NULL;
fe4e3eb8 793 else if (IS_ABSOLUTE_PATH (filename))
a89f66e4 794 *filename_opened = xfullpath (filename);
c906108c
SS
795 else
796 {
797 /* Beware the // my son, the Emacs barfs, the botch that catch... */
c5aa993b 798
58d370e0 799 char *f = concat (current_directory,
5e987968
AS
800 IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
801 ? "" : SLASH_STRING,
1754f103 802 filename, (char *)NULL);
a89f66e4 803 *filename_opened = xfullpath (f);
58d370e0 804 xfree (f);
c5aa993b 805 }
c906108c 806 }
c906108c
SS
807
808 return fd;
809}
810
c5aa993b 811
c906108c
SS
812/* This is essentially a convenience, for clients that want the behaviour
813 of openp, using source_path, but that really don't want the file to be
814 opened but want instead just to know what the full pathname is (as
815 qualified against source_path).
816
817 The current working directory is searched first.
818
819 If the file was found, this function returns 1, and FULL_PATHNAME is
820 set to the fully-qualified pathname.
821
5e987968 822 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
c906108c 823int
24f81874 824source_full_path_of (const char *filename, char **full_pathname)
c906108c 825{
c5aa993b 826 int fd;
c906108c 827
014d698b 828 fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename,
fbdebf46 829 O_RDONLY, full_pathname);
c906108c
SS
830 if (fd < 0)
831 {
832 *full_pathname = NULL;
833 return 0;
834 }
835
836 close (fd);
837 return 1;
838}
839
2f61ca93
JB
840/* Return non-zero if RULE matches PATH, that is if the rule can be
841 applied to PATH. */
842
843static int
844substitute_path_rule_matches (const struct substitute_path_rule *rule,
845 const char *path)
846{
847 const int from_len = strlen (rule->from);
848 const int path_len = strlen (path);
849 char *path_start;
850
851 if (path_len < from_len)
852 return 0;
853
854 /* The substitution rules are anchored at the start of the path,
855 so the path should start with rule->from. There is no filename
856 comparison routine, so we need to extract the first FROM_LEN
857 characters from PATH first and use that to do the comparison. */
858
859 path_start = alloca (from_len + 1);
860 strncpy (path_start, path, from_len);
861 path_start[from_len] = '\0';
862
863 if (FILENAME_CMP (path_start, rule->from) != 0)
864 return 0;
865
866 /* Make sure that the region in the path that matches the substitution
867 rule is immediately followed by a directory separator (or the end of
868 string character). */
869
870 if (path[from_len] != '\0' && !IS_DIR_SEPARATOR (path[from_len]))
871 return 0;
872
873 return 1;
874}
875
876/* Find the substitute-path rule that applies to PATH and return it.
877 Return NULL if no rule applies. */
878
879static struct substitute_path_rule *
880get_substitute_path_rule (const char *path)
881{
882 struct substitute_path_rule *rule = substitute_path_rules;
883
884 while (rule != NULL && !substitute_path_rule_matches (rule, path))
885 rule = rule->next;
886
887 return rule;
888}
889
890/* If the user specified a source path substitution rule that applies
891 to PATH, then apply it and return the new path. This new path must
892 be deallocated afterwards.
893
894 Return NULL if no substitution rule was specified by the user,
895 or if no rule applied to the given PATH. */
896
897static char *
898rewrite_source_path (const char *path)
899{
900 const struct substitute_path_rule *rule = get_substitute_path_rule (path);
901 char *new_path;
902 int from_len;
903
904 if (rule == NULL)
905 return NULL;
906
907 from_len = strlen (rule->from);
908
909 /* Compute the rewritten path and return it. */
910
911 new_path =
912 (char *) xmalloc (strlen (path) + 1 + strlen (rule->to) - from_len);
913 strcpy (new_path, rule->to);
914 strcat (new_path, path + from_len);
915
916 return new_path;
917}
918
57c22c6c 919/* This function is capable of finding the absolute path to a
e2357892
JK
920 source file, and opening it, provided you give it a FILENAME. Both the
921 DIRNAME and FULLNAME are only added suggestions on where to find the file.
57c22c6c 922
57c22c6c
BR
923 FILENAME should be the filename to open.
924 DIRNAME is the compilation directory of a particular source file.
925 Only some debug formats provide this info.
926 FULLNAME can be the last known absolute path to the file in question.
86991504
DE
927 Space for the path must have been malloc'd. If a path substitution
928 is applied we free the old value and set a new one.
57c22c6c
BR
929
930 On Success
931 A valid file descriptor is returned. ( the return value is positive )
932 FULLNAME is set to the absolute path to the file just opened.
86991504 933 The caller is responsible for freeing FULLNAME.
57c22c6c
BR
934
935 On Failure
2f61ca93 936 An invalid file descriptor is returned. ( the return value is negative )
57c22c6c 937 FULLNAME is set to NULL. */
86991504
DE
938
939static int
e2357892 940find_and_open_source (const char *filename,
5e987968
AS
941 const char *dirname,
942 char **fullname)
c906108c
SS
943{
944 char *path = source_path;
31889e00 945 const char *p;
c906108c 946 int result;
c906108c
SS
947
948 /* Quick way out if we already know its full name */
2f61ca93 949
57c22c6c 950 if (*fullname)
c906108c 951 {
2f61ca93
JB
952 /* The user may have requested that source paths be rewritten
953 according to substitution rules he provided. If a substitution
954 rule applies to this path, then apply it. */
955 char *rewritten_fullname = rewrite_source_path (*fullname);
956
957 if (rewritten_fullname != NULL)
958 {
959 xfree (*fullname);
960 *fullname = rewritten_fullname;
961 }
962
57c22c6c 963 result = open (*fullname, OPEN_MODE);
c906108c 964 if (result >= 0)
c5aa993b 965 return result;
c906108c 966 /* Didn't work -- free old one, try again. */
2dc74dc1 967 xfree (*fullname);
57c22c6c 968 *fullname = NULL;
c906108c
SS
969 }
970
57c22c6c 971 if (dirname != NULL)
c906108c 972 {
2f61ca93
JB
973 /* If necessary, rewrite the compilation directory name according
974 to the source path substitution rules specified by the user. */
975
976 char *rewritten_dirname = rewrite_source_path (dirname);
977
978 if (rewritten_dirname != NULL)
979 {
980 make_cleanup (xfree, rewritten_dirname);
981 dirname = rewritten_dirname;
982 }
983
c906108c
SS
984 /* Replace a path entry of $cdir with the compilation directory name */
985#define cdir_len 5
986 /* We cast strstr's result in case an ANSIhole has made it const,
c5aa993b
JM
987 which produces a "required warning" when assigned to a nonconst. */
988 p = (char *) strstr (source_path, "$cdir");
c906108c 989 if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)
c5aa993b 990 && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0'))
c906108c
SS
991 {
992 int len;
993
994 path = (char *)
57c22c6c 995 alloca (strlen (source_path) + 1 + strlen (dirname) + 1);
c906108c 996 len = p - source_path;
c5aa993b 997 strncpy (path, source_path, len); /* Before $cdir */
57c22c6c 998 strcpy (path + len, dirname); /* new stuff */
c5aa993b 999 strcat (path + len, source_path + len + cdir_len); /* After $cdir */
c906108c
SS
1000 }
1001 }
8da2a1df
DJ
1002
1003 if (IS_ABSOLUTE_PATH (filename))
56163ce1 1004 {
8da2a1df
DJ
1005 /* If filename is absolute path, try the source path
1006 substitution on it. */
56163ce1
JB
1007 char *rewritten_filename = rewrite_source_path (filename);
1008
1009 if (rewritten_filename != NULL)
1010 {
1011 make_cleanup (xfree, rewritten_filename);
1012 filename = rewritten_filename;
1013 }
1014 }
c906108c 1015
fbdebf46 1016 result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname);
c906108c
SS
1017 if (result < 0)
1018 {
1019 /* Didn't work. Try using just the basename. */
57c22c6c
BR
1020 p = lbasename (filename);
1021 if (p != filename)
fbdebf46 1022 result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, fullname);
c906108c 1023 }
c906108c 1024
c906108c
SS
1025 return result;
1026}
1027
57c22c6c
BR
1028/* Open a source file given a symtab S. Returns a file descriptor or
1029 negative number for error.
1030
1031 This function is a convience function to find_and_open_source. */
1032
1033int
1034open_source_file (struct symtab *s)
1035{
5e987968
AS
1036 if (!s)
1037 return -1;
57c22c6c 1038
e2357892 1039 return find_and_open_source (s->filename, s->dirname, &s->fullname);
57c22c6c
BR
1040}
1041
1042/* Finds the fullname that a symtab represents.
c906108c 1043
f132ba9d 1044 If this functions finds the fullname, it will save it in s->fullname
57c22c6c
BR
1045 and it will also return the value.
1046
1047 If this function fails to find the file that this symtab represents,
f132ba9d 1048 NULL will be returned and s->fullname will be set to NULL. */
c906108c 1049char *
57c22c6c 1050symtab_to_fullname (struct symtab *s)
c906108c 1051{
57c22c6c 1052 int r;
c906108c
SS
1053
1054 if (!s)
1055 return NULL;
1056
57c22c6c
BR
1057 /* Don't check s->fullname here, the file could have been
1058 deleted/moved/..., look for it again */
e2357892 1059 r = find_and_open_source (s->filename, s->dirname, &s->fullname);
c906108c 1060
9fe4a216 1061 if (r >= 0)
5e987968
AS
1062 {
1063 close (r);
1064 return s->fullname;
1065 }
c906108c 1066
57c22c6c
BR
1067 return NULL;
1068}
c906108c 1069
57c22c6c 1070/* Finds the fullname that a partial_symtab represents.
c906108c 1071
57c22c6c
BR
1072 If this functions finds the fullname, it will save it in ps->fullname
1073 and it will also return the value.
c906108c 1074
57c22c6c
BR
1075 If this function fails to find the file that this partial_symtab represents,
1076 NULL will be returned and ps->fullname will be set to NULL. */
1077char *
1078psymtab_to_fullname (struct partial_symtab *ps)
1079{
1080 int r;
1081
1082 if (!ps)
1083 return NULL;
1084
1085 /* Don't check ps->fullname here, the file could have been
1086 deleted/moved/..., look for it again */
e2357892 1087 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
57c22c6c 1088
9fe4a216 1089 if (r >= 0)
5e987968
AS
1090 {
1091 close (r);
1092 return ps->fullname;
1093 }
1094
57c22c6c
BR
1095 return NULL;
1096}
5e987968 1097\f
c906108c
SS
1098/* Create and initialize the table S->line_charpos that records
1099 the positions of the lines in the source file, which is assumed
1100 to be open on descriptor DESC.
1101 All set S->nlines to the number of such lines. */
1102
1103void
fba45db2 1104find_source_lines (struct symtab *s, int desc)
c906108c
SS
1105{
1106 struct stat st;
52f0bd74 1107 char *data, *p, *end;
c906108c
SS
1108 int nlines = 0;
1109 int lines_allocated = 1000;
1110 int *line_charpos;
1111 long mtime = 0;
1112 int size;
1113
be8ca11b 1114 gdb_assert (s);
7936743b 1115 line_charpos = (int *) xmalloc (lines_allocated * sizeof (int));
c906108c
SS
1116 if (fstat (desc, &st) < 0)
1117 perror_with_name (s->filename);
1118
be8ca11b 1119 if (s->objfile && s->objfile->obfd)
c04ea773 1120 mtime = s->objfile->mtime;
c906108c 1121 else if (exec_bfd)
c04ea773 1122 mtime = exec_bfd_mtime;
c906108c
SS
1123
1124 if (mtime && mtime < st.st_mtime)
8a3fe4f8 1125 warning (_("Source file is more recent than executable."));
c906108c
SS
1126
1127#ifdef LSEEK_NOT_LINEAR
1128 {
1129 char c;
1130
1131 /* Have to read it byte by byte to find out where the chars live */
1132
1133 line_charpos[0] = lseek (desc, 0, SEEK_CUR);
1134 nlines = 1;
c5aa993b 1135 while (myread (desc, &c, 1) > 0)
c906108c 1136 {
c5aa993b 1137 if (c == '\n')
c906108c 1138 {
c5aa993b 1139 if (nlines == lines_allocated)
c906108c
SS
1140 {
1141 lines_allocated *= 2;
1142 line_charpos =
0efffb96
AC
1143 (int *) xrealloc ((char *) line_charpos,
1144 sizeof (int) * lines_allocated);
c906108c
SS
1145 }
1146 line_charpos[nlines++] = lseek (desc, 0, SEEK_CUR);
1147 }
1148 }
1149 }
1150#else /* lseek linear. */
1151 {
1152 struct cleanup *old_cleanups;
1153
1154 /* st_size might be a large type, but we only support source files whose
1155 size fits in an int. */
1156 size = (int) st.st_size;
1157
1158 /* Use malloc, not alloca, because this may be pretty large, and we may
1159 run into various kinds of limits on stack size. */
1160 data = (char *) xmalloc (size);
b8c9b27d 1161 old_cleanups = make_cleanup (xfree, data);
c906108c
SS
1162
1163 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1164 size = myread (desc, data, size);
1165 if (size < 0)
1166 perror_with_name (s->filename);
1167 end = data + size;
1168 p = data;
1169 line_charpos[0] = 0;
1170 nlines = 1;
1171 while (p != end)
1172 {
1173 if (*p++ == '\n'
c5aa993b 1174 /* A newline at the end does not start a new line. */
c906108c
SS
1175 && p != end)
1176 {
1177 if (nlines == lines_allocated)
1178 {
1179 lines_allocated *= 2;
1180 line_charpos =
0efffb96
AC
1181 (int *) xrealloc ((char *) line_charpos,
1182 sizeof (int) * lines_allocated);
c906108c
SS
1183 }
1184 line_charpos[nlines++] = p - data;
1185 }
1186 }
1187 do_cleanups (old_cleanups);
1188 }
1189#endif /* lseek linear. */
1190 s->nlines = nlines;
1191 s->line_charpos =
0efffb96 1192 (int *) xrealloc ((char *) line_charpos, nlines * sizeof (int));
c906108c
SS
1193
1194}
1195
1196/* Return the character position of a line LINE in symtab S.
1197 Return 0 if anything is invalid. */
1198
c5aa993b 1199#if 0 /* Currently unused */
c906108c
SS
1200
1201int
fba45db2 1202source_line_charpos (struct symtab *s, int line)
c906108c 1203{
c5aa993b
JM
1204 if (!s)
1205 return 0;
1206 if (!s->line_charpos || line <= 0)
1207 return 0;
c906108c
SS
1208 if (line > s->nlines)
1209 line = s->nlines;
1210 return s->line_charpos[line - 1];
1211}
1212
1213/* Return the line number of character position POS in symtab S. */
1214
1215int
aa1ee363 1216source_charpos_line (struct symtab *s, int chr)
c906108c 1217{
52f0bd74
AC
1218 int line = 0;
1219 int *lnp;
c5aa993b
JM
1220
1221 if (s == 0 || s->line_charpos == 0)
1222 return 0;
c906108c
SS
1223 lnp = s->line_charpos;
1224 /* Files are usually short, so sequential search is Ok */
c5aa993b 1225 while (line < s->nlines && *lnp <= chr)
c906108c
SS
1226 {
1227 line++;
1228 lnp++;
1229 }
1230 if (line >= s->nlines)
1231 line = s->nlines;
1232 return line;
1233}
1234
c5aa993b 1235#endif /* 0 */
c906108c 1236\f
c5aa993b 1237
c906108c
SS
1238/* Get full pathname and line number positions for a symtab.
1239 Return nonzero if line numbers may have changed.
1240 Set *FULLNAME to actual name of the file as found by `openp',
1241 or to 0 if the file is not found. */
1242
1243static int
fba45db2 1244get_filename_and_charpos (struct symtab *s, char **fullname)
c906108c 1245{
52f0bd74 1246 int desc, linenums_changed = 0;
9fe4a216 1247 struct cleanup *cleanups;
c5aa993b 1248
c906108c
SS
1249 desc = open_source_file (s);
1250 if (desc < 0)
1251 {
1252 if (fullname)
1253 *fullname = NULL;
1254 return 0;
c5aa993b 1255 }
9fe4a216 1256 cleanups = make_cleanup_close (desc);
c906108c
SS
1257 if (fullname)
1258 *fullname = s->fullname;
c5aa993b
JM
1259 if (s->line_charpos == 0)
1260 linenums_changed = 1;
1261 if (linenums_changed)
1262 find_source_lines (s, desc);
9fe4a216 1263 do_cleanups (cleanups);
c906108c
SS
1264 return linenums_changed;
1265}
1266
1267/* Print text describing the full name of the source file S
1268 and the line number LINE and its corresponding character position.
1269 The text starts with two Ctrl-z so that the Emacs-GDB interface
1270 can easily find it.
1271
1272 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1273
1274 Return 1 if successful, 0 if could not find the file. */
1275
1276int
fba45db2
KB
1277identify_source_line (struct symtab *s, int line, int mid_statement,
1278 CORE_ADDR pc)
c906108c
SS
1279{
1280 if (s->line_charpos == 0)
c5aa993b 1281 get_filename_and_charpos (s, (char **) NULL);
c906108c
SS
1282 if (s->fullname == 0)
1283 return 0;
1284 if (line > s->nlines)
1285 /* Don't index off the end of the line_charpos array. */
1286 return 0;
1287 annotate_source (s->fullname, line, s->line_charpos[line - 1],
5af949e3 1288 mid_statement, get_objfile_arch (s->objfile), pc);
c906108c
SS
1289
1290 current_source_line = line;
1291 first_line_listed = line;
1292 last_line_listed = line;
1293 current_source_symtab = s;
1294 return 1;
1295}
c906108c 1296\f
c5aa993b 1297
c906108c
SS
1298/* Print source lines from the file of symtab S,
1299 starting with line number LINE and stopping before line number STOPLINE. */
1300
a14ed312
KB
1301static void print_source_lines_base (struct symtab *s, int line, int stopline,
1302 int noerror);
c906108c 1303static void
fba45db2 1304print_source_lines_base (struct symtab *s, int line, int stopline, int noerror)
c906108c 1305{
52f0bd74
AC
1306 int c;
1307 int desc;
1308 FILE *stream;
c906108c 1309 int nlines = stopline - line;
7c8a8b04 1310 struct cleanup *cleanup;
c906108c
SS
1311
1312 /* Regardless of whether we can open the file, set current_source_symtab. */
1313 current_source_symtab = s;
1314 current_source_line = line;
1315 first_line_listed = line;
1316
8b93c638
JM
1317 /* If printing of source lines is disabled, just print file and line number */
1318 if (ui_out_test_flags (uiout, ui_source_list))
1319 {
c5aa993b
JM
1320 /* Only prints "No such file or directory" once */
1321 if ((s != last_source_visited) || (!last_source_error))
1322 {
1323 last_source_visited = s;
1324 desc = open_source_file (s);
1325 }
1326 else
1327 {
1328 desc = last_source_error;
1329 noerror = 1;
1330 }
8b93c638
JM
1331 }
1332 else
1333 {
1334 desc = -1;
1335 noerror = 1;
1336 }
c906108c
SS
1337
1338 if (desc < 0)
1339 {
1340 last_source_error = desc;
1341
c5aa993b
JM
1342 if (!noerror)
1343 {
c906108c
SS
1344 char *name = alloca (strlen (s->filename) + 100);
1345 sprintf (name, "%d\t%s", line, s->filename);
1346 print_sys_errmsg (name, errno);
1347 }
1348 else
8b93c638
JM
1349 ui_out_field_int (uiout, "line", line);
1350 ui_out_text (uiout, "\tin ");
1351 ui_out_field_string (uiout, "file", s->filename);
1352 ui_out_text (uiout, "\n");
c906108c
SS
1353
1354 return;
1355 }
1356
1357 last_source_error = 0;
1358
1359 if (s->line_charpos == 0)
1360 find_source_lines (s, desc);
1361
1362 if (line < 1 || line > s->nlines)
1363 {
1364 close (desc);
8a3fe4f8 1365 error (_("Line number %d out of range; %s has %d lines."),
c906108c
SS
1366 line, s->filename, s->nlines);
1367 }
1368
1369 if (lseek (desc, s->line_charpos[line - 1], 0) < 0)
1370 {
1371 close (desc);
1372 perror_with_name (s->filename);
1373 }
1374
1375 stream = fdopen (desc, FDOPEN_MODE);
1376 clearerr (stream);
7c8a8b04 1377 cleanup = make_cleanup_fclose (stream);
c906108c
SS
1378
1379 while (nlines-- > 0)
1380 {
8b93c638
JM
1381 char buf[20];
1382
1383 c = fgetc (stream);
1384 if (c == EOF)
1385 break;
1386 last_line_listed = current_source_line;
1387 sprintf (buf, "%d\t", current_source_line++);
1388 ui_out_text (uiout, buf);
1389 do
1390 {
1391 if (c < 040 && c != '\t' && c != '\n' && c != '\r')
1392 {
1393 sprintf (buf, "^%c", c + 0100);
1394 ui_out_text (uiout, buf);
1395 }
1396 else if (c == 0177)
1397 ui_out_text (uiout, "^?");
8b93c638
JM
1398 else if (c == '\r')
1399 {
1400 /* Skip a \r character, but only before a \n. */
1401 int c1 = fgetc (stream);
1402
1403 if (c1 != '\n')
1404 printf_filtered ("^%c", c + 0100);
1405 if (c1 != EOF)
1406 ungetc (c1, stream);
1407 }
8b93c638
JM
1408 else
1409 {
1410 sprintf (buf, "%c", c);
1411 ui_out_text (uiout, buf);
1412 }
1413 }
1414 while (c != '\n' && (c = fgetc (stream)) >= 0);
c906108c
SS
1415 }
1416
7c8a8b04 1417 do_cleanups (cleanup);
c906108c
SS
1418}
1419\f
1420/* Show source lines from the file of symtab S, starting with line
f132ba9d 1421 number LINE and stopping before line number STOPLINE. If this is
c906108c
SS
1422 not the command line version, then the source is shown in the source
1423 window otherwise it is simply printed */
1424
c5aa993b 1425void
fba45db2 1426print_source_lines (struct symtab *s, int line, int stopline, int noerror)
c906108c 1427{
c5aa993b 1428 print_source_lines_base (s, line, stopline, noerror);
c906108c
SS
1429}
1430\f
c906108c
SS
1431/* Print info on range of pc's in a specified line. */
1432
1433static void
fba45db2 1434line_info (char *arg, int from_tty)
c906108c
SS
1435{
1436 struct symtabs_and_lines sals;
1437 struct symtab_and_line sal;
1438 CORE_ADDR start_pc, end_pc;
1439 int i;
1440
fe39c653 1441 init_sal (&sal); /* initialize to zeroes */
c906108c
SS
1442
1443 if (arg == 0)
1444 {
1445 sal.symtab = current_source_symtab;
1446 sal.line = last_line_listed;
1447 sals.nelts = 1;
1448 sals.sals = (struct symtab_and_line *)
1449 xmalloc (sizeof (struct symtab_and_line));
1450 sals.sals[0] = sal;
1451 }
1452 else
1453 {
1454 sals = decode_line_spec_1 (arg, 0);
c5aa993b 1455
c906108c
SS
1456 dont_repeat ();
1457 }
1458
1459 /* C++ More than one line may have been specified, as when the user
1460 specifies an overloaded function name. Print info on them all. */
1461 for (i = 0; i < sals.nelts; i++)
1462 {
1463 sal = sals.sals[i];
c5aa993b 1464
c906108c
SS
1465 if (sal.symtab == 0)
1466 {
5af949e3
UW
1467 struct gdbarch *gdbarch = get_current_arch ();
1468
a3f17187 1469 printf_filtered (_("No line number information available"));
c906108c
SS
1470 if (sal.pc != 0)
1471 {
1472 /* This is useful for "info line *0x7f34". If we can't tell the
c5aa993b
JM
1473 user about a source line, at least let them have the symbolic
1474 address. */
c906108c
SS
1475 printf_filtered (" for address ");
1476 wrap_here (" ");
5af949e3 1477 print_address (gdbarch, sal.pc, gdb_stdout);
c906108c
SS
1478 }
1479 else
1480 printf_filtered (".");
1481 printf_filtered ("\n");
1482 }
1483 else if (sal.line > 0
1484 && find_line_pc_range (sal, &start_pc, &end_pc))
1485 {
5af949e3
UW
1486 struct gdbarch *gdbarch = get_objfile_arch (sal.symtab->objfile);
1487
c906108c
SS
1488 if (start_pc == end_pc)
1489 {
1490 printf_filtered ("Line %d of \"%s\"",
1491 sal.line, sal.symtab->filename);
1492 wrap_here (" ");
1493 printf_filtered (" is at address ");
5af949e3 1494 print_address (gdbarch, start_pc, gdb_stdout);
c906108c
SS
1495 wrap_here (" ");
1496 printf_filtered (" but contains no code.\n");
1497 }
1498 else
1499 {
1500 printf_filtered ("Line %d of \"%s\"",
1501 sal.line, sal.symtab->filename);
1502 wrap_here (" ");
1503 printf_filtered (" starts at address ");
5af949e3 1504 print_address (gdbarch, start_pc, gdb_stdout);
c906108c
SS
1505 wrap_here (" ");
1506 printf_filtered (" and ends at ");
5af949e3 1507 print_address (gdbarch, end_pc, gdb_stdout);
c906108c
SS
1508 printf_filtered (".\n");
1509 }
1510
1511 /* x/i should display this line's code. */
5af949e3 1512 set_next_address (gdbarch, start_pc);
c906108c
SS
1513
1514 /* Repeating "info line" should do the following line. */
1515 last_line_listed = sal.line + 1;
1516
1517 /* If this is the only line, show the source code. If it could
1518 not find the file, don't do anything special. */
1519 if (annotation_level && sals.nelts == 1)
1520 identify_source_line (sal.symtab, sal.line, 0, start_pc);
1521 }
1522 else
1523 /* Is there any case in which we get here, and have an address
1524 which the user would want to see? If we have debugging symbols
1525 and no line numbers? */
a3f17187 1526 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
c906108c
SS
1527 sal.line, sal.symtab->filename);
1528 }
b8c9b27d 1529 xfree (sals.sals);
c906108c
SS
1530}
1531\f
1532/* Commands to search the source file for a regexp. */
1533
c906108c 1534static void
fba45db2 1535forward_search_command (char *regex, int from_tty)
c906108c 1536{
52f0bd74
AC
1537 int c;
1538 int desc;
1539 FILE *stream;
c906108c
SS
1540 int line;
1541 char *msg;
9fe4a216 1542 struct cleanup *cleanups;
c906108c 1543
c906108c 1544 line = last_line_listed + 1;
c906108c
SS
1545
1546 msg = (char *) re_comp (regex);
1547 if (msg)
8a3fe4f8 1548 error (("%s"), msg);
c906108c
SS
1549
1550 if (current_source_symtab == 0)
1551 select_source_symtab (0);
1552
1553 desc = open_source_file (current_source_symtab);
1554 if (desc < 0)
1555 perror_with_name (current_source_symtab->filename);
9fe4a216 1556 cleanups = make_cleanup_close (desc);
c906108c
SS
1557
1558 if (current_source_symtab->line_charpos == 0)
1559 find_source_lines (current_source_symtab, desc);
1560
1561 if (line < 1 || line > current_source_symtab->nlines)
9fe4a216 1562 error (_("Expression not found"));
c906108c
SS
1563
1564 if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
9fe4a216 1565 perror_with_name (current_source_symtab->filename);
c906108c 1566
9fe4a216 1567 discard_cleanups (cleanups);
c906108c
SS
1568 stream = fdopen (desc, FDOPEN_MODE);
1569 clearerr (stream);
9fe4a216 1570 cleanups = make_cleanup_fclose (stream);
c5aa993b
JM
1571 while (1)
1572 {
1573 static char *buf = NULL;
aa1ee363 1574 char *p;
c5aa993b
JM
1575 int cursize, newsize;
1576
1577 cursize = 256;
1578 buf = xmalloc (cursize);
1579 p = buf;
1580
1581 c = getc (stream);
1582 if (c == EOF)
1583 break;
1584 do
c906108c 1585 {
c5aa993b
JM
1586 *p++ = c;
1587 if (p - buf == cursize)
1588 {
1589 newsize = cursize + cursize / 2;
1590 buf = xrealloc (buf, newsize);
1591 p = buf + cursize;
1592 cursize = newsize;
1593 }
c906108c 1594 }
c5aa993b 1595 while (c != '\n' && (c = getc (stream)) >= 0);
c906108c 1596
7be570e7
JM
1597 /* Remove the \r, if any, at the end of the line, otherwise
1598 regular expressions that end with $ or \n won't work. */
1599 if (p - buf > 1 && p[-2] == '\r')
1600 {
1601 p--;
1602 p[-1] = '\n';
1603 }
7be570e7 1604
c5aa993b
JM
1605 /* we now have a source line in buf, null terminate and match */
1606 *p = 0;
1607 if (re_exec (buf) > 0)
1608 {
1609 /* Match! */
e681b284 1610 do_cleanups (cleanups);
c5aa993b 1611 print_source_lines (current_source_symtab, line, line + 1, 0);
4fa62494 1612 set_internalvar_integer (lookup_internalvar ("_"), line);
c5aa993b
JM
1613 current_source_line = max (line - lines_to_list / 2, 1);
1614 return;
1615 }
1616 line++;
1617 }
c906108c 1618
a3f17187 1619 printf_filtered (_("Expression not found\n"));
9fe4a216 1620 do_cleanups (cleanups);
c906108c
SS
1621}
1622
c906108c 1623static void
fba45db2 1624reverse_search_command (char *regex, int from_tty)
c906108c 1625{
52f0bd74
AC
1626 int c;
1627 int desc;
1628 FILE *stream;
c906108c
SS
1629 int line;
1630 char *msg;
9fe4a216 1631 struct cleanup *cleanups;
063190b6 1632
c906108c 1633 line = last_line_listed - 1;
c906108c
SS
1634
1635 msg = (char *) re_comp (regex);
1636 if (msg)
8a3fe4f8 1637 error (("%s"), msg);
c906108c
SS
1638
1639 if (current_source_symtab == 0)
1640 select_source_symtab (0);
1641
1642 desc = open_source_file (current_source_symtab);
1643 if (desc < 0)
1644 perror_with_name (current_source_symtab->filename);
9fe4a216 1645 cleanups = make_cleanup_close (desc);
c906108c
SS
1646
1647 if (current_source_symtab->line_charpos == 0)
1648 find_source_lines (current_source_symtab, desc);
1649
1650 if (line < 1 || line > current_source_symtab->nlines)
9fe4a216 1651 error (_("Expression not found"));
c906108c
SS
1652
1653 if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
9fe4a216 1654 perror_with_name (current_source_symtab->filename);
c906108c 1655
9fe4a216 1656 discard_cleanups (cleanups);
c906108c
SS
1657 stream = fdopen (desc, FDOPEN_MODE);
1658 clearerr (stream);
9fe4a216 1659 cleanups = make_cleanup_fclose (stream);
c906108c
SS
1660 while (line > 1)
1661 {
1662/* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1663 char buf[4096]; /* Should be reasonable??? */
aa1ee363 1664 char *p = buf;
c906108c
SS
1665
1666 c = getc (stream);
1667 if (c == EOF)
1668 break;
c5aa993b
JM
1669 do
1670 {
1671 *p++ = c;
1672 }
1673 while (c != '\n' && (c = getc (stream)) >= 0);
c906108c 1674
7be570e7
JM
1675 /* Remove the \r, if any, at the end of the line, otherwise
1676 regular expressions that end with $ or \n won't work. */
1677 if (p - buf > 1 && p[-2] == '\r')
1678 {
1679 p--;
1680 p[-1] = '\n';
1681 }
7be570e7 1682
c906108c
SS
1683 /* We now have a source line in buf; null terminate and match. */
1684 *p = 0;
1685 if (re_exec (buf) > 0)
1686 {
1687 /* Match! */
e681b284 1688 do_cleanups (cleanups);
c5aa993b 1689 print_source_lines (current_source_symtab, line, line + 1, 0);
4fa62494 1690 set_internalvar_integer (lookup_internalvar ("_"), line);
c906108c
SS
1691 current_source_line = max (line - lines_to_list / 2, 1);
1692 return;
1693 }
1694 line--;
1695 if (fseek (stream, current_source_symtab->line_charpos[line - 1], 0) < 0)
1696 {
e681b284 1697 do_cleanups (cleanups);
c906108c
SS
1698 perror_with_name (current_source_symtab->filename);
1699 }
1700 }
1701
a3f17187 1702 printf_filtered (_("Expression not found\n"));
9fe4a216 1703 do_cleanups (cleanups);
c906108c
SS
1704 return;
1705}
2f61ca93
JB
1706
1707/* If the last character of PATH is a directory separator, then strip it. */
1708
1709static void
1710strip_trailing_directory_separator (char *path)
1711{
1712 const int last = strlen (path) - 1;
1713
1714 if (last < 0)
1715 return; /* No stripping is needed if PATH is the empty string. */
1716
1717 if (IS_DIR_SEPARATOR (path[last]))
1718 path[last] = '\0';
1719}
1720
1721/* Return the path substitution rule that matches FROM.
1722 Return NULL if no rule matches. */
1723
1724static struct substitute_path_rule *
1725find_substitute_path_rule (const char *from)
1726{
1727 struct substitute_path_rule *rule = substitute_path_rules;
1728
1729 while (rule != NULL)
1730 {
1731 if (FILENAME_CMP (rule->from, from) == 0)
1732 return rule;
1733 rule = rule->next;
1734 }
1735
1736 return NULL;
1737}
1738
1739/* Add a new substitute-path rule at the end of the current list of rules.
1740 The new rule will replace FROM into TO. */
1741
29b0e8a2 1742void
2f61ca93
JB
1743add_substitute_path_rule (char *from, char *to)
1744{
1745 struct substitute_path_rule *rule;
1746 struct substitute_path_rule *new_rule;
1747
1748 new_rule = xmalloc (sizeof (struct substitute_path_rule));
1749 new_rule->from = xstrdup (from);
1750 new_rule->to = xstrdup (to);
1751 new_rule->next = NULL;
1752
1753 /* If the list of rules are empty, then insert the new rule
1754 at the head of the list. */
1755
1756 if (substitute_path_rules == NULL)
1757 {
1758 substitute_path_rules = new_rule;
1759 return;
1760 }
1761
1762 /* Otherwise, skip to the last rule in our list and then append
1763 the new rule. */
1764
1765 rule = substitute_path_rules;
1766 while (rule->next != NULL)
1767 rule = rule->next;
1768
1769 rule->next = new_rule;
1770}
1771
1772/* Remove the given source path substitution rule from the current list
1773 of rules. The memory allocated for that rule is also deallocated. */
1774
1775static void
1776delete_substitute_path_rule (struct substitute_path_rule *rule)
1777{
1778 if (rule == substitute_path_rules)
1779 substitute_path_rules = rule->next;
1780 else
1781 {
1782 struct substitute_path_rule *prev = substitute_path_rules;
1783
1784 while (prev != NULL && prev->next != rule)
1785 prev = prev->next;
1786
1787 gdb_assert (prev != NULL);
1788
1789 prev->next = rule->next;
1790 }
1791
1792 xfree (rule->from);
1793 xfree (rule->to);
1794 xfree (rule);
1795}
1796
1797/* Implement the "show substitute-path" command. */
1798
1799static void
1800show_substitute_path_command (char *args, int from_tty)
1801{
1802 struct substitute_path_rule *rule = substitute_path_rules;
1803 char **argv;
1804 char *from = NULL;
1805
d1a41061 1806 argv = gdb_buildargv (args);
2f61ca93
JB
1807 make_cleanup_freeargv (argv);
1808
1809 /* We expect zero or one argument. */
1810
1811 if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
1812 error (_("Too many arguments in command"));
1813
1814 if (argv != NULL && argv[0] != NULL)
1815 from = argv[0];
1816
1817 /* Print the substitution rules. */
1818
1819 if (from != NULL)
1820 printf_filtered
1821 (_("Source path substitution rule matching `%s':\n"), from);
1822 else
1823 printf_filtered (_("List of all source path substitution rules:\n"));
1824
1825 while (rule != NULL)
1826 {
1827 if (from == NULL || FILENAME_CMP (rule->from, from) == 0)
1828 printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to);
1829 rule = rule->next;
1830 }
1831}
1832
1833/* Implement the "unset substitute-path" command. */
1834
1835static void
1836unset_substitute_path_command (char *args, int from_tty)
1837{
1838 struct substitute_path_rule *rule = substitute_path_rules;
d1a41061 1839 char **argv = gdb_buildargv (args);
2f61ca93
JB
1840 char *from = NULL;
1841 int rule_found = 0;
1842
1843 /* This function takes either 0 or 1 argument. */
1844
77accacd 1845 make_cleanup_freeargv (argv);
2f61ca93
JB
1846 if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
1847 error (_("Incorrect usage, too many arguments in command"));
1848
1849 if (argv != NULL && argv[0] != NULL)
1850 from = argv[0];
1851
1852 /* If the user asked for all the rules to be deleted, ask him
1853 to confirm and give him a chance to abort before the action
1854 is performed. */
1855
1856 if (from == NULL
1857 && !query (_("Delete all source path substitution rules? ")))
1858 error (_("Canceled"));
1859
1860 /* Delete the rule matching the argument. No argument means that
1861 all rules should be deleted. */
1862
1863 while (rule != NULL)
1864 {
1865 struct substitute_path_rule *next = rule->next;
1866
1867 if (from == NULL || FILENAME_CMP (from, rule->from) == 0)
1868 {
1869 delete_substitute_path_rule (rule);
1870 rule_found = 1;
1871 }
1872
1873 rule = next;
1874 }
1875
1876 /* If the user asked for a specific rule to be deleted but
1877 we could not find it, then report an error. */
1878
1879 if (from != NULL && !rule_found)
1880 error (_("No substitution rule defined for `%s'"), from);
c4e86dd4
DJ
1881
1882 forget_cached_source_info ();
2f61ca93
JB
1883}
1884
1885/* Add a new source path substitution rule. */
1886
1887static void
1888set_substitute_path_command (char *args, int from_tty)
1889{
1890 char *from_path, *to_path;
1891 char **argv;
1892 struct substitute_path_rule *rule;
1893
d1a41061 1894 argv = gdb_buildargv (args);
2f61ca93
JB
1895 make_cleanup_freeargv (argv);
1896
1897 if (argv == NULL || argv[0] == NULL || argv [1] == NULL)
1898 error (_("Incorrect usage, too few arguments in command"));
1899
1900 if (argv[2] != NULL)
1901 error (_("Incorrect usage, too many arguments in command"));
1902
1903 if (*(argv[0]) == '\0')
1904 error (_("First argument must be at least one character long"));
1905
1906 /* Strip any trailing directory separator character in either FROM
1907 or TO. The substitution rule already implicitly contains them. */
1908 strip_trailing_directory_separator (argv[0]);
1909 strip_trailing_directory_separator (argv[1]);
1910
1911 /* If a rule with the same "from" was previously defined, then
1912 delete it. This new rule replaces it. */
1913
1914 rule = find_substitute_path_rule (argv[0]);
1915 if (rule != NULL)
1916 delete_substitute_path_rule (rule);
1917
1918 /* Insert the new substitution rule. */
1919
1920 add_substitute_path_rule (argv[0], argv[1]);
c4e86dd4 1921 forget_cached_source_info ();
2f61ca93
JB
1922}
1923
c906108c
SS
1924\f
1925void
fba45db2 1926_initialize_source (void)
c906108c
SS
1927{
1928 struct cmd_list_element *c;
1929 current_source_symtab = 0;
1930 init_source_path ();
1931
1932 /* The intention is to use POSIX Basic Regular Expressions.
1933 Always use the GNU regex routine for consistency across all hosts.
1934 Our current GNU regex.c does not have all the POSIX features, so this is
1935 just an approximation. */
1936 re_set_syntax (RE_SYNTAX_GREP);
1937
1a966eab
AC
1938 c = add_cmd ("directory", class_files, directory_command, _("\
1939Add directory DIR to beginning of search path for source files.\n\
c906108c
SS
1940Forget cached info on source file locations and line positions.\n\
1941DIR can also be $cwd for the current working directory, or $cdir for the\n\
1942directory in which the source file was compiled into object code.\n\
1a966eab 1943With no argument, reset the search path to $cdir:$cwd, the default."),
c906108c
SS
1944 &cmdlist);
1945
1946 if (dbx_commands)
c5aa993b 1947 add_com_alias ("use", "directory", class_files, 0);
c906108c 1948
5ba2abeb 1949 set_cmd_completer (c, filename_completer);
c906108c 1950
1a966eab
AC
1951 add_cmd ("directories", no_class, show_directories, _("\
1952Current search path for finding source files.\n\
c906108c 1953$cwd in the path means the current working directory.\n\
1a966eab 1954$cdir in the path means the compilation directory of the source file."),
c906108c
SS
1955 &showlist);
1956
1957 if (xdb_commands)
1958 {
c5aa993b 1959 add_com_alias ("D", "directory", class_files, 0);
1a966eab
AC
1960 add_cmd ("ld", no_class, show_directories, _("\
1961Current search path for finding source files.\n\
c906108c 1962$cwd in the path means the current working directory.\n\
1a966eab 1963$cdir in the path means the compilation directory of the source file."),
c5aa993b 1964 &cmdlist);
c906108c
SS
1965 }
1966
1967 add_info ("source", source_info,
1bedd215 1968 _("Information about the current source file."));
c906108c 1969
1bedd215
AC
1970 add_info ("line", line_info, _("\
1971Core addresses of the code for a source line.\n\
c906108c
SS
1972Line can be specified as\n\
1973 LINENUM, to list around that line in current file,\n\
1974 FILE:LINENUM, to list around that line in that file,\n\
1975 FUNCTION, to list around beginning of that function,\n\
1976 FILE:FUNCTION, to distinguish among like-named static functions.\n\
c906108c
SS
1977Default is to describe the last source line that was listed.\n\n\
1978This sets the default address for \"x\" to the line's first instruction\n\
1979so that \"x/i\" suffices to start examining the machine code.\n\
1bedd215 1980The address is also stored as the value of \"$_\"."));
c906108c 1981
1bedd215
AC
1982 add_com ("forward-search", class_files, forward_search_command, _("\
1983Search for regular expression (see regex(3)) from last line listed.\n\
1984The matching line number is also stored as the value of \"$_\"."));
c906108c
SS
1985 add_com_alias ("search", "forward-search", class_files, 0);
1986
1bedd215
AC
1987 add_com ("reverse-search", class_files, reverse_search_command, _("\
1988Search backward for regular expression (see regex(3)) from last line listed.\n\
1989The matching line number is also stored as the value of \"$_\"."));
c906108c
SS
1990
1991 if (xdb_commands)
1992 {
c5aa993b
JM
1993 add_com_alias ("/", "forward-search", class_files, 0);
1994 add_com_alias ("?", "reverse-search", class_files, 0);
c906108c
SS
1995 }
1996
bd4109fb 1997 add_setshow_integer_cmd ("listsize", class_support, &lines_to_list, _("\
35096d9d
AC
1998Set number of source lines gdb will list by default."), _("\
1999Show number of source lines gdb will list by default."), NULL,
2000 NULL,
920d2a44 2001 show_lines_to_list,
35096d9d 2002 &setlist, &showlist);
2f61ca93
JB
2003
2004 add_cmd ("substitute-path", class_files, set_substitute_path_command,
2005 _("\
7ef2b397
JB
2006Usage: set substitute-path FROM TO\n\
2007Add a substitution rule replacing FROM into TO in source file names.\n\
2008If a substitution rule was previously set for FROM, the old rule\n\
2009is replaced by the new one."),
2010 &setlist);
2f61ca93
JB
2011
2012 add_cmd ("substitute-path", class_files, unset_substitute_path_command,
2013 _("\
7ef2b397
JB
2014Usage: unset substitute-path [FROM]\n\
2015Delete the rule for substituting FROM in source file names. If FROM\n\
2016is not specified, all substituting rules are deleted.\n\
2017If the debugger cannot find a rule for FROM, it will display a warning."),
2f61ca93
JB
2018 &unsetlist);
2019
2020 add_cmd ("substitute-path", class_files, show_substitute_path_command,
7ef2b397
JB
2021 _("\
2022Usage: show substitute-path [FROM]\n\
2023Print the rule for substituting FROM in source file names. If FROM\n\
2024is not specified, print all substitution rules."),
2f61ca93 2025 &showlist);
c906108c 2026}