aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/guile')
-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.c95
-rw-r--r--gdb/guile/scm-type.c14
-rw-r--r--gdb/guile/scm-value.c29
6 files changed, 46 insertions, 129 deletions
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index b2e7c96..71cffbb 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;
- current_uiout->redirect (string_file);
+ current_uiout->redirect (&buf);
TRY
{
print_command_lines (current_uiout, breakpoint_commands (bp), 0);
@@ -998,15 +995,12 @@ gdbscm_breakpoint_commands (SCM self)
current_uiout->redirect (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 25cae5a..f8cbad6 100644
--- a/gdb/guile/scm-disasm.c
+++ b/gdb/guile/scm-disasm.c
@@ -146,7 +146,7 @@ gdbscm_disassembler::gdbscm_disassembler (struct gdbarch *gdbarch,
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)
{
gdbscm_disassembler di (gdbarch, stream, port, offset);
@@ -245,33 +245,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 9b5159e..994f92d 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 4a1c864..fb3a47b 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -37,11 +37,18 @@
/* 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 write (const char *buf, long length_buf) override;
+
+private:
+ SCM m_port;
+};
/* Data for a memory port. */
@@ -431,74 +438,21 @@ 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);
-}
-
-static void
-ioscm_file_port_rewind (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_rewind: bad magic number"));
-
- scm_truncate_file (stream->port, 0);
-}
+ioscm_file_port::ioscm_file_port (SCM port)
+ : m_port (port)
+{}
-static void
-ioscm_file_port_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
+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_put: bad magic number"));
-
- /* This function doesn't meld with ports very well. */
}
-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 +460,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,21 +473,19 @@ 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
{
- current_uiout->redirect (port_file);
+ current_uiout->redirect (port_file.get ());
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 f5de011..42a8ad2 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 b4f32b6..ebccfb6 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>