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