diff options
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 146 |
1 files changed, 52 insertions, 94 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 4027d4f..10d3d51 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1,6 +1,6 @@ /* General utility routines for GDB, the GNU debugger. - Copyright (C) 1986-2024 Free Software Foundation, Inc. + Copyright (C) 1986-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -54,7 +54,6 @@ #include "top.h" #include "ui.h" #include "main.h" -#include "solist.h" #include "inferior.h" @@ -119,7 +118,7 @@ show_sevenbit_strings (struct ui_file *file, int from_tty, /* String to be printed before warning messages, if any. */ -const char *warning_pre_print = "\nwarning: "; +const char *warning_pre_print = "\n"; bool pagination_enabled = true; static void @@ -176,8 +175,9 @@ vwarning (const char *string, va_list args) term_state.emplace (); target_terminal::ours_for_output (); } - if (warning_pre_print) - gdb_puts (warning_pre_print, gdb_stderr); + gdb_puts (warning_pre_print, gdb_stderr); + print_warning_prefix (gdb_stderr); + gdb_puts (_("warning: "), gdb_stderr); gdb_vprintf (gdb_stderr, string, args); gdb_printf (gdb_stderr, "\n"); } @@ -382,7 +382,7 @@ internal_vproblem (struct internal_problem *problem, #endif /* Create a string containing the full error/warning message. Need - to call query with this full string, as otherwize the reason + to call query with this full string, as otherwise the reason (error/warning) and question become separated. Format using a style similar to a compiler error message. Include extra detail so that the user knows that they are living on the edge. */ @@ -1401,24 +1401,31 @@ pager_file::emit_style_escape (const ui_file_style &style) { m_applied_style = style; if (m_paging) - m_stream->emit_style_escape (style); + { + /* Previous style changes will have been sent to m_stream via + escape sequences encoded in the m_wrap_buffer. As a result, + the m_stream->m_applied_style will not have been updated. + + If we now use m_stream->emit_style_escape, then the required + style might not actually be emitted as the requested style + might happen to match the out of date value in + m_stream->m_applied_style. + + Instead, send the style change directly using m_stream->puts. + + However, we track what style is currently applied to the + underlying stream in m_stream_style, this is updated whenever + m_wrap_buffer is flushed to the underlying stream. And so, if + the style we are applying matches what we know is currently + applied to the underlying stream, then we can skip sending + this style to the stream. */ + this->set_stream_style (m_applied_style); + } else m_wrap_buffer.append (style.to_ansi ()); } } -/* See pager.h. */ - -void -pager_file::reset_style () -{ - if (can_emit_style_escape ()) - { - m_applied_style = ui_file_style (); - m_wrap_buffer.append (m_applied_style.to_ansi ()); - } -} - /* Wait, so the user can read what's on the screen. Prompt the user to continue by pressing RETURN. 'q' is also provided because telling users what to do in the prompt is more user-friendly than @@ -1436,8 +1443,8 @@ pager_file::prompt_for_continue () scoped_restore save_paging = make_scoped_restore (&m_paging, true); - /* Clear the current styling. */ - m_stream->emit_style_escape (ui_file_style ()); + /* Clear the current styling on ourselves and the managed stream. */ + this->emit_style_escape (ui_file_style ()); if (annotation_level > 1) m_stream->puts (("\n\032\032pre-prompt-for-continue\n")); @@ -1520,6 +1527,7 @@ pager_file::flush_wrap_buffer () if (!m_paging && !m_wrap_buffer.empty ()) { m_stream->puts (m_wrap_buffer.c_str ()); + m_stream_style = m_applied_style; m_wrap_buffer.clear (); } } @@ -1636,10 +1644,7 @@ begin_line (void) void pager_file::puts (const char *linebuffer) { - const char *lineptr; - - if (linebuffer == 0) - return; + gdb_assert (linebuffer != nullptr); /* Don't do any filtering or wrapping if both are disabled. */ if (batch_flag @@ -1670,8 +1675,7 @@ pager_file::puts (const char *linebuffer) when this is necessary; prompt user for new page when this is necessary. */ - lineptr = linebuffer; - while (*lineptr) + while (*linebuffer != '\0') { /* Possible new page. Note that PAGINATION_DISABLED_FOR_COMMAND might be set during this loop, so we must continue to check @@ -1681,39 +1685,39 @@ pager_file::puts (const char *linebuffer) && lines_printed >= lines_allowed) prompt_for_continue (); - while (*lineptr && *lineptr != '\n') + while (*linebuffer != '\0' && *linebuffer != '\n') { int skip_bytes; /* Print a single line. */ - if (*lineptr == '\t') + if (*linebuffer == '\t') { m_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. */ chars_printed = ((chars_printed >> 3) + 1) << 3; - lineptr++; + linebuffer++; } - else if (*lineptr == '\033' - && skip_ansi_escape (lineptr, &skip_bytes)) + else if (*linebuffer == '\033' + && skip_ansi_escape (linebuffer, &skip_bytes)) { - m_wrap_buffer.append (lineptr, skip_bytes); + m_wrap_buffer.append (linebuffer, skip_bytes); /* Note that we don't consider this a character, so we don't increment chars_printed here. */ - lineptr += skip_bytes; + linebuffer += skip_bytes; } - else if (*lineptr == '\r') + else if (*linebuffer == '\r') { - m_wrap_buffer.push_back (*lineptr); + m_wrap_buffer.push_back (*linebuffer); chars_printed = 0; - lineptr++; + linebuffer++; } else { - m_wrap_buffer.push_back (*lineptr); + m_wrap_buffer.push_back (*linebuffer); chars_printed++; - lineptr++; + linebuffer++; } if (chars_printed >= chars_per_line) @@ -1740,7 +1744,8 @@ pager_file::puts (const char *linebuffer) current applied style to how it was at the WRAP_COLUMN location. */ m_applied_style = m_wrap_style; - m_stream->emit_style_escape (ui_file_style ()); + this->set_stream_style (ui_file_style ()); + /* If we aren't actually wrapping, don't output newline -- if chars_per_line is right, we probably just overflowed anyway; if it's wrong, @@ -1768,7 +1773,7 @@ pager_file::puts (const char *linebuffer) /* Having finished inserting the wrapping we should restore the style as it was at the WRAP_COLUMN. */ - m_stream->emit_style_escape (m_wrap_style); + this->set_stream_style (m_wrap_style); /* The WRAP_BUFFER will still contain content, and that content might set some alternative style. Restore @@ -1783,17 +1788,17 @@ pager_file::puts (const char *linebuffer) m_wrap_column = 0; /* And disable fancy wrap */ } else if (did_paginate) - m_stream->emit_style_escape (save_style); + this->emit_style_escape (save_style); } } - if (*lineptr == '\n') + if (*linebuffer == '\n') { chars_printed = 0; wrap_here (0); /* Spit out chars, cancel further wraps. */ lines_printed++; m_stream->puts ("\n"); - lineptr++; + linebuffer++; } } @@ -1804,7 +1809,7 @@ void pager_file::write (const char *buf, long length_buf) { /* We have to make a string here because the pager uses - skip_ansi_escape, which requires NUL-termination. */ + examine_ansi_escape, which requires NUL-termination. */ std::string str (buf, length_buf); this->puts (str.c_str ()); } @@ -3348,7 +3353,7 @@ gdb_argv_as_array_view_test () argument. */ std::string -ldirname (const char *filename) +gdb_ldirname (const char *filename) { std::string dirname; const char *base = lbasename (filename); @@ -3390,51 +3395,6 @@ parse_pid_to_attach (const char *args) return pid; } -/* Substitute all occurrences of string FROM by string TO in *STRINGP. *STRINGP - must come from xrealloc-compatible allocator and it may be updated. FROM - needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be - located at the start or end of *STRINGP. */ - -void -substitute_path_component (char **stringp, const char *from, const char *to) -{ - char *string = *stringp, *s; - const size_t from_len = strlen (from); - const size_t to_len = strlen (to); - - for (s = string;;) - { - s = strstr (s, from); - if (s == NULL) - break; - - if ((s == string || IS_DIR_SEPARATOR (s[-1]) - || s[-1] == DIRNAME_SEPARATOR) - && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len]) - || s[from_len] == DIRNAME_SEPARATOR)) - { - char *string_new; - - string_new - = (char *) xrealloc (string, (strlen (string) + to_len + 1)); - - /* Relocate the current S pointer. */ - s = s - string + string_new; - string = string_new; - - /* Replace from by to. */ - memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1); - memcpy (s, to, to_len); - - s += to_len; - } - else - s++; - } - - *stringp = string; -} - #ifdef HAVE_WAITPID #ifdef SIGALRM @@ -3756,9 +3716,7 @@ test_assign_set_return_if_changed () } #endif -void _initialize_utils (); -void -_initialize_utils () +INIT_GDB_FILE (utils) { add_setshow_uinteger_cmd ("width", class_support, &chars_per_line, _("\ Set number of characters where GDB should wrap lines of its output."), _("\ |