aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-cmds.c2
-rw-r--r--gdb/cli/cli-decode.c46
-rw-r--r--gdb/cli/cli-decode.h2
-rw-r--r--gdb/cli/cli-dump.c2
4 files changed, 21 insertions, 31 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 7e13ef8..9a5021f 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -833,7 +833,7 @@ echo_command (const char *text, int from_tty)
gdb_printf ("%c", c);
}
- gdb_stdout->reset_style ();
+ gdb_stdout->emit_style_escape (ui_file_style ());
/* Force this output to appear now. */
gdb_flush (gdb_stdout);
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index c486306..48a3466 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -2041,40 +2041,28 @@ void
print_doc_line (struct ui_file *stream, const char *str,
bool for_value_prefix)
{
- static char *line_buffer = 0;
- static int line_size;
- const char *p;
+ const char *p = strchr (str, '\n');
- if (!line_buffer)
- {
- line_size = 80;
- line_buffer = (char *) xmalloc (line_size);
- }
+ /* Only copy the input string if we really need to. */
+ std::optional<std::string> line_buffer;
+ if (p != nullptr)
+ line_buffer = std::string (str, p);
+ else if (for_value_prefix)
+ line_buffer = str;
- /* Searches for the first end of line or the end of STR. */
- p = str;
- while (*p && *p != '\n')
- p++;
- if (p - str > line_size - 1)
- {
- line_size = p - str + 1;
- xfree (line_buffer);
- line_buffer = (char *) xmalloc (line_size);
- }
- strncpy (line_buffer, str, p - str);
if (for_value_prefix)
{
- if (islower (line_buffer[0]))
- line_buffer[0] = toupper (line_buffer[0]);
- gdb_assert (p > str);
- if (line_buffer[p - str - 1] == '.')
- line_buffer[p - str - 1] = '\0';
- else
- line_buffer[p - str] = '\0';
+ char &c = (*line_buffer)[0];
+ if (islower (c))
+ c = toupper (c);
+ if (line_buffer->back () == '.')
+ line_buffer->pop_back ();
}
- else
- line_buffer[p - str] = '\0';
- gdb_puts (line_buffer, stream);
+
+ gdb_puts (line_buffer.has_value ()
+ ? line_buffer->c_str ()
+ : str,
+ stream);
}
/* Print one-line help for command C.
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 217afbc..9be446f 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -62,6 +62,8 @@ struct cmd_list_element
type (not_set_cmd),
doc (doc_)
{
+ gdb_assert (name != nullptr);
+ gdb_assert (doc != nullptr);
memset (&function, 0, sizeof (function));
}
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 0ecc7b0..3055734 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -397,7 +397,7 @@ restore_one_section (bfd *ibfd, asection *isec,
if (sec_end <= load_start
|| (load_end > 0 && sec_start >= load_end))
{
- /* No, no useable data in this section. */
+ /* No, no usable data in this section. */
gdb_printf (_("skipping section %s...\n"),
bfd_section_name (isec));
return;