Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 1/3] Remove cleanup from ada-lang.c
Date: Sat, 19 May 2018 20:37:00 -0000	[thread overview]
Message-ID: <20180519160606.19969-2-tom@tromey.com> (raw)
In-Reply-To: <20180519160606.19969-1-tom@tromey.com>

This removes a cleanup from ada-lang.c by having
ada_exception_message_1 return a unique_xmalloc_ptr.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_exception_message_1, ada_exception_message):
	Return unique_xmalloc_ptr.
	(print_it_exception): Update.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/ada-lang.c | 29 +++++++++--------------------
 2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7cbf1ec08d..da5f75030c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12342,8 +12342,6 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
    return the message which was associated to the exception, if
    available.  Return NULL if the message could not be retrieved.
 
-   The caller must xfree the string after use.
-
    Note: The exception message can be associated to an exception
    either through the use of the Raise_Exception function, or
    more simply (Ada 2005 and later), via:
@@ -12352,13 +12350,11 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
 
    */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 ada_exception_message_1 (void)
 {
   struct value *e_msg_val;
-  char *e_msg = NULL;
   int e_msg_len;
-  struct cleanup *cleanups;
 
   /* For runtimes that support this feature, the exception message
      is passed as an unbounded string argument called "message".  */
@@ -12375,22 +12371,20 @@ ada_exception_message_1 (void)
   if (e_msg_len <= 0)
     return NULL;
 
-  e_msg = (char *) xmalloc (e_msg_len + 1);
-  cleanups = make_cleanup (xfree, e_msg);
-  read_memory_string (value_address (e_msg_val), e_msg, e_msg_len + 1);
-  e_msg[e_msg_len] = '\0';
+  gdb::unique_xmalloc_ptr<char> e_msg ((char *) xmalloc (e_msg_len + 1));
+  read_memory_string (value_address (e_msg_val), e_msg.get (), e_msg_len + 1);
+  e_msg.get ()[e_msg_len] = '\0';
 
-  discard_cleanups (cleanups);
   return e_msg;
 }
 
 /* Same as ada_exception_message_1, except that all exceptions are
    contained here (returning NULL instead).  */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 ada_exception_message (void)
 {
-  char *e_msg = NULL;  /* Avoid a spurious uninitialized warning.  */
+  gdb::unique_xmalloc_ptr<char> e_msg;
 
   TRY
     {
@@ -12398,7 +12392,7 @@ ada_exception_message (void)
     }
   CATCH (e, RETURN_MASK_ERROR)
     {
-      e_msg = NULL;
+      e_msg.reset (nullptr);
     }
   END_CATCH
 
@@ -12639,7 +12633,6 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
 {
   struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
-  char *exception_message;
 
   annotate_catchpoint (b->number);
 
@@ -12707,16 +12700,12 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
 	break;
     }
 
-  exception_message = ada_exception_message ();
+  gdb::unique_xmalloc_ptr<char> exception_message = ada_exception_message ();
   if (exception_message != NULL)
     {
-      struct cleanup *cleanups = make_cleanup (xfree, exception_message);
-
       uiout->text (" (");
-      uiout->field_string ("exception-message", exception_message);
+      uiout->field_string ("exception-message", exception_message.get ());
       uiout->text (")");
-
-      do_cleanups (cleanups);
     }
 
   uiout->text (" at ");
-- 
2.13.6


  parent reply	other threads:[~2018-05-19 16:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-19 20:37 [RFA 0/3] More Ada cleanup removal Tom Tromey
2018-05-19 16:06 ` [RFA 3/3] Change ada_catchpoint::excep_string to be a std::string Tom Tromey
2018-05-21  1:12   ` Simon Marchi
2018-05-22 14:49     ` [pushed+RFC] C++ exception during command triggers stale cleanup internal-warning Joel Brobecker
2018-05-22 14:50       ` [pushed/Ada] fix "stale cleanup" internal-warning when using "catch assert" command Joel Brobecker
2018-05-22 14:58       ` [pushed+RFC] C++ exception during command triggers stale cleanup internal-warning Tom Tromey
2018-05-22 15:48         ` Joel Brobecker
2018-05-19 16:06 ` [RFA 2/3] Remove cleanup from ada_collect_symbol_completion_matches Tom Tromey
2018-05-21  0:09   ` Simon Marchi
2018-05-19 20:37 ` Tom Tromey [this message]
2018-05-21  0:06   ` [RFA 1/3] Remove cleanup from ada-lang.c Simon Marchi

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=20180519160606.19969-2-tom@tromey.com \
    --to=tom@tromey.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