summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
94f2c73)
Currently wrap buffering is implemented by allocating a string that is
the same width as the window, and then writing characters into it.
However, if gdb emits terminal escapes, then these could possibly
overflow the buffer.
To prevent this, change the wrap buffer to be a std::string and update
the various uses.
This also changes utils.c to always emit characters to the wrap
buffer. This simplifies future patches which emit terminal escape
sequences, and also makes it possible for the "echo" and "printf"
commands to be used to emit terminal escapes and have these work in
the TUI.
gdb/ChangeLog
2018-12-28 Tom Tromey <tom@tromey.com>
* utils.c (filter_initialized): New global.
(wrap_buffer): Now a std::string.
(wrap_pointer): Remove.
(flush_wrap_buffer): New function.
(filtered_printing_initialized, set_width, wrap_here)
(fputs_maybe_filtered): Update.
+2018-12-28 Tom Tromey <tom@tromey.com>
+
+ * utils.c (filter_initialized): New global.
+ (wrap_buffer): Now a std::string.
+ (wrap_pointer): Remove.
+ (flush_wrap_buffer): New function.
+ (filtered_printing_initialized, set_width, wrap_here)
+ (fputs_maybe_filtered): Update.
+
2018-12-28 Eli Zaretskii <eliz@gnu.org>
* coffread.c (coff_symtab_read): Don't record in minsyms symbols
2018-12-28 Eli Zaretskii <eliz@gnu.org>
* coffread.c (coff_symtab_read): Don't record in minsyms symbols
the end of the line, we spit out a newline, the indent, and then
the buffered output. */
the end of the line, we spit out a newline, the indent, and then
the buffered output. */
-/* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
- are waiting to be output (they have already been counted in chars_printed).
- When wrap_buffer[0] is null, the buffer is empty. */
-static char *wrap_buffer;
+static bool filter_initialized = false;
-/* Pointer in wrap_buffer to the next character to fill. */
-static char *wrap_pointer;
+/* Contains characters which are waiting to be output (they have
+ already been counted in chars_printed). */
+static std::string wrap_buffer;
/* String to indent by if the wrap occurs. Must not be NULL if wrap_column
is non-zero. */
/* String to indent by if the wrap occurs. Must not be NULL if wrap_column
is non-zero. */
int
filtered_printing_initialized (void)
{
int
filtered_printing_initialized (void)
{
- return wrap_buffer != NULL;
+ return filter_initialized;
}
set_batch_flag_and_restore_page_info::set_batch_flag_and_restore_page_info ()
}
set_batch_flag_and_restore_page_info::set_batch_flag_and_restore_page_info ()
rl_set_screen_size (rows, cols);
}
rl_set_screen_size (rows, cols);
}
-/* Reinitialize WRAP_BUFFER according to the current value of
- CHARS_PER_LINE. */
+/* Reinitialize WRAP_BUFFER. */
static void
set_width (void)
static void
set_width (void)
if (chars_per_line == 0)
init_page_info ();
if (chars_per_line == 0)
init_page_info ();
- if (!wrap_buffer)
- {
- wrap_buffer = (char *) xmalloc (chars_per_line + 2);
- wrap_buffer[0] = '\0';
- }
- else
- wrap_buffer = (char *) xrealloc (wrap_buffer, chars_per_line + 2);
- wrap_pointer = wrap_buffer; /* Start it at the beginning. */
+ wrap_buffer.clear ();
+ filter_initialized = true;
pagination_disabled_for_command = false;
}
pagination_disabled_for_command = false;
}
+/* Flush the wrap buffer to STREAM, if necessary. */
+
+static void
+flush_wrap_buffer (struct ui_file *stream)
+{
+ if (!wrap_buffer.empty ())
+ {
+ fputs_unfiltered (wrap_buffer.c_str (), stream);
+ wrap_buffer.clear ();
+ }
+}
+
/* Indicate that if the next sequence of characters overflows the line,
a newline should be inserted here rather than when it hits the end.
If INDENT is non-null, it is a string to be printed to indent the
/* Indicate that if the next sequence of characters overflows the line,
a newline should be inserted here rather than when it hits the end.
If INDENT is non-null, it is a string to be printed to indent the
wrap_here (const char *indent)
{
/* This should have been allocated, but be paranoid anyway. */
wrap_here (const char *indent)
{
/* This should have been allocated, but be paranoid anyway. */
+ if (!filter_initialized)
internal_error (__FILE__, __LINE__,
_("failed internal consistency check"));
internal_error (__FILE__, __LINE__,
_("failed internal consistency check"));
- if (wrap_buffer[0])
- {
- *wrap_pointer = '\0';
- fputs_unfiltered (wrap_buffer, gdb_stdout);
- }
- wrap_pointer = wrap_buffer;
- wrap_buffer[0] = '\0';
+ flush_wrap_buffer (gdb_stdout);
if (chars_per_line == UINT_MAX) /* No line overflow checking. */
{
wrap_column = 0;
if (chars_per_line == UINT_MAX) /* No line overflow checking. */
{
wrap_column = 0;
|| top_level_interpreter () == NULL
|| top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ())
{
|| top_level_interpreter () == NULL
|| top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ())
{
+ flush_wrap_buffer (stream);
fputs_unfiltered (linebuffer, stream);
return;
}
fputs_unfiltered (linebuffer, stream);
return;
}
/* Print a single line. */
if (*lineptr == '\t')
{
/* Print a single line. */
if (*lineptr == '\t')
{
- if (wrap_column)
- *wrap_pointer++ = '\t';
- else
- fputc_unfiltered ('\t', stream);
+ wrap_buffer.push_back ('\t');
/* Shifting right by 3 produces the number of tab stops
we have already passed, and then adding one and
shifting left 3 advances to the next tab stop. */
/* Shifting right by 3 produces the number of tab stops
we have already passed, and then adding one and
shifting left 3 advances to the next tab stop. */
- if (wrap_column)
- *wrap_pointer++ = *lineptr;
- else
- fputc_unfiltered (*lineptr, stream);
+ wrap_buffer.push_back (*lineptr);
chars_printed++;
lineptr++;
}
chars_printed++;
lineptr++;
}
if (wrap_column)
{
fputs_unfiltered (wrap_indent, stream);
if (wrap_column)
{
fputs_unfiltered (wrap_indent, stream);
- *wrap_pointer = '\0'; /* Null-terminate saved stuff, */
- fputs_unfiltered (wrap_buffer, stream); /* and eject it. */
+ flush_wrap_buffer (stream);
/* FIXME, this strlen is what prevents wrap_indent from
containing tabs. However, if we recurse to print it
and count its chars, we risk trouble if wrap_indent is
/* FIXME, this strlen is what prevents wrap_indent from
containing tabs. However, if we recurse to print it
and count its chars, we risk trouble if wrap_indent is
if we are printing a long string. */
chars_printed = strlen (wrap_indent)
+ (save_chars - wrap_column);
if we are printing a long string. */
chars_printed = strlen (wrap_indent)
+ (save_chars - wrap_column);
- wrap_pointer = wrap_buffer; /* Reset buffer */
- wrap_buffer[0] = '\0';
wrap_column = 0; /* And disable fancy wrap */
}
}
wrap_column = 0; /* And disable fancy wrap */
}
}