diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8cb475d367a..a982d917057 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-08-31 Simon Marchi + + * frame-unwind.c (frame_unwind_got_optimized): Don't set + regnum/frame in value. Call allocate_value_lazy. + * frame.c (frame_unwind_register_value): Use + val_print_not_saved. + 2020-08-31 Simon Marchi * gdbtypes.h (NULL_TYPE): Remove, change all uses to nullptr. diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index 064f6ebebda..32124c5715a 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -251,18 +251,8 @@ frame_unwind_got_optimized (struct frame_info *frame, int regnum) { struct gdbarch *gdbarch = frame_unwind_arch (frame); struct type *type = register_type (gdbarch, regnum); - struct value *val; - /* Return an lval_register value, so that we print it as - "". */ - val = allocate_value_lazy (type); - set_value_lazy (val, 0); - mark_value_bytes_optimized_out (val, 0, TYPE_LENGTH (type)); - VALUE_LVAL (val) = lval_register; - VALUE_REGNUM (val) = regnum; - VALUE_NEXT_FRAME_ID (val) - = get_frame_id (get_next_frame_sentinel_okay (frame)); - return val; + return allocate_optimized_out_value (type); } /* Return a value which indicates that FRAME copied REGNUM into diff --git a/gdb/frame-unwind.h b/gdb/frame-unwind.h index c80ddc84f29..25a601ccf4b 100644 --- a/gdb/frame-unwind.h +++ b/gdb/frame-unwind.h @@ -133,6 +133,9 @@ typedef void (frame_this_id_ftype) (struct frame_info *this_frame, may be a lazy reference to memory, a lazy reference to the value of a register in THIS frame, or a non-lvalue. + If the previous frame's register was not saved by THIS_FRAME and is + therefore undefined, return a not_lval wholly optimized-out value. + THIS_PROLOGUE_CACHE can be used to share any prolog analysis data with the other unwind methods. Memory for that cache should be allocated using FRAME_OBSTACK_ZALLOC(). */ diff --git a/gdb/frame.c b/gdb/frame.c index 7ab3cdcdad4..ccaf97dc7e9 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1295,7 +1295,7 @@ frame_unwind_register_value (frame_info *next_frame, int regnum) if (value_optimized_out (value)) { fprintf_unfiltered (gdb_stdlog, " "); - val_print_optimized_out (value, gdb_stdlog); + val_print_not_saved (gdb_stdlog); } else { diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 24da6ad79ba..db0296d09f8 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-08-31 Simon Marchi + + * gdb.dwarf2/dw2-reg-undefined.exp: Test "set debug frame 1" + output, printing a "not saved" value from history and printing a + convenience variable created from a "not saved" value. + 2020-08-31 Tom de Vries * gdb.base/eh_return.exp: Use nopie. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp b/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp index a3e6f28c54f..4ab7e2dbfc4 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp @@ -74,3 +74,15 @@ for {set f 0} {$f < 3} {incr f} { "r9\\s+${pattern_r8_r9_info}\\s*"] \ "Check values of rax, rbx, rcx, r8, r9 in frame ${f}" } + +# Test that the debug log statement in frame_unwind_register_value produces +# "not saved" and not# "optimized out". +gdb_test "set debug frame 1" +gdb_test {print $rax} {frame_unwind_register_value[^\r\n]+rax[^\r\n]+not saved.*} +gdb_test "set debug frame 0" + +# Test that history values show "not saved" and not "optimized out". +gdb_test "print" " = " + +# Test that convenience variables _don't_ show "not saved". +gdb_test {print $foo = $rax} " = "