Add file offsets to the source cache
authorTom Tromey <tromey@adacore.com>
Mon, 22 Jul 2019 20:31:43 +0000 (14:31 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 6 Aug 2019 14:04:33 +0000 (08:04 -0600)
commitcb44333d99548bbbf7be06387a31877ee9322ab4
tree8ac25ea16ebbc5556d5f1e24940e729169d08bb8
parent872dceaaff9b54764b8f510b549497b9d904b136
Add file offsets to the source cache

Currently, gdb stores the number of lines and an array of file offsets
for the start of each line in struct symtab.  This patch moves this
information to the source cache.  This has two benefits.

First, it allows gdb to read a source file less frequently.
Currently, a source file may be read multiple times: once when
computing the file offsets, once when highlighting, and then pieces
may be read again while printing source lines.  With this change, the
file is read once for its source text and file offsets; and then
perhaps read again if it is evicted from the cache.

Second, if multiple symtabs cover the same source file, then this will
share the file offsets between them.  I'm not sure whether this
happens in practice.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tromey@adacore.com>

* annotate.c (annotate_source_line): Use g_source_cache.
* source-cache.c (source_cache::get_plain_source_lines): Change
parameters.  Populate m_offset_cache.
(source_cache::ensure): New method.
(source_cache::get_line_charpos): New method.
(extract_lines): Move lower.  Change parameters.
(source_cache::get_source_lines): Move lower.
* source-cache.h (class source_cache): Update comment.
<get_line_charpos>: New method.
<get_source_lines>: Update comment.
<clear>: Clear m_offset_cache.
<get_plain_source_lines>: Change parameters.
<ensure>: New method
<m_offset_cache>: New member.
* source.c (forget_cached_source_info_for_objfile): Update.
(info_source_command): Use g_source_cache.
(find_source_lines, open_source_file_with_line_charpos): Remove.
(print_source_lines_base, search_command_helper): Use g_source_cache.
* source.h (open_source_file_with_line_charpos): Don't declare.
* symtab.h (struct symtab) <nlines, line_charpos>: Remove.
* tui/tui-source.c (tui_source_window::do_scroll_vertical):
Use g_source_cache.
gdb/ChangeLog
gdb/annotate.c
gdb/source-cache.c
gdb/source-cache.h
gdb/source.c
gdb/source.h
gdb/symtab.h
gdb/tui/tui-source.c
This page took 0.025106 seconds and 4 git commands to generate.