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