Make struct frame_arg self-managing

This changes struct frame_arg to be self-managing and then fixes the
various users.

Tested by the buildbot.

gdb/ChangeLog
2019-08-07  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.
This commit is contained in:
Tom Tromey 2019-08-06 13:50:03 -06:00
parent 3d31bc39e6
commit 123cd85148
5 changed files with 22 additions and 25 deletions

View File

@ -1,3 +1,13 @@
2019-08-07 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.
2019-08-07 Alan Hayward <alan.hayward@arm.com> 2019-08-07 Alan Hayward <alan.hayward@arm.com>
* NEWS: Expand the Pointer Authentication entry. * NEWS: Expand the Pointer Authentication entry.

View File

@ -821,15 +821,15 @@ extern frame_print_options user_frame_print_options;
struct frame_arg struct frame_arg
{ {
/* Symbol for this parameter used for example for its name. */ /* 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 /* 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. */ 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 /* String containing the error message, it is more usually NULL indicating no
error occured reading this parameter. */ error occured reading this parameter. */
char *error; gdb::unique_xmalloc_ptr<char> error;
/* One of the print_entry_values_* entries as appropriate specifically for /* One of the print_entry_values_* entries as appropriate specifically for
this frame_arg. It will be different from print_entry_values. With 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 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 (in such case print_entry_values_no and print_entry_values_only is used
for each parameter kind specifically. */ 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, extern void read_frame_arg (const frame_print_options &fp_opts,

View File

@ -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->val || arg->error)
{ {
if (arg->error) if (arg->error)
stb.printf (_("<error reading variable: %s>"), arg->error); stb.printf (_("<error reading variable: %s>"), arg->error.get ());
else else
{ {
try try
@ -641,10 +641,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
sym2 = sym; sym2 = sym;
gdb_assert (sym2 != NULL); gdb_assert (sym2 != NULL);
memset (&arg, 0, sizeof (arg));
arg.sym = sym2; arg.sym = sym2;
arg.entry_kind = print_entry_values_no; arg.entry_kind = print_entry_values_no;
memset (&entryarg, 0, sizeof (entryarg));
entryarg.sym = sym2; entryarg.sym = sym2;
entryarg.entry_kind = print_entry_values_no; 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); list_arg_or_local (&arg, what, values, skip_unavailable);
if (entryarg.entry_kind != print_entry_values_no) if (entryarg.entry_kind != print_entry_values_no)
list_arg_or_local (&entryarg, what, values, skip_unavailable); list_arg_or_local (&entryarg, what, values, skip_unavailable);
xfree (arg.error);
xfree (entryarg.error);
} }
} }

View File

@ -398,7 +398,7 @@ py_print_single_arg (struct ui_out *out,
gdb_assert (fa != NULL && fa->error != NULL); gdb_assert (fa != NULL && fa->error != NULL);
out->field_fmt ("value", out->field_fmt ("value",
_("<error reading variable: %s>"), _("<error reading variable: %s>"),
fa->error); fa->error.get ());
} }
else else
py_print_value (out, val, opts, 0, args_type, language); 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, read_frame_arg (user_frame_print_options,
sym, frame, &arg, &entryarg); 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 /* The object has not provided a value, so this is a frame
argument to be read by GDB. In this case we have to argument to be read by GDB. In this case we have to
account for entry-values. */ account for entry-values. */

View File

@ -390,7 +390,7 @@ print_frame_arg (const frame_print_options &fp_opts,
else else
{ {
if (arg->error) if (arg->error)
stb.printf (_("<error reading variable: %s>"), arg->error); stb.printf (_("<error reading variable: %s>"), arg->error.get ());
else else
{ {
try try
@ -452,13 +452,12 @@ read_frame_local (struct symbol *sym, struct frame_info *frame,
} }
catch (const gdb_exception_error &except) 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 /* Read in inferior function parameter SYM at FRAME into ARGP. This
responsible for xfree of ARGP->ERROR. This function never throws an function never throws an exception. */
exception. */
void void
read_frame_arg (const frame_print_options &fp_opts, 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->sym = sym;
argp->val = val; argp->val = val;
argp->error = val_error ? xstrdup (val_error) : NULL; argp->error.reset (val_error ? xstrdup (val_error) : NULL);
if (!val && !val_error) if (!val && !val_error)
argp->entry_kind = print_entry_values_only; argp->entry_kind = print_entry_values_only;
else if ((fp_opts.print_entry_values == print_entry_values_compact 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->sym = sym;
entryargp->val = entryval; entryargp->val = entryval;
entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL; entryargp->error.reset (entryval_error ? xstrdup (entryval_error) : NULL);
if (!entryval && !entryval_error) if (!entryval && !entryval_error)
entryargp->entry_kind = print_entry_values_no; entryargp->entry_kind = print_entry_values_no;
else else
@ -810,10 +809,8 @@ print_frame_args (const frame_print_options &fp_opts,
if (!print_args) if (!print_args)
{ {
memset (&arg, 0, sizeof (arg));
arg.sym = sym; arg.sym = sym;
arg.entry_kind = print_entry_values_no; arg.entry_kind = print_entry_values_no;
memset (&entryarg, 0, sizeof (entryarg));
entryarg.sym = sym; entryarg.sym = sym;
entryarg.entry_kind = print_entry_values_no; 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); print_frame_arg (fp_opts, &entryarg);
} }
xfree (arg.error);
xfree (entryarg.error);
first = 0; first = 0;
} }
} }