diff options
author | Tom Tromey <tom@tromey.com> | 2018-05-18 15:41:33 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-05-21 10:01:14 -0600 |
commit | 6f46ac8531ead61003c96b8e2fa6a383ea8d8c58 (patch) | |
tree | c4815185847f8d552492f4b025bcde97e93b1bca | |
parent | 15b6611c69f6fdb7a20cd50d33d9acf8c5c32037 (diff) | |
download | gdb-6f46ac8531ead61003c96b8e2fa6a383ea8d8c58.zip gdb-6f46ac8531ead61003c96b8e2fa6a383ea8d8c58.tar.gz gdb-6f46ac8531ead61003c96b8e2fa6a383ea8d8c58.tar.bz2 |
Remove cleanup from ada-lang.c
This removes a cleanup from ada-lang.c by having
ada_exception_message_1 return a unique_xmalloc_ptr.
ChangeLog
2018-05-21 Tom Tromey <tom@tromey.com>
* ada-lang.c (ada_exception_message_1, ada_exception_message):
Return unique_xmalloc_ptr.
(print_it_exception): Update.
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/ada-lang.c | 29 |
2 files changed, 15 insertions, 20 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e0a6ed4..018a98e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2018-05-21 Tom Tromey <tom@tromey.com> + * ada-lang.c (ada_exception_message_1, ada_exception_message): + Return unique_xmalloc_ptr. + (print_it_exception): Update. + +2018-05-21 Tom Tromey <tom@tromey.com> + * tracepoint.c (trace_dump_actions): Use std::string. 2018-05-21 Tom Tromey <tom@tromey.com> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f2514b1..fe6212c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12341,8 +12341,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: @@ -12351,13 +12349,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". */ @@ -12374,22 +12370,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 { @@ -12397,7 +12391,7 @@ ada_exception_message (void) } CATCH (e, RETURN_MASK_ERROR) { - e_msg = NULL; + e_msg.reset (nullptr); } END_CATCH @@ -12638,7 +12632,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); @@ -12706,16 +12699,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 "); |