From patchwork Tue Aug 6 20:30:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33978 Received: (qmail 13105 invoked by alias); 6 Aug 2019 20:30:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13031 invoked by uid 89); 6 Aug 2019 20:30:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Aug 2019 20:30:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id DF42F116470; Tue, 6 Aug 2019 16:30:45 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id o+aboFLugMcb; Tue, 6 Aug 2019 16:30:45 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 8AB6611645B; Tue, 6 Aug 2019 16:30:45 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Make struct frame_arg self-managing Date: Tue, 6 Aug 2019 14:30:43 -0600 Message-Id: <20190806203043.14648-1-tromey@adacore.com> MIME-Version: 1.0 This changes struct frame_arg to be self-managing and then fixes the various users. Tested by the buildbot. gdb/ChangeLog 2019-08-06 Tom Tromey * stack.c (print_frame_arg, read_frame_local, read_frame_arg) (print_frame_args): Update. * python/py-framefilter.c (py_print_single_arg, enumerate_args): Update. * mi/mi-cmd-stack.c (list_arg_or_local): Update. * frame.h (struct frame_arg): Add initializers. : Now a unique_xmalloc_ptr. --- gdb/ChangeLog | 10 ++++++++++ gdb/frame.h | 8 ++++---- gdb/mi/mi-cmd-stack.c | 6 +----- gdb/python/py-framefilter.c | 5 +---- gdb/stack.c | 18 ++++++------------ 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/gdb/frame.h b/gdb/frame.h index ccc285005aa..02b9d32092e 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -821,15 +821,15 @@ extern frame_print_options user_frame_print_options; struct frame_arg { /* Symbol for this parameter used for example for its name. */ - struct symbol *sym; + struct symbol *sym = nullptr; /* Value of the parameter. It is NULL if ERROR is not NULL; if both VAL and ERROR are NULL this parameter's value should not be printed. */ - struct value *val; + struct value *val = nullptr; /* String containing the error message, it is more usually NULL indicating no error occured reading this parameter. */ - char *error; + gdb::unique_xmalloc_ptr error; /* One of the print_entry_values_* entries as appropriate specifically for this frame_arg. It will be different from print_entry_values. With @@ -840,7 +840,7 @@ struct frame_arg value - print_entry_values_compact is not permitted fi ui_out_is_mi_like_p (in such case print_entry_values_no and print_entry_values_only is used for each parameter kind specifically. */ - const char *entry_kind; + const char *entry_kind = nullptr; }; extern void read_frame_arg (const frame_print_options &fp_opts, diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index e8f8d159d2d..7a3ba476415 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -533,7 +533,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what, if (arg->val || arg->error) { if (arg->error) - stb.printf (_(""), arg->error); + stb.printf (_(""), arg->error.get ()); else { try @@ -641,10 +641,8 @@ list_args_or_locals (const frame_print_options &fp_opts, sym2 = sym; gdb_assert (sym2 != NULL); - memset (&arg, 0, sizeof (arg)); arg.sym = sym2; arg.entry_kind = print_entry_values_no; - memset (&entryarg, 0, sizeof (entryarg)); entryarg.sym = sym2; entryarg.entry_kind = print_entry_values_no; @@ -669,8 +667,6 @@ list_args_or_locals (const frame_print_options &fp_opts, list_arg_or_local (&arg, what, values, skip_unavailable); if (entryarg.entry_kind != print_entry_values_no) list_arg_or_local (&entryarg, what, values, skip_unavailable); - xfree (arg.error); - xfree (entryarg.error); } } diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index a2a96ac0d39..a55b72a672d 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -398,7 +398,7 @@ py_print_single_arg (struct ui_out *out, gdb_assert (fa != NULL && fa->error != NULL); out->field_fmt ("value", _(""), - fa->error); + fa->error.get ()); } else py_print_value (out, val, opts, 0, args_type, language); @@ -486,9 +486,6 @@ enumerate_args (PyObject *iter, read_frame_arg (user_frame_print_options, sym, frame, &arg, &entryarg); - gdb::unique_xmalloc_ptr arg_holder (arg.error); - gdb::unique_xmalloc_ptr entry_holder (entryarg.error); - /* The object has not provided a value, so this is a frame argument to be read by GDB. In this case we have to account for entry-values. */ diff --git a/gdb/stack.c b/gdb/stack.c index 0dd7057fe1f..56a60694ecc 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -390,7 +390,7 @@ print_frame_arg (const frame_print_options &fp_opts, else { if (arg->error) - stb.printf (_(""), arg->error); + stb.printf (_(""), arg->error.get ()); else { try @@ -452,13 +452,12 @@ read_frame_local (struct symbol *sym, struct frame_info *frame, } catch (const gdb_exception_error &except) { - argp->error = xstrdup (except.what ()); + argp->error.reset (xstrdup (except.what ())); } } -/* Read in inferior function parameter SYM at FRAME into ARGP. Caller is - responsible for xfree of ARGP->ERROR. This function never throws an - exception. */ +/* Read in inferior function parameter SYM at FRAME into ARGP. This + function never throws an exception. */ void read_frame_arg (const frame_print_options &fp_opts, @@ -626,7 +625,7 @@ read_frame_arg (const frame_print_options &fp_opts, argp->sym = sym; argp->val = val; - argp->error = val_error ? xstrdup (val_error) : NULL; + argp->error.reset (val_error ? xstrdup (val_error) : NULL); if (!val && !val_error) argp->entry_kind = print_entry_values_only; else if ((fp_opts.print_entry_values == print_entry_values_compact @@ -641,7 +640,7 @@ read_frame_arg (const frame_print_options &fp_opts, entryargp->sym = sym; entryargp->val = entryval; - entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL; + entryargp->error.reset (entryval_error ? xstrdup (entryval_error) : NULL); if (!entryval && !entryval_error) entryargp->entry_kind = print_entry_values_no; else @@ -810,10 +809,8 @@ print_frame_args (const frame_print_options &fp_opts, if (!print_args) { - memset (&arg, 0, sizeof (arg)); arg.sym = sym; arg.entry_kind = print_entry_values_no; - memset (&entryarg, 0, sizeof (entryarg)); entryarg.sym = sym; entryarg.entry_kind = print_entry_values_no; } @@ -834,9 +831,6 @@ print_frame_args (const frame_print_options &fp_opts, print_frame_arg (fp_opts, &entryarg); } - xfree (arg.error); - xfree (entryarg.error); - first = 0; } }