Fix type of values representing optimized out static members
authorSimon Marchi <simark@simark.ca>
Wed, 7 Feb 2018 13:48:14 +0000 (08:48 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Wed, 7 Feb 2018 13:49:56 +0000 (08:49 -0500)
As reported here:

  https://sourceware.org/ml/gdb/2018-02/msg00019.html

the type of values representing static members that are optimized out is
wrong.  It currently assigns the type of the containing class rather
than the type of the field.  This patch fixes that.

I found a place in m-static.exp already dealing with optimized out
static members, so I just added some gdb_test there.

gdb/ChangeLog:

* value.c (value_static_field): Assign field type instead of
containing type when returning an optimized out value.

gdb/testsuite/ChangeLog:

* gdb.cp/m-static.exp: Check type of optimized out static
member.

gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/m-static.exp
gdb/value.c

index 229756853c7700bf6a7ac877a81c8019f5cc9586..00ed7e78c2d90d2c9e1a8b65910ad4e904226574 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-07  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * value.c (value_static_field): Assign field type instead of
+       containing type when returning an optimized out value.
+
 2018-02-06  Yao Qi  <yao.qi@linaro.org>
 
        * ft32-tdep.c (ft32_read_pc): Remove.
index 0af50b0498adb5f191f6fbc2cf20bb379c9f8ca2..18512b97245280b1a36596a53cb78b5515faab81 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-07  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * gdb.cp/m-static.exp: Check type of optimized out static
+       member.
+
 2018-02-03  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * config/sid.exp (gdb_target_sid): Remove use of cleanup.
index 65661713ff3862bab7f8521f19d20d63e06340ae..ffcbf5334f0d1b9562f41058c6773394dea620cf 100644 (file)
@@ -165,6 +165,8 @@ if {[test_compiler_info {gcc-[0-3]-*}]
     setup_xfail *-*-*
 }
 gdb_test "print test4.nowhere" "<optimized out>" "static const int initialized nowhere (print field)"
+gdb_test "ptype test4.nowhere" "type = const int"
+gdb_test "print test4.nowhere.nowhere" "Attempt to extract a component of a value that is not a structure."
 
 # Same, but print the whole struct.
 gdb_test "print test4" "static nowhere = <optimized out>.*" "static const int initialized nowhere (whole struct)"
index 9a144fb7fb62439b52a4ec5ebd25c81c050b5957..9cd9a2fcc72717d32f94e5be3854c879fb694211 100644 (file)
@@ -2976,14 +2976,12 @@ value_static_field (struct type *type, int fieldno)
             reported as non-debuggable symbols.  */
          struct bound_minimal_symbol msym
            = lookup_minimal_symbol (phys_name, NULL, NULL);
+         struct type *field_type = TYPE_FIELD_TYPE (type, fieldno);
 
          if (!msym.minsym)
-           return allocate_optimized_out_value (type);
+           retval = allocate_optimized_out_value (field_type);
          else
-           {
-             retval = value_at_lazy (TYPE_FIELD_TYPE (type, fieldno),
-                                     BMSYMBOL_VALUE_ADDRESS (msym));
-           }
+           retval = value_at_lazy (field_type, BMSYMBOL_VALUE_ADDRESS (msym));
        }
       else
        retval = value_of_variable (sym.symbol, sym.block);