summaryrefslogtreecommitdiff
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
parent05c10af4c15d9501046f6740cdf1173fbd9c3a2e (diff)
downloadbinutils-gdb-users/palves/cxx-eliminate-cleanups.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'.
-rw-r--r--gdb/ada-lang.c12
-rw-r--r--gdb/ada-valprint.c9
-rw-r--r--gdb/ada-varobj.c23
-rw-r--r--gdb/arm-tdep.c14
-rw-r--r--gdb/breakpoint.c97
-rw-r--r--gdb/c-exp.y8
-rw-r--r--gdb/cli/cli-logging.c31
-rw-r--r--gdb/cli/cli-setshow.c36
-rw-r--r--gdb/common/scoped_restore.h11
-rw-r--r--gdb/compile/compile-c-support.c62
-rw-r--r--gdb/compile/compile-c-symbols.c21
-rw-r--r--gdb/compile/compile-internal.h2
-rw-r--r--gdb/compile/compile-loc2c.c107
-rw-r--r--gdb/compile/compile.c9
-rw-r--r--gdb/compile/compile.h4
-rw-r--r--gdb/cp-support.c38
-rw-r--r--gdb/disasm.c46
-rw-r--r--gdb/disasm.h2
-rw-r--r--gdb/dummy-frame.c9
-rw-r--r--gdb/dwarf2loc.c6
-rw-r--r--gdb/dwarf2loc.h2
-rw-r--r--gdb/dwarf2read.c48
-rw-r--r--gdb/event-top.c4
-rw-r--r--gdb/gdbarch.c32
-rwxr-xr-xgdb/gdbarch.sh20
-rw-r--r--gdb/gdbtypes.c3
-rw-r--r--gdb/guile/scm-breakpoint.c12
-rw-r--r--gdb/guile/scm-disasm.c16
-rw-r--r--gdb/guile/scm-frame.c9
-rw-r--r--gdb/guile/scm-ports.c96
-rw-r--r--gdb/guile/scm-type.c14
-rw-r--r--gdb/guile/scm-value.c29
-rw-r--r--gdb/i386-tdep.c7
-rw-r--r--gdb/infcmd.c10
-rw-r--r--gdb/infrun.c36
-rw-r--r--gdb/language.c38
-rw-r--r--gdb/location.c43
-rw-r--r--gdb/main.c2
-rw-r--r--gdb/maint.c9
-rw-r--r--gdb/mi/mi-cmd-stack.c17
-rw-r--r--gdb/mi/mi-common.h12
-rw-r--r--gdb/mi/mi-console.c136
-rw-r--r--gdb/mi/mi-console.h36
-rw-r--r--gdb/mi/mi-interp.c24
-rw-r--r--gdb/mi/mi-main.c61
-rw-r--r--gdb/mi/mi-out.c8
-rw-r--r--gdb/printcmd.c10
-rw-r--r--gdb/psymtab.c19
-rw-r--r--gdb/python/py-arch.c21
-rw-r--r--gdb/python/py-breakpoint.c13
-rw-r--r--gdb/python/py-frame.c9
-rw-r--r--gdb/python/py-framefilter.c32
-rw-r--r--gdb/python/py-type.c19
-rw-r--r--gdb/python/py-unwind.c24
-rw-r--r--gdb/python/py-value.c16
-rw-r--r--gdb/record-btrace.c8
-rw-r--r--gdb/regcache.c9
-rw-r--r--gdb/reggroups.c9
-rw-r--r--gdb/remote.c12
-rw-r--r--gdb/rust-lang.c9
-rw-r--r--gdb/serial.c9
-rw-r--r--gdb/stack.c34
-rw-r--r--gdb/symmisc.c22
-rw-r--r--gdb/symtab.h2
-rw-r--r--gdb/top.c51
-rw-r--r--gdb/tracepoint.c7
-rw-r--r--gdb/tui/tui-disasm.c18
-rw-r--r--gdb/tui/tui-file.c230
-rw-r--r--gdb/tui/tui-file.h17
-rw-r--r--gdb/tui/tui-io.c4
-rw-r--r--gdb/tui/tui-regs.c21
-rw-r--r--gdb/tui/tui-stack.c33
-rw-r--r--gdb/typeprint.c17
-rw-r--r--gdb/ui-file.c782
-rw-r--r--gdb/ui-file.h296
-rw-r--r--gdb/ui-out.c10
-rw-r--r--gdb/ui-out.h2
-rw-r--r--gdb/utils.c18
-rw-r--r--gdb/utils.h2
-rw-r--r--gdb/varobj.c23
-rw-r--r--gdb/xtensa-tdep.c31
81 files changed, 1047 insertions, 2063 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e364bd85685..f6591199ad3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7602,17 +7602,11 @@ ada_value_struct_elt (struct value *arg, char *name, int no_err)
static std::string
type_as_string (struct type *type)
{
- struct ui_file *tmp_stream = mem_fileopen ();
- struct cleanup *old_chain;
-
- tmp_stream = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (tmp_stream);
+ string_file tmp_stream;
- type_print (type, "", tmp_stream, -1);
- std::string str = ui_file_as_string (tmp_stream);
+ type_print (type, "", &tmp_stream, -1);
- do_cleanups (old_chain);
- return str;
+ return std::move (tmp_stream.string ());
}
/* Given a type TYPE, look up the type of the component of type named NAME.
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index b771382ebb0..1edd91a86e3 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -298,12 +298,11 @@ static void
ada_print_floating (const gdb_byte *valaddr, struct type *type,
struct ui_file *stream)
{
- struct ui_file *tmp_stream = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
+ string_file tmp_stream;
- print_floating (valaddr, type, tmp_stream);
+ print_floating (valaddr, type, &tmp_stream);
- std::string s = ui_file_as_string (tmp_stream);
+ std::string &s = tmp_stream.string ();
size_t skip_count = 0;
/* Modify for Ada rules. */
@@ -342,8 +341,6 @@ ada_print_floating (const gdb_byte *valaddr, struct type *type,
}
else
fprintf_filtered (stream, "%s", &s[skip_count]);
-
- do_cleanups (cleanups);
}
void
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index ae46ca220e6..13ab7f19678 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -79,14 +79,10 @@ ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr)
static std::string
ada_varobj_scalar_image (struct type *type, LONGEST val)
{
- struct ui_file *buf = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (buf);
+ string_file buf;
- ada_print_scalar (type, val, buf);
- std::string result = ui_file_as_string (buf);
- do_cleanups (cleanups);
-
- return result;
+ ada_print_scalar (type, val, &buf);
+ return std::move (buf.string ());
}
/* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair designates
@@ -808,17 +804,10 @@ static std::string
ada_varobj_get_value_image (struct value *value,
struct value_print_options *opts)
{
- struct ui_file *buffer;
- struct cleanup *old_chain;
-
- buffer = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (buffer);
-
- common_val_print (value, buffer, 0, opts, current_language);
- std::string result = ui_file_as_string (buffer);
+ string_file buffer;
- do_cleanups (old_chain);
- return result;
+ common_val_print (value, &buffer, 0, opts, current_language);
+ return std::move (buffer.string ());
}
/* Assuming that the (VALUE, TYPE) pair designates an array varobj,
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 0f9f0f3b86c..5b51d030586 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9578,7 +9578,6 @@ extern initialize_file_ftype _initialize_arm_tdep; /* -Wmissing-prototypes */
void
_initialize_arm_tdep (void)
{
- struct ui_file *stb;
long length;
const char *setname;
const char *setdesc;
@@ -9650,13 +9649,12 @@ _initialize_arm_tdep (void)
valid_disassembly_styles[num_disassembly_options] = NULL;
/* Create the help text. */
- stb = mem_fileopen ();
- fprintf_unfiltered (stb, "%s%s%s",
- _("The valid values are:\n"),
- regdesc,
- _("The default is \"std\"."));
- helptext = ui_file_as_string (stb);
- ui_file_delete (stb);
+ string_file stb;
+ stb.printf ("%s%s%s",
+ _("The valid values are:\n"),
+ regdesc,
+ _("The default is \"std\"."));
+ helptext = std::move (stb.string ());
add_setshow_enum_cmd("disassembler", no_class,
valid_disassembly_styles, &disassembly_style,
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 90dad319801..0cdaedd9947 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3061,14 +3061,13 @@ update_inserted_breakpoint_locations (void)
int hw_breakpoint_error = 0;
int hw_bp_details_reported = 0;
- struct ui_file *tmp_error_stream = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
+ string_file tmp_error_stream;
/* Explicitly mark the warning -- this will only be printed if
there was an error. */
- fprintf_unfiltered (tmp_error_stream, "Warning:\n");
+ tmp_error_stream.puts ("Warning:\n");
- save_current_space_and_thread ();
+ struct cleanup *cleanups = save_current_space_and_thread ();
ALL_BP_LOCATIONS (bl, blp_tmp)
{
@@ -3093,7 +3092,7 @@ update_inserted_breakpoint_locations (void)
&& ptid_equal (inferior_ptid, null_ptid))
continue;
- val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
+ val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
&hw_breakpoint_error, &hw_bp_details_reported);
if (val)
error_flag = val;
@@ -3121,14 +3120,13 @@ insert_breakpoint_locations (void)
int hw_breakpoint_error = 0;
int hw_bp_error_explained_already = 0;
- struct ui_file *tmp_error_stream = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
-
+ string_file tmp_error_stream;
+
/* Explicitly mark the warning -- this will only be printed if
there was an error. */
- fprintf_unfiltered (tmp_error_stream, "Warning:\n");
+ tmp_error_stream.puts ("Warning:\n");
- save_current_space_and_thread ();
+ struct cleanup *cleanups = save_current_space_and_thread ();
ALL_BP_LOCATIONS (bl, blp_tmp)
{
@@ -3152,7 +3150,7 @@ insert_breakpoint_locations (void)
&& ptid_equal (inferior_ptid, null_ptid))
continue;
- val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
+ val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
&hw_breakpoint_error, &hw_bp_error_explained_already);
if (val)
error_flag = val;
@@ -3187,9 +3185,9 @@ insert_breakpoint_locations (void)
remove_breakpoint (loc);
hw_breakpoint_error = 1;
- fprintf_unfiltered (tmp_error_stream,
- "Could not insert hardware watchpoint %d.\n",
- bpt->number);
+ tmp_error_stream.printf ("Could not insert "
+ "hardware watchpoint %d.\n",
+ bpt->number);
error_flag = -1;
}
}
@@ -3200,8 +3198,7 @@ insert_breakpoint_locations (void)
message about possibly exhausted resources. */
if (hw_breakpoint_error && !hw_bp_error_explained_already)
{
- fprintf_unfiltered (tmp_error_stream,
- "Could not insert hardware breakpoints:\n\
+ tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
You may have requested too many hardware breakpoints/watchpoints.\n");
}
target_terminal_ours_for_output ();
@@ -3283,7 +3280,6 @@ reattach_breakpoints (int pid)
struct cleanup *old_chain;
struct bp_location *bl, **blp_tmp;
int val;
- struct ui_file *tmp_error_stream;
int dummy1 = 0, dummy2 = 0, dummy3 = 0;
struct inferior *inf;
struct thread_info *tp;
@@ -3297,8 +3293,7 @@ reattach_breakpoints (int pid)
inferior_ptid = tp->ptid;
- tmp_error_stream = mem_fileopen ();
- make_cleanup_ui_file_delete (tmp_error_stream);
+ string_file tmp_error_stream;
ALL_BP_LOCATIONS (bl, blp_tmp)
{
@@ -3308,7 +3303,7 @@ reattach_breakpoints (int pid)
if (bl->inserted)
{
bl->inserted = 0;
- val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
+ val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3);
if (val != 0)
{
do_cleanups (old_chain);
@@ -6185,14 +6180,11 @@ print_breakpoint_location (struct breakpoint *b,
}
else if (loc)
{
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
- print_address_symbolic (loc->gdbarch, loc->address, stb,
+ print_address_symbolic (loc->gdbarch, loc->address, &stb,
demangle, "");
ui_out_field_stream (uiout, "at", stb);
-
- do_cleanups (stb_chain);
}
else
{
@@ -10319,8 +10311,7 @@ print_one_detail_ranged_breakpoint (const struct breakpoint *b,
{
CORE_ADDR address_start, address_end;
struct bp_location *bl = b->loc;
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
+ string_file stb;
gdb_assert (bl);
@@ -10328,13 +10319,11 @@ print_one_detail_ranged_breakpoint (const struct breakpoint *b,
address_end = address_start + bl->length - 1;
ui_out_text (uiout, "\taddress range: ");
- fprintf_unfiltered (stb, "[%s, %s]",
- print_core_address (bl->gdbarch, address_start),
- print_core_address (bl->gdbarch, address_end));
+ stb.printf ("[%s, %s]",
+ print_core_address (bl->gdbarch, address_start),
+ print_core_address (bl->gdbarch, address_end));
ui_out_field_stream (uiout, "addr", stb);
ui_out_text (uiout, "\n");
-
- do_cleanups (cleanup);
}
/* Implement the "print_mention" breakpoint_ops method for
@@ -10766,7 +10755,6 @@ print_it_watchpoint (bpstat bs)
{
struct cleanup *old_chain;
struct breakpoint *b;
- struct ui_file *stb;
enum print_stop_action result;
struct watchpoint *w;
struct ui_out *uiout = current_uiout;
@@ -10776,12 +10764,13 @@ print_it_watchpoint (bpstat bs)
b = bs->breakpoint_at;
w = (struct watchpoint *) b;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ old_chain = make_cleanup (null_cleanup, NULL);
annotate_watchpoint (b->number);
maybe_print_thread_hit_breakpoint (uiout);
+ string_file stb;
+
switch (b->type)
{
case bp_watchpoint:
@@ -10793,10 +10782,10 @@ print_it_watchpoint (bpstat bs)
mention (b);
make_cleanup_ui_out_tuple_begin_end (uiout, "value");
ui_out_text (uiout, "\nOld value = ");
- watchpoint_value_print (bs->old_val, stb);
+ watchpoint_value_print (bs->old_val, &stb);
ui_out_field_stream (uiout, "old", stb);
ui_out_text (uiout, "\nNew value = ");
- watchpoint_value_print (w->val, stb);
+ watchpoint_value_print (w->val, &stb);
ui_out_field_stream (uiout, "new", stb);
ui_out_text (uiout, "\n");
/* More than one watchpoint may have been triggered. */
@@ -10811,7 +10800,7 @@ print_it_watchpoint (bpstat bs)
mention (b);
make_cleanup_ui_out_tuple_begin_end (uiout, "value");
ui_out_text (uiout, "\nValue = ");
- watchpoint_value_print (w->val, stb);
+ watchpoint_value_print (w->val, &stb);
ui_out_field_stream (uiout, "value", stb);
ui_out_text (uiout, "\n");
result = PRINT_UNKNOWN;
@@ -10827,7 +10816,7 @@ print_it_watchpoint (bpstat bs)
mention (b);
make_cleanup_ui_out_tuple_begin_end (uiout, "value");
ui_out_text (uiout, "\nOld value = ");
- watchpoint_value_print (bs->old_val, stb);
+ watchpoint_value_print (bs->old_val, &stb);
ui_out_field_stream (uiout, "old", stb);
ui_out_text (uiout, "\nNew value = ");
}
@@ -10841,7 +10830,7 @@ print_it_watchpoint (bpstat bs)
make_cleanup_ui_out_tuple_begin_end (uiout, "value");
ui_out_text (uiout, "\nValue = ");
}
- watchpoint_value_print (w->val, stb);
+ watchpoint_value_print (w->val, &stb);
ui_out_field_stream (uiout, "new", stb);
ui_out_text (uiout, "\n");
result = PRINT_UNKNOWN;
@@ -15699,7 +15688,6 @@ save_breakpoints (char *filename, int from_tty,
struct breakpoint *tp;
int any = 0;
struct cleanup *cleanup;
- struct ui_file *fp;
int extra_trace_bits = 0;
if (filename == 0 || *filename == 0)
@@ -15735,14 +15723,15 @@ save_breakpoints (char *filename, int from_tty,
filename = tilde_expand (filename);
cleanup = make_cleanup (xfree, filename);
- fp = gdb_fopen (filename, "w");
- if (!fp)
+
+ stdio_file fp;
+
+ if (!fp.open (filename, "w"))
error (_("Unable to open file '%s' for saving (%s)"),
filename, safe_strerror (errno));
- make_cleanup_ui_file_delete (fp);
if (extra_trace_bits)
- save_trace_state_variables (fp);
+ save_trace_state_variables (&fp);
ALL_BREAKPOINTS (tp)
{
@@ -15754,23 +15743,23 @@ save_breakpoints (char *filename, int from_tty,
if (filter && !filter (tp))
continue;
- tp->ops->print_recreate (tp, fp);
+ tp->ops->print_recreate (tp, &fp);
/* Note, we can't rely on tp->number for anything, as we can't
assume the recreated breakpoint numbers will match. Use $bpnum
instead. */
if (tp->cond_string)
- fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
+ fp.printf (" condition $bpnum %s\n", tp->cond_string);
if (tp->ignore_count)
- fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
+ fp.printf (" ignore $bpnum %d\n", tp->ignore_count);
if (tp->type != bp_dprintf && tp->commands)
{
- fprintf_unfiltered (fp, " commands\n");
+ fp.puts (" commands\n");
- ui_out_redirect (current_uiout, fp);
+ ui_out_redirect (current_uiout, &fp);
TRY
{
print_command_lines (current_uiout, tp->commands->commands, 2);
@@ -15783,11 +15772,11 @@ save_breakpoints (char *filename, int from_tty,
END_CATCH
ui_out_redirect (current_uiout, NULL);
- fprintf_unfiltered (fp, " end\n");
+ fp.puts (" end\n");
}
if (tp->enable_state == bp_disabled)
- fprintf_unfiltered (fp, "disable $bpnum\n");
+ fp.puts ("disable $bpnum\n");
/* If this is a multi-location breakpoint, check if the locations
should be individually disabled. Watchpoint locations are
@@ -15799,12 +15788,12 @@ save_breakpoints (char *filename, int from_tty,
for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
if (!loc->enabled)
- fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
+ fp.printf ("disable $bpnum.%d\n", n);
}
}
if (extra_trace_bits && *default_collect)
- fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
+ fp.printf ("set default-collect %s\n", default_collect);
if (from_tty)
printf_filtered (_("Saved to file '%s'.\n"), filename);
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index f08bb69acd6..e5621b92df0 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1555,13 +1555,11 @@ oper: OPERATOR NEW
| OPERATOR OBJC_LBRAC ']'
{ $$ = operator_stoken ("[]"); }
| OPERATOR conversion_type_id
- { struct ui_file *buf = mem_fileopen ();
+ { string_file buf;
- c_print_type ($2, NULL, buf, -1, 0,
+ c_print_type ($2, NULL, &buf, -1, 0,
&type_print_raw_options);
- std::string name = ui_file_as_string (buf);
- ui_file_delete (buf);
- $$ = operator_stoken (name.c_str ());
+ $$ = operator_stoken (buf.c_str ());
}
;
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index 46d4741aa28..22815a69728 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -76,7 +76,7 @@ static struct ui_file *logging_no_redirect_file;
static void
set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
{
- struct cleanup *cleanups;
+ ui_file_up destroy_old_stdout;
struct ui_file *output, *new_logging_no_redirect_file;
struct ui_out *uiout = current_uiout;
@@ -85,15 +85,13 @@ set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
|| (logging_redirect == 0 && logging_no_redirect_file != NULL))
return;
- cleanups = make_cleanup (null_cleanup, NULL);
-
if (logging_redirect != 0)
{
gdb_assert (logging_no_redirect_file != NULL);
/* ui_out_redirect still has not been called for next
gdb_stdout. */
- make_cleanup_ui_file_delete (gdb_stdout);
+ destroy_old_stdout.reset (gdb_stdout);
output = logging_no_redirect_file;
new_logging_no_redirect_file = NULL;
@@ -105,9 +103,7 @@ set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
else
{
gdb_assert (logging_no_redirect_file == NULL);
- output = tee_file_new (saved_output.out, 0, gdb_stdout, 0);
- if (output == NULL)
- perror_with_name (_("set logging"));
+ output = new tee_file (saved_output.out, 0, gdb_stdout, 0);
new_logging_no_redirect_file = gdb_stdout;
if (from_tty)
@@ -137,8 +133,6 @@ set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
if (ui_out_redirect (uiout, NULL) < 0
|| ui_out_redirect (uiout, output) < 0)
warning (_("Current output protocol does not support redirection"));
-
- do_cleanups (cleanups);
}
static void
@@ -154,7 +148,7 @@ pop_output_files (void)
{
if (logging_no_redirect_file)
{
- ui_file_delete (logging_no_redirect_file);
+ delete logging_no_redirect_file;
logging_no_redirect_file = NULL;
}
@@ -162,7 +156,7 @@ pop_output_files (void)
{
/* Only delete one of the files -- they are all set to the same
value. */
- ui_file_delete (gdb_stdout);
+ delete gdb_stdout;
gdb_stdout = saved_output.out;
gdb_stderr = saved_output.err;
@@ -186,7 +180,6 @@ pop_output_files (void)
static void
handle_redirections (int from_tty)
{
- struct cleanup *cleanups;
struct ui_file *output;
struct ui_file *no_redirect_file = NULL;
@@ -197,20 +190,18 @@ handle_redirections (int from_tty)
return;
}
- output = gdb_fopen (logging_filename, logging_overwrite ? "w" : "a");
- if (output == NULL)
+ std::unique_ptr<stdio_file> log (new stdio_file ());
+ if (!log->open (logging_filename, logging_overwrite ? "w" : "a"))
perror_with_name (_("set logging"));
- cleanups = make_cleanup_ui_file_delete (output);
+
+ output = log.get ();
/* Redirects everything to gdb_stdout while this is running. */
if (!logging_redirect)
{
no_redirect_file = output;
- output = tee_file_new (gdb_stdout, 0, no_redirect_file, 0);
- if (output == NULL)
- perror_with_name (_("set logging"));
- make_cleanup_ui_file_delete (output);
+ output = new tee_file (gdb_stdout, 0, no_redirect_file, 0);
if (from_tty)
fprintf_unfiltered (gdb_stdout, "Copying output to %s.\n",
logging_filename);
@@ -225,7 +216,7 @@ handle_redirections (int from_tty)
logging_filename);
}
- discard_cleanups (cleanups);
+ log.release ();
saved_filename = xstrdup (logging_filename);
saved_output.out = gdb_stdout;
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 84445d798a1..f087f5a13f6 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -568,13 +568,10 @@ void
do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
{
struct ui_out *uiout = current_uiout;
- struct cleanup *old_chain;
- struct ui_file *stb;
gdb_assert (c->type == show_cmd);
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
/* Possibly call the pre hook. */
if (c->pre_show_hook)
@@ -584,29 +581,29 @@ do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
{
case var_string:
if (*(char **) c->var)
- fputstr_filtered (*(char **) c->var, '"', stb);
+ stb.putstr (*(char **) c->var, '"');
break;
case var_string_noescape:
case var_optional_filename:
case var_filename:
case var_enum:
if (*(char **) c->var)
- fputs_filtered (*(char **) c->var, stb);
+ stb.puts (*(char **) c->var);
break;
case var_boolean:
- fputs_filtered (*(int *) c->var ? "on" : "off", stb);
+ stb.puts (*(int *) c->var ? "on" : "off");
break;
case var_auto_boolean:
switch (*(enum auto_boolean*) c->var)
{
case AUTO_BOOLEAN_TRUE:
- fputs_filtered ("on", stb);
+ stb.puts ("on");
break;
case AUTO_BOOLEAN_FALSE:
- fputs_filtered ("off", stb);
+ stb.puts ("off");
break;
case AUTO_BOOLEAN_AUTO:
- fputs_filtered ("auto", stb);
+ stb.puts ("auto");
break;
default:
internal_error (__FILE__, __LINE__,
@@ -619,24 +616,24 @@ do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
case var_zuinteger:
if (c->var_type == var_uinteger
&& *(unsigned int *) c->var == UINT_MAX)
- fputs_filtered ("unlimited", stb);
+ stb.puts ("unlimited");
else
- fprintf_filtered (stb, "%u", *(unsigned int *) c->var);
+ stb.printf ("%u", *(unsigned int *) c->var);
break;
case var_integer:
case var_zinteger:
if (c->var_type == var_integer
&& *(int *) c->var == INT_MAX)
- fputs_filtered ("unlimited", stb);
+ stb.puts ("unlimited");
else
- fprintf_filtered (stb, "%d", *(int *) c->var);
+ stb.printf ("%d", *(int *) c->var);
break;
case var_zuinteger_unlimited:
{
if (*(int *) c->var == -1)
- fputs_filtered ("unlimited", stb);
+ stb.puts ("unlimited");
else
- fprintf_filtered (stb, "%d", *(int *) c->var);
+ stb.printf ("%d", *(int *) c->var);
}
break;
default:
@@ -653,14 +650,11 @@ do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
ui_out_field_stream (uiout, "value", stb);
else
{
- std::string value = ui_file_as_string (stb);
-
if (c->show_value_func != NULL)
- c->show_value_func (gdb_stdout, from_tty, c, value.c_str ());
+ c->show_value_func (gdb_stdout, from_tty, c, stb.c_str ());
else
- deprecated_show_value_hack (gdb_stdout, from_tty, c, value.c_str ());
+ deprecated_show_value_hack (gdb_stdout, from_tty, c, stb.c_str ());
}
- do_cleanups (old_chain);
c->func (c, NULL, from_tty);
}
diff --git a/gdb/common/scoped_restore.h b/gdb/common/scoped_restore.h
index 8c2a5b0272b..e440d9a4c4f 100644
--- a/gdb/common/scoped_restore.h
+++ b/gdb/common/scoped_restore.h
@@ -47,8 +47,11 @@ class scoped_restore_tmpl : public scoped_restore_base
/* Create a new scoped_restore object that saves the current value
of *VAR, and sets *VAR to VALUE. *VAR will be restored when this
- scoped_restore object is destroyed. */
- scoped_restore_tmpl (T *var, T value)
+ scoped_restore object is destroyed. This is templated on T2 to
+ allow passing VALUEs of types convertible to T.
+ E.g.: T='base'; T2='derived'. */
+ template <typename T2>
+ scoped_restore_tmpl (T *var, T2 value)
: m_saved_var (var),
m_saved_value (*var)
{
@@ -90,8 +93,8 @@ scoped_restore_tmpl<T> make_scoped_restore (T *var)
/* Make a scoped_restore. This is useful because it lets template
argument deduction work. */
-template<typename T>
-scoped_restore_tmpl<T> make_scoped_restore (T *var, T value)
+template<typename T, typename T2>
+scoped_restore_tmpl<T> make_scoped_restore (T *var, T2 value)
{
return scoped_restore_tmpl<T> (var, value);
}
diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c
index 641b0fd68bc..c41b569c08e 100644
--- a/gdb/compile/compile-c-support.c
+++ b/gdb/compile/compile-c-support.c
@@ -333,15 +333,12 @@ c_compute_program (struct compile_instance *inst,
const struct block *expr_block,
CORE_ADDR expr_pc)
{
- struct ui_file *buf, *var_stream = NULL;
- std::string code;
- struct cleanup *cleanup;
struct compile_c_instance *context = (struct compile_c_instance *) inst;
- buf = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (buf);
+ string_file buf;
+ string_file var_stream;
- write_macro_definitions (expr_block, expr_pc, buf);
+ write_macro_definitions (expr_block, expr_pc, &buf);
/* Do not generate local variable information for "raw"
compilations. In this case we aren't emitting our own function
@@ -355,21 +352,17 @@ c_compute_program (struct compile_instance *inst,
before generating the function header, so we can define the
register struct before the function body. This requires a
temporary stream. */
- var_stream = mem_fileopen ();
- make_cleanup_ui_file_delete (var_stream);
registers_used = generate_c_for_variable_locations (context,
var_stream, gdbarch,
expr_block, expr_pc);
make_cleanup (xfree, registers_used);
- fputs_unfiltered ("typedef unsigned int"
- " __attribute__ ((__mode__(__pointer__)))"
- " __gdb_uintptr;\n",
- buf);
- fputs_unfiltered ("typedef int"
- " __attribute__ ((__mode__(__pointer__)))"
- " __gdb_intptr;\n",
- buf);
+ buf.puts ("typedef unsigned int"
+ " __attribute__ ((__mode__(__pointer__)))"
+ " __gdb_uintptr;\n");
+ buf.puts ("typedef int"
+ " __attribute__ ((__mode__(__pointer__)))"
+ " __gdb_intptr;\n");
/* Iterate all log2 sizes in bytes supported by c_get_mode_for_size. */
for (i = 0; i < 4; ++i)
@@ -377,24 +370,23 @@ c_compute_program (struct compile_instance *inst,
const char *mode = c_get_mode_for_size (1 << i);
gdb_assert (mode != NULL);
- fprintf_unfiltered (buf,
- "typedef int"
- " __attribute__ ((__mode__(__%s__)))"
- " __gdb_int_%s;\n",
- mode, mode);
+ buf.printf ("typedef int"
+ " __attribute__ ((__mode__(__%s__)))"
+ " __gdb_int_%s;\n",
+ mode, mode);
}
- generate_register_struct (buf, gdbarch, registers_used);
+ generate_register_struct (&buf, gdbarch, registers_used);
}
- add_code_header (inst->scope, buf);
+ add_code_header (inst->scope, &buf);
if (inst->scope == COMPILE_I_SIMPLE_SCOPE
|| inst->scope == COMPILE_I_PRINT_ADDRESS_SCOPE
|| inst->scope == COMPILE_I_PRINT_VALUE_SCOPE)
{
- ui_file_put (var_stream, ui_file_write_for_put, buf);
- fputs_unfiltered ("#pragma GCC user_expression\n", buf);
+ buf.write (var_stream.c_str (), var_stream.size ());
+ buf.puts ("#pragma GCC user_expression\n");
}
/* The user expression has to be in its own scope, so that "extern"
@@ -402,15 +394,15 @@ c_compute_program (struct compile_instance *inst,
declaration is in the same scope as the declaration provided by
gdb. */
if (inst->scope != COMPILE_I_RAW_SCOPE)
- fputs_unfiltered ("{\n", buf);
+ buf.puts ("{\n");
- fputs_unfiltered ("#line 1 \"gdb command line\"\n", buf);
+ buf.puts ("#line 1 \"gdb command line\"\n");
switch (inst->scope)
{
case COMPILE_I_PRINT_ADDRESS_SCOPE:
case COMPILE_I_PRINT_VALUE_SCOPE:
- fprintf_unfiltered (buf,
+ buf.printf (
"__auto_type " COMPILE_I_EXPR_VAL " = %s;\n"
"typeof (%s) *" COMPILE_I_EXPR_PTR_TYPE ";\n"
"memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s" COMPILE_I_EXPR_VAL ",\n"
@@ -420,22 +412,20 @@ c_compute_program (struct compile_instance *inst,
? "&" : ""));
break;
default:
- fputs_unfiltered (input, buf);
+ buf.puts (input);
break;
}
- fputs_unfiltered ("\n", buf);
+ buf.puts ("\n");
/* For larger user expressions the automatic semicolons may be
confusing. */
if (strchr (input, '\n') == NULL)
- fputs_unfiltered (";\n", buf);
+ buf.puts (";\n");
if (inst->scope != COMPILE_I_RAW_SCOPE)
- fputs_unfiltered ("}\n", buf);
+ buf.puts ("}\n");
- add_code_footer (inst->scope, buf);
- code = ui_file_as_string (buf);
- do_cleanups (cleanup);
- return code;
+ add_code_footer (inst->scope, &buf);
+ return std::move (buf.string ());
}
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index dcd530d3cb9..876677fc4d6 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -584,7 +584,7 @@ symbol_seen (htab_t hashtab, struct symbol *sym)
static void
generate_vla_size (struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc,
@@ -640,7 +640,7 @@ generate_vla_size (struct compile_c_instance *compiler,
static void
generate_c_for_for_one_variable (struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc,
@@ -651,14 +651,14 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
{
if (is_dynamic_type (SYMBOL_TYPE (sym)))
{
- struct ui_file *size_file = mem_fileopen ();
- struct cleanup *cleanup = make_cleanup_ui_file_delete (size_file);
+ /* We need to emit to a temporary buffer in case an error
+ occurs in the middle. */
+ string_file local_file;
- generate_vla_size (compiler, size_file, gdbarch, registers_used, pc,
+ generate_vla_size (compiler, local_file, gdbarch, registers_used, pc,
SYMBOL_TYPE (sym), sym);
- ui_file_put (size_file, ui_file_write_for_put, stream);
- do_cleanups (cleanup);
+ stream.write (local_file.c_str (), local_file.size ());
}
if (SYMBOL_COMPUTED_OPS (sym) != NULL)
@@ -667,14 +667,13 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
struct cleanup *cleanup = make_cleanup (xfree, generated_name);
/* We need to emit to a temporary buffer in case an error
occurs in the middle. */
- struct ui_file *local_file = mem_fileopen ();
+ string_file local_file;
- make_cleanup_ui_file_delete (local_file);
SYMBOL_COMPUTED_OPS (sym)->generate_c_location (sym, local_file,
gdbarch,
registers_used,
pc, generated_name);
- ui_file_put (local_file, ui_file_write_for_put, stream);
+ stream.write (local_file.c_str (), local_file.size ());
do_cleanups (cleanup);
}
@@ -719,7 +718,7 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
unsigned char *
generate_c_for_variable_locations (struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
const struct block *block,
CORE_ADDR pc)
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index 5a7bf1411f1..e89a88cce1c 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -135,7 +135,7 @@ extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe);
extern unsigned char *generate_c_for_variable_locations
(struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
const struct block *block,
CORE_ADDR pc);
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index e8bef55e048..a1ff8e20326 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -435,9 +435,9 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
/* Emit code to push a constant. */
static void
-push (int indent, struct ui_file *stream, ULONGEST l)
+push (int indent, string_file &stream, ULONGEST l)
{
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[++__gdb_tos] = (" GCC_UINTPTR ") %s;\n",
hex_string (l));
}
@@ -445,57 +445,57 @@ push (int indent, struct ui_file *stream, ULONGEST l)
/* Emit code to push an arbitrary expression. This works like
printf. */
-static void pushf (int indent, struct ui_file *stream, const char *format, ...)
+static void pushf (int indent, string_file &stream, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
static void
-pushf (int indent, struct ui_file *stream, const char *format, ...)
+pushf (int indent, string_file &stream, const char *format, ...)
{
va_list args;
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos + 1] = ");
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos + 1] = ");
va_start (args, format);
- vfprintf_filtered (stream, format, args);
+ stream.vprintf (format, args);
va_end (args);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
- fprintfi_filtered (indent, stream, "++__gdb_tos;\n");
+ fprintfi_filtered (indent, &stream, "++__gdb_tos;\n");
}
/* Emit code for a unary expression -- one which operates in-place on
the top-of-stack. This works like printf. */
-static void unary (int indent, struct ui_file *stream, const char *format, ...)
+static void unary (int indent, string_file &stream, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
static void
-unary (int indent, struct ui_file *stream, const char *format, ...)
+unary (int indent, string_file &stream, const char *format, ...)
{
va_list args;
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos] = ");
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos] = ");
va_start (args, format);
- vfprintf_filtered (stream, format, args);
+ stream.vprintf (format, args);
va_end (args);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
}
/* Emit code for a unary expression -- one which uses the top two
stack items, popping the topmost one. This works like printf. */
-static void binary (int indent, struct ui_file *stream, const char *format, ...)
+static void binary (int indent, string_file &stream, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
static void
-binary (int indent, struct ui_file *stream, const char *format, ...)
+binary (int indent, string_file &stream, const char *format, ...)
{
va_list args;
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos - 1] = ");
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos - 1] = ");
va_start (args, format);
- vfprintf_filtered (stream, format, args);
+ stream.vprintf (format, args);
va_end (args);
- fprintf_filtered (stream, ";\n");
- fprintfi_filtered (indent, stream, "--__gdb_tos;\n");
+ stream.puts (";\n");
+ fprintfi_filtered (indent, &stream, "--__gdb_tos;\n");
}
/* Print the name of a label given its "SCOPE", an arbitrary integer
@@ -503,10 +503,9 @@ binary (int indent, struct ui_file *stream, const char *format, ...)
corresponding to the label's point of definition. */
static void
-print_label (struct ui_file *stream, unsigned int scope, int target)
+print_label (string_file &stream, unsigned int scope, int target)
{
- fprintf_filtered (stream, "__label_%u_%s",
- scope, pulongest (target));
+ stream.printf ("__label_%u_%s", scope, pulongest (target));
}
/* Emit code that pushes a register's address on the stack.
@@ -514,7 +513,7 @@ print_label (struct ui_file *stream, unsigned int scope, int target)
register was needed by this expression. */
static void
-pushf_register_address (int indent, struct ui_file *stream,
+pushf_register_address (int indent, string_file &stream,
unsigned char *registers_used,
struct gdbarch *gdbarch, int regnum)
{
@@ -535,7 +534,7 @@ pushf_register_address (int indent, struct ui_file *stream,
register's value before it is pushed. */
static void
-pushf_register (int indent, struct ui_file *stream,
+pushf_register (int indent, string_file &stream,
unsigned char *registers_used,
struct gdbarch *gdbarch, int regnum, uint64_t offset)
{
@@ -584,7 +583,7 @@ pushf_register (int indent, struct ui_file *stream,
things. */
static void
-do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
+do_compile_dwarf_expr_to_c (int indent, string_file &stream,
const char *type_name,
const char *result_name,
struct symbol *sym, CORE_ADDR pc,
@@ -609,9 +608,9 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
++scope;
- fprintfi_filtered (indent, stream, "__attribute__ ((unused)) %s %s;\n",
+ fprintfi_filtered (indent, &stream, "__attribute__ ((unused)) %s %s;\n",
type_name, result_name);
- fprintfi_filtered (indent, stream, "{\n");
+ fprintfi_filtered (indent, &stream, "{\n");
indent += 2;
stack_depth = compute_stack_depth (byte_order, addr_size,
@@ -648,20 +647,20 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
"compiled code."),
SYMBOL_PRINT_NAME (sym));
- fprintfi_filtered (indent, stream, "%s = %s;\n",
+ fprintfi_filtered (indent, &stream, "%s = %s;\n",
result_name,
core_addr_to_string (value_address (val)));
- fprintfi_filtered (indent - 2, stream, "}\n");
+ fprintfi_filtered (indent - 2, &stream, "}\n");
do_cleanups (cleanup);
return;
}
- fprintfi_filtered (indent, stream, GCC_UINTPTR " __gdb_stack[%d];\n",
+ fprintfi_filtered (indent, &stream, GCC_UINTPTR " __gdb_stack[%d];\n",
stack_depth);
if (need_tempvar)
- fprintfi_filtered (indent, stream, GCC_UINTPTR " __gdb_tmp;\n");
- fprintfi_filtered (indent, stream, "int __gdb_tos = -1;\n");
+ fprintfi_filtered (indent, &stream, GCC_UINTPTR " __gdb_tmp;\n");
+ fprintfi_filtered (indent, &stream, "int __gdb_tos = -1;\n");
if (initial != NULL)
pushf (indent, stream, "%s", core_addr_to_string (*initial));
@@ -672,13 +671,13 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
uint64_t uoffset, reg;
int64_t offset;
- print_spaces (indent - 2, stream);
+ print_spaces (indent - 2, &stream);
if (info[op_ptr - base].label)
{
print_label (stream, scope, op_ptr - base);
- fprintf_filtered (stream, ":;");
+ stream.puts (":;");
}
- fprintf_filtered (stream, "/* %s */\n", get_DW_OP_name (op));
+ stream.printf ("/* %s */\n", get_DW_OP_name (op));
/* This is handy for debugging the generated code:
fprintf_filtered (stream, "if (__gdb_tos != %d) abort ();\n",
@@ -919,7 +918,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
break;
case DW_OP_drop:
- fprintfi_filtered (indent, stream, "--__gdb_tos;\n");
+ fprintfi_filtered (indent, &stream, "--__gdb_tos;\n");
break;
case DW_OP_pick:
@@ -929,13 +928,13 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
break;
case DW_OP_swap:
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_tmp = __gdb_stack[__gdb_tos - 1];\n");
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos - 1] = "
"__gdb_stack[__gdb_tos];\n");
- fprintfi_filtered (indent, stream, ("__gdb_stack[__gdb_tos] = "
- "__gdb_tmp;\n"));
+ fprintfi_filtered (indent, &stream, ("__gdb_stack[__gdb_tos] = "
+ "__gdb_tmp;\n"));
break;
case DW_OP_over:
@@ -943,15 +942,15 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
break;
case DW_OP_rot:
- fprintfi_filtered (indent, stream, ("__gdb_tmp = "
- "__gdb_stack[__gdb_tos];\n"));
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream, ("__gdb_tmp = "
+ "__gdb_stack[__gdb_tos];\n"));
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos] = "
"__gdb_stack[__gdb_tos - 1];\n");
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos - 1] = "
"__gdb_stack[__gdb_tos -2];\n");
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos - 2] = "
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos - 2] = "
"__gdb_tmp;\n");
break;
@@ -973,7 +972,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
/* Cast to a pointer of the desired type, then
dereference. */
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos] = "
"*((__gdb_int_%s *) "
"__gdb_stack[__gdb_tos]);\n",
@@ -1099,19 +1098,19 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
case DW_OP_skip:
offset = extract_signed_integer (op_ptr, 2, byte_order);
op_ptr += 2;
- fprintfi_filtered (indent, stream, "goto ");
+ fprintfi_filtered (indent, &stream, "goto ");
print_label (stream, scope, op_ptr + offset - base);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
break;
case DW_OP_bra:
offset = extract_signed_integer (op_ptr, 2, byte_order);
op_ptr += 2;
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"if ((( " GCC_INTPTR
") __gdb_stack[__gdb_tos--]) != 0) goto ");
print_label (stream, scope, op_ptr + offset - base);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
break;
case DW_OP_nop:
@@ -1122,9 +1121,9 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
}
}
- fprintfi_filtered (indent, stream, "%s = __gdb_stack[__gdb_tos];\n",
+ fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n",
result_name);
- fprintfi_filtered (indent - 2, stream, "}\n");
+ fprintfi_filtered (indent - 2, &stream, "}\n");
do_cleanups (cleanup);
}
@@ -1132,7 +1131,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
/* See compile.h. */
void
-compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name,
+compile_dwarf_expr_to_c (string_file &stream, const char *result_name,
struct symbol *sym, CORE_ADDR pc,
struct gdbarch *arch, unsigned char *registers_used,
unsigned int addr_size,
@@ -1147,7 +1146,7 @@ compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name,
/* See compile.h. */
void
-compile_dwarf_bounds_to_c (struct ui_file *stream,
+compile_dwarf_bounds_to_c (string_file &stream,
const char *result_name,
const struct dynamic_prop *prop,
struct symbol *sym, CORE_ADDR pc,
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 205a7e35e29..4cbd00b99c0 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -494,22 +494,19 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
/* From the provided expression, build a scope to pass to the
compiler. */
- std::string input_buf;
+ string_file input_buf;
const char *input;
if (cmd != NULL)
{
- struct ui_file *stream = mem_fileopen ();
struct command_line *iter;
- make_cleanup_ui_file_delete (stream);
for (iter = cmd->body_list[0]; iter; iter = iter->next)
{
- fputs_unfiltered (iter->line, stream);
- fputs_unfiltered ("\n", stream);
+ input_buf.puts (iter->line);
+ input_buf.puts ("\n");
}
- input_buf = ui_file_as_string (stream);
input = input_buf.c_str ();
}
else if (cmd_string != NULL)
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index f4afd9fed68..9a01b11abd5 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -55,7 +55,7 @@ extern void eval_compile_command (struct command_line *cmd,
PER_CU is the per-CU object used for looking up various other
things. */
-extern void compile_dwarf_expr_to_c (struct ui_file *stream,
+extern void compile_dwarf_expr_to_c (string_file &stream,
const char *result_name,
struct symbol *sym,
CORE_ADDR pc,
@@ -90,7 +90,7 @@ extern void compile_dwarf_expr_to_c (struct ui_file *stream,
PER_CU is the per-CU object used for looking up various other
things. */
-extern void compile_dwarf_bounds_to_c (struct ui_file *stream,
+extern void compile_dwarf_bounds_to_c (string_file &stream,
const char *result_name,
const struct dynamic_prop *prop,
struct symbol *sym, CORE_ADDR pc,
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index d409b0b92e7..b0b91fc133f 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -210,7 +210,6 @@ inspect_type (struct demangle_parse_info *info,
int is_anon;
struct type *type;
struct demangle_parse_info *i;
- struct ui_file *buf;
/* Get the real type of the typedef. */
type = check_typedef (otype);
@@ -246,23 +245,21 @@ inspect_type (struct demangle_parse_info *info,
type = last;
}
- buf = mem_fileopen ();
+ string_file buf;
TRY
- {
- type_print (type, "", buf, -1);
- }
-
+ {
+ type_print (type, "", &buf, -1);
+ }
/* If type_print threw an exception, there is little point
in continuing, so just bow out gracefully. */
CATCH (except, RETURN_MASK_ERROR)
{
- ui_file_delete (buf);
return 0;
}
END_CATCH
- name = ui_file_obsavestring (buf, &info->obstack, &len);
- ui_file_delete (buf);
+ len = buf.size ();
+ name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
/* Turn the result into a new tree. Note that this
tree will contain pointers into NAME, so NAME cannot
@@ -319,7 +316,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
{
long len;
char *name;
- struct ui_file *buf = mem_fileopen ();
+ string_file buf;
struct demangle_component *comp = ret_comp;
/* Walk each node of the qualified name, reconstructing the name of
@@ -333,9 +330,9 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
{
struct demangle_component newobj;
- ui_file_write (buf, d_left (comp)->u.s_name.s,
- d_left (comp)->u.s_name.len);
- name = ui_file_obsavestring (buf, &info->obstack, &len);
+ buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len);
+ len = buf.size ();
+ name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
newobj.type = DEMANGLE_COMPONENT_NAME;
newobj.u.s_name.s = name;
newobj.u.s_name.len = len;
@@ -348,12 +345,11 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
string and replace the top DEMANGLE_COMPONENT_QUAL_NAME
node. */
- ui_file_rewind (buf);
+ buf.rewind ();
n = cp_comp_to_string (&newobj, 100);
if (n == NULL)
{
/* If something went astray, abort typedef substitutions. */
- ui_file_delete (buf);
return;
}
@@ -378,14 +374,13 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
if (name == NULL)
{
/* If something went astray, abort typedef substitutions. */
- ui_file_delete (buf);
return;
}
- fputs_unfiltered (name, buf);
+ buf.puts (name);
xfree (name);
}
- ui_file_write (buf, "::", 2);
+ buf.write ("::", 2);
comp = d_right (comp);
}
@@ -395,8 +390,9 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
if (comp->type == DEMANGLE_COMPONENT_NAME)
{
- ui_file_write (buf, comp->u.s_name.s, comp->u.s_name.len);
- name = ui_file_obsavestring (buf, &info->obstack, &len);
+ buf.write (comp->u.s_name.s, comp->u.s_name.len);
+ len = buf.size ();
+ name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
/* Replace the top (DEMANGLE_COMPONENT_QUAL_NAME) node
with a DEMANGLE_COMPONENT_NAME node containing the whole
@@ -408,8 +404,6 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
}
else
replace_typedefs (info, comp, finder, data);
-
- ui_file_delete (buf);
}
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 07c3abe39ba..da17e68caa8 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -176,7 +176,7 @@ int
gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
const struct disasm_insn *insn, int flags,
- struct ui_file *stb)
+ string_file &stb)
{
/* parts of the symbolic representation of the address */
int unmapped;
@@ -240,7 +240,7 @@ gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
if (name != NULL)
xfree (name);
- ui_file_rewind (stb);
+ stb.rewind ();
if (flags & DISASSEMBLY_RAW_INSN)
{
CORE_ADDR end_pc;
@@ -250,9 +250,7 @@ gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
/* Build the opcodes using a temporary stream so we can
write them out in a single go for the MI. */
- struct ui_file *opcode_stream = mem_fileopen ();
- struct cleanup *cleanups =
- make_cleanup_ui_file_delete (opcode_stream);
+ string_file opcode_stream;
size = gdbarch_print_insn (gdbarch, pc, di);
end_pc = pc + size;
@@ -262,21 +260,18 @@ gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
err = (*di->read_memory_func) (pc, &data, 1, di);
if (err != 0)
(*di->memory_error_func) (err, pc, di);
- fprintf_filtered (opcode_stream, "%s%02x",
- spacer, (unsigned) data);
+ opcode_stream.printf ("%s%02x", spacer, (unsigned) data);
spacer = " ";
}
ui_out_field_stream (uiout, "opcodes", opcode_stream);
ui_out_text (uiout, "\t");
-
- do_cleanups (cleanups);
}
else
size = gdbarch_print_insn (gdbarch, pc, di);
ui_out_field_stream (uiout, "inst", stb);
- ui_file_rewind (stb);
+ stb.rewind ();
do_cleanups (ui_out_chain);
ui_out_text (uiout, "\n");
@@ -287,7 +282,7 @@ static int
dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
CORE_ADDR low, CORE_ADDR high,
- int how_many, int flags, struct ui_file *stb,
+ int how_many, int flags, string_file &stb,
CORE_ADDR *end_pc)
{
struct disasm_insn insn;
@@ -329,7 +324,7 @@ do_mixed_source_and_assembly_deprecated
(struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info *di, struct symtab *symtab,
CORE_ADDR low, CORE_ADDR high,
- int how_many, int flags, struct ui_file *stb)
+ int how_many, int flags, string_file &stb)
{
int newlines = 0;
int nlines;
@@ -492,7 +487,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info *di,
struct symtab *main_symtab,
CORE_ADDR low, CORE_ADDR high,
- int how_many, int flags, struct ui_file *stb)
+ int how_many, int flags, string_file &stb)
{
const struct linetable_entry *le, *first_le;
int i, nlines;
@@ -736,7 +731,7 @@ static void
do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
CORE_ADDR low, CORE_ADDR high,
- int how_many, int flags, struct ui_file *stb)
+ int how_many, int flags, string_file &stb)
{
struct cleanup *ui_out_chain;
@@ -794,9 +789,8 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
char *file_string, int flags, int how_many,
CORE_ADDR low, CORE_ADDR high)
{
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (stb);
- struct disassemble_info di = gdb_disassemble_info (gdbarch, stb);
+ string_file stb;
+ struct disassemble_info di = gdb_disassemble_info (gdbarch, &stb);
struct symtab *symtab;
int nlines = -1;
@@ -818,7 +812,6 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
do_mixed_source_and_assembly_deprecated (gdbarch, uiout, &di, symtab,
low, high, how_many, flags, stb);
- do_cleanups (cleanups);
gdb_flush (gdb_stdout);
}
@@ -845,28 +838,13 @@ gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
return length;
}
-static void
-do_ui_file_delete (void *arg)
-{
- ui_file_delete ((struct ui_file *) arg);
-}
-
/* Return the length in bytes of the instruction at address MEMADDR in
debugged memory. */
int
gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr)
{
- static struct ui_file *null_stream = NULL;
-
- /* Dummy file descriptor for the disassembler. */
- if (!null_stream)
- {
- null_stream = ui_file_new ();
- make_final_cleanup (do_ui_file_delete, null_stream);
- }
-
- return gdb_print_insn (gdbarch, addr, null_stream, NULL);
+ return gdb_print_insn (gdbarch, addr, &null_stream, NULL);
}
/* fprintf-function for gdb_buffered_insn_length. This function is a
diff --git a/gdb/disasm.h b/gdb/disasm.h
index a2b72b94418..3915239000e 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -53,7 +53,7 @@ struct disasm_insn
extern int gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
const struct disasm_insn *insn, int flags,
- struct ui_file *stb);
+ string_file &stb);
/* Return a filled in disassemble_info object for use by gdb. */
diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c
index 606fb852cca..285b6852878 100644
--- a/gdb/dummy-frame.c
+++ b/gdb/dummy-frame.c
@@ -409,14 +409,11 @@ maintenance_print_dummy_frames (char *args, int from_tty)
fprint_dummy_frames (gdb_stdout);
else
{
- struct cleanup *cleanups;
- struct ui_file *file = gdb_fopen (args, "w");
+ stdio_file file;
- if (file == NULL)
+ if (!file.open (args, "w"))
perror_with_name (_("maintenance print dummy-frames"));
- cleanups = make_cleanup_ui_file_delete (file);
- fprint_dummy_frames (file);
- do_cleanups (cleanups);
+ fprint_dummy_frames (&file);
}
}
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 44dceda26ea..a55d9294053 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2642,7 +2642,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
/* See dwarf2loc.h. */
void
-dwarf2_compile_property_to_c (struct ui_file *stream,
+dwarf2_compile_property_to_c (string_file &stream,
const char *result_name,
struct gdbarch *gdbarch,
unsigned char *registers_used,
@@ -4362,7 +4362,7 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
/* symbol_computed_ops 'generate_c_location' method. */
static void
-locexpr_generate_c_location (struct symbol *sym, struct ui_file *stream,
+locexpr_generate_c_location (struct symbol *sym, string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc, const char *result_name)
@@ -4572,7 +4572,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
/* symbol_computed_ops 'generate_c_location' method. */
static void
-loclist_generate_c_location (struct symbol *sym, struct ui_file *stream,
+loclist_generate_c_location (struct symbol *sym, string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc, const char *result_name)
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
index fa83459cc87..d3ec8560e69 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
@@ -151,7 +151,7 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop,
evaluated.
SYM the originating symbol, used for error reporting. */
-void dwarf2_compile_property_to_c (struct ui_file *stream,
+void dwarf2_compile_property_to_c (string_file &stream,
const char *result_name,
struct gdbarch *gdbarch,
unsigned char *registers_used,
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 58260f3c01d..6fe5d29572d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8417,17 +8417,6 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
}
}
-/* Retrieve the last character from a mem_file. */
-
-static void
-do_ui_file_peek_last (void *object, const char *buffer, long length)
-{
- char *last_char_p = (char *) object;
-
- if (length > 0)
- *last_char_p = buffer[length - 1];
-}
-
/* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
compute the physname for the object, which include a method's:
- formal parameters (C++),
@@ -8486,21 +8475,21 @@ dwarf2_compute_name (const char *name,
{
long length;
const char *prefix;
- struct ui_file *buf;
const char *canonical_name = NULL;
+ string_file buf;
+
prefix = determine_prefix (die, cu);
- buf = mem_fileopen ();
if (*prefix != '\0')
{
char *prefixed_name = typename_concat (NULL, prefix, name,
physname, cu);
- fputs_unfiltered (prefixed_name, buf);
+ buf.puts (prefixed_name);
xfree (prefixed_name);
}
else
- fputs_unfiltered (name, buf);
+ buf.puts (name);
/* Template parameters may be specified in the DIE's DW_AT_name, or
as children with DW_TAG_template_type_param or
@@ -8545,25 +8534,25 @@ dwarf2_compute_name (const char *name,
if (first)
{
- fputs_unfiltered ("<", buf);
+ buf.puts ("<");
first = 0;
}
else
- fputs_unfiltered (", ", buf);
+ buf.puts (", ");
attr = dwarf2_attr (child, DW_AT_type, cu);
if (attr == NULL)
{
complaint (&symfile_complaints,
_("template parameter missing DW_AT_type"));
- fputs_unfiltered ("UNKNOWN_TYPE", buf);
+ buf.puts ("UNKNOWN_TYPE");
continue;
}
type = die_type (child, cu);
if (child->tag == DW_TAG_template_type_param)
{
- c_print_type (type, "", buf, -1, 0, &type_print_raw_options);
+ c_print_type (type, "", &buf, -1, 0, &type_print_raw_options);
continue;
}
@@ -8573,7 +8562,7 @@ dwarf2_compute_name (const char *name,
complaint (&symfile_complaints,
_("template parameter missing "
"DW_AT_const_value"));
- fputs_unfiltered ("UNKNOWN_VALUE", buf);
+ buf.puts ("UNKNOWN_VALUE");
continue;
}
@@ -8584,7 +8573,7 @@ dwarf2_compute_name (const char *name,
if (TYPE_NOSIGN (type))
/* GDB prints characters as NUMBER 'CHAR'. If that's
changed, this can use value_print instead. */
- c_printchar (value, type, buf);
+ c_printchar (value, type, &buf);
else
{
struct value_print_options opts;
@@ -8607,7 +8596,7 @@ dwarf2_compute_name (const char *name,
the radix. */
get_formatted_print_options (&opts, 'd');
opts.raw = 1;
- value_print (v, buf, &opts);
+ value_print (v, &buf, &opts);
release_value (v);
value_free (v);
}
@@ -8619,12 +8608,10 @@ dwarf2_compute_name (const char *name,
{
/* Close the argument list, with a space if necessary
(nested templates). */
- char last_char = '\0';
- ui_file_put (buf, do_ui_file_peek_last, &last_char);
- if (last_char == '>')
- fputs_unfiltered (" >", buf);
+ if (!buf.empty () && buf.string ().back () == '>')
+ buf.puts (" >");
else
- fputs_unfiltered (">", buf);
+ buf.puts (">");
}
}
@@ -8636,7 +8623,7 @@ dwarf2_compute_name (const char *name,
{
struct type *type = read_type_die (die, cu);
- c_type_print_args (type, buf, 1, cu->language,
+ c_type_print_args (type, &buf, 1, cu->language,
&type_print_raw_options);
if (cu->language == language_cplus)
@@ -8651,12 +8638,11 @@ dwarf2_compute_name (const char *name,
&& TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
&& TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
0))))
- fputs_unfiltered (" const", buf);
+ buf.puts (" const");
}
}
- std::string intermediate_name = ui_file_as_string (buf);
- ui_file_delete (buf);
+ const std::string &intermediate_name = buf.string ();
if (cu->language == language_cplus)
canonical_name
diff --git a/gdb/event-top.c b/gdb/event-top.c
index a90a9299af2..52aa797b882 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1226,8 +1226,8 @@ gdb_setup_readline (int editing)
mess it up here. The sync stuff should really go away over
time. */
if (!batch_silent)
- gdb_stdout = stdio_fileopen (ui->outstream);
- gdb_stderr = stderr_fileopen (ui->errstream);
+ gdb_stdout = new stdio_file (ui->outstream);
+ gdb_stderr = new stderr_file (ui->errstream);
gdb_stdlog = gdb_stderr; /* for moment */
gdb_stdtarg = gdb_stderr; /* for moment */
gdb_stdtargerr = gdb_stderr; /* for moment */
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 07b3ce57920..3f07f2c4e90 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -497,17 +497,13 @@ gdbarch_free (struct gdbarch *arch)
static void
verify_gdbarch (struct gdbarch *gdbarch)
{
- struct ui_file *log;
- struct cleanup *cleanups;
- long length;
+ string_file log;
- log = mem_fileopen ();
- cleanups = make_cleanup_ui_file_delete (log);
/* fundamental */
if (gdbarch->byte_order == BFD_ENDIAN_UNKNOWN)
- fprintf_unfiltered (log, "\n\tbyte-order");
+ log.puts ("\n\tbyte-order");
if (gdbarch->bfd_arch_info == NULL)
- fprintf_unfiltered (log, "\n\tbfd_arch_info");
+ log.puts ("\n\tbfd_arch_info");
/* Check those that need to be defined for the given multi-arch level. */
/* Skip verify of bits_big_endian, invalid_p == 0 */
/* Skip verify of short_bit, invalid_p == 0 */
@@ -542,7 +538,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of pseudo_register_read_value, has predicate. */
/* Skip verify of pseudo_register_write, has predicate. */
if (gdbarch->num_regs == -1)
- fprintf_unfiltered (log, "\n\tnum_regs");
+ log.puts ("\n\tnum_regs");
/* Skip verify of num_pseudo_regs, invalid_p == 0 */
/* Skip verify of ax_pseudo_register_collect, has predicate. */
/* Skip verify of ax_pseudo_register_push_stack, has predicate. */
@@ -556,7 +552,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of sdb_reg_to_regnum, invalid_p == 0 */
/* Skip verify of dwarf2_reg_to_regnum, invalid_p == 0 */
if (gdbarch->register_name == 0)
- fprintf_unfiltered (log, "\n\tregister_name");
+ log.puts ("\n\tregister_name");
/* Skip verify of register_type, has predicate. */
/* Skip verify of dummy_id, has predicate. */
/* Skip verify of deprecated_fp_regnum, invalid_p == 0 */
@@ -579,14 +575,14 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of return_value, has predicate. */
/* Skip verify of return_in_first_hidden_param_p, invalid_p == 0 */
if (gdbarch->skip_prologue == 0)
- fprintf_unfiltered (log, "\n\tskip_prologue");
+ log.puts ("\n\tskip_prologue");
/* Skip verify of skip_main_prologue, has predicate. */
/* Skip verify of skip_entrypoint, has predicate. */
if (gdbarch->inner_than == 0)
- fprintf_unfiltered (log, "\n\tinner_than");
+ log.puts ("\n\tinner_than");
/* Skip verify of breakpoint_from_pc, invalid_p == 0 */
if (gdbarch->breakpoint_kind_from_pc == 0)
- fprintf_unfiltered (log, "\n\tbreakpoint_kind_from_pc");
+ log.puts ("\n\tbreakpoint_kind_from_pc");
/* Skip verify of sw_breakpoint_from_kind, invalid_p == 0 */
/* Skip verify of breakpoint_kind_from_current_state, invalid_p == 0 */
/* Skip verify of adjust_breakpoint_address, has predicate. */
@@ -607,7 +603,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of software_single_step, has predicate. */
/* Skip verify of single_step_through_delay, has predicate. */
if (gdbarch->print_insn == 0)
- fprintf_unfiltered (log, "\n\tprint_insn");
+ log.puts ("\n\tprint_insn");
/* Skip verify of skip_trampoline_code, invalid_p == 0 */
/* Skip verify of skip_solib_resolver, invalid_p == 0 */
/* Skip verify of in_solib_return_trampoline, invalid_p == 0 */
@@ -641,9 +637,9 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of displaced_step_hw_singlestep, invalid_p == 0 */
/* Skip verify of displaced_step_fixup, has predicate. */
if ((! gdbarch->displaced_step_free_closure) != (! gdbarch->displaced_step_copy_insn))
- fprintf_unfiltered (log, "\n\tdisplaced_step_free_closure");
+ log.puts ("\n\tdisplaced_step_free_closure");
if ((! gdbarch->displaced_step_location) != (! gdbarch->displaced_step_copy_insn))
- fprintf_unfiltered (log, "\n\tdisplaced_step_location");
+ log.puts ("\n\tdisplaced_step_location");
/* Skip verify of relocate_instruction, has predicate. */
/* Skip verify of overlay_update, has predicate. */
/* Skip verify of core_read_description, has predicate. */
@@ -696,12 +692,10 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of gcc_target_options, invalid_p == 0 */
/* Skip verify of gnu_triplet_regexp, invalid_p == 0 */
/* Skip verify of addressable_memory_unit_size, invalid_p == 0 */
- std::string buf = ui_file_as_string (log);
- if (!buf.empty ())
+ if (!log.empty ())
internal_error (__FILE__, __LINE__,
_("verify_gdbarch: the following are invalid ...%s"),
- buf.c_str ());
- do_cleanups (cleanups);
+ log.c_str ());
}
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 28a34781daa..896a1b8eabf 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1875,17 +1875,13 @@ cat <<EOF
static void
verify_gdbarch (struct gdbarch *gdbarch)
{
- struct ui_file *log;
- struct cleanup *cleanups;
- long length;
+ string_file log;
- log = mem_fileopen ();
- cleanups = make_cleanup_ui_file_delete (log);
/* fundamental */
if (gdbarch->byte_order == BFD_ENDIAN_UNKNOWN)
- fprintf_unfiltered (log, "\n\tbyte-order");
+ log.puts ("\n\tbyte-order");
if (gdbarch->bfd_arch_info == NULL)
- fprintf_unfiltered (log, "\n\tbfd_arch_info");
+ log.puts ("\n\tbfd_arch_info");
/* Check those that need to be defined for the given multi-arch level. */
EOF
function_list | while do_read
@@ -1914,21 +1910,19 @@ do
elif [ -n "${invalid_p}" ]
then
printf " if (${invalid_p})\n"
- printf " fprintf_unfiltered (log, \"\\\\n\\\\t${function}\");\n"
+ printf " log.puts (\"\\\\n\\\\t${function}\");\n"
elif [ -n "${predefault}" ]
then
printf " if (gdbarch->${function} == ${predefault})\n"
- printf " fprintf_unfiltered (log, \"\\\\n\\\\t${function}\");\n"
+ printf " log.puts (\"\\\\n\\\\t${function}\");\n"
fi
fi
done
cat <<EOF
- std::string buf = ui_file_as_string (log);
- if (!buf.empty ())
+ if (!log.empty ())
internal_error (__FILE__, __LINE__,
_("verify_gdbarch: the following are invalid ...%s"),
- buf.c_str ());
- do_cleanups (cleanups);
+ log.c_str ());
}
EOF
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 786a8a8f77e..c519871ab55 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2459,7 +2459,7 @@ safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
/* Suppress error messages. */
saved_gdb_stderr = gdb_stderr;
- gdb_stderr = ui_file_new ();
+ gdb_stderr = &null_stream;
/* Call parse_and_eval_type() without fear of longjmp()s. */
TRY
@@ -2473,7 +2473,6 @@ safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
END_CATCH
/* Stop suppressing error messages. */
- ui_file_delete (gdb_stderr);
gdb_stderr = saved_gdb_stderr;
return type;
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index 61d16da3bb5..aef63179584 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -978,8 +978,6 @@ gdbscm_breakpoint_commands (SCM self)
= bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct breakpoint *bp;
long length;
- struct ui_file *string_file;
- struct cleanup *chain;
SCM result;
bp = bp_smob->bp;
@@ -987,10 +985,9 @@ gdbscm_breakpoint_commands (SCM self)
if (bp->commands == NULL)
return SCM_BOOL_F;
- string_file = mem_fileopen ();
- chain = make_cleanup_ui_file_delete (string_file);
+ string_file buf;
- ui_out_redirect (current_uiout, string_file);
+ ui_out_redirect (current_uiout, &buf);
TRY
{
print_command_lines (current_uiout, breakpoint_commands (bp), 0);
@@ -998,15 +995,12 @@ gdbscm_breakpoint_commands (SCM self)
ui_out_redirect (current_uiout, NULL);
CATCH (except, RETURN_MASK_ALL)
{
- do_cleanups (chain);
gdbscm_throw_gdb_exception (except);
}
END_CATCH
- std::string cmdstr = ui_file_as_string (string_file);
- result = gdbscm_scm_from_c_string (cmdstr.c_str ());
+ result = gdbscm_scm_from_c_string (buf.c_str ());
- do_cleanups (chain);
return result;
}
diff --git a/gdb/guile/scm-disasm.c b/gdb/guile/scm-disasm.c
index a7d6b1464f6..4bdf4a4f5c0 100644
--- a/gdb/guile/scm-disasm.c
+++ b/gdb/guile/scm-disasm.c
@@ -162,7 +162,7 @@ gdbscm_disasm_print_address (bfd_vma addr, struct disassemble_info *info)
static int
gdbscm_print_insn_from_port (struct gdbarch *gdbarch,
SCM port, ULONGEST offset, CORE_ADDR memaddr,
- struct ui_file *stream, int *branch_delay_insns)
+ string_file *stream, int *branch_delay_insns)
{
struct disassemble_info di;
int length;
@@ -282,33 +282,29 @@ gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest)
for (pc = start, i = 0; pc <= end && i < count; )
{
int insn_len = 0;
- struct ui_file *memfile = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (memfile);
+ string_file buf;
TRY
{
if (using_port)
{
insn_len = gdbscm_print_insn_from_port (gdbarch, port, offset,
- pc, memfile, NULL);
+ pc, &buf, NULL);
}
else
- insn_len = gdb_print_insn (gdbarch, pc, memfile, NULL);
+ insn_len = gdb_print_insn (gdbarch, pc, &buf, NULL);
}
CATCH (except, RETURN_MASK_ALL)
{
- GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups);
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
}
END_CATCH
- std::string as = ui_file_as_string (memfile);
-
- result = scm_cons (dascm_make_insn (pc, as.c_str (), insn_len),
+ result = scm_cons (dascm_make_insn (pc, buf.c_str (), insn_len),
result);
pc += insn_len;
i++;
- do_cleanups (cleanups);
}
return scm_reverse_x (result, SCM_EOL);
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index a86ea5f60fc..d89016c28fe 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -156,15 +156,12 @@ static int
frscm_print_frame_smob (SCM self, SCM port, scm_print_state *pstate)
{
frame_smob *f_smob = (frame_smob *) SCM_SMOB_DATA (self);
- struct ui_file *strfile;
gdbscm_printf (port, "#<%s ", frame_smob_name);
- strfile = mem_fileopen ();
- fprint_frame_id (strfile, f_smob->frame_id);
- std::string s = ui_file_as_string (strfile);
- gdbscm_printf (port, "%s", s.c_str ());
- ui_file_delete (strfile);
+ string_file strfile;
+ fprint_frame_id (&strfile, f_smob->frame_id);
+ gdbscm_printf (port, "%s", strfile.c_str ());
scm_puts (">", port);
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index dea9077aa33..b88f2f7ca47 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -37,11 +37,19 @@
/* A ui-file for sending output to Guile. */
-typedef struct
+class ioscm_file_port : public ui_file
{
- int *magic;
- SCM port;
-} ioscm_file_port;
+public:
+ /* Return a ui_file that writes to PORT. */
+ explicit ioscm_file_port (SCM port);
+
+ void flush () override;
+ void rewind () override;
+ void write (const char *buf, long length_buf) override;
+
+private:
+ SCM m_port;
+};
/* Data for a memory port. */
@@ -431,74 +439,27 @@ gdbscm_error_port (void)
/* Support for sending GDB I/O to Guile ports. */
-static void
-ioscm_file_port_delete (struct ui_file *file)
-{
- ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
-
- if (stream->magic != &file_port_magic)
- internal_error (__FILE__, __LINE__,
- _("ioscm_file_port_delete: bad magic number"));
- xfree (stream);
-}
+ioscm_file_port::ioscm_file_port (SCM port)
+ : m_port (port)
+{}
-static void
-ioscm_file_port_rewind (struct ui_file *file)
+void
+ioscm_file_port::flush ()
{
- ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
-
- if (stream->magic != &file_port_magic)
- internal_error (__FILE__, __LINE__,
- _("ioscm_file_port_rewind: bad magic number"));
-
- scm_truncate_file (stream->port, 0);
}
-static void
-ioscm_file_port_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
+void
+ioscm_file_port::rewind ()
{
- ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
-
- if (stream->magic != &file_port_magic)
- internal_error (__FILE__, __LINE__,
- _("ioscm_file_port_put: bad magic number"));
-
- /* This function doesn't meld with ports very well. */
+ scm_truncate_file (m_port, 0);
}
-static void
-ioscm_file_port_write (struct ui_file *file,
- const char *buffer,
- long length_buffer)
+void
+ioscm_file_port::write (const char *buffer, long length_buffer)
{
- ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
-
- if (stream->magic != &file_port_magic)
- internal_error (__FILE__, __LINE__,
- _("ioscm_pot_file_write: bad magic number"));
-
- scm_c_write (stream->port, buffer, length_buffer);
+ scm_c_write (m_port, buffer, length_buffer);
}
-/* Return a ui_file that writes to PORT. */
-
-static struct ui_file *
-ioscm_file_port_new (SCM port)
-{
- ioscm_file_port *stream = XCNEW (ioscm_file_port);
- struct ui_file *file = ui_file_new ();
-
- set_ui_file_data (file, stream, ioscm_file_port_delete);
- set_ui_file_rewind (file, ioscm_file_port_rewind);
- set_ui_file_put (file, ioscm_file_port_put);
- set_ui_file_write (file, ioscm_file_port_write);
- stream->magic = &file_port_magic;
- stream->port = port;
-
- return file;
-}
/* Helper routine for with-{output,error}-to-port. */
@@ -506,7 +467,6 @@ static SCM
ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
const char *func_name)
{
- struct ui_file *port_file;
struct cleanup *cleanups;
SCM result;
@@ -520,23 +480,21 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
make_cleanup_restore_integer (&current_ui->async);
current_ui->async = 0;
- port_file = ioscm_file_port_new (port);
-
- make_cleanup_ui_file_delete (port_file);
+ ui_file_up port_file (new ioscm_file_port (port));
scoped_restore save_file = make_scoped_restore (oport == GDB_STDERR
? &gdb_stderr : &gdb_stdout);
if (oport == GDB_STDERR)
- gdb_stderr = port_file;
+ gdb_stderr = port_file.get ();
else
{
- if (ui_out_redirect (current_uiout, port_file) < 0)
+ if (ui_out_redirect (current_uiout, port_file.get ()) < 0)
warning (_("Current output protocol does not support redirection"));
else
make_cleanup_ui_out_redirect_pop (current_uiout);
- gdb_stdout = port_file;
+ gdb_stdout = port_file.get ();
}
result = gdbscm_safe_call_0 (thunk, NULL);
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 383e58a5f6b..70cdc5896a1 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -107,18 +107,10 @@ tyscm_type_name (struct type *type)
{
TRY
{
- struct cleanup *old_chain;
- struct ui_file *stb;
+ string_file stb;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
- LA_PRINT_TYPE (type, "", stb, -1, 0, &type_print_raw_options);
-
- std::string name = ui_file_as_string (stb);
- do_cleanups (old_chain);
-
- return name;
+ LA_PRINT_TYPE (type, "", &stb, -1, 0, &type_print_raw_options);
+ return std::move (stb.string ());
}
CATCH (except, RETURN_MASK_ALL)
{
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index fa0e2b71f36..81e2ca41445 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -157,15 +157,10 @@ vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
TRY
{
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
- common_val_print (v_smob->value, stb, 0, &opts, current_language);
-
- std::string s = ui_file_as_string (stb);
- scm_puts (s.c_str (), port);
-
- do_cleanups (old_chain);
+ common_val_print (v_smob->value, &stb, 0, &opts, current_language);
+ scm_puts (stb.c_str (), port);
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -1277,21 +1272,15 @@ gdbscm_value_print (SCM self)
= vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct value *value = v_smob->value;
struct value_print_options opts;
- std::string s;
- SCM result;
get_user_print_options (&opts);
opts.deref_ref = 0;
+ string_file stb;
+
TRY
{
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
-
- common_val_print (value, stb, 0, &opts, current_language);
- s = ui_file_as_string (stb);
-
- do_cleanups (old_chain);
+ common_val_print (value, &stb, 0, &opts, current_language);
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -1304,10 +1293,8 @@ gdbscm_value_print (SCM self)
IWBN to use scm_take_locale_string here, but we'd have to temporarily
override the default port conversion handler because contrary to
documentation it doesn't necessarily free the input string. */
- result = scm_from_stringn (s.c_str (), s.size (), host_charset (),
- SCM_FAILED_CONVERSION_QUESTION_MARK);
-
- return result;
+ return scm_from_stringn (stb.c_str (), stb.size (), host_charset (),
+ SCM_FAILED_CONVERSION_QUESTION_MARK);
}
/* (parse-and-eval string) -> <gdb:value>
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 22fb54cea03..dc3ae9ef6f9 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -8110,7 +8110,6 @@ i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
char **msg)
{
int len, jumplen;
- static struct ui_file *gdb_null = NULL;
/* Ask the target for the minimum instruction length supported. */
jumplen = target_get_min_fast_tracepoint_insn_len ();
@@ -8133,12 +8132,8 @@ i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
jumplen = (register_size (gdbarch, 0) == 8) ? 5 : 4;
}
- /* Dummy file descriptor for the disassembler. */
- if (!gdb_null)
- gdb_null = ui_file_new ();
-
/* Check for fit. */
- len = gdb_print_insn (gdbarch, addr, gdb_null, NULL);
+ len = gdb_print_insn (gdbarch, addr, &null_stream, NULL);
if (len < jumplen)
{
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 2440c0c78fe..bc397a8e70a 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1670,21 +1670,19 @@ print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
if (rv->value != NULL)
{
struct value_print_options opts;
- struct ui_file *stb;
- struct cleanup *old_chain;
/* Print it. */
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
ui_out_text (uiout, "Value returned is ");
ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
rv->value_history_index);
ui_out_text (uiout, " = ");
get_no_prettyformat_print_options (&opts);
- value_print (rv->value, stb, &opts);
+
+ string_file stb;
+
+ value_print (rv->value, &stb, &opts);
ui_out_field_stream (uiout, "return-value", stb);
ui_out_text (uiout, "\n");
- do_cleanups (old_chain);
}
else
{
diff --git a/gdb/infrun.c b/gdb/infrun.c
index bf0632eaad2..91b11a3fd76 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3436,40 +3436,32 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
const struct target_waitstatus *ws)
{
char *status_string = target_waitstatus_to_string (ws);
- struct ui_file *tmp_stream = mem_fileopen ();
+ string_file stb;
/* The text is split over several lines because it was getting too long.
Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
output as a unit; we want only one timestamp printed if debug_timestamp
is set. */
- fprintf_unfiltered (tmp_stream,
- "infrun: target_wait (%d.%ld.%ld",
- ptid_get_pid (waiton_ptid),
- ptid_get_lwp (waiton_ptid),
- ptid_get_tid (waiton_ptid));
+ stb.printf ("infrun: target_wait (%d.%ld.%ld",
+ ptid_get_pid (waiton_ptid),
+ ptid_get_lwp (waiton_ptid),
+ ptid_get_tid (waiton_ptid));
if (ptid_get_pid (waiton_ptid) != -1)
- fprintf_unfiltered (tmp_stream,
- " [%s]", target_pid_to_str (waiton_ptid));
- fprintf_unfiltered (tmp_stream, ", status) =\n");
- fprintf_unfiltered (tmp_stream,
- "infrun: %d.%ld.%ld [%s],\n",
- ptid_get_pid (result_ptid),
- ptid_get_lwp (result_ptid),
- ptid_get_tid (result_ptid),
- target_pid_to_str (result_ptid));
- fprintf_unfiltered (tmp_stream,
- "infrun: %s\n",
- status_string);
-
- std::string text = ui_file_as_string (tmp_stream);
+ stb.printf (" [%s]", target_pid_to_str (waiton_ptid));
+ stb.printf (", status) =\n");
+ stb.printf ("infrun: %d.%ld.%ld [%s],\n",
+ ptid_get_pid (result_ptid),
+ ptid_get_lwp (result_ptid),
+ ptid_get_tid (result_ptid),
+ target_pid_to_str (result_ptid));
+ stb.printf ("infrun: %s\n", status_string);
/* This uses %s in part to handle %'s in the text, but also to avoid
a gcc error: the format attribute requires a string literal. */
- fprintf_unfiltered (gdb_stdlog, "%s", text.c_str ());
+ fprintf_unfiltered (gdb_stdlog, "%s", stb.c_str ());
xfree (status_string);
- ui_file_delete (tmp_stream);
}
/* Select a thread at random, out of those which are resumed and have
diff --git a/gdb/language.c b/gdb/language.c
index b6f22ebe4ac..304a2a490fb 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -539,9 +539,6 @@ add_language (const struct language_defn *lang)
static const char **language_names = NULL;
/* For the "help set language" command. */
- int i;
- struct ui_file *tmp_stream;
-
if (lang->la_magic != LANG_MAGIC)
{
fprintf_unfiltered (gdb_stderr,
@@ -569,9 +566,9 @@ add_language (const struct language_defn *lang)
language_names = XRESIZEVEC (const char *, language_names,
languages_size + 1);
- for (i = 0; i < languages_size; ++i)
+ for (int i = 0; i < languages_size; ++i)
language_names[i] = languages[i]->la_name;
- language_names[i] = NULL;
+ language_names[languages_size] = NULL;
/* Add the filename extensions. */
if (lang->la_filename_extensions != NULL)
@@ -584,37 +581,32 @@ add_language (const struct language_defn *lang)
}
/* Build the "help set language" docs. */
- tmp_stream = mem_fileopen ();
+ string_file doc;
- fprintf_unfiltered (tmp_stream,
- _("Set the current source language.\n"
- "The currently understood settings are:\n\nlocal or "
- "auto Automatic setting based on source file\n"));
+ doc.printf (_("Set the current source language.\n"
+ "The currently understood settings are:\n\nlocal or "
+ "auto Automatic setting based on source file\n"));
- for (i = 0; i < languages_size; ++i)
+ for (int i = 0; i < languages_size; ++i)
{
/* Already dealt with these above. */
if (languages[i]->la_language == language_unknown
|| languages[i]->la_language == language_auto)
continue;
- /* FIXME: i18n: for now assume that the human-readable name
- is just a capitalization of the internal name. */
- fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n",
- languages[i]->la_name,
- /* Capitalize first letter of language
- name. */
- toupper (languages[i]->la_name[0]),
- languages[i]->la_name + 1);
+ /* FIXME: i18n: for now assume that the human-readable name is
+ just a capitalization of the internal name. */
+ doc.printf ("%-16s Use the %c%s language\n",
+ languages[i]->la_name,
+ /* Capitalize first letter of language name. */
+ toupper (languages[i]->la_name[0]),
+ languages[i]->la_name + 1);
}
- std::string language_set_doc = ui_file_as_string (tmp_stream);
- ui_file_delete (tmp_stream);
-
add_setshow_enum_cmd ("language", class_support,
(const char **) language_names,
&language,
- language_set_doc.c_str (),
+ doc.c_str (),
_("Show the current source language."),
NULL, set_language_command,
show_language_command,
diff --git a/gdb/location.c b/gdb/location.c
index 8dce21ada12..f0ea0f7cfcb 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -227,59 +227,52 @@ static char *
explicit_to_string_internal (int as_linespec,
const struct explicit_location *explicit_loc)
{
- struct ui_file *buf;
- char space, *result;
int need_space = 0;
- struct cleanup *cleanup;
-
- space = as_linespec ? ':' : ' ';
- buf = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (buf);
+ char space = as_linespec ? ':' : ' ';
+ string_file buf;
if (explicit_loc->source_filename != NULL)
{
if (!as_linespec)
- fputs_unfiltered ("-source ", buf);
- fputs_unfiltered (explicit_loc->source_filename, buf);
+ buf.puts ("-source ");
+ buf.puts (explicit_loc->source_filename);
need_space = 1;
}
if (explicit_loc->function_name != NULL)
{
if (need_space)
- fputc_unfiltered (space, buf);
+ buf.putc (space);
if (!as_linespec)
- fputs_unfiltered ("-function ", buf);
- fputs_unfiltered (explicit_loc->function_name, buf);
+ buf.puts ("-function ");
+ buf.puts (explicit_loc->function_name);
need_space = 1;
}
if (explicit_loc->label_name != NULL)
{
if (need_space)
- fputc_unfiltered (space, buf);
+ buf.putc (space);
if (!as_linespec)
- fputs_unfiltered ("-label ", buf);
- fputs_unfiltered (explicit_loc->label_name, buf);
+ buf.puts ("-label ");
+ buf.puts (explicit_loc->label_name);
need_space = 1;
}
if (explicit_loc->line_offset.sign != LINE_OFFSET_UNKNOWN)
{
if (need_space)
- fputc_unfiltered (space, buf);
+ buf.putc (space);
if (!as_linespec)
- fputs_unfiltered ("-line ", buf);
- fprintf_filtered (buf, "%s%d",
- (explicit_loc->line_offset.sign == LINE_OFFSET_NONE ? ""
- : (explicit_loc->line_offset.sign
- == LINE_OFFSET_PLUS ? "+" : "-")),
- explicit_loc->line_offset.offset);
+ buf.puts ("-line ");
+ buf.printf ("%s%d",
+ (explicit_loc->line_offset.sign == LINE_OFFSET_NONE ? ""
+ : (explicit_loc->line_offset.sign
+ == LINE_OFFSET_PLUS ? "+" : "-")),
+ explicit_loc->line_offset.offset);
}
- result = ui_file_xstrdup (buf, NULL);
- do_cleanups (cleanup);
- return result;
+ return xstrdup (buf.c_str ());
}
/* See description in location.h. */
diff --git a/gdb/main.c b/gdb/main.c
index fe57bf8d442..834aae02d9c 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -763,7 +763,7 @@ captured_main_1 (struct captured_main_args *context)
break;
case 'B':
batch_flag = batch_silent = 1;
- gdb_stdout = ui_file_new();
+ gdb_stdout = new null_file ();
break;
case 'D':
if (optarg[0] == '\0')
diff --git a/gdb/maint.c b/gdb/maint.c
index 3f04d9a0b51..39985d24b09 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -403,14 +403,11 @@ maintenance_print_architecture (char *args, int from_tty)
gdbarch_dump (gdbarch, gdb_stdout);
else
{
- struct cleanup *cleanups;
- struct ui_file *file = gdb_fopen (args, "w");
+ stdio_file file;
- if (file == NULL)
+ if (!file.open (args, "w"))
perror_with_name (_("maintenance print architecture"));
- cleanups = make_cleanup_ui_file_delete (file);
- gdbarch_dump (gdbarch, file);
- do_cleanups (cleanups);
+ gdbarch_dump (gdbarch, &file);
}
}
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 390fc7e833f..3c0adfb9273 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -488,7 +488,6 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
{
struct cleanup *old_chain;
struct ui_out *uiout = current_uiout;
- struct ui_file *stb;
gdb_assert (!arg->val || !arg->error);
gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
@@ -511,15 +510,16 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
TYPE_LENGTH (value_type (arg->val))))))
return;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ old_chain = make_cleanup (null_cleanup, NULL);
if (values != PRINT_NO_VALUES || what == all)
make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
- fputs_filtered (SYMBOL_PRINT_NAME (arg->sym), stb);
+ string_file stb;
+
+ stb.puts (SYMBOL_PRINT_NAME (arg->sym));
if (arg->entry_kind == print_entry_values_only)
- fputs_filtered ("@entry", stb);
+ stb.puts ("@entry");
ui_out_field_stream (uiout, "name", stb);
if (what == all && SYMBOL_IS_ARGUMENT (arg->sym))
@@ -528,7 +528,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
if (values == PRINT_SIMPLE_VALUES)
{
check_typedef (arg->sym->type);
- type_print (arg->sym->type, "", stb, -1);
+ type_print (arg->sym->type, "", &stb, -1);
ui_out_field_stream (uiout, "type", stb);
}
@@ -546,7 +546,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
get_no_prettyformat_print_options (&opts);
opts.deref_ref = 1;
- common_val_print (arg->val, stb, 0, &opts,
+ common_val_print (arg->val, &stb, 0, &opts,
language_def (SYMBOL_LANGUAGE (arg->sym)));
}
CATCH (except, RETURN_MASK_ERROR)
@@ -556,8 +556,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
END_CATCH
}
if (error_message != NULL)
- fprintf_filtered (stb, _("<error reading variable: %s>"),
- error_message);
+ stb.printf (_("<error reading variable: %s>"), error_message);
ui_out_field_stream (uiout, "value", stb);
}
diff --git a/gdb/mi/mi-common.h b/gdb/mi/mi-common.h
index c7e485546ae..f31982ec20a 100644
--- a/gdb/mi/mi-common.h
+++ b/gdb/mi/mi-common.h
@@ -19,6 +19,8 @@
#ifndef MI_COMMON_H
#define MI_COMMON_H
+struct mi_console_file;
+
/* Represents the reason why GDB is sending an asynchronous command to
the front end. NOTE: When modifing this, don't forget to update
gdb.texinfo! */
@@ -51,11 +53,11 @@ const char *async_reason_lookup (enum async_reply_reason reason);
struct mi_interp
{
/* MI's output channels */
- struct ui_file *out;
- struct ui_file *err;
- struct ui_file *log;
- struct ui_file *targ;
- struct ui_file *event_channel;
+ struct mi_console_file *out;
+ struct mi_console_file *err;
+ struct mi_console_file *log;
+ struct mi_console_file *targ;
+ struct mi_console_file *event_channel;
/* Raw console output. */
struct ui_file *raw_stdout;
diff --git a/gdb/mi/mi-console.c b/gdb/mi/mi-console.c
index 7a90d458b3c..185c73fb63b 100644
--- a/gdb/mi/mi-console.c
+++ b/gdb/mi/mi-console.c
@@ -26,118 +26,63 @@
#include "defs.h"
#include "mi-console.h"
-static ui_file_fputs_ftype mi_console_file_fputs;
-static ui_file_flush_ftype mi_console_file_flush;
-static ui_file_delete_ftype mi_console_file_delete;
-
-struct mi_console_file
- {
- int *magic;
- struct ui_file *raw;
- struct ui_file *buffer;
- const char *prefix;
- char quote;
- };
-
-/* Use the address of this otherwise-unused global as a magic number
- identifying this class of ui_file objects. */
-static int mi_console_file_magic;
/* Create a console that wraps the given output stream RAW with the
string PREFIX and quoting it with QUOTE. */
-struct ui_file *
-mi_console_file_new (struct ui_file *raw, const char *prefix, char quote)
-{
- struct ui_file *ui_file = ui_file_new ();
- struct mi_console_file *mi_console = XNEW (struct mi_console_file);
-
- mi_console->magic = &mi_console_file_magic;
- mi_console->raw = raw;
- mi_console->buffer = mem_fileopen ();
- mi_console->prefix = prefix;
- mi_console->quote = quote;
- set_ui_file_fputs (ui_file, mi_console_file_fputs);
- set_ui_file_flush (ui_file, mi_console_file_flush);
- set_ui_file_data (ui_file, mi_console, mi_console_file_delete);
-
- return ui_file;
-}
+mi_console_file::mi_console_file (struct ui_file *raw,
+ const char *prefix, char quote)
+ : m_raw (raw),
+ m_prefix (prefix),
+ m_quote (quote)
+{}
-static void
-mi_console_file_delete (struct ui_file *file)
+void
+mi_console_file::puts (const char *buf)
{
- struct mi_console_file *mi_console
- = (struct mi_console_file *) ui_file_data (file);
-
- if (mi_console->magic != &mi_console_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mi_console_file_delete: bad magic number"));
-
- xfree (mi_console);
+ this->write (buf, strlen (buf));
}
-static void
-mi_console_file_fputs (const char *buf, struct ui_file *file)
+void
+mi_console_file::write (const char *buf, long length_buf)
{
- struct mi_console_file *mi_console
- = (struct mi_console_file *) ui_file_data (file);
-
- if (mi_console->magic != &mi_console_file_magic)
- internal_error (__FILE__, __LINE__,
- "mi_console_file_fputs: bad magic number");
-
+ size_t prev_size = m_buffer.size ();
/* Append the text to our internal buffer. */
- fputs_unfiltered (buf, mi_console->buffer);
- /* Flush when an embedded newline is present anywhere in the buffer. */
- if (strchr (buf, '\n') != NULL)
- gdb_flush (file);
+ m_buffer.write (buf, length_buf);
+ /* Flush when an embedded newline is present anywhere in the
+ buffer. */
+ if (strchr (m_buffer.c_str () + prev_size, '\n') != NULL)
+ this->flush ();
}
-/* Transform a byte sequence into a console output packet. */
-
-static void
-mi_console_raw_packet (void *data, const char *buf, long length_buf)
+void
+mi_console_file::flush ()
{
- struct mi_console_file *mi_console = (struct mi_console_file *) data;
+ const std::string &str = m_buffer.string ();
- if (mi_console->magic != &mi_console_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mi_console_raw_packet: bad magic number"));
-
- if (length_buf > 0)
+ /* Transform a byte sequence into a console output packet. */
+ if (!str.empty ())
{
- fputs_unfiltered (mi_console->prefix, mi_console->raw);
- if (mi_console->quote)
+ size_t length_buf = str.size ();
+ const char *buf = str.data ();
+
+ fputs_unfiltered (m_prefix, m_raw);
+ if (m_quote)
{
- fputc_unfiltered (mi_console->quote, mi_console->raw);
- fputstrn_unfiltered (buf, length_buf,
- mi_console->quote, mi_console->raw);
- fputc_unfiltered (mi_console->quote, mi_console->raw);
- fputc_unfiltered ('\n', mi_console->raw);
+ fputc_unfiltered (m_quote, m_raw);
+ fputstrn_unfiltered (buf, length_buf, m_quote, m_raw);
+ fputc_unfiltered (m_quote, m_raw);
+ fputc_unfiltered ('\n', m_raw);
}
else
{
- fputstrn_unfiltered (buf, length_buf, 0, mi_console->raw);
- fputc_unfiltered ('\n', mi_console->raw);
+ fputstrn_unfiltered (buf, length_buf, 0, m_raw);
+ fputc_unfiltered ('\n', m_raw);
}
- gdb_flush (mi_console->raw);
+ gdb_flush (m_raw);
}
-}
-
-static void
-mi_console_file_flush (struct ui_file *file)
-{
- struct mi_console_file *mi_console
- = (struct mi_console_file *) ui_file_data (file);
-
- if (mi_console->magic != &mi_console_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mi_console_file_flush: bad magic number"));
-
- ui_file_put (mi_console->buffer, mi_console_raw_packet, mi_console);
- ui_file_rewind (mi_console->buffer);
+ m_buffer.rewind ();
}
/* Change the underlying stream of the console directly; this is
@@ -145,14 +90,7 @@ mi_console_file_flush (struct ui_file *file)
logging enable/disable. */
void
-mi_console_set_raw (struct ui_file *file, struct ui_file *raw)
+mi_console_file::set_raw (struct ui_file *raw)
{
- struct mi_console_file *mi_console
- = (struct mi_console_file *) ui_file_data (file);
-
- if (mi_console->magic != &mi_console_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mi_console_file_set_raw: bad magic number"));
-
- mi_console->raw = raw;
+ m_raw = raw;
}
diff --git a/gdb/mi/mi-console.h b/gdb/mi/mi-console.h
index 594d058a47f..e056ac606d4 100644
--- a/gdb/mi/mi-console.h
+++ b/gdb/mi/mi-console.h
@@ -20,11 +20,37 @@
#ifndef MI_CONSOLE_H
#define MI_CONSOLE_H
-extern struct ui_file *mi_console_file_new (struct ui_file *raw,
- const char *prefix,
- char quote);
+class mi_console_file : public ui_file
+{
+public:
-extern void mi_console_set_raw (struct ui_file *console,
- struct ui_file *raw);
+ /* Create a console that wraps the given output stream RAW with the
+ string PREFIX and quoting it with QUOTE. */
+ mi_console_file (struct ui_file *raw, const char *prefix, char quote);
+
+ /* MI-specific API. */
+ void set_raw (struct ui_file *raw);
+
+ /* ui_file-specific methods. */
+
+ void flush () override;
+
+ void write (const char *buf, long length_buf) override;
+
+ void puts (const char *) override;
+
+ void write_buffer_on (ui_file &where) override
+ { m_buffer.write_buffer_on (where); }
+
+ void rewind () override
+ { gdb_assert_not_reached ("mi_console_file::rewind called\n"); }
+
+private:
+
+ struct ui_file *m_raw;
+ string_file m_buffer;
+ const char *m_prefix;
+ char m_quote;
+};
#endif
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 72d63d0a05f..661a8d1e9f4 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -126,11 +126,11 @@ mi_interpreter_init (struct interp *interp, int top_level)
/* Create MI console channels, each with a different prefix so they
can be distinguished. */
- mi->out = mi_console_file_new (mi->raw_stdout, "~", '"');
- mi->err = mi_console_file_new (mi->raw_stdout, "&", '"');
+ mi->out = new mi_console_file (mi->raw_stdout, "~", '"');
+ mi->err = new mi_console_file (mi->raw_stdout, "&", '"');
mi->log = mi->err;
- mi->targ = mi_console_file_new (mi->raw_stdout, "@", '"');
- mi->event_channel = mi_console_file_new (mi->raw_stdout, "=", 0);
+ mi->targ = new mi_console_file (mi->raw_stdout, "@", '"');
+ mi->event_channel = new mi_console_file (mi->raw_stdout, "=", 0);
name = interp_name (interp);
/* INTERP_MI selects the most recent released version. "mi2" was
@@ -901,7 +901,7 @@ mi_breakpoint_created (struct breakpoint *b)
/* We want the output from gdb_breakpoint_query to go to
mi->event_channel. One approach would be to just call
gdb_breakpoint_query, and then use mi_out_put to send the current
- content of mi_outout into mi->event_channel. However, that will
+ content of mi_uiout into mi->event_channel. However, that will
break if anything is output to mi_uiout prior to calling the
breakpoint_created notifications. So, we use
ui_out_redirect. */
@@ -1394,8 +1394,8 @@ mi_set_logging (struct interp *interp, int start_log,
it), and create one based on raw_stdout instead. */
if (logfile)
{
- ui_file_delete (out);
- out = tee_file_new (mi->raw_stdout, 0, logfile, 0);
+ delete out;
+ out = new tee_file (mi->raw_stdout, false, logfile, false);
}
mi->saved_raw_stdout = mi->raw_stdout;
@@ -1407,11 +1407,11 @@ mi_set_logging (struct interp *interp, int start_log,
mi->saved_raw_stdout = NULL;
}
- mi_console_set_raw (mi->out, mi->raw_stdout);
- mi_console_set_raw (mi->err, mi->raw_stdout);
- mi_console_set_raw (mi->log, mi->raw_stdout);
- mi_console_set_raw (mi->targ, mi->raw_stdout);
- mi_console_set_raw (mi->event_channel, mi->raw_stdout);
+ mi->out->set_raw (mi->raw_stdout);
+ mi->err->set_raw (mi->raw_stdout);
+ mi->log->set_raw (mi->raw_stdout);
+ mi->targ->set_raw (mi->raw_stdout);
+ mi->event_channel->set_raw (mi->raw_stdout);
return 1;
}
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 58edd09b4b8..501e43761ef 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1263,7 +1263,6 @@ output_register (struct frame_info *frame, int regnum, int format,
struct value *val = value_of_register (regnum, frame);
struct cleanup *tuple_cleanup;
struct value_print_options opts;
- struct ui_file *stb;
if (skip_unavailable && !value_entirely_available (val))
return;
@@ -1277,14 +1276,13 @@ output_register (struct frame_info *frame, int regnum, int format,
if (format == 'r')
format = 'z';
- stb = mem_fileopen ();
- make_cleanup_ui_file_delete (stb);
+ string_file stb;
get_formatted_print_options (&opts, format);
opts.deref_ref = 1;
val_print (value_type (val),
value_embedded_offset (val), 0,
- stb, 0, val, &opts, current_language);
+ &stb, 0, val, &opts, current_language);
ui_out_field_stream (uiout, "value", stb);
do_cleanups (tuple_cleanup);
@@ -1354,15 +1352,10 @@ mi_cmd_data_write_register_values (char *command, char **argv, int argc)
void
mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
{
- struct cleanup *old_chain;
struct value *val;
- struct ui_file *stb;
struct value_print_options opts;
struct ui_out *uiout = current_uiout;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
if (argc != 1)
error (_("-data-evaluate-expression: "
"Usage: -data-evaluate-expression expression"));
@@ -1371,14 +1364,14 @@ mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
val = evaluate_expression (expr.get ());
+ string_file stb;
+
/* Print the result of the expression evaluation. */
get_user_print_options (&opts);
opts.deref_ref = 0;
- common_val_print (val, stb, 0, &opts, current_language);
+ common_val_print (val, &stb, 0, &opts, current_language);
ui_out_field_stream (uiout, "value", stb);
-
- do_cleanups (old_chain);
}
/* This is the -data-read-memory command.
@@ -1520,15 +1513,13 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
/* Build the result as a two dimentional table. */
{
- struct ui_file *stream;
- struct cleanup *cleanup_stream;
int row;
int row_byte;
+ struct cleanup *cleanup_list;
- stream = mem_fileopen ();
- cleanup_stream = make_cleanup_ui_file_delete (stream);
+ string_file stream;
- make_cleanup_ui_out_list_begin_end (uiout, "memory");
+ cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, "memory");
for (row = 0, row_byte = 0;
row < nr_rows;
row++, row_byte += nr_cols * word_size)
@@ -1555,9 +1546,9 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
}
else
{
- ui_file_rewind (stream);
+ stream.rewind ();
print_scalar_formatted (&mbuf[col_byte], word_type, &opts,
- word_asize, stream);
+ word_asize, &stream);
ui_out_field_stream (uiout, NULL, stream);
}
}
@@ -1566,22 +1557,22 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
{
int byte;
- ui_file_rewind (stream);
+ stream.rewind ();
for (byte = row_byte;
byte < row_byte + word_size * nr_cols; byte++)
{
if (byte >= nr_bytes)
- fputc_unfiltered ('X', stream);
+ stream.putc ('X');
else if (mbuf[byte] < 32 || mbuf[byte] > 126)
- fputc_unfiltered (aschar, stream);
+ stream.putc (aschar);
else
- fputc_unfiltered (mbuf[byte], stream);
+ stream.putc (mbuf[byte]);
}
ui_out_field_stream (uiout, "ascii", stream);
}
do_cleanups (cleanup_tuple);
}
- do_cleanups (cleanup_stream);
+ do_cleanups (cleanup_list);
}
}
@@ -2316,15 +2307,12 @@ mi_cmd_execute (struct mi_parse *parse)
else
{
/* FIXME: DELETE THIS. */
- struct ui_file *stb;
-
- stb = mem_fileopen ();
+ string_file stb;
- fputs_unfiltered ("Undefined mi command: ", stb);
- fputstr_unfiltered (parse->command, '"', stb);
- fputs_unfiltered (" (missing implementation)", stb);
+ stb.puts ("Undefined mi command: ");
+ stb.putstr (parse->command, '"');
+ stb.puts (" (missing implementation)");
- make_cleanup_ui_file_delete (stb);
error_stream (stb);
}
do_cleanups (cleanup);
@@ -2706,12 +2694,10 @@ print_variable_or_computed (const char *expression, enum print_values values)
{
struct cleanup *old_chain;
struct value *val;
- struct ui_file *stb;
struct type *type;
struct ui_out *uiout = current_uiout;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
expression_up expr = parse_expression (expression);
@@ -2720,6 +2706,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
else
val = evaluate_expression (expr.get ());
+ old_chain = make_cleanup (null_cleanup, NULL);
if (values != PRINT_NO_VALUES)
make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
ui_out_field_string (uiout, "name", expression);
@@ -2728,7 +2715,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
{
case PRINT_SIMPLE_VALUES:
type = check_typedef (value_type (val));
- type_print (value_type (val), "", stb, -1);
+ type_print (value_type (val), "", &stb, -1);
ui_out_field_stream (uiout, "type", stb);
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
&& TYPE_CODE (type) != TYPE_CODE_STRUCT
@@ -2738,7 +2725,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
get_no_prettyformat_print_options (&opts);
opts.deref_ref = 1;
- common_val_print (val, stb, 0, &opts, current_language);
+ common_val_print (val, &stb, 0, &opts, current_language);
ui_out_field_stream (uiout, "value", stb);
}
break;
@@ -2748,7 +2735,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
get_no_prettyformat_print_options (&opts);
opts.deref_ref = 1;
- common_val_print (val, stb, 0, &opts, current_language);
+ common_val_print (val, &stb, 0, &opts, current_language);
ui_out_field_stream (uiout, "value", stb);
}
break;
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 95132678013..d281304fbbf 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -390,8 +390,8 @@ mi_out_put (struct ui_out *uiout, struct ui_file *stream)
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
struct ui_file *outstream = VEC_last (ui_filep, data->streams);
- ui_file_put (outstream, ui_file_write_for_put, stream);
- ui_file_rewind (outstream);
+ outstream->write_buffer_on (*stream);
+ outstream->rewind ();
}
/* Return the current MI version. */
@@ -426,6 +426,8 @@ mi_out_data_dtor (struct ui_out *ui_out)
{
mi_out_data *data = (mi_out_data *) ui_out_data (ui_out);
+ /* XXX: Aren't we leaking the streams? */
+
VEC_free (ui_filep, data->streams);
xfree (data);
}
@@ -437,7 +439,7 @@ mi_out_new (int mi_version)
{
int flags = 0;
mi_out_data *data = XNEW (mi_out_data);
- struct ui_file *stream = mem_fileopen ();
+ struct ui_file *stream = new string_file ();
mi_out_data_ctor (data, mi_version, stream);
return ui_out_new (&mi_ui_out_impl, data, flags);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index f434f5f70ab..a61d6665fb3 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2716,16 +2716,12 @@ printf_command (char *arg, int from_tty)
static void
eval_command (char *arg, int from_tty)
{
- struct ui_file *ui_out = mem_fileopen ();
- struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out);
+ string_file stb;
- ui_printf (arg, ui_out);
-
- std::string expanded = ui_file_as_string (ui_out);
+ ui_printf (arg, &stb);
+ std::string &expanded = stb.string ();
execute_command (&expanded[0], from_tty);
-
- do_cleanups (cleanups);
}
void
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 825df771e55..2113d5c6831 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1953,7 +1953,6 @@ static void
maintenance_print_psymbols (char *args, int from_tty)
{
char **argv;
- struct ui_file *outfile;
struct cleanup *cleanups;
char *symname = NULL;
char *filename = DEV_TTY;
@@ -1983,23 +1982,23 @@ print-psymbols takes an output file name and optional symbol file name"));
filename = tilde_expand (filename);
make_cleanup (xfree, filename);
- outfile = gdb_fopen (filename, FOPEN_WT);
- if (outfile == NULL)
+ stdio_file outfile;
+
+ if (!outfile.open (filename, FOPEN_WT))
perror_with_name (filename);
- make_cleanup_ui_file_delete (outfile);
ALL_OBJFILES (objfile)
{
- fprintf_filtered (outfile, "\nPartial symtabs for objfile %s\n",
- objfile_name (objfile));
+ outfile.printf ("\nPartial symtabs for objfile %s\n",
+ objfile_name (objfile));
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
{
QUIT;
if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
{
- dump_psymtab (objfile, ps, outfile);
- dump_psymtab_addrmap (objfile, ps, outfile);
+ dump_psymtab (objfile, ps, &outfile);
+ dump_psymtab_addrmap (objfile, ps, &outfile);
}
}
@@ -2007,8 +2006,8 @@ print-psymbols takes an output file name and optional symbol file name"));
if (symname == NULL)
{
- fprintf_filtered (outfile, "\n");
- dump_psymtab_addrmap (objfile, NULL, outfile);
+ outfile.puts ("\n");
+ dump_psymtab_addrmap (objfile, NULL, &outfile);
}
}
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 60cc5a9dd26..854cb40d1cb 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -198,60 +198,49 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
|| (end_obj == NULL && count_obj == NULL && pc == start);)
{
int insn_len = 0;
- struct ui_file *memfile = mem_fileopen ();
PyObject *insn_dict = PyDict_New ();
if (insn_dict == NULL)
{
Py_DECREF (result_list);
- ui_file_delete (memfile);
-
return NULL;
}
if (PyList_Append (result_list, insn_dict))
{
Py_DECREF (result_list);
Py_DECREF (insn_dict);
- ui_file_delete (memfile);
-
return NULL; /* PyList_Append Sets the exception. */
}
+ string_file stb;
+
TRY
{
- insn_len = gdb_print_insn (gdbarch, pc, memfile, NULL);
+ insn_len = gdb_print_insn (gdbarch, pc, &stb, NULL);
}
CATCH (except, RETURN_MASK_ALL)
{
Py_DECREF (result_list);
- ui_file_delete (memfile);
-
gdbpy_convert_exception (except);
return NULL;
}
END_CATCH
- std::string as = ui_file_as_string (memfile);
-
if (PyDict_SetItemString (insn_dict, "addr",
gdb_py_long_from_ulongest (pc))
|| PyDict_SetItemString (insn_dict, "asm",
- PyString_FromString (!as.empty ()
- ? as.c_str ()
+ PyString_FromString (!stb.empty ()
+ ? stb.c_str ()
: "<unknown>"))
|| PyDict_SetItemString (insn_dict, "length",
PyInt_FromLong (insn_len)))
{
Py_DECREF (result_list);
-
- ui_file_delete (memfile);
-
return NULL;
}
pc += insn_len;
i++;
- ui_file_delete (memfile);
}
return result_list;
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 0897acf7389..4f73197b674 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -485,19 +485,16 @@ bppy_get_commands (PyObject *self, void *closure)
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
struct breakpoint *bp = self_bp->bp;
long length;
- struct ui_file *string_file;
PyObject *result;
- struct cleanup *chain;
BPPY_REQUIRE_VALID (self_bp);
if (! self_bp->bp->commands)
Py_RETURN_NONE;
- string_file = mem_fileopen ();
- chain = make_cleanup_ui_file_delete (string_file);
+ string_file stb;
- ui_out_redirect (current_uiout, string_file);
+ ui_out_redirect (current_uiout, &stb);
TRY
{
print_command_lines (current_uiout, breakpoint_commands (bp), 0);
@@ -505,17 +502,13 @@ bppy_get_commands (PyObject *self, void *closure)
CATCH (except, RETURN_MASK_ALL)
{
ui_out_redirect (current_uiout, NULL);
- do_cleanups (chain);
gdbpy_convert_exception (except);
return NULL;
}
END_CATCH
ui_out_redirect (current_uiout, NULL);
- std::string cmdstr = ui_file_as_string (string_file);
- result = host_string_to_python_string (cmdstr.c_str ());
- do_cleanups (chain);
- return result;
+ return host_string_to_python_string (stb.c_str ());
}
/* Python function to get the breakpoint type. */
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 7c958036f83..258d30c1052 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -80,13 +80,10 @@ frame_object_to_frame_info (PyObject *obj)
static PyObject *
frapy_str (PyObject *self)
{
- PyObject *result;
- struct ui_file *strfile;
+ string_file strfile;
- strfile = mem_fileopen ();
- fprint_frame_id (strfile, ((frame_object *) self)->frame_id);
- std::string s = ui_file_as_string (strfile);
- return PyString_FromString (s.c_str ());
+ fprint_frame_id (&strfile, ((frame_object *) self)->frame_id);
+ return PyString_FromString (strfile.c_str ());
}
/* Implementation of gdb.Frame.is_valid (self) -> Boolean.
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 3beea129f21..0497d09c20b 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -212,15 +212,11 @@ py_print_type (struct ui_out *out, struct value *val)
TRY
{
- struct ui_file *stb;
- struct cleanup *cleanup;
-
- stb = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (stb);
check_typedef (value_type (val));
- type_print (value_type (val), "", stb, -1);
+
+ string_file stb;
+ type_print (value_type (val), "", &stb, -1);
ui_out_field_stream (out, "type", stb);
- do_cleanups (cleanup);
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -284,14 +280,10 @@ py_print_value (struct ui_out *out, struct value *val,
{
TRY
{
- struct ui_file *stb;
- struct cleanup *cleanup;
+ string_file stb;
- stb = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (stb);
- common_val_print (val, stb, indent, opts, language);
+ common_val_print (val, &stb, indent, opts, language);
ui_out_field_stream (out, "value", stb);
- do_cleanups (cleanup);
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -400,26 +392,22 @@ py_print_single_arg (struct ui_out *out,
entry value options. */
if (fa != NULL)
{
- struct ui_file *stb;
+ string_file stb;
- stb = mem_fileopen ();
- make_cleanup_ui_file_delete (stb);
- fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (fa->sym),
+ fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (fa->sym),
SYMBOL_LANGUAGE (fa->sym),
DMGL_PARAMS | DMGL_ANSI);
if (fa->entry_kind == print_entry_values_compact)
{
- fputs_filtered ("=", stb);
+ stb.puts ("=");
- fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (fa->sym),
+ fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (fa->sym),
SYMBOL_LANGUAGE (fa->sym),
DMGL_PARAMS | DMGL_ANSI);
}
if (fa->entry_kind == print_entry_values_only
|| fa->entry_kind == print_entry_values_compact)
- {
- fputs_filtered ("@entry", stb);
- }
+ stb.puts ("@entry");
ui_out_field_stream (out, "name", stb);
}
else
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 17fa297960b..94112f06d2c 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1010,22 +1010,13 @@ typy_template_argument (PyObject *self, PyObject *args)
static PyObject *
typy_str (PyObject *self)
{
- std::string thetype;
+ string_file thetype;
PyObject *result;
TRY
{
- struct cleanup *old_chain;
- struct ui_file *stb;
-
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
- LA_PRINT_TYPE (type_object_to_type (self), "", stb, -1, 0,
+ LA_PRINT_TYPE (type_object_to_type (self), "", &thetype, -1, 0,
&type_print_raw_options);
-
- thetype = ui_file_as_string (stb);
- do_cleanups (old_chain);
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -1033,10 +1024,8 @@ typy_str (PyObject *self)
}
END_CATCH
- result = PyUnicode_Decode (thetype.c_str (), thetype.length (),
- host_charset (), NULL);
-
- return result;
+ return PyUnicode_Decode (thetype.c_str (), thetype.size (),
+ host_charset (), NULL);
}
/* Implement the richcompare method. */
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 65c705f04ca..ba214ffc7fe 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -198,12 +198,11 @@ pyuw_object_attribute_to_pointer (PyObject *pyo, const char *attr_name,
static PyObject *
unwind_infopy_str (PyObject *self)
{
- struct ui_file *strfile = mem_fileopen ();
unwind_info_object *unwind_info = (unwind_info_object *) self;
- PyObject *result;
+ string_file stb;
- fprintf_unfiltered (strfile, "Frame ID: ");
- fprint_frame_id (strfile, unwind_info->frame_id);
+ stb.puts ("Frame ID: ");
+ fprint_frame_id (&stb, unwind_info->frame_id);
{
char *sep = "";
int i;
@@ -211,18 +210,18 @@ unwind_infopy_str (PyObject *self)
saved_reg *reg;
get_user_print_options (&opts);
- fprintf_unfiltered (strfile, "\nSaved registers: (");
+ stb.printf ("\nSaved registers: (");
for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
{
struct value *value = value_object_to_value (reg->value);
- fprintf_unfiltered (strfile, "%s(%d, ", sep, reg->number);
+ stb.printf ("%s(%d, ", sep, reg->number);
if (value != NULL)
{
TRY
{
- value_print (value, strfile, &opts);
- fprintf_unfiltered (strfile, ")");
+ value_print (value, &stb, &opts);
+ stb.puts (")");
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -231,16 +230,13 @@ unwind_infopy_str (PyObject *self)
END_CATCH
}
else
- fprintf_unfiltered (strfile, "<BAD>)");
+ stb.puts ("<BAD>)");
sep = ", ";
}
- fprintf_unfiltered (strfile, ")");
+ stb.puts (")");
}
- std::string s = ui_file_as_string (strfile);
- result = PyString_FromString (s.c_str ());
- ui_file_delete (strfile);
- return result;
+ return PyString_FromString (stb.c_str ());
}
/* Create UnwindInfo instance for given PendingFrame and frame ID.
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index b959f2e10dd..5bd0043cde4 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -895,23 +895,17 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
static PyObject *
valpy_str (PyObject *self)
{
- std::string s;
- PyObject *result;
struct value_print_options opts;
get_user_print_options (&opts);
opts.deref_ref = 0;
+ string_file stb;
+
TRY
{
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
-
- common_val_print (((value_object *) self)->value, stb, 0,
+ common_val_print (((value_object *) self)->value, &stb, 0,
&opts, python_language);
- s = ui_file_as_string (stb);
-
- do_cleanups (old_chain);
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -919,9 +913,7 @@ valpy_str (PyObject *self)
}
END_CATCH
- result = PyUnicode_Decode (s.c_str (), s.length (), host_charset (), NULL);
-
- return result;
+ return PyUnicode_Decode (stb.c_str (), stb.size (), host_charset (), NULL);
}
/* Implements gdb.Value.is_optimized_out. */
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 7c0e39f4af4..af421806f31 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -696,7 +696,6 @@ btrace_insn_history (struct ui_out *uiout,
const struct btrace_insn_iterator *begin,
const struct btrace_insn_iterator *end, int flags)
{
- struct ui_file *stb;
struct cleanup *cleanups, *ui_item_chain;
struct disassemble_info di;
struct gdbarch *gdbarch;
@@ -709,12 +708,11 @@ btrace_insn_history (struct ui_out *uiout,
flags |= DISASSEMBLY_SPECULATIVE;
gdbarch = target_gdbarch ();
- stb = mem_fileopen ();
- cleanups = make_cleanup_ui_file_delete (stb);
- di = gdb_disassemble_info (gdbarch, stb);
+ string_file stb;
+ di = gdb_disassemble_info (gdbarch, &stb);
last_lines = btrace_mk_line_range (NULL, 0, 0);
- make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
+ cleanups = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
/* UI_ITEM_CHAIN is a cleanup chain for the last source line and the
instructions corresponding to that line. */
diff --git a/gdb/regcache.c b/gdb/regcache.c
index a5c90a6314c..b5bd62e9416 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1484,14 +1484,11 @@ regcache_print (char *args, enum regcache_dump_what what_to_dump)
regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
else
{
- struct cleanup *cleanups;
- struct ui_file *file = gdb_fopen (args, "w");
+ stdio_file file;
- if (file == NULL)
+ if (!file.open (args, "w"))
perror_with_name (_("maintenance print architecture"));
- cleanups = make_cleanup_ui_file_delete (file);
- regcache_dump (get_current_regcache (), file, what_to_dump);
- do_cleanups (cleanups);
+ regcache_dump (get_current_regcache (), &file, what_to_dump);
}
}
diff --git a/gdb/reggroups.c b/gdb/reggroups.c
index f8e7abd865b..323f8fa5ad8 100644
--- a/gdb/reggroups.c
+++ b/gdb/reggroups.c
@@ -270,14 +270,11 @@ maintenance_print_reggroups (char *args, int from_tty)
reggroups_dump (gdbarch, gdb_stdout);
else
{
- struct cleanup *cleanups;
- struct ui_file *file = gdb_fopen (args, "w");
+ stdio_file file;
- if (file == NULL)
+ if (!file.open (args, "w"))
perror_with_name (_("maintenance print reggroups"));
- cleanups = make_cleanup_ui_file_delete (file);
- reggroups_dump (gdbarch, file);
- do_cleanups (cleanups);
+ reggroups_dump (gdbarch, &file);
}
}
diff --git a/gdb/remote.c b/gdb/remote.c
index adae5ec18d6..d07bcfb1ab0 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8656,16 +8656,10 @@ remote_send (char **buf,
static std::string
escape_buffer (const char *buf, int n)
{
- struct cleanup *old_chain;
- struct ui_file *stb;
-
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
- fputstrn_unfiltered (buf, n, '\\', stb);
- std::string str = ui_file_as_string (stb);
- do_cleanups (old_chain);
- return str;
+ stb.putstrn (buf, n, '\\');
+ return std::move (stb.string ());
}
/* Display a null-terminated packet on stdout, for debugging, using C
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 9bc5febfbba..55279e9687b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -125,7 +125,6 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
int i;
struct disr_info ret;
struct type *disr_type;
- struct ui_file *temp_file;
struct value_print_options opts;
struct cleanup *cleanup;
const char *name_segment;
@@ -229,17 +228,16 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
if (strcmp (TYPE_FIELD_NAME (disr_type, 0), "RUST$ENUM$DISR") != 0)
error (_("Rust debug format has changed"));
- temp_file = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (temp_file);
+ string_file temp_file;
/* The first value of the first field (or any field)
is the discriminant value. */
c_val_print (TYPE_FIELD_TYPE (disr_type, 0),
(embedded_offset + TYPE_FIELD_BITPOS (type, 0) / 8
+ TYPE_FIELD_BITPOS (disr_type, 0) / 8),
- address, temp_file,
+ address, &temp_file,
0, val, &opts);
- ret.name = ui_file_as_string (temp_file);
+ ret.name = std::move (temp_file.string ());
name_segment = rust_last_path_segment (ret.name.c_str ());
if (name_segment != NULL)
{
@@ -271,7 +269,6 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
TYPE_TAG_NAME (type), ret.name.c_str ());
}
- do_cleanups (cleanup);
return ret;
}
diff --git a/gdb/serial.c b/gdb/serial.c
index a95f85e287b..87e7c3ac07f 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -255,9 +255,12 @@ serial_open_ops_1 (const struct serial_ops *ops, const char *open_name)
if (serial_logfile != NULL)
{
- serial_logfp = gdb_fopen (serial_logfile, "w");
- if (serial_logfp == NULL)
+ std::unique_ptr<stdio_file> file (new stdio_file ());
+
+ if (!file->open (serial_logfile, "w"))
perror_with_name (serial_logfile);
+
+ serial_logfp = file.release ();
}
return scb;
@@ -319,7 +322,7 @@ do_serial_close (struct serial *scb, int really_close)
serial_current_type = 0;
/* XXX - What if serial_logfp == gdb_stdout or gdb_stderr? */
- ui_file_delete (serial_logfp);
+ delete serial_logfp;
serial_logfp = NULL;
}
diff --git a/gdb/stack.c b/gdb/stack.c
index 9b4e356fd80..36b2de612e8 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -225,11 +225,9 @@ print_frame_arg (const struct frame_arg *arg)
{
struct ui_out *uiout = current_uiout;
struct cleanup *old_chain;
- struct ui_file *stb;
const char *error_message = NULL;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
gdb_assert (!arg->val || !arg->error);
gdb_assert (arg->entry_kind == print_entry_values_no
@@ -239,22 +237,22 @@ print_frame_arg (const struct frame_arg *arg)
annotate_arg_begin ();
- make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
- fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
+ old_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
if (arg->entry_kind == print_entry_values_compact)
{
/* It is OK to provide invalid MI-like stream as with
PRINT_ENTRY_VALUE_COMPACT we never use MI. */
- fputs_filtered ("=", stb);
+ stb.puts ("=");
- fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
+ fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
SYMBOL_LANGUAGE (arg->sym),
DMGL_PARAMS | DMGL_ANSI);
}
if (arg->entry_kind == print_entry_values_only
|| arg->entry_kind == print_entry_values_compact)
- fputs_filtered ("@entry", stb);
+ stb.puts ("@entry");
ui_out_field_stream (uiout, "name", stb);
annotate_arg_name_end ();
ui_out_text (uiout, "=");
@@ -294,7 +292,7 @@ print_frame_arg (const struct frame_arg *arg)
/* True in "summary" mode, false otherwise. */
opts.summary = !strcmp (print_frame_arguments, "scalars");
- common_val_print (arg->val, stb, 2, &opts, language);
+ common_val_print (arg->val, &stb, 2, &opts, language);
}
CATCH (except, RETURN_MASK_ERROR)
{
@@ -303,8 +301,7 @@ print_frame_arg (const struct frame_arg *arg)
END_CATCH
}
if (error_message != NULL)
- fprintf_filtered (stb, _("<error reading variable: %s>"),
- error_message);
+ stb.printf (_("<error reading variable: %s>"), error_message);
}
ui_out_field_stream (uiout, "value", stb);
@@ -554,13 +551,9 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
/* Number of ints of arguments that we have printed so far. */
int args_printed = 0;
struct cleanup *old_chain;
- struct ui_file *stb;
/* True if we should print arguments, false otherwise. */
int print_args = strcmp (print_frame_arguments, "none");
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
if (func)
{
const struct block *b = SYMBOL_BLOCK_VALUE (func);
@@ -730,8 +723,6 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
print_frame_nameless_args (frame, start, num - args_printed,
first, stream);
}
-
- do_cleanups (old_chain);
}
/* Set the current source and line to the location given by frame
@@ -1165,7 +1156,6 @@ print_frame (struct frame_info *frame, int print_level,
struct ui_out *uiout = current_uiout;
char *funname = NULL;
enum language funlang = language_unknown;
- struct ui_file *stb;
struct cleanup *old_chain, *list_chain;
struct value_print_options opts;
struct symbol *func;
@@ -1174,11 +1164,9 @@ print_frame (struct frame_info *frame, int print_level,
pc_p = get_frame_pc_if_available (frame, &pc);
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
find_frame_funname (frame, &funname, &funlang, &func);
- make_cleanup (xfree, funname);
+ old_chain = make_cleanup (xfree, funname);
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
gdbarch, pc);
@@ -1206,7 +1194,9 @@ print_frame (struct frame_info *frame, int print_level,
ui_out_text (uiout, " in ");
}
annotate_frame_function_name ();
- fprintf_symbol_filtered (stb, funname ? funname : "??",
+
+ string_file stb;
+ fprintf_symbol_filtered (&stb, funname ? funname : "??",
funlang, DMGL_ANSI);
ui_out_field_stream (uiout, "func", stb);
ui_out_wrap_hint (uiout, " ");
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index bba8a710df0..3fe388f8ebb 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -412,7 +412,6 @@ static void
maintenance_print_symbols (char *args, int from_tty)
{
char **argv;
- struct ui_file *outfile;
struct cleanup *cleanups;
char *symname = NULL;
char *filename = DEV_TTY;
@@ -443,18 +442,19 @@ maintenance_print_symbols (char *args, int from_tty)
filename = tilde_expand (filename);
make_cleanup (xfree, filename);
- outfile = gdb_fopen (filename, FOPEN_WT);
- if (outfile == 0)
+ stdio_file outfile;
+
+ if (!outfile.open (filename, FOPEN_WT))
perror_with_name (filename);
- make_cleanup_ui_file_delete (outfile);
ALL_FILETABS (objfile, cu, s)
{
QUIT;
if (symname == NULL
|| filename_cmp (symname, symtab_to_filename_for_display (s)) == 0)
- dump_symtab (s, outfile);
+ dump_symtab (s, &outfile);
}
+
do_cleanups (cleanups);
}
@@ -644,7 +644,6 @@ static void
maintenance_print_msymbols (char *args, int from_tty)
{
char **argv;
- struct ui_file *outfile;
struct cleanup *cleanups;
char *filename = DEV_TTY;
char *symname = NULL;
@@ -679,10 +678,10 @@ maintenance_print_msymbols (char *args, int from_tty)
filename = tilde_expand (filename);
make_cleanup (xfree, filename);
- outfile = gdb_fopen (filename, FOPEN_WT);
- if (outfile == 0)
+ stdio_file outfile;
+
+ if (!outfile.open (filename, FOPEN_WT))
perror_with_name (filename);
- make_cleanup_ui_file_delete (outfile);
ALL_PSPACES (pspace)
ALL_PSPACE_OBJFILES (pspace, objfile)
@@ -691,9 +690,10 @@ maintenance_print_msymbols (char *args, int from_tty)
if (symname == NULL || (!stat (objfile_name (objfile), &obj_st)
&& sym_st.st_dev == obj_st.st_dev
&& sym_st.st_ino == obj_st.st_ino))
- dump_msymbols (objfile, outfile);
+ dump_msymbols (objfile, &outfile);
}
- fprintf_filtered (outfile, "\n\n");
+ outfile.puts ("\n\n");
+
do_cleanups (cleanups);
}
diff --git a/gdb/symtab.h b/gdb/symtab.h
index a6bf65598c4..08a68e03e2a 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -674,7 +674,7 @@ struct symbol_computed_ops
The generated C code must assign the location to a local
variable; this variable's name is RESULT_NAME. */
- void (*generate_c_location) (struct symbol *symbol, struct ui_file *stream,
+ void (*generate_c_location) (struct symbol *symbol, string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc, const char *result_name);
diff --git a/gdb/top.c b/gdb/top.c
index 989113614de..a1ee6076a79 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -272,9 +272,9 @@ new_ui (FILE *instream, FILE *outstream, FILE *errstream)
ui->input_interactive_p = ISATTY (ui->instream);
- ui->m_gdb_stdin = stdio_fileopen (ui->instream);
- ui->m_gdb_stdout = stdio_fileopen (ui->outstream);
- ui->m_gdb_stderr = stderr_fileopen (ui->errstream);
+ ui->m_gdb_stdin = new stdio_file (ui->instream);
+ ui->m_gdb_stdout = new stdio_file (ui->outstream);
+ ui->m_gdb_stderr = new stderr_file (ui->errstream);
ui->m_gdb_stdlog = ui->m_gdb_stderr;
ui->prompt_state = PROMPT_NEEDED;
@@ -296,9 +296,9 @@ new_ui (FILE *instream, FILE *outstream, FILE *errstream)
static void
free_ui (struct ui *ui)
{
- ui_file_delete (ui->m_gdb_stdin);
- ui_file_delete (ui->m_gdb_stdout);
- ui_file_delete (ui->m_gdb_stderr);
+ delete ui->m_gdb_stdin;
+ delete ui->m_gdb_stdout;
+ delete ui->m_gdb_stderr;
xfree (ui);
}
@@ -693,7 +693,6 @@ execute_command (char *p, int from_tty)
std::string
execute_command_to_string (char *p, int from_tty)
{
- struct ui_file *str_file;
struct cleanup *cleanup;
/* GDB_STDOUT should be better already restored during these
@@ -702,33 +701,29 @@ execute_command_to_string (char *p, int from_tty)
scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
- str_file = mem_fileopen ();
+ string_file str_file;
- make_cleanup_ui_file_delete (str_file);
-
- if (ui_out_redirect (current_uiout, str_file) < 0)
+ if (ui_out_redirect (current_uiout, &str_file) < 0)
warning (_("Current output protocol does not support redirection"));
else
make_cleanup_ui_out_redirect_pop (current_uiout);
scoped_restore save_stdout
- = make_scoped_restore (&gdb_stdout, str_file);
+ = make_scoped_restore (&gdb_stdout, &str_file);
scoped_restore save_stderr
- = make_scoped_restore (&gdb_stderr, str_file);
+ = make_scoped_restore (&gdb_stderr, &str_file);
scoped_restore save_stdlog
- = make_scoped_restore (&gdb_stdlog, str_file);
+ = make_scoped_restore (&gdb_stdlog, &str_file);
scoped_restore save_stdtarg
- = make_scoped_restore (&gdb_stdtarg, str_file);
+ = make_scoped_restore (&gdb_stdtarg, &str_file);
scoped_restore save_stdtargerr
- = make_scoped_restore (&gdb_stdtargerr, str_file);
+ = make_scoped_restore (&gdb_stdtargerr, &str_file);
execute_command (p, from_tty);
- std::string retval = ui_file_as_string (str_file);
-
do_cleanups (cleanup);
- return retval;
+ return std::move (str_file.string ());
}
@@ -1574,26 +1569,18 @@ print_inferior_quit_action (struct inferior *inf, void *arg)
int
quit_confirm (void)
{
- struct ui_file *stb;
- struct cleanup *old_chain;
-
/* Don't even ask if we're only debugging a core file inferior. */
if (!have_live_inferiors ())
return 1;
/* Build the query string as a single string. */
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
- fprintf_filtered (stb, _("A debugging session is active.\n\n"));
- iterate_over_inferiors (print_inferior_quit_action, stb);
- fprintf_filtered (stb, _("\nQuit anyway? "));
+ string_file stb;
- std::string str = ui_file_as_string (stb);
-
- do_cleanups (old_chain);
+ stb.puts (_("A debugging session is active.\n\n"));
+ iterate_over_inferiors (print_inferior_quit_action, &stb);
+ stb.puts (_("\nQuit anyway? "));
- return query ("%s", str.c_str ());
+ return query ("%s", stb.c_str ());
}
/* Prepare to exit GDB cleanly by undoing any changes made to the
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 7435380b41b..78929862cd3 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1304,12 +1304,11 @@ collection_list::stringify ()
void
collection_list::append_exp (struct expression *exp)
{
- struct ui_file *tmp_stream = mem_fileopen ();
+ string_file tmp_stream;
- print_expression (exp, tmp_stream);
+ print_expression (exp, &tmp_stream);
- m_computed.push_back (ui_file_as_string (tmp_stream));
- ui_file_delete (tmp_stream);
+ m_computed.push_back (std::move (tmp_stream.string ()));
}
void
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 6811be3f519..d465438a4f4 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -54,10 +54,7 @@ static CORE_ADDR
tui_disassemble (struct gdbarch *gdbarch, struct tui_asm_line *asm_lines,
CORE_ADDR pc, int count)
{
- struct ui_file *gdb_dis_out;
-
- /* Now init the ui_file structure. */
- gdb_dis_out = tui_sfileopen (256);
+ string_file gdb_dis_out;
/* Now construct each line. */
for (; count > 0; count--, asm_lines++)
@@ -67,20 +64,19 @@ tui_disassemble (struct gdbarch *gdbarch, struct tui_asm_line *asm_lines,
if (asm_lines->insn)
xfree (asm_lines->insn);
- print_address (gdbarch, pc, gdb_dis_out);
+ print_address (gdbarch, pc, &gdb_dis_out);
asm_lines->addr = pc;
- asm_lines->addr_string = xstrdup (tui_file_get_strbuf (gdb_dis_out));
+ asm_lines->addr_string = xstrdup (gdb_dis_out.c_str ());
- ui_file_rewind (gdb_dis_out);
+ gdb_dis_out.rewind ();
- pc = pc + gdb_print_insn (gdbarch, pc, gdb_dis_out, NULL);
+ pc = pc + gdb_print_insn (gdbarch, pc, &gdb_dis_out, NULL);
- asm_lines->insn = xstrdup (tui_file_get_strbuf (gdb_dis_out));
+ asm_lines->insn = xstrdup (gdb_dis_out.c_str ());
/* Reset the buffer to empty. */
- ui_file_rewind (gdb_dis_out);
+ gdb_dis_out.rewind ();
}
- ui_file_delete (gdb_dis_out);
return pc;
}
diff --git a/gdb/tui/tui-file.c b/gdb/tui/tui-file.c
index 6cac1d3ff35..7b0de637f86 100644
--- a/gdb/tui/tui-file.c
+++ b/gdb/tui/tui-file.c
@@ -17,145 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
-#include "ui-file.h"
#include "tui/tui-file.h"
#include "tui/tui-io.h"
#include "tui/tui-command.h"
#include "tui.h"
-/* A ``struct ui_file'' that is compatible with all the legacy
- code. */
-
-/* new */
-enum streamtype
-{
- afile,
- astring
-};
-
-/* new */
-struct tui_stream
-{
- int *ts_magic;
- enum streamtype ts_streamtype;
- FILE *ts_filestream;
- char *ts_strbuf;
- int ts_buflen;
-};
-
-static ui_file_flush_ftype tui_file_flush;
-extern ui_file_fputs_ftype tui_file_fputs;
-static ui_file_isatty_ftype tui_file_isatty;
-static ui_file_rewind_ftype tui_file_rewind;
-static ui_file_put_ftype tui_file_put;
-static ui_file_delete_ftype tui_file_delete;
-static struct ui_file *tui_file_new (void);
-static int tui_file_magic;
-
-static struct ui_file *
-tui_file_new (void)
-{
- struct tui_stream *tui = XNEW (struct tui_stream);
- struct ui_file *file = ui_file_new ();
-
- set_ui_file_data (file, tui, tui_file_delete);
- set_ui_file_flush (file, tui_file_flush);
- set_ui_file_fputs (file, tui_file_fputs);
- set_ui_file_isatty (file, tui_file_isatty);
- set_ui_file_rewind (file, tui_file_rewind);
- set_ui_file_put (file, tui_file_put);
- tui->ts_magic = &tui_file_magic;
- return file;
-}
-
-static void
-tui_file_delete (struct ui_file *file)
-{
- struct tui_stream *tmpstream = (struct tui_stream *) ui_file_data (file);
-
- if (tmpstream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_delete: bad magic number"));
- if ((tmpstream->ts_streamtype == astring)
- && (tmpstream->ts_strbuf != NULL))
- {
- xfree (tmpstream->ts_strbuf);
- }
- xfree (tmpstream);
-}
-
-struct ui_file *
-tui_fileopen (FILE *stream)
-{
- struct ui_file *file = tui_file_new ();
- struct tui_stream *tmpstream = (struct tui_stream *) ui_file_data (file);
-
- tmpstream->ts_streamtype = afile;
- tmpstream->ts_filestream = stream;
- tmpstream->ts_strbuf = NULL;
- tmpstream->ts_buflen = 0;
- return file;
-}
-
-struct ui_file *
-tui_sfileopen (int n)
-{
- struct ui_file *file = tui_file_new ();
- struct tui_stream *tmpstream = (struct tui_stream *) ui_file_data (file);
-
- tmpstream->ts_streamtype = astring;
- tmpstream->ts_filestream = NULL;
- if (n > 0)
- {
- tmpstream->ts_strbuf = XNEWVEC (char, n + 1);
- tmpstream->ts_strbuf[0] = '\0';
- }
- else
- /* Do not allocate the buffer now. The first time something is
- printed one will be allocated by tui_file_adjust_strbuf(). */
- tmpstream->ts_strbuf = NULL;
- tmpstream->ts_buflen = n;
- return file;
-}
-
-static int
-tui_file_isatty (struct ui_file *file)
-{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
-
- if (stream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_isatty: bad magic number"));
- if (stream->ts_streamtype == afile)
- return (isatty (fileno (stream->ts_filestream)));
- else
- return 0;
-}
-
-static void
-tui_file_rewind (struct ui_file *file)
-{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
-
- if (stream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_rewind: bad magic number"));
- stream->ts_strbuf[0] = '\0';
-}
-
-static void
-tui_file_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
-{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
-
- if (stream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_put: bad magic number"));
- if (stream->ts_streamtype == astring)
- write (dest, stream->ts_strbuf, strlen (stream->ts_strbuf));
-}
+tui_file::tui_file (FILE *stream)
+ : stdio_file (stream)
+{}
/* All TUI I/O sent to the *_filtered and *_unfiltered functions
eventually ends up here. The fputs_unfiltered_hook is primarily
@@ -164,91 +33,22 @@ tui_file_put (struct ui_file *file,
gdb_stderr are sent to the hook. Everything else is sent on to
fputs to allow file I/O to be handled appropriately. */
-/* FIXME: Should be broken up and moved to a TUI specific file. */
-
void
-tui_file_fputs (const char *linebuffer, struct ui_file *file)
-{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
-
- if (stream->ts_streamtype == astring)
- {
- tui_file_adjust_strbuf (strlen (linebuffer), file);
- strcat (stream->ts_strbuf, linebuffer);
- }
- else
- {
- tui_puts (linebuffer);
- /* gdb_stdout is buffered, and the caller must gdb_flush it at
- appropriate times. Other streams are not so buffered. */
- if (file != gdb_stdout)
- tui_refresh_cmd_win ();
- }
-}
-
-char *
-tui_file_get_strbuf (struct ui_file *file)
+tui_file::puts (const char *linebuffer)
{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
-
- if (stream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_get_strbuf: bad magic number"));
- return (stream->ts_strbuf);
+ tui_puts (linebuffer);
+ /* gdb_stdout is buffered, and the caller must gdb_flush it at
+ appropriate times. Other streams are not so buffered. */
+ if (this != gdb_stdout)
+ tui_refresh_cmd_win ();
}
-/* Adjust the length of the buffer by the amount necessary to
- accomodate appending a string of length N to the buffer
- contents. */
void
-tui_file_adjust_strbuf (int n, struct ui_file *file)
-{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
- int non_null_chars;
-
- if (stream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_adjust_strbuf: bad magic number"));
-
- if (stream->ts_streamtype != astring)
- return;
-
- if (stream->ts_strbuf)
- {
- /* There is already a buffer allocated. */
- non_null_chars = strlen (stream->ts_strbuf);
-
- if (n > (stream->ts_buflen - non_null_chars - 1))
- {
- stream->ts_buflen = n + non_null_chars + 1;
- stream->ts_strbuf
- = XRESIZEVEC (char, stream->ts_strbuf, stream->ts_buflen);
- }
- }
- else
- /* No buffer yet, so allocate one of the desired size. */
- stream->ts_strbuf = XNEWVEC (char, n + 1);
-}
-
-static void
-tui_file_flush (struct ui_file *file)
+tui_file::flush ()
{
- struct tui_stream *stream = (struct tui_stream *) ui_file_data (file);
-
- if (stream->ts_magic != &tui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tui_file_flush: bad magic number"));
-
- switch (stream->ts_streamtype)
- {
- case astring:
- break;
- case afile:
- /* gdb_stdout is buffered. Other files are always flushed on
- every write. */
- if (file == gdb_stdout)
- tui_refresh_cmd_win ();
- fflush (stream->ts_filestream);
- break;
- }
+ /* gdb_stdout is buffered. Other files are always flushed on
+ every write. */
+ if (this == gdb_stdout)
+ tui_refresh_cmd_win ();
+ stdio_file::flush ();
}
diff --git a/gdb/tui/tui-file.h b/gdb/tui/tui-file.h
index e84d37111b1..a548dd2beb5 100644
--- a/gdb/tui/tui-file.h
+++ b/gdb/tui/tui-file.h
@@ -19,9 +19,18 @@
#ifndef TUI_FILE_H
#define TUI_FILE_H
-extern struct ui_file *tui_fileopen (FILE *);
-extern struct ui_file *tui_sfileopen (int);
-extern char *tui_file_get_strbuf (struct ui_file *);
-extern void tui_file_adjust_strbuf (int, struct ui_file *);
+#include "ui-file.h"
+
+/* A ``struct ui_file'' that is compatible with all the legacy
+ code. XXX */
+
+class tui_file : public stdio_file
+{
+public:
+ explicit tui_file (FILE *stream);
+
+ void flush () override;
+ void puts (const char *) override;
+};
#endif
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 93bed883281..3a0385b750e 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -526,8 +526,8 @@ tui_initialize_io (void)
#endif
/* Create tui output streams. */
- tui_stdout = tui_fileopen (stdout);
- tui_stderr = tui_fileopen (stderr);
+ tui_stdout = new tui_file (stdout);
+ tui_stderr = new tui_file (stderr);
tui_out = tui_out_new (tui_stdout);
/* Create the default UI. */
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 834e692db1f..00394ab84d6 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -711,7 +711,7 @@ TUI command to control the register window."), tuicmd);
static void
tui_restore_gdbout (void *ui)
{
- ui_file_delete (gdb_stdout);
+ delete gdb_stdout;
gdb_stdout = (struct ui_file*) ui;
pagination_enabled = 1;
}
@@ -723,29 +723,26 @@ static char *
tui_register_format (struct frame_info *frame, int regnum)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct ui_file *stream;
struct ui_file *old_stdout;
struct cleanup *cleanups;
char *p, *s;
char *ret;
+ string_file stream;
+
pagination_enabled = 0;
old_stdout = gdb_stdout;
- stream = tui_sfileopen (256);
- gdb_stdout = stream;
+ gdb_stdout = &stream;
cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout);
- gdbarch_print_registers_info (gdbarch, stream, frame, regnum, 1);
-
- /* Save formatted output in the buffer. */
- p = tui_file_get_strbuf (stream);
+ gdbarch_print_registers_info (gdbarch, &stream, frame, regnum, 1);
/* Remove the possible \n. */
- s = strrchr (p, '\n');
- if (s && s[1] == 0)
- *s = 0;
+ std::string &str = stream.string ();
+ if (!str.empty () && str.back () == '\n')
+ str.resize (str.size () - 1);
/* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */
- ret = tui_expand_tabs (p, 0);
+ ret = tui_expand_tabs (str.c_str (), 0);
do_cleanups (cleanups);
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;
}
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index c1b46beb88a..693558a1f3d 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -371,26 +371,19 @@ type_print (struct type *type, const char *varstring, struct ui_file *stream,
std::string
type_to_string (struct type *type)
{
- std::string s;
- struct ui_file *stb;
- struct cleanup *old_chain;
-
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
TRY
{
- type_print (type, "", stb, -1);
- s = ui_file_as_string (stb);
+ string_file stb;
+
+ type_print (type, "", &stb, -1);
+ return std::move (stb.string ());
}
CATCH (except, RETURN_MASK_ALL)
{
}
END_CATCH
- do_cleanups (old_chain);
-
- return s;
+ return std::string ();
}
/* Print type of EXP, or last thing in value history if EXP == NULL.
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index 07594895d01..c69af432093 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -25,193 +25,88 @@
#include "gdb_select.h"
#include "filestuff.h"
-static ui_file_isatty_ftype null_file_isatty;
-static ui_file_write_ftype null_file_write;
-static ui_file_write_ftype null_file_write_async_safe;
-static ui_file_fputs_ftype null_file_fputs;
-static ui_file_read_ftype null_file_read;
-static ui_file_flush_ftype null_file_flush;
-static ui_file_delete_ftype null_file_delete;
-static ui_file_rewind_ftype null_file_rewind;
-static ui_file_put_ftype null_file_put;
-static ui_file_fseek_ftype null_file_fseek;
-
-struct ui_file
- {
- int *magic;
- ui_file_flush_ftype *to_flush;
- ui_file_write_ftype *to_write;
- ui_file_write_async_safe_ftype *to_write_async_safe;
- ui_file_fputs_ftype *to_fputs;
- ui_file_read_ftype *to_read;
- ui_file_delete_ftype *to_delete;
- ui_file_isatty_ftype *to_isatty;
- ui_file_rewind_ftype *to_rewind;
- ui_file_put_ftype *to_put;
- ui_file_fseek_ftype *to_fseek;
- void *to_data;
- };
-int ui_file_magic;
-
-struct ui_file *
-ui_file_new (void)
-{
- struct ui_file *file = XNEW (struct ui_file);
-
- file->magic = &ui_file_magic;
- set_ui_file_data (file, NULL, null_file_delete);
- set_ui_file_flush (file, null_file_flush);
- set_ui_file_write (file, null_file_write);
- set_ui_file_write_async_safe (file, null_file_write_async_safe);
- set_ui_file_fputs (file, null_file_fputs);
- set_ui_file_read (file, null_file_read);
- set_ui_file_isatty (file, null_file_isatty);
- set_ui_file_rewind (file, null_file_rewind);
- set_ui_file_put (file, null_file_put);
- set_ui_file_fseek (file, null_file_fseek);
- return file;
-}
+null_file null_stream;
-void
-ui_file_delete (struct ui_file *file)
+ui_file::ui_file ()
{
- file->to_delete (file);
- xfree (file);
}
-static int
-null_file_isatty (struct ui_file *file)
+ui_file::~ui_file ()
{
- return 0;
}
-static void
-null_file_rewind (struct ui_file *file)
+void
+ui_file::printf (const char *format, ...)
{
- return;
-}
+ va_list args;
-static void
-null_file_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
-{
- return;
+ va_start (args, format);
+ vfprintf_unfiltered (this, format, args);
+ va_end (args);
}
-static void
-null_file_flush (struct ui_file *file)
+void
+ui_file::putstr (const char *str, int quoter)
{
- return;
+ fputstr_unfiltered (str, quoter, this);
}
-static void
-null_file_write (struct ui_file *file,
- const char *buf,
- long sizeof_buf)
+void
+ui_file::putstrn (const char *str, int n, int quoter)
{
- if (file->to_fputs == null_file_fputs)
- /* Both the write and fputs methods are null. Discard the
- request. */
- return;
- else
- {
- /* The fputs method isn't null, slowly pass the write request
- onto that. FYI, this isn't as bad as it may look - the
- current (as of 1999-11-07) printf_* function calls fputc and
- fputc does exactly the below. By having a write function it
- is possible to clean up that code. */
- int i;
- char b[2];
-
- b[1] = '\0';
- for (i = 0; i < sizeof_buf; i++)
- {
- b[0] = buf[i];
- file->to_fputs (b, file);
- }
- return;
- }
+ fputstrn_unfiltered (str, n, quoter, this);
}
-static long
-null_file_read (struct ui_file *file,
- char *buf,
- long sizeof_buf)
+int
+ui_file::putc (int c)
{
- errno = EBADF;
- return 0;
+ return fputc_unfiltered (c, this);
}
-static void
-null_file_fputs (const char *buf, struct ui_file *file)
-{
- if (file->to_write == null_file_write)
- /* Both the write and fputs methods are null. Discard the
- request. */
- return;
- else
- {
- /* The write method was implemented, use that. */
- file->to_write (file, buf, strlen (buf));
- }
-}
+
-static void
-null_file_write_async_safe (struct ui_file *file,
- const char *buf,
- long sizeof_buf)
+void
+ui_file::vprintf (const char *format, va_list args)
{
- return;
+ vfprintf_unfiltered (this, format, args);
}
-static void
-null_file_delete (struct ui_file *file)
+void
+null_file::write (const char *buf, long sizeof_buf)
{
- return;
+ /* Discard the request. */
}
-static int
-null_file_fseek (struct ui_file *stream, long offset, int whence)
+void
+null_file::puts (const char *)
{
- errno = EBADF;
-
- return -1;
+ /* Discard the request. */
}
-void *
-ui_file_data (struct ui_file *file)
+void
+null_file::write_async_safe (const char *buf, long sizeof_buf)
{
- if (file->magic != &ui_file_magic)
- internal_error (__FILE__, __LINE__,
- _("ui_file_data: bad magic number"));
- return file->to_data;
+ /* Discard the request. */
}
+
+
void
gdb_flush (struct ui_file *file)
{
- file->to_flush (file);
+ file->flush ();
}
int
ui_file_isatty (struct ui_file *file)
{
- return file->to_isatty (file);
+ return file->isatty ();
}
void
ui_file_rewind (struct ui_file *file)
{
- file->to_rewind (file);
-}
-
-void
-ui_file_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
-{
- file->to_put (file, write, dest);
+ file->rewind ();
}
void
@@ -219,13 +114,7 @@ ui_file_write (struct ui_file *file,
const char *buf,
long length_buf)
{
- file->to_write (file, buf, length_buf);
-}
-
-void
-ui_file_write_for_put (void *data, const char *buffer, long length_buffer)
-{
- ui_file_write ((struct ui_file *) data, buffer, length_buffer);
+ file->write (buf, length_buf);
}
void
@@ -233,622 +122,229 @@ ui_file_write_async_safe (struct ui_file *file,
const char *buf,
long length_buf)
{
- file->to_write_async_safe (file, buf, length_buf);
+ file->write_async_safe (buf, length_buf);
}
long
ui_file_read (struct ui_file *file, char *buf, long length_buf)
{
- return file->to_read (file, buf, length_buf);
-}
-
-int
-ui_file_fseek (struct ui_file *file, long offset, int whence)
-{
- return file->to_fseek (file, offset, whence);
+ return file->read (buf, length_buf);
}
void
fputs_unfiltered (const char *buf, struct ui_file *file)
{
- file->to_fputs (buf, file);
-}
-
-void
-set_ui_file_flush (struct ui_file *file, ui_file_flush_ftype *flush_ptr)
-{
- file->to_flush = flush_ptr;
-}
-
-void
-set_ui_file_isatty (struct ui_file *file, ui_file_isatty_ftype *isatty_ptr)
-{
- file->to_isatty = isatty_ptr;
-}
-
-void
-set_ui_file_rewind (struct ui_file *file, ui_file_rewind_ftype *rewind_ptr)
-{
- file->to_rewind = rewind_ptr;
+ file->puts (buf);
}
-void
-set_ui_file_put (struct ui_file *file, ui_file_put_ftype *put_ptr)
-{
- file->to_put = put_ptr;
-}
+
-void
-set_ui_file_write (struct ui_file *file,
- ui_file_write_ftype *write_ptr)
-{
- file->to_write = write_ptr;
-}
+string_file::string_file ()
+{}
-void
-set_ui_file_write_async_safe (struct ui_file *file,
- ui_file_write_async_safe_ftype *write_async_safe_ptr)
-{
- file->to_write_async_safe = write_async_safe_ptr;
-}
+string_file::~string_file ()
+{}
void
-set_ui_file_read (struct ui_file *file, ui_file_read_ftype *read_ptr)
+string_file::write (const char *buf, long length_buf)
{
- file->to_read = read_ptr;
+ m_string.append (buf, length_buf);
}
-void
-set_ui_file_fputs (struct ui_file *file, ui_file_fputs_ftype *fputs_ptr)
+std::string &
+string_file::string ()
{
- file->to_fputs = fputs_ptr;
+ return m_string;
}
-void
-set_ui_file_fseek (struct ui_file *file, ui_file_fseek_ftype *fseek_ptr)
+bool
+string_file::empty () const
{
- file->to_fseek = fseek_ptr;
+ return m_string.empty ();
}
void
-set_ui_file_data (struct ui_file *file, void *data,
- ui_file_delete_ftype *delete_ptr)
-{
- file->to_data = data;
- file->to_delete = delete_ptr;
-}
-
-/* ui_file utility function for converting a ``struct ui_file'' into
- a memory buffer. */
-
-struct accumulated_ui_file
-{
- char *buffer;
- long length;
-};
-
-static void
-do_ui_file_xstrdup (void *context, const char *buffer, long length)
-{
- struct accumulated_ui_file *acc = (struct accumulated_ui_file *) context;
-
- if (acc->buffer == NULL)
- acc->buffer = (char *) xmalloc (length + 1);
- else
- acc->buffer = (char *) xrealloc (acc->buffer, acc->length + length + 1);
- memcpy (acc->buffer + acc->length, buffer, length);
- acc->length += length;
- acc->buffer[acc->length] = '\0';
-}
-
-char *
-ui_file_xstrdup (struct ui_file *file, long *length)
-{
- struct accumulated_ui_file acc;
-
- acc.buffer = NULL;
- acc.length = 0;
- ui_file_put (file, do_ui_file_xstrdup, &acc);
- if (acc.buffer == NULL)
- acc.buffer = xstrdup ("");
- if (length != NULL)
- *length = acc.length;
- return acc.buffer;
-}
-
-/* ui_file utility function for converting a ``struct ui_file'' into a
- std:string. */
-
-static void
-do_ui_file_as_string (void *context, const char *buffer, long length)
-{
- std::string *str = (std::string *) context;
-
- *str = std::string (buffer, length);
-}
-
-/* See ui-file.h. */
-
-std::string
-ui_file_as_string (struct ui_file *file)
+string_file::rewind ()
{
- std::string str;
-
- ui_file_put (file, do_ui_file_as_string, &str);
- return str;
+ m_string.clear ();
}
-static void
-do_ui_file_obsavestring (void *context, const char *buffer, long length)
-{
- struct obstack *obstack = (struct obstack *) context;
-
- obstack_grow (obstack, buffer, length);
-}
-
-char *
-ui_file_obsavestring (struct ui_file *file, struct obstack *obstack,
- long *length)
-{
- ui_file_put (file, do_ui_file_obsavestring, obstack);
- *length = obstack_object_size (obstack);
- obstack_1grow (obstack, '\0');
- return (char *) obstack_finish (obstack);
-}
-/* A pure memory based ``struct ui_file'' that can be used an output
- buffer. The buffers accumulated contents are available via
- ui_file_put(). */
-
-struct mem_file
- {
- int *magic;
- char *buffer;
- int sizeof_buffer;
- int length_buffer;
- };
-static ui_file_rewind_ftype mem_file_rewind;
-static ui_file_put_ftype mem_file_put;
-static ui_file_write_ftype mem_file_write;
-static ui_file_delete_ftype mem_file_delete;
-static struct ui_file *mem_file_new (void);
-static int mem_file_magic;
-
-static struct ui_file *
-mem_file_new (void)
+stdio_file::stdio_file (FILE *file, bool close_p)
{
- struct mem_file *stream = XNEW (struct mem_file);
- struct ui_file *file = ui_file_new ();
-
- set_ui_file_data (file, stream, mem_file_delete);
- set_ui_file_rewind (file, mem_file_rewind);
- set_ui_file_put (file, mem_file_put);
- set_ui_file_write (file, mem_file_write);
- stream->magic = &mem_file_magic;
- stream->buffer = NULL;
- stream->sizeof_buffer = 0;
- stream->length_buffer = 0;
- return file;
+ set_stream (file);
+ m_close_p = close_p;
}
-static void
-mem_file_delete (struct ui_file *file)
-{
- struct mem_file *stream = (struct mem_file *) ui_file_data (file);
-
- if (stream->magic != &mem_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mem_file_delete: bad magic number"));
- if (stream->buffer != NULL)
- xfree (stream->buffer);
- xfree (stream);
-}
+stdio_file::stdio_file ()
+ : m_file (NULL),
+ m_fd (-1),
+ m_close_p (false)
+{}
-struct ui_file *
-mem_fileopen (void)
+stdio_file::~stdio_file ()
{
- return mem_file_new ();
+ if (m_close_p)
+ fclose (m_file);
}
-static void
-mem_file_rewind (struct ui_file *file)
+void
+stdio_file::set_stream (FILE *file)
{
- struct mem_file *stream = (struct mem_file *) ui_file_data (file);
-
- if (stream->magic != &mem_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mem_file_rewind: bad magic number"));
- stream->length_buffer = 0;
+ m_file = file;
+ m_fd = fileno (file);
}
-static void
-mem_file_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
+bool
+stdio_file::open (const char *name, const char *mode)
{
- struct mem_file *stream = (struct mem_file *) ui_file_data (file);
+ FILE *f = gdb_fopen_cloexec (name, mode);
- if (stream->magic != &mem_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mem_file_put: bad magic number"));
- if (stream->length_buffer > 0)
- write (dest, stream->buffer, stream->length_buffer);
-}
+ if (f == NULL)
+ return false;
-void
-mem_file_write (struct ui_file *file,
- const char *buffer,
- long length_buffer)
-{
- struct mem_file *stream = (struct mem_file *) ui_file_data (file);
+ set_stream (f);
+ m_close_p = true;
- if (stream->magic != &mem_file_magic)
- internal_error (__FILE__, __LINE__,
- _("mem_file_write: bad magic number"));
- if (stream->buffer == NULL)
- {
- stream->length_buffer = length_buffer;
- stream->sizeof_buffer = length_buffer;
- stream->buffer = (char *) xmalloc (stream->sizeof_buffer);
- memcpy (stream->buffer, buffer, length_buffer);
- }
- else
- {
- int new_length = stream->length_buffer + length_buffer;
-
- if (new_length >= stream->sizeof_buffer)
- {
- stream->sizeof_buffer = new_length;
- stream->buffer
- = (char *) xrealloc (stream->buffer, stream->sizeof_buffer);
- }
- memcpy (stream->buffer + stream->length_buffer, buffer, length_buffer);
- stream->length_buffer = new_length;
- }
-}
-
-/* ``struct ui_file'' implementation that maps directly onto
- <stdio.h>'s FILE. */
-
-static ui_file_write_ftype stdio_file_write;
-static ui_file_write_async_safe_ftype stdio_file_write_async_safe;
-static ui_file_fputs_ftype stdio_file_fputs;
-static ui_file_read_ftype stdio_file_read;
-static ui_file_isatty_ftype stdio_file_isatty;
-static ui_file_delete_ftype stdio_file_delete;
-static struct ui_file *stdio_file_new (FILE *file, int close_p);
-static ui_file_flush_ftype stdio_file_flush;
-static ui_file_fseek_ftype stdio_file_fseek;
-
-static int stdio_file_magic;
-
-struct stdio_file
- {
- int *magic;
- FILE *file;
- /* The associated file descriptor is extracted ahead of time for
- stdio_file_write_async_safe's benefit, in case fileno isn't async-safe. */
- int fd;
- int close_p;
- };
-
-static struct ui_file *
-stdio_file_new (FILE *file, int close_p)
-{
- struct ui_file *ui_file = ui_file_new ();
- struct stdio_file *stdio = XNEW (struct stdio_file);
-
- stdio->magic = &stdio_file_magic;
- stdio->file = file;
- stdio->fd = fileno (file);
- stdio->close_p = close_p;
- set_ui_file_data (ui_file, stdio, stdio_file_delete);
- set_ui_file_flush (ui_file, stdio_file_flush);
- set_ui_file_write (ui_file, stdio_file_write);
- set_ui_file_write_async_safe (ui_file, stdio_file_write_async_safe);
- set_ui_file_fputs (ui_file, stdio_file_fputs);
- set_ui_file_read (ui_file, stdio_file_read);
- set_ui_file_isatty (ui_file, stdio_file_isatty);
- set_ui_file_fseek (ui_file, stdio_file_fseek);
- return ui_file;
-}
-
-static void
-stdio_file_delete (struct ui_file *file)
-{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_delete: bad magic number"));
- if (stdio->close_p)
- {
- fclose (stdio->file);
- }
- xfree (stdio);
+ return true;
}
-static void
-stdio_file_flush (struct ui_file *file)
+void
+stdio_file::flush ()
{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_flush: bad magic number"));
- fflush (stdio->file);
+ fflush (m_file);
}
-static long
-stdio_file_read (struct ui_file *file, char *buf, long length_buf)
+long
+stdio_file::read (char *buf, long length_buf)
{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_read: bad magic number"));
-
/* Wait until at least one byte of data is available, or we get
interrupted with Control-C. */
{
fd_set readfds;
FD_ZERO (&readfds);
- FD_SET (stdio->fd, &readfds);
- if (interruptible_select (stdio->fd + 1, &readfds, NULL, NULL, NULL) == -1)
+ FD_SET (m_fd, &readfds);
+ if (interruptible_select (m_fd + 1, &readfds, NULL, NULL, NULL) == -1)
return -1;
}
- return read (stdio->fd, buf, length_buf);
+ return ::read (m_fd, buf, length_buf);
}
-static void
-stdio_file_write (struct ui_file *file, const char *buf, long length_buf)
+void
+stdio_file::write (const char *buf, long length_buf)
{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_write: bad magic number"));
/* Calling error crashes when we are called from the exception framework. */
- if (gnulib::fwrite (buf, length_buf, 1, stdio->file))
+ if (gnulib::fwrite (buf, length_buf, 1, m_file))
{
/* Nothing. */
}
}
-static void
-stdio_file_write_async_safe (struct ui_file *file,
- const char *buf, long length_buf)
+void
+stdio_file::write_async_safe (const char *buf, long length_buf)
{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- {
- /* gettext isn't necessarily async safe, so we can't use _("error message") here.
- We could extract the correct translation ahead of time, but this is an extremely
- rare event, and one of the other stdio_file_* routines will presumably catch
- the problem anyway. For now keep it simple and ignore the error here. */
- return;
- }
-
/* This is written the way it is to avoid a warning from gcc about not using the
result of write (since it can be declared with attribute warn_unused_result).
Alas casting to void doesn't work for this. */
- if (write (stdio->fd, buf, length_buf))
+ if (::write (m_fd, buf, length_buf))
{
/* Nothing. */
}
}
-static void
-stdio_file_fputs (const char *linebuffer, struct ui_file *file)
+void
+stdio_file::puts (const char *linebuffer)
{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_fputs: bad magic number"));
/* Calling error crashes when we are called from the exception framework. */
- if (gnulib::fputs (linebuffer, stdio->file))
+ if (gnulib::fputs (linebuffer, m_file))
{
/* Nothing. */
}
}
-static int
-stdio_file_isatty (struct ui_file *file)
-{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_isatty: bad magic number"));
- return (isatty (stdio->fd));
-}
-
-static int
-stdio_file_fseek (struct ui_file *file, long offset, int whence)
+bool
+stdio_file::isatty ()
{
- struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
-
- if (stdio->magic != &stdio_file_magic)
- internal_error (__FILE__, __LINE__,
- _("stdio_file_fseek: bad magic number"));
-
- return fseek (stdio->file, offset, whence);
+ return (::isatty (m_fd));
}
-#ifdef __MINGW32__
-/* This is the implementation of ui_file method to_write for stderr.
+/* This is the implementation of ui_file method 'write' for stderr.
gdb_stdout is flushed before writing to gdb_stderr. */
-static void
-stderr_file_write (struct ui_file *file, const char *buf, long length_buf)
+void
+stderr_file::write (const char *buf, long length_buf)
{
gdb_flush (gdb_stdout);
- stdio_file_write (file, buf, length_buf);
+ stdio_file::write (buf, length_buf);
}
-/* This is the implementation of ui_file method to_fputs for stderr.
+/* This is the implementation of ui_file method 'puts' for stderr.
gdb_stdout is flushed before writing to gdb_stderr. */
-static void
-stderr_file_fputs (const char *linebuffer, struct ui_file *file)
+void
+stderr_file::puts (const char *linebuffer)
{
gdb_flush (gdb_stdout);
- stdio_file_fputs (linebuffer, file);
+ stdio_file::puts (linebuffer);
}
-#endif
-struct ui_file *
-stderr_fileopen (FILE *stream)
+stderr_file::stderr_file (FILE *stream)
+ : stdio_file (stream)
{
- struct ui_file *ui_file = stdio_fileopen (stream);
-
-#ifdef __MINGW32__
- /* There is no real line-buffering on Windows, see
- http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx
- so the stdout is either fully-buffered or non-buffered. We can't
- make stdout non-buffered, because of two concerns,
- 1. non-buffering hurts performance,
- 2. non-buffering may change GDB's behavior when it is interacting
- with front-end, such as Emacs.
-
- We decided to leave stdout as fully buffered, but flush it first
- when something is written to stderr. */
-
- /* Method 'to_write_async_safe' is not overwritten, because there's
- no way to flush a stream in an async-safe manner. Fortunately,
- it doesn't really matter, because:
- - that method is only used for printing internal debug output
- from signal handlers.
- - Windows hosts don't have a concept of async-safeness. Signal
- handlers run in a separate thread, so they can call
- the regular non-async-safe output routines freely. */
- set_ui_file_write (ui_file, stderr_file_write);
- set_ui_file_fputs (ui_file, stderr_file_fputs);
-#endif
-
- return ui_file;
}
-/* Like fdopen(). Create a ui_file from a previously opened FILE. */
+
-struct ui_file *
-stdio_fileopen (FILE *file)
+tee_file::tee_file (struct ui_file *one, int close_one,
+ struct ui_file *two, int close_two)
{
- return stdio_file_new (file, 0);
+ m_one = one;
+ m_two = two;
+ m_close_one = close_one;
+ m_close_two = close_two;
}
-struct ui_file *
-gdb_fopen (const char *name, const char *mode)
+tee_file::~tee_file ()
{
- FILE *f = gdb_fopen_cloexec (name, mode);
-
- if (f == NULL)
- return NULL;
- return stdio_file_new (f, 1);
+ if (m_close_one)
+ delete m_one;
+ if (m_close_two)
+ delete m_two;
}
-/* ``struct ui_file'' implementation that maps onto two ui-file objects. */
-
-static ui_file_write_ftype tee_file_write;
-static ui_file_fputs_ftype tee_file_fputs;
-static ui_file_isatty_ftype tee_file_isatty;
-static ui_file_delete_ftype tee_file_delete;
-static ui_file_flush_ftype tee_file_flush;
-
-static int tee_file_magic;
-
-struct tee_file
- {
- int *magic;
- struct ui_file *one, *two;
- int close_one, close_two;
- };
-
-struct ui_file *
-tee_file_new (struct ui_file *one, int close_one,
- struct ui_file *two, int close_two)
+void
+tee_file::flush ()
{
- struct ui_file *ui_file = ui_file_new ();
- struct tee_file *tee = XNEW (struct tee_file);
-
- tee->magic = &tee_file_magic;
- tee->one = one;
- tee->two = two;
- tee->close_one = close_one;
- tee->close_two = close_two;
- set_ui_file_data (ui_file, tee, tee_file_delete);
- set_ui_file_flush (ui_file, tee_file_flush);
- set_ui_file_write (ui_file, tee_file_write);
- set_ui_file_fputs (ui_file, tee_file_fputs);
- set_ui_file_isatty (ui_file, tee_file_isatty);
- return ui_file;
+ m_one->flush ();
+ m_two->flush ();
}
-static void
-tee_file_delete (struct ui_file *file)
-{
- struct tee_file *tee = (struct tee_file *) ui_file_data (file);
-
- if (tee->magic != &tee_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tee_file_delete: bad magic number"));
- if (tee->close_one)
- ui_file_delete (tee->one);
- if (tee->close_two)
- ui_file_delete (tee->two);
-
- xfree (tee);
-}
-
-static void
-tee_file_flush (struct ui_file *file)
+void
+tee_file::write (const char *buf, long length_buf)
{
- struct tee_file *tee = (struct tee_file *) ui_file_data (file);
-
- if (tee->magic != &tee_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tee_file_flush: bad magic number"));
- tee->one->to_flush (tee->one);
- tee->two->to_flush (tee->two);
+ m_one->write (buf, length_buf);
+ m_two->write (buf, length_buf);
}
-static void
-tee_file_write (struct ui_file *file, const char *buf, long length_buf)
+void
+tee_file::write_async_safe (const char *buf, long length_buf)
{
- struct tee_file *tee = (struct tee_file *) ui_file_data (file);
-
- if (tee->magic != &tee_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tee_file_write: bad magic number"));
- ui_file_write (tee->one, buf, length_buf);
- ui_file_write (tee->two, buf, length_buf);
+ m_one->write_async_safe (buf, length_buf);
+ m_two->write_async_safe (buf, length_buf);
}
-static void
-tee_file_fputs (const char *linebuffer, struct ui_file *file)
+void
+tee_file::puts (const char *linebuffer)
{
- struct tee_file *tee = (struct tee_file *) ui_file_data (file);
-
- if (tee->magic != &tee_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tee_file_fputs: bad magic number"));
- tee->one->to_fputs (linebuffer, tee->one);
- tee->two->to_fputs (linebuffer, tee->two);
+ m_one->puts (linebuffer);
+ m_two->puts (linebuffer);
}
-static int
-tee_file_isatty (struct ui_file *file)
+bool
+tee_file::isatty ()
{
- struct tee_file *tee = (struct tee_file *) ui_file_data (file);
-
- if (tee->magic != &tee_file_magic)
- internal_error (__FILE__, __LINE__,
- _("tee_file_isatty: bad magic number"));
-
- return ui_file_isatty (tee->one);
+ return m_one->isatty ();
}
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 2ed11ded82c..136397bdf40 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -24,74 +24,79 @@ struct ui_file;
#include <string>
-/* Create a generic ui_file object with null methods. */
-
-extern struct ui_file *ui_file_new (void);
-
-/* Override methods used by specific implementations of a UI_FILE
- object. */
-
-typedef void (ui_file_flush_ftype) (struct ui_file *stream);
-extern void set_ui_file_flush (struct ui_file *stream,
- ui_file_flush_ftype *flush);
-
-/* NOTE: Both fputs and write methods are available. Default
- implementations that mapping one onto the other are included. */
-typedef void (ui_file_write_ftype) (struct ui_file *stream,
- const char *buf, long length_buf);
-extern void set_ui_file_write (struct ui_file *stream,
- ui_file_write_ftype *fputs);
-
-typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream);
-extern void set_ui_file_fputs (struct ui_file *stream,
- ui_file_fputs_ftype *fputs);
-
-/* This version of "write" is safe for use in signal handlers.
- It's not guaranteed that all existing output will have been
- flushed first.
- Implementations are also free to ignore some or all of the request.
- fputs_async is not provided as the async versions are rarely used,
- no point in having both for a rarely used interface. */
-typedef void (ui_file_write_async_safe_ftype)
- (struct ui_file *stream, const char *buf, long length_buf);
-extern void set_ui_file_write_async_safe
- (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe);
-
-typedef long (ui_file_read_ftype) (struct ui_file *stream,
- char *buf, long length_buf);
-extern void set_ui_file_read (struct ui_file *stream,
- ui_file_read_ftype *fread);
-
-typedef int (ui_file_isatty_ftype) (struct ui_file *stream);
-extern void set_ui_file_isatty (struct ui_file *stream,
- ui_file_isatty_ftype *isatty);
-
-typedef void (ui_file_rewind_ftype) (struct ui_file *stream);
-extern void set_ui_file_rewind (struct ui_file *stream,
- ui_file_rewind_ftype *rewind);
-
typedef void (ui_file_put_method_ftype) (void *object, const char *buffer,
long length_buffer);
-typedef void (ui_file_put_ftype) (struct ui_file *stream,
- ui_file_put_method_ftype *method,
- void *context);
-extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put);
-typedef void (ui_file_delete_ftype) (struct ui_file * stream);
-extern void set_ui_file_data (struct ui_file *stream, void *data,
- ui_file_delete_ftype *to_delete);
+struct ui_file
+{
+ ui_file ();
+ virtual ~ui_file ();
-typedef int (ui_file_fseek_ftype) (struct ui_file *stream, long offset,
- int whence);
-extern void set_ui_file_fseek (struct ui_file *stream,
- ui_file_fseek_ftype *fseek_ptr);
+ /* Public non-virtual API. */
-extern void *ui_file_data (struct ui_file *file);
+ void printf (const char *, ...) ATTRIBUTE_PRINTF (2, 3);
+ /* Print a string whose delimiter is QUOTER. Note that these
+ routines should only be call for printing things which are
+ independent of the language of the program being debugged. */
+ void putstr (const char *str, int quoter);
-extern void gdb_flush (struct ui_file *);
+ void putstrn (const char *str, int n, int quoter);
+
+ int putc (int c);
+
+ void vprintf (const char *, va_list) ATTRIBUTE_PRINTF (2, 0);
+
+ /* Methods below are both public, and overridable by ui_file
+ subclasses. */
+
+ virtual void write (const char *buf, long length_buf) = 0;
+
+ /* This version of "write" is safe for use in signal handlers. It's
+ not guaranteed that all existing output will have been flushed
+ first. Implementations are also free to ignore some or all of
+ the request. puts_async is not provided as the async versions
+ are rarely used, no point in having both for a rarely used
+ interface. */
+ virtual void write_async_safe (const char *buf, long length_buf)
+ { gdb_assert_not_reached ("write_async_safe"); }
+
+ virtual void puts (const char *str)
+ { this->write (str, strlen (str)); }
+
+ virtual long read (char *buf, long length_buf)
+ { gdb_assert_not_reached ("can't read from this file type"); }
+
+ virtual bool isatty ()
+ { return false; }
+
+ virtual void flush ()
+ {}
+
+ /* The following two methods are meant to be overridden by
+ locally-buffered files. */
-extern void ui_file_delete (struct ui_file *stream);
+ virtual void rewind ()
+ {}
+
+ virtual void write_buffer_on (ui_file &where)
+ {}
+};
+
+typedef std::unique_ptr<ui_file> ui_file_up;
+
+class null_file : public ui_file
+{
+public:
+ void write (const char *buf, long length_buf) override;
+ void write_async_safe (const char *buf, long sizeof_buf) override;
+ void puts (const char *str) override;
+};
+
+/* A preallocated null_file stream. */
+extern null_file null_stream;
+
+extern void gdb_flush (struct ui_file *);
extern void ui_file_rewind (struct ui_file *stream);
@@ -100,59 +105,152 @@ extern int ui_file_isatty (struct ui_file *);
extern void ui_file_write (struct ui_file *file, const char *buf,
long length_buf);
-/* A wrapper for ui_file_write that is suitable for use by
- ui_file_put. */
-
-extern void ui_file_write_for_put (void *data, const char *buffer,
- long length_buffer);
-
extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
long length_buf);
-/* NOTE: copies left to right. */
-extern void ui_file_put (struct ui_file *src,
- ui_file_put_method_ftype *write, void *dest);
+extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
+
+/* A std::string based file. Can be used as a scratch buffer for
+ collecting output. */
+struct string_file : public ui_file
+{
+ string_file ();
+ ~string_file () override;
-/* Returns a freshly allocated buffer containing the entire contents
- of FILE (as determined by ui_file_put()) with a NUL character
- appended. LENGTH, if not NULL, is set to the size of the buffer
- minus that appended NUL. */
-extern char *ui_file_xstrdup (struct ui_file *file, long *length);
+ /* Override ui_file methods. */
-/* Returns a std::string containing the entire contents of FILE (as
- determined by ui_file_put()). */
-extern std::string ui_file_as_string (struct ui_file *file);
+ void rewind () override;
-/* Similar to ui_file_xstrdup, but return a new string allocated on
- OBSTACK. */
-extern char *ui_file_obsavestring (struct ui_file *file,
- struct obstack *obstack, long *length);
+ void write (const char *buf, long length_buf) override;
-extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
+ void write_buffer_on (ui_file &where) override
+ { where.write (m_string.data (), m_string.size ()); }
+
+ long read (char *buf, long length_buf) override
+ { gdb_assert_not_reached ("a string_file is not readable"); }
+
+ /* string_file-specific public API. */
+
+ /* Accesses the std::string containing the entire output collected
+ so far. Returns a non-const reference so that it's easy to move
+ the string contents out of the string_file. */
+ std::string &string ();
+
+ /* Provide a few convenience methods with the same API as the
+ underlying std::string. */
+ const char *data () const { return m_string.data (); }
+ const char *c_str () const { return m_string.c_str (); }
+ size_t size () const { return m_string.size (); }
+ bool empty () const;
+
+private:
+ std::string m_string;
+};
+
+/* ``struct ui_file'' implementation that maps directly onto
+ <stdio.h>'s FILE. */
+
+struct stdio_file : public ui_file
+{
+ /* Create a ui_file from a previously opened FILE. If not CLOSE_P,
+ then behave like like fdopen(). */
+ explicit stdio_file (FILE *file, bool close_p = false);
+
+ /* Create an stdio_file that is not managing any file yet. Call
+ open to actually open something. */
+ stdio_file ();
+
+ ~stdio_file () override;
+
+ /* Open NAME in mode MODE. Returns true on success, false
+ otherwise. Destroying the stdio_file closes the underlying FILE
+ handle. */
+ bool open (const char *name, const char *mode);
+
+ void flush () override;
+
+ void write (const char *buf, long length_buf) override;
+
+ void write_async_safe (const char *buf, long length_buf) override;
+
+ void puts (const char *) override;
+
+ long read (char *buf, long length_buf) override;
+
+ bool isatty () override;
+
+ void rewind () override
+ { gdb_assert_not_reached ("can't rewind a stdio file"); }
+
+private:
+ void set_stream (FILE *file);
+
+ FILE *m_file;
+ /* The associated file descriptor is extracted ahead of time for
+ stdio_file::write_async_safe's benefit, in case fileno isn't
+ async-safe. */
+ int m_fd;
+ bool m_close_p;
+};
+
+
+/* There is no real line-buffering on Windows, see
+ http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx
+ so the stdout is either fully-buffered or non-buffered. We can't
+ make stdout non-buffered, because of two concerns,
+ 1. non-buffering hurts performance,
+ 2. non-buffering may change GDB's behavior when it is interacting
+ with front-end, such as Emacs.
+
+ We decided to leave stdout as fully buffered, but flush it first
+ when something is written to stderr. */
+
+/* The 'write_async_safe' method is not overwritten, because there's
+ no way to flush a stream in an async-safe manner. Fortunately, it
+ doesn't really matter, because:
+ - that method is only used for printing internal debug output
+ from signal handlers.
+ - Windows hosts don't have a concept of async-safeness. Signal
+ handlers run in a separate thread, so they can call
+ the regular non-async-safe output routines freely. */
+
+struct stderr_file : public stdio_file
+{
+ explicit stderr_file (FILE *stream);
-extern int ui_file_fseek (struct ui_file *file, long offset, int whence);
+ /* gdb_stdout is flushed before writing to gdb_stderr. */
+ void write (const char *buf, long length_buf) override;
-/* Create/open a memory based file. Can be used as a scratch buffer
- for collecting output. */
-extern struct ui_file *mem_fileopen (void);
+ /* gdb_stdout is flushed before writing to gdb_stderr. */
+ void puts (const char *linebuffer) override;
+};
+/* ``struct ui_file'' implementation that maps onto two ui-file
+ objects. */
+class tee_file : public ui_file
+{
+public:
+ /* Create a file which writes to both ONE and TWO. CLOSE_ONE and
+ CLOSE_TWO indicate whether the original files should be closed
+ when the new file is closed. */
+ tee_file (ui_file *one, int close_one,
+ ui_file *two, int close_two);
+ ~tee_file () override;
-/* Open/create a STDIO based UI_FILE using the already open FILE. */
-extern struct ui_file *stdio_fileopen (FILE *file);
+ void write (const char *buf, long length_buf) override;
+ void write_async_safe (const char *buf, long length_buf) override;
+ void puts (const char *) override;
-/* Likewise, for stderr-like streams. */
-extern struct ui_file *stderr_fileopen (FILE *file);
+ bool isatty () override;
+ void flush () override;
+ void rewind () override
+ { gdb_assert_not_reached ("tee_file::rewind called\n"); }
-/* Open NAME returning an STDIO based UI_FILE. */
-extern struct ui_file *gdb_fopen (const char *name, const char *mode);
+private:
+ struct ui_file *m_one, *m_two;
+ bool m_close_one, m_close_two;
+};
-/* Create a file which writes to both ONE and TWO. CLOSE_ONE
- and CLOSE_TWO indicate whether the original files should be
- closed when the new file is closed. */
-extern struct ui_file *tee_file_new (struct ui_file *one,
- int close_one,
- struct ui_file *two,
- int close_two);
#endif
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 60d18eee2bb..ebefd5abcdb 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -423,15 +423,13 @@ ui_out_field_core_addr (struct ui_out *uiout,
void
ui_out_field_stream (struct ui_out *uiout,
const char *fldname,
- struct ui_file *stream)
+ string_file &stream)
{
- std::string buffer = ui_file_as_string (stream);
-
- if (!buffer.empty ())
- ui_out_field_string (uiout, fldname, buffer.c_str ());
+ if (!stream.empty ())
+ ui_out_field_string (uiout, fldname, stream.c_str ());
else
ui_out_field_skip (uiout, fldname);
- ui_file_rewind (stream);
+ stream.rewind ();
}
/* Used to omit a field. */
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 9e1e74dabc6..833428e45ac 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -111,7 +111,7 @@ extern void ui_out_field_string (struct ui_out * uiout, const char *fldname,
const char *string);
extern void ui_out_field_stream (struct ui_out *uiout, const char *fldname,
- struct ui_file *stream);
+ string_file &stream);
extern void ui_out_field_fmt (struct ui_out *uiout, const char *fldname,
const char *format, ...)
diff --git a/gdb/utils.c b/gdb/utils.c
index e2fab873ee7..9e743132a1f 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -199,18 +199,6 @@ make_cleanup_obstack_free (struct obstack *obstack)
return make_cleanup (do_obstack_free, obstack);
}
-static void
-do_ui_file_delete (void *arg)
-{
- ui_file_delete ((struct ui_file *) arg);
-}
-
-struct cleanup *
-make_cleanup_ui_file_delete (struct ui_file *arg)
-{
- return make_cleanup (do_ui_file_delete, arg);
-}
-
/* Helper function for make_cleanup_ui_out_redirect_pop. */
static void
@@ -476,11 +464,9 @@ verror (const char *string, va_list args)
}
void
-error_stream (struct ui_file *stream)
+error_stream (const string_file &stream)
{
- std::string message = ui_file_as_string (stream);
-
- error (("%s"), message.c_str ());
+ error (("%s"), stream.c_str ());
}
/* Emit a message and abort. */
diff --git a/gdb/utils.h b/gdb/utils.h
index 62091f07894..71b9c3caf42 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -295,7 +295,7 @@ extern void (*deprecated_error_begin_hook) (void);
extern char *warning_pre_print;
-extern void error_stream (struct ui_file *) ATTRIBUTE_NORETURN;
+extern void error_stream (const string_file &) ATTRIBUTE_NORETURN;
extern void demangler_vwarning (const char *file, int line,
const char *, va_list ap)
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 03edf0eb969..63ae7f974db 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2417,8 +2417,6 @@ varobj_value_get_print_value (struct value *value,
enum varobj_display_formats format,
const struct varobj *var)
{
- struct ui_file *stb;
- struct cleanup *old_chain;
struct value_print_options opts;
struct type *type = NULL;
long len = 0;
@@ -2430,9 +2428,7 @@ varobj_value_get_print_value (struct value *value,
if (value == NULL)
return std::string ();
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
+ string_file stb;
std::string thevalue;
#if HAVE_PYTHON
@@ -2440,7 +2436,7 @@ varobj_value_get_print_value (struct value *value,
{
PyObject *value_formatter = var->dynamic->pretty_printer;
- varobj_ensure_python_env (var);
+ struct cleanup *old_chain = varobj_ensure_python_env (var);
if (value_formatter)
{
@@ -2459,7 +2455,7 @@ varobj_value_get_print_value (struct value *value,
output = apply_varobj_pretty_printer (value_formatter,
&replacement,
- stb);
+ &stb);
/* If we have string like output ... */
if (output)
@@ -2521,6 +2517,8 @@ varobj_value_get_print_value (struct value *value,
value = replacement;
}
}
+
+ do_cleanups (old_chain);
}
#endif
@@ -2528,20 +2526,17 @@ varobj_value_get_print_value (struct value *value,
/* If the THEVALUE has contents, it is a regular string. */
if (!thevalue.empty ())
- LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue.c_str (),
+ LA_PRINT_STRING (&stb, type, (gdb_byte *) thevalue.c_str (),
len, encoding, 0, &opts);
else if (string_print)
/* Otherwise, if string_print is set, and it is not a regular
string, it is a lazy string. */
- val_print_string (type, encoding, str_addr, len, stb, &opts);
+ val_print_string (type, encoding, str_addr, len, &stb, &opts);
else
/* All other cases. */
- common_val_print (value, stb, 0, &opts, current_language);
-
- thevalue = ui_file_as_string (stb);
+ common_val_print (value, &stb, 0, &opts, current_language);
- do_cleanups (old_chain);
- return thevalue;
+ return std::move (stb.string ());
}
int
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index e47c90a969e..adb9c62ebb0 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -3063,45 +3063,38 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
static void
xtensa_verify_config (struct gdbarch *gdbarch)
{
- struct ui_file *log;
- struct cleanup *cleanups;
- struct gdbarch_tdep *tdep;
-
- tdep = gdbarch_tdep (gdbarch);
- log = mem_fileopen ();
- cleanups = make_cleanup_ui_file_delete (log);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ string_file log;
/* Verify that we got a reasonable number of AREGS. */
if ((tdep->num_aregs & -tdep->num_aregs) != tdep->num_aregs)
- fprintf_unfiltered (log, _("\
+ log.printf (_("\
\n\tnum_aregs: Number of AR registers (%d) is not a power of two!"),
- tdep->num_aregs);
+ tdep->num_aregs);
/* Verify that certain registers exist. */
if (tdep->pc_regnum == -1)
- fprintf_unfiltered (log, _("\n\tpc_regnum: No PC register"));
+ log.printf (_("\n\tpc_regnum: No PC register"));
if (tdep->isa_use_exceptions && tdep->ps_regnum == -1)
- fprintf_unfiltered (log, _("\n\tps_regnum: No PS register"));
+ log.printf (_("\n\tps_regnum: No PS register"));
if (tdep->isa_use_windowed_registers)
{
if (tdep->wb_regnum == -1)
- fprintf_unfiltered (log, _("\n\twb_regnum: No WB register"));
+ log.printf (_("\n\twb_regnum: No WB register"));
if (tdep->ws_regnum == -1)
- fprintf_unfiltered (log, _("\n\tws_regnum: No WS register"));
+ log.printf (_("\n\tws_regnum: No WS register"));
if (tdep->ar_base == -1)
- fprintf_unfiltered (log, _("\n\tar_base: No AR registers"));
+ log.printf (_("\n\tar_base: No AR registers"));
}
if (tdep->a0_base == -1)
- fprintf_unfiltered (log, _("\n\ta0_base: No Ax registers"));
+ log.printf (_("\n\ta0_base: No Ax registers"));
- std::string buf = ui_file_as_string (log);
- if (!buf.empty ())
+ if (!log.empty ())
internal_error (__FILE__, __LINE__,
- _("the following are invalid: %s"), buf.c_str ());
- do_cleanups (cleanups);
+ _("the following are invalid: %s"), log.c_str ());
}