blob: 9211cf6d24a058f099bb1e377cbc56d7982b5af3 [file]
# Copyright 2013-2026 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/>.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support
require allow_cplus_tests
standard_testfile main.c -dw.S
# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
# Using a funny address size here and in the pointer type lets us
# also check for a sign-extension bug in the
# DW_OP_GNU_implicit_pointer code.
cu { addr_size 2 } {
compile_unit {} {
declare_labels struct_label short_type_label
declare_labels char_type_label ptr_label
declare_labels var_label
struct_label: structure_type {
DW_AT_name S
DW_AT_byte_size 4 DW_FORM_sdata
} {
member {
DW_AT_name a
DW_AT_type :$short_type_label
DW_AT_data_member_location 0 DW_FORM_sdata
}
member {
DW_AT_name b
DW_AT_type :$char_type_label
DW_AT_data_member_location 2 DW_FORM_sdata
}
member {
DW_AT_name c
DW_AT_type :$char_type_label
DW_AT_data_member_location 3 DW_FORM_sdata
}
}
short_type_label: base_type {
DW_AT_name "short int"
DW_AT_encoding @DW_ATE_signed
DW_AT_byte_size 2 DW_FORM_sdata
}
char_type_label: base_type {
DW_AT_name "signed char"
DW_AT_encoding @DW_ATE_signed
DW_AT_byte_size 1 DW_FORM_sdata
}
# See comment above to understand the pointer size.
ptr_label: pointer_type {
DW_AT_byte_size 2 DW_FORM_sdata
DW_AT_type :$char_type_label
}
var_label: DW_TAG_variable {
DW_AT_name s
DW_AT_type :$struct_label
DW_AT_location {
DW_OP_const2u 0x5678
DW_OP_stack_value
DW_OP_piece 2
DW_OP_const1u 2
DW_OP_stack_value
DW_OP_piece 1
DW_OP_const1u 3
DW_OP_stack_value
DW_OP_piece 1
} SPECIAL_expr
}
DW_TAG_variable {
DW_AT_name p
DW_AT_type :$ptr_label
DW_AT_location {
DW_OP_GNU_implicit_pointer $var_label 2
} SPECIAL_expr
}
}
}
}
if { [prepare_for_testing "failed to prepare" ${testfile} \
[list $srcfile $asm_file] {nodebug}] } {
return
}
if {![runto_main]} {
return
}
# Determine byte order.
set endian [get_endianness]
# Access the second byte of s through an implicit pointer to the third
# byte of s, using a negative offset. Compare that to the second byte of
# the short integer 0x5678 in target byte order.
switch $endian { little {set val 0x56} big {set val 0x78} }
gdb_test "p/x p\[-1\]" " = $val"