aboutsummaryrefslogtreecommitdiff
path: root/gdb/source-cache.h
AgeCommit message (Collapse)AuthorFilesLines
2022-01-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker1-1/+1
This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
2021-01-01Update copyright year range in all GDB filesJoel Brobecker1-1/+1
This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
2020-01-01Update copyright year range in all GDB files.Joel Brobecker1-1/+1
gdb/ChangeLog: Update copyright year range in all GDB files.
2019-08-06Add file offsets to the source cacheTom Tromey1-11/+41
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.
2019-08-06Save plain text in the source cacheTom Tromey1-5/+4
Currently the source cache will only store highlighted text. However, there's no reason it could not also store plain text, when styling is turned off. This patch makes this change. This also simplifies the source cache code somewhat. gdb/ChangeLog 2019-08-06 Tom Tromey <tromey@adacore.com> * source-cache.c (source_cache::get_plain_source_lines): Remove "first_line" and "last_line" parameters. (source_cache::get_source_lines): Cache plain text. * source-cache.h (class source_cache) <get_plain_source_lines>: Update.
2019-08-06Fix latent bug in source cacheTom Tromey1-6/+0
The source cache was not returning the final \n of the requested range of lines. This caused regressions with later patches in this series, so this patch pre-emptively fixes the bug. This adds a self-test of "extract_lines" to the source cache code. To make it simpler to test, I changed extract_lines to be a static function, and changed it's API a bit. gdb/ChangeLog 2019-08-06 Tom Tromey <tromey@adacore.com> * source-cache.c (extract_lines): No longer a method. Changed type of parameter. Include final newline. (selftests::extract_lines_test): New function. (_initialize_source_cache): Likewise. * source-cache.h (class source_cache) <extract_lines>: Don't declare.
2019-03-14Avoid a crash in source_cache::extract_linesTom Tromey1-3/+4
If the first requested line is larger than the number of lines in the source buffer, source_cache::extract_lines could crash, because it would try to pass string::npos" to string::substr. This patch avoids the crash by checking for this case. This version of the patch changes get_source_lines to return std::string. gdb/ChangeLog 2019-03-14 Tom Tromey <tromey@adacore.com> * source-cache.h (class source_cache) <get_source_lines>: Return std::string. * source-cache.c (source_cache::extract_lines): Handle case where first_pos==npos. Return std::string. (source_cache::get_source_lines): Update.
2019-01-22Rename "lines" parameter in source-cache.hTom Tromey1-5/+5
A compile in the TUI somehow had "lines" defined as a macro. This caused a compile error when including source-cache.h after whatever header did that. I tracked this down to a #define in /usr/include/term.h, so I just changed source-cache.h to avoid the clash. gdb/ChangeLog 2019-01-22 Tom Tromey <tom@tromey.com> * source-cache.h (class source_cache) <get_source_lines, get_plain_source_lines, extract_lines>: Rename "lines" parameter.
2019-01-01Update copyright year range in all GDB files.Joel Brobecker1-1/+1
This commit applies all changes made after running the gdb/copyright.py script. Note that one file was flagged by the script, due to an invalid copyright header (gdb/unittests/basic_string_view/element_access/char/empty.cc). As the file was copied from GCC's libstdc++-v3 testsuite, this commit leaves this file untouched for the time being; a patch to fix the header was sent to gcc-patches first. gdb/ChangeLog: Update copyright year range in all GDB files.
2018-12-28Highlight source code using GNU Source HighlightTom Tromey1-0/+79
This changes gdb to highlight source using GNU Source Highlight, if it is available. This affects the output of the "list" command and also the TUI source window. No new test because I didn't see a way to make it work when Source Highlight is not found. gdb/ChangeLog 2018-12-28 Tom Tromey <tom@tromey.com> * utils.h (can_emit_style_escape): Declare. * utils.c (can_emit_style_escape): No longer static. * cli/cli-style.c (set_style_enabled): New function. (_initialize_cli_style): Use it. * tui/tui-winsource.c (tui_show_source_line): Use tui_puts. (tui_alloc_source_buffer): Change how source lines are allocated. * tui/tui-source.c (copy_source_line): New function. (tui_set_source_content): Use source cache. * tui/tui-io.h (tui_puts): Update. * tui/tui-io.c (tui_puts_internal): Add window parameter. (tui_puts): Likewise. (tui_redisplay_readline): Update. * tui/tui-data.c (free_content_elements): Change how source window contents are freed. * source.c (forget_cached_source_info): Clear the source cache. (print_source_lines_base): Use the source cache. * source-cache.h: New file. * source-cache.c: New file. * configure.ac: Check for GNU Source Highlight library. * configure: Update. * config.in: Update. * Makefile.in (SRCHIGH_LIBS, SRCHIGH_CFLAGS): New variables. (INTERNAL_CFLAGS_BASE): Add SRCHIGH_CFLAGS. (CLIBS): Add SRCHIGH_LIBS. (COMMON_SFILES): Add source-cache.c. (HFILES_NO_SRCDIR): Add source-cache.h.