From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 14/31] Use ui_file_as_string in gdb/guile/
Date: Wed, 19 Oct 2016 01:13:00 -0000 [thread overview]
Message-ID: <1476839539-8374-15-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com>
gdb/ChangeLog:
yyyy-mm-yy Pedro Alves <palves@redhat.com>
* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use
ui_file_as_string and adjust to use std::string.
* guile/scm-disasm.c (gdbscm_arch_disassemble): Likewise.
* guile/scm-frame.c (frscm_print_frame_smob): Likewise.
* guile/scm-type.c (tyscm_type_name): Use ui_file_as_string and
adjust to use std::string. Throw exception directly instead of
returning it in EXCP output parameter.
(tyscm_print_type_smob, gdbscm_type_print_name): Adjust to
tyscm_type_name interface change.
* guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print):
Use ui_file_as_string and std::string.
---
gdb/guile/scm-breakpoint.c | 6 ++----
gdb/guile/scm-disasm.c | 6 ++----
gdb/guile/scm-frame.c | 6 ++----
gdb/guile/scm-type.c | 42 ++++++++++++++----------------------------
gdb/guile/scm-value.c | 18 ++++++------------
5 files changed, 26 insertions(+), 52 deletions(-)
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index baecf01..61d16da 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -981,7 +981,6 @@ gdbscm_breakpoint_commands (SCM self)
struct ui_file *string_file;
struct cleanup *chain;
SCM result;
- char *cmdstr;
bp = bp_smob->bp;
@@ -1004,9 +1003,8 @@ gdbscm_breakpoint_commands (SCM self)
}
END_CATCH
- cmdstr = ui_file_xstrdup (string_file, &length);
- make_cleanup (xfree, cmdstr);
- result = gdbscm_scm_from_c_string (cmdstr);
+ std::string cmdstr = ui_file_as_string (string_file);
+ result = gdbscm_scm_from_c_string (cmdstr.c_str ());
do_cleanups (chain);
return result;
diff --git a/gdb/guile/scm-disasm.c b/gdb/guile/scm-disasm.c
index 78a7b83..a7d6b14 100644
--- a/gdb/guile/scm-disasm.c
+++ b/gdb/guile/scm-disasm.c
@@ -282,7 +282,6 @@ gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest)
for (pc = start, i = 0; pc <= end && i < count; )
{
int insn_len = 0;
- char *as = NULL;
struct ui_file *memfile = mem_fileopen ();
struct cleanup *cleanups = make_cleanup_ui_file_delete (memfile);
@@ -302,15 +301,14 @@ gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest)
}
END_CATCH
- as = ui_file_xstrdup (memfile, NULL);
+ std::string as = ui_file_as_string (memfile);
- result = scm_cons (dascm_make_insn (pc, as, insn_len),
+ result = scm_cons (dascm_make_insn (pc, as.c_str (), insn_len),
result);
pc += insn_len;
i++;
do_cleanups (cleanups);
- xfree (as);
}
return scm_reverse_x (result, SCM_EOL);
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 8f920b2..a86ea5f 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -157,16 +157,14 @@ 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;
- char *s;
gdbscm_printf (port, "#<%s ", frame_smob_name);
strfile = mem_fileopen ();
fprint_frame_id (strfile, f_smob->frame_id);
- s = ui_file_xstrdup (strfile, NULL);
- gdbscm_printf (port, "%s", s);
+ std::string s = ui_file_as_string (strfile);
+ gdbscm_printf (port, "%s", s.c_str ());
ui_file_delete (strfile);
- xfree (s);
scm_puts (">", port);
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 2acdfad..383e58a 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -99,16 +99,12 @@ tyscm_type_smob_type (type_smob *t_smob)
return t_smob->type;
}
-/* Return the name of TYPE in expanded form.
- Space for the result is malloc'd, caller must free.
- If there's an error computing the name, the result is NULL and the
- exception is stored in *EXCP. */
+/* Return the name of TYPE in expanded form. If there's an error
+ computing the name, throws the gdb exception with scm_throw. */
-static char *
-tyscm_type_name (struct type *type, SCM *excp)
+static std::string
+tyscm_type_name (struct type *type)
{
- char *name = NULL;
-
TRY
{
struct cleanup *old_chain;
@@ -119,17 +115,19 @@ tyscm_type_name (struct type *type, SCM *excp)
LA_PRINT_TYPE (type, "", stb, -1, 0, &type_print_raw_options);
- name = ui_file_xstrdup (stb, NULL);
+ std::string name = ui_file_as_string (stb);
do_cleanups (old_chain);
+
+ return name;
}
CATCH (except, RETURN_MASK_ALL)
{
- *excp = gdbscm_scm_from_gdb_exception (except);
- return NULL;
+ SCM excp = gdbscm_scm_from_gdb_exception (except);
+ gdbscm_throw (excp);
}
END_CATCH
- return name;
+ gdb_assert_not_reached ("no way to get here");
}
\f
/* Administrivia for type smobs. */
@@ -207,11 +205,7 @@ static int
tyscm_print_type_smob (SCM self, SCM port, scm_print_state *pstate)
{
type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (self);
- SCM exception;
- char *name = tyscm_type_name (t_smob->type, &exception);
-
- if (name == NULL)
- gdbscm_throw (exception);
+ std::string name = tyscm_type_name (t_smob->type);
/* pstate->writingp = zero if invoked by display/~A, and nonzero if
invoked by write/~S. What to do here may need to evolve.
@@ -220,7 +214,7 @@ tyscm_print_type_smob (SCM self, SCM port, scm_print_state *pstate)
if (pstate->writingp)
gdbscm_printf (port, "#<%s ", type_smob_name);
- scm_puts (name, port);
+ scm_puts (name.c_str (), port);
if (pstate->writingp)
scm_puts (">", port);
@@ -608,16 +602,8 @@ gdbscm_type_print_name (SCM self)
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- char *thetype;
- SCM exception, result;
-
- thetype = tyscm_type_name (type, &exception);
-
- if (thetype == NULL)
- gdbscm_throw (exception);
-
- result = gdbscm_scm_from_c_string (thetype);
- xfree (thetype);
+ std::string thetype = tyscm_type_name (type);
+ SCM result = gdbscm_scm_from_c_string (thetype.c_str ());
return result;
}
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 1cdf953..7c1449e 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -141,7 +141,6 @@ static int
vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
{
value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (self);
- char *s = NULL;
struct value_print_options opts;
if (pstate->writingp)
@@ -162,7 +161,9 @@ vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
common_val_print (v_smob->value, stb, 0, &opts, current_language);
- s = ui_file_xstrdup (stb, NULL);
+
+ std::string s = ui_file_as_string (stb);
+ scm_puts (s.c_str (), port);
do_cleanups (old_chain);
}
@@ -172,12 +173,6 @@ vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
}
END_CATCH
- if (s != NULL)
- {
- scm_puts (s, port);
- xfree (s);
- }
-
if (pstate->writingp)
scm_puts (">", port);
@@ -1281,7 +1276,7 @@ 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;
- char *s = NULL;
+ std::string s;
SCM result;
get_user_print_options (&opts);
@@ -1293,7 +1288,7 @@ gdbscm_value_print (SCM self)
struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
common_val_print (value, stb, 0, &opts, current_language);
- s = ui_file_xstrdup (stb, NULL);
+ s = ui_file_as_string (stb);
do_cleanups (old_chain);
}
@@ -1308,9 +1303,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, strlen (s), host_charset (),
+ result = scm_from_stringn (s.c_str (), s.size (), host_charset (),
SCM_FAILED_CONVERSION_QUESTION_MARK);
- xfree (s);
return result;
}
--
2.5.5
next prev parent reply other threads:[~2016-10-19 1:12 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-19 1:13 [PATCH v2 00/31] More cleanup elimination & unlimited args to user-defined funcs Pedro Alves
2016-10-19 1:12 ` [PATCH v2 12/31] Use ui_file_as_string in gdb/utils.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 20/31] Use ui_file_as_string in gdb/cli/cli-setshow.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 01/31] Introduce string_printf Pedro Alves
2016-10-19 13:43 ` Trevor Saunders
2016-10-19 14:41 ` Pedro Alves
2016-10-19 17:18 ` Simon Marchi
2016-10-19 21:02 ` Pedro Alves
2016-11-08 15:35 ` Pedro Alves
2016-10-19 1:12 ` [PATCH v2 06/31] Introduce ui_file_as_string Pedro Alves
2016-10-19 1:12 ` [PATCH v2 24/31] Use ui_file_as_string in gdb/ada-lang.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 07/31] Clean up tracepoint.h/c:collection_list Pedro Alves
2016-10-19 1:12 ` [PATCH v2 19/31] Use ui_file_as_string in gdb/remote.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 21/31] Use ui_file_as_string in gdb/compile/ Pedro Alves
2016-10-19 23:08 ` Simon Marchi
2016-10-19 23:48 ` Pedro Alves
2016-10-20 3:17 ` Simon Marchi
2016-10-20 12:13 ` Pedro Alves
2016-10-19 1:12 ` [PATCH v2 22/31] Use ui_file_as_string in gdb/c-exp.y Pedro Alves
2016-10-19 1:13 ` [PATCH v2 31/31] Support an "unlimited" number of user-defined arguments Pedro Alves
2016-10-19 6:29 ` Eli Zaretskii
2016-10-19 11:33 ` Philipp Rudo
2016-10-19 12:47 ` Pedro Alves
2016-10-19 17:40 ` Philipp Rudo
2016-10-19 17:45 ` Pedro Alves
2016-11-08 15:41 ` Pedro Alves
2016-10-19 1:13 ` [PATCH v2 02/31] cli/cli-script.c: Remove some dead NULL checks Pedro Alves
2016-10-19 17:24 ` Simon Marchi
2016-10-19 21:18 ` Pedro Alves
2016-10-19 1:13 ` [PATCH v2 08/31] Use ui_file_as_string in dwarf2_compute_name Pedro Alves
2016-10-19 1:13 ` [PATCH v2 15/31] Use ui_file_as_string in execute_command_to_string Pedro Alves
2016-10-19 1:13 ` [PATCH v2 27/31] Use ui_file_as_string in gdb/language.c Pedro Alves
2016-10-19 1:13 ` [PATCH v2 29/31] 'struct agent_expr *' -> unique_ptr<agent_expr> Pedro Alves
2016-10-19 23:19 ` Simon Marchi
2016-10-19 23:58 ` Pedro Alves
2016-10-19 1:13 ` Pedro Alves [this message]
2016-10-19 1:13 ` [PATCH v2 03/31] breakpoint.c:commands_command_1 constification and cleanup Pedro Alves
2016-10-19 1:13 ` [PATCH v2 26/31] Use ui_file_as_string in gdb/rust-lang.c Pedro Alves
2016-10-19 1:13 ` [PATCH v2 23/31] Use ui_file_as_string in gdbarch.sh/gdbarch.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 09/31] Use ui_file_as_string in gdb/xtensa-tdep.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 25/31] Use ui_file_as_string in gdb/infrun.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 11/31] Use ui_file_as_string in gdb/ui-out.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 10/31] Use ui_file_as_string in gdb/ada-valprint.c Pedro Alves
2016-10-19 1:18 ` [PATCH v2 30/31] Eliminate agent_expr_p; VEC -> std::vector in struct bp_target_info Pedro Alves
2016-10-19 1:18 ` [PATCH v2 05/31] 'struct expression *' -> gdb::unique_xmalloc_ptr<expression> Pedro Alves
2016-10-19 18:45 ` Simon Marchi
2016-10-19 21:50 ` Pedro Alves
2016-10-19 22:25 ` Simon Marchi
2016-10-19 22:36 ` Pedro Alves
2016-10-19 1:19 ` [PATCH v2 04/31] cli-script.c: Simplify using std::string, eliminate cleanups Pedro Alves
2016-10-19 18:25 ` Simon Marchi
2016-10-19 21:45 ` Pedro Alves
2016-10-19 1:21 ` [PATCH v2 17/31] Use ui_file_as_string in gdb/printcmd.c Pedro Alves
2016-10-19 1:21 ` [PATCH v2 16/31] Use ui_file_as_string in gdb/top.c Pedro Alves
2016-10-19 1:21 ` [PATCH v2 18/31] Use ui_file_as_string in gdb/python/ Pedro Alves
2016-10-19 1:21 ` [PATCH v2 13/31] Use ui_file_as_string in gdb/arm-tdep.c Pedro Alves
2016-10-19 22:54 ` Simon Marchi
2016-10-20 13:08 ` [PATCH v2 28/31] Use ui_file_as_string throughout more Pedro Alves
2017-02-23 10:23 ` Yao Qi
2017-02-23 10:53 ` Pedro Alves
2017-02-23 10:35 ` Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1476839539-8374-15-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).