aboutsummaryrefslogtreecommitdiff
path: root/gdb/source.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-10-09 22:21:05 -0600
committerTom Tromey <tom@tromey.com>2018-12-28 12:49:54 -0700
commit62f29fda90cf1d5a1899f57ef78452471c707fd6 (patch)
tree4d2e519c41de4248f7b4f169f8f379f73f3f0a51 /gdb/source.c
parent4a3045920bbe4e50a0f4920b0fdc4e88ef23015c (diff)
downloadbinutils-62f29fda90cf1d5a1899f57ef78452471c707fd6.zip
binutils-62f29fda90cf1d5a1899f57ef78452471c707fd6.tar.gz
binutils-62f29fda90cf1d5a1899f57ef78452471c707fd6.tar.bz2
Highlight source code using GNU Source Highlight
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.
Diffstat (limited to 'gdb/source.c')
-rw-r--r--gdb/source.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/gdb/source.c b/gdb/source.c
index 575e46c..66ef883 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -45,6 +45,7 @@
#include "common/scoped_fd.h"
#include <algorithm>
#include "common/pathstuff.h"
+#include "source-cache.h"
#define OPEN_MODE (O_RDONLY | O_BINARY)
#define FDOPEN_MODE FOPEN_RB
@@ -393,6 +394,7 @@ forget_cached_source_info (void)
forget_cached_source_info_for_objfile (objfile);
}
+ g_source_cache.clear ();
last_source_visited = NULL;
}
@@ -1344,25 +1346,18 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
last_source_error = 0;
- if (s->line_charpos == 0)
- find_source_lines (s, desc.get ());
-
- if (line < 1 || line > s->nlines)
+ std::string lines;
+ if (!g_source_cache.get_source_lines (s, line, stopline - 1, &lines))
error (_("Line number %d out of range; %s has %d lines."),
line, symtab_to_filename_for_display (s), s->nlines);
- if (lseek (desc.get (), s->line_charpos[line - 1], 0) < 0)
- perror_with_name (symtab_to_filename_for_display (s));
-
- gdb_file_up stream = desc.to_file (FDOPEN_MODE);
- clearerr (stream.get ());
-
+ const char *iter = lines.c_str ();
while (nlines-- > 0)
{
char buf[20];
- c = fgetc (stream.get ());
- if (c == EOF)
+ c = *iter++;
+ if (c == '\0')
break;
last_line_listed = current_source_line;
if (flags & PRINT_SOURCE_LINES_FILENAME)
@@ -1374,7 +1369,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
uiout->text (buf);
do
{
- if (c < 040 && c != '\t' && c != '\n' && c != '\r')
+ if (c < 040 && c != '\t' && c != '\n' && c != '\r' && c != '\033')
{
xsnprintf (buf, sizeof (buf), "^%c", c + 0100);
uiout->text (buf);
@@ -1384,12 +1379,13 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
else if (c == '\r')
{
/* Skip a \r character, but only before a \n. */
- int c1 = fgetc (stream.get ());
-
- if (c1 != '\n')
+ if (iter[1] == '\n')
+ {
+ ++iter;
+ c = '\n';
+ }
+ else
printf_filtered ("^%c", c + 0100);
- if (c1 != EOF)
- ungetc (c1, stream.get ());
}
else
{
@@ -1397,8 +1393,12 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
uiout->text (buf);
}
}
- while (c != '\n' && (c = fgetc (stream.get ())) >= 0);
+ while (c != '\n' && (c = *iter++) != '\0');
+ if (c == '\0')
+ break;
}
+ if (lines.back () != '\n')
+ uiout->text ("\n");
}
/* Show source lines from the file of symtab S, starting with line