-\f
-/* Create and initialize the table S->line_charpos that records
- the positions of the lines in the source file, which is assumed
- to be open on descriptor DESC.
- All set S->nlines to the number of such lines. */
-
-void
-find_source_lines (struct symtab *s, int desc)
-{
- struct stat st;
- char *data, *p, *end;
- int nlines = 0;
- int lines_allocated = 1000;
- int *line_charpos;
- long mtime = 0;
- int size;
-
- gdb_assert (s);
- line_charpos = XNEWVEC (int, lines_allocated);
- if (fstat (desc, &st) < 0)
- perror_with_name (symtab_to_filename_for_display (s));
-
- if (SYMTAB_OBJFILE (s) != NULL && SYMTAB_OBJFILE (s)->obfd != NULL)
- mtime = SYMTAB_OBJFILE (s)->mtime;
- else if (exec_bfd)
- mtime = exec_bfd_mtime;
-
- if (mtime && mtime < st.st_mtime)
- warning (_("Source file is more recent than executable."));
-
- {
- struct cleanup *old_cleanups;
-
- /* st_size might be a large type, but we only support source files whose
- size fits in an int. */
- size = (int) st.st_size;
-
- /* Use malloc, not alloca, because this may be pretty large, and we may
- run into various kinds of limits on stack size. */
- data = (char *) xmalloc (size);
- old_cleanups = make_cleanup (xfree, data);
-
- /* Reassign `size' to result of read for systems where \r\n -> \n. */
- size = myread (desc, data, size);
- if (size < 0)
- perror_with_name (symtab_to_filename_for_display (s));
- end = data + size;
- p = data;
- line_charpos[0] = 0;
- nlines = 1;
- while (p != end)
- {
- if (*p++ == '\n'
- /* A newline at the end does not start a new line. */
- && p != end)
- {
- if (nlines == lines_allocated)
- {
- lines_allocated *= 2;
- line_charpos =
- (int *) xrealloc ((char *) line_charpos,
- sizeof (int) * lines_allocated);
- }
- line_charpos[nlines++] = p - data;
- }
- }
- do_cleanups (old_cleanups);
- }
-
- s->nlines = nlines;
- s->line_charpos =
- (int *) xrealloc ((char *) line_charpos, nlines * sizeof (int));
-
-}
-
-\f
-
-/* Get full pathname and line number positions for a symtab.
- Return nonzero if line numbers may have changed.
- Set *FULLNAME to actual name of the file as found by `openp',
- or to 0 if the file is not found. */
-
-static int
-get_filename_and_charpos (struct symtab *s, char **fullname)
-{
- int desc, linenums_changed = 0;
- struct cleanup *cleanups;
-
- desc = open_source_file (s);
- if (desc < 0)
- {
- if (fullname)
- *fullname = NULL;
- return 0;
- }
- cleanups = make_cleanup_close (desc);
- if (fullname)
- *fullname = s->fullname;
- if (s->line_charpos == 0)
- linenums_changed = 1;
- if (linenums_changed)
- find_source_lines (s, desc);
- do_cleanups (cleanups);
- return linenums_changed;
-}
-
-/* Print text describing the full name of the source file S
- and the line number LINE and its corresponding character position.
- The text starts with two Ctrl-z so that the Emacs-GDB interface
- can easily find it.