diff options
author | Tom de Vries <tdevries@suse.de> | 2025-04-09 12:02:18 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2025-04-09 12:02:18 +0200 |
commit | 1bafda2c4595f0f936a5845caf9667b70b198091 (patch) | |
tree | bfa39a306a83e53607626c26e150d1f238a9716a /gdb/testsuite/gdb.dwarf2 | |
parent | 981fe5fd80faf511aa265e841a380c9b46be30e6 (diff) | |
download | binutils-1bafda2c4595f0f936a5845caf9667b70b198091.zip binutils-1bafda2c4595f0f936a5845caf9667b70b198091.tar.gz binutils-1bafda2c4595f0f936a5845caf9667b70b198091.tar.bz2 |
[gdb/symtab] Handle DW_OP_entry_value at function entry
On riscv64-linux, with test-case gdb.base/vla-optimized-out.exp I ran into:
...
(gdb) p sizeof (a)^M
$2 = <optimized out>^M
(gdb) FAIL: $exp: o1: printed size of optimized out vla
...
The variable a has type 0xbf:
...
<1><bf>: Abbrev Number: 12 (DW_TAG_array_type)
<c0> DW_AT_type : <0xe3>
<c4> DW_AT_sibling : <0xdc>
<2><c8>: Abbrev Number: 13 (DW_TAG_subrange_type)
<c9> DW_AT_type : <0xdc>
<cd> DW_AT_upper_bound : 13 byte block:
a3 1 5a 23 1 8 20 24 8 20 26 31 1c
(DW_OP_entry_value: (DW_OP_reg10 (a0));
DW_OP_plus_uconst: 1; DW_OP_const1u: 32;
DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra;
DW_OP_lit1; DW_OP_minus)
...
which has an upper bound using a DW_OP_entry_value, and since the
corresponding call site contains no information to resolve the value of a0 at
function entry:
...
<2><6b>: Abbrev Number: 6 (DW_TAG_call_site)
<6c> DW_AT_call_return_pc: 0x638
<74> DW_AT_call_origin : <0x85>
...
evaluting the dwarf expression fails, and we get <optimized out>.
My first thought was to try breaking at *f1 instead of f1 to see if that would
help, but actually the breakpoint resolved to the same address.
In other words, the inferior is stopped at function entry.
Fix this by resolving DW_OP_entry_value when stopped at function entry by
simply evaluating the expression.
This handles these two cases (x86_64, using reg rdi):
- DW_OP_entry_value: (DW_OP_regx: 5 (rdi))
- DW_OP_entry_value: (DW_OP_bregx: 5 (rdi) 0; DW_OP_deref_size: 4)
Tested on x86_64-linux.
Tested gdb.base/vla-optimized-out.exp on riscv64-linux.
Tested an earlier version of gdb.dwarf2/dw2-entry-value-2.exp on
riscv64-linux, but atm I'm running into trouble on that machine (cfarm92) so
I haven't tested the current version there.
Diffstat (limited to 'gdb/testsuite/gdb.dwarf2')
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.c | 32 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.exp | 125 |
2 files changed, 157 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.c b/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.c new file mode 100644 index 0000000..57025e0 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.c @@ -0,0 +1,32 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025 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 <http://www.gnu.org/licenses/>. */ + +int var = 2; + +static +void bar (int *p) +{ + asm ("bar_label: .globl bar_label"); +} + +int +main() +{ + asm ("main_label: .globl main_label"); + bar (&var); + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.exp new file mode 100644 index 0000000..55ecf9c --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.exp @@ -0,0 +1,125 @@ +# Copyright 2025 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 <http://www.gnu.org/licenses/>. + +# Check that we can get DW_OP_entry_value at function entry. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +standard_testfile .c -debug.S + +set test "get dwarf regnum for first argument register" +if { [is_x86_64_m64_target] } { + set dwarf_regnum 5 +} elseif { [istarget riscv64*] } { + set dwarf_regnum 10 +} else { + set reason "architecture-specific setting missing" + unsupported "$test ($reason)" + return +} +pass $test + +# Set up the DWARF for the test. + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile + + get_func_info main + get_func_info bar + + cu {} { + DW_TAG_compile_unit { + {DW_AT_name $srcfile} + } { + declare_labels integer + + integer: DW_TAG_base_type { + {DW_AT_byte_size 8 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name integer} + } + + DW_TAG_subprogram { + { DW_AT_name main } + { DW_AT_low_pc $main_start DW_FORM_addr } + { DW_AT_high_pc $main_end DW_FORM_addr } + } { + DW_TAG_variable { + { DW_AT_name argc } + { DW_AT_type :$integer } + { DW_AT_location { + DW_OP_entry_value { + DW_OP_regx $::dwarf_regnum + } + } SPECIAL_expr } + } + } + + DW_TAG_subprogram { + { DW_AT_name bar } + { DW_AT_low_pc $bar_start DW_FORM_addr } + { DW_AT_high_pc $bar_end DW_FORM_addr } + } { + DW_TAG_variable { + { DW_AT_name foo } + { DW_AT_type :$integer } + { DW_AT_location { + DW_OP_entry_value { + DW_OP_bregx $::dwarf_regnum 0 + DW_OP_deref_size 4 + } + DW_OP_stack_value + } SPECIAL_expr } + } + } + } + } +} + +if { [prepare_for_testing "failed to prepare" $testfile \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if { ![runto *main] } { + return +} + +with_test_prefix "at main+0" { + gdb_test "p argc" " = 1" + + gdb_test "stepi" +} + +with_test_prefix "at main+1" { + gdb_test "p argc" " = <optimized out>" +} + +gdb_breakpoint "*bar" +gdb_continue_to_breakpoint "bar" + +with_test_prefix "at bar+0" { + gdb_test "p foo" " = 2" + + gdb_test "stepi" +} + +with_test_prefix "at bar+1" { + gdb_test "p foo" " = <optimized out>" +} |