From 686d4defdf4a343d4b700b8b544cd40c4f16b0d1 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 25 Oct 2013 11:37:13 +0100 Subject: Print nonexisting/optimized out static fields gracefully. With: struct static_struct { static int aaa; }; struct static_struct sss; int main () { return 0; } We get: (gdb) p sss $1 = {static aaa = } (gdb) p sss.aaa field aaa is nonexistent or has been optimized out Note that the "field aaa ..." message is an error being thrown. GDB is graceful everywhere else when printing optimized out values. IOW it usually prints an value and puts that in the value history. I see no reason for here to be different, more so that when the print the whole "containing" object (well, it's a static field, so it's not really a container), we already print . After the patch: (gdb) p sss $1 = {static aaa = } (gdb) p sss.aaa $2 = The value_entirely_optimized_out checks are there to preserve behavior. Without those, if the static field is a struct/union, GDB would go and print its fields one by one (and print for each). Tested on x86_64 Fedora 17. gdb/ 2013-10-25 Pedro Alves * cp-valprint.c (cp_print_value_fields): No longer handle a NULL static field value. (cp_print_static_field): If the value is entirely optimized out, print here. * jv-valprint.c (java_print_value_fields): No longer handle a NULL static field value. * p-valprint.c (pascal_object_print_static_field): If the value is entirely optimized out, print here. * valops.c (do_search_struct_field) (value_struct_elt_for_reference): No longer handle a NULL static field value. * value.c (value_static_field): Return an optimized out value instead of NULL. gdb/testsuite/ 2013-10-25 Pedro Alves * gdb.cp/m-static.exp: Adjust expected output of printing a nonexistent or optimized out static field. Also test printing the the "container" object. --- gdb/valops.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'gdb/valops.c') diff --git a/gdb/valops.c b/gdb/valops.c index 15fd7c3..8bff686 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1853,13 +1853,7 @@ do_search_struct_field (const char *name, struct value *arg1, int offset, struct value *v; if (field_is_static (&TYPE_FIELD (type, i))) - { - v = value_static_field (type, i); - if (v == 0) - error (_("field %s is nonexistent or " - "has been optimized out"), - name); - } + v = value_static_field (type, i); else v = value_primitive_field (arg1, offset, i, type); *result_ptr = v; @@ -3123,9 +3117,6 @@ value_struct_elt_for_reference (struct type *domain, int offset, if (field_is_static (&TYPE_FIELD (t, i))) { v = value_static_field (t, i); - if (v == NULL) - error (_("static field %s has been optimized out"), - name); if (want_address) v = value_addr (v); return v; -- cgit v1.1