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
This commit is contained in:
Tom Tromey
2024-11-18 13:47:22 -07:00
parent 523a46ee97
commit 2134b0b4a5
4 changed files with 9 additions and 14 deletions

View File

@@ -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");
}
}