From: Doug Evans Date: Tue, 29 Jul 2014 02:20:30 +0000 (-0700) Subject: PR guile/17203 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7ebdbe9292e4b696740b021938369adb1484da27;p=binutils-gdb.git PR guile/17203 * guile/scm-param.c (pascm_parameter_defined_p): New function. (gdbscm_register_parameter_x): Call it. Raise error for pre-existing parameters. testsuite/ * gdb.guile/scm-parameter.exp: Add tests for trying to create previously existing parameter, and previously ambiguously spelled parameter. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0b808694ef6..0e47fbcb39a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2014-07-28 Doug Evans + + PR guile/17203 + * guile/scm-param.c (pascm_parameter_defined_p): New function. + (gdbscm_register_parameter_x): Call it. Raise error for pre-existing + parameters. + 2014-07-28 Will Newton * arm-linux-tdep.c (THUMB2_SET_R7_SIGRETURN1): New define. diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c index 683ec7d5960..f0f83cd434b 100644 --- a/gdb/guile/scm-param.c +++ b/gdb/guile/scm-param.c @@ -966,9 +966,23 @@ gdbscm_make_parameter (SCM name_scm, SCM rest) 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! ) -> 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) @@ -990,6 +1004,17 @@ gdbscm_register_parameter_x (SCM self) p_smob->cmd_name = gdbscm_gc_xstrdup (cmd_name); xfree (cmd_name); + 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_CATCH (except, RETURN_MASK_ALL) { add_setshow_generic (p_smob->type, p_smob->cmd_class, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 2da2c66c269..e65e76a044f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2014-07-28 Doug Evans + + PR guile/17203 + * gdb.guile/scm-parameter.exp: Add tests for trying to create + previously existing parameter, and previously ambiguously spelled + parameter. + 2014-07-28 Will Newton * gdb.base/varargs.exp: Remove KFAILs for ARM. diff --git a/gdb/testsuite/gdb.guile/scm-parameter.exp b/gdb/testsuite/gdb.guile/scm-parameter.exp index 0dd8a471d27..c0df185dee5 100644 --- a/gdb/testsuite/gdb.guile/scm-parameter.exp +++ b/gdb/testsuite/gdb.guile/scm-parameter.exp @@ -166,3 +166,31 @@ with_test_prefix "test-restricted-param" { gdb_test "set test-restricted-param 42" "Error: Range of parameter is 0-10." gdb_test "show test-restricted-param" "The value of the restricted parameter is 2." } + +# Test registering a parameter that already exists. + +gdb_test "guile (register-parameter! (make-parameter \"height\"))" \ + "ERROR.*is already defined.*" "error registering existing parameter" + +# Test registering a parameter named with what was an ambiguous spelling +# of existing parameters. + +gdb_test_multiline "previously ambiguously named boolean parameter" \ + "guile" "" \ + "(define prev-ambig" "" \ + " (make-parameter \"print s\"" "" \ + " #:parameter-type PARAM_BOOLEAN))" "" \ + "end" + +gdb_test_no_output "guile (register-parameter! prev-ambig)" + +with_test_prefix "previously-ambiguous" { + gdb_test "guile (print (parameter-value prev-ambig))" "= #f" "parameter value (false)" + gdb_test "show print s" "Command is not documented is off." "Show parameter off" + gdb_test_no_output "set print s on" + gdb_test "show print s" "Command is not documented is on." "Show parameter on" + gdb_test "guile (print (parameter-value prev-ambig))" "= #t" "parameter value (true)" + gdb_test "help show print s" "This command is not documented." "show help" + gdb_test "help set print s" "This command is not documented." "set help" + gdb_test "help set print" "set print s -- This command is not documented.*" "general help" +}