aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-11-18 13:47:22 -0700
committerTom Tromey <tromey@adacore.com>2024-12-09 14:17:21 -0700
commit2134b0b4a5ff493878386183dfd8a735b5334ad7 (patch)
treee9b318cc897c5b3fdffbe6f37f97c8d8b29504e6 /gdb/python
parent523a46ee9795bbec2d1d5cf7e434adc2a3044f94 (diff)
downloadbinutils-2134b0b4a5ff493878386183dfd8a735b5334ad7.zip
binutils-2134b0b4a5ff493878386183dfd8a735b5334ad7.tar.gz
binutils-2134b0b4a5ff493878386183dfd8a735b5334ad7.tar.bz2
Reject non-string types in gdb.Value.lazy_string
Currently, gdb.Value.lazy_string will allow the conversion of any object to a "lazy string". However, this was never the intent and is weird besides. This patch changes this code to correctly throw an exception in the non-matching cases. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20769
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-lazy-string.c4
-rw-r--r--gdb/python/py-value.c13
2 files changed, 3 insertions, 14 deletions
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index e61b80a..30a171d 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -264,9 +264,7 @@ stpy_lazy_string_elt_type (lazy_string_object *lazy)
case TYPE_CODE_ARRAY:
return check_typedef (realtype->target_type ());
default:
- /* This is done to preserve existing behavior. PR 20769.
- E.g., gdb.parse_and_eval("my_int_variable").lazy_string().type. */
- return realtype;
+ gdb_assert_not_reached ("invalid lazy string");
}
}
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 1e8e58a..02c50b4 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -521,14 +521,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
If LENGTH is provided then the length parameter is set to LENGTH.
Otherwise if the value is an array of known length then the array's length
is used. Otherwise the length will be set to -1 (meaning first null of
- appropriate with).
-
- Note: In order to not break any existing uses this allows creating
- lazy strings from anything. PR 20769. E.g.,
- gdb.parse_and_eval("my_int_variable").lazy_string().
- "It's easier to relax restrictions than it is to impose them after the
- fact." So we should be flagging any unintended uses as errors, but it's
- perhaps too late for that. */
+ appropriate with). */
static PyObject *
valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
@@ -596,9 +589,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
addr = value_as_address (value);
break;
default:
- /* Should flag an error here. PR 20769. */
- addr = value->address ();
- break;
+ error (_("Cannot make lazy string from this object"));
}
str_obj = gdbpy_create_lazy_string_object (addr, length, user_encoding,