From eebc056c8e1ae9bc015645acf861bde0eff8335a Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 28 Nov 2013 18:54:20 +0000 Subject: [PATCH] Print entirely unavailable struct/union values as a single . When printing an entirely optimized out structure/class/union, we print a single instead of printing for each field. This patch makes an entirely unavailable structure/class/union be likewise displayed with a single "" rather than the whole object with all fields . This seems good because this way the user can quickly tell whether the whole value is unavailable, rather than having to skim all fields. Consistency with optimized out values also seems to be a good thing to have. A few updates to gdb.trace/unavailable.exp where required. Tested on x86_64 Fedora 17, native gdbserver. gdb/ 2013-11-28 Andrew Burgess Pedro Alves * valprint.c (value_check_printable): If the value is entirely unavailable, print a single "" instead of printing all subfields. gdb/testsuite/ 2013-11-28 Andrew Burgess * gdb.trace/unavailable.exp (gdb_collect_args_test): Update expected results. (gdb_collect_locals_test): Likewise. (gdb_collect_globals_test): Likewise. --- gdb/ChangeLog | 7 +++++ gdb/testsuite/ChangeLog | 7 +++++ gdb/testsuite/gdb.trace/unavailable.exp | 41 +++++++++++-------------- gdb/valprint.c | 9 ++++++ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b15bee9676..41c43d48f5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2013-11-28 Andrew Burgess + Pedro Alves + + * valprint.c (value_check_printable): If the value is entirely + unavailable, print a single "" instead of printing + all subfields. + 2013-11-28 Pedro Alves * frame.c (get_prev_frame_1) : diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 8697d639a9..601517253b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2013-11-28 Andrew Burgess + + * gdb.trace/unavailable.exp (gdb_collect_args_test): Update + expected results. + (gdb_collect_locals_test): Likewise. + (gdb_collect_globals_test): Likewise. + 2013-11-28 Yao Qi * lib/gdb.exp (with_gdb_prompt): New proc. diff --git a/gdb/testsuite/gdb.trace/unavailable.exp b/gdb/testsuite/gdb.trace/unavailable.exp index ed14798ba7..40319d58c4 100644 --- a/gdb/testsuite/gdb.trace/unavailable.exp +++ b/gdb/testsuite/gdb.trace/unavailable.exp @@ -169,15 +169,14 @@ proc gdb_collect_args_test {} { # struct arg as one of several args (near end of list) - gdb_test "print argstruct" \ - " = \{memberc = , memberi = , memberf = , memberd = \}" + gdb_test "print argstruct" " = " gdb_test "print argstruct.memberc" " = " gdb_test "print argstruct.memberi" " = " gdb_test "print argstruct.memberf" " = " gdb_test "print argstruct.memberd" " = " - gdb_test "print argarray" " = \\(int \\*\\) " + gdb_test "print argarray" " = " gdb_test "print &argarray" \ "Can't take address of \"argarray\" which isn't an lvalue\." @@ -190,7 +189,7 @@ proc gdb_collect_args_test {} { set r "${r}argi = ${cr}" set r "${r}argf = ${cr}" set r "${r}argd = ${cr}" - set r "${r}argstruct = {memberc = , memberi = , memberf = , memberd = }${cr}" + set r "${r}argstruct = ${cr}" set r "${r}argarray = ${cr}" gdb_test "info args" "$r" "info args" @@ -237,11 +236,11 @@ proc gdb_collect_locals_test { func msg } { set r "" set r "${r}locf = ${cr}" set r "${r}locd = ${cr}" - set r "${r}locst = {memberc = , memberi = , memberf = , memberd = }${cr}" - set r "${r}locar = {, , , }${cr}" + set r "${r}locst = ${cr}" + set r "${r}locar = ${cr}" set r "${r}i = ${cr}" if { $func == "local_test_func" } { - set r "${r}locdefst = {}${cr}" + set r "${r}locdefst = ${cr}" } set r "${r}locc = ${cr}" set r "${r}loci = ${cr}" @@ -398,8 +397,7 @@ proc gdb_collect_globals_test { } { gdb_test "print globalstruct.memberf" " = " gdb_test "print globalstruct.memberd" " = " - gdb_test "print globalstruct" \ - " = {memberc = , memberi = , memberf = , memberd = }" + gdb_test "print globalstruct" " = " gdb_test "print globalp == &globalstruct" \ "value is not available" \ @@ -449,8 +447,7 @@ proc gdb_collect_globals_test { } { # Static fields - gdb_test "print struct_b.static_struct_a" \ - " = {a = , b = , array = { }, ptr = , bitfield = }" + gdb_test "print struct_b.static_struct_a" " = " # Bitfields @@ -468,8 +465,7 @@ proc gdb_collect_globals_test { } { "\\$\[0-9\]+ = $cr" \ "referenced integer was not collected (taking address of reference)" - gdb_test "print *g_structref_p" \ - " = {d = , ref = }" + gdb_test "print *g_structref_p" " = " # Strings @@ -483,7 +479,7 @@ proc gdb_collect_globals_test { } { "printing constant string through collected pointer" gdb_test "print g_string_unavail" \ - " = \{ \}" \ + " = " \ "printing non collected string" # Incomplete strings print as an array. @@ -521,15 +517,15 @@ proc gdb_collect_globals_test { } { # unavailable-ness is propagated. History values are easy # non-lazy values, so use those. The first test just sets up for # the second. - gdb_test "print g_smallstruct" " = \\{member = \\}" + gdb_test "print g_smallstruct" " = " gdb_test "print \$.member" " = " # Cast to baseclass, checking the unavailable-ness is propagated. - gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = \\}" + gdb_test "print (small_struct) g_smallstruct_b" " = " # Same cast, but starting from a non-lazy, value. - gdb_test "print g_smallstruct_b" " = \\{ = \\{member = \\}, \\}" - gdb_test "print (small_struct) \$" " = \\{member = \\}" + gdb_test "print g_smallstruct_b" " = " + gdb_test "print (small_struct) \$" " = " gdb_test_no_output "set print object on" @@ -538,11 +534,10 @@ proc gdb_collect_globals_test { } { # the pointed-to object, to check its run-time type. Make # sure that fails gracefully and transparently when the # pointer itself is unavailable. - gdb_test "print virtualp" " = \\(Virtual \\*\\) " + gdb_test "print virtualp" " = " # no vtable pointer available - gdb_test "print derived_unavail" \ - " = { = , _vptr.Derived = , z = }" + gdb_test "print derived_unavail" " = " # vtable pointer available, but nothing else gdb_test "print derived_partial" \ @@ -556,11 +551,11 @@ proc gdb_collect_globals_test { } { gdb_test_no_output "set print object off" with_test_prefix "print object off" { - gdb_test "print virtualp" " = \\(Virtual \\*\\) " + gdb_test "print virtualp" " = " # no vtable pointer available gdb_test "print derived_unavail" \ - " = { = , _vptr.Derived = , z = }" + " = " # vtable pointer available, but nothing else gdb_test "print derived_partial" \ diff --git a/gdb/valprint.c b/gdb/valprint.c index ecc3411b6e..0124934cb7 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -812,6 +812,15 @@ value_check_printable (struct value *val, struct ui_file *stream, return 0; } + if (value_entirely_unavailable (val)) + { + if (options->summary && !val_print_scalar_type_p (value_type (val))) + fprintf_filtered (stream, "..."); + else + val_print_unavailable (stream); + return 0; + } + if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION) { fprintf_filtered (stream, _(""),