public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>,
	 Simon Marchi <simon.marchi@polymtl.ca>,
	Tom Tromey <tom@tromey.com>,  Simon Sobisch <simonsobisch@web.de>
Subject: [PATCH v6 1/8] GDB/Guile: Don't assert that an integer value is boolean
Date: Wed, 17 Aug 2022 23:03:42 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.2.20.2208151614000.10833@tpp.orcam.me.uk> (raw)
In-Reply-To: <alpine.DEB.2.20.2208151502460.10833@tpp.orcam.me.uk>

Do not assert that a value intended for an integer parameter, of either 
the PARAM_UINTEGER or the PARAM_ZUINTEGER_UNLIMITED type, is boolean,
causing error messages such as:

ERROR: In procedure make-parameter:
ERROR: In procedure gdbscm_make_parameter: Wrong type argument in position 15 (expecting integer or #:unlimited): 3
Error while executing Scheme code.

when initialization with a number is attempted.  Instead assert that it 
is integer.  Keep matching `#:unlimited' keyword as an alternative.  Add 
suitable test cases.
---
Hi,

 Probably obvious, and shows how much use this code gets.

  Maciej

New change in v6.
---
 gdb/guile/scm-param.c                     |    2 
 gdb/testsuite/gdb.guile/scm-parameter.exp |  176 ++++++++++++++++++++++++++++++
 2 files changed, 177 insertions(+), 1 deletion(-)

gdb-guile-scm-param-is-integer.diff
Index: src/gdb/guile/scm-param.c
===================================================================
--- src.orig/gdb/guile/scm-param.c
+++ src/gdb/guile/scm-param.c
@@ -742,7 +742,7 @@ pascm_set_param_value_x (param_smob *p_s
       if (var.type () == var_uinteger
 	  || var.type () == var_zuinteger_unlimited)
 	{
-	  SCM_ASSERT_TYPE (gdbscm_is_bool (value)
+	  SCM_ASSERT_TYPE (scm_is_integer (value)
 			   || scm_is_eq (value, unlimited_keyword),
 			   value, arg_pos, func_name,
 			   _("integer or #:unlimited"));
Index: src/gdb/testsuite/gdb.guile/scm-parameter.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.guile/scm-parameter.exp
+++ src/gdb/testsuite/gdb.guile/scm-parameter.exp
@@ -29,6 +29,14 @@ if { [skip_guile_tests] } { continue }
 gdb_install_guile_utils
 gdb_install_guile_module
 
+proc scm_param_test_maybe_no_output { command pattern args } {
+    if [string length $pattern] {
+	gdb_test $command $pattern $args
+    } else {
+	gdb_test_no_output $command $args
+    }
+}
+
 # We use "." here instead of ":" so that this works on win32 too.
 set escaped_directory [string_to_regexp "$srcdir/$subdir"]
 gdb_test "guile (print (parameter-value \"directories\"))" "$escaped_directory.\\\$cdir.\\\$cwd"
@@ -91,6 +99,172 @@ with_test_prefix "test-enum-param" {
     gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "set invalid enum parameter" 
 }
 
+# Test integer parameters.
+
+foreach_with_prefix param {
+    "listsize"
+    "print elements"
+    "max-completions"
+} {
+    set param_range_error "integer -1 out of range"
+    set param_type_error \
+	"#<gdb:exception out-of-range\
+	 \\(\"gdbscm_parameter_value\"\
+	    \"Out of range: program error: unhandled type in position 1: ~S\"\
+	    \\(3\\) \\(3\\)\\)>"
+    switch -- $param {
+	"listsize" {
+	    set param_get_one $param_type_error
+	    set param_get_zero $param_type_error
+	    set param_get_minus_one $param_type_error
+	    set param_get_unlimited $param_type_error
+	    set param_set_minus_one ""
+	}
+	"print elements" {
+	    set param_get_one 1
+	    set param_get_zero "#:unlimited"
+	    set param_get_minus_one "#:unlimited"
+	    set param_get_unlimited "#:unlimited"
+	    set param_set_minus_one $param_range_error
+	}
+	"max-completions" {
+	    set param_get_one 1
+	    set param_get_zero 0
+	    set param_get_minus_one "#:unlimited"
+	    set param_get_unlimited "#:unlimited"
+	    set param_set_minus_one ""
+	}
+	default {
+	    error "invalid param: $param"
+	}
+    }
+
+    gdb_test_no_output "set $param 1" "test set to 1"
+
+    gdb_test "guile (print (parameter-value \"$param\"))" \
+	$param_get_one "test value of 1"
+
+    gdb_test_no_output "set $param 0" "test set to 0"
+
+    gdb_test "guile (print (parameter-value \"$param\"))" \
+	$param_get_zero "test value of 0"
+
+    scm_param_test_maybe_no_output "set $param -1" \
+	$param_set_minus_one "test set to -1"
+
+    gdb_test "guile (print (parameter-value \"$param\"))" \
+	$param_get_minus_one "test value of -1"
+
+    gdb_test_no_output "set $param unlimited" "test set to 'unlimited'"
+
+    gdb_test "guile (print (parameter-value \"$param\"))" \
+	$param_get_unlimited "test value of 'unlimited'"
+}
+
+foreach_with_prefix kind {
+    PARAM_UINTEGER
+    PARAM_ZINTEGER
+    PARAM_ZUINTEGER
+    PARAM_ZUINTEGER_UNLIMITED
+} {
+    gdb_test_multiline "create gdb parameter" \
+	"guile" "" \
+	"(define test-$kind-param" "" \
+	"  (make-parameter \"print test-$kind-param\"" "" \
+	"   #:command-class COMMAND_DATA" "" \
+	"   #:parameter-type $kind" "" \
+	"   #:doc \"Set to a number or 'unlimited' to yield an effect.\"" "" \
+	"   #:show-doc \"Show the state of $kind.\"" "" \
+	"   #:set-doc \"Set the state of $kind.\"" "" \
+	"   #:show-func (lambda (self value)" "" \
+	"      (format #f \"The state of $kind is ~a.\" value))" "" \
+	"   #:initial-value 3))" "" \
+	"(register-parameter! test-$kind-param)" "" \
+	"end"
+
+    set param_integer_error \
+	"ERROR: In procedure set-parameter-value!:\r\nERROR: In procedure\
+	 gdbscm_set_parameter_value_x: Wrong type argument in position 2\
+	 \\(expecting integer\\): #:unlimited\r\nError while executing Scheme\
+	 code\\."
+    set param_minus_one_error "integer -1 out of range"
+    set param_minus_two_range "integer -2 out of range"
+    set param_minus_two_unlimited "only -1 is allowed to set as unlimited"
+    switch -- $kind {
+	PARAM_UINTEGER {
+	    set param_get_zero "#:unlimited"
+	    set param_get_minus_one "#:unlimited"
+	    set param_get_minus_two "#:unlimited"
+	    set param_str_unlimited unlimited
+	    set param_set_unlimited ""
+	    set param_set_minus_one $param_minus_one_error
+	    set param_set_minus_two $param_minus_two_range
+	}
+	PARAM_ZINTEGER {
+	    set param_get_zero 0
+	    set param_get_minus_one -1
+	    set param_get_minus_two -2
+	    set param_str_unlimited 2
+	    set param_set_unlimited $param_integer_error
+	    set param_set_minus_one ""
+	    set param_set_minus_two ""
+	}
+	PARAM_ZUINTEGER {
+	    set param_get_zero 0
+	    set param_get_minus_one 0
+	    set param_get_minus_two 0
+	    set param_str_unlimited 2
+	    set param_set_unlimited $param_integer_error
+	    set param_set_minus_one $param_minus_one_error
+	    set param_set_minus_two $param_minus_two_range
+	}
+	PARAM_ZUINTEGER_UNLIMITED {
+	    set param_get_zero 0
+	    set param_get_minus_one "#:unlimited"
+	    set param_get_minus_two "#:unlimited"
+	    set param_str_unlimited unlimited
+	    set param_set_unlimited ""
+	    set param_set_minus_one ""
+	    set param_set_minus_two $param_minus_two_unlimited
+	}
+	default {
+	    error "invalid kind: $kind"
+	}
+    }
+
+    with_test_prefix "test-$kind-param" {
+	gdb_test "guile (print (parameter-value test-$kind-param))" \
+	    3 "$kind parameter value (3)"
+	gdb_test "show print test-$kind-param" \
+	    "The state of $kind is 3." "show initial value"
+	gdb_test_no_output "set print test-$kind-param 2"
+	gdb_test "show print test-$kind-param" \
+	    "The state of $kind is 2." "show new value"
+	gdb_test "guile (print (parameter-value test-$kind-param))" \
+	    2 "$kind parameter value (2)"
+	scm_param_test_maybe_no_output \
+	    "guile (set-parameter-value! test-$kind-param #:unlimited)" \
+	    $param_set_unlimited
+	gdb_test "show print test-$kind-param" \
+	    "The state of $kind is $param_str_unlimited." \
+	    "show unlimited value"
+	gdb_test_no_output "guile (set-parameter-value! test-$kind-param 1)"
+	gdb_test "guile (print (parameter-value test-$kind-param))" \
+	    1 "$kind parameter value (1)"
+	gdb_test_no_output "guile (set-parameter-value! test-$kind-param 0)"
+	gdb_test "guile (print (parameter-value test-$kind-param))" \
+	    $param_get_zero "$kind parameter value (0)"
+	scm_param_test_maybe_no_output "set print test-$kind-param -1" \
+	    $param_set_minus_one
+	gdb_test "guile (print (parameter-value test-$kind-param))" \
+	    $param_get_minus_one "$kind parameter value (-1)"
+	scm_param_test_maybe_no_output "set print test-$kind-param -2" \
+	    $param_set_minus_two
+	gdb_test "guile (print (parameter-value test-$kind-param))" \
+	    $param_get_minus_two "$kind parameter value (-2)"
+    }
+}
+
 # Test a file parameter.
 
 gdb_test_multiline "file gdb parameter" \
@@ -206,3 +380,5 @@ with_test_prefix "previously-ambiguous"
     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"
 }
+
+rename scm_param_test_maybe_no_output ""

  reply	other threads:[~2022-08-17 22:03 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17 22:03 [PATCH v6 0/8] gdb: split array and string limiting options Maciej W. Rozycki
2022-08-17 22:03 ` Maciej W. Rozycki [this message]
2022-10-17 13:43   ` [PATCH v6 1/8] GDB/Guile: Don't assert that an integer value is boolean Simon Marchi
2022-10-21  7:58     ` Maciej W. Rozycki
2022-10-21 18:44   ` Simon Marchi
2022-10-21 20:54     ` Maciej W. Rozycki
2022-10-22  0:48       ` Simon Marchi
2022-08-17 22:03 ` [PATCH v6 2/8] GDB/doc: Document the Guile `#:unlimited' keyword Maciej W. Rozycki
2022-08-18  6:06   ` Eli Zaretskii
2022-09-01 10:31     ` Maciej W. Rozycki
2022-08-17 22:04 ` [PATCH v6 3/8] GDB/testsuite: Expand Python integer parameter coverage across all types Maciej W. Rozycki
2022-10-17 13:56   ` Simon Marchi
2022-10-21  7:59     ` Maciej W. Rozycki
2022-08-17 22:04 ` [PATCH v6 4/8] GDB/Python: Make `None' stand for `unlimited' in setting integer parameters Maciej W. Rozycki
2022-10-17 14:26   ` Simon Marchi
2022-10-21  8:03     ` Maciej W. Rozycki
2022-08-17 22:04 ` [PATCH v6 5/8] GDB/Python: Use None for `var_zuinteger_unlimited' value set to `unlimited' Maciej W. Rozycki
2022-08-18  6:08   ` Eli Zaretskii
2022-10-17 15:02   ` Simon Marchi
2022-10-29 15:58     ` Maciej W. Rozycki
2022-10-31 13:00       ` Simon Marchi
2022-10-31 13:31         ` Maciej W. Rozycki
2022-11-01 12:28           ` Maciej W. Rozycki
2022-10-26 11:58   ` Luis Machado
2022-10-29 13:52     ` Maciej W. Rozycki
2022-10-31  8:14       ` Luis Machado
2022-10-31 12:37         ` Luis Machado
2022-10-31 13:08           ` Maciej W. Rozycki
2022-10-31 13:14             ` Luis Machado
2022-10-31 14:05               ` Maciej W. Rozycki
2022-08-17 22:04 ` [PATCH v6 6/8] GDB: Allow arbitrary keywords in integer set commands Maciej W. Rozycki
2022-08-17 22:05 ` [PATCH v6 7/8] GDB: Add a character string limiting option Maciej W. Rozycki
2022-08-17 22:05 ` [PATCH v6 8/8] GDB/testsuite: Expand for character string limiting options Maciej W. Rozycki
2022-08-18  0:07   ` [PATCH v6.1 " Maciej W. Rozycki
2022-09-01 10:32 ` [PING][PATCH v6 0/8] gdb: split array and " Maciej W. Rozycki
2022-09-08  9:37 ` [PING^2][PATCH " Maciej W. Rozycki
2022-09-14 17:43 ` [PING^3][PATCH " Maciej W. Rozycki
2022-09-22 22:07 ` [PING^4][PATCH " Maciej W. Rozycki
2022-09-29  7:09 ` [PING^5][PATCH " Maciej W. Rozycki
2022-09-29  7:12   ` Simon Sobisch
2022-10-06 15:46 ` [PING^6][PATCH " Maciej W. Rozycki
2022-10-12 21:19 ` [PING^7][PATCH " Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.2208151614000.10833@tpp.orcam.me.uk \
    --to=macro@embecosm.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=simonsobisch@web.de \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).