From 2aaba7444679492ae9e2757d7d05ba63bd2ec3c7 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 26 Feb 2024 15:31:34 +0100 Subject: [PATCH] [gdb] Fix "value is not available" with debug frame On arm-linux, with a started hello world, running "info frame" works fine, but when I set debug frame to on, I run into: ... (gdb) info frame ... [frame] frame_unwind_register_value: exit value is not available (gdb) ... The problem is here in frame_unwind_register_value: ... if (value->lazy ()) gdb_printf (&debug_file, " lazy"); else { int i; gdb::array_view buf = value->contents (); ... where we call value->contents () while !value->entirely_available (). Fix this by checking value->entirely_available () and printing: ... [frame] frame_unwind_register_value: -> register=91 unavailable ... Tested on arm-linux. PR gdb/31369 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31369 --- gdb/frame.c | 2 + gdb/testsuite/gdb.base/debug-frame-2.c | 22 ++++++++++ gdb/testsuite/gdb.base/debug-frame.c | 25 +++++++++++ gdb/testsuite/gdb.base/debug-frame.exp | 57 ++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 gdb/testsuite/gdb.base/debug-frame-2.c create mode 100644 gdb/testsuite/gdb.base/debug-frame.c create mode 100644 gdb/testsuite/gdb.base/debug-frame.exp diff --git a/gdb/frame.c b/gdb/frame.c index 9c3f0dfd4f2..5c7aae9edf4 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1315,6 +1315,8 @@ frame_unwind_register_value (const frame_info_ptr &next_frame, int regnum) if (value->lazy ()) gdb_printf (&debug_file, " lazy"); + else if (!value->entirely_available ()) + gdb_printf (&debug_file, " unavailable"); else { int i; diff --git a/gdb/testsuite/gdb.base/debug-frame-2.c b/gdb/testsuite/gdb.base/debug-frame-2.c new file mode 100644 index 00000000000..571b1407374 --- /dev/null +++ b/gdb/testsuite/gdb.base/debug-frame-2.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +void +foo (void) +{ + +} diff --git a/gdb/testsuite/gdb.base/debug-frame.c b/gdb/testsuite/gdb.base/debug-frame.c new file mode 100644 index 00000000000..629c3097aaf --- /dev/null +++ b/gdb/testsuite/gdb.base/debug-frame.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +extern void foo (void); + +int +main (void) +{ + foo (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/debug-frame.exp b/gdb/testsuite/gdb.base/debug-frame.exp new file mode 100644 index 00000000000..f928f19daec --- /dev/null +++ b/gdb/testsuite/gdb.base/debug-frame.exp @@ -0,0 +1,57 @@ +# Copyright 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test relies on checking gdb debug output. Do not run if gdb debug is +# enabled as any debug will be redirected to the log. +require !gdb_debug_enabled + +standard_testfile .c -2.c +set srcfiles [list $srcfile $srcfile2] +if {[prepare_for_testing "failed to prepare" $testfile $srcfiles]} { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Redirect debug output to file. +set logfile [host_standard_output_file gdb.txt] +gdb_test_no_output "set logging file $logfile" \ + "set logging file [file tail $logfile]" +gdb_test_no_output "set logging debugredirect on" +gdb_test "set logging enabled on" + +# Enable debug frame. +gdb_test "set debug frame 1" + +# Check that calling info frame doesn't trigger an exception that escapes to +# the CLI. +set re_locals " Locals at \[^\r\n\]*" +set re_regs1 " Saved registers:" +set re_reg "\[^ \]+ at $hex" +set re_regs2 " $re_reg,( $re_reg,)*" +set re_regs3 " ${re_reg}(, $re_reg)*" + +set re1 $re_locals +set re2 \ + [multi_line \ + $re_locals\ + $re_regs1 \ + ($re_regs2\r\n)*$re_regs3] +gdb_test "info frame" "\r\n($re1|$re2)" + +gdb_test_no_output "set debug frame 0" +gdb_test "set logging enabled off" -- 2.39.5