diff options
author | George Barrett <bob@bob131.so> | 2021-07-30 01:12:18 +1000 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-07-29 12:55:16 -0400 |
commit | b5b591a865b3021453a47c612ece5e7574b47d04 (patch) | |
tree | fd2005dd4656f5414fc395b1fa64081e1ff36933 /gdb/guile | |
parent | c3c1e6459f89167fc01de9376c6b34574d710278 (diff) | |
download | gdb-b5b591a865b3021453a47c612ece5e7574b47d04.zip gdb-b5b591a865b3021453a47c612ece5e7574b47d04.tar.gz gdb-b5b591a865b3021453a47c612ece5e7574b47d04.tar.bz2 |
guile: fix make-value with pointer type
Calling the `make-value' procedure with an integer value and a pointer
type for the #:type argument triggers a failed assertion in
`get_unsigned_type_max', as that function doesn't consider pointers to
be an unsigned type. This commit fixes the issue by adding a separate
code path for pointers.
As previously suggested, range checking is done using a new helper
function in gdbtypes.
gdb/ChangeLog:
2021-07-30 George Barrett <bob@bob131.so>
* gdbtypes.h (get_pointer_type_max): Add declaration.
* gdbtypes.c (get_pointer_type_max): Add definition for new
helper function.
* guile/scm-math.c (vlscm_convert_typed_number): Add code path
for handling conversions to pointer types without failing an
assert.
gdb/testsuite/ChangeLog:
2021-07-30 George Barrett <bob@bob131.so>
* gdb.guile/scm-math.exp (test_value_numeric_ops): Add test
for creating pointers with make-value.
(test_make_pointer_value, test_pointer_numeric_range): Add
test procedures containing checks for integer-to-pointer
validation.
Change-Id: I9994dd1c848840a3d995f745e6d72867732049f0
Diffstat (limited to 'gdb/guile')
-rw-r--r-- | gdb/guile/scm-math.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c index 15b7247..96d8cb4 100644 --- a/gdb/guile/scm-math.c +++ b/gdb/guile/scm-math.c @@ -524,8 +524,7 @@ vlscm_convert_typed_number (const char *func_name, int obj_arg_pos, SCM obj, int type_arg_pos, SCM type_scm, struct type *type, struct gdbarch *gdbarch, SCM *except_scmp) { - if (is_integral_type (type) - || type->code () == TYPE_CODE_PTR) + if (is_integral_type (type)) { if (type->is_unsigned ()) { @@ -556,6 +555,19 @@ vlscm_convert_typed_number (const char *func_name, int obj_arg_pos, SCM obj, return value_from_longest (type, gdbscm_scm_to_longest (obj)); } } + else if (type->code () == TYPE_CODE_PTR) + { + CORE_ADDR max = get_pointer_type_max (type); + if (!scm_is_unsigned_integer (obj, 0, max)) + { + *except_scmp + = gdbscm_make_out_of_range_error (func_name, + obj_arg_pos, obj, + _("value out of range for type")); + return NULL; + } + return value_from_pointer (type, gdbscm_scm_to_ulongest (obj)); + } else if (type->code () == TYPE_CODE_FLT) return value_from_host_double (type, scm_to_double (obj)); else |