From: Hannes Domani Date: Tue, 9 Sep 2025 17:28:36 +0000 (+0200) Subject: Fix gdb.Value.dynamic_type attribute X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b7e3459d2c08c16e85af69690eb7e42c824a447a;p=thirdparty%2Fbinutils-gdb.git Fix gdb.Value.dynamic_type attribute gdb currently crashes if you try to get the dynamic_type from a gdb.Value of a POD struct: (gdb) py print(gdb.parse_and_eval('pod').dynamic_type) Fatal signal: Segmentation fault It happens because value_rtti_type() returns NULL for them, and this is not handled correctly. Fixed by using val->type() as a fallback in this case. Approved-By: Simon Marchi --- diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 7cde7a5a327..5d8fab90c04 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -478,6 +478,9 @@ valpy_get_dynamic_type (PyObject *self, void *closure) type = value_rtti_type (val, NULL, NULL, NULL); else type = val->type (); + + if (type == nullptr) + type = val->type (); } catch (const gdb_exception &except) { diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index 5052950ce0d..f6dbf5563e6 100644 --- a/gdb/testsuite/gdb.python/py-value.c +++ b/gdb/testsuite/gdb.python/py-value.c @@ -68,6 +68,7 @@ struct Derived : public Base { Base *base = new Derived (); Derived derived; Base &base_ref = derived; +struct str pod; void ptr_ref(int*& rptr_int) { diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 089bf7563bf..b4e80a21135 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -458,6 +458,8 @@ proc test_subscript_regression {exefile lang} { "Derived \[*\]" gdb_test "python print (gdb.parse_and_eval('base_ref').dynamic_type)" \ "Derived \[&\]" + gdb_test "python print (gdb.parse_and_eval('pod').dynamic_type)" \ + "str" # A static type case. gdb_test "python print (gdb.parse_and_eval('5').dynamic_type)" \ "int"