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

@@ -24,6 +24,7 @@ main ()
const char array[] = "array";
pointer typedef_ptr = "typedef pointer";
const char *null = 0;
int not_a_string = 23;
return 0; /* break here */
}

View File

@@ -73,3 +73,8 @@ foreach var_spec { { "ptr" "pointer" "const char \\*" -1 } \
#gdb_test "python print ($var.lazy_string(length=0).value())" "\"\"" "empty lazy string value"
}
}
gdb_py_test_silent_cmd "python nas = gdb.parse_and_eval('not_a_string')" \
"get not_a_string" 1
gdb_test "python print(nas.lazy_string())" \
"Cannot make lazy string from this object"