summaryrefslogtreecommitdiff
path: root/gdb/tui/tui-stack.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-10-28 23:08:08 +0100
committerPedro Alves <palves@redhat.com>2016-11-17 03:10:00 +0000
commit3d4ed53ca597f71c72ff0db995468578482a0ee0 (patch)
tree23c91cebc43c07ae98f0a494642734aa8abc83f5 /gdb/tui/tui-stack.c
parent05c10af4c15d9501046f6740cdf1173fbd9c3a2e (diff)
downloadbinutils-gdb-3d4ed53ca597f71c72ff0db995468578482a0ee0.tar.gz
Eliminate make_cleanup_ui_file_deleteusers/palves/cxx-eliminate-cleanups
And now that ui_file_as_string is in, let's eliminate it. :-) Makes ui_file a real C++ hierarchy. mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows almost 1k loc dropped.) string_file has a string() method that gives you a direct reference to the internal std::string. This is what replaces old (well, new) ui_file_as_string, which used to alway return a new copy of the same data the stream had inside.. With direct access via a writable reference, we can instead move the string out of the string_stream. Note I needed a tweak on scoped_restore. That one should probably be split out to a separate patch. This exposed the need to make use of gnulib namespace support. Otherwise, making use of read/write/printf/puts/etc symbol names will clash on systems where gnulib replaces those functions, due to '#define foo rpl_foo'.
Diffstat (limited to 'gdb/tui/tui-stack.c')
-rw-r--r--gdb/tui/tui-stack.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index b6cf144c1dd..09de6b72235 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -68,12 +68,9 @@ tui_make_status_line (struct tui_locator_element *loc)
int status_size;
int i, proc_width;
const char *pid_name;
- const char *pc_buf;
int target_width;
int pid_width;
int line_width;
- int pc_width;
- struct ui_file *pc_out;
if (ptid_equal (inferior_ptid, null_ptid))
pid_name = "No process";
@@ -102,12 +99,14 @@ tui_make_status_line (struct tui_locator_element *loc)
line_width = MIN_LINE_WIDTH;
/* Translate PC address. */
- pc_out = tui_sfileopen (128);
+ string_file pc_out;
+
fputs_filtered (loc->gdbarch? paddress (loc->gdbarch, loc->addr) : "??",
- pc_out);
- pc_buf = tui_file_get_strbuf (pc_out);
- pc_width = strlen (pc_buf);
-
+ &pc_out);
+
+ const char *pc_buf = pc_out.c_str ();
+ int pc_width = pc_out.size ();
+
/* First determine the amount of proc name width we have available.
The +1 are for a space separator between fields.
The -1 are to take into account the \0 counted by sizeof. */
@@ -204,7 +203,6 @@ tui_make_status_line (struct tui_locator_element *loc)
string[i] = ' ';
string[status_size] = (char) 0;
- ui_file_delete (pc_out);
return string;
}
@@ -215,21 +213,21 @@ static char*
tui_get_function_from_frame (struct frame_info *fi)
{
static char name[256];
- struct ui_file *stream = tui_sfileopen (256);
- char *p;
+ string_file stream;
print_address_symbolic (get_frame_arch (fi), get_frame_pc (fi),
- stream, demangle, "");
- p = tui_file_get_strbuf (stream);
+ &stream, demangle, "");
/* Use simple heuristics to isolate the function name. The symbol
can be demangled and we can have function parameters. Remove
them because the status line is too short to display them. */
- if (*p == '<')
- p++;
- strncpy (name, p, sizeof (name) - 1);
+ const char *d = stream.c_str ();
+ if (*d == '<')
+ d++;
+ strncpy (name, d, sizeof (name) - 1);
name[sizeof (name) - 1] = 0;
- p = strchr (name, '(');
+
+ char *p = strchr (name, '(');
if (!p)
p = strchr (name, '>');
if (p)
@@ -237,7 +235,6 @@ tui_get_function_from_frame (struct frame_info *fi)
p = strchr (name, '+');
if (p)
*p = 0;
- ui_file_delete (stream);
return name;
}