2006-05-15 Peter O'Gorman <gdb-patches@mlists.thewrittenword.com>
[deliverable/binutils-gdb.git] / gdb / source.c
1 /* List lines of source files for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
3 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23 #include "defs.h"
24 #include "symtab.h"
25 #include "expression.h"
26 #include "language.h"
27 #include "command.h"
28 #include "source.h"
29 #include "gdbcmd.h"
30 #include "frame.h"
31 #include "value.h"
32
33 #include <sys/types.h>
34 #include "gdb_string.h"
35 #include "gdb_stat.h"
36 #include <fcntl.h>
37 #include "gdbcore.h"
38 #include "gdb_regex.h"
39 #include "symfile.h"
40 #include "objfiles.h"
41 #include "annotate.h"
42 #include "gdbtypes.h"
43 #include "linespec.h"
44 #include "filenames.h" /* for DOSish file names */
45 #include "completer.h"
46 #include "ui-out.h"
47 #include "readline/readline.h"
48
49
50 #define OPEN_MODE (O_RDONLY | O_BINARY)
51 #define FDOPEN_MODE FOPEN_RB
52
53 /* Prototypes for exported functions. */
54
55 void _initialize_source (void);
56
57 /* Prototypes for local functions. */
58
59 static int get_filename_and_charpos (struct symtab *, char **);
60
61 static void reverse_search_command (char *, int);
62
63 static void forward_search_command (char *, int);
64
65 static void line_info (char *, int);
66
67 static void source_info (char *, int);
68
69 static void show_directories (char *, int);
70
71 /* Path of directories to search for source files.
72 Same format as the PATH environment variable's value. */
73
74 char *source_path;
75
76 /* Symtab of default file for listing lines of. */
77
78 static struct symtab *current_source_symtab;
79
80 /* Default next line to list. */
81
82 static int current_source_line;
83
84 /* Default number of lines to print with commands like "list".
85 This is based on guessing how many long (i.e. more than chars_per_line
86 characters) lines there will be. To be completely correct, "list"
87 and friends should be rewritten to count characters and see where
88 things are wrapping, but that would be a fair amount of work. */
89
90 int lines_to_list = 10;
91 static void
92 show_lines_to_list (struct ui_file *file, int from_tty,
93 struct cmd_list_element *c, const char *value)
94 {
95 fprintf_filtered (file, _("\
96 Number of source lines gdb will list by default is %s.\n"),
97 value);
98 }
99
100 /* Line number of last line printed. Default for various commands.
101 current_source_line is usually, but not always, the same as this. */
102
103 static int last_line_listed;
104
105 /* First line number listed by last listing command. */
106
107 static int first_line_listed;
108
109 /* Saves the name of the last source file visited and a possible error code.
110 Used to prevent repeating annoying "No such file or directories" msgs */
111
112 static struct symtab *last_source_visited = NULL;
113 static int last_source_error = 0;
114 \f
115 /* Return the first line listed by print_source_lines.
116 Used by command interpreters to request listing from
117 a previous point. */
118
119 int
120 get_first_line_listed (void)
121 {
122 return first_line_listed;
123 }
124
125 /* Return the default number of lines to print with commands like the
126 cli "list". The caller of print_source_lines must use this to
127 calculate the end line and use it in the call to print_source_lines
128 as it does not automatically use this value. */
129
130 int
131 get_lines_to_list (void)
132 {
133 return lines_to_list;
134 }
135
136 /* Return the current source file for listing and next line to list.
137 NOTE: The returned sal pc and end fields are not valid. */
138
139 struct symtab_and_line
140 get_current_source_symtab_and_line (void)
141 {
142 struct symtab_and_line cursal = { 0 };
143
144 cursal.symtab = current_source_symtab;
145 cursal.line = current_source_line;
146 cursal.pc = 0;
147 cursal.end = 0;
148
149 return cursal;
150 }
151
152 /* If the current source file for listing is not set, try and get a default.
153 Usually called before get_current_source_symtab_and_line() is called.
154 It may err out if a default cannot be determined.
155 We must be cautious about where it is called, as it can recurse as the
156 process of determining a new default may call the caller!
157 Use get_current_source_symtab_and_line only to get whatever
158 we have without erroring out or trying to get a default. */
159
160 void
161 set_default_source_symtab_and_line (void)
162 {
163 struct symtab_and_line cursal;
164
165 if (!have_full_symbols () && !have_partial_symbols ())
166 error (_("No symbol table is loaded. Use the \"file\" command."));
167
168 /* Pull in a current source symtab if necessary */
169 if (current_source_symtab == 0)
170 select_source_symtab (0);
171 }
172
173 /* Return the current default file for listing and next line to list
174 (the returned sal pc and end fields are not valid.)
175 and set the current default to whatever is in SAL.
176 NOTE: The returned sal pc and end fields are not valid. */
177
178 struct symtab_and_line
179 set_current_source_symtab_and_line (const struct symtab_and_line *sal)
180 {
181 struct symtab_and_line cursal = { 0 };
182
183 cursal.symtab = current_source_symtab;
184 cursal.line = current_source_line;
185
186 current_source_symtab = sal->symtab;
187 current_source_line = sal->line;
188 cursal.pc = 0;
189 cursal.end = 0;
190
191 return cursal;
192 }
193
194 /* Reset any information stored about a default file and line to print. */
195
196 void
197 clear_current_source_symtab_and_line (void)
198 {
199 current_source_symtab = 0;
200 current_source_line = 0;
201 }
202
203 /* Set the source file default for the "list" command to be S.
204
205 If S is NULL, and we don't have a default, find one. This
206 should only be called when the user actually tries to use the
207 default, since we produce an error if we can't find a reasonable
208 default. Also, since this can cause symbols to be read, doing it
209 before we need to would make things slower than necessary. */
210
211 void
212 select_source_symtab (struct symtab *s)
213 {
214 struct symtabs_and_lines sals;
215 struct symtab_and_line sal;
216 struct partial_symtab *ps;
217 struct partial_symtab *cs_pst = 0;
218 struct objfile *ofp;
219
220 if (s)
221 {
222 current_source_symtab = s;
223 current_source_line = 1;
224 return;
225 }
226
227 if (current_source_symtab)
228 return;
229
230 /* Make the default place to list be the function `main'
231 if one exists. */
232 if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0, NULL))
233 {
234 sals = decode_line_spec (main_name (), 1);
235 sal = sals.sals[0];
236 xfree (sals.sals);
237 current_source_symtab = sal.symtab;
238 current_source_line = max (sal.line - (lines_to_list - 1), 1);
239 if (current_source_symtab)
240 return;
241 }
242
243 /* All right; find the last file in the symtab list (ignoring .h's). */
244
245 current_source_line = 1;
246
247 for (ofp = object_files; ofp != NULL; ofp = ofp->next)
248 {
249 for (s = ofp->symtabs; s; s = s->next)
250 {
251 const char *name = s->filename;
252 int len = strlen (name);
253 if (!(len > 2 && strcmp(&name[len - 2], ".h") == 0))
254 current_source_symtab = s;
255 }
256 }
257 if (current_source_symtab)
258 return;
259
260 /* Howabout the partial symbol tables? */
261
262 for (ofp = object_files; ofp != NULL; ofp = ofp->next)
263 {
264 for (ps = ofp->psymtabs; ps != NULL; ps = ps->next)
265 {
266 const char *name = ps->filename;
267 int len = strlen (name);
268 if (!(len > 2 && strcmp (&name[len - 2], ".h") == 0))
269 cs_pst = ps;
270 }
271 }
272 if (cs_pst)
273 {
274 if (cs_pst->readin)
275 {
276 internal_error (__FILE__, __LINE__,
277 _("select_source_symtab: "
278 "readin pst found and no symtabs."));
279 }
280 else
281 {
282 current_source_symtab = PSYMTAB_TO_SYMTAB (cs_pst);
283 }
284 }
285 if (current_source_symtab)
286 return;
287
288 error (_("Can't find a default source file"));
289 }
290 \f
291 static void
292 show_directories (char *ignore, int from_tty)
293 {
294 puts_filtered ("Source directories searched: ");
295 puts_filtered (source_path);
296 puts_filtered ("\n");
297 }
298
299 /* Forget what we learned about line positions in source files, and
300 which directories contain them; must check again now since files
301 may be found in a different directory now. */
302
303 void
304 forget_cached_source_info (void)
305 {
306 struct symtab *s;
307 struct objfile *objfile;
308 struct partial_symtab *pst;
309
310 for (objfile = object_files; objfile != NULL; objfile = objfile->next)
311 {
312 for (s = objfile->symtabs; s != NULL; s = s->next)
313 {
314 if (s->line_charpos != NULL)
315 {
316 xfree (s->line_charpos);
317 s->line_charpos = NULL;
318 }
319 if (s->fullname != NULL)
320 {
321 xfree (s->fullname);
322 s->fullname = NULL;
323 }
324 }
325
326 ALL_OBJFILE_PSYMTABS (objfile, pst)
327 {
328 if (pst->fullname != NULL)
329 {
330 xfree (pst->fullname);
331 pst->fullname = NULL;
332 }
333 }
334 }
335 }
336
337 void
338 init_source_path (void)
339 {
340 char buf[20];
341
342 sprintf (buf, "$cdir%c$cwd", DIRNAME_SEPARATOR);
343 source_path = xstrdup (buf);
344 forget_cached_source_info ();
345 }
346
347 void
348 init_last_source_visited (void)
349 {
350 last_source_visited = NULL;
351 }
352
353 /* Add zero or more directories to the front of the source path. */
354
355 void
356 directory_command (char *dirname, int from_tty)
357 {
358 dont_repeat ();
359 /* FIXME, this goes to "delete dir"... */
360 if (dirname == 0)
361 {
362 if (from_tty && query (_("Reinitialize source path to empty? ")))
363 {
364 xfree (source_path);
365 init_source_path ();
366 }
367 }
368 else
369 {
370 mod_path (dirname, &source_path);
371 last_source_visited = NULL;
372 }
373 if (from_tty)
374 show_directories ((char *) 0, from_tty);
375 forget_cached_source_info ();
376 }
377
378 /* Add a path given with the -d command line switch.
379 This will not be quoted so we must not treat spaces as separators. */
380
381 void
382 directory_switch (char *dirname, int from_tty)
383 {
384 add_path (dirname, &source_path, 0);
385 }
386
387 /* Add zero or more directories to the front of an arbitrary path. */
388
389 void
390 mod_path (char *dirname, char **which_path)
391 {
392 add_path (dirname, which_path, 1);
393 }
394
395 /* Workhorse of mod_path. Takes an extra argument to determine
396 if dirname should be parsed for separators that indicate multiple
397 directories. This allows for interfaces that pre-parse the dirname
398 and allow specification of traditional separator characters such
399 as space or tab. */
400
401 void
402 add_path (char *dirname, char **which_path, int parse_separators)
403 {
404 char *old = *which_path;
405 int prefix = 0;
406 char **argv = NULL;
407 char *arg;
408 int argv_index = 0;
409
410 if (dirname == 0)
411 return;
412
413 if (parse_separators)
414 {
415 /* This will properly parse the space and tab separators
416 and any quotes that may exist. DIRNAME_SEPARATOR will
417 be dealt with later. */
418 argv = buildargv (dirname);
419 make_cleanup_freeargv (argv);
420
421 if (argv == NULL)
422 nomem (0);
423
424 arg = argv[0];
425 }
426 else
427 {
428 arg = xstrdup (dirname);
429 make_cleanup (xfree, arg);
430 }
431
432 do
433 {
434 char *name = arg;
435 char *p;
436 struct stat st;
437
438 {
439 char *separator = NULL;
440
441 /* Spaces and tabs will have been removed by buildargv().
442 The directories will there be split into a list but
443 each entry may still contain DIRNAME_SEPARATOR. */
444 if (parse_separators)
445 separator = strchr (name, DIRNAME_SEPARATOR);
446
447 if (separator == 0)
448 p = arg = name + strlen (name);
449 else
450 {
451 p = separator;
452 arg = p + 1;
453 while (*arg == DIRNAME_SEPARATOR)
454 ++arg;
455 }
456
457 /* If there are no more directories in this argument then start
458 on the next argument next time round the loop (if any). */
459 if (*arg == '\0')
460 arg = parse_separators ? argv[++argv_index] : NULL;
461 }
462
463 /* name is the start of the directory.
464 p is the separator (or null) following the end. */
465
466 while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */
467 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
468 /* On MS-DOS and MS-Windows, h:\ is different from h: */
469 && !(p == name + 3 && name[1] == ':') /* "d:/" */
470 #endif
471 && IS_DIR_SEPARATOR (p[-1]))
472 /* Sigh. "foo/" => "foo" */
473 --p;
474 *p = '\0';
475
476 while (p > name && p[-1] == '.')
477 {
478 if (p - name == 1)
479 {
480 /* "." => getwd (). */
481 name = current_directory;
482 goto append;
483 }
484 else if (p > name + 1 && IS_DIR_SEPARATOR (p[-2]))
485 {
486 if (p - name == 2)
487 {
488 /* "/." => "/". */
489 *--p = '\0';
490 goto append;
491 }
492 else
493 {
494 /* "...foo/." => "...foo". */
495 p -= 2;
496 *p = '\0';
497 continue;
498 }
499 }
500 else
501 break;
502 }
503
504 if (name[0] == '~')
505 name = tilde_expand (name);
506 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
507 else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */
508 name = concat (name, ".", (char *)NULL);
509 #endif
510 else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$')
511 name = concat (current_directory, SLASH_STRING, name, (char *)NULL);
512 else
513 name = savestring (name, p - name);
514 make_cleanup (xfree, name);
515
516 /* Unless it's a variable, check existence. */
517 if (name[0] != '$')
518 {
519 /* These are warnings, not errors, since we don't want a
520 non-existent directory in a .gdbinit file to stop processing
521 of the .gdbinit file.
522
523 Whether they get added to the path is more debatable. Current
524 answer is yes, in case the user wants to go make the directory
525 or whatever. If the directory continues to not exist/not be
526 a directory/etc, then having them in the path should be
527 harmless. */
528 if (stat (name, &st) < 0)
529 {
530 int save_errno = errno;
531 fprintf_unfiltered (gdb_stderr, "Warning: ");
532 print_sys_errmsg (name, save_errno);
533 }
534 else if ((st.st_mode & S_IFMT) != S_IFDIR)
535 warning (_("%s is not a directory."), name);
536 }
537
538 append:
539 {
540 unsigned int len = strlen (name);
541
542 p = *which_path;
543 while (1)
544 {
545 /* FIXME: strncmp loses in interesting ways on MS-DOS and
546 MS-Windows because of case-insensitivity and two different
547 but functionally identical slash characters. We need a
548 special filesystem-dependent file-name comparison function.
549
550 Actually, even on Unix I would use realpath() or its work-
551 alike before comparing. Then all the code above which
552 removes excess slashes and dots could simply go away. */
553 if (!strncmp (p, name, len)
554 && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
555 {
556 /* Found it in the search path, remove old copy */
557 if (p > *which_path)
558 p--; /* Back over leading separator */
559 if (prefix > p - *which_path)
560 goto skip_dup; /* Same dir twice in one cmd */
561 strcpy (p, &p[len + 1]); /* Copy from next \0 or : */
562 }
563 p = strchr (p, DIRNAME_SEPARATOR);
564 if (p != 0)
565 ++p;
566 else
567 break;
568 }
569 if (p == 0)
570 {
571 char tinybuf[2];
572
573 tinybuf[0] = DIRNAME_SEPARATOR;
574 tinybuf[1] = '\0';
575
576 /* If we have already tacked on a name(s) in this command, be sure they stay
577 on the front as we tack on some more. */
578 if (prefix)
579 {
580 char *temp, c;
581
582 c = old[prefix];
583 old[prefix] = '\0';
584 temp = concat (old, tinybuf, name, (char *)NULL);
585 old[prefix] = c;
586 *which_path = concat (temp, "", &old[prefix], (char *)NULL);
587 prefix = strlen (temp);
588 xfree (temp);
589 }
590 else
591 {
592 *which_path = concat (name, (old[0] ? tinybuf : old),
593 old, (char *)NULL);
594 prefix = strlen (name);
595 }
596 xfree (old);
597 old = *which_path;
598 }
599 }
600 skip_dup:;
601 }
602 while (arg != NULL);
603 }
604
605
606 static void
607 source_info (char *ignore, int from_tty)
608 {
609 struct symtab *s = current_source_symtab;
610
611 if (!s)
612 {
613 printf_filtered (_("No current source file.\n"));
614 return;
615 }
616 printf_filtered (_("Current source file is %s\n"), s->filename);
617 if (s->dirname)
618 printf_filtered (_("Compilation directory is %s\n"), s->dirname);
619 if (s->fullname)
620 printf_filtered (_("Located in %s\n"), s->fullname);
621 if (s->nlines)
622 printf_filtered (_("Contains %d line%s.\n"), s->nlines,
623 s->nlines == 1 ? "" : "s");
624
625 printf_filtered (_("Source language is %s.\n"), language_str (s->language));
626 printf_filtered (_("Compiled with %s debugging format.\n"), s->debugformat);
627 printf_filtered (_("%s preprocessor macro info.\n"),
628 s->macro_table ? "Includes" : "Does not include");
629 }
630 \f
631
632 /* Return True if the file NAME exists and is a regular file */
633 static int
634 is_regular_file (const char *name)
635 {
636 struct stat st;
637 const int status = stat (name, &st);
638
639 /* Stat should never fail except when the file does not exist.
640 If stat fails, analyze the source of error and return True
641 unless the file does not exist, to avoid returning false results
642 on obscure systems where stat does not work as expected.
643 */
644 if (status != 0)
645 return (errno != ENOENT);
646
647 return S_ISREG (st.st_mode);
648 }
649
650 /* Open a file named STRING, searching path PATH (dir names sep by some char)
651 using mode MODE and protection bits PROT in the calls to open.
652
653 OPTS specifies the function behaviour in specific cases.
654
655 If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
656 (ie pretend the first element of PATH is "."). This also indicates
657 that a slash in STRING disables searching of the path (this is
658 so that "exec-file ./foo" or "symbol-file ./foo" insures that you
659 get that particular version of foo or an error message).
660
661 If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
662 searched in path (we usually want this for source files but not for
663 executables).
664
665 If FILENAME_OPENED is non-null, set it to a newly allocated string naming
666 the actual file opened (this string will always start with a "/"). We
667 have to take special pains to avoid doubling the "/" between the directory
668 and the file, sigh! Emacs gets confuzzed by this when we print the
669 source file name!!!
670
671 If a file is found, return the descriptor.
672 Otherwise, return -1, with errno set for the last name we tried to open. */
673
674 /* >>>> This should only allow files of certain types,
675 >>>> eg executable, non-directory */
676 int
677 openp (const char *path, int opts, const char *string,
678 int mode, int prot,
679 char **filename_opened)
680 {
681 int fd;
682 char *filename;
683 const char *p;
684 const char *p1;
685 int len;
686 int alloclen;
687
688 if (!path)
689 path = ".";
690
691 mode |= O_BINARY;
692
693 if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string))
694 {
695 int i;
696
697 if (is_regular_file (string))
698 {
699 filename = alloca (strlen (string) + 1);
700 strcpy (filename, string);
701 fd = open (filename, mode, prot);
702 if (fd >= 0)
703 goto done;
704 }
705 else
706 {
707 filename = NULL;
708 fd = -1;
709 }
710
711 if (!(opts & OPF_SEARCH_IN_PATH))
712 for (i = 0; string[i]; i++)
713 if (IS_DIR_SEPARATOR (string[i]))
714 goto done;
715 }
716
717 /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
718 while (IS_DIR_SEPARATOR(string[0]))
719 string++;
720
721 /* ./foo => foo */
722 while (string[0] == '.' && IS_DIR_SEPARATOR (string[1]))
723 string += 2;
724
725 alloclen = strlen (path) + strlen (string) + 2;
726 filename = alloca (alloclen);
727 fd = -1;
728 for (p = path; p; p = p1 ? p1 + 1 : 0)
729 {
730 p1 = strchr (p, DIRNAME_SEPARATOR);
731 if (p1)
732 len = p1 - p;
733 else
734 len = strlen (p);
735
736 if (len == 4 && p[0] == '$' && p[1] == 'c'
737 && p[2] == 'w' && p[3] == 'd')
738 {
739 /* Name is $cwd -- insert current directory name instead. */
740 int newlen;
741
742 /* First, realloc the filename buffer if too short. */
743 len = strlen (current_directory);
744 newlen = len + strlen (string) + 2;
745 if (newlen > alloclen)
746 {
747 alloclen = newlen;
748 filename = alloca (alloclen);
749 }
750 strcpy (filename, current_directory);
751 }
752 else
753 {
754 /* Normal file name in path -- just use it. */
755 strncpy (filename, p, len);
756 filename[len] = 0;
757 }
758
759 /* Remove trailing slashes */
760 while (len > 0 && IS_DIR_SEPARATOR (filename[len - 1]))
761 filename[--len] = 0;
762
763 strcat (filename + len, SLASH_STRING);
764 strcat (filename, string);
765
766 if (is_regular_file (filename))
767 {
768 fd = open (filename, mode);
769 if (fd >= 0)
770 break;
771 }
772 }
773
774 done:
775 if (filename_opened)
776 {
777 /* If a file was opened, canonicalize its filename. Use xfullpath
778 rather than gdb_realpath to avoid resolving the basename part
779 of filenames when the associated file is a symbolic link. This
780 fixes a potential inconsistency between the filenames known to
781 GDB and the filenames it prints in the annotations. */
782 if (fd < 0)
783 *filename_opened = NULL;
784 else if (IS_ABSOLUTE_PATH (filename))
785 *filename_opened = xfullpath (filename);
786 else
787 {
788 /* Beware the // my son, the Emacs barfs, the botch that catch... */
789
790 char *f = concat (current_directory,
791 IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
792 ? "" : SLASH_STRING,
793 filename, (char *)NULL);
794 *filename_opened = xfullpath (f);
795 xfree (f);
796 }
797 }
798
799 return fd;
800 }
801
802
803 /* This is essentially a convenience, for clients that want the behaviour
804 of openp, using source_path, but that really don't want the file to be
805 opened but want instead just to know what the full pathname is (as
806 qualified against source_path).
807
808 The current working directory is searched first.
809
810 If the file was found, this function returns 1, and FULL_PATHNAME is
811 set to the fully-qualified pathname.
812
813 Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */
814 int
815 source_full_path_of (char *filename, char **full_pathname)
816 {
817 int fd;
818
819 fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename,
820 O_RDONLY, 0, full_pathname);
821 if (fd < 0)
822 {
823 *full_pathname = NULL;
824 return 0;
825 }
826
827 close (fd);
828 return 1;
829 }
830
831 /* This function is capable of finding the absolute path to a
832 source file, and opening it, provided you give it an
833 OBJFILE and FILENAME. Both the DIRNAME and FULLNAME are only
834 added suggestions on where to find the file.
835
836 OBJFILE should be the objfile associated with a psymtab or symtab.
837 FILENAME should be the filename to open.
838 DIRNAME is the compilation directory of a particular source file.
839 Only some debug formats provide this info.
840 FULLNAME can be the last known absolute path to the file in question.
841
842 On Success
843 A valid file descriptor is returned. ( the return value is positive )
844 FULLNAME is set to the absolute path to the file just opened.
845
846 On Failure
847 A non valid file descriptor is returned. ( the return value is negitive )
848 FULLNAME is set to NULL. */
849 int
850 find_and_open_source (struct objfile *objfile,
851 const char *filename,
852 const char *dirname,
853 char **fullname)
854 {
855 char *path = source_path;
856 const char *p;
857 int result;
858
859 /* Quick way out if we already know its full name */
860 if (*fullname)
861 {
862 result = open (*fullname, OPEN_MODE);
863 if (result >= 0)
864 return result;
865 /* Didn't work -- free old one, try again. */
866 xfree (*fullname);
867 *fullname = NULL;
868 }
869
870 if (dirname != NULL)
871 {
872 /* Replace a path entry of $cdir with the compilation directory name */
873 #define cdir_len 5
874 /* We cast strstr's result in case an ANSIhole has made it const,
875 which produces a "required warning" when assigned to a nonconst. */
876 p = (char *) strstr (source_path, "$cdir");
877 if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)
878 && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0'))
879 {
880 int len;
881
882 path = (char *)
883 alloca (strlen (source_path) + 1 + strlen (dirname) + 1);
884 len = p - source_path;
885 strncpy (path, source_path, len); /* Before $cdir */
886 strcpy (path + len, dirname); /* new stuff */
887 strcat (path + len, source_path + len + cdir_len); /* After $cdir */
888 }
889 }
890
891 result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, 0, fullname);
892 if (result < 0)
893 {
894 /* Didn't work. Try using just the basename. */
895 p = lbasename (filename);
896 if (p != filename)
897 result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname);
898 }
899
900 if (result >= 0)
901 {
902 char *tmp_fullname;
903 tmp_fullname = *fullname;
904 *fullname = xstrdup (tmp_fullname);
905 xfree (tmp_fullname);
906 }
907 return result;
908 }
909
910 /* Open a source file given a symtab S. Returns a file descriptor or
911 negative number for error.
912
913 This function is a convience function to find_and_open_source. */
914
915 int
916 open_source_file (struct symtab *s)
917 {
918 if (!s)
919 return -1;
920
921 return find_and_open_source (s->objfile, s->filename, s->dirname,
922 &s->fullname);
923 }
924
925 /* Finds the fullname that a symtab represents.
926
927 If this functions finds the fullname, it will save it in ps->fullname
928 and it will also return the value.
929
930 If this function fails to find the file that this symtab represents,
931 NULL will be returned and ps->fullname will be set to NULL. */
932 char *
933 symtab_to_fullname (struct symtab *s)
934 {
935 int r;
936
937 if (!s)
938 return NULL;
939
940 /* Don't check s->fullname here, the file could have been
941 deleted/moved/..., look for it again */
942 r = find_and_open_source (s->objfile, s->filename, s->dirname,
943 &s->fullname);
944
945 if (r)
946 {
947 close (r);
948 return s->fullname;
949 }
950
951 return NULL;
952 }
953
954 /* Finds the fullname that a partial_symtab represents.
955
956 If this functions finds the fullname, it will save it in ps->fullname
957 and it will also return the value.
958
959 If this function fails to find the file that this partial_symtab represents,
960 NULL will be returned and ps->fullname will be set to NULL. */
961 char *
962 psymtab_to_fullname (struct partial_symtab *ps)
963 {
964 int r;
965
966 if (!ps)
967 return NULL;
968
969 /* Don't check ps->fullname here, the file could have been
970 deleted/moved/..., look for it again */
971 r = find_and_open_source (ps->objfile, ps->filename, ps->dirname,
972 &ps->fullname);
973
974 if (r)
975 {
976 close (r);
977 return ps->fullname;
978 }
979
980 return NULL;
981 }
982 \f
983 /* Create and initialize the table S->line_charpos that records
984 the positions of the lines in the source file, which is assumed
985 to be open on descriptor DESC.
986 All set S->nlines to the number of such lines. */
987
988 void
989 find_source_lines (struct symtab *s, int desc)
990 {
991 struct stat st;
992 char *data, *p, *end;
993 int nlines = 0;
994 int lines_allocated = 1000;
995 int *line_charpos;
996 long mtime = 0;
997 int size;
998
999 line_charpos = (int *) xmalloc (lines_allocated * sizeof (int));
1000 if (fstat (desc, &st) < 0)
1001 perror_with_name (s->filename);
1002
1003 if (s && s->objfile && s->objfile->obfd)
1004 mtime = bfd_get_mtime (s->objfile->obfd);
1005 else if (exec_bfd)
1006 mtime = bfd_get_mtime (exec_bfd);
1007
1008 if (mtime && mtime < st.st_mtime)
1009 warning (_("Source file is more recent than executable."));
1010
1011 #ifdef LSEEK_NOT_LINEAR
1012 {
1013 char c;
1014
1015 /* Have to read it byte by byte to find out where the chars live */
1016
1017 line_charpos[0] = lseek (desc, 0, SEEK_CUR);
1018 nlines = 1;
1019 while (myread (desc, &c, 1) > 0)
1020 {
1021 if (c == '\n')
1022 {
1023 if (nlines == lines_allocated)
1024 {
1025 lines_allocated *= 2;
1026 line_charpos =
1027 (int *) xrealloc ((char *) line_charpos,
1028 sizeof (int) * lines_allocated);
1029 }
1030 line_charpos[nlines++] = lseek (desc, 0, SEEK_CUR);
1031 }
1032 }
1033 }
1034 #else /* lseek linear. */
1035 {
1036 struct cleanup *old_cleanups;
1037
1038 /* st_size might be a large type, but we only support source files whose
1039 size fits in an int. */
1040 size = (int) st.st_size;
1041
1042 /* Use malloc, not alloca, because this may be pretty large, and we may
1043 run into various kinds of limits on stack size. */
1044 data = (char *) xmalloc (size);
1045 old_cleanups = make_cleanup (xfree, data);
1046
1047 /* Reassign `size' to result of read for systems where \r\n -> \n. */
1048 size = myread (desc, data, size);
1049 if (size < 0)
1050 perror_with_name (s->filename);
1051 end = data + size;
1052 p = data;
1053 line_charpos[0] = 0;
1054 nlines = 1;
1055 while (p != end)
1056 {
1057 if (*p++ == '\n'
1058 /* A newline at the end does not start a new line. */
1059 && p != end)
1060 {
1061 if (nlines == lines_allocated)
1062 {
1063 lines_allocated *= 2;
1064 line_charpos =
1065 (int *) xrealloc ((char *) line_charpos,
1066 sizeof (int) * lines_allocated);
1067 }
1068 line_charpos[nlines++] = p - data;
1069 }
1070 }
1071 do_cleanups (old_cleanups);
1072 }
1073 #endif /* lseek linear. */
1074 s->nlines = nlines;
1075 s->line_charpos =
1076 (int *) xrealloc ((char *) line_charpos, nlines * sizeof (int));
1077
1078 }
1079
1080 /* Return the character position of a line LINE in symtab S.
1081 Return 0 if anything is invalid. */
1082
1083 #if 0 /* Currently unused */
1084
1085 int
1086 source_line_charpos (struct symtab *s, int line)
1087 {
1088 if (!s)
1089 return 0;
1090 if (!s->line_charpos || line <= 0)
1091 return 0;
1092 if (line > s->nlines)
1093 line = s->nlines;
1094 return s->line_charpos[line - 1];
1095 }
1096
1097 /* Return the line number of character position POS in symtab S. */
1098
1099 int
1100 source_charpos_line (struct symtab *s, int chr)
1101 {
1102 int line = 0;
1103 int *lnp;
1104
1105 if (s == 0 || s->line_charpos == 0)
1106 return 0;
1107 lnp = s->line_charpos;
1108 /* Files are usually short, so sequential search is Ok */
1109 while (line < s->nlines && *lnp <= chr)
1110 {
1111 line++;
1112 lnp++;
1113 }
1114 if (line >= s->nlines)
1115 line = s->nlines;
1116 return line;
1117 }
1118
1119 #endif /* 0 */
1120 \f
1121
1122 /* Get full pathname and line number positions for a symtab.
1123 Return nonzero if line numbers may have changed.
1124 Set *FULLNAME to actual name of the file as found by `openp',
1125 or to 0 if the file is not found. */
1126
1127 static int
1128 get_filename_and_charpos (struct symtab *s, char **fullname)
1129 {
1130 int desc, linenums_changed = 0;
1131
1132 desc = open_source_file (s);
1133 if (desc < 0)
1134 {
1135 if (fullname)
1136 *fullname = NULL;
1137 return 0;
1138 }
1139 if (fullname)
1140 *fullname = s->fullname;
1141 if (s->line_charpos == 0)
1142 linenums_changed = 1;
1143 if (linenums_changed)
1144 find_source_lines (s, desc);
1145 close (desc);
1146 return linenums_changed;
1147 }
1148
1149 /* Print text describing the full name of the source file S
1150 and the line number LINE and its corresponding character position.
1151 The text starts with two Ctrl-z so that the Emacs-GDB interface
1152 can easily find it.
1153
1154 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
1155
1156 Return 1 if successful, 0 if could not find the file. */
1157
1158 int
1159 identify_source_line (struct symtab *s, int line, int mid_statement,
1160 CORE_ADDR pc)
1161 {
1162 if (s->line_charpos == 0)
1163 get_filename_and_charpos (s, (char **) NULL);
1164 if (s->fullname == 0)
1165 return 0;
1166 if (line > s->nlines)
1167 /* Don't index off the end of the line_charpos array. */
1168 return 0;
1169 annotate_source (s->fullname, line, s->line_charpos[line - 1],
1170 mid_statement, pc);
1171
1172 current_source_line = line;
1173 first_line_listed = line;
1174 last_line_listed = line;
1175 current_source_symtab = s;
1176 return 1;
1177 }
1178 \f
1179
1180 /* Print source lines from the file of symtab S,
1181 starting with line number LINE and stopping before line number STOPLINE. */
1182
1183 static void print_source_lines_base (struct symtab *s, int line, int stopline,
1184 int noerror);
1185 static void
1186 print_source_lines_base (struct symtab *s, int line, int stopline, int noerror)
1187 {
1188 int c;
1189 int desc;
1190 FILE *stream;
1191 int nlines = stopline - line;
1192
1193 /* Regardless of whether we can open the file, set current_source_symtab. */
1194 current_source_symtab = s;
1195 current_source_line = line;
1196 first_line_listed = line;
1197
1198 /* If printing of source lines is disabled, just print file and line number */
1199 if (ui_out_test_flags (uiout, ui_source_list))
1200 {
1201 /* Only prints "No such file or directory" once */
1202 if ((s != last_source_visited) || (!last_source_error))
1203 {
1204 last_source_visited = s;
1205 desc = open_source_file (s);
1206 }
1207 else
1208 {
1209 desc = last_source_error;
1210 noerror = 1;
1211 }
1212 }
1213 else
1214 {
1215 desc = -1;
1216 noerror = 1;
1217 }
1218
1219 if (desc < 0)
1220 {
1221 last_source_error = desc;
1222
1223 if (!noerror)
1224 {
1225 char *name = alloca (strlen (s->filename) + 100);
1226 sprintf (name, "%d\t%s", line, s->filename);
1227 print_sys_errmsg (name, errno);
1228 }
1229 else
1230 ui_out_field_int (uiout, "line", line);
1231 ui_out_text (uiout, "\tin ");
1232 ui_out_field_string (uiout, "file", s->filename);
1233 ui_out_text (uiout, "\n");
1234
1235 return;
1236 }
1237
1238 last_source_error = 0;
1239
1240 if (s->line_charpos == 0)
1241 find_source_lines (s, desc);
1242
1243 if (line < 1 || line > s->nlines)
1244 {
1245 close (desc);
1246 error (_("Line number %d out of range; %s has %d lines."),
1247 line, s->filename, s->nlines);
1248 }
1249
1250 if (lseek (desc, s->line_charpos[line - 1], 0) < 0)
1251 {
1252 close (desc);
1253 perror_with_name (s->filename);
1254 }
1255
1256 stream = fdopen (desc, FDOPEN_MODE);
1257 clearerr (stream);
1258
1259 while (nlines-- > 0)
1260 {
1261 char buf[20];
1262
1263 c = fgetc (stream);
1264 if (c == EOF)
1265 break;
1266 last_line_listed = current_source_line;
1267 sprintf (buf, "%d\t", current_source_line++);
1268 ui_out_text (uiout, buf);
1269 do
1270 {
1271 if (c < 040 && c != '\t' && c != '\n' && c != '\r')
1272 {
1273 sprintf (buf, "^%c", c + 0100);
1274 ui_out_text (uiout, buf);
1275 }
1276 else if (c == 0177)
1277 ui_out_text (uiout, "^?");
1278 else if (c == '\r')
1279 {
1280 /* Skip a \r character, but only before a \n. */
1281 int c1 = fgetc (stream);
1282
1283 if (c1 != '\n')
1284 printf_filtered ("^%c", c + 0100);
1285 if (c1 != EOF)
1286 ungetc (c1, stream);
1287 }
1288 else
1289 {
1290 sprintf (buf, "%c", c);
1291 ui_out_text (uiout, buf);
1292 }
1293 }
1294 while (c != '\n' && (c = fgetc (stream)) >= 0);
1295 }
1296
1297 fclose (stream);
1298 }
1299 \f
1300 /* Show source lines from the file of symtab S, starting with line
1301 number LINE and stopping before line number STOPLINE. If this is the
1302 not the command line version, then the source is shown in the source
1303 window otherwise it is simply printed */
1304
1305 void
1306 print_source_lines (struct symtab *s, int line, int stopline, int noerror)
1307 {
1308 print_source_lines_base (s, line, stopline, noerror);
1309 }
1310 \f
1311 /* Print info on range of pc's in a specified line. */
1312
1313 static void
1314 line_info (char *arg, int from_tty)
1315 {
1316 struct symtabs_and_lines sals;
1317 struct symtab_and_line sal;
1318 CORE_ADDR start_pc, end_pc;
1319 int i;
1320
1321 init_sal (&sal); /* initialize to zeroes */
1322
1323 if (arg == 0)
1324 {
1325 sal.symtab = current_source_symtab;
1326 sal.line = last_line_listed;
1327 sals.nelts = 1;
1328 sals.sals = (struct symtab_and_line *)
1329 xmalloc (sizeof (struct symtab_and_line));
1330 sals.sals[0] = sal;
1331 }
1332 else
1333 {
1334 sals = decode_line_spec_1 (arg, 0);
1335
1336 dont_repeat ();
1337 }
1338
1339 /* C++ More than one line may have been specified, as when the user
1340 specifies an overloaded function name. Print info on them all. */
1341 for (i = 0; i < sals.nelts; i++)
1342 {
1343 sal = sals.sals[i];
1344
1345 if (sal.symtab == 0)
1346 {
1347 printf_filtered (_("No line number information available"));
1348 if (sal.pc != 0)
1349 {
1350 /* This is useful for "info line *0x7f34". If we can't tell the
1351 user about a source line, at least let them have the symbolic
1352 address. */
1353 printf_filtered (" for address ");
1354 wrap_here (" ");
1355 print_address (sal.pc, gdb_stdout);
1356 }
1357 else
1358 printf_filtered (".");
1359 printf_filtered ("\n");
1360 }
1361 else if (sal.line > 0
1362 && find_line_pc_range (sal, &start_pc, &end_pc))
1363 {
1364 if (start_pc == end_pc)
1365 {
1366 printf_filtered ("Line %d of \"%s\"",
1367 sal.line, sal.symtab->filename);
1368 wrap_here (" ");
1369 printf_filtered (" is at address ");
1370 print_address (start_pc, gdb_stdout);
1371 wrap_here (" ");
1372 printf_filtered (" but contains no code.\n");
1373 }
1374 else
1375 {
1376 printf_filtered ("Line %d of \"%s\"",
1377 sal.line, sal.symtab->filename);
1378 wrap_here (" ");
1379 printf_filtered (" starts at address ");
1380 print_address (start_pc, gdb_stdout);
1381 wrap_here (" ");
1382 printf_filtered (" and ends at ");
1383 print_address (end_pc, gdb_stdout);
1384 printf_filtered (".\n");
1385 }
1386
1387 /* x/i should display this line's code. */
1388 set_next_address (start_pc);
1389
1390 /* Repeating "info line" should do the following line. */
1391 last_line_listed = sal.line + 1;
1392
1393 /* If this is the only line, show the source code. If it could
1394 not find the file, don't do anything special. */
1395 if (annotation_level && sals.nelts == 1)
1396 identify_source_line (sal.symtab, sal.line, 0, start_pc);
1397 }
1398 else
1399 /* Is there any case in which we get here, and have an address
1400 which the user would want to see? If we have debugging symbols
1401 and no line numbers? */
1402 printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
1403 sal.line, sal.symtab->filename);
1404 }
1405 xfree (sals.sals);
1406 }
1407 \f
1408 /* Commands to search the source file for a regexp. */
1409
1410 static void
1411 forward_search_command (char *regex, int from_tty)
1412 {
1413 int c;
1414 int desc;
1415 FILE *stream;
1416 int line;
1417 char *msg;
1418
1419 line = last_line_listed + 1;
1420
1421 msg = (char *) re_comp (regex);
1422 if (msg)
1423 error (("%s"), msg);
1424
1425 if (current_source_symtab == 0)
1426 select_source_symtab (0);
1427
1428 desc = open_source_file (current_source_symtab);
1429 if (desc < 0)
1430 perror_with_name (current_source_symtab->filename);
1431
1432 if (current_source_symtab->line_charpos == 0)
1433 find_source_lines (current_source_symtab, desc);
1434
1435 if (line < 1 || line > current_source_symtab->nlines)
1436 {
1437 close (desc);
1438 error (_("Expression not found"));
1439 }
1440
1441 if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
1442 {
1443 close (desc);
1444 perror_with_name (current_source_symtab->filename);
1445 }
1446
1447 stream = fdopen (desc, FDOPEN_MODE);
1448 clearerr (stream);
1449 while (1)
1450 {
1451 static char *buf = NULL;
1452 char *p;
1453 int cursize, newsize;
1454
1455 cursize = 256;
1456 buf = xmalloc (cursize);
1457 p = buf;
1458
1459 c = getc (stream);
1460 if (c == EOF)
1461 break;
1462 do
1463 {
1464 *p++ = c;
1465 if (p - buf == cursize)
1466 {
1467 newsize = cursize + cursize / 2;
1468 buf = xrealloc (buf, newsize);
1469 p = buf + cursize;
1470 cursize = newsize;
1471 }
1472 }
1473 while (c != '\n' && (c = getc (stream)) >= 0);
1474
1475 /* Remove the \r, if any, at the end of the line, otherwise
1476 regular expressions that end with $ or \n won't work. */
1477 if (p - buf > 1 && p[-2] == '\r')
1478 {
1479 p--;
1480 p[-1] = '\n';
1481 }
1482
1483 /* we now have a source line in buf, null terminate and match */
1484 *p = 0;
1485 if (re_exec (buf) > 0)
1486 {
1487 /* Match! */
1488 fclose (stream);
1489 print_source_lines (current_source_symtab, line, line + 1, 0);
1490 set_internalvar (lookup_internalvar ("_"),
1491 value_from_longest (builtin_type_int,
1492 (LONGEST) line));
1493 current_source_line = max (line - lines_to_list / 2, 1);
1494 return;
1495 }
1496 line++;
1497 }
1498
1499 printf_filtered (_("Expression not found\n"));
1500 fclose (stream);
1501 }
1502
1503 static void
1504 reverse_search_command (char *regex, int from_tty)
1505 {
1506 int c;
1507 int desc;
1508 FILE *stream;
1509 int line;
1510 char *msg;
1511
1512 line = last_line_listed - 1;
1513
1514 msg = (char *) re_comp (regex);
1515 if (msg)
1516 error (("%s"), msg);
1517
1518 if (current_source_symtab == 0)
1519 select_source_symtab (0);
1520
1521 desc = open_source_file (current_source_symtab);
1522 if (desc < 0)
1523 perror_with_name (current_source_symtab->filename);
1524
1525 if (current_source_symtab->line_charpos == 0)
1526 find_source_lines (current_source_symtab, desc);
1527
1528 if (line < 1 || line > current_source_symtab->nlines)
1529 {
1530 close (desc);
1531 error (_("Expression not found"));
1532 }
1533
1534 if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
1535 {
1536 close (desc);
1537 perror_with_name (current_source_symtab->filename);
1538 }
1539
1540 stream = fdopen (desc, FDOPEN_MODE);
1541 clearerr (stream);
1542 while (line > 1)
1543 {
1544 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1545 char buf[4096]; /* Should be reasonable??? */
1546 char *p = buf;
1547
1548 c = getc (stream);
1549 if (c == EOF)
1550 break;
1551 do
1552 {
1553 *p++ = c;
1554 }
1555 while (c != '\n' && (c = getc (stream)) >= 0);
1556
1557 /* Remove the \r, if any, at the end of the line, otherwise
1558 regular expressions that end with $ or \n won't work. */
1559 if (p - buf > 1 && p[-2] == '\r')
1560 {
1561 p--;
1562 p[-1] = '\n';
1563 }
1564
1565 /* We now have a source line in buf; null terminate and match. */
1566 *p = 0;
1567 if (re_exec (buf) > 0)
1568 {
1569 /* Match! */
1570 fclose (stream);
1571 print_source_lines (current_source_symtab, line, line + 1, 0);
1572 set_internalvar (lookup_internalvar ("_"),
1573 value_from_longest (builtin_type_int,
1574 (LONGEST) line));
1575 current_source_line = max (line - lines_to_list / 2, 1);
1576 return;
1577 }
1578 line--;
1579 if (fseek (stream, current_source_symtab->line_charpos[line - 1], 0) < 0)
1580 {
1581 fclose (stream);
1582 perror_with_name (current_source_symtab->filename);
1583 }
1584 }
1585
1586 printf_filtered (_("Expression not found\n"));
1587 fclose (stream);
1588 return;
1589 }
1590 \f
1591 void
1592 _initialize_source (void)
1593 {
1594 struct cmd_list_element *c;
1595 current_source_symtab = 0;
1596 init_source_path ();
1597
1598 /* The intention is to use POSIX Basic Regular Expressions.
1599 Always use the GNU regex routine for consistency across all hosts.
1600 Our current GNU regex.c does not have all the POSIX features, so this is
1601 just an approximation. */
1602 re_set_syntax (RE_SYNTAX_GREP);
1603
1604 c = add_cmd ("directory", class_files, directory_command, _("\
1605 Add directory DIR to beginning of search path for source files.\n\
1606 Forget cached info on source file locations and line positions.\n\
1607 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1608 directory in which the source file was compiled into object code.\n\
1609 With no argument, reset the search path to $cdir:$cwd, the default."),
1610 &cmdlist);
1611
1612 if (dbx_commands)
1613 add_com_alias ("use", "directory", class_files, 0);
1614
1615 set_cmd_completer (c, filename_completer);
1616
1617 add_cmd ("directories", no_class, show_directories, _("\
1618 Current search path for finding source files.\n\
1619 $cwd in the path means the current working directory.\n\
1620 $cdir in the path means the compilation directory of the source file."),
1621 &showlist);
1622
1623 if (xdb_commands)
1624 {
1625 add_com_alias ("D", "directory", class_files, 0);
1626 add_cmd ("ld", no_class, show_directories, _("\
1627 Current search path for finding source files.\n\
1628 $cwd in the path means the current working directory.\n\
1629 $cdir in the path means the compilation directory of the source file."),
1630 &cmdlist);
1631 }
1632
1633 add_info ("source", source_info,
1634 _("Information about the current source file."));
1635
1636 add_info ("line", line_info, _("\
1637 Core addresses of the code for a source line.\n\
1638 Line can be specified as\n\
1639 LINENUM, to list around that line in current file,\n\
1640 FILE:LINENUM, to list around that line in that file,\n\
1641 FUNCTION, to list around beginning of that function,\n\
1642 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1643 Default is to describe the last source line that was listed.\n\n\
1644 This sets the default address for \"x\" to the line's first instruction\n\
1645 so that \"x/i\" suffices to start examining the machine code.\n\
1646 The address is also stored as the value of \"$_\"."));
1647
1648 add_com ("forward-search", class_files, forward_search_command, _("\
1649 Search for regular expression (see regex(3)) from last line listed.\n\
1650 The matching line number is also stored as the value of \"$_\"."));
1651 add_com_alias ("search", "forward-search", class_files, 0);
1652
1653 add_com ("reverse-search", class_files, reverse_search_command, _("\
1654 Search backward for regular expression (see regex(3)) from last line listed.\n\
1655 The matching line number is also stored as the value of \"$_\"."));
1656
1657 if (xdb_commands)
1658 {
1659 add_com_alias ("/", "forward-search", class_files, 0);
1660 add_com_alias ("?", "reverse-search", class_files, 0);
1661 }
1662
1663 add_setshow_integer_cmd ("listsize", class_support, &lines_to_list, _("\
1664 Set number of source lines gdb will list by default."), _("\
1665 Show number of source lines gdb will list by default."), NULL,
1666 NULL,
1667 show_lines_to_list,
1668 &setlist, &showlist);
1669 }
This page took 0.06378 seconds and 5 git commands to generate.