Patchwork Make struct frame_arg self-managing

login
register
mail settings
Submitter Tom Tromey
Date Aug. 6, 2019, 8:30 p.m.
Message ID <20190806203043.14648-1-tromey@adacore.com>
Download mbox | patch
Permalink /patch/33978/
State New
Headers show

Comments

Tom Tromey - Aug. 6, 2019, 8:30 p.m.
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  <tromey@adacore.com>

	* 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.
	<error>: 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(-)
Kevin Buettner - Aug. 6, 2019, 9:36 p.m.
On Tue,  6 Aug 2019 14:30:43 -0600
Tom Tromey <tromey@adacore.com> wrote:

> 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  <tromey@adacore.com>
> 
> 	* 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.
> 	<error>: Now a unique_xmalloc_ptr.

LGTM.

Kevin

Patch

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<char> 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 (_("<error reading variable: %s>"), arg->error);
+	stb.printf (_("<error reading variable: %s>"), 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",
 			      _("<error reading variable: %s>"),
-			      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<char> arg_holder (arg.error);
-	  gdb::unique_xmalloc_ptr<char> 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 (_("<error reading variable: %s>"), arg->error);
+	stb.printf (_("<error reading variable: %s>"), 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;
 	}
     }