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