diff options
author | Tom Tromey <tom@tromey.com> | 2018-05-26 23:21:23 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-07-17 13:21:47 -0600 |
commit | 15bf30027bcb167833a0ca2c619c03f177ef1ba4 (patch) | |
tree | 117580eb74accac812d65ad76bb839237f0ab4d3 /gdb | |
parent | 7eb1a66c26b57803bb4245f84cf15278297bb649 (diff) | |
download | gdb-15bf30027bcb167833a0ca2c619c03f177ef1ba4.zip gdb-15bf30027bcb167833a0ca2c619c03f177ef1ba4.tar.gz gdb-15bf30027bcb167833a0ca2c619c03f177ef1ba4.tar.bz2 |
Change gdbscm_exception_message_to_string to return a unique_xmalloc_ptr
This changes gdbscm_exception_message_to_string to return a
unique_xmalloc_ptr, allowing for the removal of some cleanups.
unique_xmalloc_ptr was chosen because at the root of the call chains
is a function from Guile that returns a malloc'd string.
gdb/ChangeLog
2018-07-17 Tom Tromey <tom@tromey.com>
* guile/scm-param.c (pascm_signal_setshow_error): Update.
* guile/guile-internal.h (gdbscm_exception_message_to_string):
Update.
* guile/scm-cmd.c (cmdscm_function): Update.
* guile/scm-pretty-print.c
(ppscm_print_exception_unless_memory_error): Update.
* guile/scm-exception.c (gdbscm_exception_message_to_string):
Return unique_xmalloc_ptr.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 11 | ||||
-rw-r--r-- | gdb/guile/guile-internal.h | 3 | ||||
-rw-r--r-- | gdb/guile/scm-cmd.c | 6 | ||||
-rw-r--r-- | gdb/guile/scm-exception.c | 11 | ||||
-rw-r--r-- | gdb/guile/scm-param.c | 6 | ||||
-rw-r--r-- | gdb/guile/scm-pretty-print.c | 17 |
6 files changed, 31 insertions, 23 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 584ea6f..1956f78 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ 2018-07-17 Tom Tromey <tom@tromey.com> + * guile/scm-param.c (pascm_signal_setshow_error): Update. + * guile/guile-internal.h (gdbscm_exception_message_to_string): + Update. + * guile/scm-cmd.c (cmdscm_function): Update. + * guile/scm-pretty-print.c + (ppscm_print_exception_unless_memory_error): Update. + * guile/scm-exception.c (gdbscm_exception_message_to_string): + Return unique_xmalloc_ptr. + +2018-07-17 Tom Tromey <tom@tromey.com> + * guile/scm-pretty-print.c (ppscm_make_pp_type_error_exception): Use string_printf. diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h index 6bce58e..20e2c70 100644 --- a/gdb/guile/guile-internal.h +++ b/gdb/guile/guile-internal.h @@ -362,7 +362,8 @@ extern void gdbscm_print_exception_with_stack (SCM port, SCM stack, extern void gdbscm_print_gdb_exception (SCM port, SCM exception); -extern char *gdbscm_exception_message_to_string (SCM exception); +extern gdb::unique_xmalloc_ptr<char> gdbscm_exception_message_to_string + (SCM exception); extern excp_matcher_func gdbscm_memory_error_p; diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index 64243d1..8bb4662 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -316,10 +316,10 @@ cmdscm_function (struct cmd_list_element *command, itself. */ if (gdbscm_user_error_p (gdbscm_exception_key (result))) { - char *msg = gdbscm_exception_message_to_string (result); + gdb::unique_xmalloc_ptr<char> msg + = gdbscm_exception_message_to_string (result); - make_cleanup (xfree, msg); - error ("%s", msg); + error ("%s", msg.get ()); } else { diff --git a/gdb/guile/scm-exception.c b/gdb/guile/scm-exception.c index e4b81a1..f0bcdcd 100644 --- a/gdb/guile/scm-exception.c +++ b/gdb/guile/scm-exception.c @@ -575,16 +575,13 @@ gdbscm_print_gdb_exception (SCM port, SCM exception) /* Return a string description of <gdb:exception> EXCEPTION. If EXCEPTION is a gdb:with-stack exception, unwrap it, a backtrace - is never returned as part of the result. + is never returned as part of the result. */ - Space for the result is malloc'd, the caller must free. */ - -char * +gdb::unique_xmalloc_ptr<char> gdbscm_exception_message_to_string (SCM exception) { SCM port = scm_open_output_string (); SCM key, args; - char *result; gdb_assert (gdbscm_is_exception (exception)); @@ -601,9 +598,9 @@ gdbscm_exception_message_to_string (SCM exception) } gdbscm_print_exception_message (port, SCM_BOOL_F, key, args); - result = gdbscm_scm_to_c_string (scm_get_output_string (port)); + gdb::unique_xmalloc_ptr<char> result + (gdbscm_scm_to_c_string (scm_get_output_string (port))); scm_close_port (port); - return result; } diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c index d48f14e..7ff4af9 100644 --- a/gdb/guile/scm-param.c +++ b/gdb/guile/scm-param.c @@ -251,10 +251,10 @@ pascm_signal_setshow_error (SCM exception, const char *msg) itself. */ if (gdbscm_user_error_p (gdbscm_exception_key (exception))) { - char *excp_text = gdbscm_exception_message_to_string (exception); + gdb::unique_xmalloc_ptr<char> excp_text + = gdbscm_exception_message_to_string (exception); - make_cleanup (xfree, excp_text); - error ("%s", excp_text); + error ("%s", excp_text.get ()); } else { diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c index 5e8a2a9..eea524b 100644 --- a/gdb/guile/scm-pretty-print.c +++ b/gdb/guile/scm-pretty-print.c @@ -614,25 +614,24 @@ ppscm_print_exception_unless_memory_error (SCM exception, { if (gdbscm_memory_error_p (gdbscm_exception_key (exception))) { - char *msg = gdbscm_exception_message_to_string (exception); - struct cleanup *cleanup = make_cleanup (xfree, msg); + gdb::unique_xmalloc_ptr<char> msg + = gdbscm_exception_message_to_string (exception); /* This "shouldn't happen", but play it safe. */ - if (msg == NULL || *msg == '\0') + if (msg == NULL || msg.get ()[0] == '\0') fprintf_filtered (stream, _("<error reading variable>")); else { /* Remove the trailing newline. We could instead call a special routine for printing memory error messages, but this is easy enough for now. */ - size_t len = strlen (msg); + char *msg_text = msg.get (); + size_t len = strlen (msg_text); - if (msg[len - 1] == '\n') - msg[len - 1] = '\0'; - fprintf_filtered (stream, _("<error reading variable: %s>"), msg); + if (msg_text[len - 1] == '\n') + msg_text[len - 1] = '\0'; + fprintf_filtered (stream, _("<error reading variable: %s>"), msg_text); } - - do_cleanups (cleanup); } else gdbscm_print_gdb_exception (SCM_BOOL_F, exception); |