1 /* List lines of source files for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "expression.h"
29 #include <sys/types.h>
33 #include <sys/param.h>
40 /* Prototypes for local functions. */
43 open_source_file
PARAMS ((struct symtab
*));
46 get_filename_and_charpos
PARAMS ((struct symtab
*, char **));
49 reverse_search_command
PARAMS ((char *, int));
52 forward_search_command
PARAMS ((char *, int));
55 line_info
PARAMS ((char *, int));
58 list_command
PARAMS ((char *, int));
61 ambiguous_line_spec
PARAMS ((struct symtabs_and_lines
*));
64 source_info
PARAMS ((void));
67 show_directories
PARAMS ((void));
70 find_source_lines
PARAMS ((struct symtab
*, int));
72 /* If we use this declaration, it breaks because of fucking ANSI "const" stuff
73 on some systems. We just have to not declare it at all, have it default
74 to int, and possibly botch on a few systems. Thanks, ANSIholes... */
75 /* extern char *strstr(); */
77 /* Path of directories to search for source files.
78 Same format as the PATH environment variable's value. */
82 /* Symtab of default file for listing lines of. */
84 struct symtab
*current_source_symtab
;
86 /* Default next line to list. */
88 int current_source_line
;
90 /* Default number of lines to print with commands like "list".
91 This is based on guessing how many long (i.e. more than chars_per_line
92 characters) lines there will be. To be completely correct, "list"
93 and friends should be rewritten to count characters and see where
94 things are wrapping, but that would be a fair amount of work. */
96 int lines_to_list
= 10;
98 /* Line number of last line printed. Default for various commands.
99 current_source_line is usually, but not always, the same as this. */
101 static int last_line_listed
;
103 /* First line number listed by last listing command. */
105 static int first_line_listed
;
108 /* Set the source file default for the "list" command, specifying a
109 symtab. Sigh. Behavior specification: If it is called with a
110 non-zero argument, that is the symtab to select. If it is not,
111 first lookup "main"; if it exists, use the symtab and line it
112 defines. If not, take the last symtab in the symtab lists (if it
113 exists) or the last symtab in the psymtab lists (if *it* exists). If
114 none of this works, report an error. */
117 select_source_symtab (s
)
118 register struct symtab
*s
;
120 struct symtabs_and_lines sals
;
121 struct symtab_and_line sal
;
122 struct partial_symtab
*ps
;
123 struct partial_symtab
*cs_pst
= 0;
128 current_source_symtab
= s
;
129 current_source_line
= 1;
133 /* Make the default place to list be the function `main'
135 if (lookup_symbol ("main", 0, VAR_NAMESPACE
, 0, NULL
))
137 sals
= decode_line_spec ("main", 1);
140 current_source_symtab
= sal
.symtab
;
141 current_source_line
= max (sal
.line
- (lines_to_list
- 1), 1);
142 if (current_source_symtab
)
146 /* All right; find the last file in the symtab list (ignoring .h's). */
148 current_source_line
= 1;
150 for (ofp
= object_files
; ofp
!= NULL
; ofp
= ofp
-> next
)
152 for (s
= ofp
-> symtabs
; s
; s
= s
->next
)
154 char *name
= s
-> filename
;
155 int len
= strlen (name
);
156 if (! (len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0)))
158 current_source_symtab
= s
;
162 if (current_source_symtab
)
165 /* Howabout the partial symbol tables? */
167 for (ofp
= object_files
; ofp
!= NULL
; ofp
= ofp
-> next
)
169 for (ps
= ofp
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
171 char *name
= ps
-> filename
;
172 int len
= strlen (name
);
173 if (! (len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0)))
181 if (cs_pst
-> readin
)
183 fatal ("Internal: select_source_symtab: readin pst found and no symtabs.");
187 current_source_symtab
= PSYMTAB_TO_SYMTAB (cs_pst
);
191 if (current_source_symtab
)
194 error ("Can't find a default source file");
200 printf ("Source directories searched: %s\n", source_path
);
203 /* Forget what we learned about line positions in source files,
204 and which directories contain them;
205 must check again now since files may be found in
206 a different directory now. */
209 forget_cached_source_info ()
211 register struct symtab
*s
;
212 register struct objfile
*objfile
;
214 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
216 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
218 if (s
-> line_charpos
!= NULL
)
220 mfree (objfile
-> md
, s
-> line_charpos
);
221 s
-> line_charpos
= NULL
;
223 if (s
-> fullname
!= NULL
)
225 mfree (objfile
-> md
, s
-> fullname
);
226 s
-> fullname
= NULL
;
235 source_path
= savestring ("$cdir:$cwd", /* strlen of it */ 10);
236 forget_cached_source_info ();
239 /* Add zero or more directories to the front of the source path. */
242 directory_command (dirname
, from_tty
)
247 /* FIXME, this goes to "delete dir"... */
250 if (query ("Reinitialize source path to empty? ", ""))
257 mod_path (dirname
, &source_path
);
260 forget_cached_source_info ();
263 /* Add zero or more directories to the front of an arbitrary path. */
266 mod_path (dirname
, which_path
)
270 char *old
= *which_path
;
276 dirname
= strsave (dirname
);
277 make_cleanup (free
, dirname
);
281 char *name
= dirname
;
286 char *colon
= strchr (name
, ':');
287 char *space
= strchr (name
, ' ');
288 char *tab
= strchr (name
, '\t');
289 if (colon
== 0 && space
== 0 && tab
== 0)
290 p
= dirname
= name
+ strlen (name
);
294 if (colon
!= 0 && (p
== 0 || colon
< p
))
296 if (space
!= 0 && (p
== 0 || space
< p
))
298 if (tab
!= 0 && (p
== 0 || tab
< p
))
301 while (*dirname
== ':' || *dirname
== ' ' || *dirname
== '\t')
307 /* Sigh. "foo/" => "foo" */
315 /* "." => getwd (). */
316 name
= current_directory
;
319 else if (p
[-2] == '/')
329 /* "...foo/." => "...foo". */
340 name
= tilde_expand (name
);
341 else if (name
[0] != '/' && name
[0] != '$')
342 name
= concat (current_directory
, "/", name
, NULL
);
344 name
= savestring (name
, p
- name
);
345 make_cleanup (free
, name
);
347 /* Unless it's a variable, check existence. */
348 if (name
[0] != '$') {
349 if (stat (name
, &st
) < 0)
350 perror_with_name (name
);
351 if ((st
.st_mode
& S_IFMT
) != S_IFDIR
)
352 error ("%s is not a directory.", name
);
357 register unsigned int len
= strlen (name
);
362 if (!strncmp (p
, name
, len
)
363 && (p
[len
] == '\0' || p
[len
] == ':'))
365 /* Found it in the search path, remove old copy */
367 p
--; /* Back over leading colon */
368 if (prefix
> p
- *which_path
)
369 goto skip_dup
; /* Same dir twice in one cmd */
370 strcpy (p
, &p
[len
+1]); /* Copy from next \0 or : */
380 /* If we have already tacked on a name(s) in this command, be sure they stay on the front as we tack on some more. */
387 temp
= concat (old
, ":", name
, NULL
);
389 *which_path
= concat (temp
, "", &old
[prefix
], NULL
);
390 prefix
= strlen (temp
);
395 *which_path
= concat (name
, (old
[0]? ":" : old
), old
, NULL
);
396 prefix
= strlen (name
);
403 } while (*dirname
!= '\0');
410 register struct symtab
*s
= current_source_symtab
;
414 printf("No current source file.\n");
417 printf ("Current source file is %s\n", s
->filename
);
419 printf ("Compilation directory is %s\n", s
->dirname
);
421 printf ("Located in %s\n", s
->fullname
);
423 printf ("Contains %d lines\n", s
->nlines
);
425 printf("Source language %s.\n", language_str (s
->language
));
430 /* Open a file named STRING, searching path PATH (dir names sep by colons)
431 using mode MODE and protection bits PROT in the calls to open.
432 If TRY_CWD_FIRST, try to open ./STRING before searching PATH.
433 (ie pretend the first element of PATH is ".")
434 If FILENAMED_OPENED is non-null, set it to a newly allocated string naming
435 the actual file opened (this string will always start with a "/". We
436 have to take special pains to avoid doubling the "/" between the directory
437 and the file, sigh! Emacs gets confuzzed by this when we print the
440 If a file is found, return the descriptor.
441 Otherwise, return -1, with errno set for the last name we tried to open. */
443 /* >>>> This should only allow files of certain types,
444 >>>> eg executable, non-directory */
446 openp (path
, try_cwd_first
, string
, mode
, prot
, filename_opened
)
452 char **filename_opened
;
455 register char *filename
;
456 register char *p
, *p1
;
464 while (string
[0] == '.' && string
[1] == '/')
467 if (try_cwd_first
|| string
[0] == '/')
470 fd
= open (filename
, mode
, prot
);
471 if (fd
>= 0 || string
[0] == '/')
475 alloclen
= strlen (path
) + strlen (string
) + 2;
476 filename
= (char *) alloca (alloclen
);
478 for (p
= path
; p
; p
= p1
? p1
+ 1 : 0)
480 p1
= (char *) strchr (p
, ':');
486 if (len
== 4 && p
[0] == '$' && p
[1] == 'c'
487 && p
[2] == 'w' && p
[3] == 'd') {
488 /* Name is $cwd -- insert current directory name instead. */
491 /* First, realloc the filename buffer if too short. */
492 len
= strlen (current_directory
);
493 newlen
= len
+ strlen (string
) + 2;
494 if (newlen
> alloclen
) {
496 filename
= (char *) alloca (alloclen
);
498 strcpy (filename
, current_directory
);
500 /* Normal file name in path -- just use it. */
501 strncpy (filename
, p
, len
);
505 /* Beware the // my son, the Emacs barfs, the botch that catch... */
506 while (len
> 1 && filename
[len
-1] == '/')
508 strcat (filename
+len
, "/");
509 strcat (filename
, string
);
511 fd
= open (filename
, mode
, prot
);
518 *filename_opened
= (char *) 0;
519 else if (filename
[0] == '/')
520 *filename_opened
= savestring (filename
, strlen (filename
));
523 /* Beware the // my son, the Emacs barfs, the botch that catch... */
525 *filename_opened
= concat (current_directory
,
526 '/' == current_directory
[strlen(current_directory
)-1]? "": "/",
533 /* Open a source file given a symtab S. Returns a file descriptor
534 or negative number for error. */
540 char *path
= source_path
;
545 /* Quick way out if we already know its full name */
548 result
= open (s
->fullname
, O_RDONLY
);
551 /* Didn't work -- free old one, try again. */
552 mfree (s
->objfile
->md
, s
->fullname
);
556 if (s
->dirname
!= NULL
)
558 /* Replace a path entry of $cdir with the compilation directory name */
560 /* We cast strstr's result in case an ANSIhole has made it const,
561 which produces a "required warning" when assigned to a nonconst. */
562 p
= (char *)strstr (source_path
, "$cdir");
563 if (p
&& (p
== path
|| p
[-1] == ':')
564 && (p
[cdir_len
] == ':' || p
[cdir_len
] == '\0')) {
568 alloca (strlen (source_path
) + 1 + strlen (s
->dirname
) + 1);
569 len
= p
- source_path
;
570 strncpy (path
, source_path
, len
); /* Before $cdir */
571 strcpy (path
+ len
, s
->dirname
); /* new stuff */
572 strcat (path
+ len
, source_path
+ len
+ cdir_len
); /* After $cdir */
576 result
= openp (path
, 0, s
->filename
, O_RDONLY
, 0, &s
->fullname
);
579 /* Didn't work. Try using just the basename. */
580 p
= basename (s
->filename
);
581 if (p
!= s
->filename
)
582 result
= openp(path
, 0, p
, O_RDONLY
,0, &s
->fullname
);
586 fullname
= s
-> fullname
;
587 s
-> fullname
= mstrsave (s
-> objfile
-> md
, s
-> fullname
);
594 /* Create and initialize the table S->line_charpos that records
595 the positions of the lines in the source file, which is assumed
596 to be open on descriptor DESC.
597 All set S->nlines to the number of such lines. */
600 find_source_lines (s
, desc
)
605 register char *data
, *p
, *end
;
607 int lines_allocated
= 1000;
611 line_charpos
= (int *) xmmalloc (s
-> objfile
-> md
,
612 lines_allocated
* sizeof (int));
613 if (fstat (desc
, &st
) < 0)
614 perror_with_name (s
->filename
);
617 exec_mtime
= bfd_get_mtime(exec_bfd
);
618 if (exec_mtime
&& exec_mtime
< st
.st_mtime
)
619 printf ("Source file is more recent than executable.\n");
622 #ifdef BROKEN_LARGE_ALLOCA
623 data
= (char *) xmalloc (st
.st_size
);
624 make_cleanup (free
, data
);
626 data
= (char *) alloca (st
.st_size
);
628 if (myread (desc
, data
, st
.st_size
) < 0)
629 perror_with_name (s
->filename
);
630 end
= data
+ st
.st_size
;
637 /* A newline at the end does not start a new line. */
640 if (nlines
== lines_allocated
)
642 lines_allocated
*= 2;
644 (int *) xmrealloc (s
-> objfile
-> md
, (char *) line_charpos
,
645 sizeof (int) * lines_allocated
);
647 line_charpos
[nlines
++] = p
- data
;
652 (int *) xmrealloc (s
-> objfile
-> md
, (char *) line_charpos
,
653 nlines
* sizeof (int));
656 /* Return the character position of a line LINE in symtab S.
657 Return 0 if anything is invalid. */
659 #if 0 /* Currently unused */
662 source_line_charpos (s
, line
)
667 if (!s
->line_charpos
|| line
<= 0) return 0;
668 if (line
> s
->nlines
)
670 return s
->line_charpos
[line
- 1];
673 /* Return the line number of character position POS in symtab S. */
676 source_charpos_line (s
, chr
)
677 register struct symtab
*s
;
680 register int line
= 0;
683 if (s
== 0 || s
->line_charpos
== 0) return 0;
684 lnp
= s
->line_charpos
;
685 /* Files are usually short, so sequential search is Ok */
686 while (line
< s
->nlines
&& *lnp
<= chr
)
691 if (line
>= s
->nlines
)
699 /* Get full pathname and line number positions for a symtab.
700 Return nonzero if line numbers may have changed.
701 Set *FULLNAME to actual name of the file as found by `openp',
702 or to 0 if the file is not found. */
705 get_filename_and_charpos (s
, fullname
)
709 register int desc
, linenums_changed
= 0;
711 desc
= open_source_file (s
);
719 *fullname
= s
->fullname
;
720 if (s
->line_charpos
== 0) linenums_changed
= 1;
721 if (linenums_changed
) find_source_lines (s
, desc
);
723 return linenums_changed
;
726 /* Print text describing the full name of the source file S
727 and the line number LINE and its corresponding character position.
728 The text starts with two Ctrl-z so that the Emacs-GDB interface
731 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
733 Return 1 if successful, 0 if could not find the file. */
736 identify_source_line (s
, line
, mid_statement
)
741 if (s
->line_charpos
== 0)
742 get_filename_and_charpos (s
, (char **)NULL
);
743 if (s
->fullname
== 0)
745 printf ("\032\032%s:%d:%d:%s:0x%x\n", s
->fullname
,
746 line
, s
->line_charpos
[line
- 1],
747 mid_statement
? "middle" : "beg",
748 get_frame_pc (get_current_frame()));
749 current_source_line
= line
;
750 first_line_listed
= line
;
751 last_line_listed
= line
;
752 current_source_symtab
= s
;
756 /* Print source lines from the file of symtab S,
757 starting with line number LINE and stopping before line number STOPLINE. */
760 print_source_lines (s
, line
, stopline
, noerror
)
767 register FILE *stream
;
768 int nlines
= stopline
- line
;
770 /* Regardless of whether we can open the file, set current_source_symtab. */
771 current_source_symtab
= s
;
772 current_source_line
= line
;
773 first_line_listed
= line
;
775 desc
= open_source_file (s
);
779 char *name
= alloca (strlen (s
->filename
) + 100);
780 sprintf (name
, "%s:%d", s
->filename
, line
);
781 print_sys_errmsg (name
, errno
);
786 if (s
->line_charpos
== 0)
787 find_source_lines (s
, desc
);
789 if (line
< 1 || line
> s
->nlines
)
792 error ("Line number %d out of range; %s has %d lines.",
793 line
, s
->filename
, s
->nlines
);
796 if (lseek (desc
, s
->line_charpos
[line
- 1], 0) < 0)
799 perror_with_name (s
->filename
);
802 stream
= fdopen (desc
, "r");
809 last_line_listed
= current_source_line
;
810 printf_filtered ("%d\t", current_source_line
++);
813 if (c
< 040 && c
!= '\t' && c
!= '\n')
814 printf_filtered ("^%c", c
+ 0100);
816 printf_filtered ("^?");
818 printf_filtered ("%c", c
);
819 } while (c
!= '\n' && (c
= fgetc (stream
)) >= 0);
829 Print a list of files and line numbers which a user may choose from
830 in order to list a function which was specified ambiguously
831 (as with `list classname::overloadedfuncname', for example).
832 The vector in SALS provides the filenames and line numbers.
835 ambiguous_line_spec (sals
)
836 struct symtabs_and_lines
*sals
;
840 for (i
= 0; i
< sals
->nelts
; ++i
)
841 printf("file: \"%s\", line number: %d\n",
842 sals
->sals
[i
].symtab
->filename
, sals
->sals
[i
].line
);
847 list_command (arg
, from_tty
)
851 struct symtabs_and_lines sals
, sals_end
;
852 struct symtab_and_line sal
, sal_end
;
861 if (!have_full_symbols () && !have_partial_symbols())
862 error ("No symbol table is loaded. Use the \"file\" command.");
864 /* Pull in a current source symtab if necessary */
865 if (current_source_symtab
== 0 &&
866 (arg
== 0 || arg
[0] == '+' || arg
[0] == '-'))
867 select_source_symtab (0);
869 /* "l" or "l +" lists next ten lines. */
871 if (arg
== 0 || !strcmp (arg
, "+"))
873 if (current_source_symtab
== 0)
874 error ("No default source file yet. Do \"help list\".");
875 print_source_lines (current_source_symtab
, current_source_line
,
876 current_source_line
+ lines_to_list
, 0);
880 /* "l -" lists previous ten lines, the ones before the ten just listed. */
881 if (!strcmp (arg
, "-"))
883 if (current_source_symtab
== 0)
884 error ("No default source file yet. Do \"help list\".");
885 print_source_lines (current_source_symtab
,
886 max (first_line_listed
- lines_to_list
, 1),
887 first_line_listed
, 0);
891 /* Now if there is only one argument, decode it in SAL
893 If there are two arguments, decode them in SAL and SAL_END
894 and clear NO_END; however, if one of the arguments is blank,
895 set DUMMY_BEG or DUMMY_END to record that fact. */
902 sals
= decode_line_1 (&arg1
, 0, 0, 0);
904 if (! sals
.nelts
) return; /* C++ */
907 ambiguous_line_spec (&sals
);
916 /* Record whether the BEG arg is all digits. */
918 for (p
= arg
; p
!= arg1
&& *p
>= '0' && *p
<= '9'; p
++);
919 linenum_beg
= (p
== arg1
);
921 while (*arg1
== ' ' || *arg1
== '\t')
927 while (*arg1
== ' ' || *arg1
== '\t')
934 sals_end
= decode_line_1 (&arg1
, 0, 0, 0);
936 sals_end
= decode_line_1 (&arg1
, 0, sal
.symtab
, sal
.line
);
937 if (sals_end
.nelts
== 0)
939 if (sals_end
.nelts
> 1)
941 ambiguous_line_spec (&sals_end
);
942 free (sals_end
.sals
);
945 sal_end
= sals_end
.sals
[0];
946 free (sals_end
.sals
);
951 error ("Junk at end of line specification.");
953 if (!no_end
&& !dummy_beg
&& !dummy_end
954 && sal
.symtab
!= sal_end
.symtab
)
955 error ("Specified start and end are in different files.");
956 if (dummy_beg
&& dummy_end
)
957 error ("Two empty args do not say what lines to list.");
959 /* if line was specified by address,
960 first print exactly which line, and which file.
961 In this case, sal.symtab == 0 means address is outside
962 of all known source files, not that user failed to give a filename. */
966 error ("No source file for address %s.", local_hex_string(sal
.pc
));
967 sym
= find_pc_function (sal
.pc
);
969 printf ("%s is in %s (%s:%d).\n",
970 local_hex_string(sal
.pc
),
971 SYMBOL_NAME (sym
), sal
.symtab
->filename
, sal
.line
);
973 printf ("%s is at %s:%d.\n",
974 local_hex_string(sal
.pc
),
975 sal
.symtab
->filename
, sal
.line
);
978 /* If line was not specified by just a line number,
979 and it does not imply a symtab, it must be an undebuggable symbol
980 which means no source code. */
982 if (! linenum_beg
&& sal
.symtab
== 0)
983 error ("No line number known for %s.", arg
);
985 /* If this command is repeated with RET,
986 turn it into the no-arg variant. */
991 if (dummy_beg
&& sal_end
.symtab
== 0)
992 error ("No default source file yet. Do \"help list\".");
994 print_source_lines (sal_end
.symtab
,
995 max (sal_end
.line
- (lines_to_list
- 1), 1),
996 sal_end
.line
+ 1, 0);
997 else if (sal
.symtab
== 0)
998 error ("No default source file yet. Do \"help list\".");
1000 print_source_lines (sal
.symtab
,
1001 max (sal
.line
- (lines_to_list
/ 2), 1),
1002 sal
.line
+ (lines_to_list
/ 2), 0);
1004 print_source_lines (sal
.symtab
, sal
.line
,
1006 ? sal
.line
+ lines_to_list
1007 : sal_end
.line
+ 1),
1011 /* Print info on range of pc's in a specified line. */
1014 line_info (arg
, from_tty
)
1018 struct symtabs_and_lines sals
;
1019 struct symtab_and_line sal
;
1020 CORE_ADDR start_pc
, end_pc
;
1025 sal
.symtab
= current_source_symtab
;
1026 sal
.line
= last_line_listed
;
1028 sals
.sals
= (struct symtab_and_line
*)
1029 xmalloc (sizeof (struct symtab_and_line
));
1034 sals
= decode_line_spec_1 (arg
, 0);
1036 /* If this command is repeated with RET,
1037 turn it into the no-arg variant. */
1042 /* C++ More than one line may have been specified, as when the user
1043 specifies an overloaded function name. Print info on them all. */
1044 for (i
= 0; i
< sals
.nelts
; i
++)
1048 if (sal
.symtab
== 0)
1049 error ("No source file specified.");
1052 && find_line_pc_range (sal
.symtab
, sal
.line
, &start_pc
, &end_pc
))
1054 if (start_pc
== end_pc
)
1055 printf ("Line %d of \"%s\" is at pc %s but contains no code.\n",
1056 sal
.line
, sal
.symtab
->filename
, local_hex_string(start_pc
));
1059 printf ("Line %d of \"%s\" starts at pc %s",
1060 sal
.line
, sal
.symtab
->filename
,
1061 local_hex_string(start_pc
));
1062 printf (" and ends at %s.\n",
1063 local_hex_string(end_pc
));
1065 /* x/i should display this line's code. */
1066 set_next_address (start_pc
);
1067 /* Repeating "info line" should do the following line. */
1068 last_line_listed
= sal
.line
+ 1;
1071 printf ("Line number %d is out of range for \"%s\".\n",
1072 sal
.line
, sal
.symtab
->filename
);
1076 /* Commands to search the source file for a regexp. */
1080 forward_search_command (regex
, from_tty
)
1086 register FILE *stream
;
1087 int line
= last_line_listed
+ 1;
1090 msg
= (char *) re_comp (regex
);
1094 if (current_source_symtab
== 0)
1095 select_source_symtab (0);
1097 /* Search from last_line_listed+1 in current_source_symtab */
1099 desc
= open_source_file (current_source_symtab
);
1101 perror_with_name (current_source_symtab
->filename
);
1103 if (current_source_symtab
->line_charpos
== 0)
1104 find_source_lines (current_source_symtab
, desc
);
1106 if (line
< 1 || line
> current_source_symtab
->nlines
)
1109 error ("Expression not found");
1112 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1115 perror_with_name (current_source_symtab
->filename
);
1118 stream
= fdopen (desc
, "r");
1121 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1122 char buf
[4096]; /* Should be reasonable??? */
1123 register char *p
= buf
;
1130 } while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1132 /* we now have a source line in buf, null terminate and match */
1134 if (re_exec (buf
) > 0)
1138 print_source_lines (current_source_symtab
,
1140 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1146 printf ("Expression not found\n");
1152 reverse_search_command (regex
, from_tty
)
1158 register FILE *stream
;
1159 int line
= last_line_listed
- 1;
1162 msg
= (char *) re_comp (regex
);
1166 if (current_source_symtab
== 0)
1167 select_source_symtab (0);
1169 /* Search from last_line_listed-1 in current_source_symtab */
1171 desc
= open_source_file (current_source_symtab
);
1173 perror_with_name (current_source_symtab
->filename
);
1175 if (current_source_symtab
->line_charpos
== 0)
1176 find_source_lines (current_source_symtab
, desc
);
1178 if (line
< 1 || line
> current_source_symtab
->nlines
)
1181 error ("Expression not found");
1184 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1187 perror_with_name (current_source_symtab
->filename
);
1190 stream
= fdopen (desc
, "r");
1194 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1195 char buf
[4096]; /* Should be reasonable??? */
1196 register char *p
= buf
;
1203 } while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1205 /* We now have a source line in buf; null terminate and match. */
1207 if (re_exec (buf
) > 0)
1211 print_source_lines (current_source_symtab
,
1213 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1217 if (fseek (stream
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1220 perror_with_name (current_source_symtab
->filename
);
1224 printf ("Expression not found\n");
1230 _initialize_source ()
1232 current_source_symtab
= 0;
1233 init_source_path ();
1235 add_com ("directory", class_files
, directory_command
,
1236 "Add directory DIR to beginning of search path for source files.\n\
1237 Forget cached info on source file locations and line positions.\n\
1238 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1239 directory in which the source file was compiled into object code.\n\
1240 With no argument, reset the search path to $cdir:$cwd, the default.");
1242 add_cmd ("directories", no_class
, show_directories
,
1243 "Current search path for finding source files.\n\
1244 $cwd in the path means the current working directory.\n\
1245 $cdir in the path means the compilation directory of the source file.",
1248 add_info ("source", source_info
,
1249 "Information about the current source file.");
1251 add_info ("line", line_info
,
1252 "Core addresses of the code for a source line.\n\
1253 Line can be specified as\n\
1254 LINENUM, to list around that line in current file,\n\
1255 FILE:LINENUM, to list around that line in that file,\n\
1256 FUNCTION, to list around beginning of that function,\n\
1257 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1258 Default is to describe the last source line that was listed.\n\n\
1259 This sets the default address for \"x\" to the line's first instruction\n\
1260 so that \"x/i\" suffices to start examining the machine code.\n\
1261 The address is also stored as the value of \"$_\".");
1263 add_com ("forward-search", class_files
, forward_search_command
,
1264 "Search for regular expression (see regex(3)) from last line listed.");
1265 add_com_alias ("search", "forward-search", class_files
, 0);
1267 add_com ("reverse-search", class_files
, reverse_search_command
,
1268 "Search backward for regular expression (see regex(3)) from last line listed.");
1270 add_com ("list", class_files
, list_command
,
1271 "List specified function or line.\n\
1272 With no argument, lists ten more lines after or around previous listing.\n\
1273 \"list -\" lists the ten lines before a previous ten-line listing.\n\
1274 One argument specifies a line, and ten lines are listed around that line.\n\
1275 Two arguments with comma between specify starting and ending lines to list.\n\
1276 Lines can be specified in these ways:\n\
1277 LINENUM, to list around that line in current file,\n\
1278 FILE:LINENUM, to list around that line in that file,\n\
1279 FUNCTION, to list around beginning of that function,\n\
1280 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1281 *ADDRESS, to list around the line containing that address.\n\
1282 With two args if one is empty it stands for ten lines away from the other arg.");
1283 add_com_alias ("l", "list", class_files
, 0);
1286 (add_set_cmd ("listsize", class_support
, var_uinteger
,
1287 (char *)&lines_to_list
,
1288 "Set number of source lines gdb will list by default.",
This page took 0.068581 seconds and 5 git commands to generate.