/* GDB parameters implemented in Guile.
- Copyright (C) 2008-2014 Free Software Foundation, Inc.
+ Copyright (C) 2008-2015 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "value.h"
-#include "exceptions.h"
#include "charset.h"
#include "gdbcmd.h"
#include "cli/cli-decode.h"
if (! pascm_is_valid (p_smob))
scm_puts (" {invalid}", port);
- gdbscm_printf (port, " %s", pascm_param_type_name (p_smob->type));
+ gdbscm_printf (port, " %s ", pascm_param_type_name (p_smob->type));
value = pascm_param_value (p_smob->type, &p_smob->value,
GDBSCM_ARG_NONE, NULL);
_("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))
/* These are all stored in GC space so that we don't have to worry about
freeing them if we throw an exception. */
p_smob->name = name;
- p_smob->cmd_class = cmd_class;
+ p_smob->cmd_class = (enum command_class) cmd_class;
p_smob->type = (enum var_types) param_type;
p_smob->doc = doc;
p_smob->set_doc = set_doc;
if (gdbscm_is_exception (initial_value_scm))
gdbscm_throw (initial_value_scm);
}
- pascm_set_param_value_x (param_type, &p_smob->value, enum_list,
+ pascm_set_param_value_x (p_smob->type, &p_smob->value, enum_list,
initial_value_scm,
initial_value_arg_pos, FUNC_NAME);
}
return p_scm;
}
+/* Subroutine of gdbscm_register_parameter_x to simplify it.
+ Return non-zero if parameter NAME is already defined in LIST. */
+
+static int
+pascm_parameter_defined_p (const char *name, struct cmd_list_element *list)
+{
+ struct cmd_list_element *c;
+
+ c = lookup_cmd_1 (&name, list, NULL, 1);
+
+ /* If the name is ambiguous that's ok, it's a new parameter still. */
+ return c != NULL && c != CMD_LIST_AMBIGUOUS;
+}
+
/* (register-parameter! <gdb:parameter>) -> unspecified
- It is an error to register a parameter more than once. */
+ It is an error to register a pre-existing parameter. */
static SCM
gdbscm_register_parameter_x (SCM self)
= pascm_get_param_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
char *cmd_name;
struct cmd_list_element **set_list, **show_list;
- volatile struct gdb_exception except;
if (pascm_is_valid (p_smob))
scm_misc_error (FUNC_NAME, _("parameter is already registered"), SCM_EOL);
p_smob->cmd_name = gdbscm_gc_xstrdup (cmd_name);
xfree (cmd_name);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ if (pascm_parameter_defined_p (p_smob->cmd_name, *set_list))
+ {
+ gdbscm_misc_error (FUNC_NAME, SCM_ARG1, self,
+ _("parameter exists, \"set\" command is already defined"));
+ }
+ if (pascm_parameter_defined_p (p_smob->cmd_name, *show_list))
+ {
+ gdbscm_misc_error (FUNC_NAME, SCM_ARG1, self,
+ _("parameter exists, \"show\" command is already defined"));
+ }
+
+ 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);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
/* Note: At this point the parameter exists in gdb.
So no more errors after this point. */
const char *arg;
char *newarg;
int found = -1;
- volatile struct gdb_exception except;
+ struct gdb_exception except = exception_none;
name = gdbscm_scm_to_host_string (self, NULL, &except_scm);
if (name == NULL)
gdbscm_throw (except_scm);
newarg = concat ("show ", name, (char *) NULL);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
}
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ except = ex;
+ }
+ END_CATCH
+
xfree (name);
xfree (newarg);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
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\