summaryrefslogtreecommitdiff
path: root/gdb/tui/tui-source.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-07-22 14:31:43 -0600
committerTom Tromey <tromey@adacore.com>2019-08-06 08:04:33 -0600
commitcb44333d99548bbbf7be06387a31877ee9322ab4 (patch)
tree8ac25ea16ebbc5556d5f1e24940e729169d08bb8 /gdb/tui/tui-source.c
parent872dceaaff9b54764b8f510b549497b9d904b136 (diff)
downloadbinutils-gdb-cb44333d99548bbbf7be06387a31877ee9322ab4.tar.gz
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.
Diffstat (limited to 'gdb/tui/tui-source.c')
-rw-r--r--gdb/tui/tui-source.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index f0bac24bfea..619d9374500 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -251,7 +251,9 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
l.loa = LOA_LINE;
l.u.line_no = content[0].line_or_addr.u.line_no
+ num_to_scroll;
- if (l.u.line_no > s->nlines)
+ const std::vector<off_t> *offsets;
+ if (g_source_cache.get_line_charpos (s, &offsets)
+ && l.u.line_no > offsets->size ())
/* line = s->nlines - win_info->content_size + 1; */
/* elz: fix for dts 23398. */
l.u.line_no = content[0].line_or_addr.u.line_no;