]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix gdb.Value.dynamic_type attribute
authorHannes Domani <ssbssa@yahoo.de>
Tue, 9 Sep 2025 17:28:36 +0000 (19:28 +0200)
committerHannes Domani <ssbssa@yahoo.de>
Tue, 9 Sep 2025 19:11:27 +0000 (21:11 +0200)
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 <simon.marchi@efficios.com>
gdb/python/py-value.c
gdb/testsuite/gdb.python/py-value.c
gdb/testsuite/gdb.python/py-value.exp

index 7cde7a5a32791e57b1a8b12255b8623d36675a47..5d8fab90c04c4b5c98d9efc60700ac5f503138d2 100644 (file)
@@ -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)
     {
index 5052950ce0ddbba13e56b1e29bc36eeb7e2c354d..f6dbf5563e6d3a216c20cd2d8e6d6f3f39641f04 100644 (file)
@@ -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)
 {
index 089bf7563bfd8bff309e4d214461385748d7ef9b..b4e80a21135213a50df1d4ca261701319459f3af 100644 (file)
@@ -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"