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. */
30 #include <sys/types.h>
34 #include <sys/param.h>
40 /* If we use this declaration, it breaks because of fucking ANSI "const" stuff
41 on some systems. We just have to not declare it at all, have it default
42 to int, and possibly botch on a few systems. Thanks, ANSIholes... */
43 /* extern char *strstr(); */
45 extern void set_next_address ();
47 /* Path of directories to search for source files.
48 Same format as the PATH environment variable's value. */
52 /* Symtab of default file for listing lines of. */
54 struct symtab
*current_source_symtab
;
56 /* Default next line to list. */
58 int current_source_line
;
60 /* Default number of lines to print with commands like "list".
61 This is based on guessing how many long (i.e. more than chars_per_line
62 characters) lines there will be. To be completely correct, "list"
63 and friends should be rewritten to count characters and see where
64 things are wrapping, but that would be a fair amount of work. */
66 unsigned lines_to_list
= 10;
68 /* Line number of last line printed. Default for various commands.
69 current_source_line is usually, but not always, the same as this. */
71 static int last_line_listed
;
73 /* First line number listed by last listing command. */
75 static int first_line_listed
;
78 /* Set the source file default for the "list" command, specifying a
79 symtab. Sigh. Behavior specification: If it is called with a
80 non-zero argument, that is the symtab to select. If it is not,
81 first lookup "main"; if it exists, use the symtab and line it
82 defines. If not, take the last symtab in the symtab_list (if it
83 exists) or the last symtab in the psymtab_list (if *it* exists). If
84 none of this works, report an error. */
87 select_source_symtab (s
)
88 register struct symtab
*s
;
90 struct symtabs_and_lines sals
;
91 struct symtab_and_line sal
;
92 struct partial_symtab
*ps
;
93 struct partial_symtab
*cs_pst
= 0;
97 current_source_symtab
= s
;
98 current_source_line
= 1;
102 /* Make the default place to list be the function `main'
104 if (lookup_symbol ("main", 0, VAR_NAMESPACE
, 0, NULL
))
106 sals
= decode_line_spec ("main", 1);
109 current_source_symtab
= sal
.symtab
;
110 current_source_line
= max (sal
.line
- (lines_to_list
- 1), 1);
111 if (current_source_symtab
)
115 /* All right; find the last file in the symtab list (ignoring .h's). */
117 current_source_line
= 1;
119 for (s
= symtab_list
; s
; s
= s
->next
)
121 char *name
= s
->filename
;
122 int len
= strlen (name
);
123 if (! (len
> 2 && !strcmp (&name
[len
- 2], ".h")))
124 current_source_symtab
= s
;
126 if (current_source_symtab
)
129 /* Howabout the partial symtab list? */
131 if (partial_symtab_list
)
133 ps
= partial_symtab_list
;
136 char *name
= ps
->filename
;
137 int len
= strlen (name
);
138 if (! (len
> 2 && !strcmp (&name
[len
- 2], ".h")))
144 fatal ("Internal: select_source_symtab: readin pst found and no symtabs.");
146 current_source_symtab
= PSYMTAB_TO_SYMTAB (cs_pst
);
148 if (current_source_symtab
)
151 error ("Can't find a default source file");
157 printf ("Source directories searched: %s\n", source_path
);
160 /* Forget what we learned about line positions in source files,
161 and which directories contain them;
162 must check again now since files may be found in
163 a different directory now. */
166 forget_cached_source_info ()
168 register struct symtab
*s
;
170 for (s
= symtab_list
; s
; s
= s
->next
)
172 if (s
->line_charpos
!= 0)
174 free (s
->line_charpos
);
177 if (s
->fullname
!= 0)
188 source_path
= savestring ("$cdir:$cwd", /* strlen of it */ 10);
189 forget_cached_source_info ();
192 /* Add zero or more directories to the front of the source path. */
195 directory_command (dirname
, from_tty
)
200 /* FIXME, this goes to "delete dir"... */
203 if (query ("Reinitialize source path to empty? ", ""))
210 mod_path (dirname
, &source_path
);
213 forget_cached_source_info ();
216 /* Add zero or more directories to the front of an arbitrary path. */
219 mod_path (dirname
, which_path
)
223 char *old
= *which_path
;
229 dirname
= strsave (dirname
);
230 make_cleanup (free
, dirname
);
234 extern char *index ();
235 char *name
= dirname
;
240 char *colon
= index (name
, ':');
241 char *space
= index (name
, ' ');
242 char *tab
= index (name
, '\t');
243 if (colon
== 0 && space
== 0 && tab
== 0)
244 p
= dirname
= name
+ strlen (name
);
248 if (colon
!= 0 && (p
== 0 || colon
< p
))
250 if (space
!= 0 && (p
== 0 || space
< p
))
252 if (tab
!= 0 && (p
== 0 || tab
< p
))
255 while (*dirname
== ':' || *dirname
== ' ' || *dirname
== '\t')
261 /* Sigh. "foo/" => "foo" */
269 /* "." => getwd (). */
270 name
= current_directory
;
273 else if (p
[-2] == '/')
283 /* "...foo/." => "...foo". */
294 name
= tilde_expand (name
);
295 else if (name
[0] != '/' && name
[0] != '$')
296 name
= concat (current_directory
, "/", name
);
298 name
= savestring (name
, p
- name
);
299 make_cleanup (free
, name
);
301 /* Unless it's a variable, check existence. */
302 if (name
[0] != '$') {
303 if (stat (name
, &st
) < 0)
304 perror_with_name (name
);
305 if ((st
.st_mode
& S_IFMT
) != S_IFDIR
)
306 error ("%s is not a directory.", name
);
311 register unsigned int len
= strlen (name
);
316 if (!strncmp (p
, name
, len
)
317 && (p
[len
] == '\0' || p
[len
] == ':'))
319 /* Found it in the search path, remove old copy */
321 p
--; /* Back over leading colon */
322 if (prefix
> p
- *which_path
)
323 goto skip_dup
; /* Same dir twice in one cmd */
324 strcpy (p
, &p
[len
+1]); /* Copy from next \0 or : */
334 /* 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. */
341 temp
= concat (old
, ":", name
);
343 *which_path
= concat (temp
, "", &old
[prefix
]);
344 prefix
= strlen (temp
);
349 *which_path
= concat (name
, (old
[0]? ":" : old
), old
);
350 prefix
= strlen (name
);
357 } while (*dirname
!= '\0');
364 register struct symtab
*s
= current_source_symtab
;
368 printf("No current source file.\n");
371 printf ("Current source file is %s\n", s
->filename
);
373 printf ("Compilation directory is %s\n", s
->dirname
);
375 printf ("Located in %s\n", s
->fullname
);
377 printf ("Contains %d lines\n", s
->nlines
);
379 printf("Source language %s.\n", language_str (s
->language
));
384 /* Open a file named STRING, searching path PATH (dir names sep by colons)
385 using mode MODE and protection bits PROT in the calls to open.
386 If TRY_CWD_FIRST, try to open ./STRING before searching PATH.
387 (ie pretend the first element of PATH is ".")
388 If FILENAMED_OPENED is non-null, set it to a newly allocated string naming
389 the actual file opened (this string will always start with a "/". We
390 have to take special pains to avoid doubling the "/" between the directory
391 and the file, sigh! Emacs gets confuzzed by this when we print the
394 If a file is found, return the descriptor.
395 Otherwise, return -1, with errno set for the last name we tried to open. */
397 /* >>>> This should only allow files of certain types,
398 >>>> eg executable, non-directory */
400 openp (path
, try_cwd_first
, string
, mode
, prot
, filename_opened
)
406 char **filename_opened
;
409 register char *filename
;
410 register char *p
, *p1
;
418 while (string
[0] == '.' && string
[1] == '/')
421 if (try_cwd_first
|| string
[0] == '/')
424 fd
= open (filename
, mode
, prot
);
425 if (fd
>= 0 || string
[0] == '/')
429 alloclen
= strlen (path
) + strlen (string
) + 2;
430 filename
= (char *) alloca (alloclen
);
432 for (p
= path
; p
; p
= p1
? p1
+ 1 : 0)
434 p1
= (char *) index (p
, ':');
440 if (len
== 4 && p
[0] == '$' && p
[1] == 'c'
441 && p
[2] == 'w' && p
[3] == 'd') {
442 /* Name is $cwd -- insert current directory name instead. */
445 /* First, realloc the filename buffer if too short. */
446 len
= strlen (current_directory
);
447 newlen
= len
+ strlen (string
) + 2;
448 if (newlen
> alloclen
) {
450 filename
= (char *) alloca (alloclen
);
452 strcpy (filename
, current_directory
);
454 /* Normal file name in path -- just use it. */
455 strncpy (filename
, p
, len
);
459 /* Beware the // my son, the Emacs barfs, the botch that catch... */
460 while (len
> 1 && filename
[len
-1] == '/')
462 strcat (filename
+len
, "/");
463 strcat (filename
, string
);
465 fd
= open (filename
, mode
, prot
);
472 *filename_opened
= (char *) 0;
473 else if (filename
[0] == '/')
474 *filename_opened
= savestring (filename
, strlen (filename
));
477 /* Beware the // my son, the Emacs barfs, the botch that catch... */
479 *filename_opened
= concat (current_directory
,
480 '/' == current_directory
[strlen(current_directory
)-1]? "": "/",
487 /* Open a source file given a symtab S. Returns a file descriptor
488 or negative number for error. */
493 char *path
= source_path
;
497 /* Quick way out if we already know its full name */
500 result
= open (s
->fullname
, O_RDONLY
);
503 /* Didn't work -- free old one, try again. */
508 if (s
->dirname
!= NULL
)
510 /* Replace a path entry of $cdir with the compilation directory name */
512 /* We cast strstr's result in case an ANSIhole has made it const,
513 which produces a "required warning" when assigned to a nonconst. */
514 p
= (char *)strstr (source_path
, "$cdir");
515 if (p
&& (p
== path
|| p
[-1] == ':')
516 && (p
[cdir_len
] == ':' || p
[cdir_len
] == '\0')) {
520 alloca (strlen (source_path
) + 1 + strlen (s
->dirname
) + 1);
521 len
= p
- source_path
;
522 strncpy (path
, source_path
, len
); /* Before $cdir */
523 strcpy (path
+ len
, s
->dirname
); /* new stuff */
524 strcat (path
+ len
, source_path
+ len
+ cdir_len
); /* After $cdir */
528 return openp (path
, 0, s
->filename
, O_RDONLY
, 0, &s
->fullname
);
532 /* Create and initialize the table S->line_charpos that records
533 the positions of the lines in the source file, which is assumed
534 to be open on descriptor DESC.
535 All set S->nlines to the number of such lines. */
538 find_source_lines (s
, desc
)
543 register char *data
, *p
, *end
;
545 int lines_allocated
= 1000;
546 int *line_charpos
= (int *) xmalloc (lines_allocated
* sizeof (int));
548 if (fstat (desc
, &st
) < 0)
549 perror_with_name (s
->filename
);
550 if (exec_bfd
&& bfd_get_mtime(exec_bfd
) < st
.st_mtime
)
551 printf ("Source file is more recent than executable.\n");
553 #ifdef BROKEN_LARGE_ALLOCA
554 data
= (char *) xmalloc (st
.st_size
);
555 make_cleanup (free
, data
);
557 data
= (char *) alloca (st
.st_size
);
559 if (myread (desc
, data
, st
.st_size
) < 0)
560 perror_with_name (s
->filename
);
561 end
= data
+ st
.st_size
;
568 /* A newline at the end does not start a new line. */
571 if (nlines
== lines_allocated
)
573 lines_allocated
*= 2;
574 line_charpos
= (int *) xrealloc (line_charpos
,
575 sizeof (int) * lines_allocated
);
577 line_charpos
[nlines
++] = p
- data
;
581 s
->line_charpos
= (int *) xrealloc (line_charpos
, nlines
* sizeof (int));
584 /* Return the character position of a line LINE in symtab S.
585 Return 0 if anything is invalid. */
588 source_line_charpos (s
, line
)
593 if (!s
->line_charpos
|| line
<= 0) return 0;
594 if (line
> s
->nlines
)
596 return s
->line_charpos
[line
- 1];
599 /* Return the line number of character position POS in symtab S. */
602 source_charpos_line (s
, chr
)
603 register struct symtab
*s
;
606 register int line
= 0;
609 if (s
== 0 || s
->line_charpos
== 0) return 0;
610 lnp
= s
->line_charpos
;
611 /* Files are usually short, so sequential search is Ok */
612 while (line
< s
->nlines
&& *lnp
<= chr
)
617 if (line
>= s
->nlines
)
622 /* Get full pathname and line number positions for a symtab.
623 Return nonzero if line numbers may have changed.
624 Set *FULLNAME to actual name of the file as found by `openp',
625 or to 0 if the file is not found. */
628 get_filename_and_charpos (s
, fullname
)
632 register int desc
, linenums_changed
= 0;
634 desc
= open_source_file (s
);
642 *fullname
= s
->fullname
;
643 if (s
->line_charpos
== 0) linenums_changed
= 1;
644 if (linenums_changed
) find_source_lines (s
, desc
);
646 return linenums_changed
;
649 /* Print text describing the full name of the source file S
650 and the line number LINE and its corresponding character position.
651 The text starts with two Ctrl-z so that the Emacs-GDB interface
654 MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
656 Return 1 if successful, 0 if could not find the file. */
659 identify_source_line (s
, line
, mid_statement
)
664 if (s
->line_charpos
== 0)
665 get_filename_and_charpos (s
, (char **)NULL
);
666 if (s
->fullname
== 0)
668 printf ("\032\032%s:%d:%d:%s:0x%x\n", s
->fullname
,
669 line
, s
->line_charpos
[line
- 1],
670 mid_statement
? "middle" : "beg",
671 get_frame_pc (get_current_frame()));
672 current_source_line
= line
;
673 first_line_listed
= line
;
674 last_line_listed
= line
;
675 current_source_symtab
= s
;
679 /* Print source lines from the file of symtab S,
680 starting with line number LINE and stopping before line number STOPLINE. */
683 print_source_lines (s
, line
, stopline
, noerror
)
690 register FILE *stream
;
691 int nlines
= stopline
- line
;
693 /* Regardless of whether we can open the file, set current_source_symtab. */
694 current_source_symtab
= s
;
695 current_source_line
= line
;
696 first_line_listed
= line
;
698 desc
= open_source_file (s
);
702 char *name
= alloca (strlen (s
->filename
) + 100);
703 sprintf (name
, "%s:%d", s
->filename
, line
);
704 print_sys_errmsg (name
, errno
);
709 if (s
->line_charpos
== 0)
710 find_source_lines (s
, desc
);
712 if (line
< 1 || line
> s
->nlines
)
715 error ("Line number %d out of range; %s has %d lines.",
716 line
, s
->filename
, s
->nlines
);
719 if (lseek (desc
, s
->line_charpos
[line
- 1], 0) < 0)
722 perror_with_name (s
->filename
);
725 stream
= fdopen (desc
, "r");
732 last_line_listed
= current_source_line
;
733 printf_filtered ("%d\t", current_source_line
++);
736 if (c
< 040 && c
!= '\t' && c
!= '\n')
737 printf_filtered ("^%c", c
+ 0100);
739 printf_filtered ("^?");
741 printf_filtered ("%c", c
);
742 } while (c
!= '\n' && (c
= fgetc (stream
)) >= 0);
752 Print a list of files and line numbers which a user may choose from
753 in order to list a function which was specified ambiguously
754 (as with `list classname::overloadedfuncname', for example).
755 The vector in SALS provides the filenames and line numbers.
758 ambiguous_line_spec (sals
)
759 struct symtabs_and_lines
*sals
;
763 for (i
= 0; i
< sals
->nelts
; ++i
)
764 printf("file: \"%s\", line number: %d\n",
765 sals
->sals
[i
].symtab
->filename
, sals
->sals
[i
].line
);
770 list_command (arg
, from_tty
)
774 struct symtabs_and_lines sals
, sals_end
;
775 struct symtab_and_line sal
, sal_end
;
784 if (symtab_list
== 0 && partial_symtab_list
== 0)
785 error ("No symbol table is loaded. Use the \"file\" command.");
787 /* Pull in a current source symtab if necessary */
788 if (current_source_symtab
== 0 &&
789 (arg
== 0 || arg
[0] == '+' || arg
[0] == '-'))
790 select_source_symtab (0);
792 /* "l" or "l +" lists next ten lines. */
794 if (arg
== 0 || !strcmp (arg
, "+"))
796 if (current_source_symtab
== 0)
797 error ("No default source file yet. Do \"help list\".");
798 print_source_lines (current_source_symtab
, current_source_line
,
799 current_source_line
+ lines_to_list
, 0);
803 /* "l -" lists previous ten lines, the ones before the ten just listed. */
804 if (!strcmp (arg
, "-"))
806 if (current_source_symtab
== 0)
807 error ("No default source file yet. Do \"help list\".");
808 print_source_lines (current_source_symtab
,
809 max (first_line_listed
- lines_to_list
, 1),
810 first_line_listed
, 0);
814 /* Now if there is only one argument, decode it in SAL
816 If there are two arguments, decode them in SAL and SAL_END
817 and clear NO_END; however, if one of the arguments is blank,
818 set DUMMY_BEG or DUMMY_END to record that fact. */
825 sals
= decode_line_1 (&arg1
, 0, 0, 0);
827 if (! sals
.nelts
) return; /* C++ */
830 ambiguous_line_spec (&sals
);
839 /* Record whether the BEG arg is all digits. */
841 for (p
= arg
; p
!= arg1
&& *p
>= '0' && *p
<= '9'; p
++);
842 linenum_beg
= (p
== arg1
);
844 while (*arg1
== ' ' || *arg1
== '\t')
850 while (*arg1
== ' ' || *arg1
== '\t')
857 sals_end
= decode_line_1 (&arg1
, 0, 0, 0);
859 sals_end
= decode_line_1 (&arg1
, 0, sal
.symtab
, sal
.line
);
860 if (sals_end
.nelts
== 0)
862 if (sals_end
.nelts
> 1)
864 ambiguous_line_spec (&sals_end
);
865 free (sals_end
.sals
);
868 sal_end
= sals_end
.sals
[0];
869 free (sals_end
.sals
);
874 error ("Junk at end of line specification.");
876 if (!no_end
&& !dummy_beg
&& !dummy_end
877 && sal
.symtab
!= sal_end
.symtab
)
878 error ("Specified start and end are in different files.");
879 if (dummy_beg
&& dummy_end
)
880 error ("Two empty args do not say what lines to list.");
882 /* if line was specified by address,
883 first print exactly which line, and which file.
884 In this case, sal.symtab == 0 means address is outside
885 of all known source files, not that user failed to give a filename. */
889 error ("No source file for address %s.", local_hex_string(sal
.pc
));
890 sym
= find_pc_function (sal
.pc
);
892 printf ("%s is in %s (%s, line %d).\n",
893 local_hex_string(sal
.pc
),
894 SYMBOL_NAME (sym
), sal
.symtab
->filename
, sal
.line
);
896 printf ("%s is in %s, line %d.\n",
897 local_hex_string(sal
.pc
),
898 sal
.symtab
->filename
, sal
.line
);
901 /* If line was not specified by just a line number,
902 and it does not imply a symtab, it must be an undebuggable symbol
903 which means no source code. */
905 if (! linenum_beg
&& sal
.symtab
== 0)
906 error ("No line number known for %s.", arg
);
908 /* If this command is repeated with RET,
909 turn it into the no-arg variant. */
914 if (dummy_beg
&& sal_end
.symtab
== 0)
915 error ("No default source file yet. Do \"help list\".");
917 print_source_lines (sal_end
.symtab
,
918 max (sal_end
.line
- (lines_to_list
- 1), 1),
919 sal_end
.line
+ 1, 0);
920 else if (sal
.symtab
== 0)
921 error ("No default source file yet. Do \"help list\".");
923 print_source_lines (sal
.symtab
,
924 max (sal
.line
- (lines_to_list
/ 2), 1),
925 sal
.line
+ (lines_to_list
/ 2), 0);
927 print_source_lines (sal
.symtab
, sal
.line
,
929 ? sal
.line
+ lines_to_list
934 /* Print info on range of pc's in a specified line. */
937 line_info (arg
, from_tty
)
941 struct symtabs_and_lines sals
;
942 struct symtab_and_line sal
;
943 CORE_ADDR start_pc
, end_pc
;
948 sal
.symtab
= current_source_symtab
;
949 sal
.line
= last_line_listed
;
951 sals
.sals
= (struct symtab_and_line
*)
952 xmalloc (sizeof (struct symtab_and_line
));
957 sals
= decode_line_spec_1 (arg
, 0);
959 /* If this command is repeated with RET,
960 turn it into the no-arg variant. */
965 /* C++ More than one line may have been specified, as when the user
966 specifies an overloaded function name. Print info on them all. */
967 for (i
= 0; i
< sals
.nelts
; i
++)
972 error ("No source file specified.");
975 && find_line_pc_range (sal
.symtab
, sal
.line
, &start_pc
, &end_pc
))
977 if (start_pc
== end_pc
)
978 printf ("Line %d of \"%s\" is at pc %s but contains no code.\n",
979 sal
.line
, sal
.symtab
->filename
, local_hex_string(start_pc
));
981 printf ("Line %d of \"%s\" starts at pc %s",
982 sal
.line
, sal
.symtab
->filename
,
983 local_hex_string(start_pc
));
984 printf (" and ends at %s.\n",
985 local_hex_string(end_pc
));
986 /* x/i should display this line's code. */
987 set_next_address (start_pc
);
988 /* Repeating "info line" should do the following line. */
989 last_line_listed
= sal
.line
+ 1;
992 printf ("Line number %d is out of range for \"%s\".\n",
993 sal
.line
, sal
.symtab
->filename
);
997 /* Commands to search the source file for a regexp. */
1001 forward_search_command (regex
, from_tty
)
1007 register FILE *stream
;
1008 int line
= last_line_listed
+ 1;
1011 msg
= (char *) re_comp (regex
);
1015 if (current_source_symtab
== 0)
1016 select_source_symtab (0);
1018 /* Search from last_line_listed+1 in current_source_symtab */
1020 desc
= open_source_file (current_source_symtab
);
1022 perror_with_name (current_source_symtab
->filename
);
1024 if (current_source_symtab
->line_charpos
== 0)
1025 find_source_lines (current_source_symtab
, desc
);
1027 if (line
< 1 || line
> current_source_symtab
->nlines
)
1030 error ("Expression not found");
1033 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1036 perror_with_name (current_source_symtab
->filename
);
1039 stream
= fdopen (desc
, "r");
1042 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1043 char buf
[4096]; /* Should be reasonable??? */
1044 register char *p
= buf
;
1051 } while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1053 /* we now have a source line in buf, null terminate and match */
1055 if (re_exec (buf
) > 0)
1059 print_source_lines (current_source_symtab
,
1061 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1067 printf ("Expression not found\n");
1073 reverse_search_command (regex
, from_tty
)
1079 register FILE *stream
;
1080 int line
= last_line_listed
- 1;
1083 msg
= (char *) re_comp (regex
);
1087 if (current_source_symtab
== 0)
1088 select_source_symtab (0);
1090 /* Search from last_line_listed-1 in current_source_symtab */
1092 desc
= open_source_file (current_source_symtab
);
1094 perror_with_name (current_source_symtab
->filename
);
1096 if (current_source_symtab
->line_charpos
== 0)
1097 find_source_lines (current_source_symtab
, desc
);
1099 if (line
< 1 || line
> current_source_symtab
->nlines
)
1102 error ("Expression not found");
1105 if (lseek (desc
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1108 perror_with_name (current_source_symtab
->filename
);
1111 stream
= fdopen (desc
, "r");
1115 /* FIXME!!! We walk right off the end of buf if we get a long line!!! */
1116 char buf
[4096]; /* Should be reasonable??? */
1117 register char *p
= buf
;
1124 } while (c
!= '\n' && (c
= getc (stream
)) >= 0);
1126 /* We now have a source line in buf; null terminate and match. */
1128 if (re_exec (buf
) > 0)
1132 print_source_lines (current_source_symtab
,
1134 current_source_line
= max (line
- lines_to_list
/ 2, 1);
1138 if (fseek (stream
, current_source_symtab
->line_charpos
[line
- 1], 0) < 0)
1141 perror_with_name (current_source_symtab
->filename
);
1145 printf ("Expression not found\n");
1151 _initialize_source ()
1153 current_source_symtab
= 0;
1154 init_source_path ();
1156 add_com ("directory", class_files
, directory_command
,
1157 "Add directory DIR to beginning of search path for source files.\n\
1158 Forget cached info on source file locations and line positions.\n\
1159 DIR can also be $cwd for the current working directory, or $cdir for the\n\
1160 directory in which the source file was compiled into object code.\n\
1161 With no argument, reset the search path to $cdir:$cwd, the default.");
1163 add_cmd ("directories", no_class
, show_directories
,
1164 "Current search path for finding source files.\n\
1165 $cwd in the path means the current working directory.\n\
1166 $cdir in the path means the compilation directory of the source file.",
1169 add_info ("source", source_info
,
1170 "Information about the current source file.");
1172 add_info ("line", line_info
,
1173 "Core addresses of the code for a source line.\n\
1174 Line can be specified as\n\
1175 LINENUM, to list around that line in current file,\n\
1176 FILE:LINENUM, to list around that line in that file,\n\
1177 FUNCTION, to list around beginning of that function,\n\
1178 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1179 Default is to describe the last source line that was listed.\n\n\
1180 This sets the default address for \"x\" to the line's first instruction\n\
1181 so that \"x/i\" suffices to start examining the machine code.\n\
1182 The address is also stored as the value of \"$_\".");
1184 add_com ("forward-search", class_files
, forward_search_command
,
1185 "Search for regular expression (see regex(3)) from last line listed.");
1186 add_com_alias ("search", "forward-search", class_files
, 0);
1188 add_com ("reverse-search", class_files
, reverse_search_command
,
1189 "Search backward for regular expression (see regex(3)) from last line listed.");
1191 add_com ("list", class_files
, list_command
,
1192 "List specified function or line.\n\
1193 With no argument, lists ten more lines after or around previous listing.\n\
1194 \"list -\" lists the ten lines before a previous ten-line listing.\n\
1195 One argument specifies a line, and ten lines are listed around that line.\n\
1196 Two arguments with comma between specify starting and ending lines to list.\n\
1197 Lines can be specified in these ways:\n\
1198 LINENUM, to list around that line in current file,\n\
1199 FILE:LINENUM, to list around that line in that file,\n\
1200 FUNCTION, to list around beginning of that function,\n\
1201 FILE:FUNCTION, to distinguish among like-named static functions.\n\
1202 *ADDRESS, to list around the line containing that address.\n\
1203 With two args if one is empty it stands for ten lines away from the other arg.");
1204 add_com_alias ("l", "list", class_files
, 0);
1207 (add_set_cmd ("listsize", class_support
, var_uinteger
,
1208 (char *)&lines_to_list
,
1209 "Set number of source lines gdb will list by default.",
This page took 0.057132 seconds and 4 git commands to generate.