aboutsummaryrefslogtreecommitdiff
path: root/gdb/annotate.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/annotate.c
parent872dceaaff9b54764b8f510b549497b9d904b136 (diff)
downloadgdb-cb44333d99548bbbf7be06387a31877ee9322ab4.zip
gdb-cb44333d99548bbbf7be06387a31877ee9322ab4.tar.gz
gdb-cb44333d99548bbbf7be06387a31877ee9322ab4.tar.bz2
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/annotate.c')
-rw-r--r--gdb/annotate.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 8d8a019..3011b26 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -28,6 +28,7 @@
#include "top.h"
#include "source.h"
#include "objfiles.h"
+#include "source-cache.h"
/* Prototypes for local functions. */
@@ -440,15 +441,15 @@ annotate_source_line (struct symtab *s, int line, int mid_statement,
{
if (annotation_level > 0)
{
- if (s->line_charpos == nullptr)
- open_source_file_with_line_charpos (s);
- if (s->fullname == nullptr)
+ const std::vector<off_t> *offsets;
+ if (!g_source_cache.get_line_charpos (s, &offsets))
return;
+
/* Don't index off the end of the line_charpos array. */
- if (line > s->nlines)
+ if (line > offsets->size ())
return;
- annotate_source (s->fullname, line, s->line_charpos[line - 1],
+ annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
mid_statement, get_objfile_arch (SYMTAB_OBJFILE (s)),
pc);
}