/* GDB parameters implemented in Guile.
- Copyright (C) 2008-2015 Free Software Foundation, Inc.
+ Copyright (C) 2008-2020 Free Software Foundation, Inc.
This file is part of GDB.
union pascm_variable
{
- /* Hold an integer value, for boolean and integer types. */
+ /* Hold an boolean value. */
+ bool boolval;
+
+ /* Hold an integer value. */
int intval;
/* Hold an auto_boolean. */
itself. */
if (gdbscm_user_error_p (gdbscm_exception_key (exception)))
{
- char *excp_text = gdbscm_exception_message_to_string (exception);
+ gdb::unique_xmalloc_ptr<char> excp_text
+ = gdbscm_exception_message_to_string (exception);
- make_cleanup (xfree, excp_text);
- error ("%s", excp_text);
+ error ("%s", excp_text.get ());
}
else
{
Note: ARGS is always passed as NULL. */
static void
-pascm_set_func (char *args, int from_tty, struct cmd_list_element *c)
+pascm_set_func (const char *args, int from_tty, struct cmd_list_element *c)
{
param_smob *p_smob = (param_smob *) get_cmd_context (c);
SCM self, result, exception;
- char *msg;
- struct cleanup *cleanups;
gdb_assert (gdbscm_is_procedure (p_smob->set_func));
if (!scm_is_string (result))
error (_("Result of %s set-func is not a string."), p_smob->name);
- msg = gdbscm_scm_to_host_string (result, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> msg = gdbscm_scm_to_host_string (result, NULL,
+ &exception);
if (msg == NULL)
{
gdbscm_print_gdb_exception (SCM_BOOL_F, exception);
error (_("Error converting show text to host string."));
}
- cleanups = make_cleanup (xfree, msg);
/* GDB is usually silent when a parameter is set. */
- if (*msg != '\0')
- fprintf_filtered (gdb_stdout, "%s\n", msg);
- do_cleanups (cleanups);
+ if (*msg.get () != '\0')
+ fprintf_filtered (gdb_stdout, "%s\n", msg.get ());
}
/* A callback function that is registered against the respective
{
param_smob *p_smob = (param_smob *) get_cmd_context (c);
SCM value_scm, self, result, exception;
- char *msg;
- struct cleanup *cleanups;
gdb_assert (gdbscm_is_procedure (p_smob->show_func));
_("Error occurred showing parameter."));
}
- msg = gdbscm_scm_to_host_string (result, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> msg = gdbscm_scm_to_host_string (result, NULL,
+ &exception);
if (msg == NULL)
{
gdbscm_print_gdb_exception (SCM_BOOL_F, exception);
error (_("Error converting show text to host string."));
}
- cleanups = make_cleanup (xfree, msg);
- fprintf_filtered (file, "%s\n", msg);
- do_cleanups (cleanups);
+ fprintf_filtered (file, "%s\n", msg.get ());
}
/* A helper function that dispatches to the appropriate add_setshow
add_setshow_generic (enum var_types param_type, enum command_class cmd_class,
char *cmd_name, param_smob *self,
char *set_doc, char *show_doc, char *help_doc,
- cmd_sfunc_ftype *set_func,
+ cmd_const_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list,
{
case var_boolean:
add_setshow_boolean_cmd (cmd_name, cmd_class,
- &self->value.intval,
+ &self->value.boolval,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list);
/* Lookup created parameter, and register Scheme object against the
parameter context. Perform this task against both lists. */
tmp_name = cmd_name;
- param = lookup_cmd (&tmp_name, *show_list, "", 0, 1);
+ param = lookup_cmd (&tmp_name, *show_list, "", NULL, 0, 1);
gdb_assert (param != NULL);
set_cmd_context (param, self);
*set_cmd = param;
tmp_name = cmd_name;
- param = lookup_cmd (&tmp_name, *set_list, "", 0, 1);
+ param = lookup_cmd (&tmp_name, *set_list, "", NULL, 0, 1);
gdb_assert (param != NULL);
set_cmd_context (param, self);
*show_cmd = param;
_("enumeration list is empty"));
}
- enum_values = xmalloc ((size + 1) * sizeof (char *));
- memset (enum_values, 0, (size + 1) * sizeof (char *));
+ enum_values = XCNEWVEC (char *, size + 1);
i = 0;
while (!scm_is_eq (enum_values_scm, SCM_EOL))
freeargv (enum_values);
SCM_ASSERT_TYPE (0, value, arg_pos, func_name, _("string"));
}
- enum_values[i] = gdbscm_scm_to_host_string (value, NULL, &exception);
+ enum_values[i] = gdbscm_scm_to_host_string (value, NULL,
+ &exception).release ();
if (enum_values[i] == NULL)
{
freeargv (enum_values);
case var_filename:
case var_enum:
{
- char *str = * (char **) var;
+ const char *str = *(char **) var;
if (str == NULL)
str = "";
case var_boolean:
{
- if (* (int *) var)
+ if (* (bool *) var)
return SCM_BOOL_T;
else
return SCM_BOOL_F;
}
else
{
- char *string;
SCM exception;
- string = gdbscm_scm_to_host_string (value, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> string
+ = gdbscm_scm_to_host_string (value, NULL, &exception);
if (string == NULL)
gdbscm_throw (exception);
xfree (var->stringval);
- var->stringval = string;
+ var->stringval = string.release ();
}
break;
case var_enum:
{
int i;
- char *str;
SCM exception;
SCM_ASSERT_TYPE (scm_is_string (value), value, arg_pos, func_name,
_("string"));
- str = gdbscm_scm_to_host_string (value, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> str
+ = gdbscm_scm_to_host_string (value, NULL, &exception);
if (str == NULL)
gdbscm_throw (exception);
for (i = 0; enumeration[i]; ++i)
{
- if (strcmp (enumeration[i], str) == 0)
+ if (strcmp (enumeration[i], str.get ()) == 0)
break;
}
- xfree (str);
if (enumeration[i] == NULL)
{
gdbscm_out_of_range_error (func_name, arg_pos, value,
case var_boolean:
SCM_ASSERT_TYPE (gdbscm_is_bool (value), value, arg_pos, func_name,
_("boolean"));
- var->intval = gdbscm_is_true (value);
+ var->boolval = gdbscm_is_true (value);
break;
case var_auto_boolean:
{
struct cmd_list_element *c;
- c = lookup_cmd_1 (&name, list, NULL, 1);
+ c = lookup_cmd_1 (&name, list, NULL, NULL, 1);
/* If the name is ambiguous that's ok, it's a new parameter still. */
return c != NULL && c != CMD_LIST_AMBIGUOUS;
_("parameter exists, \"show\" command is already defined"));
}
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
add_setshow_generic (p_smob->type, p_smob->cmd_class,
p_smob->cmd_name, p_smob,
set_list, show_list,
&p_smob->set_command, &p_smob->show_command);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
/* Note: At this point the parameter exists in gdb.
So no more errors after this point. */
}
else
{
- char *name;
SCM except_scm;
struct cmd_list_element *alias, *prefix, *cmd;
- const char *arg;
char *newarg;
int found = -1;
- struct gdb_exception except = exception_none;
+ gdbscm_gdb_exception except {};
- name = gdbscm_scm_to_host_string (self, NULL, &except_scm);
+ gdb::unique_xmalloc_ptr<char> name
+ = gdbscm_scm_to_host_string (self, NULL, &except_scm);
if (name == NULL)
gdbscm_throw (except_scm);
- newarg = concat ("show ", name, (char *) NULL);
- TRY
+ newarg = concat ("show ", name.get (), (char *) NULL);
+ try
{
found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
}
- CATCH (ex, RETURN_MASK_ALL)
+ catch (const gdb_exception &ex)
{
- except = ex;
+ except = unpack (ex);
}
- END_CATCH
- xfree (name);
xfree (newarg);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (!found)
static const scheme_function parameter_functions[] =
{
- { "make-parameter", 1, 0, 1, gdbscm_make_parameter,
+ { "make-parameter", 1, 0, 1, as_a_scm_t_subr (gdbscm_make_parameter),
"\
Make a GDB parameter object.\n\
\n\
show-doc: The \"doc string\" when showing the parameter.\n\
initial-value: The initial value of the parameter." },
- { "register-parameter!", 1, 0, 0, gdbscm_register_parameter_x,
+ { "register-parameter!", 1, 0, 0,
+ as_a_scm_t_subr (gdbscm_register_parameter_x),
"\
Register a <gdb:parameter> object with GDB." },
- { "parameter?", 1, 0, 0, gdbscm_parameter_p,
+ { "parameter?", 1, 0, 0, as_a_scm_t_subr (gdbscm_parameter_p),
"\
Return #t if the object is a <gdb:parameter> object." },
- { "parameter-value", 1, 0, 0, gdbscm_parameter_value,
+ { "parameter-value", 1, 0, 0, as_a_scm_t_subr (gdbscm_parameter_value),
"\
Return the value of a <gdb:parameter> object\n\
or any gdb parameter if param is a string naming the parameter." },
- { "set-parameter-value!", 2, 0, 0, gdbscm_set_parameter_value_x,
+ { "set-parameter-value!", 2, 0, 0,
+ as_a_scm_t_subr (gdbscm_set_parameter_value_x),
"\
Set the value of a <gdb:parameter> object.\n\
\n\